Skip to content

Commit 5a8d165

Browse files
author
Alena Prokharchyk
committed
CLOUDSTACK-6198: use List DS for storing NicProfiles as public network can have more than one nic
Conflicts: engine/api/src/com/cloud/vm/VirtualMachineManager.java engine/api/src/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java engine/orchestration/src/org/apache/cloudstack/engine/orchestration/CloudOrchestrator.java engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java server/test/com/cloud/vpc/MockNetworkManagerImpl.java services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java
1 parent 339c4f4 commit 5a8d165

14 files changed

Lines changed: 162 additions & 128 deletions

File tree

engine/api/src/com/cloud/vm/VirtualMachineManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.net.URI;
2020
import java.util.LinkedHashMap;
21+
import java.util.List;
2122
import java.util.Map;
2223

2324
import org.apache.cloudstack.framework.config.ConfigKey;
@@ -76,11 +77,11 @@ public interface Topics {
7677
* @throws InsufficientCapacityException If there are insufficient capacity to deploy this vm.
7778
*/
7879
void allocate(String vmInstanceName, VirtualMachineTemplate template, ServiceOffering serviceOffering, Pair<? extends DiskOffering, Long> rootDiskOffering,
79-
LinkedHashMap<? extends DiskOffering, Long> dataDiskOfferings, LinkedHashMap<? extends Network, ? extends NicProfile> auxiliaryNetworks, DeploymentPlan plan,
80+
LinkedHashMap<? extends DiskOffering, Long> dataDiskOfferings, LinkedHashMap<? extends Network, List<? extends NicProfile>> auxiliaryNetworks, DeploymentPlan plan,
8081
HypervisorType hyperType) throws InsufficientCapacityException;
8182

8283
void allocate(String vmInstanceName, VirtualMachineTemplate template, ServiceOffering serviceOffering,
83-
LinkedHashMap<? extends Network, ? extends NicProfile> networkProfiles, DeploymentPlan plan, HypervisorType hyperType) throws InsufficientCapacityException;
84+
LinkedHashMap<? extends Network, List<? extends NicProfile>> networkProfiles, DeploymentPlan plan, HypervisorType hyperType) throws InsufficientCapacityException;
8485

8586
void start(String vmUuid, Map<VirtualMachineProfile.Param, Object> params);
8687

engine/api/src/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ List<? extends Network> setupNetwork(Account owner, NetworkOffering offering, Ne
7777
boolean errorIfAlreadySetup, Long domainId, ACLType aclType, Boolean subdomainAccess, Long vpcId, Boolean isDisplayNetworkEnabled)
7878
throws ConcurrentOperationException;
7979

80-
void allocate(VirtualMachineProfile vm, LinkedHashMap<? extends Network, ? extends NicProfile> networks) throws InsufficientCapacityException,
80+
void allocate(VirtualMachineProfile vm, LinkedHashMap<? extends Network, List<? extends NicProfile>> networks) throws InsufficientCapacityException,
8181
ConcurrentOperationException;
8282

