|
54 | 54 | import org.apache.cloudstack.context.CallContext; |
55 | 55 | import org.apache.commons.collections.CollectionUtils; |
56 | 56 | import org.apache.commons.collections.MapUtils; |
| 57 | +import org.apache.commons.lang3.BooleanUtils; |
| 58 | +import org.apache.commons.lang3.StringUtils; |
57 | 59 | import org.apache.log4j.Logger; |
58 | 60 |
|
59 | 61 | import com.cloud.agent.api.LogLevel; |
|
75 | 77 | import com.cloud.vm.VirtualMachine; |
76 | 78 | import com.cloud.vm.VmDetailConstants; |
77 | 79 |
|
78 | | -import org.apache.commons.lang3.BooleanUtils; |
79 | | -import org.apache.commons.lang3.StringUtils; |
80 | | - |
81 | 80 | @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}, |
82 | 81 | requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) |
83 | 82 | public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityGroupAction, UserCmd { |
@@ -782,32 +781,28 @@ public ApiCommandResourceType getApiResourceType() { |
782 | 781 | public void execute() { |
783 | 782 | UserVm result; |
784 | 783 |
|
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"); |
804 | 801 | } |
805 | | - s_logger.info(ex); |
806 | | - s_logger.info(message.toString(), ex); |
807 | | - throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString()); |
808 | 802 | } |
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()); |
811 | 806 | } |
812 | 807 |
|
813 | 808 | if (result != null) { |
|
0 commit comments