use of org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClient in project cloudstack by apache.
the class ScaleIOVMSnapshotStrategy method deleteVMSnapshot.
@Override
public boolean deleteVMSnapshot(VMSnapshot vmSnapshot) {
UserVmVO userVm = userVmDao.findById(vmSnapshot.getVmId());
VMSnapshotVO vmSnapshotVO = (VMSnapshotVO) vmSnapshot;
try {
vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.ExpungeRequested);
} catch (NoTransitionException e) {
LOGGER.debug("Failed to change vm snapshot state with event ExpungeRequested");
throw new CloudRuntimeException("Failed to change vm snapshot state with event ExpungeRequested: " + e.getMessage());
}
try {
List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(vmSnapshot.getVmId());
Long storagePoolId = vmSnapshotHelper.getStoragePoolForVM(userVm.getId());
String systemId = storagePoolDetailsDao.findDetail(storagePoolId, ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID).getValue();
if (systemId == null) {
throw new CloudRuntimeException("Failed to get the system id for PowerFlex storage pool for deleting VM snapshot: " + vmSnapshot.getName());
}
VMSnapshotDetailsVO vmSnapshotDetailsVO = vmSnapshotDetailsDao.findDetail(vmSnapshot.getId(), "SnapshotGroupId");
if (vmSnapshotDetailsVO == null) {
throw new CloudRuntimeException("Failed to get snapshot group id for the VM snapshot: " + vmSnapshot.getName());
}
String snapshotGroupId = vmSnapshotDetailsVO.getValue();
final ScaleIOGatewayClient client = getScaleIOClient(storagePoolId);
int volumesDeleted = client.deleteSnapshotGroup(systemId, snapshotGroupId);
if (volumesDeleted <= 0) {
throw new CloudRuntimeException("Failed to delete VM snapshot: " + vmSnapshot.getName());
} else if (volumesDeleted != volumeTOs.size()) {
LOGGER.warn("Unable to delete all volumes of the VM snapshot: " + vmSnapshot.getName());
}
finalizeDelete(vmSnapshotVO, volumeTOs);
long full_chain_size = 0;
for (VolumeObjectTO volumeTo : volumeTOs) {
publishUsageEvent(EventTypes.EVENT_VM_SNAPSHOT_DELETE, vmSnapshot, userVm, volumeTo);
full_chain_size += volumeTo.getSize();
}
publishUsageEvent(EventTypes.EVENT_VM_SNAPSHOT_OFF_PRIMARY, vmSnapshot, userVm, full_chain_size, 0L);
return true;
} catch (Exception e) {
String errMsg = "Unable to delete vm snapshot: " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " due to " + e.getMessage();
LOGGER.warn(errMsg, e);
throw new CloudRuntimeException(errMsg);
}
}
use of org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClient in project cloudstack by apache.
the class ScaleIOVMSnapshotStrategy method revertVMSnapshot.
@Override
public boolean revertVMSnapshot(VMSnapshot vmSnapshot) {
VMSnapshotVO vmSnapshotVO = (VMSnapshotVO) vmSnapshot;
UserVmVO userVm = userVmDao.findById(vmSnapshot.getVmId());
try {
vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshotVO, VMSnapshot.Event.RevertRequested);
} catch (NoTransitionException e) {
throw new CloudRuntimeException(e.getMessage());
}
boolean result = false;
try {
List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(userVm.getId());
Long storagePoolId = vmSnapshotHelper.getStoragePoolForVM(userVm.getId());
Map<String, String> srcSnapshotDestVolumeMap = new HashMap<>();
for (VolumeObjectTO volume : volumeTOs) {
VMSnapshotDetailsVO vmSnapshotDetail = vmSnapshotDetailsDao.findDetail(vmSnapshotVO.getId(), "Vol_" + volume.getId() + "_Snapshot");
String srcSnapshotVolumeId = ScaleIOUtil.getVolumePath(vmSnapshotDetail.getValue());
String destVolumeId = ScaleIOUtil.getVolumePath(volume.getPath());
srcSnapshotDestVolumeMap.put(srcSnapshotVolumeId, destVolumeId);
}
String systemId = storagePoolDetailsDao.findDetail(storagePoolId, ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID).getValue();
if (systemId == null) {
throw new CloudRuntimeException("Failed to get the system id for PowerFlex storage pool for reverting VM snapshot: " + vmSnapshot.getName());
}
final ScaleIOGatewayClient client = getScaleIOClient(storagePoolId);
result = client.revertSnapshot(systemId, srcSnapshotDestVolumeMap);
if (!result) {
throw new CloudRuntimeException("Failed to revert VM snapshot on PowerFlex storage pool");
}
finalizeRevert(vmSnapshotVO, volumeTOs);
result = true;
} catch (Exception e) {
String errMsg = "Revert VM: " + userVm.getInstanceName() + " to snapshot: " + vmSnapshotVO.getName() + " failed due to " + e.getMessage();
LOGGER.error(errMsg, e);
throw new CloudRuntimeException(errMsg);
} finally {
if (!result) {
try {
vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed);
} catch (NoTransitionException e1) {
LOGGER.error("Cannot set vm snapshot state due to: " + e1.getMessage());
}
}
}
return result;
}
Aggregations