mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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.mrt22@gmail.com>
This commit is contained in:
parent
8c546bd5a6
commit
a0eb0aa5f7
@ -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) {
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user