use of com.cloud.storage.Snapshot 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());
}
}
}
}
use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.
the class ListSnapshotsCmd method execute.
@Override
public void execute() {
final Pair<List<? extends Snapshot>, Integer> result = _snapshotService.listSnapshots(this);
final ListResponse<SnapshotResponse> response = new ListResponse<>();
final List<SnapshotResponse> snapshotResponses = new ArrayList<>();
for (final Snapshot snapshot : result.first()) {
final SnapshotResponse snapshotResponse = _responseGenerator.createSnapshotResponse(snapshot);
snapshotResponse.setObjectName("snapshot");
snapshotResponses.add(snapshotResponse);
}
response.setResponses(snapshotResponses, result.second());
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.
the class RevertSnapshotCmd method execute.
@Override
public void execute() {
CallContext.current().setEventDetails("Snapshot Id: " + getId());
final Snapshot snapshot = _snapshotService.revertSnapshot(getId());
if (snapshot != null) {
final SnapshotResponse response = _responseGenerator.createSnapshotResponse(snapshot);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to revert snapshot");
}
}
use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.
the class SnapshotStateListener method pubishOnEventBus.
private void pubishOnEventBus(final String event, final String status, final Snapshot vo, final State oldState, final State newState) {
final String configKey = Config.PublishResourceStateEvent.key();
final String value = s_configDao.getValue(configKey);
final boolean configValue = Boolean.parseBoolean(value);
if (!configValue) {
return;
}
try {
s_eventBus = ComponentContext.getComponent(EventBus.class);
} catch (final NoSuchBeanDefinitionException nbe) {
// no provider is configured to provide events bus, so just return
return;
}
final String resourceName = getEntityFromClassName(Snapshot.class.getName());
final com.cloud.framework.events.Event eventMsg = new com.cloud.framework.events.Event(ManagementService.Name, EventCategory.RESOURCE_STATE_CHANGE_EVENT.getName(), event, resourceName, vo.getUuid());
final Map<String, String> eventDescription = new HashMap<>();
eventDescription.put("resource", resourceName);
eventDescription.put("id", vo.getUuid());
eventDescription.put("old-state", oldState.name());
eventDescription.put("new-state", newState.name());
final String eventDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
eventDescription.put("eventDateTime", eventDate);
eventMsg.setDescription(eventDescription);
try {
s_eventBus.publish(eventMsg);
} catch (final EventBusException e) {
s_logger.warn("Failed to publish state change event on the the event bus.");
}
}
use of com.cloud.storage.Snapshot in project cloudstack by apache.
the class CreateSnapshotCmd method execute.
@Override
public void execute() {
Snapshot snapshot;
try {
snapshot = _volumeService.takeSnapshot(getVolumeId(), getPolicyId(), getEntityId(), _accountService.getAccount(getEntityOwnerId()), getQuiescevm(), getLocationType(), getAsyncBackup(), getTags());
if (snapshot != null) {
SnapshotResponse response = _responseGenerator.createSnapshotResponse(snapshot);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Snapshot from volume [%s] was not found in database.", getVolumeUuid()));
}
} catch (Exception e) {
String errorMessage = "Failed to create snapshot due to an internal error creating snapshot for volume " + getVolumeUuid();
s_logger.error(errorMessage, e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMessage);
}
}
Aggregations