use of org.apache.cloudstack.storage.command.CreateObjectAnswer in project cloudstack by apache.
the class Ovm3StorageProcessor method deleteVolume.
@Override
public Answer deleteVolume(DeleteCommand cmd) {
LOGGER.debug("execute deleteVolume: " + cmd.getClass());
DataTO data = cmd.getData();
VolumeObjectTO volume = (VolumeObjectTO) data;
try {
String poolUuid = data.getDataStore().getUuid();
String uuid = volume.getUuid();
String path = getVirtualDiskPath(uuid, poolUuid);
StoragePlugin sp = new StoragePlugin(c);
sp.storagePluginDestroy(poolUuid, path);
LOGGER.debug("Volume deletion success: " + path);
} catch (Ovm3ResourceException e) {
LOGGER.info("Volume deletion failed: " + e.toString(), e);
return new CreateObjectAnswer(e.toString());
}
return new Answer(cmd);
}
use of org.apache.cloudstack.storage.command.CreateObjectAnswer in project cloudstack by apache.
the class XenServerStorageProcessor method createSnapshot.
@Override
public Answer createSnapshot(final CreateObjectCommand cmd) {
final Connection conn = hypervisorResource.getConnection();
final SnapshotObjectTO snapshotTO = (SnapshotObjectTO) cmd.getData();
final long snapshotId = snapshotTO.getId();
final String snapshotName = snapshotTO.getName();
String details = "create snapshot operation Failed for snapshotId: " + snapshotId;
String snapshotUUID = null;
try {
final String volumeUUID = snapshotTO.getVolume().getPath();
final VDI volume = VDI.getByUuid(conn, volumeUUID);
final VDI snapshot = volume.snapshot(conn, new HashMap<String, String>());
if (snapshotName != null) {
snapshot.setNameLabel(conn, snapshotName);
}
snapshotUUID = snapshot.getUuid(conn);
final String preSnapshotUUID = snapshotTO.getParentSnapshotPath();
//check if it is a empty snapshot
if (preSnapshotUUID != null) {
final SR sr = volume.getSR(conn);
final String srUUID = sr.getUuid(conn);
final String type = sr.getType(conn);
final Boolean isISCSI = IsISCSI(type);
final String snapshotParentUUID = getVhdParent(conn, srUUID, snapshotUUID, isISCSI);
try {
final String preSnapshotParentUUID = getVhdParent(conn, srUUID, preSnapshotUUID, isISCSI);
if (snapshotParentUUID != null && snapshotParentUUID.equals(preSnapshotParentUUID)) {
// this is empty snapshot, remove it
snapshot.destroy(conn);
snapshotUUID = preSnapshotUUID;
}
} catch (final Exception e) {
s_logger.debug("Failed to get parent snapshot", e);
}
}
final SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
newSnapshot.setPath(snapshotUUID);
return new CreateObjectAnswer(newSnapshot);
} catch (final XenAPIException e) {
details += ", reason: " + e.toString();
s_logger.warn(details, e);
} catch (final Exception e) {
details += ", reason: " + e.toString();
s_logger.warn(details, e);
}
return new CreateObjectAnswer(details);
}
use of org.apache.cloudstack.storage.command.CreateObjectAnswer in project cloudstack by apache.
the class SimulatorStorageProcessor method createSnapshot.
@Override
public Answer createSnapshot(CreateObjectCommand cmd) {
String snapshotName = UUID.randomUUID().toString();
SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
newSnapshot.setPath(snapshotName);
return new CreateObjectAnswer(newSnapshot);
}
use of org.apache.cloudstack.storage.command.CreateObjectAnswer in project cloudstack by apache.
the class SimulatorStorageProcessor method createVolume.
@Override
public Answer createVolume(CreateObjectCommand cmd) {
VolumeObjectTO volume = (VolumeObjectTO) cmd.getData();
VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(volume.getName());
return new CreateObjectAnswer(newVol);
}
use of org.apache.cloudstack.storage.command.CreateObjectAnswer in project cloudstack by apache.
the class SolidFirePrimaryDataStoreDriver method takeSnapshot.
@Override
public void takeSnapshot(SnapshotInfo snapshotInfo, AsyncCompletionCallback<CreateCmdResult> callback) {
CreateCmdResult result = null;
try {
VolumeInfo volumeInfo = snapshotInfo.getBaseVolume();
VolumeVO volumeVO = volumeDao.findById(volumeInfo.getId());
long sfVolumeId = Long.parseLong(volumeVO.getFolder());
long storagePoolId = volumeVO.getPoolId();
SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, storagePoolDetailsDao);
SolidFireUtil.SolidFireVolume sfVolume = SolidFireUtil.getVolume(sfConnection, sfVolumeId);
StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
long capacityBytes = storagePool.getCapacityBytes();
// getUsedBytes(StoragePool) will not include the bytes of the proposed new volume or snapshot because
// updateSnapshotDetails has not yet been called for this new volume or snapshot
long usedBytes = getUsedBytes(storagePool);
long sfVolumeSize = sfVolume.getTotalSize();
usedBytes += sfVolumeSize;
// that is serving as the volume the snapshot is of (either a new SolidFire volume or a SolidFire snapshot).
if (usedBytes > capacityBytes) {
throw new CloudRuntimeException("Insufficient amount of space remains in this primary storage to take a snapshot");
}
storagePool.setUsedBytes(usedBytes);
SnapshotObjectTO snapshotObjectTo = (SnapshotObjectTO) snapshotInfo.getTO();
if (shouldTakeSnapshot(snapshotInfo.getId())) {
// We are supposed to take a SolidFire snapshot to serve as the back-end for our CloudStack volume snapshot.
String sfNewSnapshotName = volumeInfo.getName() + "-" + snapshotInfo.getUuid();
long sfNewSnapshotId = SolidFireUtil.createSnapshot(sfConnection, sfVolumeId, sfNewSnapshotName, getSnapshotAttributes(snapshotInfo));
updateSnapshotDetails(snapshotInfo.getId(), sfVolumeId, sfNewSnapshotId, storagePoolId, sfVolumeSize);
snapshotObjectTo.setPath("SfSnapshotId=" + sfNewSnapshotId);
} else {
// We are supposed to create a new SolidFire volume to serve as the back-end for our CloudStack volume snapshot.
String sfNewVolumeName = volumeInfo.getName() + "-" + snapshotInfo.getUuid();
final Iops iops = getIops(MIN_IOPS_FOR_SNAPSHOT_VOLUME, MAX_IOPS_FOR_SNAPSHOT_VOLUME, storagePoolId);
long sfNewVolumeId = SolidFireUtil.createVolume(sfConnection, sfNewVolumeName, sfVolume.getAccountId(), sfVolumeSize, sfVolume.isEnable512e(), getSnapshotAttributes(snapshotInfo), iops.getMinIops(), iops.getMaxIops(), iops.getBurstIops());
SolidFireUtil.SolidFireVolume sfNewVolume = SolidFireUtil.getVolume(sfConnection, sfNewVolumeId);
updateSnapshotDetails(snapshotInfo.getId(), sfNewVolumeId, storagePoolId, sfVolumeSize, sfNewVolume.getIqn());
snapshotObjectTo.setPath("SfVolumeId=" + sfNewVolumeId);
}
// Now that we have successfully created a volume or a snapshot, update the space usage in the cloud.storage_pool table
// (even though cloud.storage_pool.used_bytes is likely no longer in use).
storagePoolDao.update(storagePoolId, storagePool);
CreateObjectAnswer createObjectAnswer = new CreateObjectAnswer(snapshotObjectTo);
result = new CreateCmdResult(null, createObjectAnswer);
result.setResult(null);
} catch (Exception ex) {
LOGGER.debug(SolidFireUtil.LOG_PREFIX + "Failed to take CloudStack snapshot: " + snapshotInfo.getId(), ex);
result = new CreateCmdResult(null, new CreateObjectAnswer(ex.toString()));
result.setResult(ex.toString());
}
callback.complete(result);
}
Aggregations