Search in sources :

Example 1 with SnapshotResponse

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

the class CreateSnapshotCmd method execute.

@Override
public void execute() {
    UserContext.current().setEventDetails("Volume Id: " + getVolumeId());
    Snapshot snapshot = _snapshotService.createSnapshot(getVolumeId(), getPolicyId(), getEntityId(), _accountService.getAccount(getEntityOwnerId()));
    if (snapshot != null) {
        SnapshotResponse response = _responseGenerator.createSnapshotResponse(snapshot);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + volumeId);
    }
}
Also used : Snapshot(com.cloud.storage.Snapshot) ServerApiException(com.cloud.api.ServerApiException) SnapshotResponse(com.cloud.api.response.SnapshotResponse)

Example 2 with SnapshotResponse

use of com.cloud.api.response.SnapshotResponse in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createSnapshotResponse.

@Override
public SnapshotResponse createSnapshotResponse(final Snapshot snapshot) {
    final SnapshotResponse snapshotResponse = new SnapshotResponse();
    snapshotResponse.setId(snapshot.getUuid());
    populateOwner(snapshotResponse, snapshot);
    final VolumeVO volume = findVolumeById(snapshot.getVolumeId());
    final String snapshotTypeStr = snapshot.getRecurringType().name();
    snapshotResponse.setSnapshotType(snapshotTypeStr);
    if (volume != null) {
        snapshotResponse.setVolumeId(volume.getUuid());
        snapshotResponse.setVolumeName(volume.getName());
        snapshotResponse.setVolumeType(volume.getVolumeType().name());
        final DataCenter zone = ApiDBUtils.findZoneById(volume.getDataCenterId());
        if (zone != null) {
            snapshotResponse.setZoneId(zone.getUuid());
        }
    }
    snapshotResponse.setCreated(snapshot.getCreated());
    snapshotResponse.setName(snapshot.getName());
    snapshotResponse.setIntervalType(ApiDBUtils.getSnapshotIntervalTypes(snapshot.getId()));
    snapshotResponse.setState(snapshot.getState());
    final SnapshotInfo snapshotInfo;
    if (snapshot instanceof SnapshotInfo) {
        snapshotInfo = (SnapshotInfo) snapshot;
    } else {
        final DataStoreRole dataStoreRole = getDataStoreRole(snapshot, _snapshotStoreDao, _dataStoreMgr);
        snapshotInfo = snapshotfactory.getSnapshot(snapshot.getId(), dataStoreRole);
    }
    if (snapshotInfo == null) {
        s_logger.debug("Unable to find info for image store snapshot with uuid " + snapshot.getUuid());
        snapshotResponse.setRevertable(false);
    } else {
        snapshotResponse.setRevertable(snapshotInfo.isRevertable());
        snapshotResponse.setPhysicaSize(snapshotInfo.getPhysicalSize());
    }
    // set tag information
    final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.Snapshot, snapshot.getId());
    final List<ResourceTagResponse> tagResponses = new ArrayList<>();
    for (final ResourceTag tag : tags) {
        final ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    snapshotResponse.setTags(tagResponses);
    snapshotResponse.setObjectName("snapshot");
    return snapshotResponse;
}
Also used : DataStoreRole(com.cloud.storage.DataStoreRole) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) DataCenter(com.cloud.dc.DataCenter) ResourceTag(com.cloud.server.ResourceTag) VolumeVO(com.cloud.storage.VolumeVO) VMSnapshotResponse(com.cloud.api.response.VMSnapshotResponse) SnapshotResponse(com.cloud.api.response.SnapshotResponse) ResourceTagResponse(com.cloud.api.response.ResourceTagResponse) ArrayList(java.util.ArrayList)

Example 3 with SnapshotResponse

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

the class ListSnapshotsCmd method execute.

@Override
public void execute() {
    List<? extends Snapshot> result = _snapshotService.listSnapshots(this);
    ListResponse<SnapshotResponse> response = new ListResponse<SnapshotResponse>();
    List<SnapshotResponse> snapshotResponses = new ArrayList<SnapshotResponse>();
    for (Snapshot snapshot : result) {
        SnapshotResponse snapshotResponse = _responseGenerator.createSnapshotResponse(snapshot);
        snapshotResponse.setObjectName("snapshot");
        snapshotResponses.add(snapshotResponse);
    }
    response.setResponses(snapshotResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : Snapshot(com.cloud.storage.Snapshot) ListResponse(com.cloud.api.response.ListResponse) SnapshotResponse(com.cloud.api.response.SnapshotResponse) ArrayList(java.util.ArrayList)

Example 4 with SnapshotResponse

use of com.cloud.api.response.SnapshotResponse in project cosmic by MissionCriticalCloud.

the class CreateSnapshotCmd method execute.

@Override
public void execute() {
    s_logger.info("VOLSS: createSnapshotCmd starts:" + System.currentTimeMillis());
    CallContext.current().setEventDetails("Volume Id: " + getVolumeUuid());
    final Snapshot snapshot;
    try {
        snapshot = _volumeService.takeSnapshot(getVolumeId(), getPolicyId(), getEntityId(), _accountService.getAccount(getEntityOwnerId()), getQuiescevm());
        if (snapshot != null) {
            final SnapshotResponse response = _responseGenerator.createSnapshotResponse(snapshot);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + volumeId);
        }
    } catch (final Exception e) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + volumeId);
    }
}
Also used : Snapshot(com.cloud.storage.Snapshot) ServerApiException(com.cloud.api.ServerApiException) SnapshotResponse(com.cloud.api.response.SnapshotResponse) ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Example 5 with SnapshotResponse

use of com.cloud.api.response.SnapshotResponse in project cosmic by MissionCriticalCloud.

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 (final InvalidParameterValueException ex) {
        throw ex;
    } catch (final 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 (final 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(com.cloud.api.ServerApiException) VMSnapshotResponse(com.cloud.api.response.VMSnapshotResponse) SnapshotResponse(com.cloud.api.response.SnapshotResponse) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Aggregations

SnapshotResponse (com.cloud.api.response.SnapshotResponse)7 Snapshot (com.cloud.storage.Snapshot)6 ServerApiException (com.cloud.api.ServerApiException)4 ArrayList (java.util.ArrayList)3 ListResponse (com.cloud.api.response.ListResponse)2 VMSnapshotResponse (com.cloud.api.response.VMSnapshotResponse)2 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)2 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)2 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)2 ResourceTagResponse (com.cloud.api.response.ResourceTagResponse)1 DataCenter (com.cloud.dc.DataCenter)1 SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)1 ResourceTag (com.cloud.server.ResourceTag)1 DataStoreRole (com.cloud.storage.DataStoreRole)1 VolumeVO (com.cloud.storage.VolumeVO)1 VMSnapshot (com.cloud.vm.snapshot.VMSnapshot)1 List (java.util.List)1