use of org.apache.cloudstack.storage.command.CreateObjectAnswer in project cloudstack by apache.
the class VmwareStorageProcessor method createSnapshot.
@Override
public Answer createSnapshot(CreateObjectCommand cmd) {
// snapshot operation (create or destroy) is handled inside BackupSnapshotCommand(), we just fake
// a success return here
String snapshotUUID = UUID.randomUUID().toString();
SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
newSnapshot.setPath(snapshotUUID);
return new CreateObjectAnswer(newSnapshot);
}
use of org.apache.cloudstack.storage.command.CreateObjectAnswer 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.command.CreateObjectAnswer 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.command.CreateObjectAnswer in project cloudstack by apache.
the class Ovm3StorageProcessor method createVolume.
/**
* Creates a volume, just a normal empty volume.
*/
@Override
public Answer createVolume(CreateObjectCommand cmd) {
LOGGER.debug("execute createVolume: " + cmd.getClass());
DataTO data = cmd.getData();
VolumeObjectTO volume = (VolumeObjectTO) data;
try {
/*
* public Boolean storagePluginCreate(String uuid, String ssuuid,
* String host, String file, Integer size)
*/
String poolUuid = data.getDataStore().getUuid();
String storeUrl = data.getDataStore().getUrl();
URI uri = new URI(storeUrl);
String host = uri.getHost();
String file = getVirtualDiskPath(volume.getUuid(), poolUuid);
Long size = volume.getSize();
StoragePlugin sp = new StoragePlugin(c);
FileProperties fp = sp.storagePluginCreate(poolUuid, host, file, size, false);
if (!fp.getName().equals(file)) {
return new CreateObjectAnswer("Filename mismatch: " + fp.getName() + " != " + file);
}
VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setName(volume.getName());
newVol.setSize(fp.getSize());
newVol.setPath(volume.getUuid());
return new CreateObjectAnswer(newVol);
} catch (Ovm3ResourceException | URISyntaxException e) {
LOGGER.info("Volume creation failed: " + e.toString(), e);
return new CreateObjectAnswer(e.toString());
}
}
use of org.apache.cloudstack.storage.command.CreateObjectAnswer 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