diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index 08276d77ffa..e999c4b3e7a 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -71,10 +71,10 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.IpAddress; import com.cloud.network.IpAddressManager; import com.cloud.network.Network; +import com.cloud.network.Network.Capability; import com.cloud.network.Network.GuestType; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; -import com.cloud.network.Network.Capability; import com.cloud.network.NetworkModel; import com.cloud.network.NetworkService; import com.cloud.network.Networks.BroadcastDomainType; @@ -228,32 +228,32 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @PostConstruct protected void setupSupportedVpcHypervisorsList() { - this.hTypes.add(HypervisorType.XenServer); - this.hTypes.add(HypervisorType.VMware); - this.hTypes.add(HypervisorType.KVM); - this.hTypes.add(HypervisorType.Simulator); - this.hTypes.add(HypervisorType.LXC); - this.hTypes.add(HypervisorType.Hyperv); - this.hTypes.add(HypervisorType.Ovm3); + hTypes.add(HypervisorType.XenServer); + hTypes.add(HypervisorType.VMware); + hTypes.add(HypervisorType.KVM); + hTypes.add(HypervisorType.Simulator); + hTypes.add(HypervisorType.LXC); + hTypes.add(HypervisorType.Hyperv); + hTypes.add(HypervisorType.Ovm3); } @Override @DB - public boolean configure(String name, Map params) throws ConfigurationException { + public boolean configure(final String name, final Map params) throws ConfigurationException { //configure default vpc offering Transaction.execute(new TransactionCallbackNoReturn() { @Override - public void doInTransactionWithoutResult(TransactionStatus status) { + public void doInTransactionWithoutResult(final TransactionStatus status) { if (_vpcOffDao.findByUniqueName(VpcOffering.defaultVPCOfferingName) == null) { s_logger.debug("Creating default VPC offering " + VpcOffering.defaultVPCOfferingName); - Map> svcProviderMap = new HashMap>(); - Set defaultProviders = new HashSet(); + final Map> svcProviderMap = new HashMap>(); + final Set defaultProviders = new HashSet(); defaultProviders.add(Provider.VPCVirtualRouter); - for (Service svc : getSupportedServices()) { + for (final Service svc : getSupportedServices()) { if (svc == Service.Lb) { - Set lbProviders = new HashSet(); + final Set lbProviders = new HashSet(); lbProviders.add(Provider.VPCVirtualRouter); lbProviders.add(Provider.InternalLbVm); svcProviderMap.put(svc, lbProviders); @@ -268,12 +268,12 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis //configure default vpc offering with Netscaler as LB Provider if (_vpcOffDao.findByUniqueName(VpcOffering.defaultVPCNSOfferingName) == null) { s_logger.debug("Creating default VPC offering with Netscaler as LB Provider" + VpcOffering.defaultVPCNSOfferingName); - Map> svcProviderMap = new HashMap>(); - Set defaultProviders = new HashSet(); + final Map> svcProviderMap = new HashMap>(); + final Set defaultProviders = new HashSet(); defaultProviders.add(Provider.VPCVirtualRouter); - for (Service svc : getSupportedServices()) { + for (final Service svc : getSupportedServices()) { if (svc == Service.Lb) { - Set lbProviders = new HashSet(); + final Set lbProviders = new HashSet(); lbProviders.add(Provider.Netscaler); lbProviders.add(Provider.InternalLbVm); svcProviderMap.put(svc, lbProviders); @@ -289,12 +289,12 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis if (_vpcOffDao.findByUniqueName(VpcOffering.redundantVPCOfferingName) == null) { s_logger.debug("Creating Redundant VPC offering " + VpcOffering.redundantVPCOfferingName); - Map> svcProviderMap = new HashMap>(); - Set defaultProviders = new HashSet(); + final Map> svcProviderMap = new HashMap>(); + final Set defaultProviders = new HashSet(); defaultProviders.add(Provider.VPCVirtualRouter); - for (Service svc : getSupportedServices()) { + for (final Service svc : getSupportedServices()) { if (svc == Service.Lb) { - Set lbProviders = new HashSet(); + final Set lbProviders = new HashSet(); lbProviders.add(Provider.VPCVirtualRouter); lbProviders.add(Provider.InternalLbVm); svcProviderMap.put(svc, lbProviders); @@ -308,11 +308,11 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } }); - Map configs = _configDao.getConfiguration(params); - String value = configs.get(Config.VpcCleanupInterval.key()); + final Map configs = _configDao.getConfiguration(params); + final String value = configs.get(Config.VpcCleanupInterval.key()); _cleanupInterval = NumbersUtil.parseInt(value, 60 * 60); // 1 hour - String maxNtwks = configs.get(Config.VpcMaxNetworks.key()); + final String maxNtwks = configs.get(Config.VpcMaxNetworks.key()); _maxNetworks = NumbersUtil.parseInt(maxNtwks, 3); // max=3 is default IpAddressSearch = _ipAddressDao.createSearchBuilder(); @@ -320,10 +320,10 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis IpAddressSearch.and("dataCenterId", IpAddressSearch.entity().getDataCenterId(), Op.EQ); IpAddressSearch.and("vpcId", IpAddressSearch.entity().getVpcId(), Op.EQ); IpAddressSearch.and("associatedWithNetworkId", IpAddressSearch.entity().getAssociatedWithNetworkId(), Op.EQ); - SearchBuilder virtualNetworkVlanSB = _vlanDao.createSearchBuilder(); + final SearchBuilder virtualNetworkVlanSB = _vlanDao.createSearchBuilder(); virtualNetworkVlanSB.and("vlanType", virtualNetworkVlanSB.entity().getVlanType(), Op.EQ); IpAddressSearch.join("virtualNetworkVlanSB", virtualNetworkVlanSB, IpAddressSearch.entity().getVlanId(), virtualNetworkVlanSB.entity().getId(), - JoinBuilder.JoinType.INNER); + JoinBuilder.JoinType.INNER); IpAddressSearch.done(); return true; @@ -341,27 +341,27 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } @Override - public List getVpcNetworks(long vpcId) { + public List getVpcNetworks(final long vpcId) { return _ntwkDao.listByVpc(vpcId); } @Override - public VpcOffering getVpcOffering(long vpcOffId) { + public VpcOffering getVpcOffering(final long vpcOffId) { return _vpcOffDao.findById(vpcOffId); } @Override @ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_CREATE, eventDescription = "creating vpc offering", create = true) - public VpcOffering createVpcOffering(String name, String displayText, List supportedServices, - Map> serviceProviders, - Map serviceCapabilitystList, - Long serviceOfferingId) { + public VpcOffering createVpcOffering(final String name, final String displayText, final List supportedServices, + final Map> serviceProviders, + final Map serviceCapabilitystList, + final Long serviceOfferingId) { - Map> svcProviderMap = new HashMap>(); - Set defaultProviders = new HashSet(); + final Map> svcProviderMap = new HashMap>(); + final Set defaultProviders = new HashSet(); defaultProviders.add(Provider.VPCVirtualRouter); // Just here for 4.1, replaced by commit 836ce6c1 in newer versions - Set sdnProviders = new HashSet(); + final Set sdnProviders = new HashSet(); sdnProviders.add(Provider.NiciraNvp); sdnProviders.add(Provider.JuniperContrailVpcRouter); sdnProviders.add(Provider.NuageVsp); @@ -369,9 +369,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis boolean sourceNatSvc = false; boolean firewallSvs = false; // populate the services first - for (String serviceName : supportedServices) { + for (final String serviceName : supportedServices) { // validate if the service is supported - Service service = Network.Service.getService(serviceName); + final Service service = Network.Service.getService(serviceName); if (service == null || nonSupportedServices.contains(service)) { throw new InvalidParameterValueException("Service " + serviceName + " is not supported in VPC"); } @@ -404,17 +404,17 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis svcProviderMap.put(Service.Gateway, defaultProviders); if (serviceProviders != null) { - for (Entry> serviceEntry : serviceProviders.entrySet()) { - Network.Service service = Network.Service.getService(serviceEntry.getKey()); + for (final Entry> serviceEntry : serviceProviders.entrySet()) { + final Network.Service service = Network.Service.getService(serviceEntry.getKey()); if (svcProviderMap.containsKey(service)) { - Set providers = new HashSet(); + final Set providers = new HashSet(); // don't allow to specify more than 1 provider per service if (serviceEntry.getValue() != null && serviceEntry.getValue().size() > 1) { throw new InvalidParameterValueException("In the current release only one provider can be " + "specified for the service"); } - for (String prvNameStr : serviceEntry.getValue()) { + for (final String prvNameStr : serviceEntry.getValue()) { // check if provider is supported - Network.Provider provider = Network.Provider.getProvider(prvNameStr); + final Network.Provider provider = Network.Provider.getProvider(prvNameStr); if (provider == null) { throw new InvalidParameterValueException("Invalid service provider: " + prvNameStr); } @@ -431,10 +431,10 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis validateConnectivtyServiceCapabilities(svcProviderMap.get(Service.Connectivity), serviceCapabilitystList); - boolean supportsDistributedRouter = isVpcOfferingSupportsDistributedRouter(serviceCapabilitystList); - boolean offersRegionLevelVPC = isVpcOfferingForRegionLevelVpc(serviceCapabilitystList); - boolean redundantRouter = this.isVpcOfferingRedundantRouter(serviceCapabilitystList); - VpcOffering offering = createVpcOffering(name, displayText, svcProviderMap, false, null, + final boolean supportsDistributedRouter = isVpcOfferingSupportsDistributedRouter(serviceCapabilitystList); + final boolean offersRegionLevelVPC = isVpcOfferingForRegionLevelVpc(serviceCapabilitystList); + final boolean redundantRouter = isVpcOfferingRedundantRouter(serviceCapabilitystList); + final VpcOffering offering = createVpcOffering(name, displayText, svcProviderMap, false, null, serviceOfferingId, supportsDistributedRouter, offersRegionLevelVPC, redundantRouter); CallContext.current().setEventDetails(" Id: " + offering.getId() + " Name: " + name); @@ -443,14 +443,14 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @DB protected VpcOffering createVpcOffering(final String name, final String displayText, - final Map> svcProviderMap, - final boolean isDefault, final State state, final Long serviceOfferingId, - final boolean supportsDistributedRouter, final boolean offersRegionLevelVPC, - final boolean redundantRouter) { + final Map> svcProviderMap, + final boolean isDefault, final State state, final Long serviceOfferingId, + final boolean supportsDistributedRouter, final boolean offersRegionLevelVPC, + final boolean redundantRouter) { return Transaction.execute(new TransactionCallback() { @Override - public VpcOffering doInTransaction(TransactionStatus status) { + public VpcOffering doInTransaction(final TransactionStatus status) { // create vpc offering object VpcOfferingVO offering = new VpcOfferingVO(name, displayText, isDefault, serviceOfferingId, supportsDistributedRouter, offersRegionLevelVPC, redundantRouter); @@ -462,11 +462,11 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis offering = _vpcOffDao.persist(offering); // populate services and providers if (svcProviderMap != null) { - for (Network.Service service : svcProviderMap.keySet()) { - Set providers = svcProviderMap.get(service); + for (final Network.Service service : svcProviderMap.keySet()) { + final Set providers = svcProviderMap.get(service); if (providers != null && !providers.isEmpty()) { - for (Network.Provider provider : providers) { - VpcOfferingServiceMapVO offService = new VpcOfferingServiceMapVO(offering.getId(), service, provider); + for (final Network.Provider provider : providers) { + final VpcOfferingServiceMapVO offService = new VpcOfferingServiceMapVO(offering.getId(), service, provider); _vpcOffSvcMapDao.persist(offService); s_logger.trace("Added service for the vpc offering: " + offService + " with provider " + provider.getName()); } @@ -485,13 +485,13 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis final Service service) { // TODO Shouldn't it fail it there are no providers? if (providers != null) { - for (Provider provider: providers) { - NetworkElement element = _ntwkModel.getElementImplementingProvider(provider.getName()); - Map> capabilities = element.getCapabilities(); + for (final Provider provider: providers) { + final NetworkElement element = _ntwkModel.getElementImplementingProvider(provider.getName()); + final Map> capabilities = element.getCapabilities(); if (capabilities != null && !capabilities.isEmpty()) { - Map connectivityCapabilities = capabilities.get(service); - if (connectivityCapabilities == null || (connectivityCapabilities != null && - !connectivityCapabilities.keySet().contains(capability))) { + final Map connectivityCapabilities = capabilities.get(service); + if (connectivityCapabilities == null || connectivityCapabilities != null && + !connectivityCapabilities.keySet().contains(capability)) { throw new InvalidParameterValueException(String.format( "Provider %s does not support %s capability.", provider.getName(), capability.getName())); @@ -501,28 +501,28 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } } - private void validateConnectivtyServiceCapabilities(Set providers, Map serviceCapabilitystList) { + private void validateConnectivtyServiceCapabilities(final Set providers, final Map serviceCapabilitystList) { if (serviceCapabilitystList != null && !serviceCapabilitystList.isEmpty()) { - Collection serviceCapabilityCollection = serviceCapabilitystList.values(); - Iterator iter = serviceCapabilityCollection.iterator(); - List specifiedCapabilities = new ArrayList<>(); + final Collection serviceCapabilityCollection = serviceCapabilitystList.values(); + final Iterator iter = serviceCapabilityCollection.iterator(); + final List specifiedCapabilities = new ArrayList<>(); while (iter.hasNext()) { - HashMap svcCapabilityMap = (HashMap)iter.next(); + final HashMap svcCapabilityMap = (HashMap)iter.next(); Capability capability = null; - String svc = svcCapabilityMap.get(SERVICE); - String capabilityName = svcCapabilityMap.get(CAPABILITYTYPE); - String capabilityValue = svcCapabilityMap.get(CAPABILITYVALUE); + final String svc = svcCapabilityMap.get(SERVICE); + final String capabilityName = svcCapabilityMap.get(CAPABILITYTYPE); + final String capabilityValue = svcCapabilityMap.get(CAPABILITYVALUE); if (capabilityName != null) { capability = Capability.getCapability(capabilityName); } - if ((capability == null) || (capabilityValue == null)) { + if (capability == null || capabilityValue == null) { throw new InvalidParameterValueException("Invalid capability:" + capabilityName + " capability value:" + capabilityValue); } - Service usedService = Service.getService(svc); + final Service usedService = Service.getService(svc); - this.checkCapabilityPerServiceProvider(providers, capability, usedService); + checkCapabilityPerServiceProvider(providers, capability, usedService); if (!capabilityValue.equalsIgnoreCase(TRUE_VALUE) && !capabilityValue.equalsIgnoreCase(FALSE_VALUE)) { throw new InvalidParameterValueException("Invalid Capability value:" + capabilityValue + " specified."); @@ -531,17 +531,17 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } } - private boolean findCapabilityForService(Map serviceCapabilitystList, Capability capability, Service service) { + private boolean findCapabilityForService(final Map serviceCapabilitystList, final Capability capability, final Service service) { boolean foundCapability = false; if (serviceCapabilitystList != null && !serviceCapabilitystList.isEmpty()) { - Iterator iter = serviceCapabilitystList.values().iterator(); + final Iterator iter = serviceCapabilitystList.values().iterator(); while (iter.hasNext()) { - HashMap currentCapabilityMap = (HashMap)iter.next(); - String currentCapabilityService = currentCapabilityMap.get(SERVICE); - String currentCapabilityName = currentCapabilityMap.get(CAPABILITYTYPE); - String currentCapabilityValue = currentCapabilityMap.get(CAPABILITYVALUE); + final HashMap currentCapabilityMap = (HashMap)iter.next(); + final String currentCapabilityService = currentCapabilityMap.get(SERVICE); + final String currentCapabilityName = currentCapabilityMap.get(CAPABILITYTYPE); + final String currentCapabilityValue = currentCapabilityMap.get(CAPABILITYVALUE); - if ((currentCapabilityName == null) || (currentCapabilityService == null) || (currentCapabilityValue == null)) { + if (currentCapabilityName == null || currentCapabilityService == null || currentCapabilityValue == null) { throw new InvalidParameterValueException(String.format("Invalid capability with name %s, value %s and service %s", currentCapabilityName, currentCapabilityValue, currentCapabilityService)); } @@ -562,33 +562,33 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis return foundCapability; } - private boolean isVpcOfferingForRegionLevelVpc(Map serviceCapabilitystList) { - return this.findCapabilityForService(serviceCapabilitystList, Capability.RegionLevelVpc, + private boolean isVpcOfferingForRegionLevelVpc(final Map serviceCapabilitystList) { + return findCapabilityForService(serviceCapabilitystList, Capability.RegionLevelVpc, Service.Connectivity); } - private boolean isVpcOfferingSupportsDistributedRouter(Map serviceCapabilitystList) { - return this.findCapabilityForService(serviceCapabilitystList, Capability.DistributedRouter, + private boolean isVpcOfferingSupportsDistributedRouter(final Map serviceCapabilitystList) { + return findCapabilityForService(serviceCapabilitystList, Capability.DistributedRouter, Service.Connectivity); } - private boolean isVpcOfferingRedundantRouter(Map serviceCapabilitystList) { - return this.findCapabilityForService(serviceCapabilitystList, Capability.RedundantRouter, + private boolean isVpcOfferingRedundantRouter(final Map serviceCapabilitystList) { + return findCapabilityForService(serviceCapabilitystList, Capability.RedundantRouter, Service.SourceNat); } @Override - public Vpc getActiveVpc(long vpcId) { + public Vpc getActiveVpc(final long vpcId) { return _vpcDao.getActiveVpcById(vpcId); } @Override - public Map> getVpcOffSvcProvidersMap(long vpcOffId) { - Map> serviceProviderMap = new HashMap>(); - List map = _vpcOffSvcMapDao.listByVpcOffId(vpcOffId); + public Map> getVpcOffSvcProvidersMap(final long vpcOffId) { + final Map> serviceProviderMap = new HashMap>(); + final List map = _vpcOffSvcMapDao.listByVpcOffId(vpcOffId); - for (VpcOfferingServiceMapVO instance : map) { - Service service = Service.getService(instance.getService()); + for (final VpcOfferingServiceMapVO instance : map) { + final Service service = Service.getService(instance.getService()); Set providers; providers = serviceProviderMap.get(service); if (providers == null) { @@ -602,13 +602,13 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } @Override - public Pair,Integer> listVpcOfferings(Long id, String name, String displayText, List supportedServicesStr, Boolean isDefault, String keyword, - String state, Long startIndex, Long pageSizeVal) { - Filter searchFilter = new Filter(VpcOfferingVO.class, "created", false, null, null); - SearchCriteria sc = _vpcOffDao.createSearchCriteria(); + public Pair,Integer> listVpcOfferings(final Long id, final String name, final String displayText, final List supportedServicesStr, final Boolean isDefault, final String keyword, + final String state, final Long startIndex, final Long pageSizeVal) { + final Filter searchFilter = new Filter(VpcOfferingVO.class, "created", false, null, null); + final SearchCriteria sc = _vpcOffDao.createSearchCriteria(); if (keyword != null) { - SearchCriteria ssc = _vpcOffDao.createSearchCriteria(); + final SearchCriteria ssc = _vpcOffDao.createSearchCriteria(); ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); @@ -635,20 +635,20 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis sc.addAnd("id", SearchCriteria.Op.EQ, id); } - List offerings = _vpcOffDao.search(sc, searchFilter); + final List offerings = _vpcOffDao.search(sc, searchFilter); // filter by supported services - boolean listBySupportedServices = (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty()); + final boolean listBySupportedServices = supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty(); if (listBySupportedServices) { - List supportedOfferings = new ArrayList(); + final List supportedOfferings = new ArrayList(); Service[] supportedServices = null; if (listBySupportedServices) { supportedServices = new Service[supportedServicesStr.size()]; int i = 0; - for (String supportedServiceStr : supportedServicesStr) { - Service service = Service.getService(supportedServiceStr); + for (final String supportedServiceStr : supportedServicesStr) { + final Service service = Service.getService(supportedServiceStr); if (service == null) { throw new InvalidParameterValueException("Invalid service specified " + supportedServiceStr); } else { @@ -658,39 +658,39 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } } - for (VpcOfferingVO offering : offerings) { + for (final VpcOfferingVO offering : offerings) { if (areServicesSupportedByVpcOffering(offering.getId(), supportedServices)) { supportedOfferings.add(offering); } } - List wPagination = StringUtils.applyPagination(supportedOfferings, startIndex, pageSizeVal); + final List wPagination = StringUtils.applyPagination(supportedOfferings, startIndex, pageSizeVal); if (wPagination != null) { - Pair, Integer> listWPagination = new Pair, Integer>(wPagination, supportedOfferings.size()); + final Pair, Integer> listWPagination = new Pair, Integer>(wPagination, supportedOfferings.size()); return listWPagination; } return new Pair, Integer>(supportedOfferings, supportedOfferings.size()); } else { - List wPagination = StringUtils.applyPagination(offerings, startIndex, pageSizeVal); + final List wPagination = StringUtils.applyPagination(offerings, startIndex, pageSizeVal); if (wPagination != null) { - Pair, Integer> listWPagination = new Pair, Integer>(wPagination, offerings.size()); + final Pair, Integer> listWPagination = new Pair, Integer>(wPagination, offerings.size()); return listWPagination; } return new Pair, Integer>(offerings, offerings.size()); } } - protected boolean areServicesSupportedByVpcOffering(long vpcOffId, Service... services) { - return (_vpcOffSvcMapDao.areServicesSupportedByNetworkOffering(vpcOffId, services)); + protected boolean areServicesSupportedByVpcOffering(final long vpcOffId, final Service... services) { + return _vpcOffSvcMapDao.areServicesSupportedByNetworkOffering(vpcOffId, services); } @Override @ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_DELETE, eventDescription = "deleting vpc offering") - public boolean deleteVpcOffering(long offId) { + public boolean deleteVpcOffering(final long offId) { CallContext.current().setEventDetails(" Id: " + offId); // Verify vpc offering id - VpcOfferingVO offering = _vpcOffDao.findById(offId); + final VpcOfferingVO offering = _vpcOffDao.findById(offId); if (offering == null) { throw new InvalidParameterValueException("unable to find vpc offering " + offId); } @@ -701,7 +701,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } // don't allow to delete vpc offering if it's in use by existing vpcs (the offering can be disabled though) - int vpcCount = _vpcDao.getVpcCountByOfferingId(offId); + final int vpcCount = _vpcDao.getVpcCountByOfferingId(offId); if (vpcCount > 0) { throw new InvalidParameterValueException("Can't delete vpc offering " + offId + " as its used by " + vpcCount + " vpcs. " + "To make the network offering unavaiable, disable it"); @@ -716,16 +716,16 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @Override @ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_UPDATE, eventDescription = "updating vpc offering") - public VpcOffering updateVpcOffering(long vpcOffId, String vpcOfferingName, String displayText, String state) { + public VpcOffering updateVpcOffering(final long vpcOffId, final String vpcOfferingName, final String displayText, final String state) { CallContext.current().setEventDetails(" Id: " + vpcOffId); // Verify input parameters - VpcOfferingVO offeringToUpdate = _vpcOffDao.findById(vpcOffId); + final VpcOfferingVO offeringToUpdate = _vpcOffDao.findById(vpcOffId); if (offeringToUpdate == null) { throw new InvalidParameterValueException("Unable to find vpc offering " + vpcOffId); } - VpcOfferingVO offering = _vpcOffDao.createForUpdate(vpcOffId); + final VpcOfferingVO offering = _vpcOffDao.createForUpdate(vpcOffId); if (vpcOfferingName != null) { offering.setName(vpcOfferingName); @@ -737,7 +737,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis if (state != null) { boolean validState = false; - for (VpcOffering.State st : VpcOffering.State.values()) { + for (final VpcOffering.State st : VpcOffering.State.values()) { if (st.name().equalsIgnoreCase(state)) { validState = true; offering.setState(st); @@ -758,10 +758,10 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @Override @ActionEvent(eventType = EventTypes.EVENT_VPC_CREATE, eventDescription = "creating vpc", create = true) - public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr, String networkDomain, Boolean displayVpc) - throws ResourceAllocationException { - Account caller = CallContext.current().getCallingAccount(); - Account owner = _accountMgr.getAccount(vpcOwnerId); + public Vpc createVpc(final long zoneId, final long vpcOffId, final long vpcOwnerId, final String vpcName, final String displayText, final String cidr, String networkDomain, final Boolean displayVpc) + throws ResourceAllocationException { + final Account caller = CallContext.current().getCallingAccount(); + final Account owner = _accountMgr.getAccount(vpcOwnerId); //Verify that caller can perform actions in behalf of vpc owner _accountMgr.checkAccess(caller, null, false, owner); @@ -770,9 +770,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis _resourceLimitMgr.checkResourceLimit(owner, ResourceType.vpc); // Validate vpc offering - VpcOfferingVO vpcOff = _vpcOffDao.findById(vpcOffId); + final VpcOfferingVO vpcOff = _vpcOffDao.findById(vpcOffId); if (vpcOff == null || vpcOff.getState() != State.Enabled) { - InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find vpc offering in " + State.Enabled + " state by specified id"); + final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find vpc offering in " + State.Enabled + " state by specified id"); if (vpcOff == null) { ex.addProxyObject(String.valueOf(vpcOffId), "vpcOfferingId"); } else { @@ -781,20 +781,20 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis throw ex; } - boolean isRegionLevelVpcOff = vpcOff.offersRegionLevelVPC(); + final boolean isRegionLevelVpcOff = vpcOff.offersRegionLevelVPC(); if (isRegionLevelVpcOff && networkDomain == null) { throw new InvalidParameterValueException("Network domain must be specified for region level VPC"); } //Validate zone - DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId); + final DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId); if (zone == null) { throw new InvalidParameterValueException("Can't find zone by id specified"); } if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getId())) { // See DataCenterVO.java - PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation since specified Zone is currently disabled"); + final PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation since specified Zone is currently disabled"); ex.addProxyObject(zone.getUuid(), "zoneId"); throw ex; } @@ -809,7 +809,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } } - boolean useDistributedRouter = vpcOff.supportsDistributedRouter(); + final boolean useDistributedRouter = vpcOff.supportsDistributedRouter(); final VpcVO vpc = new VpcVO(zoneId, vpcName, displayText, owner.getId(), owner.getDomainId(), vpcOffId, cidr, networkDomain, useDistributedRouter, isRegionLevelVpcOff, vpcOff.getRedundantRouter()); @@ -832,18 +832,18 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis // validate network domain if (!NetUtils.verifyDomainName(vpc.getNetworkDomain())) { throw new InvalidParameterValueException("Invalid network domain. Total length shouldn't exceed 190 chars. Each domain " - + "label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', " + "the digits '0' through '9', " - + "and the hyphen ('-'); can't start or end with \"-\""); + + "label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', " + "the digits '0' through '9', " + + "and the hyphen ('-'); can't start or end with \"-\""); } return Transaction.execute(new TransactionCallback() { @Override - public VpcVO doInTransaction(TransactionStatus status) { + public VpcVO doInTransaction(final TransactionStatus status) { if (displayVpc != null) { vpc.setDisplay(displayVpc); } - VpcVO persistedVpc = _vpcDao.persist(vpc, finalizeServicesAndProvidersForVpc(vpc.getZoneId(), vpc.getVpcOfferingId())); + final VpcVO persistedVpc = _vpcDao.persist(vpc, finalizeServicesAndProvidersForVpc(vpc.getZoneId(), vpc.getVpcOfferingId())); _resourceLimitMgr.incrementResourceCount(vpc.getAccountId(), ResourceType.vpc); s_logger.debug("Created VPC " + persistedVpc); @@ -852,12 +852,12 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis }); } - private Map> finalizeServicesAndProvidersForVpc(long zoneId, long offeringId) { - Map> svcProviders = new HashMap<>(); - List servicesMap = _vpcOffSvcMapDao.listByVpcOffId(offeringId); + private Map> finalizeServicesAndProvidersForVpc(final long zoneId, final long offeringId) { + final Map> svcProviders = new HashMap<>(); + final List servicesMap = _vpcOffSvcMapDao.listByVpcOffId(offeringId); - for (VpcOfferingServiceMapVO serviceMap : servicesMap) { - String service = serviceMap.getService(); + for (final VpcOfferingServiceMapVO serviceMap : servicesMap) { + final String service = serviceMap.getService(); String provider = serviceMap.getProvider(); if (provider == null) { @@ -884,12 +884,12 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @Override @ActionEvent(eventType = EventTypes.EVENT_VPC_DELETE, eventDescription = "deleting VPC") - public boolean deleteVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException { + public boolean deleteVpc(final long vpcId) throws ConcurrentOperationException, ResourceUnavailableException { CallContext.current().setEventDetails(" Id: " + vpcId); - CallContext ctx = CallContext.current(); + final CallContext ctx = CallContext.current(); // Verify vpc id - Vpc vpc = _vpcDao.findById(vpcId); + final Vpc vpc = _vpcDao.findById(vpcId); if (vpc == null) { throw new InvalidParameterValueException("unable to find VPC id=" + vpcId); } @@ -902,12 +902,12 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @Override @DB - public boolean destroyVpc(final Vpc vpc, Account caller, Long callerUserId) throws ConcurrentOperationException, ResourceUnavailableException { + public boolean destroyVpc(final Vpc vpc, final Account caller, final Long callerUserId) throws ConcurrentOperationException, ResourceUnavailableException { s_logger.debug("Destroying vpc " + vpc); //don't allow to delete vpc if it's in use by existing non system networks (system networks are networks of a private gateway of the VPC, //and they will get removed as a part of VPC cleanup - int networksCount = _ntwkDao.getNonSystemNetworkCountByVpcId(vpc.getId()); + final int networksCount = _ntwkDao.getNonSystemNetworkCountByVpcId(vpc.getId()); if (networksCount > 0) { throw new InvalidParameterValueException("Can't delete VPC " + vpc + " as its used by " + networksCount + " networks"); } @@ -920,11 +920,11 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis Transaction.execute(new TransactionCallbackNoReturn() { @Override - public void doInTransactionWithoutResult(TransactionStatus status) { - _vpcDao.update(vpc.getId(), vpcVO); + public void doInTransactionWithoutResult(final TransactionStatus status) { + _vpcDao.update(vpc.getId(), vpcVO); - //decrement resource count - _resourceLimitMgr.decrementResourceCount(vpc.getAccountId(), ResourceType.vpc); + //decrement resource count + _resourceLimitMgr.decrementResourceCount(vpc.getAccountId(), ResourceType.vpc); } }); } @@ -953,19 +953,19 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @Override @ActionEvent(eventType = EventTypes.EVENT_VPC_UPDATE, eventDescription = "updating vpc") - public Vpc updateVpc(long vpcId, String vpcName, String displayText, String customId, Boolean displayVpc) { + public Vpc updateVpc(final long vpcId, final String vpcName, final String displayText, final String customId, final Boolean displayVpc) { CallContext.current().setEventDetails(" Id: " + vpcId); - Account caller = CallContext.current().getCallingAccount(); + final Account caller = CallContext.current().getCallingAccount(); // Verify input parameters - VpcVO vpcToUpdate = _vpcDao.findById(vpcId); + final VpcVO vpcToUpdate = _vpcDao.findById(vpcId); if (vpcToUpdate == null) { throw new InvalidParameterValueException("Unable to find vpc by id " + vpcId); } _accountMgr.checkAccess(caller, null, false, vpcToUpdate); - VpcVO vpc = _vpcDao.createForUpdate(vpcId); + final VpcVO vpc = _vpcDao.createForUpdate(vpcId); if (vpcName != null) { vpc.setName(vpcName); @@ -992,21 +992,21 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } @Override - public Pair, Integer> listVpcs(Long id, String vpcName, String displayText, List supportedServicesStr, String cidr, Long vpcOffId, String state, - String accountName, Long domainId, String keyword, Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll, Boolean restartRequired, - Map tags, Long projectId, Boolean display) { - Account caller = CallContext.current().getCallingAccount(); - List permittedAccounts = new ArrayList(); - Ternary domainIdRecursiveListProject = new Ternary, Integer> listVpcs(final Long id, final String vpcName, final String displayText, final List supportedServicesStr, final String cidr, final Long vpcOffId, final String state, + final String accountName, Long domainId, final String keyword, final Long startIndex, final Long pageSizeVal, final Long zoneId, Boolean isRecursive, final Boolean listAll, final Boolean restartRequired, + final Map tags, final Long projectId, final Boolean display) { + final Account caller = CallContext.current().getCallingAccount(); + final List permittedAccounts = new ArrayList(); + final Ternary domainIdRecursiveListProject = new Ternary(domainId, isRecursive, null); _accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject, listAll, false); domainId = domainIdRecursiveListProject.first(); isRecursive = domainIdRecursiveListProject.second(); - ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); - Filter searchFilter = new Filter(VpcVO.class, "created", false, null, null); + final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); + final Filter searchFilter = new Filter(VpcVO.class, "created", false, null, null); - SearchBuilder sb = _vpcDao.createSearchBuilder(); + final SearchBuilder sb = _vpcDao.createSearchBuilder(); _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); @@ -1020,7 +1020,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis sb.and("display", sb.entity().isDisplay(), SearchCriteria.Op.EQ); if (tags != null && !tags.isEmpty()) { - SearchBuilder tagSearch = _resourceTagDao.createSearchBuilder(); + final SearchBuilder 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); @@ -1032,11 +1032,11 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } // now set the SC criteria... - SearchCriteria sc = sb.create(); + final SearchCriteria sc = sb.create(); _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); if (keyword != null) { - SearchCriteria ssc = _vpcDao.createSearchCriteria(); + final SearchCriteria ssc = _vpcDao.createSearchCriteria(); ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); sc.addAnd("name", SearchCriteria.Op.SC, ssc); @@ -1053,12 +1053,12 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis if (tags != null && !tags.isEmpty()) { int count = 0; sc.setJoinParameters("tagSearch", "resourceType", ResourceObjectType.Vpc.toString()); - for (Map.Entryentry : tags.entrySet()) { + for (final Map.Entryentry : tags.entrySet()) { sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), entry.getKey()); sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), entry.getValue()); count++; } - } + } if (display != null) { sc.setParameters("display", display); @@ -1088,20 +1088,20 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis sc.addAnd("restartRequired", SearchCriteria.Op.EQ, restartRequired); } - List vpcs = _vpcDao.search(sc, searchFilter); + final List vpcs = _vpcDao.search(sc, searchFilter); // filter by supported services - boolean listBySupportedServices = (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !vpcs.isEmpty()); + final boolean listBySupportedServices = supportedServicesStr != null && !supportedServicesStr.isEmpty() && !vpcs.isEmpty(); if (listBySupportedServices) { - List supportedVpcs = new ArrayList(); + final List supportedVpcs = new ArrayList(); Service[] supportedServices = null; if (listBySupportedServices) { supportedServices = new Service[supportedServicesStr.size()]; int i = 0; - for (String supportedServiceStr : supportedServicesStr) { - Service service = Service.getService(supportedServiceStr); + for (final String supportedServiceStr : supportedServicesStr) { + final Service service = Service.getService(supportedServiceStr); if (service == null) { throw new InvalidParameterValueException("Invalid service specified " + supportedServiceStr); } else { @@ -1111,22 +1111,22 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } } - for (VpcVO vpc : vpcs) { + for (final VpcVO vpc : vpcs) { if (areServicesSupportedByVpcOffering(vpc.getVpcOfferingId(), supportedServices)) { supportedVpcs.add(vpc); } } - List wPagination = StringUtils.applyPagination(supportedVpcs, startIndex, pageSizeVal); + final List wPagination = StringUtils.applyPagination(supportedVpcs, startIndex, pageSizeVal); if (wPagination != null) { - Pair, Integer> listWPagination = new Pair, Integer>(wPagination, supportedVpcs.size()); + final Pair, Integer> listWPagination = new Pair, Integer>(wPagination, supportedVpcs.size()); return listWPagination; } return new Pair, Integer>(supportedVpcs, supportedVpcs.size()); } else { - List wPagination = StringUtils.applyPagination(vpcs, startIndex, pageSizeVal); + final List wPagination = StringUtils.applyPagination(vpcs, startIndex, pageSizeVal); if (wPagination != null) { - Pair, Integer> listWPagination = new Pair, Integer>(wPagination, vpcs.size()); + final Pair, Integer> listWPagination = new Pair, Integer>(wPagination, vpcs.size()); return listWPagination; } return new Pair, Integer>(vpcs, vpcs.size()); @@ -1134,7 +1134,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } protected List getSupportedServices() { - List services = new ArrayList(); + final List services = new ArrayList(); services.add(Network.Service.Dhcp); services.add(Network.Service.Dns); services.add(Network.Service.UserData); @@ -1149,15 +1149,15 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } @Override - public boolean startVpc(long vpcId, boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - CallContext ctx = CallContext.current(); - Account caller = ctx.getCallingAccount(); - User callerUser = _accountMgr.getActiveUser(ctx.getCallingUserId()); + public boolean startVpc(final long vpcId, final boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + final CallContext ctx = CallContext.current(); + final Account caller = ctx.getCallingAccount(); + final User callerUser = _accountMgr.getActiveUser(ctx.getCallingUserId()); //check if vpc exists - Vpc vpc = getActiveVpc(vpcId); + final Vpc vpc = getActiveVpc(vpcId); if (vpc == null) { - InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find Enabled VPC by id specified"); + final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find Enabled VPC by id specified"); ex.addProxyObject(String.valueOf(vpcId), "VPC"); throw ex; } @@ -1165,10 +1165,10 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis //permission check _accountMgr.checkAccess(caller, null, false, vpc); - DataCenter dc = _entityMgr.findById(DataCenter.class, vpc.getZoneId()); + final DataCenter dc = _entityMgr.findById(DataCenter.class, vpc.getZoneId()); - DeployDestination dest = new DeployDestination(dc, null, null, null); - ReservationContext context = new ReservationContextImpl(null, null, callerUser, _accountMgr.getAccount(vpc.getAccountId())); + final DeployDestination dest = new DeployDestination(dc, null, null, null); + final ReservationContext context = new ReservationContextImpl(null, null, callerUser, _accountMgr.getAccount(vpc.getAccountId())); boolean result = true; try { @@ -1176,7 +1176,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis s_logger.warn("Failed to start vpc " + vpc); result = false; } - } catch (Exception ex) { + } catch (final Exception ex) { s_logger.warn("Failed to start vpc " + vpc + " due to ", ex); result = false; } finally { @@ -1193,12 +1193,12 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis return result; } - protected boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, - InsufficientCapacityException { + protected boolean startVpc(final Vpc vpc, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { //deploy provider boolean success = true; - List providersToImplement = getVpcProviders(vpc.getId()); - for (VpcProvider element : getVpcElements()) { + final List providersToImplement = getVpcProviders(vpc.getId()); + for (final VpcProvider element : getVpcElements()) { if (providersToImplement.contains(element.getProvider())) { if (element.implementVpc(vpc, dest, context)) { s_logger.debug("Vpc " + vpc + " has started succesfully"); @@ -1212,12 +1212,12 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } @Override - public boolean shutdownVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException { - CallContext ctx = CallContext.current(); - Account caller = ctx.getCallingAccount(); + public boolean shutdownVpc(final long vpcId) throws ConcurrentOperationException, ResourceUnavailableException { + final CallContext ctx = CallContext.current(); + final Account caller = ctx.getCallingAccount(); //check if vpc exists - Vpc vpc = _vpcDao.findById(vpcId); + final Vpc vpc = _vpcDao.findById(vpcId); if (vpc == null) { throw new InvalidParameterValueException("Unable to find vpc by id " + vpcId); } @@ -1230,9 +1230,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis //TODO - shutdown all vpc resources here (ACLs, gateways, etc) boolean success = true; - List providersToImplement = getVpcProviders(vpc.getId()); - ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(ctx.getCallingUserId()), caller); - for (VpcProvider element : getVpcElements()) { + final List providersToImplement = getVpcProviders(vpc.getId()); + final ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(ctx.getCallingUserId()), caller); + for (final VpcProvider element : getVpcElements()) { if (providersToImplement.contains(element.getProvider())) { if (element.shutdownVpc(vpc, context)) { s_logger.debug("Vpc " + vpc + " has been shutdown succesfully"); @@ -1248,10 +1248,10 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @DB @Override - public void validateNtwkOffForNtwkInVpc(Long networkId, long newNtwkOffId, String newCidr, String newNetworkDomain, Vpc vpc, String gateway, Account networkOwner, - Long aclId) { + public void validateNtwkOffForNtwkInVpc(final Long networkId, final long newNtwkOffId, final String newCidr, final String newNetworkDomain, final Vpc vpc, final String gateway, final Account networkOwner, + final Long aclId) { - NetworkOffering guestNtwkOff = _entityMgr.findById(NetworkOffering.class, newNtwkOffId); + final NetworkOffering guestNtwkOff = _entityMgr.findById(NetworkOffering.class, newNtwkOffId); if (guestNtwkOff == null) { throw new InvalidParameterValueException("Can't find network offering by id specified"); @@ -1263,15 +1263,15 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } //2) validate network offering attributes - List svcs = _ntwkModel.listNetworkOfferingServices(guestNtwkOff.getId()); + final List svcs = _ntwkModel.listNetworkOfferingServices(guestNtwkOff.getId()); validateNtwkOffForVpc(guestNtwkOff, svcs); //3) Check services/providers against VPC providers - List networkProviders = _ntwkOffServiceDao.listByNetworkOfferingId(guestNtwkOff.getId()); + final List networkProviders = _ntwkOffServiceDao.listByNetworkOfferingId(guestNtwkOff.getId()); - for (NetworkOfferingServiceMapVO nSvcVO : networkProviders) { - String pr = nSvcVO.getProvider(); - String service = nSvcVO.getService(); + for (final NetworkOfferingServiceMapVO nSvcVO : networkProviders) { + final String pr = nSvcVO.getProvider(); + final String service = nSvcVO.getService(); if (_vpcOffServiceDao.findByServiceProviderAndOfferingId(service, pr, vpc.getVpcOfferingId()) == null) { throw new InvalidParameterValueException("Service/provider combination " + service + "/" + pr + " is not supported by VPC " + vpc); } @@ -1279,14 +1279,16 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis //4) Only one network in the VPC can support public LB inside the VPC. Internal LB can be supported on multiple VPC tiers if (_ntwkModel.areServicesSupportedByNetworkOffering(guestNtwkOff.getId(), Service.Lb) && guestNtwkOff.getPublicLb()) { - List networks = getVpcNetworks(vpc.getId()); - for (Network network : networks) { + final List networks = getVpcNetworks(vpc.getId()); + for (final Network network : networks) { if (networkId != null && network.getId() == networkId.longValue()) { //skip my own network continue; } else { - NetworkOffering otherOff = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId()); - if (_ntwkModel.areServicesSupportedInNetwork(network.getId(), Service.Lb) && otherOff.getPublicLb()) { + final NetworkOffering otherOff = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId()); + //throw only if networks have different offerings with public lb support + if (_ntwkModel.areServicesSupportedInNetwork(network.getId(), Service.Lb) && otherOff.getPublicLb() && + guestNtwkOff.getId() != otherOff.getId()) { throw new InvalidParameterValueException("Public LB service is already supported " + "by network " + network + " in VPC " + vpc); } } @@ -1294,17 +1296,17 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } //5) When aclId is provided, verify that ACLProvider is supported by network offering - if (aclId != null && (!_ntwkModel.areServicesSupportedByNetworkOffering(guestNtwkOff.getId(), Service.NetworkACL))) { + if (aclId != null && !_ntwkModel.areServicesSupportedByNetworkOffering(guestNtwkOff.getId(), Service.NetworkACL)) { throw new InvalidParameterValueException("Cannot apply NetworkACL. Network Offering does not support NetworkACL service"); } } @Override - public void validateNtwkOffForVpc(NetworkOffering guestNtwkOff, List supportedSvcs) { + public void validateNtwkOffForVpc(final NetworkOffering guestNtwkOff, final List supportedSvcs) { //1) in current release, only vpc provider is supported by Vpc offering - List providers = _ntwkModel.getNtwkOffDistinctProviders(guestNtwkOff.getId()); - for (Provider provider : providers) { + final List providers = _ntwkModel.getNtwkOffDistinctProviders(guestNtwkOff.getId()); + for (final Provider provider : providers) { if (!supportedProviders.contains(provider)) { throw new InvalidParameterValueException("Provider of type " + provider.getName() + " is not supported for network offerings that can be used in VPC"); } @@ -1322,14 +1324,14 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis if (guestNtwkOff.getRedundantRouter()) { throw new InvalidParameterValueException("No redunant router support when network belnogs to VPC"); } - */ + */ //4) Conserve mode should be off if (guestNtwkOff.isConserveMode()) { throw new InvalidParameterValueException("Only networks with conserve mode Off can belong to VPC"); } - //5) If Netscaler is LB provider make sure it is in dedicated mode + //5) If Netscaler is LB provider make sure it is in dedicated mode if (providers.contains(Provider.Netscaler) && !guestNtwkOff.getDedicatedLB()) { throw new InvalidParameterValueException("Netscaler only with Dedicated LB can belong to VPC"); } @@ -1341,58 +1343,58 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis Transaction.execute(new TransactionCallbackNoReturn() { @Override - public void doInTransactionWithoutResult(TransactionStatus status) { - Vpc locked = _vpcDao.acquireInLockTable(vpc.getId()); - if (locked == null) { - throw new CloudRuntimeException("Unable to acquire lock on " + vpc); - } + public void doInTransactionWithoutResult(final TransactionStatus status) { + final Vpc locked = _vpcDao.acquireInLockTable(vpc.getId()); + if (locked == null) { + throw new CloudRuntimeException("Unable to acquire lock on " + vpc); + } - try { - //check number of active networks in vpc - if (_ntwkDao.countVpcNetworks(vpc.getId()) >= _maxNetworks) { + try { + //check number of active networks in vpc + if (_ntwkDao.countVpcNetworks(vpc.getId()) >= _maxNetworks) { throw new CloudRuntimeException("Number of networks per VPC can't extend " + _maxNetworks + "; increase it using global config " + - Config.VpcMaxNetworks); - } + Config.VpcMaxNetworks); + } - //1) CIDR is required - if (cidr == null) { - throw new InvalidParameterValueException("Gateway/netmask are required when create network for VPC"); - } + //1) CIDR is required + if (cidr == null) { + throw new InvalidParameterValueException("Gateway/netmask are required when create network for VPC"); + } - //2) Network cidr should be within vpcCidr - if (!NetUtils.isNetworkAWithinNetworkB(cidr, vpc.getCidr())) { - throw new InvalidParameterValueException("Network cidr " + cidr + " is not within vpc " + vpc + " cidr"); - } + //2) Network cidr should be within vpcCidr + if (!NetUtils.isNetworkAWithinNetworkB(cidr, vpc.getCidr())) { + throw new InvalidParameterValueException("Network cidr " + cidr + " is not within vpc " + vpc + " cidr"); + } - //3) Network cidr shouldn't cross the cidr of other vpc network cidrs - List ntwks = _ntwkDao.listByVpc(vpc.getId()); - for (Network ntwk : ntwks) { - assert (cidr != null) : "Why the network cidr is null when it belongs to vpc?"; + //3) Network cidr shouldn't cross the cidr of other vpc network cidrs + final List ntwks = _ntwkDao.listByVpc(vpc.getId()); + for (final Network ntwk : ntwks) { + assert cidr != null : "Why the network cidr is null when it belongs to vpc?"; if (NetUtils.isNetworkAWithinNetworkB(ntwk.getCidr(), cidr) || NetUtils.isNetworkAWithinNetworkB(cidr, ntwk.getCidr())) { throw new InvalidParameterValueException("Network cidr " + cidr + " crosses other network cidr " + ntwk + " belonging to the same vpc " + vpc); + } + } + + //4) vpc and network should belong to the same owner + if (vpc.getAccountId() != networkOwner.getId()) { + throw new InvalidParameterValueException("Vpc " + vpc + " owner is different from the network owner " + networkOwner); + } + + //5) network domain should be the same as VPC's + if (!networkDomain.equalsIgnoreCase(vpc.getNetworkDomain())) { + throw new InvalidParameterValueException("Network domain of the new network should match network" + " domain of vpc " + vpc); + } + + //6) gateway should never be equal to the cidr subnet + if (NetUtils.getCidrSubNet(cidr).equalsIgnoreCase(gateway)) { + throw new InvalidParameterValueException("Invalid gateway specified. It should never be equal to the cidr subnet value"); + } + } finally { + s_logger.debug("Releasing lock for " + locked); + _vpcDao.releaseFromLockTable(locked.getId()); } } - - //4) vpc and network should belong to the same owner - if (vpc.getAccountId() != networkOwner.getId()) { - throw new InvalidParameterValueException("Vpc " + vpc + " owner is different from the network owner " + networkOwner); - } - - //5) network domain should be the same as VPC's - if (!networkDomain.equalsIgnoreCase(vpc.getNetworkDomain())) { - throw new InvalidParameterValueException("Network domain of the new network should match network" + " domain of vpc " + vpc); - } - - //6) gateway should never be equal to the cidr subnet - if (NetUtils.getCidrSubNet(cidr).equalsIgnoreCase(gateway)) { - throw new InvalidParameterValueException("Invalid gateway specified. It should never be equal to the cidr subnet value"); - } - } finally { - s_logger.debug("Releasing lock for " + locked); - _vpcDao.releaseFromLockTable(locked.getId()); - } - } }); } @@ -1411,13 +1413,13 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } @Override - public List getVpcsForAccount(long accountId) { - List vpcs = new ArrayList(); + public List getVpcsForAccount(final long accountId) { + final List vpcs = new ArrayList(); vpcs.addAll(_vpcDao.listByAccountId(accountId)); return vpcs; } - public boolean cleanupVpcResources(long vpcId, Account caller, long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException { + public boolean cleanupVpcResources(final long vpcId, final Account caller, final long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException { s_logger.debug("Cleaning up resources for vpc id=" + vpcId); boolean success = true; @@ -1428,9 +1430,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis _s2sVpnMgr.cleanupVpnGatewayByVpc(vpcId); //2) release all ip addresses - List ipsToRelease = _ipAddressDao.listByAssociatedVpc(vpcId, null); + final List ipsToRelease = _ipAddressDao.listByAssociatedVpc(vpcId, null); s_logger.debug("Releasing ips for vpc id=" + vpcId + " as a part of vpc cleanup"); - for (IPAddressVO ipToRelease : ipsToRelease) { + for (final IPAddressVO ipToRelease : ipsToRelease) { if (ipToRelease.isPortable()) { // portable IP address are associated with owner, until explicitly requested to be disassociated. // so as part of VPC clean up just break IP association with VPC @@ -1460,9 +1462,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } //4) Delete private gateways - List gateways = getVpcPrivateGateways(vpcId); + final List gateways = getVpcPrivateGateways(vpcId); if (gateways != null) { - for (PrivateGateway gateway : gateways) { + for (final PrivateGateway gateway : gateways) { if (gateway != null) { s_logger.debug("Deleting private gateway " + gateway + " as a part of vpc " + vpcId + " resources cleanup"); if (!deleteVpcPrivateGateway(gateway.getId())) { @@ -1480,13 +1482,13 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @Override @ActionEvent(eventType = EventTypes.EVENT_VPC_RESTART, eventDescription = "restarting vpc") - public boolean restartVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - Account caller = CallContext.current().getCallingAccount(); + public boolean restartVpc(final long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + final Account caller = CallContext.current().getCallingAccount(); // Verify input parameters - Vpc vpc = getActiveVpc(vpcId); + final Vpc vpc = getActiveVpc(vpcId); if (vpc == null) { - InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find Enabled VPC by id specified"); + final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find Enabled VPC by id specified"); ex.addProxyObject(String.valueOf(vpcId), "VPC"); throw ex; } @@ -1513,19 +1515,19 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis return true; } finally { s_logger.debug("Updating VPC " + vpc + " with restartRequired=" + restartRequired); - VpcVO vo = _vpcDao.findById(vpcId); + final VpcVO vo = _vpcDao.findById(vpcId); vo.setRestartRequired(restartRequired); _vpcDao.update(vpc.getId(), vo); } } @Override - public List getVpcPrivateGateways(long vpcId) { - List gateways = _vpcGatewayDao.listByVpcIdAndType(vpcId, VpcGateway.Type.Private); + public List getVpcPrivateGateways(final long vpcId) { + final List gateways = _vpcGatewayDao.listByVpcIdAndType(vpcId, VpcGateway.Type.Private); if (gateways != null) { - List pvtGateway = new ArrayList(); - for (VpcGatewayVO gateway : gateways) { + final List pvtGateway = new ArrayList(); + for (final VpcGatewayVO gateway : gateways) { pvtGateway.add(getPrivateGatewayProfile(gateway)); } return pvtGateway; @@ -1535,8 +1537,8 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } @Override - public PrivateGateway getVpcPrivateGateway(long id) { - VpcGateway gateway = _vpcGatewayDao.findById(id); + public PrivateGateway getVpcPrivateGateway(final long id) { + final VpcGateway gateway = _vpcGatewayDao.findById(id); if (gateway == null || gateway.getType() != VpcGateway.Type.Private) { return null; @@ -1544,8 +1546,8 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis return getPrivateGatewayProfile(gateway); } - protected PrivateGateway getPrivateGatewayProfile(VpcGateway gateway) { - Network network = _ntwkModel.getNetwork(gateway.getNetworkId()); + protected PrivateGateway getPrivateGatewayProfile(final VpcGateway gateway) { + final Network network = _ntwkModel.getNetwork(gateway.getNetworkId()); return new PrivateGatewayProfile(gateway, network.getPhysicalNetworkId()); } @@ -1553,13 +1555,13 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @DB @ActionEvent(eventType = EventTypes.EVENT_PRIVATE_GATEWAY_CREATE, eventDescription = "creating VPC private gateway", create = true) public PrivateGateway createVpcPrivateGateway(final long vpcId, Long physicalNetworkId, final String broadcastUri, final String ipAddress, final String gateway, - final String netmask, final long gatewayOwnerId, final Long networkOfferingId, final Boolean isSourceNat, final Long aclId) throws ResourceAllocationException, + final String netmask, final long gatewayOwnerId, final Long networkOfferingId, final Boolean isSourceNat, final Long aclId) throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException { //Validate parameters final Vpc vpc = getActiveVpc(vpcId); if (vpc == null) { - InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find Enabled VPC by id specified"); + final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find Enabled VPC by id specified"); ex.addProxyObject(String.valueOf(vpcId), "VPC"); throw ex; } @@ -1567,7 +1569,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis PhysicalNetwork physNet = null; //Validate physical network if (physicalNetworkId == null) { - List pNtwks = _ntwkModel.getPhysicalNtwksSupportingTrafficType(vpc.getZoneId(), TrafficType.Guest); + final List pNtwks = _ntwkModel.getPhysicalNtwksSupportingTrafficType(vpc.getZoneId(), TrafficType.Guest); if (pNtwks.isEmpty() || pNtwks.size() != 1) { throw new InvalidParameterValueException("Physical network can't be determined; pass physical network id"); } @@ -1586,81 +1588,81 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis try { gatewayVO = Transaction.execute(new TransactionCallbackWithException() { @Override - public VpcGatewayVO doInTransaction(TransactionStatus status) throws ResourceAllocationException, ConcurrentOperationException, - InsufficientCapacityException { - s_logger.debug("Creating Private gateway for VPC " + vpc); - //1) create private network unless it is existing and lswitch'd - Network privateNtwk = null; - if (BroadcastDomainType.getSchemeValue(BroadcastDomainType.fromString(broadcastUri)) == BroadcastDomainType.Lswitch) { - String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask); + public VpcGatewayVO doInTransaction(final TransactionStatus status) throws ResourceAllocationException, ConcurrentOperationException, + InsufficientCapacityException { + s_logger.debug("Creating Private gateway for VPC " + vpc); + //1) create private network unless it is existing and lswitch'd + Network privateNtwk = null; + if (BroadcastDomainType.getSchemeValue(BroadcastDomainType.fromString(broadcastUri)) == BroadcastDomainType.Lswitch) { + final String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask); privateNtwk = _ntwkDao.getPrivateNetwork(broadcastUri, cidr, gatewayOwnerId, dcId, networkOfferingId); // if the dcid is different we get no network so next we try to create it - } - if (privateNtwk == null) { - s_logger.info("creating new network for vpc " + vpc + " using broadcast uri: " + broadcastUri); - String networkName = "vpc-" + vpc.getName() + "-privateNetwork"; + } + if (privateNtwk == null) { + s_logger.info("creating new network for vpc " + vpc + " using broadcast uri: " + broadcastUri); + final String networkName = "vpc-" + vpc.getName() + "-privateNetwork"; privateNtwk = - _ntwkSvc.createPrivateNetwork(networkName, networkName, physicalNetworkIdFinal, broadcastUri, ipAddress, null, gateway, netmask, - gatewayOwnerId, vpcId, isSourceNat, networkOfferingId); - } else { // create the nic/ip as createPrivateNetwork doesn''t do that work for us now + _ntwkSvc.createPrivateNetwork(networkName, networkName, physicalNetworkIdFinal, broadcastUri, ipAddress, null, gateway, netmask, + gatewayOwnerId, vpcId, isSourceNat, networkOfferingId); + } else { // create the nic/ip as createPrivateNetwork doesn''t do that work for us now s_logger.info("found and using existing network for vpc " + vpc + ": " + broadcastUri); - DataCenterVO dc = _dcDao.lockRow(physNetFinal.getDataCenterId(), true); + final DataCenterVO dc = _dcDao.lockRow(physNetFinal.getDataCenterId(), true); - //add entry to private_ip_address table - PrivateIpVO privateIp = _privateIpDao.findByIpAndSourceNetworkId(privateNtwk.getId(), ipAddress); - if (privateIp != null) { + //add entry to private_ip_address table + PrivateIpVO privateIp = _privateIpDao.findByIpAndSourceNetworkId(privateNtwk.getId(), ipAddress); + if (privateIp != null) { throw new InvalidParameterValueException("Private ip address " + ipAddress + " already used for private gateway" + " in zone " + - _entityMgr.findById(DataCenter.class, dcId).getName()); - } + _entityMgr.findById(DataCenter.class, dcId).getName()); + } - Long mac = dc.getMacAddress(); - Long nextMac = mac + 1; - dc.setMacAddress(nextMac); + final Long mac = dc.getMacAddress(); + final Long nextMac = mac + 1; + dc.setMacAddress(nextMac); s_logger.info("creating private ip adress for vpc (" + ipAddress + ", " + privateNtwk.getId() + ", " + nextMac + ", " + vpcId + ", " + isSourceNat + ")"); privateIp = new PrivateIpVO(ipAddress, privateNtwk.getId(), nextMac, vpcId, isSourceNat); - _privateIpDao.persist(privateIp); + _privateIpDao.persist(privateIp); - _dcDao.update(dc.getId(), dc); - } + _dcDao.update(dc.getId(), dc); + } - long networkAclId = NetworkACL.DEFAULT_DENY; - if (aclId != null) { - NetworkACLVO aclVO = _networkAclDao.findById(aclId); + long networkAclId = NetworkACL.DEFAULT_DENY; + if (aclId != null) { + final NetworkACLVO aclVO = _networkAclDao.findById(aclId); if (aclVO == null) { - throw new InvalidParameterValueException("Invalid network acl id passed "); - } - if ((aclVO.getVpcId() != vpcId) && !(aclId == NetworkACL.DEFAULT_DENY || aclId == NetworkACL.DEFAULT_ALLOW)) { - throw new InvalidParameterValueException("Private gateway and network acl are not in the same vpc"); - } + throw new InvalidParameterValueException("Invalid network acl id passed "); + } + if (aclVO.getVpcId() != vpcId && !(aclId == NetworkACL.DEFAULT_DENY || aclId == NetworkACL.DEFAULT_ALLOW)) { + throw new InvalidParameterValueException("Private gateway and network acl are not in the same vpc"); + } - networkAclId = aclId; - } + networkAclId = aclId; + } - { // experimental block, this is a hack - // set vpc id in network to null - // might be needed for all types of broadcast domains - // the ugly hack is that vpc gateway nets are created as guest network - // while they are not. - // A more permanent solution would be to define a type of 'gatewaynetwork' - // so that handling code is not mixed between the two - NetworkVO gatewaynet = _ntwkDao.findById(privateNtwk.getId()); - gatewaynet.setVpcId(null); - _ntwkDao.persist(gatewaynet); - } + { // experimental block, this is a hack + // set vpc id in network to null + // might be needed for all types of broadcast domains + // the ugly hack is that vpc gateway nets are created as guest network + // while they are not. + // A more permanent solution would be to define a type of 'gatewaynetwork' + // so that handling code is not mixed between the two + final NetworkVO gatewaynet = _ntwkDao.findById(privateNtwk.getId()); + gatewaynet.setVpcId(vpcId); + _ntwkDao.persist(gatewaynet); + } - //2) create gateway entry - VpcGatewayVO gatewayVO = - new VpcGatewayVO(ipAddress, VpcGateway.Type.Private, vpcId, privateNtwk.getDataCenterId(), privateNtwk.getId(), broadcastUri, gateway, netmask, - vpc.getAccountId(), vpc.getDomainId(), isSourceNat, networkAclId); - _vpcGatewayDao.persist(gatewayVO); + //2) create gateway entry + final VpcGatewayVO gatewayVO = + new VpcGatewayVO(ipAddress, VpcGateway.Type.Private, vpcId, privateNtwk.getDataCenterId(), privateNtwk.getId(), broadcastUri, gateway, netmask, + vpc.getAccountId(), vpc.getDomainId(), isSourceNat, networkAclId); + _vpcGatewayDao.persist(gatewayVO); - s_logger.debug("Created vpc gateway entry " + gatewayVO); + s_logger.debug("Created vpc gateway entry " + gatewayVO); return gatewayVO; } }); - } catch (Exception e) { + } catch (final Exception e) { ExceptionUtil.rethrowRuntime(e); ExceptionUtil.rethrow(e, InsufficientCapacityException.class); ExceptionUtil.rethrow(e, ResourceAllocationException.class); @@ -1673,15 +1675,15 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @Override @ActionEvent(eventType = EventTypes.EVENT_PRIVATE_GATEWAY_CREATE, eventDescription = "Applying VPC private gateway", async = true) - public PrivateGateway applyVpcPrivateGateway(long gatewayId, boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException { - VpcGatewayVO vo = _vpcGatewayDao.findById(gatewayId); + public PrivateGateway applyVpcPrivateGateway(final long gatewayId, final boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException { + final VpcGatewayVO vo = _vpcGatewayDao.findById(gatewayId); boolean success = true; try { - List providersToImplement = getVpcProviders(vo.getVpcId()); + final List providersToImplement = getVpcProviders(vo.getVpcId()); - PrivateGateway gateway = getVpcPrivateGateway(gatewayId); - for (VpcProvider provider : getVpcElements()) { + final PrivateGateway gateway = getVpcPrivateGateway(gatewayId); + for (final VpcProvider provider : getVpcElements()) { if (providersToImplement.contains(provider.getProvider())) { if (!provider.createPrivateGateway(gateway)) { success = false; @@ -1720,7 +1722,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @Override @ActionEvent(eventType = EventTypes.EVENT_PRIVATE_GATEWAY_DELETE, eventDescription = "deleting private gateway") @DB - public boolean deleteVpcPrivateGateway(long gatewayId) throws ConcurrentOperationException, ResourceUnavailableException { + public boolean deleteVpcPrivateGateway(final long gatewayId) throws ConcurrentOperationException, ResourceUnavailableException { final VpcGatewayVO gatewayVO = _vpcGatewayDao.acquireInLockTable(gatewayId); if (gatewayVO == null || gatewayVO.getType() != VpcGateway.Type.Private) { @@ -1730,24 +1732,24 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis try { Transaction.execute(new TransactionCallbackNoReturn() { @Override - public void doInTransactionWithoutResult(TransactionStatus status) { - //don't allow to remove gateway when there are static routes associated with it - long routeCount = _staticRouteDao.countRoutesByGateway(gatewayVO.getId()); - if (routeCount > 0) { - throw new CloudRuntimeException("Can't delete private gateway " + gatewayVO + " as it has " + routeCount + - " static routes applied. Remove the routes first"); - } + public void doInTransactionWithoutResult(final TransactionStatus status) { + //don't allow to remove gateway when there are static routes associated with it + final long routeCount = _staticRouteDao.countRoutesByGateway(gatewayVO.getId()); + if (routeCount > 0) { + throw new CloudRuntimeException("Can't delete private gateway " + gatewayVO + " as it has " + routeCount + + " static routes applied. Remove the routes first"); + } - gatewayVO.setState(VpcGateway.State.Deleting); - _vpcGatewayDao.update(gatewayVO.getId(), gatewayVO); - s_logger.debug("Marked gateway " + gatewayVO + " with state " + VpcGateway.State.Deleting); + gatewayVO.setState(VpcGateway.State.Deleting); + _vpcGatewayDao.update(gatewayVO.getId(), gatewayVO); + s_logger.debug("Marked gateway " + gatewayVO + " with state " + VpcGateway.State.Deleting); } }); //1) delete the gateway on the backend - List providersToImplement = getVpcProviders(gatewayVO.getVpcId()); - PrivateGateway gateway = getVpcPrivateGateway(gatewayId); - for (VpcProvider provider : getVpcElements()) { + final List providersToImplement = getVpcProviders(gatewayVO.getVpcId()); + final PrivateGateway gateway = getVpcPrivateGateway(gatewayId); + for (final VpcProvider provider : getVpcElements()) { if (providersToImplement.contains(provider.getProvider())) { if (provider.deletePrivateGateway(gateway)) { s_logger.debug("Private gateway " + gateway + " was applied succesfully on the backend"); @@ -1778,7 +1780,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis final long networkId = gateway.getNetworkId(); boolean deleteNetwork = true; - List privateIps = _privateIpDao.listByNetworkId(networkId); + final List privateIps = _privateIpDao.listByNetworkId(networkId); if (privateIps.size() > 1 || !privateIps.get(0).getIpAddress().equalsIgnoreCase(gateway.getIp4Address())) { s_logger.debug("Not removing network id=" + gateway.getNetworkId() + " as it has private ip addresses for other gateways"); deleteNetwork = false; @@ -1789,23 +1791,23 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis final boolean deleteNetworkFinal = deleteNetwork; Transaction.execute(new TransactionCallbackNoReturn() { @Override - public void doInTransactionWithoutResult(TransactionStatus status) { - PrivateIpVO ip = _privateIpDao.findByIpAndVpcId(gateway.getVpcId(), gateway.getIp4Address()); - if (ip != null) { - _privateIpDao.remove(ip.getId()); - s_logger.debug("Deleted private ip " + ip); - } + public void doInTransactionWithoutResult(final TransactionStatus status) { + final PrivateIpVO ip = _privateIpDao.findByIpAndVpcId(gateway.getVpcId(), gateway.getIp4Address()); + if (ip != null) { + _privateIpDao.remove(ip.getId()); + s_logger.debug("Deleted private ip " + ip); + } if (deleteNetworkFinal) { - User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId()); - Account owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM); - ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner); + final User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId()); + final Account owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM); + final ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner); _ntwkMgr.destroyNetwork(networkId, context, false); - s_logger.debug("Deleted private network id=" + networkId); - } + s_logger.debug("Deleted private network id=" + networkId); + } - _vpcGatewayDao.remove(gateway.getId()); - s_logger.debug("Deleted private gateway " + gateway); + _vpcGatewayDao.remove(gateway.getId()); + s_logger.debug("Deleted private gateway " + gateway); } }); @@ -1813,38 +1815,38 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } @Override - public Pair, Integer> listPrivateGateway(ListPrivateGatewaysCmd cmd) { - String ipAddress = cmd.getIpAddress(); - String vlan = cmd.getVlan(); - Long vpcId = cmd.getVpcId(); - Long id = cmd.getId(); + public Pair, Integer> listPrivateGateway(final ListPrivateGatewaysCmd cmd) { + final String ipAddress = cmd.getIpAddress(); + final String vlan = cmd.getVlan(); + final Long vpcId = cmd.getVpcId(); + final Long id = cmd.getId(); Boolean isRecursive = cmd.isRecursive(); - Boolean listAll = cmd.listAll(); + final Boolean listAll = cmd.listAll(); Long domainId = cmd.getDomainId(); - String accountName = cmd.getAccountName(); - Account caller = CallContext.current().getCallingAccount(); - List permittedAccounts = new ArrayList(); - String state = cmd.getState(); - Long projectId = cmd.getProjectId(); + final String accountName = cmd.getAccountName(); + final Account caller = CallContext.current().getCallingAccount(); + final List permittedAccounts = new ArrayList(); + final String state = cmd.getState(); + final Long projectId = cmd.getProjectId(); - Filter searchFilter = new Filter(VpcGatewayVO.class, "id", false, cmd.getStartIndex(), cmd.getPageSizeVal()); - Ternary domainIdRecursiveListProject = new Ternary domainIdRecursiveListProject = new Ternary(domainId, isRecursive, null); _accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject, listAll, false); domainId = domainIdRecursiveListProject.first(); isRecursive = domainIdRecursiveListProject.second(); - ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); + final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); - SearchBuilder sb = _vpcGatewayDao.createSearchBuilder(); + final SearchBuilder sb = _vpcGatewayDao.createSearchBuilder(); _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); if (vlan != null) { - SearchBuilder ntwkSearch = _ntwkDao.createSearchBuilder(); + final SearchBuilder ntwkSearch = _ntwkDao.createSearchBuilder(); ntwkSearch.and("vlan", ntwkSearch.entity().getBroadcastUri(), SearchCriteria.Op.EQ); sb.join("networkSearch", ntwkSearch, sb.entity().getNetworkId(), ntwkSearch.entity().getId(), JoinBuilder.JoinType.INNER); } - SearchCriteria sc = sb.create(); + final SearchCriteria sc = sb.create(); _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); if (id != null) { sc.addAnd("id", Op.EQ, id); @@ -1866,9 +1868,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis sc.setJoinParameters("networkSearch", "vlan", BroadcastDomainType.Vlan.toUri(vlan)); } - Pair, Integer> vos = _vpcGatewayDao.searchAndCount(sc, searchFilter); - List privateGtws = new ArrayList(vos.first().size()); - for (VpcGateway vo : vos.first()) { + final Pair, Integer> vos = _vpcGatewayDao.searchAndCount(sc, searchFilter); + final List privateGtws = new ArrayList(vos.first().size()); + for (final VpcGateway vo : vos.first()) { privateGtws.add(getPrivateGatewayProfile(vo)); } @@ -1876,22 +1878,22 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } @Override - public StaticRoute getStaticRoute(long routeId) { + public StaticRoute getStaticRoute(final long routeId) { return _staticRouteDao.findById(routeId); } @Override - public boolean applyStaticRoutesForVpc(long vpcId) throws ResourceUnavailableException { - Account caller = CallContext.current().getCallingAccount(); - List routes = _staticRouteDao.listByVpcId(vpcId); + public boolean applyStaticRoutesForVpc(final long vpcId) throws ResourceUnavailableException { + final Account caller = CallContext.current().getCallingAccount(); + final List routes = _staticRouteDao.listByVpcId(vpcId); return applyStaticRoutes(routes, caller, true); } - protected boolean applyStaticRoutes(List routes, Account caller, boolean updateRoutesInDB) throws ResourceUnavailableException { - boolean success = true; - List staticRouteProfiles = new ArrayList(routes.size()); - Map gatewayMap = new HashMap(); - for (StaticRoute route : routes) { + protected boolean applyStaticRoutes(final List routes, final Account caller, final boolean updateRoutesInDB) throws ResourceUnavailableException { + final boolean success = true; + final List staticRouteProfiles = new ArrayList(routes.size()); + final Map gatewayMap = new HashMap(); + for (final StaticRoute route : routes) { VpcGateway gateway = gatewayMap.get(route.getVpcGatewayId()); if (gateway == null) { gateway = _vpcGatewayDao.findById(route.getVpcGatewayId()); @@ -1904,12 +1906,12 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis return false; } else { if (updateRoutesInDB) { - for (StaticRoute route : routes) { + for (final StaticRoute route : routes) { if (route.getState() == StaticRoute.State.Revoke) { _staticRouteDao.remove(route.getId()); s_logger.debug("Removed route " + route + " from the DB"); } else if (route.getState() == StaticRoute.State.Add) { - StaticRouteVO ruleVO = _staticRouteDao.findById(route.getId()); + final StaticRouteVO ruleVO = _staticRouteDao.findById(route.getId()); ruleVO.setState(StaticRoute.State.Active); _staticRouteDao.update(ruleVO.getId(), ruleVO); s_logger.debug("Marked route " + route + " with state " + StaticRoute.State.Active); @@ -1921,17 +1923,17 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis return success; } - protected boolean applyStaticRoutes(List routes) throws ResourceUnavailableException { + protected boolean applyStaticRoutes(final List routes) throws ResourceUnavailableException { if (routes.isEmpty()) { s_logger.debug("No static routes to apply"); return true; } - Vpc vpc = _vpcDao.findById(routes.get(0).getVpcId()); + final Vpc vpc = _vpcDao.findById(routes.get(0).getVpcId()); s_logger.debug("Applying static routes for vpc " + vpc); - String staticNatProvider = _vpcSrvcDao.getProviderForServiceInVpc(vpc.getId(), Service.StaticNat); + final String staticNatProvider = _vpcSrvcDao.getProviderForServiceInVpc(vpc.getId(), Service.StaticNat); - for (VpcProvider provider : getVpcElements()) { + for (final VpcProvider provider : getVpcElements()) { if (!(provider instanceof StaticNatServiceProvider && provider.getName().equalsIgnoreCase(staticNatProvider))) { continue; } @@ -1949,10 +1951,10 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @Override @ActionEvent(eventType = EventTypes.EVENT_STATIC_ROUTE_DELETE, eventDescription = "deleting static route") - public boolean revokeStaticRoute(long routeId) throws ResourceUnavailableException { - Account caller = CallContext.current().getCallingAccount(); + public boolean revokeStaticRoute(final long routeId) throws ResourceUnavailableException { + final Account caller = CallContext.current().getCallingAccount(); - StaticRouteVO route = _staticRouteDao.findById(routeId); + final StaticRouteVO route = _staticRouteDao.findById(routeId); if (route == null) { throw new InvalidParameterValueException("Unable to find static route by id"); } @@ -1965,7 +1967,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } @DB - protected boolean revokeStaticRoutesForVpc(long vpcId, final Account caller) throws ResourceUnavailableException { + protected boolean revokeStaticRoutesForVpc(final long vpcId, final Account caller) throws ResourceUnavailableException { //get all static routes for the vpc final List routes = _staticRouteDao.listByVpcId(vpcId); s_logger.debug("Found " + routes.size() + " to revoke for the vpc " + vpcId); @@ -1973,10 +1975,10 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis //mark all of them as revoke Transaction.execute(new TransactionCallbackNoReturn() { @Override - public void doInTransactionWithoutResult(TransactionStatus status) { - for (StaticRouteVO route : routes) { - markStaticRouteForRevoke(route, caller); - } + public void doInTransactionWithoutResult(final TransactionStatus status) { + for (final StaticRouteVO route : routes) { + markStaticRouteForRevoke(route, caller); + } } }); return applyStaticRoutesForVpc(vpcId); @@ -1988,8 +1990,8 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @Override @DB @ActionEvent(eventType = EventTypes.EVENT_STATIC_ROUTE_CREATE, eventDescription = "creating static route", create = true) - public StaticRoute createStaticRoute(long gatewayId, final String cidr) throws NetworkRuleConflictException { - Account caller = CallContext.current().getCallingAccount(); + public StaticRoute createStaticRoute(final long gatewayId, final String cidr) throws NetworkRuleConflictException { + final Account caller = CallContext.current().getCallingAccount(); //parameters validation final VpcGateway gateway = _vpcGatewayDao.findById(gatewayId); @@ -2029,30 +2031,30 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis return Transaction.execute(new TransactionCallbackWithException() { @Override - public StaticRouteVO doInTransaction(TransactionStatus status) throws NetworkRuleConflictException { - StaticRouteVO newRoute = new StaticRouteVO(gateway.getId(), cidr, vpc.getId(), vpc.getAccountId(), vpc.getDomainId()); - s_logger.debug("Adding static route " + newRoute); - newRoute = _staticRouteDao.persist(newRoute); + public StaticRouteVO doInTransaction(final TransactionStatus status) throws NetworkRuleConflictException { + StaticRouteVO newRoute = new StaticRouteVO(gateway.getId(), cidr, vpc.getId(), vpc.getAccountId(), vpc.getDomainId()); + s_logger.debug("Adding static route " + newRoute); + newRoute = _staticRouteDao.persist(newRoute); - detectRoutesConflict(newRoute); + detectRoutesConflict(newRoute); - if (!_staticRouteDao.setStateToAdd(newRoute)) { - throw new CloudRuntimeException("Unable to update the state to add for " + newRoute); - } - CallContext.current().setEventDetails("Static route Id: " + newRoute.getId()); + if (!_staticRouteDao.setStateToAdd(newRoute)) { + throw new CloudRuntimeException("Unable to update the state to add for " + newRoute); + } + CallContext.current().setEventDetails("Static route Id: " + newRoute.getId()); - return newRoute; - } + return newRoute; + } }); } - protected boolean isCidrBlacklisted(String cidr, long zoneId) { - String routesStr = NetworkOrchestrationService.GuestDomainSuffix.valueIn(zoneId); + protected boolean isCidrBlacklisted(final String cidr, final long zoneId) { + final String routesStr = NetworkOrchestrationService.GuestDomainSuffix.valueIn(zoneId); if (routesStr != null && !routesStr.isEmpty()) { - String[] cidrBlackList = routesStr.split(","); + final String[] cidrBlackList = routesStr.split(","); if (cidrBlackList != null && cidrBlackList.length > 0) { - for (String blackListedRoute : cidrBlackList) { + for (final String blackListedRoute : cidrBlackList) { if (NetUtils.isNetworksOverlap(blackListedRoute, cidr)) { return true; } @@ -2064,29 +2066,29 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } @Override - public Pair, Integer> listStaticRoutes(ListStaticRoutesCmd cmd) { - Long id = cmd.getId(); - Long gatewayId = cmd.getGatewayId(); - Long vpcId = cmd.getVpcId(); + public Pair, Integer> listStaticRoutes(final ListStaticRoutesCmd cmd) { + final Long id = cmd.getId(); + final Long gatewayId = cmd.getGatewayId(); + final Long vpcId = cmd.getVpcId(); Long domainId = cmd.getDomainId(); Boolean isRecursive = cmd.isRecursive(); - Boolean listAll = cmd.listAll(); - String accountName = cmd.getAccountName(); - Account caller = CallContext.current().getCallingAccount(); - List permittedAccounts = new ArrayList(); - Map tags = cmd.getTags(); - Long projectId = cmd.getProjectId(); + final Boolean listAll = cmd.listAll(); + final String accountName = cmd.getAccountName(); + final Account caller = CallContext.current().getCallingAccount(); + final List permittedAccounts = new ArrayList(); + final Map tags = cmd.getTags(); + final Long projectId = cmd.getProjectId(); - Ternary domainIdRecursiveListProject = new Ternary domainIdRecursiveListProject = new Ternary(domainId, isRecursive, null); _accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject, listAll, false); domainId = domainIdRecursiveListProject.first(); isRecursive = domainIdRecursiveListProject.second(); - ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); - Filter searchFilter = new Filter(StaticRouteVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal()); + final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); + final Filter searchFilter = new Filter(StaticRouteVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal()); - SearchBuilder sb = _staticRouteDao.createSearchBuilder(); + final SearchBuilder sb = _staticRouteDao.createSearchBuilder(); _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); @@ -2094,7 +2096,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis sb.and("vpcGatewayId", sb.entity().getVpcGatewayId(), SearchCriteria.Op.EQ); if (tags != null && !tags.isEmpty()) { - SearchBuilder tagSearch = _resourceTagDao.createSearchBuilder(); + final SearchBuilder 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); @@ -2105,7 +2107,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER); } - SearchCriteria sc = sb.create(); + final SearchCriteria sc = sb.create(); _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); if (id != null) { sc.addAnd("id", Op.EQ, id); @@ -2122,25 +2124,25 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis if (tags != null && !tags.isEmpty()) { int count = 0; sc.setJoinParameters("tagSearch", "resourceType", ResourceObjectType.StaticRoute.toString()); - for (String key : tags.keySet()) { + for (final String key : tags.keySet()) { sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key); sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key)); count++; } } - Pair, Integer> result = _staticRouteDao.searchAndCount(sc, searchFilter); + final Pair, Integer> result = _staticRouteDao.searchAndCount(sc, searchFilter); return new Pair, Integer>(result.first(), result.second()); } - protected void detectRoutesConflict(StaticRoute newRoute) throws NetworkRuleConflictException { + protected void detectRoutesConflict(final StaticRoute newRoute) throws NetworkRuleConflictException { //Multiple private gateways can exist within Vpc. Check for conflicts for all static routes in Vpc //and not just the gateway - List routes = _staticRouteDao.listByVpcIdAndNotRevoked(newRoute.getVpcId()); - assert (routes.size() >= 1) : "For static routes, we now always first persist the route and then check for " - + "network conflicts so we should at least have one rule at this point."; + final List routes = _staticRouteDao.listByVpcIdAndNotRevoked(newRoute.getVpcId()); + assert routes.size() >= 1 : "For static routes, we now always first persist the route and then check for " + + "network conflicts so we should at least have one rule at this point."; - for (StaticRoute route : routes) { + for (final StaticRoute route : routes) { if (route.getId() == newRoute.getId()) { continue; // Skips my own route. } @@ -2151,7 +2153,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } } - protected void markStaticRouteForRevoke(StaticRouteVO route, Account caller) { + protected void markStaticRouteForRevoke(final StaticRouteVO route, final Account caller) { s_logger.debug("Revoking static route " + route); if (caller != null) { _accountMgr.checkAccess(caller, null, false, route); @@ -2173,7 +2175,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @Override protected void runInContext() { try { - GlobalLock lock = GlobalLock.getInternLock("VpcCleanup"); + final GlobalLock lock = GlobalLock.getInternLock("VpcCleanup"); if (lock == null) { s_logger.debug("Couldn't get the global lock"); return; @@ -2186,20 +2188,20 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis try { // Cleanup inactive VPCs - List inactiveVpcs = _vpcDao.listInactiveVpcs(); + final List inactiveVpcs = _vpcDao.listInactiveVpcs(); if (inactiveVpcs != null) { s_logger.info("Found " + inactiveVpcs.size() + " removed VPCs to cleanup"); - for (VpcVO vpc : inactiveVpcs) { + for (final VpcVO vpc : inactiveVpcs) { s_logger.debug("Cleaning up " + vpc); destroyVpc(vpc, _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM), User.UID_SYSTEM); } } - } catch (Exception e) { + } catch (final Exception e) { s_logger.error("Exception ", e); } finally { lock.unlock(); } - } catch (Exception e) { + } catch (final Exception e) { s_logger.error("Exception ", e); } } @@ -2210,10 +2212,10 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "associating Ip", async = true) public IpAddress associateIPToVpc(final long ipId, final long vpcId) throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException, ConcurrentOperationException { - Account caller = CallContext.current().getCallingAccount(); + final Account caller = CallContext.current().getCallingAccount(); Account owner = null; - IpAddress ipToAssoc = _ntwkModel.getIp(ipId); + final IpAddress ipToAssoc = _ntwkModel.getIp(ipId); if (ipToAssoc != null) { _accountMgr.checkAccess(caller, null, true, ipToAssoc); owner = _accountMgr.getAccount(ipToAssoc.getAllocatedToAccountId()); @@ -2222,7 +2224,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis return null; } - Vpc vpc = _vpcDao.findById(vpcId); + final Vpc vpc = _vpcDao.findById(vpcId); if (vpc == null) { throw new InvalidParameterValueException("Invalid VPC id provided"); } @@ -2240,16 +2242,16 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis final boolean isSourceNatFinal = isSourceNat; Transaction.execute(new TransactionCallbackNoReturn() { @Override - public void doInTransactionWithoutResult(TransactionStatus status) { - IPAddressVO ip = _ipAddressDao.findById(ipId); - //update ip address with networkId - ip.setVpcId(vpcId); + public void doInTransactionWithoutResult(final TransactionStatus status) { + final IPAddressVO ip = _ipAddressDao.findById(ipId); + //update ip address with networkId + ip.setVpcId(vpcId); ip.setSourceNat(isSourceNatFinal); - _ipAddressDao.update(ipId, ip); + _ipAddressDao.update(ipId, ip); - //mark ip as allocated - _ipAddrMgr.markPublicIpAsAllocated(ip); + //mark ip as allocated + _ipAddrMgr.markPublicIpAsAllocated(ip); } }); @@ -2259,8 +2261,8 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } @Override - public void unassignIPFromVpcNetwork(long ipId, long networkId) { - IPAddressVO ip = _ipAddressDao.findById(ipId); + public void unassignIPFromVpcNetwork(final long ipId, final long networkId) { + final IPAddressVO ip = _ipAddressDao.findById(ipId); if (isIpAllocatedToVpc(ip)) { return; } @@ -2271,12 +2273,12 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis s_logger.debug("Releasing VPC ip address " + ip + " from vpc network id=" + networkId); - long vpcId = ip.getVpcId(); + final long vpcId = ip.getVpcId(); boolean success = false; try { //unassign ip from the VPC router success = _ipAddrMgr.applyIpAssociations(_ntwkModel.getNetwork(networkId), true); - } catch (ResourceUnavailableException ex) { + } catch (final ResourceUnavailableException ex) { throw new CloudRuntimeException("Failed to apply ip associations for network id=" + networkId + " as a part of unassigning ip " + ipId + " from vpc", ex); } @@ -2291,20 +2293,20 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } @Override - public boolean isIpAllocatedToVpc(IpAddress ip) { - return (ip != null && ip.getVpcId() != null && (ip.isOneToOneNat() || !_firewallDao.listByIp(ip.getId()).isEmpty())); + public boolean isIpAllocatedToVpc(final IpAddress ip) { + return ip != null && ip.getVpcId() != null && (ip.isOneToOneNat() || !_firewallDao.listByIp(ip.getId()).isEmpty()); } @DB @Override - public Network createVpcGuestNetwork(long ntwkOffId, String name, String displayText, String gateway, String cidr, String vlanId, String networkDomain, - Account owner, Long domainId, PhysicalNetwork pNtwk, long zoneId, ACLType aclType, Boolean subdomainAccess, long vpcId, Long aclId, Account caller, - Boolean isDisplayNetworkEnabled) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { + public Network createVpcGuestNetwork(final long ntwkOffId, final String name, final String displayText, final String gateway, final String cidr, final String vlanId, String networkDomain, + final Account owner, final Long domainId, final PhysicalNetwork pNtwk, final long zoneId, final ACLType aclType, final Boolean subdomainAccess, final long vpcId, final Long aclId, final Account caller, + final Boolean isDisplayNetworkEnabled) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { - Vpc vpc = getActiveVpc(vpcId); + final Vpc vpc = getActiveVpc(vpcId); if (vpc == null) { - InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find Enabled VPC "); + final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find Enabled VPC "); ex.addProxyObject(String.valueOf(vpcId), "VPC"); throw ex; } @@ -2322,9 +2324,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis validateNtwkOffForNtwkInVpc(null, ntwkOffId, cidr, networkDomain, vpc, gateway, owner, aclId); //2) Create network - Network guestNetwork = - _ntwkMgr.createGuestNetwork(ntwkOffId, name, displayText, gateway, cidr, vlanId, networkDomain, owner, domainId, pNtwk, zoneId, aclType, subdomainAccess, - vpcId, null, null, isDisplayNetworkEnabled, null); + final Network guestNetwork = + _ntwkMgr.createGuestNetwork(ntwkOffId, name, displayText, gateway, cidr, vlanId, networkDomain, owner, domainId, pNtwk, zoneId, aclType, subdomainAccess, + vpcId, null, null, isDisplayNetworkEnabled, null); if (guestNetwork != null) { guestNetwork.setNetworkACLId(aclId); @@ -2333,30 +2335,30 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis return guestNetwork; } - protected IPAddressVO getExistingSourceNatInVpc(long ownerId, long vpcId) { + protected IPAddressVO getExistingSourceNatInVpc(final long ownerId, final long vpcId) { - List addrs = listPublicIpsAssignedToVpc(ownerId, true, vpcId); + final List addrs = listPublicIpsAssignedToVpc(ownerId, true, vpcId); IPAddressVO sourceNatIp = null; if (addrs.isEmpty()) { return null; } else { // Account already has ip addresses - for (IPAddressVO addr : addrs) { + for (final IPAddressVO addr : addrs) { if (addr.isSourceNat()) { sourceNatIp = addr; return sourceNatIp; } } - assert (sourceNatIp != null) : "How do we get a bunch of ip addresses but none of them are source nat? " + "account=" + ownerId + "; vpcId=" + vpcId; + assert sourceNatIp != null : "How do we get a bunch of ip addresses but none of them are source nat? " + "account=" + ownerId + "; vpcId=" + vpcId; } return sourceNatIp; } - protected List listPublicIpsAssignedToVpc(long accountId, Boolean sourceNat, long vpcId) { - SearchCriteria sc = IpAddressSearch.create(); + protected List listPublicIpsAssignedToVpc(final long accountId, final Boolean sourceNat, final long vpcId) { + final SearchCriteria sc = IpAddressSearch.create(); sc.setParameters("accountId", accountId); sc.setParameters("vpcId", vpcId); @@ -2369,10 +2371,10 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } @Override - public PublicIp assignSourceNatIpAddressToVpc(Account owner, Vpc vpc) throws InsufficientAddressCapacityException, ConcurrentOperationException { - long dcId = vpc.getZoneId(); + public PublicIp assignSourceNatIpAddressToVpc(final Account owner, final Vpc vpc) throws InsufficientAddressCapacityException, ConcurrentOperationException { + final long dcId = vpc.getZoneId(); - IPAddressVO sourceNatIp = getExistingSourceNatInVpc(owner.getId(), vpc.getId()); + final IPAddressVO sourceNatIp = getExistingSourceNatInVpc(owner.getId(), vpc.getId()); PublicIp ipToReturn = null; @@ -2387,13 +2389,13 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis @Override public List getSupportedVpcHypervisors() { - return Collections.unmodifiableList(this.hTypes); + return Collections.unmodifiableList(hTypes); } - private List getVpcProviders(long vpcId) { - List providerNames = _vpcSrvcDao.getDistinctProviders(vpcId); - Map providers = new HashMap(); - for (String providerName : providerNames) { + private List getVpcProviders(final long vpcId) { + final List providerNames = _vpcSrvcDao.getDistinctProviders(vpcId); + final Map providers = new HashMap(); + for (final String providerName : providerNames) { if (!providers.containsKey(providerName)) { providers.put(providerName, Network.Provider.getProvider(providerName)); } @@ -2403,14 +2405,14 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis } @Inject - public void setVpcElements(List vpcElements) { + public void setVpcElements(final List vpcElements) { this.vpcElements = vpcElements; } @Override @ActionEvent(eventType = EventTypes.EVENT_STATIC_ROUTE_CREATE, eventDescription = "Applying static route", async = true) - public boolean applyStaticRoute(long routeId) throws ResourceUnavailableException { - StaticRoute route = _staticRouteDao.findById(routeId); + public boolean applyStaticRoute(final long routeId) throws ResourceUnavailableException { + final StaticRoute route = _staticRouteDao.findById(routeId); return applyStaticRoutesForVpc(route.getVpcId()); } }