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);
}
}
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;
}
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);
}
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);
}
}
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());
}
}
}
}
Aggregations