You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ah...@apache.org on 2013/01/19 01:00:12 UTC
[34/51] [abbrv] All merge conflicts resolved
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/10d9c019/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/element/VpcVirtualRouterElement.java
index 60924a2,f923ae1..27b1a2a
--- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
+++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
@@@ -61,13 -60,14 +60,15 @@@ import com.cloud.vm.ReservationContext
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.Type;
import com.cloud.vm.VirtualMachineProfile;
+
- @Local(value = NetworkElement.class)
+ @Local(value = {NetworkElement.class, FirewallServiceProvider.class,
+ DhcpServiceProvider.class, UserDataServiceProvider.class,
+ StaticNatServiceProvider.class, LoadBalancingServiceProvider.class,
+ PortForwardingServiceProvider.class, IpDeployer.class, VpcProvider.class,
+ Site2SiteVpnServiceProvider.class, NetworkACLServiceProvider.class})
public class VpcVirtualRouterElement extends VirtualRouterElement implements VpcProvider, Site2SiteVpnServiceProvider, NetworkACLServiceProvider{
private static final Logger s_logger = Logger.getLogger(VpcVirtualRouterElement.class);
- @Inject
+ @Inject
- NetworkService _ntwkService;
- @Inject
VpcManager _vpcMgr;
@Inject
VpcVirtualNetworkApplianceManager _vpcRouterMgr;
@@@ -75,16 -75,16 +76,16 @@@
Site2SiteVpnGatewayDao _vpnGatewayDao;
@Inject
IPAddressDao _ipAddressDao;
--
++
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
--
++
@Override
protected boolean canHandle(Network network, Service service) {
Long physicalNetworkId = _networkMgr.getPhysicalNetworkId(network);
if (physicalNetworkId == null) {
return false;
}
--
++
if (network.getVpcId() == null) {
return false;
}
@@@ -108,11 -108,11 +109,11 @@@
return true;
}
--
++
@Override
public boolean implementVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException {
--
++
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
@@@ -120,7 -120,7 +121,7 @@@
return true;
}
--
++
@Override
public boolean shutdownVpc(Vpc vpc, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
List<DomainRouterVO> routers = _routerDao.listByVpcId(vpc.getId());
@@@ -133,67 -133,67 +134,67 @@@
}
return result;
}
--
++
@Override
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context)
throws ResourceUnavailableException, ConcurrentOperationException,
InsufficientCapacityException {
--
-- Long vpcId = network.getVpcId();
-- if (vpcId == null) {
-- s_logger.warn("Network " + network + " is not associated with any VPC");
-- return false;
-- }
--
-- Vpc vpc = _vpcMgr.getActiveVpc(vpcId);
-- if (vpc == null) {
-- s_logger.warn("Unable to find Enabled VPC by id " + vpcId);
-- return false;
-- }
--
-- Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
-- params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
--
-- List<DomainRouterVO> routers = _vpcRouterMgr.deployVirtualRouterInVpc(vpc, dest, _accountMgr.getAccount(vpc.getAccountId()), params);
-- if ((routers == null) || (routers.size() == 0)) {
-- throw new ResourceUnavailableException("Can't find at least one running router!",
-- DataCenter.class, network.getDataCenterId());
-- }
--
-- if (routers.size() > 1) {
-- throw new CloudRuntimeException("Found more than one router in vpc " + vpc);
-- }
--
-- DomainRouterVO router = routers.get(0);
-- //Add router to guest network if needed
-- if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) {
-- if (!_vpcRouterMgr.addVpcRouterToGuestNetwork(router, network, false)) {
-- throw new CloudRuntimeException("Failed to add VPC router " + router + " to guest network " + network);
-- } else {
-- s_logger.debug("Successfully added VPC router " + router + " to guest network " + network);
-- }
-- }
--
-- return true;
++
++ Long vpcId = network.getVpcId();
++ if (vpcId == null) {
++ s_logger.warn("Network " + network + " is not associated with any VPC");
++ return false;
++ }
++
++ Vpc vpc = _vpcMgr.getActiveVpc(vpcId);
++ if (vpc == null) {
++ s_logger.warn("Unable to find Enabled VPC by id " + vpcId);
++ return false;
++ }
++
++ Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
++ params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
++
++ List<DomainRouterVO> routers = _vpcRouterMgr.deployVirtualRouterInVpc(vpc, dest, _accountMgr.getAccount(vpc.getAccountId()), params);
++ if ((routers == null) || (routers.size() == 0)) {
++ throw new ResourceUnavailableException("Can't find at least one running router!",
++ DataCenter.class, network.getDataCenterId());
++ }
++
++ if (routers.size() > 1) {
++ throw new CloudRuntimeException("Found more than one router in vpc " + vpc);
++ }
++
++ DomainRouterVO router = routers.get(0);
++ //Add router to guest network if needed
++ if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) {
++ if (!_vpcRouterMgr.addVpcRouterToGuestNetwork(router, network, false)) {
++ throw new CloudRuntimeException("Failed to add VPC router " + router + " to guest network " + network);
++ } else {
++ s_logger.debug("Successfully added VPC router " + router + " to guest network " + network);
++ }
++ }
++
++ return true;
}
--
++
@Override
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm,
DeployDestination dest, ReservationContext context)
throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
--
++
Long vpcId = network.getVpcId();
if (vpcId == null) {
s_logger.warn("Network " + network + " is not associated with any VPC");
return false;
}
--
++
Vpc vpc = _vpcMgr.getActiveVpc(vpcId);
if (vpc == null) {
s_logger.warn("Unable to find Enabled VPC by id " + vpcId);
return false;
}
--
++
if (vm.getType() == Type.User) {
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
@@@ -203,11 -203,11 +204,11 @@@
throw new ResourceUnavailableException("Can't find at least one running router!",
DataCenter.class, network.getDataCenterId());
}
--
++
if (routers.size() > 1) {
throw new CloudRuntimeException("Found more than one router in vpc " + vpc);
}
--
++
DomainRouterVO router = routers.get(0);
//Add router to guest network if needed
if (!_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) {
@@@ -218,10 -218,10 +219,10 @@@
}
}
}
--
++
return true;
}
--
++
@Override
public boolean shutdown(Network network, ReservationContext context, boolean cleanup)
throws ConcurrentOperationException, ResourceUnavailableException {
@@@ -231,7 -231,7 +232,7 @@@
s_logger.debug("Network " + network + " doesn't belong to any vpc, so skipping unplug nic part");
return success;
}
--
++
List<? extends VirtualRouter> routers = _routerDao.listByVpcId(vpcId);
for (VirtualRouter router : routers) {
//1) Check if router is already a part of the network
@@@ -247,7 -247,7 +248,7 @@@
s_logger.debug("Successfully unplugged nic in network " + network + " for virtual router " + router);
}
}
--
++
return success;
}
@@@ -259,7 -259,7 +260,7 @@@
s_logger.debug("Network " + config + " doesn't belong to any vpc, so skipping unplug nic part");
return success;
}
--
++
List<? extends VirtualRouter> routers = _routerDao.listByVpcId(vpcId);
for (VirtualRouter router : routers) {
//1) Check if router is already a part of the network
@@@ -275,91 -275,91 +276,91 @@@
s_logger.debug("Successfully unplugged nic in network " + config + " for virtual router " + router);
}
}
--
++
return success;
}
--
++
@Override
public Provider getProvider() {
return Provider.VPCVirtualRouter;
}
--
++
private static Map<Service, Map<Capability, String>> setCapabilities() {
Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
capabilities.putAll(VirtualRouterElement.capabilities);
--
++
Map<Capability, String> sourceNatCapabilities = new HashMap<Capability, String>();
sourceNatCapabilities.putAll(capabilities.get(Service.SourceNat));
sourceNatCapabilities.put(Capability.RedundantRouter, "false");
capabilities.put(Service.SourceNat, sourceNatCapabilities);
--
++
Map<Capability, String> vpnCapabilities = new HashMap<Capability, String>();
vpnCapabilities.putAll(capabilities.get(Service.Vpn));
vpnCapabilities.put(Capability.VpnTypes, "s2svpn");
capabilities.put(Service.Vpn, vpnCapabilities);
--
++
//remove firewall capability
capabilities.remove(Service.Firewall);
--
++
//add network ACL capability
Map<Capability, String> networkACLCapabilities = new HashMap<Capability, String>();
networkACLCapabilities.put(Capability.SupportedProtocols, "tcp,udp,icmp");
capabilities.put(Service.NetworkACL, networkACLCapabilities);
-
+
return capabilities;
}
--
++
@Override
public Map<Service, Map<Capability, String>> getCapabilities() {
return capabilities;
}
--
++
@Override
public boolean createPrivateGateway(PrivateGateway gateway) throws ConcurrentOperationException, ResourceUnavailableException {
if (gateway.getType() != VpcGateway.Type.Private) {
s_logger.warn("Type of vpc gateway is not " + VpcGateway.Type.Private);
return false;
}
--
++
List<DomainRouterVO> routers = _vpcMgr.getVpcRouters(gateway.getVpcId());
if (routers == null || routers.isEmpty()) {
s_logger.debug(this.getName() + " element doesn't need to create Private gateway on the backend; VPC virtual " +
"router doesn't exist in the vpc id=" + gateway.getVpcId());
return true;
}
--
++
if (routers.size() > 1) {
throw new CloudRuntimeException("Found more than one router in vpc " + gateway.getVpcId());
}
--
++
VirtualRouter router = routers.get(0);
--
++
return _vpcRouterMgr.setupPrivateGateway(gateway, router);
}
--
++
@Override
public boolean deletePrivateGateway(PrivateGateway gateway) throws ConcurrentOperationException, ResourceUnavailableException {
if (gateway.getType() != VpcGateway.Type.Private) {
s_logger.warn("Type of vpc gateway is not " + VpcGateway.Type.Private);
return false;
}
--
++
List<DomainRouterVO> routers = _vpcMgr.getVpcRouters(gateway.getVpcId());
if (routers == null || routers.isEmpty()) {
s_logger.debug(this.getName() + " element doesn't need to delete Private gateway on the backend; VPC virtual " +
"router doesn't exist in the vpc id=" + gateway.getVpcId());
return true;
}
--
++
if (routers.size() > 1) {
throw new CloudRuntimeException("Found more than one router in vpc " + gateway.getVpcId());
}
--
++
VirtualRouter router = routers.get(0);
--
++
return _vpcRouterMgr.destroyPrivateGateway(gateway, router);
}
--
++
@Override
protected List<DomainRouterVO> getRouters(Network network, DeployDestination dest) {
return _vpcMgr.getVpcRouters(network.getVpcId());
@@@ -388,7 -388,7 +389,7 @@@
return false;
}
}
--
++
@Override
public boolean applyNetworkACLs(Network config, List<? extends FirewallRule> rules) throws ResourceUnavailableException {
if (canHandle(config, Service.NetworkACL)) {
@@@ -408,7 -408,7 +409,7 @@@
return true;
}
}
--
++
@Override
protected VirtualRouterProviderType getVirtualRouterProvider() {
return VirtualRouterProviderType.VPCVirtualRouter;
@@@ -431,6 -431,6 +432,7 @@@
}
}
++ @Override
public boolean startSite2SiteVpn(Site2SiteVpnConnection conn) throws ResourceUnavailableException {
Site2SiteVpnGateway vpnGw = _vpnGatewayDao.findById(conn.getVpnGatewayId());
IpAddress ip = _ipAddressDao.findById(vpnGw.getAddrId());
@@@ -440,10 -440,10 +442,10 @@@
s_logger.error("try to start site 2 site vpn on unsupported network element?");
return false;
}
--
++
Long vpcId = ip.getVpcId();
Vpc vpc = _vpcMgr.getVpc(vpcId);
--
++
if (!_vpcMgr.vpcProviderEnabledInZone(vpc.getZoneId())) {
throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(),
DataCenter.class, vpc.getZoneId());
@@@ -468,10 -468,10 +470,10 @@@
s_logger.error("try to stop site 2 site vpn on unsupported network element?");
return false;
}
--
++
Long vpcId = ip.getVpcId();
Vpc vpc = _vpcMgr.getVpc(vpcId);
--
++
if (!_vpcMgr.vpcProviderEnabledInZone(vpc.getZoneId())) {
throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(),
DataCenter.class, vpc.getZoneId());
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/10d9c019/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/firewall/FirewallManagerImpl.java
index 6193d11,7bab1ba..c3fc03b
--- a/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
+++ b/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
@@@ -51,6 -51,11 +53,10 @@@ import com.cloud.network.NetworkRuleApp
import com.cloud.network.dao.FirewallRulesCidrsDao;
import com.cloud.network.dao.FirewallRulesDao;
import com.cloud.network.dao.IPAddressDao;
+ import com.cloud.network.element.FirewallServiceProvider;
+ import com.cloud.network.element.NetworkACLServiceProvider;
-import com.cloud.network.element.NetworkElement;
+ import com.cloud.network.element.PortForwardingServiceProvider;
+ import com.cloud.network.element.StaticNatServiceProvider;
import com.cloud.network.rules.FirewallManager;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.FirewallRule.FirewallRuleType;
@@@ -83,9 -92,8 +91,9 @@@ import com.cloud.utils.net.NetUtils
import com.cloud.vm.UserVmVO;
import com.cloud.vm.dao.UserVmDao;
+@Component
@Local(value = { FirewallService.class, FirewallManager.class})
- public class FirewallManagerImpl implements FirewallService, FirewallManager, Manager {
+ public class FirewallManagerImpl implements FirewallService, FirewallManager, NetworkRuleApplier, Manager {
private static final Logger s_logger = Logger.getLogger(FirewallManagerImpl.class);
String _name;
@@@ -117,6 -127,17 +127,13 @@@
ResourceTagDao _resourceTagDao;
@Inject
VpcManager _vpcMgr;
- @Inject(adapter = FirewallServiceProvider.class)
- Adapters<FirewallServiceProvider> _firewallElements;
-
- @Inject(adapter = PortForwardingServiceProvider.class)
- Adapters<PortForwardingServiceProvider> _pfElements;
-
- @Inject(adapter = StaticNatServiceProvider.class)
- Adapters<StaticNatServiceProvider> _staticNatElements;
-
- @Inject(adapter = NetworkACLServiceProvider.class)
- Adapters<NetworkACLServiceProvider> _networkAclElements;
++ @Inject List<FirewallServiceProvider> _firewallElements;
++
++ @Inject List<PortForwardingServiceProvider> _pfElements;
++
++ @Inject List<StaticNatServiceProvider> _staticNatElements;
++
++ @Inject List<NetworkACLServiceProvider> _networkAclElements;
private boolean _elbEnabled = false;
@@@ -158,7 -180,7 +176,7 @@@
public FirewallRule createFirewallRule(long ipAddrId, Account caller, String xId, Integer portStart,
Integer portEnd, String protocol, List<String> sourceCidrList, Integer icmpCode, Integer icmpType,
Long relatedRuleId, FirewallRule.FirewallRuleType type, long networkId) throws NetworkRuleConflictException {
--
++
IPAddressVO ipAddress = _ipAddressDao.findById(ipAddrId);
// Validate ip address
if (ipAddress == null && type == FirewallRule.FirewallRuleType.User) {
@@@ -241,16 -263,16 +259,16 @@@
if (tags != null && !tags.isEmpty()) {
-- SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
-- for (int count=0; count < tags.size(); count++) {
-- tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
-- tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
-- tagSearch.cp();
-- }
-- tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
-- sb.groupBy(sb.entity().getId());
-- sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
-- }
++ SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
++ for (int count=0; count < tags.size(); count++) {
++ tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
++ tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
++ tagSearch.cp();
++ }
++ tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
++ sb.groupBy(sb.entity().getId());
++ sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
++ }
SearchCriteria<FirewallRuleVO> sc = sb.create();
_accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
@@@ -284,7 -306,7 +302,7 @@@
List<FirewallRuleVO> rules = _firewallDao.listByIpAndPurposeAndNotRevoked(newRule.getSourceIpAddressId(), null);
assert (rules.size() >= 1) : "For network rules, we now always first persist the rule and then check for " +
-- "network conflicts so we should at least have one rule at this point.";
++ "network conflicts so we should at least have one rule at this point.";
for (FirewallRuleVO rule : rules) {
if (rule.getId() == newRule.getId()) {
@@@ -293,7 -315,7 +311,7 @@@
boolean oneOfRulesIsFirewall = ((rule.getPurpose() == Purpose.Firewall || newRule.getPurpose() == Purpose.Firewall)
&& ((newRule.getPurpose() != rule.getPurpose()) || (!newRule.getProtocol()
-- .equalsIgnoreCase(rule.getProtocol()))));
++ .equalsIgnoreCase(rule.getProtocol()))));
// if both rules are firewall and their cidrs are different, we can skip port ranges verification
boolean bothRulesFirewall = (rule.getPurpose() == newRule.getPurpose() && rule.getPurpose() == Purpose.Firewall);
@@@ -345,12 -367,12 +363,12 @@@
} else if (!oneOfRulesIsFirewall && !(bothRulesFirewall && !duplicatedCidrs)
&& ((rule.getSourcePortStart().intValue() <= newRule.getSourcePortStart().intValue()
&& rule.getSourcePortEnd().intValue() >= newRule.getSourcePortStart().intValue())
-- || (rule.getSourcePortStart().intValue() <= newRule.getSourcePortEnd().intValue()
-- && rule.getSourcePortEnd().intValue() >= newRule.getSourcePortEnd().intValue())
-- || (newRule.getSourcePortStart().intValue() <= rule.getSourcePortStart().intValue()
-- && newRule.getSourcePortEnd().intValue() >= rule.getSourcePortStart().intValue())
-- || (newRule.getSourcePortStart().intValue() <= rule.getSourcePortEnd().intValue()
-- && newRule.getSourcePortEnd().intValue() >= rule.getSourcePortEnd().intValue()))) {
++ || (rule.getSourcePortStart().intValue() <= newRule.getSourcePortEnd().intValue()
++ && rule.getSourcePortEnd().intValue() >= newRule.getSourcePortEnd().intValue())
++ || (newRule.getSourcePortStart().intValue() <= rule.getSourcePortStart().intValue()
++ && newRule.getSourcePortEnd().intValue() >= rule.getSourcePortStart().intValue())
++ || (newRule.getSourcePortStart().intValue() <= rule.getSourcePortEnd().intValue()
++ && newRule.getSourcePortEnd().intValue() >= rule.getSourcePortEnd().intValue()))) {
// we allow port forwarding rules with the same parameters but different protocols
boolean allowPf = (rule.getPurpose() == Purpose.PortForwarding && newRule.getPurpose() == Purpose.PortForwarding
@@@ -447,7 -474,7 +470,7 @@@
//if the rule is the last one for the ip address assigned to VPC, unassign it from the network
IpAddress ip = _ipAddressDao.findById(rule.getSourceIpAddressId());
_vpcMgr.unassignIPFromVpcNetwork(ip.getId(), rule.getNetworkId());
-- }
++ }
}
} else if (rule.getState() == FirewallRule.State.Add) {
FirewallRuleVO ruleVO = _firewallDao.findById(rule.getId());
@@@ -462,6 -489,46 +485,46 @@@
}
@Override
+ public boolean applyRules(Network network, Purpose purpose, List<? extends FirewallRule> rules)
+ throws ResourceUnavailableException {
- boolean handled = false;
- switch (purpose){
- case Firewall:
- for (FirewallServiceProvider fwElement: _firewallElements) {
- handled = fwElement.applyFWRules(network, rules);
- if (handled)
- break;
- }
- case PortForwarding:
- for (PortForwardingServiceProvider element: _pfElements) {
++ boolean handled = false;
++ switch (purpose){
++ case Firewall:
++ for (FirewallServiceProvider fwElement: _firewallElements) {
++ handled = fwElement.applyFWRules(network, rules);
++ if (handled)
++ break;
++ }
++ case PortForwarding:
++ for (PortForwardingServiceProvider element: _pfElements) {
+ handled = element.applyPFRules(network, (List<PortForwardingRule>) rules);
+ if (handled)
+ break;
+ }
- break;
- case StaticNat:
++ break;
++ case StaticNat:
+ for (StaticNatServiceProvider element: _staticNatElements) {
+ handled = element.applyStaticNats(network, (List<? extends StaticNat>) rules);
+ if (handled)
+ break;
+ }
+ break;
- case NetworkACL:
++ case NetworkACL:
+ for (NetworkACLServiceProvider element: _networkAclElements) {
- handled = element.applyNetworkACLs(network, (List<? extends FirewallRule>) rules);
++ handled = element.applyNetworkACLs(network, rules);
+ if (handled)
+ break;
+ }
+ break;
- default:
- assert(false): "Unexpected fall through in applying rules to the network elements";
- s_logger.error("FirewallManager cannot process rules of type " + purpose);
- throw new CloudRuntimeException("FirewallManager cannot process rules of type " + purpose);
- }
- return handled;
++ default:
++ assert(false): "Unexpected fall through in applying rules to the network elements";
++ s_logger.error("FirewallManager cannot process rules of type " + purpose);
++ throw new CloudRuntimeException("FirewallManager cannot process rules of type " + purpose);
++ }
++ return handled;
+ }
-
++
+ @Override
public void removeRule(FirewallRule rule) {
//remove the rule
@@@ -607,7 -674,7 +670,7 @@@
@Override
public FirewallRule createRuleForAllCidrs(long ipAddrId, Account caller,
Integer startPort, Integer endPort, String protocol, Integer icmpCode, Integer icmpType, Long relatedRuleId, long networkId)
-- throws NetworkRuleConflictException {
++ throws NetworkRuleConflictException {
// If firwallRule for this port range already exists, return it
List<FirewallRuleVO> rules = _firewallDao.listByIpPurposeAndProtocolAndNotRevoked(ipAddrId, startPort, endPort,
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/10d9c019/server/src/com/cloud/network/guru/ControlNetworkGuru.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/guru/ControlNetworkGuru.java
index 3132ffd,ef80522..d095e34
--- a/server/src/com/cloud/network/guru/ControlNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/ControlNetworkGuru.java
@@@ -45,7 -44,8 +45,6 @@@ import com.cloud.network.Networks.Mode
import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
-
-import com.cloud.utils.component.ComponentLocator;
-import com.cloud.utils.component.Inject;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.Nic;
@@@ -58,35 -58,34 +57,35 @@@ import com.cloud.vm.VirtualMachineProfi
public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGuru {
private static final Logger s_logger = Logger.getLogger(ControlNetworkGuru.class);
@Inject DataCenterDao _dcDao;
- @Inject NetworkManager _networkMgr;
+ @Inject ConfigurationDao _configDao;
+ @Inject NetworkModel _networkMgr;
String _cidr;
String _gateway;
--
++
private static final TrafficType[] _trafficTypes = {TrafficType.Control};
--
++
@Override
public boolean isMyTrafficType(TrafficType type) {
-- for (TrafficType t : _trafficTypes) {
-- if (t == type) {
-- return true;
-- }
-- }
-- return false;
++ for (TrafficType t : _trafficTypes) {
++ if (t == type) {
++ return true;
++ }
++ }
++ return false;
}
--
++
@Override
public TrafficType[] getSupportedTrafficType() {
-- return _trafficTypes;
++ return _trafficTypes;
}
--
++
protected boolean canHandle(NetworkOffering offering) {
-- if (offering.isSystemOnly() && isMyTrafficType(offering.getTrafficType())) {
-- return true;
-- } else {
-- s_logger.trace("We only care about System only Control network");
-- return false;
-- }
++ if (offering.isSystemOnly() && isMyTrafficType(offering.getTrafficType())) {
++ return true;
++ } else {
++ s_logger.trace("We only care about System only Control network");
++ return false;
++ }
}
@Override
@@@ -94,67 -93,67 +93,67 @@@
if (!canHandle(offering)) {
return null;
}
--
++
NetworkVO config = new NetworkVO(offering.getTrafficType(), Mode.Static, BroadcastDomainType.LinkLocal, offering.getId(), Network.State.Setup, plan.getDataCenterId(), plan.getPhysicalNetworkId());
config.setCidr(_cidr);
config.setGateway(_gateway);
--
++
return config;
}
--
++
protected ControlNetworkGuru() {
super();
}
--
++
@Override
public NicProfile allocate(Network config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException,
-- InsufficientAddressCapacityException {
--
++ InsufficientAddressCapacityException {
++
if(vm.getHypervisorType() == HypervisorType.VMware && vm.getType() != VirtualMachine.Type.DomainRouter) {
-- NicProfile nicProf = new NicProfile(Nic.ReservationStrategy.Create, null, null, null, null);
++ NicProfile nicProf = new NicProfile(Nic.ReservationStrategy.Create, null, null, null, null);
String mac = _networkMgr.getNextAvailableMacAddressInNetwork(config.getId());
nicProf.setMacAddress(mac);
return nicProf;
}
--
++
if (nic != null) {
throw new CloudRuntimeException("Does not support nic specification at this time: " + nic);
}
--
++
return new NicProfile(Nic.ReservationStrategy.Start, null, null, null, null);
}
--
++
@Override
public void deallocate(Network config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) {
}
@Override
public void reserve(NicProfile nic, Network config, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException,
-- InsufficientAddressCapacityException {
++ InsufficientAddressCapacityException {
assert nic.getTrafficType() == TrafficType.Control;
if (dest.getHost().getHypervisorType() == HypervisorType.VMware && vm.getType() == VirtualMachine.Type.DomainRouter) {
-- if(dest.getDataCenter().getNetworkType() != NetworkType.Basic) {
-- super.reserve(nic, config, vm, dest, context);
--
-- String mac = _networkMgr.getNextAvailableMacAddressInNetwork(config.getId());
-- nic.setMacAddress(mac);
-- return;
-- } else {
-- // in basic mode and in VMware case, control network will be shared with guest network
-- String mac = _networkMgr.getNextAvailableMacAddressInNetwork(config.getId());
-- nic.setMacAddress(mac);
-- nic.setIp4Address("0.0.0.0");
-- nic.setNetmask("0.0.0.0");
-- nic.setFormat(AddressFormat.Ip4);
-- nic.setGateway("0.0.0.0");
-- return;
-- }
++ if(dest.getDataCenter().getNetworkType() != NetworkType.Basic) {
++ super.reserve(nic, config, vm, dest, context);
++
++ String mac = _networkMgr.getNextAvailableMacAddressInNetwork(config.getId());
++ nic.setMacAddress(mac);
++ return;
++ } else {
++ // in basic mode and in VMware case, control network will be shared with guest network
++ String mac = _networkMgr.getNextAvailableMacAddressInNetwork(config.getId());
++ nic.setMacAddress(mac);
++ nic.setIp4Address("0.0.0.0");
++ nic.setNetmask("0.0.0.0");
++ nic.setFormat(AddressFormat.Ip4);
++ nic.setGateway("0.0.0.0");
++ return;
++ }
}
--
++
String ip = _dcDao.allocateLinkLocalIpAddress(dest.getDataCenter().getId(), dest.getPod().getId(), nic.getId(), context.getReservationId());
if (ip == null) {
-- throw new InsufficientAddressCapacityException("Insufficient link local address capacity", DataCenter.class, dest.getDataCenter().getId());
++ throw new InsufficientAddressCapacityException("Insufficient link local address capacity", DataCenter.class, dest.getDataCenter().getId());
}
nic.setIp4Address(ip);
nic.setMacAddress(NetUtils.long2Mac(NetUtils.ip2Long(ip) | (14l << 40)));
@@@ -168,30 -167,30 +167,30 @@@
assert nic.getTrafficType() == TrafficType.Control;
if (vm.getHypervisorType() == HypervisorType.VMware && vm.getType() == VirtualMachine.Type.DomainRouter) {
-- long dcId = vm.getVirtualMachine().getDataCenterIdToDeployIn();
-- DataCenterVO dcVo = _dcDao.findById(dcId);
-- if(dcVo.getNetworkType() != NetworkType.Basic) {
-- super.release(nic, vm, reservationId);
-- if (s_logger.isDebugEnabled()) {
-- s_logger.debug("Released nic: " + nic);
-- }
-- return true;
-- } else {
++ long dcId = vm.getVirtualMachine().getDataCenterIdToDeployIn();
++ DataCenterVO dcVo = _dcDao.findById(dcId);
++ if(dcVo.getNetworkType() != NetworkType.Basic) {
++ super.release(nic, vm, reservationId);
++ if (s_logger.isDebugEnabled()) {
++ s_logger.debug("Released nic: " + nic);
++ }
++ return true;
++ } else {
nic.deallocate();
if (s_logger.isDebugEnabled()) {
s_logger.debug("Released nic: " + nic);
}
-- return true;
-- }
++ return true;
++ }
}
--
++
_dcDao.releaseLinkLocalIpAddress(nic.getId(), reservationId);
--
++
nic.deallocate();
if (s_logger.isDebugEnabled()) {
s_logger.debug("Released nic: " + nic);
}
--
++
return true;
}
@@@ -200,30 -199,33 +199,30 @@@
assert config.getTrafficType() == TrafficType.Control : "Why are you sending this configuration to me " + config;
return config;
}
--
++
@Override
public void shutdown(NetworkProfile config, NetworkOffering offering) {
assert false : "Destroying a link local...Either you're out of your mind or something has changed.";
}
--
++
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
super.configure(name, params);
--
- ComponentLocator locator = ComponentLocator.getCurrentLocator();
-
- ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
- Map<String, String> dbParams = configDao.getConfiguration(params);
-
++
+ Map<String, String> dbParams = _configDao.getConfiguration(params);
-
++
_cidr = dbParams.get(Config.ControlCidr);
if (_cidr == null) {
_cidr = "169.254.0.0/16";
}
--
++
_gateway = dbParams.get(Config.ControlGateway);
if (_gateway == null) {
_gateway = NetUtils.getLinkLocalGateway();
}
--
++
s_logger.info("Control network setup: cidr=" + _cidr + "; gateway = " + _gateway);
--
++
return true;
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/10d9c019/server/src/com/cloud/network/guru/DirectNetworkGuru.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/10d9c019/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/10d9c019/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/10d9c019/server/src/com/cloud/network/guru/GuestNetworkGuru.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/10d9c019/server/src/com/cloud/network/guru/PrivateNetworkGuru.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/10d9c019/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
index 0ffdcea,dfd5232..e52f63a
--- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
+++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
@@@ -28,17 -28,15 +28,19 @@@ import java.util.Map
import java.util.Set;
import javax.ejb.Local;
+import javax.inject.Inject;
import javax.naming.ConfigurationException;
--import org.apache.cloudstack.api.command.user.loadbalancer.*;
--import org.apache.log4j.Logger;
- import org.springframework.stereotype.Component;
--
import org.apache.cloudstack.api.command.user.loadbalancer.CreateLBStickinessPolicyCmd;
++import org.apache.cloudstack.api.command.user.loadbalancer.CreateLoadBalancerRuleCmd;
++import org.apache.cloudstack.api.command.user.loadbalancer.ListLBStickinessPoliciesCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.ListLoadBalancerRuleInstancesCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.ListLoadBalancerRulesCmd;
++import org.apache.cloudstack.api.command.user.loadbalancer.UpdateLoadBalancerRuleCmd;
import org.apache.cloudstack.api.response.ServiceResponse;
++import org.apache.log4j.Logger;
++import org.springframework.stereotype.Component;
++
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.dao.ConfigurationDao;
@@@ -92,6 -92,8 +96,7 @@@ import com.cloud.network.dao.LoadBalanc
import com.cloud.network.dao.LoadBalancerVMMapDao;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkServiceMapDao;
+ import com.cloud.network.element.LoadBalancingServiceProvider;
-import com.cloud.network.element.NetworkElement;
import com.cloud.network.lb.LoadBalancingRule.LbAutoScalePolicy;
import com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup;
import com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmProfile;
@@@ -144,9 -147,8 +148,9 @@@ import com.cloud.vm.dao.UserVmDao
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
+@Component
@Local(value = { LoadBalancingRulesManager.class, LoadBalancingRulesService.class })
- public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesManager, LoadBalancingRulesService, Manager {
+ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesManager, LoadBalancingRulesService, NetworkRuleApplier, Manager {
private static final Logger s_logger = Logger.getLogger(LoadBalancingRulesManagerImpl.class);
String _name;
@@@ -191,11 -195,10 +197,10 @@@
DomainService _domainMgr;
@Inject
ConfigurationManager _configMgr;
- @Inject
- TemplateManager _templateMgr;
-
++
@Inject
ExternalLoadBalancerUsageManager _externalLBUsageMgr;
- @Inject
+ @Inject
NetworkServiceMapDao _ntwkSrvcDao;
@Inject
ResourceTagDao _resourceTagDao;
@@@ -225,7 -228,8 +230,7 @@@
DataCenterDao _dcDao = null;
@Inject
UserDao _userDao;
-
- @Inject(adapter = LoadBalancingServiceProvider.class)
- Adapters<LoadBalancingServiceProvider> _lbProviders;
++ @Inject List<LoadBalancingServiceProvider> _lbProviders;
// Will return a string. For LB Stickiness this will be a json, for autoscale this will be "," separated values
@Override
@@@ -493,15 -497,31 +498,31 @@@
return policy;
}
-
++
+ private boolean validateRule(LoadBalancingRule lbRule) {
+ Network network = _networkDao.findById(lbRule.getNetworkId());
+ Purpose purpose = lbRule.getPurpose();
+ if (purpose != Purpose.LoadBalancing) {
+ s_logger.debug("Unable to validate network rules for purpose: " + purpose.toString());
+ return false;
+ }
+ for (LoadBalancingServiceProvider ne : _lbProviders) {
+ boolean validated = ne.validateLBRule(network, lbRule);
+ if (!validated)
+ return false;
+ }
+ return true;
+ }
-
++
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_LB_STICKINESSPOLICY_CREATE, eventDescription = "Apply Stickinesspolicy to load balancer ", async = true)
public boolean applyLBStickinessPolicy(CreateLBStickinessPolicyCmd cmd) {
boolean success = true;
-
+
LoadBalancerVO loadBalancer = _lbDao.findById(cmd.getLbRuleId());
if (loadBalancer == null) {
- throw new InvalidParameterException("Invalid Load balancer Id:" + cmd.getLbRuleId());
+ throw new InvalidParameterException("Invalid Load balancer Id:" + cmd.getLbRuleId());
}
FirewallRule.State backupState = loadBalancer.getState();
loadBalancer.setState(FirewallRule.State.Add);
@@@ -614,8 -634,8 +635,8 @@@
UserVm vm = _vmDao.findById(instanceId);
if (vm == null || vm.getState() == State.Destroyed || vm.getState() == State.Expunging) {
- InvalidParameterValueException ex = new InvalidParameterValueException("Invalid instance id specified");
- ex.addProxyObject(vm, instanceId, "instanceId");
+ InvalidParameterValueException ex = new InvalidParameterValueException("Invalid instance id specified");
- ex.addProxyObject(vm, instanceId, "instanceId");
++ ex.addProxyObject(vm, instanceId, "instanceId");
throw ex;
}
@@@ -636,8 -656,8 +657,8 @@@
}
if (nicInSameNetwork == null) {
- InvalidParameterValueException ex = new InvalidParameterValueException("VM " + instanceId + " cannot be added because it doesn't belong in the same network.");
- ex.addProxyObject(vm, instanceId, "instanceId");
+ InvalidParameterValueException ex = new InvalidParameterValueException("VM " + instanceId + " cannot be added because it doesn't belong in the same network.");
- ex.addProxyObject(vm, instanceId, "instanceId");
++ ex.addProxyObject(vm, instanceId, "instanceId");
throw ex;
}
@@@ -685,11 -705,11 +706,11 @@@
}
s_logger.warn("Unable to apply the load balancer config because resource is unavaliable.", e);
}
-
+
if (!success) {
- CloudRuntimeException ex = new CloudRuntimeException("Failed to add specified loadbalancerruleid for vms " + instanceIds);
- ex.addProxyObject(loadBalancer, loadBalancerId, "loadBalancerId");
+ CloudRuntimeException ex = new CloudRuntimeException("Failed to add specified loadbalancerruleid for vms " + instanceIds);
- ex.addProxyObject(loadBalancer, loadBalancerId, "loadBalancerId");
- // TBD: Also pack in the instanceIds in the exception using the right VO object or table name.
++ ex.addProxyObject(loadBalancer, loadBalancerId, "loadBalancerId");
+ // TBD: Also pack in the instanceIds in the exception using the right VO object or table name.
throw ex;
}
@@@ -757,10 -777,10 +778,10 @@@
s_logger.warn("Unable to apply the load balancer config because resource is unavaliable.", e);
}
if (!success) {
- CloudRuntimeException ex = new CloudRuntimeException("Failed to remove specified load balancer rule id for vms " + instanceIds);
- ex.addProxyObject(loadBalancer, loadBalancerId, "loadBalancerId");
+ CloudRuntimeException ex = new CloudRuntimeException("Failed to remove specified load balancer rule id for vms " + instanceIds);
- ex.addProxyObject(loadBalancer, loadBalancerId, "loadBalancerId");
++ ex.addProxyObject(loadBalancer, loadBalancerId, "loadBalancerId");
throw ex;
- }
+ }
return success;
}
@@@ -940,8 -960,8 +961,8 @@@
if (ipAddrId != null) {
ipVO = _ipAddressDao.findById(ipAddrId);
}
--
- Network network = _networkMgr.getNetwork(lb.getNetworkId());
++
+ Network network = _networkModel.getNetwork(lb.getNetworkId());
// FIXME: breaking the dependency on ELB manager. This breaks functionality of ELB using virtual router
// Bug CS-15411 opened to document this
@@@ -955,31 -975,31 +976,31 @@@
lb.setSourceIpAddressId(systemIp.getId());
ipVO = _ipAddressDao.findById(systemIp.getId());
}
--
++
// Validate ip address
if (ipVO == null) {
throw new InvalidParameterValueException("Unable to create load balance rule; can't find/allocate source IP");
} else if (ipVO.isOneToOneNat()) {
throw new NetworkRuleConflictException("Can't do load balance on ip address: " + ipVO.getAddress());
}
--
++
boolean performedIpAssoc = false;
try {
if (ipVO.getAssociatedWithNetworkId() == null) {
boolean assignToVpcNtwk = network.getVpcId() != null
- && ipVO.getVpcId() != null && ipVO.getVpcId().longValue() == network.getVpcId();
+ && ipVO.getVpcId() != null && ipVO.getVpcId().longValue() == network.getVpcId();
if (assignToVpcNtwk) {
//set networkId just for verification purposes
- _networkMgr.checkIpForService(ipVO, Service.Lb, lb.getNetworkId());
+ _networkModel.checkIpForService(ipVO, Service.Lb, lb.getNetworkId());
s_logger.debug("The ip is not associated with the VPC network id="+ lb.getNetworkId() + " so assigning");
ipVO = _networkMgr.associateIPToGuestNetwork(ipAddrId, lb.getNetworkId(), false);
performedIpAssoc = true;
}
} else {
- _networkMgr.checkIpForService(ipVO, Service.Lb, null);
+ _networkModel.checkIpForService(ipVO, Service.Lb, null);
}
--
++
if (ipVO.getAssociatedWithNetworkId() == null) {
throw new InvalidParameterValueException("Ip address " + ipVO + " is not assigned to the network " + network);
}
@@@ -1025,12 -1045,12 +1046,12 @@@
IPAddressVO ipAddr = _ipAddressDao.findById(sourceIpId);
// make sure ip address exists
if (ipAddr == null || !ipAddr.readyToUse()) {
- InvalidParameterValueException ex = new InvalidParameterValueException("Unable to create load balancer rule, invalid IP address id specified");
- ex.addProxyObject(ipAddr, sourceIpId, "sourceIpId");
+ InvalidParameterValueException ex = new InvalidParameterValueException("Unable to create load balancer rule, invalid IP address id specified");
- ex.addProxyObject(ipAddr, sourceIpId, "sourceIpId");
++ ex.addProxyObject(ipAddr, sourceIpId, "sourceIpId");
throw ex;
} else if (ipAddr.isOneToOneNat()) {
- InvalidParameterValueException ex = new InvalidParameterValueException("Unable to create load balancer rule; specified sourceip id has static nat enabled");
- ex.addProxyObject(ipAddr, sourceIpId, "sourceIpId");
+ InvalidParameterValueException ex = new InvalidParameterValueException("Unable to create load balancer rule; specified sourceip id has static nat enabled");
- ex.addProxyObject(ipAddr, sourceIpId, "sourceIpId");
++ ex.addProxyObject(ipAddr, sourceIpId, "sourceIpId");
throw ex;
}
@@@ -1039,8 -1059,8 +1060,8 @@@
Long networkId = ipAddr.getAssociatedWithNetworkId();
if (networkId == null) {
- InvalidParameterValueException ex = new InvalidParameterValueException("Unable to create load balancer rule ; specified sourceip id is not associated with any network");
- ex.addProxyObject(ipAddr, sourceIpId, "sourceIpId");
+ InvalidParameterValueException ex = new InvalidParameterValueException("Unable to create load balancer rule ; specified sourceip id is not associated with any network");
- ex.addProxyObject(ipAddr, sourceIpId, "sourceIpId");
++ ex.addProxyObject(ipAddr, sourceIpId, "sourceIpId");
throw ex;
}
@@@ -1049,9 -1069,9 +1070,9 @@@
_accountMgr.checkAccess(caller.getCaller(), null, true, ipAddr);
// verify that lb service is supported by the network
- if (!_networkMgr.areServicesSupportedInNetwork(network.getId(), Service.Lb)) {
- InvalidParameterValueException ex = new InvalidParameterValueException("LB service is not supported in specified network id");
- ex.addProxyObject(network, networkId, "networkId");
+ if (!_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Lb)) {
+ InvalidParameterValueException ex = new InvalidParameterValueException("LB service is not supported in specified network id");
- ex.addProxyObject(network, networkId, "networkId");
++ ex.addProxyObject(network, networkId, "networkId");
throw ex;
}
@@@ -1063,10 -1083,10 +1084,10 @@@
// verify rule is supported by Lb provider of the network
LoadBalancingRule loadBalancing = new LoadBalancingRule(newRule, new ArrayList<LbDestination>(), new ArrayList<LbStickinessPolicy>());
- if (!_networkMgr.validateRule(loadBalancing)) {
+ if (!validateRule(loadBalancing)) {
throw new InvalidParameterValueException("LB service provider cannot support this rule");
}
--
++
newRule = _lbDao.persist(newRule);
if (openFirewall) {
@@@ -1130,7 -1150,20 +1151,20 @@@
return true;
}
}
-
+
+ @Override
+ public boolean applyRules(Network network, Purpose purpose, List<? extends FirewallRule> rules)
+ throws ResourceUnavailableException {
+ assert(purpose == Purpose.LoadBalancing): "LB Manager asked to handle non-LB rules";
+ boolean handled = false;
+ for (LoadBalancingServiceProvider lbElement: _lbProviders) {
- handled = lbElement.applyLBRules(network, (List<LoadBalancingRule>) rules);
- if (handled)
- break;
++ handled = lbElement.applyLBRules(network, (List<LoadBalancingRule>) rules);
++ if (handled)
++ break;
+ }
+ return handled;
+ }
+
@DB
protected boolean applyLoadBalancerRules(List<LoadBalancerVO> lbs, boolean updateRulesInDB) throws ResourceUnavailableException {
Transaction txn = Transaction.currentTxn();
@@@ -1580,4 -1613,6 +1614,6 @@@
//remove the rule
_lbDao.remove(rule.getId());
}
-
-
++
++
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/10d9c019/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index 255a1af,e1c78e1..2f625cc
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@@ -1377,9 -1385,9 +1380,9 @@@ public class VirtualNetworkApplianceMan
// 1) Get deployment plan and find out the list of routers
boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic ||
- _networkMgr.areServicesSupportedInNetwork(guestNetwork.getId(), Service.SecurityGroup))
+ _networkModel.areServicesSupportedInNetwork(guestNetwork.getId(), Service.SecurityGroup))
&& guestNetwork.getTrafficType() == TrafficType.Guest;
-
+
// dest has pod=null, for Basic Zone findOrDeployVRs for all Pods
List<DeployDestination> destinations = new ArrayList<DeployDestination>();
@@@ -1418,88 -1426,72 +1421,72 @@@
// Except for Basic Zone, the for loop will iterate only once
for (DeployDestination destination: destinations) {
Pair<DeploymentPlan, List<DomainRouterVO>> planAndRouters = getDeploymentPlanAndRouters(isPodBased, destination, guestNetwork.getId());
- routers = planAndRouters.second();
-
- // 2) Figure out required routers count
- int routerCount = 1;
- if (isRedundant) {
- routerCount = 2;
- }
-
+ routers = planAndRouters.second();
+
+ // 2) Figure out required routers count
+ int routerCount = 1;
+ if (isRedundant) {
+ routerCount = 2;
+ }
+
// If old network is redundant but new is single router, then routers.size() = 2 but routerCount = 1
- if (routers.size() >= routerCount) {
- return routers;
- }
-
- if (routers.size() >= 5) {
- s_logger.error("Too much redundant routers!");
- }
+ if (routers.size() >= routerCount) {
+ return routers;
+ }
+
+ if (routers.size() >= 5) {
+ s_logger.error("Too much redundant routers!");
+ }
- // Check if providers are supported in the physical networks
- VirtualRouterProviderType type = VirtualRouterProviderType.VirtualRouter;
+ // Check if providers are supported in the physical networks
+ VirtualRouterProviderType type = VirtualRouterProviderType.VirtualRouter;
- Long physicalNetworkId = _networkMgr.getPhysicalNetworkId(guestNetwork);
+ Long physicalNetworkId = _networkModel.getPhysicalNetworkId(guestNetwork);
- PhysicalNetworkServiceProvider provider = _physicalProviderDao.findByServiceProvider(physicalNetworkId, type.toString());
- if (provider == null) {
- throw new CloudRuntimeException("Cannot find service provider " + type.toString() + " in physical network " + physicalNetworkId);
- }
- VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), type);
- if (vrProvider == null) {
+ PhysicalNetworkServiceProvider provider = _physicalProviderDao.findByServiceProvider(physicalNetworkId, type.toString());
+ if (provider == null) {
+ throw new CloudRuntimeException("Cannot find service provider " + type.toString() + " in physical network " + physicalNetworkId);
+ }
+ VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), type);
+ if (vrProvider == null) {
throw new CloudRuntimeException("Cannot find virtual router provider " + type.toString() + " as service provider " + provider.getId());
- }
+ }
- if (_networkMgr.isNetworkSystem(guestNetwork) || guestNetwork.getGuestType() == Network.GuestType.Shared) {
+ if (_networkModel.isNetworkSystem(guestNetwork) || guestNetwork.getGuestType() == Network.GuestType.Shared) {
- owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
- }
+ owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
+ }
// Check if public network has to be set on VR
- boolean publicNetwork = false;
+ boolean publicNetwork = false;
- if (_networkMgr.isProviderSupportServiceInNetwork(guestNetwork.getId(), Service.SourceNat, Provider.VirtualRouter)) {
+ if (_networkModel.isProviderSupportServiceInNetwork(guestNetwork.getId(), Service.SourceNat, Provider.VirtualRouter)) {
- publicNetwork = true;
- }
- if (isRedundant && !publicNetwork) {
- s_logger.error("Didn't support redundant virtual router without public network!");
- return null;
- }
+ publicNetwork = true;
+ }
+ if (isRedundant && !publicNetwork) {
+ s_logger.error("Didn't support redundant virtual router without public network!");
+ return null;
+ }
- Long offeringId = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId()).getServiceOfferingId();
- if (offeringId == null) {
- offeringId = _offering.getId();
- }
+ Long offeringId = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId()).getServiceOfferingId();
+ if (offeringId == null) {
+ offeringId = _offering.getId();
+ }
- // 3) deploy virtual router(s)
- int count = routerCount - routers.size();
- DeploymentPlan plan = planAndRouters.first();
- for (int i = 0; i < count; i++) {
- PublicIp sourceNatIp = null;
- if (publicNetwork) {
- sourceNatIp = _networkMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork);
- }
+ PublicIp sourceNatIp = null;
+ if (publicNetwork) {
- int failCount = 0;
- // Generate different MAC for VR
- while (sourceNatIp == null) {
+ sourceNatIp = _networkMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork);
- NicVO nic = _nicDao.findByMacAddress(sourceNatIp.getMacAddress());
- // We got duplicate MAC here, so regenerate the mac
- if (nic != null) {
- s_logger.debug("Failed to find a different mac for redundant router. Try again. The current mac is " + sourceNatIp.getMacAddress());
- sourceNatIp = null;
- failCount ++;
- }
- //Prevent infinite loop
- if (failCount > 3) {
- s_logger.error("Failed to find a different mac for redundant router! Abort operation!");
- throw new InsufficientAddressCapacityException("Failed to find a different mac for redundant router", null, offeringId);
- }
- }
+ }
+ // 3) deploy virtual router(s)
+ int count = routerCount - routers.size();
+ DeploymentPlan plan = planAndRouters.first();
+ for (int i = 0; i < count; i++) {
- List<Pair<NetworkVO, NicProfile>> networks = createRouterNetworks(owner, isRedundant, plan, guestNetwork,
- new Pair<Boolean, PublicIp>(publicNetwork, sourceNatIp));
- //don't start the router as we are holding the network lock that needs to be released at the end of router allocation
+ List<Pair<NetworkVO, NicProfile>> networks = createRouterNetworks(owner, isRedundant, plan, guestNetwork,
+ new Pair<Boolean, PublicIp>(publicNetwork, sourceNatIp));
+ //don't start the router as we are holding the network lock that needs to be released at the end of router allocation
DomainRouterVO router = deployRouter(owner, destination, plan, params, isRedundant, vrProvider, offeringId,
- null, networks, false, null);
+ null, networks, false, null);
- _routerDao.addRouterToGuestNetwork(router, guestNetwork);
- routers.add(router);
- }
+ _routerDao.addRouterToGuestNetwork(router, guestNetwork);
+ routers.add(router);
+ }
}
} finally {
if (lock != null) {
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/10d9c019/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/10d9c019/server/src/com/cloud/network/rules/RulesManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/rules/RulesManagerImpl.java
index 9f67e05,fc12660..e4f4735
--- a/server/src/com/cloud/network/rules/RulesManagerImpl.java
+++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java
@@@ -81,13 -64,13 +82,8 @@@ import com.cloud.vm.VirtualMachine
import com.cloud.vm.VirtualMachine.Type;
import com.cloud.vm.dao.NicDao;
import com.cloud.vm.dao.UserVmDao;
- import org.apache.log4j.Logger;
-
- import javax.ejb.Local;
- import javax.naming.ConfigurationException;
- import java.util.*;
-import org.apache.cloudstack.api.command.user.firewall.ListPortForwardingRulesCmd;
-import org.apache.log4j.Logger;
-
-import javax.ejb.Local;
-import javax.naming.ConfigurationException;
-import java.util.*;
+@Component
@Local(value = { RulesManager.class, RulesService.class })
public class RulesManagerImpl implements RulesManager, RulesService, Manager {
private static final Logger s_logger = Logger.getLogger(RulesManagerImpl.class);
@@@ -189,9 -174,9 +187,9 @@@
} else if (ipAddress.isOneToOneNat()) {
throw new InvalidParameterValueException("Unable to create port forwarding rule; ip id=" + ipAddrId + " has static nat enabled");
}
--
++
Long networkId = rule.getNetworkId();
- Network network = _networkMgr.getNetwork(networkId);
+ Network network = _networkModel.getNetwork(networkId);
//associate ip address to network (if needed)
boolean performedIpAssoc = false;
if (ipAddress.getAssociatedWithNetworkId() == null) {
@@@ -210,13 -195,13 +208,13 @@@
}
}
} else {
- _networkMgr.checkIpForService(ipAddress, Service.PortForwarding, null);
+ _networkModel.checkIpForService(ipAddress, Service.PortForwarding, null);
}
--
++
if (ipAddress.getAssociatedWithNetworkId() == null) {
throw new InvalidParameterValueException("Ip address " + ipAddress + " is not assigned to the network " + network);
}
--
++
try {
_firewallMgr.validateFirewallRule(caller, ipAddress, rule.getSourcePortStart(), rule.getSourcePortEnd(),
rule.getProtocol(), Purpose.PortForwarding, FirewallRuleType.User);
@@@ -252,20 -237,20 +250,20 @@@
} else {
dstIp = new Ip(guestNic.getIp4Address());
}
--
++
//if start port and end port are passed in, and they are not equal to each other, perform the validation
boolean validatePortRange = false;
if (rule.getSourcePortStart().intValue() != rule.getSourcePortEnd().intValue()
|| rule.getDestinationPortStart() != rule.getDestinationPortEnd()) {
validatePortRange = true;
}
--
++
if (validatePortRange) {
//source start port and source dest port should be the same. The same applies to dest ports
if (rule.getSourcePortStart().intValue() != rule.getDestinationPortStart()) {
throw new InvalidParameterValueException("Private port start should be equal to public port start");
}
--
++
if (rule.getSourcePortEnd().intValue() != rule.getDestinationPortEnd()) {
throw new InvalidParameterValueException("Private port end should be equal to public port end");
}
@@@ -308,7 -293,7 +306,7 @@@
if (e instanceof NetworkRuleConflictException) {
throw (NetworkRuleConflictException) e;
}
--
++
throw new CloudRuntimeException("Unable to add rule for the ip id=" + ipAddrId, e);
}
} finally {
@@@ -420,19 -405,19 +418,19 @@@
if (network == null) {
throw new InvalidParameterValueException("Unable to find network by id");
}
--
++
// Check that vm has a nic in the network
- Nic guestNic = _networkMgr.getNicInNetwork(vmId, networkId);
+ Nic guestNic = _networkModel.getNicInNetwork(vmId, networkId);
if (guestNic == null) {
throw new InvalidParameterValueException("Vm doesn't belong to the network with specified id");
}
--
- if (!_networkMgr.areServicesSupportedInNetwork(network.getId(), Service.StaticNat)) {
++
+ if (!_networkModel.areServicesSupportedInNetwork(network.getId(), Service.StaticNat)) {
throw new InvalidParameterValueException("Unable to create static nat rule; StaticNat service is not " +
"supported in network with specified id");
}
--
++
if (!isSystemVm) {
UserVmVO vm = _vmDao.findById(vmId);
if (vm == null) {
@@@ -444,8 -429,8 +442,8 @@@
boolean assignToVpcNtwk = network.getVpcId() != null
&& ipAddress.getVpcId() != null && ipAddress.getVpcId().longValue() == network.getVpcId();
if (assignToVpcNtwk) {
- _networkMgr.checkIpForService(ipAddress, Service.StaticNat, networkId);
-
+ _networkModel.checkIpForService(ipAddress, Service.StaticNat, networkId);
-
++
s_logger.debug("The ip is not associated with the VPC network id="+ networkId + ", so assigning");
try {
ipAddress = _networkMgr.associateIPToGuestNetwork(ipId, networkId, false);
@@@ -457,20 -442,20 +455,20 @@@
performedIpAssoc = true;
}
} else {
- _networkMgr.checkIpForService(ipAddress, Service.StaticNat, null);
+ _networkModel.checkIpForService(ipAddress, Service.StaticNat, null);
}
--
++
if (ipAddress.getAssociatedWithNetworkId() == null) {
throw new InvalidParameterValueException("Ip address " + ipAddress + " is not assigned to the network " + network);
}
// Check permissions
checkIpAndUserVm(ipAddress, vm, caller);
--
++
// Verify ip address parameter
isIpReadyForStaticNat(vmId, ipAddress, caller, ctx.getCallerUserId());
}
--
++
ipAddress.setOneToOneNat(true);
ipAddress.setAssociatedWithVmId(vmId);
@@@ -484,14 -469,14 +482,14 @@@
}
} else {
s_logger.warn("Failed to update ip address " + ipAddress + " in the DB as a part of enableStaticNat");
--
++
}
} finally {
if (!result) {
ipAddress.setOneToOneNat(false);
ipAddress.setAssociatedWithVmId(null);
_ipAddressDao.update(ipAddress.getId(), ipAddress);
--
++
if (performedIpAssoc) {
//if the rule is the last one for the ip address assigned to VPC, unassign it from the network
IpAddress ip = _ipAddressDao.findById(ipAddress.getId());
@@@ -1174,15 -1159,15 +1172,15 @@@
checkIpAndUserVm(ipAddress, null, caller);
if (ipAddress.getSystem()) {
-- InvalidParameterValueException ex = new InvalidParameterValueException("Can't disable static nat for system IP address with specified id");
-- ex.addProxyObject(ipAddress, ipId, "ipId");
++ InvalidParameterValueException ex = new InvalidParameterValueException("Can't disable static nat for system IP address with specified id");
++ ex.addProxyObject(ipAddress, ipId, "ipId");
throw ex;
}
Long vmId = ipAddress.getAssociatedWithVmId();
if (vmId == null) {
-- InvalidParameterValueException ex = new InvalidParameterValueException("Specified IP address id is not associated with any vm Id");
-- ex.addProxyObject(ipAddress, ipId, "ipId");
++ InvalidParameterValueException ex = new InvalidParameterValueException("Specified IP address id is not associated with any vm Id");
++ ex.addProxyObject(ipAddress, ipId, "ipId");
throw ex;
}
@@@ -1208,8 -1192,8 +1205,8 @@@
long networkId = ipAddress.getAssociatedWithNetworkId();
if (!ipAddress.isOneToOneNat()) {
-- InvalidParameterValueException ex = new InvalidParameterValueException("One to one nat is not enabled for the specified ip id");
-- ex.addProxyObject(ipAddress, ipId, "ipId");
++ InvalidParameterValueException ex = new InvalidParameterValueException("One to one nat is not enabled for the specified ip id");
++ ex.addProxyObject(ipAddress, ipId, "ipId");
throw ex;
}
@@@ -1268,16 -1252,16 +1265,16 @@@
FirewallRuleVO ruleVO = _firewallDao.findById(rule.getId());
if (ip == null || !ip.isOneToOneNat() || ip.getAssociatedWithVmId() == null) {
-- InvalidParameterValueException ex = new InvalidParameterValueException("Source ip address of the specified firewall rule id is not static nat enabled");
-- ex.addProxyObject(ruleVO, rule.getId(), "ruleId");
++ InvalidParameterValueException ex = new InvalidParameterValueException("Source ip address of the specified firewall rule id is not static nat enabled");
++ ex.addProxyObject(ruleVO, rule.getId(), "ruleId");
throw ex;
}
--
++
String dstIp;
if (forRevoke) {
- dstIp = _networkMgr.getIpInNetworkIncludingRemoved(ip.getAssociatedWithVmId(), rule.getNetworkId());
+ dstIp = _networkModel.getIpInNetworkIncludingRemoved(ip.getAssociatedWithVmId(), rule.getNetworkId());
} else {
- dstIp = _networkMgr.getIpInNetwork(ip.getAssociatedWithVmId(), rule.getNetworkId());
+ dstIp = _networkModel.getIpInNetwork(ip.getAssociatedWithVmId(), rule.getNetworkId());
}
return new StaticNatRuleImpl(ruleVO, dstIp);
@@@ -1286,7 -1270,7 +1283,7 @@@
@Override
public boolean applyStaticNatForIp(long sourceIpId, boolean continueOnError, Account caller, boolean forRevoke) {
IpAddress sourceIp = _ipAddressDao.findById(sourceIpId);
--
++
List<StaticNat> staticNats = createStaticNatForIp(sourceIp, caller, forRevoke);
if (staticNats != null && !staticNats.isEmpty()) {
@@@ -1302,8 -1286,8 +1299,8 @@@
return true;
}
--
--
++
++
@Override
public boolean applyStaticNatForNetwork(long networkId, boolean continueOnError, Account caller, boolean forRevoke) {
List<? extends IpAddress> staticNatIps = _ipAddressDao.listStaticNatPublicIps(networkId);
@@@ -1329,8 -1313,8 +1326,8 @@@
s_logger.debug("Found 0 static nat rules to apply for network id " + networkId);
}
-- return true;
-- }
++ return true;
++ }
protected List<StaticNat> createStaticNatForIp(IpAddress sourceIp, Account caller, boolean forRevoke) {
List<StaticNat> staticNats = new ArrayList<StaticNat>();
@@@ -1345,10 -1329,10 +1342,10 @@@
}
UserVmVO vm = _vmDao.findById(sourceIp.getAssociatedWithVmId());
- Network network = _networkMgr.getNetwork(networkId);
+ Network network = _networkModel.getNetwork(networkId);
if (network == null) {
-- CloudRuntimeException ex = new CloudRuntimeException("Unable to find an ip address to map to specified vm id");
-- ex.addProxyObject(vm, vm.getId(), "vmId");
++ CloudRuntimeException ex = new CloudRuntimeException("Unable to find an ip address to map to specified vm id");
++ ex.addProxyObject(vm, vm.getId(), "vmId");
throw ex;
}
@@@ -1405,11 -1385,11 +1398,11 @@@
success = enableStaticNat(ip.getId(), vm.getId(), guestNetwork.getId(), isSystemVM);
} catch (NetworkRuleConflictException ex) {
s_logger.warn("Failed to enable static nat as a part of enabling elasticIp and staticNat for vm " +
-- vm + " in guest network " + guestNetwork + " due to exception ", ex);
++ vm + " in guest network " + guestNetwork + " due to exception ", ex);
success = false;
} catch (ResourceUnavailableException ex) {
s_logger.warn("Failed to enable static nat as a part of enabling elasticIp and staticNat for vm " +
-- vm + " in guest network " + guestNetwork + " due to exception ", ex);
++ vm + " in guest network " + guestNetwork + " due to exception ", ex);
success = false;
}
@@@ -1424,7 -1404,7 +1417,7 @@@
}
}
--
++
protected void removePFRule(PortForwardingRuleVO rule) {
_portForwardingDao.remove(rule.getId());
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/10d9c019/server/src/com/cloud/network/security/SecurityGroupManagerImpl.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/10d9c019/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/10d9c019/server/src/com/cloud/network/vpc/VpcManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/network/vpc/VpcManagerImpl.java
index 00205a1,fa6bd30..94d4e02
--- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java
+++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
@@@ -981,9 -987,9 +987,9 @@@ public class VpcManagerImpl implements
//skip my own network
continue;
} else {
- if (_ntwkMgr.areServicesSupportedInNetwork(network.getId(), Service.Lb)) {
+ if (_ntwkModel.areServicesSupportedInNetwork(network.getId(), Service.Lb)) {
throw new InvalidParameterValueException("LB service is already supported " +
- "by network " + network + " in VPC " + vpc);
+ "by network " + network + " in VPC " + vpc);
}
}
}