Search in sources :

Example 11 with UserVmResponse

use of org.apache.cloudstack.api.response.UserVmResponse in project cloudstack by apache.

the class RebootVMCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException {
    CallContext.current().setEventDetails("Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getId()));
    UserVm result;
    result = _userVmService.rebootVirtualMachine(this);
    if (result != null) {
        UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", result).get(0);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reboot vm instance");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Example 12 with UserVmResponse

use of org.apache.cloudstack.api.response.UserVmResponse in project cloudstack by apache.

the class RemoveNicFromVMCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getVmId()) + " Nic Id: " + this._uuidMgr.getUuid(Nic.class, getNicId()));
    UserVm result = _userVmService.removeNicFromVirtualMachine(this);
    ArrayList<VMDetails> dc = new ArrayList<VMDetails>();
    dc.add(VMDetails.valueOf("nics"));
    EnumSet<VMDetails> details = EnumSet.copyOf(dc);
    if (result != null) {
        UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", details, result).get(0);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove NIC from vm, see error log for details");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) VMDetails(org.apache.cloudstack.api.ApiConstants.VMDetails) ServerApiException(org.apache.cloudstack.api.ServerApiException) ArrayList(java.util.ArrayList) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Example 13 with UserVmResponse

use of org.apache.cloudstack.api.response.UserVmResponse in project cloudstack by apache.

the class StartVMCmd method execute.

@Override
public void execute() {
    try {
        CallContext.current().setEventDetails("Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getId()));
        UserVm result;
        result = _userVmService.startVirtualMachine(this);
        if (result != null) {
            UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", result).get(0);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to start a vm");
        }
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (StorageUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ExecutionException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } 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 (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());
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) ExecutionException(com.cloud.utils.exception.ExecutionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 14 with UserVmResponse

use of org.apache.cloudstack.api.response.UserVmResponse in project cloudstack by apache.

the class StopVMCmd method execute.

@Override
public void execute() throws ServerApiException, ConcurrentOperationException {
    CallContext.current().setEventDetails("Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getId()));
    UserVm result;
    result = _userVmService.stopVirtualMachine(getId(), isForced());
    if (result != null) {
        UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", result).get(0);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to stop vm");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Example 15 with UserVmResponse

use of org.apache.cloudstack.api.response.UserVmResponse in project cloudstack by apache.

the class AssignVMCmd method execute.

@Override
public void execute() {
    try {
        UserVm userVm = _userVmService.moveVMToUser(this);
        if (userVm == null) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm");
        }
        UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", userVm).get(0);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } catch (InvalidParameterValueException e) {
        e.printStackTrace();
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    } catch (Exception e) {
        s_logger.error("Failed to move vm due to: " + e.getStackTrace());
        if (e.getMessage() != null) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm due to " + e.getMessage());
        } else if (e.getCause() != null) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm due to " + e.getCause());
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm");
        }
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

Aggregations

UserVmResponse (org.apache.cloudstack.api.response.UserVmResponse)56 UserVm (com.cloud.uservm.UserVm)49 ServerApiException (org.apache.cloudstack.api.ServerApiException)43 ArrayList (java.util.ArrayList)19 VMDetails (org.apache.cloudstack.api.ApiConstants.VMDetails)12 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)8 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)7 Account (com.cloud.user.Account)7 UserVmJoinVO (com.cloud.api.query.vo.UserVmJoinVO)6 VirtualMachine (com.cloud.vm.VirtualMachine)6 List (java.util.List)5 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4 InsufficientServerCapacityException (com.cloud.exception.InsufficientServerCapacityException)4 ManagementServerException (com.cloud.exception.ManagementServerException)4 VirtualMachineMigrationException (com.cloud.exception.VirtualMachineMigrationException)4 Host (com.cloud.host.Host)4 ServiceOffering (com.cloud.offering.ServiceOffering)4 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)4 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)4