Skip to content

Commit 62fa45a

Browse files
committed
Merge remote-tracking branch 'origin/4.18'
2 parents 9ddfeac + a0eb0aa commit 62fa45a

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

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

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
import org.apache.cloudstack.context.CallContext;
5555
import org.apache.commons.collections.CollectionUtils;
5656
import org.apache.commons.collections.MapUtils;
57+
import org.apache.commons.lang3.BooleanUtils;
58+
import org.apache.commons.lang3.StringUtils;
5759
import org.apache.log4j.Logger;
5860

5961
import com.cloud.agent.api.LogLevel;
@@ -75,9 +77,6 @@
7577
import com.cloud.vm.VirtualMachine;
7678
import com.cloud.vm.VmDetailConstants;
7779

78-
import org.apache.commons.lang3.BooleanUtils;
79-
import org.apache.commons.lang3.StringUtils;
80-
8180
@APICommand(name = "deployVirtualMachine", description = "Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
8281
requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
8382
public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityGroupAction, UserCmd {
@@ -782,32 +781,28 @@ public ApiCommandResourceType getApiResourceType() {
782781
public void execute() {
783782
UserVm result;
784783

785-
if (getStartVm()) {
786-
try {
787-
CallContext.current().setEventDetails("Vm Id: " + getEntityUuid());
788-
result = _userVmService.startVirtualMachine(this);
789-
} catch (ResourceUnavailableException ex) {
790-
s_logger.warn("Exception: ", ex);
791-
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
792-
} catch (ResourceAllocationException ex) {
793-
s_logger.warn("Exception: ", ex);
794-
throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
795-
} catch (ConcurrentOperationException ex) {
796-
s_logger.warn("Exception: ", ex);
797-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
798-
} catch (InsufficientCapacityException ex) {
799-
StringBuilder message = new StringBuilder(ex.getMessage());
800-
if (ex instanceof InsufficientServerCapacityException) {
801-
if (((InsufficientServerCapacityException)ex).isAffinityApplied()) {
802-
message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them");
803-
}
784+
try {
785+
CallContext.current().setEventDetails("Vm Id: " + getEntityUuid());
786+
result = _userVmService.startVirtualMachine(this);
787+
} catch (ResourceUnavailableException ex) {
788+
s_logger.warn("Exception: ", ex);
789+
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
790+
} catch (ResourceAllocationException ex) {
791+
s_logger.warn("Exception: ", ex);
792+
throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
793+
} catch (ConcurrentOperationException ex) {
794+
s_logger.warn("Exception: ", ex);
795+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
796+
} catch (InsufficientCapacityException ex) {
797+
StringBuilder message = new StringBuilder(ex.getMessage());
798+
if (ex instanceof InsufficientServerCapacityException) {
799+
if (((InsufficientServerCapacityException)ex).isAffinityApplied()) {
800+
message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them");
804801
}
805-
s_logger.info(ex);
806-
s_logger.info(message.toString(), ex);
807-
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString());
808802
}
809-
} else {
810-
result = _userVmService.getUserVm(getEntityId());
803+
s_logger.info(ex);
804+
s_logger.info(message.toString(), ex);
805+
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString());
811806
}
812807

813808
if (result != null) {

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4810,9 +4810,12 @@ protected String validateUserData(String userData, HTTPMethod httpmethod) {
48104810
}
48114811

48124812
@Override
4813-
@ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = "starting Vm", async = true)
4813+
@ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = "deploying Vm", async = true)
48144814
public UserVm startVirtualMachine(DeployVMCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException {
48154815
long vmId = cmd.getEntityId();
4816+
if (!cmd.getStartVm()) {
4817+
return getUserVm(vmId);
4818+
}
48164819
Long podId = null;
48174820
Long clusterId = null;
48184821
Long hostId = cmd.getHostId();

0 commit comments

Comments
 (0)