Search in sources :

Example 76 with ServerApiException

use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.

the class DeployVMCmd method execute.

@Override
public void execute() {
    UserVm result;
    if (getStartVm()) {
        try {
            UserContext.current().setEventDetails("Vm Id: " + getEntityId());
            if (getHypervisor() == HypervisorType.BareMetal) {
                result = _bareMetalVmService.startVirtualMachine(this);
            } else {
                result = _userVmService.startVirtualMachine(this);
            }
        } catch (ResourceUnavailableException ex) {
            s_logger.warn("Exception: ", ex);
            throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
        } catch (ConcurrentOperationException ex) {
            s_logger.warn("Exception: ", ex);
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
        } catch (InsufficientCapacityException ex) {
            s_logger.info(ex);
            s_logger.trace(ex);
            throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
        }
    } else {
        result = _userVmService.getUserVm(getEntityId());
    }
    if (result != null) {
        UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to deploy vm");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(com.cloud.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) UserVmResponse(com.cloud.api.response.UserVmResponse)

Example 77 with ServerApiException

use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.

the class DestroyConsoleProxyCmd method execute.

@Override
public void execute() {
    boolean result = _consoleProxyService.destroyConsoleProxy(this);
    if (result) {
        SuccessResponse response = new SuccessResponse(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to destroy console proxy");
    }
}
Also used : SuccessResponse(com.cloud.api.response.SuccessResponse) ServerApiException(com.cloud.api.ServerApiException)

Example 78 with ServerApiException

use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.

the class DestroySystemVmCmd method execute.

@Override
public void execute() {
    UserContext.current().setEventDetails("Vm Id: " + getId());
    VirtualMachine instance = _mgr.destroySystemVM(this);
    if (instance != null) {
        SystemVmResponse response = _responseGenerator.createSystemVmResponse(instance);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Fail to destroy system vm");
    }
}
Also used : SystemVmResponse(com.cloud.api.response.SystemVmResponse) ServerApiException(com.cloud.api.ServerApiException) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 79 with ServerApiException

use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.

the class DestroyVMCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ConcurrentOperationException {
    UserContext.current().setEventDetails("Vm Id: " + getId());
    UserVm result;
    if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
        result = _bareMetalVmService.destroyVm(this);
    } else {
        result = _userVmService.destroyVm(this);
    }
    if (result != null) {
        UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
        response.setResponseName("virtualmachine");
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to destroy vm");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(com.cloud.api.ServerApiException) UserVmResponse(com.cloud.api.response.UserVmResponse)

Example 80 with ServerApiException

use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.

the class DetachIsoCmd method execute.

@Override
public void execute() {
    boolean result = _templateService.detachIso(virtualMachineId);
    if (result) {
        UserVm userVm = _entityMgr.findById(UserVm.class, virtualMachineId);
        UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", userVm).get(0);
        response.setResponseName(DeployVMCmd.getResultObjectName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to detach iso");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(com.cloud.api.ServerApiException) UserVmResponse(com.cloud.api.response.UserVmResponse)

Aggregations

ServerApiException (com.cloud.api.ServerApiException)170 SuccessResponse (com.cloud.api.response.SuccessResponse)46 UserVm (com.cloud.uservm.UserVm)15 UserVmResponse (com.cloud.api.response.UserVmResponse)14 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)12 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)12 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)12 Account (com.cloud.user.Account)9 Host (com.cloud.host.Host)8 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)8 ListResponse (com.cloud.api.response.ListResponse)7 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)7 HostResponse (com.cloud.api.response.HostResponse)6 TemplateResponse (com.cloud.api.response.TemplateResponse)6 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)6 AccountResponse (com.cloud.api.response.AccountResponse)5 SystemVmResponse (com.cloud.api.response.SystemVmResponse)5 UserResponse (com.cloud.api.response.UserResponse)5 VolumeResponse (com.cloud.api.response.VolumeResponse)5 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)5