Skip to content

Commit c7c899f

Browse files
author
Prachi Damle
committed
Fixes after functional tests
Conflicts: client/tomcatconf/commands.properties.in
1 parent bb9bdf0 commit c7c899f

14 files changed

Lines changed: 201 additions & 236 deletions

File tree

api/src/com/cloud/exception/AffinityConflictException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.cloud.exception;
22

3-
import com.cloud.exception.CloudException;
43
import com.cloud.utils.SerialVersionUID;
4+
import com.cloud.utils.exception.CloudRuntimeException;
55

6-
public class AffinityConflictException extends CloudException {
6+
public class AffinityConflictException extends CloudRuntimeException {
77

88
private static final long serialVersionUID = SerialVersionUID.AffinityConflictException;
99

api/src/org/apache/cloudstack/affinity/AffinityGroupProcessor.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
package org.apache.cloudstack.affinity;
22

3-
import org.apache.cloudstack.deploy.UserPreferrenceProcessor;
3+
import com.cloud.deploy.DeploymentPlan;
4+
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
5+
import com.cloud.exception.AffinityConflictException;
6+
import com.cloud.utils.component.Adapter;
7+
import com.cloud.vm.VirtualMachine;
8+
import com.cloud.vm.VirtualMachineProfile;
49

5-
public interface AffinityGroupProcessor extends UserPreferrenceProcessor {
10+
public interface AffinityGroupProcessor extends Adapter {
11+
12+
/**
13+
* process() is called to apply any user preferences to the deployment plan
14+
* and avoid set for the given VM placement.
15+
*
16+
* @param vm
17+
* virtual machine.
18+
* @param plan
19+
* deployment plan that tells you where it's being deployed to.
20+
* @param avoid
21+
* avoid these data centers, pods, clusters, or hosts.
22+
*/
23+
void process(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, ExcludeList avoid)
24+
throws AffinityConflictException;
625

726
/**
827
* getType() should return the affinity/anti-affinity group being
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.apache.cloudstack.affinity;
2+
3+
import com.cloud.deploy.DeploymentPlan;
4+
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
5+
import com.cloud.exception.AffinityConflictException;
6+
import com.cloud.utils.component.AdapterBase;
7+
import com.cloud.vm.VirtualMachine;
8+
import com.cloud.vm.VirtualMachineProfile;
9+
10+
public class AffinityProcessorBase extends AdapterBase implements AffinityGroupProcessor {
11+
12+
protected String _type;
13+
14+
@Override
15+
public void process(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, ExcludeList avoid)
16+
throws AffinityConflictException {
17+
18+
}
19+
20+
@Override
21+
public String getType() {
22+
return _type;
23+
}
24+
25+
public void setType(String type) {
26+
_type = type;
27+
}
28+
}

api/src/org/apache/cloudstack/deploy/UserPreferrenceProcessor.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

client/tomcatconf/commands.properties.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,3 +574,4 @@ createAffinityGroup=15
574574
deleteAffinityGroup=15
575575
listAffinityGroups=15
576576
updateVMAffinityGroup=15
577+
listAffinityGroupTypes=15

engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
import com.cloud.deploy.DeployDestination;
3737
import com.cloud.deploy.DeploymentPlan;
3838
import com.cloud.deploy.DeploymentPlanner;
39+
import com.cloud.deploy.DeploymentPlanningManager;
3940
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
41+
import com.cloud.exception.AffinityConflictException;
4042
import com.cloud.exception.AgentUnavailableException;
4143
import com.cloud.exception.ConcurrentOperationException;
4244
import com.cloud.exception.InsufficientCapacityException;
@@ -55,7 +57,7 @@
5557
import com.cloud.storage.dao.VolumeDao;
5658
import com.cloud.user.dao.AccountDao;
5759
import com.cloud.user.dao.UserDao;
58-
import com.cloud.utils.component.ComponentContext;
60+
import com.cloud.utils.exception.CloudRuntimeException;
5961
import com.cloud.vm.VMInstanceVO;
6062
import com.cloud.vm.VirtualMachineManager;
6163
import com.cloud.vm.VirtualMachineProfile;
@@ -69,42 +71,45 @@ public class VMEntityManagerImpl implements VMEntityManager {
6971
protected VMInstanceDao _vmDao;
7072
@Inject
7173
protected VMTemplateDao _templateDao = null;
72-
74+
7375
@Inject
7476
protected ServiceOfferingDao _serviceOfferingDao;
75-
77+
7678
@Inject
7779
protected DiskOfferingDao _diskOfferingDao = null;
78-
80+
7981
@Inject
8082
protected NetworkDao _networkDao;
81-
83+
8284
@Inject
8385
protected AccountDao _accountDao = null;
8486

8587
@Inject
8688
protected UserDao _userDao = null;
8789

88-
@Inject
90+
@Inject
8991
protected VMEntityDao _vmEntityDao;
90-
91-
@Inject
92+
93+
@Inject
9294
protected VMReservationDao _reservationDao;
93-
95+
9496
@Inject
9597
protected VirtualMachineManager _itMgr;
96-
98+
9799
@Inject
98100
protected List<DeploymentPlanner> _planners;
99-
101+
100102
@Inject
101103
protected VolumeDao _volsDao;
102-
104+
103105
@Inject
104106
protected PrimaryDataStoreDao _storagePoolDao;
105107
@Inject
106108
DataStoreManager dataStoreMgr;
107-
109+
110+
@Inject
111+
DeploymentPlanningManager _dpMgr;
112+
108113
@Override
109114
public VMEntityVO loadVirtualMachine(String vmId) {
110115
// TODO Auto-generated method stub
@@ -114,11 +119,11 @@ public VMEntityVO loadVirtualMachine(String vmId) {
114119
@Override
115120
public void saveVirtualMachine(VMEntityVO entity) {
116121
_vmEntityDao.persist(entity);
117-
122+
118123
}
119124

120125
@Override
121-
public String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse, DeploymentPlan planToDeploy, ExcludeList exclude)
126+
public String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse, DeploymentPlan planToDeploy, ExcludeList exclude)
122127
throws InsufficientCapacityException, ResourceUnavailableException {
123128

124129
//call planner and get the deployDestination.
@@ -130,12 +135,12 @@ public String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse,
130135
if(planToDeploy != null && planToDeploy.getDataCenterId() != 0){
131136
plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), planToDeploy.getPoolId(), planToDeploy.getPhysicalNetworkId());
132137
}
133-
138+
134139
List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
135140
if(!vols.isEmpty()){
136141
VolumeVO vol = vols.get(0);
137142
StoragePool pool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(vol.getPoolId());
138-
143+
139144
if (!pool.isInMaintenance()) {
140145
long rootVolDcId = pool.getDataCenterId();
141146
Long rootVolPodId = pool.getPodId();
@@ -156,21 +161,21 @@ public String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse,
156161

157162
}
158163
}
159-
164+
165+
}
166+
167+
DeployDestination dest;
168+
try {
169+
dest = _dpMgr.planDeployment(vmProfile, plan, exclude);
170+
} catch (AffinityConflictException e) {
171+
throw new CloudRuntimeException("Unable to create deployment, affinity rules associted to the VM conflict");
160172
}
161-
162-
DeploymentPlanner planner = ComponentContext.getComponent(plannerToUse);
163-
DeployDestination dest = null;
164-
165-
if (planner.canHandle(vmProfile, plan, exclude)) {
166-
dest = planner.plan(vmProfile, plan, exclude);
167-
}
168173

169174
if (dest != null) {
170175
//save destination with VMEntityVO
171176
VMReservationVO vmReservation = new VMReservationVO(vm.getId(), dest.getDataCenter().getId(), dest.getPod().getId(), dest.getCluster().getId(), dest.getHost().getId());
172177
Map<Long,Long> volumeReservationMap = new HashMap<Long,Long>();
173-
178+
174179
if (vm.getHypervisorType() != HypervisorType.BareMetal) {
175180
for(Volume vo : dest.getStorageForDisks().keySet()){
176181
volumeReservationMap.put(vo.getId(), dest.getStorageForDisks().get(vo).getId());
@@ -180,21 +185,21 @@ public String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse,
180185

181186
vmEntityVO.setVmReservation(vmReservation);
182187
_vmEntityDao.persist(vmEntityVO);
183-
188+
184189
return vmReservation.getUuid();
185190
}else{
186191
throw new InsufficientServerCapacityException("Unable to create a deployment for " + vmProfile, DataCenter.class, plan.getDataCenterId());
187192
}
188-
193+
189194
}
190195

191196
@Override
192197
public void deployVirtualMachine(String reservationId, String caller, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException{
193198
//grab the VM Id and destination using the reservationId.
194-
199+
195200
VMReservationVO vmReservation = _reservationDao.findByReservationId(reservationId);
196201
long vmId = vmReservation.getVmId();
197-
202+
198203
VMInstanceVO vm = _vmDao.findById(vmId);
199204
//Pass it down
200205
Long poolId = null;
@@ -205,12 +210,17 @@ public void deployVirtualMachine(String reservationId, String caller, Map<Virtua
205210
poolId = storage.get(volIdList.get(0));
206211
}
207212
}
208-
209-
DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vmReservation.getPodId(), vmReservation.getClusterId(),
213+
214+
DataCenterDeployment reservedPlan = new DataCenterDeployment(vm.getDataCenterId(), vmReservation.getPodId(), vmReservation.getClusterId(),
210215
vmReservation.getHostId(), null , null);
211-
212-
VMInstanceVO vmDeployed = _itMgr.start(vm, params, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()), plan);
213-
216+
try{
217+
VMInstanceVO vmDeployed = _itMgr.start(vm, params, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()), reservedPlan);
218+
}catch(Exception ex){
219+
//Retry the deployment without using the reservation plan
220+
DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), null, null,null, null , null);
221+
_itMgr.start(vm, params, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()), plan);
222+
}
223+
214224
}
215225

216226
@Override
@@ -227,7 +237,7 @@ public boolean destroyVirtualMachine(VMEntityVO vmEntityVO, String caller) throw
227237
VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
228238
return _itMgr.destroy(vm, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()));
229239

230-
240+
231241
}
232242

233243
}

plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@
2828
import com.cloud.deploy.DeploymentPlan;
2929
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
3030
import com.cloud.exception.AffinityConflictException;
31-
import com.cloud.utils.component.AdapterBase;
3231
import com.cloud.vm.VMInstanceVO;
3332
import com.cloud.vm.VirtualMachine;
3433
import com.cloud.vm.VirtualMachineProfile;
3534
import com.cloud.vm.dao.UserVmDao;
3635
import com.cloud.vm.dao.VMInstanceDao;
3736

3837
@Local(value = AffinityGroupProcessor.class)
39-
public class HostAntiAffinityProcessor extends AdapterBase implements AffinityGroupProcessor {
38+
public class HostAntiAffinityProcessor extends AffinityProcessorBase implements AffinityGroupProcessor {
4039

4140
private static final Logger s_logger = Logger.getLogger(HostAntiAffinityProcessor.class);
4241
@Inject
@@ -74,9 +73,4 @@ public void process(VirtualMachineProfile<? extends VirtualMachine> vmProfile, D
7473

7574
}
7675

77-
@Override
78-
public String getType() {
79-
return "HostAntiAffinity";
80-
}
81-
8276
}

server/src/com/cloud/deploy/FirstFitPlanner.java

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -161,38 +161,44 @@ public DeployDestination plan(VirtualMachineProfile<? extends VirtualMachine> vm
161161
+ hostIdSpecified);
162162
}
163163
HostVO host = _hostDao.findById(hostIdSpecified);
164-
if (s_logger.isDebugEnabled()) {
165-
if(host == null){
166-
s_logger.debug("The specified host cannot be found");
167-
}else{
164+
if (host == null) {
165+
s_logger.debug("The specified host cannot be found");
166+
} else if (avoid.shouldAvoid(host)) {
167+
s_logger.debug("The specified host is in avoid set");
168+
} else {
169+
if (s_logger.isDebugEnabled()) {
168170
s_logger.debug("Looking for suitable pools for this host under zone: "+host.getDataCenterId() +", pod: "+ host.getPodId()+", cluster: "+ host.getClusterId());
169171
}
170-
}
171172

172-
//search for storage under the zone, pod, cluster of the host.
173-
DataCenterDeployment lastPlan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), hostIdSpecified, plan.getPoolId(), null, plan.getReservationContext());
173+
// search for storage under the zone, pod, cluster of the host.
174+
DataCenterDeployment lastPlan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(),
175+
host.getClusterId(), hostIdSpecified, plan.getPoolId(), null, plan.getReservationContext());
174176

175-
Pair<Map<Volume, List<StoragePool>>, List<Volume>> result = findSuitablePoolsForVolumes(vmProfile, lastPlan, avoid, HostAllocator.RETURN_UPTO_ALL);
176-
Map<Volume, List<StoragePool>> suitableVolumeStoragePools = result.first();
177-
List<Volume> readyAndReusedVolumes = result.second();
177+
Pair<Map<Volume, List<StoragePool>>, List<Volume>> result = findSuitablePoolsForVolumes(vmProfile,
178+
lastPlan, avoid, HostAllocator.RETURN_UPTO_ALL);
179+
Map<Volume, List<StoragePool>> suitableVolumeStoragePools = result.first();
180+
List<Volume> readyAndReusedVolumes = result.second();
178181

179-
//choose the potential pool for this VM for this host
180-
if(!suitableVolumeStoragePools.isEmpty()){
181-
List<Host> suitableHosts = new ArrayList<Host>();
182-
suitableHosts.add(host);
182+
// choose the potential pool for this VM for this host
183+
if (!suitableVolumeStoragePools.isEmpty()) {
184+
List<Host> suitableHosts = new ArrayList<Host>();
185+
suitableHosts.add(host);
183186

184-
Pair<Host, Map<Volume, StoragePool>> potentialResources = findPotentialDeploymentResources(suitableHosts, suitableVolumeStoragePools);
185-
if(potentialResources != null){
186-
Pod pod = _podDao.findById(host.getPodId());
187-
Cluster cluster = _clusterDao.findById(host.getClusterId());
188-
Map<Volume, StoragePool> storageVolMap = potentialResources.second();
189-
// remove the reused vol<->pool from destination, since we don't have to prepare this volume.
190-
for(Volume vol : readyAndReusedVolumes){
191-
storageVolMap.remove(vol);
187+
Pair<Host, Map<Volume, StoragePool>> potentialResources = findPotentialDeploymentResources(
188+
suitableHosts, suitableVolumeStoragePools);
189+
if (potentialResources != null) {
190+
Pod pod = _podDao.findById(host.getPodId());
191+
Cluster cluster = _clusterDao.findById(host.getClusterId());
192+
Map<Volume, StoragePool> storageVolMap = potentialResources.second();
193+
// remove the reused vol<->pool from destination, since
194+
// we don't have to prepare this volume.
195+
for (Volume vol : readyAndReusedVolumes) {
196+
storageVolMap.remove(vol);
197+
}
198+
DeployDestination dest = new DeployDestination(dc, pod, cluster, host, storageVolMap);
199+
s_logger.debug("Returning Deployment Destination: " + dest);
200+
return dest;
192201
}
193-
DeployDestination dest = new DeployDestination(dc, pod, cluster, host, storageVolMap);
194-
s_logger.debug("Returning Deployment Destination: "+ dest);
195-
return dest;
196202
}
197203
}
198204
s_logger.debug("Cannnot deploy to specified host, returning.");

0 commit comments

Comments
 (0)