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.cloudstack.context.CallContext;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.collections.MapUtils;
|
import org.apache.commons.collections.MapUtils;
|
||||||
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.agent.api.LogLevel;
|
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.VirtualMachine;
|
||||||
import com.cloud.vm.VmDetailConstants;
|
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},
|
@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)
|
requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
|
||||||
public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityGroupAction, UserCmd {
|
public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityGroupAction, UserCmd {
|
||||||
@ -766,32 +765,28 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG
|
|||||||
public void execute() {
|
public void execute() {
|
||||||
UserVm result;
|
UserVm result;
|
||||||
|
|
||||||
if (getStartVm()) {
|
try {
|
||||||
try {
|
CallContext.current().setEventDetails("Vm Id: " + getEntityUuid());
|
||||||
CallContext.current().setEventDetails("Vm Id: " + getEntityUuid());
|
result = _userVmService.startVirtualMachine(this);
|
||||||
result = _userVmService.startVirtualMachine(this);
|
} catch (ResourceUnavailableException ex) {
|
||||||
} catch (ResourceUnavailableException ex) {
|
s_logger.warn("Exception: ", ex);
|
||||||
s_logger.warn("Exception: ", ex);
|
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
|
||||||
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
|
} catch (ResourceAllocationException ex) {
|
||||||
} catch (ResourceAllocationException ex) {
|
s_logger.warn("Exception: ", ex);
|
||||||
s_logger.warn("Exception: ", ex);
|
throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
|
||||||
throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
|
} catch (ConcurrentOperationException ex) {
|
||||||
} catch (ConcurrentOperationException ex) {
|
s_logger.warn("Exception: ", ex);
|
||||||
s_logger.warn("Exception: ", ex);
|
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
|
||||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
|
} catch (InsufficientCapacityException ex) {
|
||||||
} catch (InsufficientCapacityException ex) {
|
StringBuilder message = new StringBuilder(ex.getMessage());
|
||||||
StringBuilder message = new StringBuilder(ex.getMessage());
|
if (ex instanceof InsufficientServerCapacityException) {
|
||||||
if (ex instanceof InsufficientServerCapacityException) {
|
if (((InsufficientServerCapacityException)ex).isAffinityApplied()) {
|
||||||
if (((InsufficientServerCapacityException)ex).isAffinityApplied()) {
|
message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them");
|
||||||
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 {
|
s_logger.info(ex);
|
||||||
result = _userVmService.getUserVm(getEntityId());
|
s_logger.info(message.toString(), ex);
|
||||||
|
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
|||||||
@ -4810,9 +4810,12 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 {
|
public UserVm startVirtualMachine(DeployVMCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException {
|
||||||
long vmId = cmd.getEntityId();
|
long vmId = cmd.getEntityId();
|
||||||
|
if (!cmd.getStartVm()) {
|
||||||
|
return getUserVm(vmId);
|
||||||
|
}
|
||||||
Long podId = null;
|
Long podId = null;
|
||||||
Long clusterId = null;
|
Long clusterId = null;
|
||||||
Long hostId = cmd.getHostId();
|
Long hostId = cmd.getHostId();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user