8383
void prepare(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException,

engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ public void registerGuru(VirtualMachine.Type type, VirtualMachineGuru guru) {
369369
@DB
370370
public void allocate(String vmInstanceName, final VirtualMachineTemplate template, ServiceOffering serviceOffering,
371371
final Pair<? extends DiskOffering, Long> rootDiskOffering, LinkedHashMap<? extends DiskOffering, Long> dataDiskOfferings,
372-
final LinkedHashMap<? extends Network, ? extends NicProfile> auxiliaryNetworks, DeploymentPlan plan, HypervisorType hyperType)
372+
final LinkedHashMap<? extends Network, List<? extends NicProfile>> auxiliaryNetworks, DeploymentPlan plan, HypervisorType hyperType)
373373
throws InsufficientCapacityException {
374374

375375
VMInstanceVO vm = _vmDao.findVMByInstanceName(vmInstanceName);
@@ -428,7 +428,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) throws Insuff
428428

429429
@Override
430430
public void allocate(String vmInstanceName, VirtualMachineTemplate template, ServiceOffering serviceOffering,
431-
LinkedHashMap<? extends Network, ? extends NicProfile> networks, DeploymentPlan plan, HypervisorType hyperType) throws InsufficientCapacityException {
431+
LinkedHashMap<? extends Network, List<? extends NicProfile>> networks, DeploymentPlan plan, HypervisorType hyperType) throws InsufficientCapacityException {
432432
allocate(vmInstanceName, template, serviceOffering, new Pair<DiskOffering, Long>(serviceOffering, null), null, networks, plan, hyperType);
433433
}
434434

engine/orchestration/src/org/apache/cloudstack/engine/orchestration/CloudOrchestrator.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020

2121
import java.net.URL;
2222
import java.util.ArrayList;
23+
import java.util.Arrays;
2324
import java.util.LinkedHashMap;
2425
import java.util.List;
2526
import java.util.Map;
2627

2728
import javax.inject.Inject;
2829

29-
import org.springframework.stereotype.Component;
30-
3130
import org.apache.cloudstack.engine.cloud.entity.api.NetworkEntity;
3231
import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
3332
import org.apache.cloudstack.engine.cloud.entity.api.VMEntityManager;
@@ -36,6 +35,7 @@
3635
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
3736
import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
3837
import org.apache.cloudstack.engine.service.api.OrchestrationService;
38+
import org.springframework.stereotype.Component;
3939

4040
import com.cloud.deploy.DeploymentPlan;
4141
import com.cloud.exception.InsufficientCapacityException;
@@ -157,11 +157,11 @@ public VirtualMachineEntity createVirtualMachine(String id, String owner, String
157157
// VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks,
158158
// vmEntityManager);
159159

160-
LinkedHashMap<NetworkVO, NicProfile> networkIpMap = new LinkedHashMap<NetworkVO, NicProfile>();
160+
LinkedHashMap<NetworkVO, List<? extends NicProfile>> networkIpMap = new LinkedHashMap<NetworkVO, List<? extends NicProfile>>();
161161
for (String uuid : networkNicMap.keySet()) {
162162
NetworkVO network = _networkDao.findByUuid(uuid);
163-
if (network != null) {
164-
networkIpMap.put(network, networkNicMap.get(uuid));
163+
if(network != null){
164+
networkIpMap.put(network, new ArrayList<NicProfile>(Arrays.asList(networkNicMap.get(uuid))));
165165
}
166166
}
167167

@@ -241,11 +241,11 @@ public VirtualMachineEntity createVirtualMachineFromScratch(String id, String ow
241241
rootDiskOffering.first(diskOffering);
242242
rootDiskOffering.second(size);
243243

244-
LinkedHashMap<Network, NicProfile> networkIpMap = new LinkedHashMap<Network, NicProfile>();
244+
LinkedHashMap<Network, List<? extends NicProfile>> networkIpMap = new LinkedHashMap<Network, List<? extends NicProfile>>();
245245
for (String uuid : networkNicMap.keySet()) {
246246
NetworkVO network = _networkDao.findByUuid(uuid);
247-
if (network != null) {
248-
networkIpMap.put(network, networkNicMap.get(uuid));
247+
if(network != null){
248+
networkIpMap.put(network, new ArrayList<NicProfile>(Arrays.asList(networkNicMap.get(uuid))));
249249
}
250250
}
251251

engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -685,67 +685,82 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
685685

686686
@Override
687687
@DB
688-
public void allocate(final VirtualMachineProfile vm, final LinkedHashMap<? extends Network, ? extends NicProfile> networks) throws InsufficientCapacityException,
688+
public void allocate(final VirtualMachineProfile vm, final LinkedHashMap<? extends Network, List<? extends NicProfile>> networks) throws InsufficientCapacityException,
689689
ConcurrentOperationException {
690690

691691
Transaction.execute(new TransactionCallbackWithExceptionNoReturn<InsufficientCapacityException>() {
692692
@Override
693693
public void doInTransactionWithoutResult(TransactionStatus status) throws InsufficientCapacityException {
694694
int deviceId = 0;
695+
int size = 0;
696+
for (Network ntwk : networks.keySet()) {
697+
List<? extends NicProfile> profiles = networks.get(ntwk);
698+
if (profiles != null && !profiles.isEmpty()) {
699+
size = size + profiles.size();
700+
} else {
701+
size = size + 1;
702+
}
703+
}
695704

696-
boolean[] deviceIds = new boolean[networks.size()];
705+
boolean[] deviceIds = new boolean[size];
697706
Arrays.fill(deviceIds, false);
698707

699-
List<NicProfile> nics = new ArrayList<NicProfile>(networks.size());
708+
List<NicProfile> nics = new ArrayList<NicProfile>(size);
700709
NicProfile defaultNic = null;
701710

702-
for (Map.Entry<? extends Network, ? extends NicProfile> network : networks.entrySet()) {
711+
for (Map.Entry<? extends Network, List<? extends NicProfile>> network : networks.entrySet()) {
703712
Network config = network.getKey();
704-
NicProfile requested = network.getValue();
705-
706-
Boolean isDefaultNic = false;
707-
if (vm != null && (requested != null && requested.isDefaultNic())) {
708-
isDefaultNic = true;
713+
List<? extends NicProfile> requestedProfiles = network.getValue();
714+
if (requestedProfiles == null) {
715+
requestedProfiles = new ArrayList<NicProfile>();
709716
}
710-
711-
while (deviceIds[deviceId] && deviceId < deviceIds.length) {
712-
deviceId++;
717+
if (requestedProfiles.isEmpty()) {
718+
requestedProfiles.add(null);
713719
}
714720

715-
Pair<NicProfile, Integer> vmNicPair = allocateNic(requested, config, isDefaultNic, deviceId, vm);
721+
for (NicProfile requested : requestedProfiles) {
722+
Boolean isDefaultNic = false;
723+
if (vm != null && (requested != null && requested.isDefaultNic())) {
724+
isDefaultNic = true;
725+
}
716726

717-
NicProfile vmNic = vmNicPair.first();
718-
if (vmNic == null) {
719-
continue;
720-
}
727+
while (deviceIds[deviceId] && deviceId < deviceIds.length) {
728+
deviceId++;
729+
}
721730

722-
deviceId = vmNicPair.second();
731+
Pair<NicProfile, Integer> vmNicPair = allocateNic(requested, config, isDefaultNic, deviceId, vm);
723732

724-
int devId = vmNic.getDeviceId();
725-
if (devId > deviceIds.length) {
726-
throw new IllegalArgumentException("Device id for nic is too large: " + vmNic);
727-
}
728-
if (deviceIds[devId]) {
729-
throw new IllegalArgumentException("Conflicting device id for two different nics: " + vmNic);
730-
}
733+
NicProfile vmNic = vmNicPair.first();
734+
if (vmNic == null) {
735+
continue;
736+
}
731737

732-
deviceIds[devId] = true;
738+
deviceId = vmNicPair.second();
733739

734-
if (vmNic.isDefaultNic()) {
735-
if (defaultNic != null) {
736-
throw new IllegalArgumentException("You cannot specify two nics as default nics: nic 1 = " + defaultNic + "; nic 2 = " + vmNic);
740+
int devId = vmNic.getDeviceId();
741+
if (devId > deviceIds.length) {
742+
throw new IllegalArgumentException("Device id for nic is too large: " + vmNic);
743+
}
744+
if (deviceIds[devId]) {
745+
throw new IllegalArgumentException("Conflicting device id for two different nics: " + vmNic);
737746
}
738-
defaultNic = vmNic;
739-
}
740747

741-
nics.add(vmNic);
742-
vm.addNic(vmNic);
748+
deviceIds[devId] = true;
743749

744-
}
750+
if (vmNic.isDefaultNic()) {
751+
if (defaultNic != null) {
752+
throw new IllegalArgumentException("You cannot specify two nics as default nics: nic 1 = " + defaultNic + "; nic 2 = " + vmNic);
753+
}
754+
defaultNic = vmNic;
755+
}
745756

746-
if (nics.size() != networks.size()) {
747-
s_logger.warn("Number of nics " + nics.size() + " doesn't match number of requested networks " + networks.size());
748-
throw new CloudRuntimeException("Number of nics " + nics.size() + " doesn't match number of requested networks " + networks.size());
757+
nics.add(vmNic);
758+
vm.addNic(vmNic);
759+
}
760+
}
761+
if (nics.size() != size) {
762+
s_logger.warn("Number of nics " + nics.size() + " doesn't match number of requested nics " + size);
763+
throw new CloudRuntimeException("Number of nics " + nics.size() + " doesn't match number of requested networks " + size);
749764
}
750765

751766
if (nics.size() == 1) {
@@ -768,14 +783,14 @@ public Pair<NicProfile, Integer> allocateNic(NicProfile requested, Network netwo
768783
requested.setMode(network.getMode());
769784
}
770785
NicProfile profile = guru.allocate(network, requested, vm);
771-
if (isDefaultNic != null) {
772-
profile.setDefaultNic(isDefaultNic);
773-
}
774-
775786
if (profile == null) {
776787
return null;
777788
}
778789

790+
if (isDefaultNic != null) {
791+
profile.setDefaultNic(isDefaultNic);
792+
}
793+
779794
if (requested != null && requested.getMode() == null) {
780795
profile.setMode(requested.getMode());
781796
} else {
@@ -2478,8 +2493,8 @@ public boolean reallocate(final VirtualMachineProfile vm, DataCenterDeployment d
24782493
if (dc.getNetworkType() == NetworkType.Basic) {
24792494
List<NicVO> nics = _nicDao.listByVmId(vmInstance.getId());
24802495
NetworkVO network = _networksDao.findById(nics.get(0).getNetworkId());
2481-
final LinkedHashMap<Network, NicProfile> profiles = new LinkedHashMap<Network, NicProfile>();
2482-
profiles.put(network, null);
2496+
final LinkedHashMap<Network, List<? extends NicProfile>> profiles = new LinkedHashMap<Network, List<? extends NicProfile>>();
2497+
profiles.put(network, new ArrayList<NicProfile>());
24832498

24842499
Transaction.execute(new TransactionCallbackWithExceptionNoReturn<InsufficientCapacityException>() {
24852500
@Override

plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/LoadBalanceRuleHandler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.cloud.network.lb;
1919

2020
import java.util.ArrayList;
21+
import java.util.Arrays;
2122
import java.util.HashMap;
2223
import java.util.LinkedHashMap;
2324
import java.util.List;
@@ -252,11 +253,11 @@ private DomainRouterVO deployELBVm(Network guestNetwork, DeployDestination dest,
252253
NetworkOffering controlOffering = offerings.get(0);
253254
Network controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0);
254255

255-
LinkedHashMap<Network, NicProfile> networks = new LinkedHashMap<Network, NicProfile>(2);
256+
LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(2);
256257
NicProfile guestNic = new NicProfile();
257258
guestNic.setDefaultNic(true);
258-
networks.put(controlConfig, null);
259-
networks.put(guestNetwork, guestNic);
259+
networks.put(controlConfig, new ArrayList<NicProfile>());
260+
networks.put(guestNetwork, new ArrayList<NicProfile>(Arrays.asList(guestNic)));
260261

261262
VMTemplateVO template = _templateDao.findSystemVMTemplate(dcId);
262263

plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.cloudstack.network.lb;
1818

1919
import java.util.ArrayList;
20+
import java.util.Arrays;
2021
import java.util.Iterator;
2122
import java.util.LinkedHashMap;
2223
import java.util.List;
@@ -26,12 +27,11 @@
2627
import javax.inject.Inject;
2728
import javax.naming.ConfigurationException;
2829

29-
import org.apache.log4j.Logger;
30-
3130
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
3231
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
3332
import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
3433
import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao;
34+
import org.apache.log4j.Logger;
3535

3636
import com.cloud.agent.AgentManager;
3737
import com.cloud.agent.api.Answer;
@@ -613,7 +613,7 @@ protected List<DomainRouterVO> findOrDeployInternalLbVm(Network guestNetwork, Ip
613613
return internalLbVms;
614614
}
615615

616-
LinkedHashMap<Network, NicProfile> networks = createInternalLbVmNetworks(guestNetwork, plan, requestedGuestIp);
616+
LinkedHashMap<Network, List<? extends NicProfile>> networks = createInternalLbVmNetworks(guestNetwork, plan, requestedGuestIp);
617617
//Pass startVm=false as we are holding the network lock that needs to be released at the end of vm allocation
618618
DomainRouterVO internalLbVm =
619619
deployInternalLbVm(owner, dest, plan, params, internalLbProviderId, _internalLbVmOfferingId, guestNetwork.getVpcId(), networks, false);
@@ -649,11 +649,11 @@ protected long getInternalLbProviderId(Network guestNetwork) {
649649
return internalLbProvider.getId();
650650
}
651651

652-
protected LinkedHashMap<Network, NicProfile> createInternalLbVmNetworks(Network guestNetwork, DeploymentPlan plan, Ip guestIp) throws ConcurrentOperationException,
653-
InsufficientAddressCapacityException {
652+
protected LinkedHashMap<Network, List<? extends NicProfile>> createInternalLbVmNetworks(Network guestNetwork, DeploymentPlan plan, Ip guestIp) throws ConcurrentOperationException,
653+
InsufficientAddressCapacityException {
654654

655655
//Form networks
656-
LinkedHashMap<Network, NicProfile> networks = new LinkedHashMap<Network, NicProfile>(3);
656+
LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(3);
657657

658658
//1) Guest network - default
659659
if (guestNetwork != null) {
@@ -672,15 +672,15 @@ protected LinkedHashMap<Network, NicProfile> createInternalLbVmNetworks(Network
672672
String gatewayCidr = guestNetwork.getCidr();
673673
guestNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr));
674674
guestNic.setDefaultNic(true);
675-
networks.put(guestNetwork, guestNic);
675+
networks.put(guestNetwork, new ArrayList<NicProfile>(Arrays.asList(guestNic)));
676676
}
677677

678678
//2) Control network
679679
s_logger.debug("Adding nic for Internal LB vm in Control network ");
680680
List<? extends NetworkOffering> offerings = _ntwkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
681681
NetworkOffering controlOffering = offerings.get(0);
682682
Network controlConfig = _ntwkMgr.setupNetwork(_accountMgr.getSystemAccount(), controlOffering, plan, null, null, false).get(0);
683-
networks.put(controlConfig, null);
683+
networks.put(controlConfig, new ArrayList<NicProfile>());
684684

685685
return networks;
686686
}
@@ -711,7 +711,7 @@ public List<DomainRouterVO> findInternalLbVms(long guestNetworkId, Ip requestedG
711711
}
712712

713713
protected DomainRouterVO deployInternalLbVm(Account owner, DeployDestination dest, DeploymentPlan plan, Map<Param, Object> params, long internalLbProviderId,
714-
long svcOffId, Long vpcId, LinkedHashMap<Network, NicProfile> networks, boolean startVm) throws ConcurrentOperationException,
714+
long svcOffId, Long vpcId, LinkedHashMap<Network, List<? extends NicProfile>> networks, boolean startVm) throws ConcurrentOperationException,
715715
InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException,
716716
ResourceUnavailableException {
717717

0 commit comments

Comments
 (0)