Search in sources :

Example 6 with SnapshotResponse

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

the class CreateSnapshotFromVMSnapshotCmd method execute.

@Override
public void execute() {
    s_logger.info("CreateSnapshotFromVMSnapshotCmd with vm snapshot id:" + getVMSnapshotId() + " and snapshot id:" + getEntityId() + " starts:" + System.currentTimeMillis());
    CallContext.current().setEventDetails("Vm Snapshot Id: " + getVMSnapshotId());
    Snapshot snapshot = null;
    try {
        snapshot = _snapshotService.backupSnapshotFromVmSnapshot(getEntityId(), getVmId(), getVolumeId(), getVMSnapshotId());
        if (snapshot != null) {
            SnapshotResponse response = _responseGenerator.createSnapshotResponse(snapshot);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot from vm snapshot " + getVMSnapshotId());
        }
    } catch (InvalidParameterValueException ex) {
        throw ex;
    } catch (Exception e) {
        s_logger.debug("Failed to create snapshot", e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot from vm snapshot " + getVMSnapshotId());
    } finally {
        if (snapshot == null) {
            try {
                _snapshotService.deleteSnapshot(getEntityId());
            } catch (Exception e) {
                s_logger.debug("Failed to clean failed snapshot" + getEntityId());
            }
        }
    }
}
Also used : VMSnapshot(com.cloud.vm.snapshot.VMSnapshot) Snapshot(com.cloud.storage.Snapshot) ServerApiException(org.apache.cloudstack.api.ServerApiException) SnapshotResponse(org.apache.cloudstack.api.response.SnapshotResponse) VMSnapshotResponse(org.apache.cloudstack.api.response.VMSnapshotResponse) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Aggregations

SnapshotResponse (org.apache.cloudstack.api.response.SnapshotResponse)6 Snapshot (com.cloud.storage.Snapshot)5 ServerApiException (org.apache.cloudstack.api.ServerApiException)4 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)2 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)2 ArrayList (java.util.ArrayList)2 VMSnapshotResponse (org.apache.cloudstack.api.response.VMSnapshotResponse)2 DataCenter (com.cloud.dc.DataCenter)1 ResourceTag (com.cloud.server.ResourceTag)1 DataStoreRole (com.cloud.storage.DataStoreRole)1 GuestOS (com.cloud.storage.GuestOS)1 VolumeApiService (com.cloud.storage.VolumeApiService)1 VolumeVO (com.cloud.storage.VolumeVO)1 Account (com.cloud.user.Account)1 AccountService (com.cloud.user.AccountService)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)1 VMSnapshot (com.cloud.vm.snapshot.VMSnapshot)1 List (java.util.List)1