Skip to content

Commit 1b83698

Browse files
author
Alena Prokharchyk
committed
deployVm/startVm APIs: ability to define deploymentPlanner for VmToStart in the api call (available to ROOT admin only)
1 parent 5779292 commit 1b83698

18 files changed

Lines changed: 113 additions & 64 deletions

File tree

api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd {
178178
@Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, since = "4.3", description = "used to specify the custom parameters.")
179179
private Map details;
180180

181+
@Parameter(name = ApiConstants.DEPLOYMENT_PLANNER, type = CommandType.STRING, description = "Deployment planner to use for vm allocation. Available to ROOT admin only", since = "4.4", authorized = { RoleType.Admin })
182+
private String deploymentPlanner;
183+
181184
/////////////////////////////////////////////////////
182185
/////////////////// Accessors ///////////////////////
183186
/////////////////////////////////////////////////////
@@ -193,6 +196,10 @@ public Long getDiskOfferingId() {
193196
return diskOfferingId;
194197
}
195198

199+
public String getDeploymentPlanner() {
200+
return deploymentPlanner;
201+
}
202+
196203
public String getDisplayName() {
197204
return displayName;
198205
}

api/src/org/apache/cloudstack/api/command/user/vm/StartVMCmd.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.vm;
1818

19-
import org.apache.cloudstack.api.BaseAsyncVMCmd;
20-
import org.apache.log4j.Logger;
21-
19+
import org.apache.cloudstack.acl.RoleType;
2220
import org.apache.cloudstack.api.APICommand;
2321
import org.apache.cloudstack.api.ApiCommandJobType;
2422
import org.apache.cloudstack.api.ApiConstants;
2523
import org.apache.cloudstack.api.ApiErrorCode;
24+
import org.apache.cloudstack.api.BaseAsyncVMCmd;
2625
import org.apache.cloudstack.api.Parameter;
2726
import org.apache.cloudstack.api.ServerApiException;
2827
import org.apache.cloudstack.api.response.HostResponse;
2928
import org.apache.cloudstack.api.response.UserVmResponse;
3029
import org.apache.cloudstack.context.CallContext;
30+
import org.apache.log4j.Logger;
3131

3232
import com.cloud.event.EventTypes;
3333
import com.cloud.exception.ConcurrentOperationException;
@@ -61,6 +61,9 @@ public class StartVMCmd extends BaseAsyncVMCmd {
6161
since = "3.0.1")
6262
private Long hostId;
6363

64+
@Parameter(name = ApiConstants.DEPLOYMENT_PLANNER, type = CommandType.STRING, description = "Deployment planner to use for vm allocation. Available to ROOT admin only", since = "4.4", authorized = { RoleType.Admin })
65+
private String deploymentPlanner;
66+
6467
// ///////////////////////////////////////////////////
6568
// ///////////////// Accessors ///////////////////////
6669
// ///////////////////////////////////////////////////
@@ -86,6 +89,10 @@ public static String getResultObjectName() {
8689
return "virtualmachine";
8790
}
8891

