use of org.apache.cloudstack.storage.to.SnapshotObjectTO in project cloudstack by apache.
the class CloudStackPrimaryDataStoreDriverImpl method takeSnapshot.
@Override
public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CreateCmdResult> callback) {
CreateCmdResult result = null;
try {
SnapshotObjectTO snapshotTO = (SnapshotObjectTO) snapshot.getTO();
Object payload = snapshot.getPayload();
if (payload != null && payload instanceof CreateSnapshotPayload) {
CreateSnapshotPayload snapshotPayload = (CreateSnapshotPayload) payload;
snapshotTO.setQuiescevm(snapshotPayload.getQuiescevm());
}
CreateObjectCommand cmd = new CreateObjectCommand(snapshotTO);
EndPoint ep = epSelector.select(snapshot, StorageAction.TAKESNAPSHOT);
Answer answer = null;
if (ep == null) {
String errMsg = "No remote endpoint to send createObjectCommand, check if host or ssvm is down?";
s_logger.error(errMsg);
answer = new Answer(cmd, false, errMsg);
} else {
answer = ep.sendMessage(cmd);
}
result = new CreateCmdResult(null, answer);
if (answer != null && !answer.getResult()) {
result.setResult(answer.getDetails());
}
callback.complete(result);
return;
} catch (Exception e) {
s_logger.debug("Failed to take snapshot: " + snapshot.getId(), e);
result = new CreateCmdResult(null, null);
result.setResult(e.toString());
}
callback.complete(result);
}
use of org.apache.cloudstack.storage.to.SnapshotObjectTO in project cloudstack by apache.
the class CloudStackPrimaryDataStoreDriverImpl method revertSnapshot.
@Override
public void revertSnapshot(SnapshotInfo snapshot, SnapshotInfo snapshotOnPrimaryStore, AsyncCompletionCallback<CommandResult> callback) {
SnapshotObjectTO snapshotTO = (SnapshotObjectTO) snapshot.getTO();
RevertSnapshotCommand cmd = new RevertSnapshotCommand(snapshotTO);
CommandResult result = new CommandResult();
try {
EndPoint ep = epSelector.select(snapshotOnPrimaryStore);
if (ep == null) {
String errMsg = "No remote endpoint to send RevertSnapshotCommand, check if host or ssvm is down?";
s_logger.error(errMsg);
result.setResult(errMsg);
} else {
Answer answer = ep.sendMessage(cmd);
if (answer != null && !answer.getResult()) {
result.setResult(answer.getDetails());
}
}
} catch (Exception ex) {
s_logger.debug("Unable to revert snapshot " + snapshot.getId(), ex);
result.setResult(ex.toString());
}
callback.complete(result);
}
use of org.apache.cloudstack.storage.to.SnapshotObjectTO in project cloudstack by apache.
the class ElastistorPrimaryDataStoreDriver method takeSnapshot.
@Override
public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CreateCmdResult> callback) {
CreateCmdResult result = null;
try {
s_logger.info("taking elastistor volume snapshot");
SnapshotObjectTO snapshotTO = (SnapshotObjectTO) snapshot.getTO();
String volumeid = snapshotTO.getVolume().getUuid();
String snapshotname = snapshotTO.getName();
Answer answer = ElastistorUtil.createElastistorVolumeSnapshot(volumeid, snapshotname);
if (answer.getResult() == false) {
s_logger.info("elastistor volume snapshot failed");
throw new CloudRuntimeException("elastistor volume snapshot failed");
} else {
s_logger.info("elastistor volume snapshot succesfull");
snapshotTO.setPath(answer.getDetails());
CreateObjectAnswer createObjectAnswer = new CreateObjectAnswer(snapshotTO);
result = new CreateCmdResult(null, createObjectAnswer);
result.setResult(null);
}
} catch (Throwable e) {
s_logger.debug("Failed to take snapshot: " + e.getMessage());
result = new CreateCmdResult(null, null);
result.setResult(e.toString());
}
callback.complete(result);
}
use of org.apache.cloudstack.storage.to.SnapshotObjectTO in project cloudstack by apache.
the class SnapshotObject method processEvent.
@Override
public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answer) {
try {
SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findByStoreSnapshot(getDataStore().getRole(), getDataStore().getId(), getId());
if (answer instanceof CreateObjectAnswer) {
SnapshotObjectTO snapshotTO = (SnapshotObjectTO) ((CreateObjectAnswer) answer).getData();
snapshotStore.setInstallPath(snapshotTO.getPath());
snapshotStoreDao.update(snapshotStore.getId(), snapshotStore);
} else if (answer instanceof CopyCmdAnswer) {
SnapshotObjectTO snapshotTO = (SnapshotObjectTO) ((CopyCmdAnswer) answer).getNewData();
snapshotStore.setInstallPath(snapshotTO.getPath());
if (snapshotTO.getPhysicalSize() != null) {
// For S3 delta snapshot, physical size is currently not set
snapshotStore.setPhysicalSize(snapshotTO.getPhysicalSize());
}
if (snapshotTO.getParentSnapshotPath() == null) {
snapshotStore.setParentSnapshotId(0L);
}
snapshotStoreDao.update(snapshotStore.getId(), snapshotStore);
// update side-effect of snapshot operation
if (snapshotTO.getVolume() != null && snapshotTO.getVolume().getPath() != null) {
VolumeVO vol = volumeDao.findByUuid(snapshotTO.getVolume().getUuid());
if (vol != null) {
s_logger.info("Update volume path change due to snapshot operation, volume " + vol.getId() + " path: " + vol.getPath() + "->" + snapshotTO.getVolume().getPath());
vol.setPath(snapshotTO.getVolume().getPath());
volumeDao.update(vol.getId(), vol);
} else {
s_logger.error("Cound't find the original volume with uuid: " + snapshotTO.getVolume().getUuid());
}
}
} else {
throw new CloudRuntimeException("Unknown answer: " + answer.getClass());
}
} catch (RuntimeException ex) {
if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
objectInStoreMgr.deleteIfNotReady(this);
}
throw ex;
}
this.processEvent(event);
}
use of org.apache.cloudstack.storage.to.SnapshotObjectTO in project cloudstack by apache.
the class Ovm3StorageProcessor method deleteSnapshot.
/**
* Is not used in normal operation, the SSVM takes care of this.
*/
@Override
public Answer deleteSnapshot(DeleteCommand cmd) {
LOGGER.debug("execute deleteSnapshot: " + cmd.getClass());
DataTO data = cmd.getData();
SnapshotObjectTO snap = (SnapshotObjectTO) data;
String storeUrl = data.getDataStore().getUrl();
String snapUuid = snap.getPath();
try {
// snapshots/accountid/volumeid
String secPoolUuid = pool.setupSecondaryStorage(storeUrl);
String filePath = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + snapUuid + ".raw";
StoragePlugin sp = new StoragePlugin(c);
sp.storagePluginDestroy(secPoolUuid, filePath);
LOGGER.debug("Snapshot deletion success: " + filePath);
return new Answer(cmd, true, "Deleted Snapshot " + filePath);
} catch (Ovm3ResourceException e) {
LOGGER.info("Snapshot deletion failed: " + e.toString(), e);
return new CreateObjectAnswer(e.toString());
}
}
Aggregations