This is an automated email from the ASF dual-hosted git repository. rohit pushed a commit to branch 4.18 in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.18 by this push: new a0eb0aa5f7a api,server: fix VM.CREATE events on vm deploy without start (#7421) a0eb0aa5f7a is described below commit a0eb0aa5f7ad07cc45fb3e0d66fddd41437460b7 Author: Abhishek Kumar <abhishek.mr...@gmail.com> AuthorDate: Thu May 11 23:23:00 2023 +0530 api,server: fix VM.CREATE events on vm deploy without start (#7421) Fixes #6697 Allows the server to generate started and completed events for VM.CREATE event type when VM is deployed with startvm=false. Signed-off-by: Abhishek Kumar <abhishek.mr...@gmail.com> --- .../api/command/user/vm/DeployVMCmd.java | 49 ++++++++++------------ .../main/java/com/cloud/vm/UserVmManagerImpl.java | 5 ++- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java index 628b332cecb..78d6155d012 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java @@ -54,6 +54,8 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import com.cloud.agent.api.LogLevel; @@ -75,9 +77,6 @@ import com.cloud.utils.net.NetUtils; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VmDetailConstants; -import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.StringUtils; - @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}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityGroupAction, UserCmd { @@ -766,32 +765,28 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG public void execute() { UserVm result; - if (getStartVm()) { - try { - CallContext.current().setEventDetails("Vm Id: " + getEntityUuid()); - result = _userVmService.startVirtualMachine(this); - } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); - throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); - } catch (ResourceAllocationException ex) { - s_logger.warn("Exception: ", ex); - throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage()); - } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); - throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); - } catch (InsufficientCapacityException ex) { - StringBuilder message = new StringBuilder(ex.getMessage()); - if (ex instanceof InsufficientServerCapacityException) { - if (((InsufficientServerCapacityException)ex).isAffinityApplied()) { - message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them"); - } + try { + CallContext.current().setEventDetails("Vm Id: " + getEntityUuid()); + result = _userVmService.startVirtualMachine(this); + } catch (ResourceUnavailableException ex) { + s_logger.warn("Exception: ", ex); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + } catch (ResourceAllocationException ex) { + s_logger.warn("Exception: ", ex); + throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage()); + } catch (ConcurrentOperationException ex) { + s_logger.warn("Exception: ", ex); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } catch (InsufficientCapacityException ex) { + StringBuilder message = new StringBuilder(ex.getMessage()); + if (ex instanceof InsufficientServerCapacityException) { + if (((InsufficientServerCapacityException)ex).isAffinityApplied()) { + message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them"); } - s_logger.info(ex); - s_logger.info(message.toString(), ex); - throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString()); } - } else { - result = _userVmService.getUserVm(getEntityId()); + s_logger.info(ex); + s_logger.info(message.toString(), ex); + throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString()); } if (result != null) { diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java index 7307ccca6e6..3f73b620c38 100644 --- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java @@ -4810,9 +4810,12 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } @Override - @ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = "starting Vm", async = true) + @ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = "deploying Vm", async = true) public UserVm startVirtualMachine(DeployVMCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException { long vmId = cmd.getEntityId(); + if (!cmd.getStartVm()) { + return getUserVm(vmId); + } Long podId = null; Long clusterId = null; Long hostId = cmd.getHostId();