92+
public String getDeploymentPlanner() {
93+
return deploymentPlanner;
94+
}
95+
8996
@Override
9097
public long getEntityOwnerId() {
9198
UserVm vm = _responseGenerator.findUserVmById(getId());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void allocate(String vmInstanceName, VirtualMachineTemplate template, ServiceOff
8585

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

88-
void start(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, DeploymentPlan planToDeploy);
88+
void start(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, DeploymentPlan planToDeploy, DeploymentPlanner planner);
8989

9090
void stop(String vmUuid) throws ResourceUnavailableException;
9191

engine/api/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.cloudstack.engine.entity.api.CloudStackEntity;
3131

3232
import com.cloud.deploy.DeploymentPlan;
33+
import com.cloud.deploy.DeploymentPlanner;
3334
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
3435
import com.cloud.exception.AgentUnavailableException;
3536
import com.cloud.exception.CloudException;
@@ -90,7 +91,7 @@ public interface VirtualMachineEntity extends CloudStackEntity {
9091
* @param exclude list of areas to exclude
9192
* @return a reservation id
9293
*/
93-
String reserve(String plannerToUse, @BeanParam DeploymentPlan plan, ExcludeList exclude, String caller) throws InsufficientCapacityException,
94+
String reserve(DeploymentPlanner plannerToUse, @BeanParam DeploymentPlan plan, ExcludeList exclude, String caller) throws InsufficientCapacityException,
9495
ResourceUnavailableException;
9596

9697
/**

engine/components-api/src/com/cloud/deploy/DeploymentPlanningManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ DeployDestination planDeployment(VirtualMachineProfile vmProfile, DeploymentPlan
4343
ExcludeList avoids, DeploymentPlanner planner) throws InsufficientServerCapacityException, AffinityConflictException;
4444

4545
String finalizeReservation(DeployDestination plannedDestination,
46-
VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids)
46+
VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids, DeploymentPlanner planner)
4747
throws InsufficientServerCapacityException, AffinityConflictException;
4848

4949
void cleanupVMReservations();
50+
51+
DeploymentPlanner getDeploymentPlannerByName(String plannerName);
5052
}

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
import javax.inject.Inject;
4141
import javax.naming.ConfigurationException;
4242

43-
import org.apache.log4j.Logger;
44-
4543
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
4644
import org.apache.cloudstack.context.CallContext;
4745
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
@@ -70,6 +68,7 @@
7068
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
7169
import org.apache.cloudstack.storage.to.VolumeObjectTO;
7270
import org.apache.cloudstack.utils.identity.ManagementServerNode;
71+
import org.apache.log4j.Logger;
7372

7473
import com.cloud.agent.AgentManager;
7574
import com.cloud.agent.Listener;
@@ -80,8 +79,8 @@
8079
import com.cloud.agent.api.CheckVirtualMachineCommand;
8180
import com.cloud.agent.api.ClusterSyncAnswer;
8281
import com.cloud.agent.api.ClusterSyncCommand;
83-
import com.cloud.agent.api.ClusterVMMetaDataSyncCommand;
8482
import com.cloud.agent.api.ClusterVMMetaDataSyncAnswer;
83+
import com.cloud.agent.api.ClusterVMMetaDataSyncCommand;
8584
import com.cloud.agent.api.Command;
8685
import com.cloud.agent.api.MigrateAnswer;
8786
import com.cloud.agent.api.MigrateCommand;
@@ -608,13 +607,13 @@ protected VirtualMachineManagerImpl() {
608607

609608
@Override
610609
public void start(String vmUuid, Map<VirtualMachineProfile.Param, Object> params) {
611-
start(vmUuid, params, null);
610+
start(vmUuid, params, null, null);
612611
}
613612

614613
@Override
615-
public void start(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, DeploymentPlan planToDeploy) {
614+
public void start(String vmUuid, Map<VirtualMachineProfile.Param, Object> params, DeploymentPlan planToDeploy, DeploymentPlanner planner) {
616615
try {
617-
advanceStart(vmUuid, params, planToDeploy, null);
616+
advanceStart(vmUuid, params, planToDeploy, planner);
618617
} catch (ConcurrentOperationException e) {
619618
throw new CloudRuntimeException("Unable to start a VM due to concurrent operation", e).add(VirtualMachine.class, vmUuid);
620619
} catch (InsufficientCapacityException e) {
@@ -779,7 +778,7 @@ public void advanceStart(String vmUuid, Map<VirtualMachineProfile.Param, Object>
779778
_workJobDao.expunge(placeHolder.getId());
780779
}
781780
} else {
782-
Outcome<VirtualMachine> outcome = startVmThroughJobQueue(vmUuid, params, planToDeploy);
781+
Outcome<VirtualMachine> outcome = startVmThroughJobQueue(vmUuid, params, planToDeploy, planner);
783782

784783
try {
785784
VirtualMachine vm = outcome.get();
@@ -4451,7 +4450,7 @@ protected VirtualMachine retrieve() {
44514450
//
44524451
public Outcome<VirtualMachine> startVmThroughJobQueue(final String vmUuid,
44534452
final Map<VirtualMachineProfile.Param, Object> params,
4454-
final DeploymentPlan planToDeploy) {
4453+
final DeploymentPlan planToDeploy, final DeploymentPlanner planner) {
44554454

44564455
final CallContext context = CallContext.current();
44574456
final User callingUser = context.getCallingUser();
@@ -4488,6 +4487,9 @@ public Object[] doInTransaction(TransactionStatus status) {
44884487
// save work context info (there are some duplications)
44894488
VmWorkStart workInfo = new VmWorkStart(callingUser.getId(), callingAccount.getId(), vm.getId(), VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER);
44904489
workInfo.setPlan(planToDeploy);
4490+
if (planner != null) {
4491+
workInfo.setDeploymentPlanner(planner.getName());
4492+
}
44914493
workInfo.setParams(params);
44924494
workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
44934495

@@ -5123,7 +5125,7 @@ private Pair<JobInfo.Status, String> orchestrateStart(VmWorkStart work) throws E
51235125
}
51245126
assert (vm != null);
51255127

5126-
orchestrateStart(vm.getUuid(), work.getParams(), work.getPlan(), null);
5128+
orchestrateStart(vm.getUuid(), work.getParams(), work.getPlan(), _dpMgr.getDeploymentPlannerByName(work.getDeploymentPlanner()));
51275129
return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, null);
51285130
}
51295131

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
import java.util.HashMap;
2222
import java.util.Map;
2323

24-
import org.apache.log4j.Logger;
25-
2624
import org.apache.cloudstack.context.CallContext;
2725
import org.apache.cloudstack.framework.jobs.impl.JobSerializerHelper;
26+
import org.apache.log4j.Logger;
2827

2928
import com.cloud.deploy.DataCenterDeployment;
3029
import com.cloud.deploy.DeploymentPlan;
@@ -46,6 +45,7 @@ public class VmWorkStart extends VmWork {
4645

4746
String reservationId;
4847
String journalName;
48+
String planner;
4949

5050
// use serialization friendly map
5151
private Map<String, String> rawParams;
@@ -91,6 +91,14 @@ public void setPlan(DeploymentPlan plan) {
9191
}
9292
}
9393

94+
public void setDeploymentPlanner(String planner) {
95+
this.planner = planner;
96+
}
97+
98+
public String getDeploymentPlanner() {
99+
return this.planner;
100+
}
101+
94102
public Map<String, String> getRawParams() {
95103
return rawParams;
96104
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO;
2222

2323
import com.cloud.deploy.DeploymentPlan;
24+
import com.cloud.deploy.DeploymentPlanner;
2425
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
2526
import com.cloud.exception.AgentUnavailableException;
2627
import com.cloud.exception.ConcurrentOperationException;
@@ -35,7 +36,7 @@ public interface VMEntityManager {
3536

3637
void saveVirtualMachine(VMEntityVO vmInstanceVO);
3738

38-
String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse, DeploymentPlan plan, ExcludeList exclude) throws InsufficientCapacityException,
39+
String reserveVirtualMachine(VMEntityVO vmEntityVO, DeploymentPlanner plannerToUse, DeploymentPlan plan, ExcludeList exclude) throws InsufficientCapacityException,
3940
ResourceUnavailableException;
4041

4142
void deployVirtualMachine(String reservationId, VMEntityVO vmEntityVO, String caller, Map<VirtualMachineProfile.Param, Object> params)

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@
2222

2323
import javax.inject.Inject;
2424

25-
import org.apache.log4j.Logger;
26-
import org.springframework.stereotype.Component;
27-
2825
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
2926
import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO;
3027
import org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO;
3128
import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMEntityDao;
3229
import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMReservationDao;
3330
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
3431
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
32+
import org.apache.log4j.Logger;
33+
import org.springframework.stereotype.Component;
3534

3635
import com.cloud.dc.DataCenter;
3736
import com.cloud.deploy.DataCenterDeployment;
@@ -114,6 +113,8 @@ public class VMEntityManagerImpl implements VMEntityManager {
114113

115114
@Inject
116115
protected AffinityGroupVMMapDao _affinityGroupVMMapDao;
116+
@Inject
117+
DeploymentPlanningManager _planningMgr;
117118

118119
@Override
119120
public VMEntityVO loadVirtualMachine(String vmId) {
@@ -138,7 +139,7 @@ protected boolean areAffinityGroupsAssociated(VirtualMachineProfile vmProfile) {
138139
}
139140

140141
@Override
141-
public String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse, DeploymentPlan planToDeploy, ExcludeList exclude)
142+
public String reserveVirtualMachine(VMEntityVO vmEntityVO, DeploymentPlanner plannerToUse, DeploymentPlan planToDeploy, ExcludeList exclude)
142143
throws InsufficientCapacityException, ResourceUnavailableException {
143144

144145
//call planner and get the deployDestination.
@@ -189,13 +190,13 @@ public String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse,
189190
while (true) {
190191
DeployDestination dest = null;
191192
try {
192-
dest = _dpMgr.planDeployment(vmProfile, plan, exclude, null);
193+
dest = _dpMgr.planDeployment(vmProfile, plan, exclude, plannerToUse);
193194
} catch (AffinityConflictException e) {
194195
throw new CloudRuntimeException("Unable to create deployment, affinity rules associted to the VM conflict");
195196
}
196197

197198
if (dest != null) {
198-
String reservationId = _dpMgr.finalizeReservation(dest, vmProfile, plan, exclude);
199+
String reservationId = _dpMgr.finalizeReservation(dest, vmProfile, plan, exclude, plannerToUse);
199200
if (reservationId != null) {
200201
return reservationId;
201202
} else {
@@ -229,7 +230,7 @@ public void deployVirtualMachine(String reservationId, VMEntityVO vmEntityVO, St
229230
DataCenterDeployment reservedPlan =
230231
new DataCenterDeployment(vm.getDataCenterId(), vmReservation.getPodId(), vmReservation.getClusterId(), vmReservation.getHostId(), null, null);
231232
try {
232-
_itMgr.start(vm.getUuid(), params, reservedPlan);
233+
_itMgr.start(vm.getUuid(), params, reservedPlan, _planningMgr.getDeploymentPlannerByName(vmReservation.getDeploymentPlanner()));
233234
} catch (Exception ex) {
234235
// Retry the deployment without using the reservation plan
235236
DataCenterDeployment plan = new DataCenterDeployment(0, null, null, null, null, null);
@@ -238,11 +239,11 @@ public void deployVirtualMachine(String reservationId, VMEntityVO vmEntityVO, St
238239
plan.setAvoids(reservedPlan.getAvoids());
239240
}
240241

241-
_itMgr.start(vm.getUuid(), params, plan);
242+
_itMgr.start(vm.getUuid(), params, plan, null);
242243
}
243244
} else {
244245
// no reservation found. Let VirtualMachineManager retry
245-
_itMgr.start(vm.getUuid(), params, null);
246+
_itMgr.start(vm.getUuid(), params, null, null);
246247
}
247248

248249
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
import javax.inject.Inject;
2525

2626
import org.springframework.stereotype.Component;
27-
2827
import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO;
2928

3029
import com.cloud.deploy.DeploymentPlan;
30+
import com.cloud.deploy.DeploymentPlanner;
3131
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
3232
import com.cloud.exception.AgentUnavailableException;
3333
import com.cloud.exception.ConcurrentOperationException;
@@ -195,7 +195,7 @@ public void delTag() {
195195
}
196196

197197
@Override
198-
public String reserve(String plannerToUse, DeploymentPlan plan, ExcludeList exclude, String caller) throws InsufficientCapacityException,
198+
public String reserve(DeploymentPlanner plannerToUse, DeploymentPlan plan, ExcludeList exclude, String caller) throws InsufficientCapacityException,
199199
ResourceUnavailableException {
200200
return manager.reserveVirtualMachine(this.vmEntityVO, plannerToUse, plan, exclude);
201201
}

0 commit comments

Comments
 (0)