Search in sources :

Example 11 with VolumeResponse

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

the class ResizeVolumeCmdByAdmin method execute.

@Override
public void execute() throws ResourceAllocationException {
    Volume volume = null;
    try {
        CallContext.current().setEventDetails("Volume Id: " + getEntityId() + " to size " + getSize() + "G");
        volume = _volumeService.resizeVolume(this);
    } catch (InvalidParameterValueException ex) {
        s_logger.info(ex.getMessage());
        throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, ex.getMessage());
    }
    if (volume != null) {
        VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume);
        //FIXME - have to be moved to ApiResponseHelper
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to resize volume");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) VolumeResponse(org.apache.cloudstack.api.response.VolumeResponse) Volume(com.cloud.storage.Volume) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

Example 12 with VolumeResponse

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

the class UpdateVolumeCmd 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.Restricted, 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)

Example 13 with VolumeResponse

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

the class AttachVolumeCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Volume Id: " + getId() + " VmId: " + getVirtualMachineId());
    Volume result = _volumeService.attachVolumeToVM(this);
    if (result != null) {
        VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to attach volume");
    }
}
Also used : VolumeResponse(org.apache.cloudstack.api.response.VolumeResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Volume(com.cloud.storage.Volume)

Example 14 with VolumeResponse

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

the class CreateVolumeCmd 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.Restricted, 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 15 with VolumeResponse

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

the class MigrateVolumeCmd method execute.

@Override
public void execute() {
    Volume result;
    result = _volumeService.migrateVolume(this);
    if (result != null) {
        VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, 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)

Aggregations

VolumeResponse (org.apache.cloudstack.api.response.VolumeResponse)18 ServerApiException (org.apache.cloudstack.api.ServerApiException)15 Volume (com.cloud.storage.Volume)14 ArrayList (java.util.ArrayList)3 VolumeJoinVO (com.cloud.api.query.vo.VolumeJoinVO)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 Snapshot (com.cloud.storage.Snapshot)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)1 ListVolumesCmdByAdmin (org.apache.cloudstack.api.command.admin.volume.ListVolumesCmdByAdmin)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)1 DataStoreDriver (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver)1 VolumeMetricsResponse (org.apache.cloudstack.response.VolumeMetricsResponse)1