use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.
the class VolumeOrchestrator method migrateVolumes.
@Override
public void migrateVolumes(VirtualMachine vm, VirtualMachineTO vmTo, Host srcHost, Host destHost, Map<Volume, StoragePool> volumeToPool) {
// Check if all the vms being migrated belong to the vm.
// Check if the storage pool is of the right type.
// Create a VolumeInfo to DataStore map too.
Map<VolumeInfo, DataStore> volumeMap = new HashMap<VolumeInfo, DataStore>();
for (Map.Entry<Volume, StoragePool> entry : volumeToPool.entrySet()) {
Volume volume = entry.getKey();
StoragePool storagePool = entry.getValue();
StoragePool destPool = (StoragePool) dataStoreMgr.getDataStore(storagePool.getId(), DataStoreRole.Primary);
if (volume.getInstanceId() != vm.getId()) {
throw new CloudRuntimeException("Volume " + volume + " that has to be migrated doesn't belong to the" + " instance " + vm);
}
if (destPool == null) {
throw new CloudRuntimeException("Failed to find the destination storage pool " + storagePool.getId());
}
volumeMap.put(volFactory.getVolume(volume.getId()), (DataStore) destPool);
}
AsyncCallFuture<CommandResult> future = volService.migrateVolumes(volumeMap, vmTo, srcHost, destHost);
try {
CommandResult result = future.get();
if (result.isFailed()) {
s_logger.debug("Failed to migrated vm " + vm + " along with its volumes. " + result.getResult());
throw new CloudRuntimeException("Failed to migrated vm " + vm + " along with its volumes. ");
}
} catch (InterruptedException e) {
s_logger.debug("Failed to migrated vm " + vm + " along with its volumes.", e);
} catch (ExecutionException e) {
s_logger.debug("Failed to migrated vm " + vm + " along with its volumes.", e);
}
}
use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.
the class BaseImageStoreDriverImpl method deleteAsync.
@Override
public void deleteAsync(DataStore dataStore, DataObject data, AsyncCompletionCallback<CommandResult> callback) {
CommandResult result = new CommandResult();
try {
DeleteCommand cmd = new DeleteCommand(data.getTO());
EndPoint ep = _epSelector.select(data);
Answer answer = null;
if (ep == null) {
String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
LOGGER.error(errMsg);
answer = new Answer(cmd, false, errMsg);
} else {
answer = ep.sendMessage(cmd);
}
if (answer != null && !answer.getResult()) {
result.setResult(answer.getDetails());
}
} catch (Exception ex) {
LOGGER.debug("Unable to destoy " + data.getType().toString() + ": " + data.getId(), ex);
result.setResult(ex.toString());
}
callback.complete(result);
}
use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.
the class ScaleIOPrimaryDataStoreDriver method revertSnapshot.
@Override
public void revertSnapshot(SnapshotInfo snapshot, SnapshotInfo snapshotOnPrimaryStore, AsyncCompletionCallback<CommandResult> callback) {
LOGGER.debug("Reverting to PowerFlex volume snapshot");
Preconditions.checkArgument(snapshot != null, "snapshotInfo cannot be null");
VolumeInfo volumeInfo = snapshot.getBaseVolume();
Preconditions.checkArgument(volumeInfo != null, "volumeInfo cannot be null");
VolumeVO volumeVO = volumeDao.findById(volumeInfo.getId());
try {
if (volumeVO == null || volumeVO.getRemoved() != null) {
String errMsg = "The volume that the snapshot belongs to no longer exists.";
CommandResult commandResult = new CommandResult();
commandResult.setResult(errMsg);
callback.complete(commandResult);
return;
}
long storagePoolId = volumeVO.getPoolId();
final ScaleIOGatewayClient client = getScaleIOClient(storagePoolId);
String snapshotVolumeId = ScaleIOUtil.getVolumePath(snapshot.getPath());
final String destVolumeId = ScaleIOUtil.getVolumePath(volumeVO.getPath());
client.revertSnapshot(snapshotVolumeId, destVolumeId);
CommandResult commandResult = new CommandResult();
callback.complete(commandResult);
} catch (Exception ex) {
LOGGER.debug("Unable to revert to PowerFlex snapshot: " + snapshot.getId(), ex);
throw new CloudRuntimeException(ex.getMessage());
}
}
use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.
the class SolidFirePrimaryDataStoreDriver method deleteAsync.
@Override
public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CommandResult> callback) {
String errMsg = null;
try {
if (dataObject.getType() == DataObjectType.VOLUME) {
deleteVolume((VolumeInfo) dataObject, dataStore.getId());
} else if (dataObject.getType() == DataObjectType.SNAPSHOT) {
deleteSnapshot((SnapshotInfo) dataObject, dataStore.getId());
} else if (dataObject.getType() == DataObjectType.TEMPLATE) {
deleteTemplate((TemplateInfo) dataObject, dataStore.getId());
} else {
errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to deleteAsync";
}
} catch (Exception ex) {
errMsg = ex.getMessage();
LOGGER.error(errMsg);
}
if (callback != null) {
CommandResult result = new CommandResult();
result.setResult(errMsg);
callback.complete(result);
}
}
use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.
the class ScaleIOPrimaryDataStoreDriver method deleteAsync.
@Override
public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CommandResult> callback) {
Preconditions.checkArgument(dataObject != null, "dataObject cannot be null");
long storagePoolId = dataStore.getId();
StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
Preconditions.checkArgument(storagePoolId > 0, "storagePoolId should be > 0");
Preconditions.checkArgument(storagePool != null && storagePool.getHostAddress() != null, "storagePool and host address should not be null");
String errMsg = null;
String scaleIOVolumePath = null;
try {
boolean deleteResult = false;
if (dataObject.getType() == DataObjectType.VOLUME) {
LOGGER.debug("deleteAsync - deleting volume");
scaleIOVolumePath = ((VolumeInfo) dataObject).getPath();
} else if (dataObject.getType() == DataObjectType.SNAPSHOT) {
LOGGER.debug("deleteAsync - deleting snapshot");
scaleIOVolumePath = ((SnapshotInfo) dataObject).getPath();
} else if (dataObject.getType() == DataObjectType.TEMPLATE) {
LOGGER.debug("deleteAsync - deleting template");
scaleIOVolumePath = ((TemplateInfo) dataObject).getInstallPath();
} else {
errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to deleteAsync";
LOGGER.error(errMsg);
throw new CloudRuntimeException(errMsg);
}
try {
String scaleIOVolumeId = ScaleIOUtil.getVolumePath(scaleIOVolumePath);
final ScaleIOGatewayClient client = getScaleIOClient(storagePoolId);
deleteResult = client.deleteVolume(scaleIOVolumeId);
if (!deleteResult) {
errMsg = "Failed to delete PowerFlex volume with id: " + scaleIOVolumeId;
}
long usedBytes = storagePool.getUsedBytes();
usedBytes -= dataObject.getSize();
storagePool.setUsedBytes(usedBytes < 0 ? 0 : usedBytes);
storagePoolDao.update(storagePoolId, storagePool);
} catch (Exception e) {
errMsg = "Unable to delete PowerFlex volume: " + scaleIOVolumePath + " due to " + e.getMessage();
LOGGER.warn(errMsg);
throw new CloudRuntimeException(errMsg, e);
}
} catch (Exception ex) {
errMsg = ex.getMessage();
LOGGER.error(errMsg);
if (callback == null) {
throw ex;
}
}
if (callback != null) {
CommandResult result = new CommandResult();
result.setResult(errMsg);
callback.complete(result);
}
}
Aggregations