Search in sources :

Example 11 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class DestroyVMCmdByAdmin method execute.

@Override
public void execute() throws ResourceUnavailableException, ConcurrentOperationException {
    CallContext.current().setEventDetails("Vm Id: " + getId());
    UserVm result = _userVmService.destroyVm(this);
    UserVmResponse response = new UserVmResponse();
    if (result != null) {
        List<UserVmResponse> responses = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result);
        if (responses != null && !responses.isEmpty()) {
            response = responses.get(0);
        }
        response.setResponseName("virtualmachine");
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to destroy vm");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Example 12 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class UpdateVPCCmdByAdmin method execute.

@Override
public void execute() {
    Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText(), getCustomId(), getDisplayVpc());
    if (result != null) {
        VpcResponse response = _responseGenerator.createVpcResponse(ResponseView.Full, result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update VPC");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) VpcResponse(org.apache.cloudstack.api.response.VpcResponse) Vpc(com.cloud.network.vpc.Vpc)

Example 13 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class CreateVolumeCmdByAdmin method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Volume Id: " + getEntityId() + ((getSnapshotId() == null) ? "" : " from snapshot: " + getSnapshotId()));
    Volume volume = _volumeService.createVolume(this);
    if (volume != null) {
        VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume);
        //FIXME - have to be moved to ApiResponseHelper
        if (getSnapshotId() != null) {
            Snapshot snap = _entityMgr.findById(Snapshot.class, getSnapshotId());
            if (snap != null) {
                // if the volume was
                response.setSnapshotId(snap.getUuid());
            // created from a
            // snapshot,
            // snapshotId will
            // be set so we pass
            // it back in the
            // response
            }
        }
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a volume");
    }
}
Also used : Snapshot(com.cloud.storage.Snapshot) VolumeResponse(org.apache.cloudstack.api.response.VolumeResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Volume(com.cloud.storage.Volume)

Example 14 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class MigrateVolumeCmdByAdmin method execute.

@Override
public void execute() {
    Volume result;
    result = _volumeService.migrateVolume(this);
    if (result != null) {
        VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate volume");
    }
}
Also used : VolumeResponse(org.apache.cloudstack.api.response.VolumeResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Volume(com.cloud.storage.Volume)

Example 15 with ServerApiException

use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.

the class UpdateVolumeCmdByAdmin method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Volume Id: " + getId());
    Volume result = _volumeService.updateVolume(getId(), getPath(), getState(), getStorageId(), getDisplayVolume(), getCustomId(), getEntityOwnerId(), getChainInfo());
    if (result != null) {
        VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update volume");
    }
}
Also used : VolumeResponse(org.apache.cloudstack.api.response.VolumeResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Volume(com.cloud.storage.Volume)

Aggregations

ServerApiException (org.apache.cloudstack.api.ServerApiException)628 SuccessResponse (org.apache.cloudstack.api.response.SuccessResponse)154 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)143 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)104 ArrayList (java.util.ArrayList)74 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)55 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)51 ListResponse (org.apache.cloudstack.api.response.ListResponse)49 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)47 UserVm (com.cloud.uservm.UserVm)47 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)43 UserVmResponse (org.apache.cloudstack.api.response.UserVmResponse)42 Account (com.cloud.user.Account)32 Host (com.cloud.host.Host)30 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)29 Volume (com.cloud.storage.Volume)25 Test (org.junit.Test)23 VolumeResponse (org.apache.cloudstack.api.response.VolumeResponse)20 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)15 UserAccount (com.cloud.user.UserAccount)15