diff --git a/engine/api/src/com/cloud/vm/VirtualMachineManager.java b/engine/api/src/com/cloud/vm/VirtualMachineManager.java index fcfa3f1d8da..3535a320b4c 100644 --- a/engine/api/src/com/cloud/vm/VirtualMachineManager.java +++ b/engine/api/src/com/cloud/vm/VirtualMachineManager.java @@ -18,6 +18,7 @@ package com.cloud.vm; import java.net.URI; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import org.apache.cloudstack.framework.config.ConfigKey; @@ -76,11 +77,11 @@ public interface VirtualMachineManager extends Manager { * @throws InsufficientCapacityException If there are insufficient capacity to deploy this vm. */ void allocate(String vmInstanceName, VirtualMachineTemplate template, ServiceOffering serviceOffering, Pair rootDiskOffering, - LinkedHashMap dataDiskOfferings, LinkedHashMap auxiliaryNetworks, DeploymentPlan plan, + LinkedHashMap dataDiskOfferings, LinkedHashMap> auxiliaryNetworks, DeploymentPlan plan, HypervisorType hyperType) throws InsufficientCapacityException; void allocate(String vmInstanceName, VirtualMachineTemplate template, ServiceOffering serviceOffering, - LinkedHashMap networkProfiles, DeploymentPlan plan, HypervisorType hyperType) throws InsufficientCapacityException; + LinkedHashMap> networkProfiles, DeploymentPlan plan, HypervisorType hyperType) throws InsufficientCapacityException; void start(String vmUuid, Map params); diff --git a/engine/api/src/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java b/engine/api/src/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java index a50c184a5e0..1061c4d007a 100755 --- a/engine/api/src/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java +++ b/engine/api/src/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java @@ -77,7 +77,7 @@ public interface NetworkOrchestrationService { boolean errorIfAlreadySetup, Long domainId, ACLType aclType, Boolean subdomainAccess, Long vpcId, Boolean isDisplayNetworkEnabled) throws ConcurrentOperationException; - void allocate(VirtualMachineProfile vm, LinkedHashMap networks) throws InsufficientCapacityException, + void allocate(VirtualMachineProfile vm, LinkedHashMap> networks) throws InsufficientCapacityException, ConcurrentOperationException; void prepare(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java index 6b73f4d730f..3c272e48e55 100755 --- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -369,7 +369,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac @DB public void allocate(String vmInstanceName, final VirtualMachineTemplate template, ServiceOffering serviceOffering, final Pair rootDiskOffering, LinkedHashMap dataDiskOfferings, - final LinkedHashMap auxiliaryNetworks, DeploymentPlan plan, HypervisorType hyperType) + final LinkedHashMap> auxiliaryNetworks, DeploymentPlan plan, HypervisorType hyperType) throws InsufficientCapacityException { VMInstanceVO vm = _vmDao.findVMByInstanceName(vmInstanceName); @@ -428,7 +428,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac @Override public void allocate(String vmInstanceName, VirtualMachineTemplate template, ServiceOffering serviceOffering, - LinkedHashMap networks, DeploymentPlan plan, HypervisorType hyperType) throws InsufficientCapacityException { + LinkedHashMap> networks, DeploymentPlan plan, HypervisorType hyperType) throws InsufficientCapacityException { allocate(vmInstanceName, template, serviceOffering, new Pair(serviceOffering, null), null, networks, plan, hyperType); } diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/CloudOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/CloudOrchestrator.java index f55f58ce542..b00b5ad7499 100755 --- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/CloudOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/CloudOrchestrator.java @@ -20,14 +20,13 @@ package org.apache.cloudstack.engine.orchestration; import java.net.URL; import java.util.ArrayList; +import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import javax.inject.Inject; -import org.springframework.stereotype.Component; - import org.apache.cloudstack.engine.cloud.entity.api.NetworkEntity; import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity; import org.apache.cloudstack.engine.cloud.entity.api.VMEntityManager; @@ -36,6 +35,7 @@ import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl; import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity; import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService; import org.apache.cloudstack.engine.service.api.OrchestrationService; +import org.springframework.stereotype.Component; import com.cloud.deploy.DeploymentPlan; import com.cloud.exception.InsufficientCapacityException; @@ -157,11 +157,11 @@ public class CloudOrchestrator implements OrchestrationService { // VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks, // vmEntityManager); - LinkedHashMap networkIpMap = new LinkedHashMap(); + LinkedHashMap> networkIpMap = new LinkedHashMap>(); for (String uuid : networkNicMap.keySet()) { NetworkVO network = _networkDao.findByUuid(uuid); - if (network != null) { - networkIpMap.put(network, networkNicMap.get(uuid)); + if(network != null){ + networkIpMap.put(network, new ArrayList(Arrays.asList(networkNicMap.get(uuid)))); } } @@ -241,11 +241,11 @@ public class CloudOrchestrator implements OrchestrationService { rootDiskOffering.first(diskOffering); rootDiskOffering.second(size); - LinkedHashMap networkIpMap = new LinkedHashMap(); + LinkedHashMap> networkIpMap = new LinkedHashMap>(); for (String uuid : networkNicMap.keySet()) { NetworkVO network = _networkDao.findByUuid(uuid); - if (network != null) { - networkIpMap.put(network, networkNicMap.get(uuid)); + if(network != null){ + networkIpMap.put(network, new ArrayList(Arrays.asList(networkNicMap.get(uuid)))); } } diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java index 97b8ecb169a..7853c3be86f 100755 --- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java @@ -685,67 +685,82 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra @Override @DB - public void allocate(final VirtualMachineProfile vm, final LinkedHashMap networks) throws InsufficientCapacityException, + public void allocate(final VirtualMachineProfile vm, final LinkedHashMap> networks) throws InsufficientCapacityException, ConcurrentOperationException { Transaction.execute(new TransactionCallbackWithExceptionNoReturn() { @Override public void doInTransactionWithoutResult(TransactionStatus status) throws InsufficientCapacityException { int deviceId = 0; - - boolean[] deviceIds = new boolean[networks.size()]; - Arrays.fill(deviceIds, false); - - List nics = new ArrayList(networks.size()); - NicProfile defaultNic = null; - - for (Map.Entry network : networks.entrySet()) { - Network config = network.getKey(); - NicProfile requested = network.getValue(); - - Boolean isDefaultNic = false; - if (vm != null && (requested != null && requested.isDefaultNic())) { - isDefaultNic = true; + int size = 0; + for (Network ntwk : networks.keySet()) { + List profiles = networks.get(ntwk); + if (profiles != null && !profiles.isEmpty()) { + size = size + profiles.size(); + } else { + size = size + 1; } - - while (deviceIds[deviceId] && deviceId < deviceIds.length) { - deviceId++; - } - - Pair vmNicPair = allocateNic(requested, config, isDefaultNic, deviceId, vm); - - NicProfile vmNic = vmNicPair.first(); - if (vmNic == null) { - continue; - } - - deviceId = vmNicPair.second(); - - int devId = vmNic.getDeviceId(); - if (devId > deviceIds.length) { - throw new IllegalArgumentException("Device id for nic is too large: " + vmNic); - } - if (deviceIds[devId]) { - throw new IllegalArgumentException("Conflicting device id for two different nics: " + vmNic); - } - - deviceIds[devId] = true; - - if (vmNic.isDefaultNic()) { - if (defaultNic != null) { - throw new IllegalArgumentException("You cannot specify two nics as default nics: nic 1 = " + defaultNic + "; nic 2 = " + vmNic); - } - defaultNic = vmNic; - } - - nics.add(vmNic); - vm.addNic(vmNic); - } - if (nics.size() != networks.size()) { - s_logger.warn("Number of nics " + nics.size() + " doesn't match number of requested networks " + networks.size()); - throw new CloudRuntimeException("Number of nics " + nics.size() + " doesn't match number of requested networks " + networks.size()); + boolean[] deviceIds = new boolean[size]; + Arrays.fill(deviceIds, false); + + List nics = new ArrayList(size); + NicProfile defaultNic = null; + + for (Map.Entry> network : networks.entrySet()) { + Network config = network.getKey(); + List requestedProfiles = network.getValue(); + if (requestedProfiles == null) { + requestedProfiles = new ArrayList(); + } + if (requestedProfiles.isEmpty()) { + requestedProfiles.add(null); + } + + for (NicProfile requested : requestedProfiles) { + Boolean isDefaultNic = false; + if (vm != null && (requested != null && requested.isDefaultNic())) { + isDefaultNic = true; + } + + while (deviceIds[deviceId] && deviceId < deviceIds.length) { + deviceId++; + } + + Pair vmNicPair = allocateNic(requested, config, isDefaultNic, deviceId, vm); + + NicProfile vmNic = vmNicPair.first(); + if (vmNic == null) { + continue; + } + + deviceId = vmNicPair.second(); + + int devId = vmNic.getDeviceId(); + if (devId > deviceIds.length) { + throw new IllegalArgumentException("Device id for nic is too large: " + vmNic); + } + if (deviceIds[devId]) { + throw new IllegalArgumentException("Conflicting device id for two different nics: " + vmNic); + } + + deviceIds[devId] = true; + + if (vmNic.isDefaultNic()) { + if (defaultNic != null) { + throw new IllegalArgumentException("You cannot specify two nics as default nics: nic 1 = " + defaultNic + "; nic 2 = " + vmNic); + } + defaultNic = vmNic; + } + + nics.add(vmNic); + vm.addNic(vmNic); + } + } + if (nics.size() != size) { + s_logger.warn("Number of nics " + nics.size() + " doesn't match number of requested nics " + size); + throw new CloudRuntimeException("Number of nics " + nics.size() + " doesn't match number of requested networks " + size); } if (nics.size() == 1) { @@ -768,14 +783,14 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra requested.setMode(network.getMode()); } NicProfile profile = guru.allocate(network, requested, vm); - if (isDefaultNic != null) { - profile.setDefaultNic(isDefaultNic); - } - if (profile == null) { return null; } + if (isDefaultNic != null) { + profile.setDefaultNic(isDefaultNic); + } + if (requested != null && requested.getMode() == null) { profile.setMode(requested.getMode()); } else { @@ -2478,8 +2493,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (dc.getNetworkType() == NetworkType.Basic) { List nics = _nicDao.listByVmId(vmInstance.getId()); NetworkVO network = _networksDao.findById(nics.get(0).getNetworkId()); - final LinkedHashMap profiles = new LinkedHashMap(); - profiles.put(network, null); + final LinkedHashMap> profiles = new LinkedHashMap>(); + profiles.put(network, new ArrayList()); Transaction.execute(new TransactionCallbackWithExceptionNoReturn() { @Override diff --git a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/LoadBalanceRuleHandler.java b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/LoadBalanceRuleHandler.java index f65d928c449..32292cddd47 100644 --- a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/LoadBalanceRuleHandler.java +++ b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/LoadBalanceRuleHandler.java @@ -18,6 +18,7 @@ package com.cloud.network.lb; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -252,11 +253,11 @@ public class LoadBalanceRuleHandler { NetworkOffering controlOffering = offerings.get(0); Network controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); - LinkedHashMap networks = new LinkedHashMap(2); + LinkedHashMap> networks = new LinkedHashMap>(2); NicProfile guestNic = new NicProfile(); guestNic.setDefaultNic(true); - networks.put(controlConfig, null); - networks.put(guestNetwork, guestNic); + networks.put(controlConfig, new ArrayList()); + networks.put(guestNetwork, new ArrayList(Arrays.asList(guestNic))); VMTemplateVO template = _templateDao.findSystemVMTemplate(dcId); diff --git a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java index b2030a93f60..8b823063e5f 100644 --- a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java +++ b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java @@ -17,6 +17,7 @@ package org.apache.cloudstack.network.lb; import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -26,12 +27,11 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; - import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO; import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao; +import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -613,7 +613,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements In return internalLbVms; } - LinkedHashMap networks = createInternalLbVmNetworks(guestNetwork, plan, requestedGuestIp); + LinkedHashMap> networks = createInternalLbVmNetworks(guestNetwork, plan, requestedGuestIp); //Pass startVm=false as we are holding the network lock that needs to be released at the end of vm allocation DomainRouterVO internalLbVm = deployInternalLbVm(owner, dest, plan, params, internalLbProviderId, _internalLbVmOfferingId, guestNetwork.getVpcId(), networks, false); @@ -649,11 +649,11 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements In return internalLbProvider.getId(); } - protected LinkedHashMap createInternalLbVmNetworks(Network guestNetwork, DeploymentPlan plan, Ip guestIp) throws ConcurrentOperationException, - InsufficientAddressCapacityException { + protected LinkedHashMap> createInternalLbVmNetworks(Network guestNetwork, DeploymentPlan plan, Ip guestIp) throws ConcurrentOperationException, + InsufficientAddressCapacityException { //Form networks - LinkedHashMap networks = new LinkedHashMap(3); + LinkedHashMap> networks = new LinkedHashMap>(3); //1) Guest network - default if (guestNetwork != null) { @@ -672,7 +672,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements In String gatewayCidr = guestNetwork.getCidr(); guestNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr)); guestNic.setDefaultNic(true); - networks.put(guestNetwork, guestNic); + networks.put(guestNetwork, new ArrayList(Arrays.asList(guestNic))); } //2) Control network @@ -680,7 +680,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements In List offerings = _ntwkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork); NetworkOffering controlOffering = offerings.get(0); Network controlConfig = _ntwkMgr.setupNetwork(_accountMgr.getSystemAccount(), controlOffering, plan, null, null, false).get(0); - networks.put(controlConfig, null); + networks.put(controlConfig, new ArrayList()); return networks; } @@ -711,7 +711,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements In } protected DomainRouterVO deployInternalLbVm(Account owner, DeployDestination dest, DeploymentPlan plan, Map params, long internalLbProviderId, - long svcOffId, Long vpcId, LinkedHashMap networks, boolean startVm) throws ConcurrentOperationException, + long svcOffId, Long vpcId, LinkedHashMap> networks, boolean startVm) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException { diff --git a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java index 9860faf7f09..f34eaccbb06 100644 --- a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java +++ b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java @@ -18,8 +18,10 @@ package org.apache.cloudstack.network.contrail.management; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import javax.ejb.Local; @@ -33,7 +35,6 @@ import org.apache.cloudstack.network.contrail.api.response.ServiceInstanceRespon import org.apache.cloudstack.network.contrail.model.ServiceInstanceModel; import org.apache.cloudstack.network.contrail.model.VirtualMachineModel; import org.apache.cloudstack.network.contrail.model.VirtualNetworkModel; - import org.apache.log4j.Logger; import com.cloud.api.ApiDBUtils; @@ -101,13 +102,12 @@ public class ServiceManagerImpl implements ServiceManager { long id = _vmDao.getNextInSequence(Long.class, "id"); DataCenterDeployment plan = new DataCenterDeployment(zone.getId()); - - LinkedHashMap networks = new LinkedHashMap(); - NetworkVO linklocal = (NetworkVO)_networkModel.getSystemNetworkByZoneAndTrafficType(zone.getId(), TrafficType.Management); - networks.put(linklocal, null); - networks.put((NetworkVO)left, null); - networks.put((NetworkVO)right, null); - + LinkedHashMap> networks = new LinkedHashMap>(); + NetworkVO linklocal = (NetworkVO) _networkModel.getSystemNetworkByZoneAndTrafficType(zone.getId(), + TrafficType.Management); + networks.put(linklocal, new ArrayList()); + networks.put((NetworkVO)left, new ArrayList()); + networks.put((NetworkVO)right, new ArrayList()); String instanceName = VirtualMachineName.getVmName(id, owner.getId(), "SRV"); ServiceVirtualMachine svm = new ServiceVirtualMachine(id, instanceName, name, template.getId(), serviceOffering.getId(), template.getHypervisorType(), template.getGuestOSId(), diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 813888707a3..3e4c57e6852 100755 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -17,6 +17,7 @@ package com.cloud.consoleproxy; import java.nio.charset.Charset; +import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; @@ -703,16 +704,16 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy List offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork, NetworkOffering.SystemManagementNetwork); - LinkedHashMap networks = new LinkedHashMap(offerings.size() + 1); + LinkedHashMap> networks = new LinkedHashMap>(offerings.size() + 1); NicProfile defaultNic = new NicProfile(); defaultNic.setDefaultNic(true); defaultNic.setDeviceId(2); networks.put(_networkMgr.setupNetwork(systemAcct, _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0), - defaultNic); + new ArrayList(Arrays.asList(defaultNic))); for (NetworkOffering offering : offerings) { - networks.put(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), null); + networks.put(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), new ArrayList()); } ConsoleProxyVO proxy = diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 8404cabcad0..37171f540a1 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -18,6 +18,7 @@ package com.cloud.network.router; import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; @@ -41,8 +42,6 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; - import org.apache.cloudstack.api.command.admin.router.RebootRouterCmd; import org.apache.cloudstack.api.command.admin.router.UpgradeRouterCmd; import org.apache.cloudstack.api.command.admin.router.UpgradeRouterTemplateCmd; @@ -57,6 +56,7 @@ import org.apache.cloudstack.framework.jobs.AsyncJobManager; import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO; import org.apache.cloudstack.managed.context.ManagedContextRunnable; import org.apache.cloudstack.utils.identity.ManagementServerNode; +import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.Listener; @@ -1569,10 +1569,10 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V final int count = routerCount - routers.size(); final DeploymentPlan plan = planAndRouters.first(); for (int i = 0; i < count; i++) { - final LinkedHashMap networks = - createRouterNetworks(owner, isRedundant, plan, guestNetwork, new Pair(publicNetwork, sourceNatIp)); + LinkedHashMap> networks = createRouterNetworks(owner, isRedundant, plan, guestNetwork, new Pair( + publicNetwork, sourceNatIp)); //don't start the router as we are holding the network lock that needs to be released at the end of router allocation - final DomainRouterVO router = deployRouter(owner, destination, plan, params, isRedundant, vrProvider, offeringId, null, networks, false, null); + DomainRouterVO router = deployRouter(owner, destination, plan, params, isRedundant, vrProvider, offeringId, null, networks, false, null); if (router != null) { _routerDao.addRouterToGuestNetwork(router, guestNetwork); @@ -1610,7 +1610,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V } protected DomainRouterVO deployRouter(final Account owner, final DeployDestination dest, final DeploymentPlan plan, final Map params, final boolean isRedundant, - final VirtualRouterProvider vrProvider, final long svcOffId, final Long vpcId, final LinkedHashMap networks, final boolean startRouter, + final VirtualRouterProvider vrProvider, final long svcOffId, final Long vpcId, final LinkedHashMap> networks, final boolean startRouter, final List supportedHypervisors) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException { @@ -1750,7 +1750,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V return hypervisors; } - protected LinkedHashMap createRouterNetworks(final Account owner, final boolean isRedundant, final DeploymentPlan plan, final Network guestNetwork, + protected LinkedHashMap> createRouterNetworks(final Account owner, final boolean isRedundant, final DeploymentPlan plan, final Network guestNetwork, final Pair publicNetwork) throws ConcurrentOperationException, InsufficientAddressCapacityException { boolean setupPublicNetwork = false; @@ -1759,8 +1759,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V } //Form networks - final LinkedHashMap networks = new LinkedHashMap(3); - + LinkedHashMap> networks = new LinkedHashMap>(3); //1) Guest network boolean hasGuestNetwork = false; if (guestNetwork != null) { @@ -1816,17 +1815,16 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V gatewayNic.setDefaultNic(true); } - networks.put(guestNetwork, gatewayNic); + networks.put(guestNetwork, new ArrayList(Arrays.asList(gatewayNic))); hasGuestNetwork = true; } //2) Control network s_logger.debug("Adding nic for Virtual Router in Control network "); - final List offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork); - final NetworkOffering controlOffering = offerings.get(0); - final Network controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); - networks.put(controlConfig, null); - + List offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork); + NetworkOffering controlOffering = offerings.get(0); + Network controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); + networks.put(controlConfig, new ArrayList()); //3) Public network if (setupPublicNetwork) { final PublicIp sourceNatIp = publicNetwork.second(); @@ -1861,7 +1859,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V s_logger.info("Use same MAC as previous RvR, the MAC is " + peerNic.getMacAddress()); defaultNic.setMacAddress(peerNic.getMacAddress()); } - networks.put(publicNetworks.get(0), defaultNic); + networks.put(publicNetworks.get(0), new ArrayList(Arrays.asList(defaultNic))); } return networks; diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index 2b798bf4680..f6bd9e1ed42 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -16,6 +16,24 @@ // under the License. package com.cloud.network.router; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeSet; + +import javax.ejb.Local; +import javax.inject.Inject; +import javax.naming.ConfigurationException; + +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; import com.cloud.agent.api.NetworkUsageCommand; @@ -109,20 +127,6 @@ import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.VirtualMachineProfile.Param; import com.cloud.vm.dao.VMInstanceDao; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - -import javax.ejb.Local; -import javax.inject.Inject; -import javax.naming.ConfigurationException; -import java.net.URI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.TreeSet; @Component @Local(value = {VpcVirtualNetworkApplianceManager.class, VpcVirtualNetworkApplianceService.class}) @@ -318,7 +322,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian VirtualRouterProvider vrProvider, long svcOffId, Long vpcId, PublicIp sourceNatIp) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException { - LinkedHashMap networks = createVpcRouterNetworks(owner, isRedundant, plan, new Pair(true, sourceNatIp), vpcId); + LinkedHashMap> networks = createVpcRouterNetworks(owner, isRedundant, plan, new Pair(true, sourceNatIp),vpcId); DomainRouterVO router = super.deployRouter(owner, dest, plan, params, isRedundant, vrProvider, svcOffId, vpcId, networks, true, _vpcMgr.getSupportedVpcHypervisors()); @@ -1150,10 +1154,10 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian } } - protected LinkedHashMap createVpcRouterNetworks(Account owner, boolean isRedundant, DeploymentPlan plan, Pair sourceNatIp, + protected LinkedHashMap> createVpcRouterNetworks(Account owner, boolean isRedundant, DeploymentPlan plan, Pair sourceNatIp, long vpcId) throws ConcurrentOperationException, InsufficientAddressCapacityException { - LinkedHashMap networks = new LinkedHashMap(4); + LinkedHashMap> networks = new LinkedHashMap>(4); TreeSet publicVlans = new TreeSet(); publicVlans.add(sourceNatIp.second().getVlanTag()); @@ -1167,7 +1171,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian for (PrivateGateway privateGateway : privateGateways) { NicProfile privateNic = createPrivateNicProfileForGateway(privateGateway); Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId()); - networks.put(privateNetwork, privateNic); + networks.put(privateNetwork, new ArrayList(Arrays.asList(privateNic))); } } @@ -1176,12 +1180,14 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian for (Network guestNetwork : guestNetworks) { if (guestNetwork.getState() == Network.State.Implemented) { NicProfile guestNic = createGuestNicProfileForVpcRouter(guestNetwork); - networks.put(guestNetwork, guestNic); + networks.put(guestNetwork, new ArrayList(Arrays.asList(guestNic))); } } //4) allocate nic for additional public network(s) List ips = _ipAddressDao.listByAssociatedVpc(vpcId, false); + List publicNics = new ArrayList(); + Network publicNetwork = null; for (IPAddressVO ip : ips) { PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId())); if ((ip.getState() == IpAddress.State.Allocated || ip.getState() == IpAddress.State.Allocating) && _vpcMgr.isIpAllocatedToVpc(ip) && @@ -1197,11 +1203,23 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian publicNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(publicIp.getVlanTag())); publicNic.setIsolationUri(IsolationType.Vlan.toUri(publicIp.getVlanTag())); NetworkOffering publicOffering = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0); - List publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false); - networks.put(publicNetworks.get(0), publicNic); + if (publicNetwork == null) { + List publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false); + publicNetwork = publicNetworks.get(0); + } + publicNics.add(publicNic); publicVlans.add(publicIp.getVlanTag()); } } + if (publicNetwork != null) { + if (networks.get(publicNetwork) != null) { + List publicNicProfiles = (List)networks.get(publicNetwork); + publicNicProfiles.addAll(publicNics); + networks.put(publicNetwork, publicNicProfiles); + } else { + networks.put(publicNetwork, publicNics); + } + } return networks; } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 2f686be1976..9874dc30f4e 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -17,6 +17,7 @@ package com.cloud.vm; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -4464,10 +4465,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } } - LinkedHashMap networks = new LinkedHashMap(); + LinkedHashMap> networks = new LinkedHashMap>(); NicProfile profile = new NicProfile(); profile.setDefaultNic(true); - networks.put(networkList.get(0), profile); + networks.put(networkList.get(0), new ArrayList(Arrays.asList(profile))); VirtualMachine vmi = _itMgr.findById(vm.getId()); VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmi); @@ -4571,7 +4572,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } // add the new nics - LinkedHashMap networks = new LinkedHashMap(); + LinkedHashMap> networks = new LinkedHashMap>(); int toggle = 0; for (NetworkVO appNet : applicableNetworks) { NicProfile defaultNic = new NicProfile(); @@ -4579,7 +4580,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir defaultNic.setDefaultNic(true); toggle++; } - networks.put(appNet, defaultNic); + networks.put(appNet, new ArrayList(Arrays.asList(defaultNic))); } VirtualMachine vmi = _itMgr.findById(vm.getId()); VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmi); diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java index b06ddf14914..ac303dddfcb 100644 --- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java @@ -521,10 +521,9 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkOrches * @see com.cloud.network.NetworkManager#allocate(com.cloud.vm.VirtualMachineProfile, java.util.List) */ @Override - public void allocate(VirtualMachineProfile vm, LinkedHashMap networks) throws InsufficientCapacityException, - ConcurrentOperationException { + public void allocate(VirtualMachineProfile vm, LinkedHashMap> networks) + throws InsufficientCapacityException, ConcurrentOperationException { // TODO Auto-generated method stub - } /* (non-Javadoc) diff --git a/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java b/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java index 6fc7eef92b0..dd0c26774d2 100755 --- a/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java +++ b/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.secondarystorage; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.HashMap; @@ -30,8 +31,6 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; - import org.apache.cloudstack.config.ApiServiceConfiguration; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; @@ -44,6 +43,7 @@ import org.apache.cloudstack.storage.datastore.db.ImageStoreDao; import org.apache.cloudstack.storage.datastore.db.ImageStoreVO; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; import org.apache.cloudstack.utils.identity.ManagementServerNode; +import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -547,15 +547,15 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar List offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork, NetworkOffering.SystemManagementNetwork, NetworkOffering.SystemStorageNetwork); - LinkedHashMap networks = new LinkedHashMap(offerings.size() + 1); + LinkedHashMap> networks = new LinkedHashMap>(offerings.size() + 1); NicProfile defaultNic = new NicProfile(); defaultNic.setDefaultNic(true); defaultNic.setDeviceId(2); try { networks.put(_networkMgr.setupNetwork(systemAcct, _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0), - defaultNic); + new ArrayList(Arrays.asList(defaultNic))); for (NetworkOffering offering : offerings) { - networks.put(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), null); + networks.put(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), new ArrayList()); } } catch (ConcurrentOperationException e) { s_logger.info("Unable to setup due to concurrent operation. " + e);