use of com.cloud.storage.command.CommandResult in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method deleteVolumeCallback.
public Void deleteVolumeCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CommandResult> callback, final DeleteVolumeContext<VolumeApiResult> context) {
final CommandResult result = callback.getResult();
final VolumeObject vo = context.getVolume();
final VolumeApiResult apiResult = new VolumeApiResult(vo);
try {
if (result.isSuccess()) {
vo.processEvent(Event.OperationSuccessed);
if (canVolumeBeRemoved(vo.getId())) {
s_logger.info("Volume " + vo.getId() + " is not referred anywhere, remove it from volumes table");
volDao.remove(vo.getId());
}
} else {
vo.processEvent(Event.OperationFailed);
apiResult.setResult(result.getResult());
}
} catch (final Exception e) {
s_logger.debug("ignore delete volume status update failure, it will be picked up by storage clean up thread later", e);
}
context.getFuture().complete(apiResult);
return null;
}
use of com.cloud.storage.command.CommandResult in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method expungeVolumeAsync.
@DB
@Override
public AsyncCallFuture<VolumeApiResult> expungeVolumeAsync(final VolumeInfo volume) {
final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
final VolumeApiResult result = new VolumeApiResult(volume);
if (volume.getDataStore() == null) {
s_logger.info("Expunge volume with no data store specified");
if (canVolumeBeRemoved(volume.getId())) {
s_logger.info("Volume " + volume.getId() + " is not referred anywhere, remove it from volumes table");
volDao.remove(volume.getId());
}
future.complete(result);
return future;
}
// Find out if the volume is at state of download_in_progress on secondary storage
final VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(volume.getId());
if (volumeStore != null) {
if (volumeStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS) {
s_logger.debug("Volume: " + volume.getName() + " is currently being uploaded; cant' delete it.");
future.complete(result);
return future;
}
}
final VolumeVO vol = volDao.findById(volume.getId());
if (vol == null) {
s_logger.debug("Volume " + volume.getId() + " is not found");
future.complete(result);
return future;
}
final String volumePath = vol.getPath();
final Long poolId = vol.getPoolId();
if (poolId == null || volumePath == null || volumePath.trim().isEmpty()) {
// not created on primary store
if (volumeStore == null) {
// also not created on secondary store
if (s_logger.isDebugEnabled()) {
s_logger.debug("Marking volume that was never created as destroyed: " + vol);
}
volDao.remove(vol.getId());
future.complete(result);
return future;
}
}
final VolumeObject vo = (VolumeObject) volume;
if (volume.getDataStore().getRole() == DataStoreRole.Image) {
// no need to change state in volumes table
volume.processEventOnly(Event.DestroyRequested);
} else if (volume.getDataStore().getRole() == DataStoreRole.Primary) {
volume.processEvent(Event.ExpungeRequested);
}
final DeleteVolumeContext<VolumeApiResult> context = new DeleteVolumeContext<>(null, vo, future);
final AsyncCallbackDispatcher<VolumeServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().deleteVolumeCallback(null, null)).setContext(context);
volume.getDataStore().getDriver().deleteAsync(volume.getDataStore(), volume, caller);
return future;
}
use of com.cloud.storage.command.CommandResult in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method migrateVolumes.
@Override
public AsyncCallFuture<CommandResult> migrateVolumes(final Map<VolumeInfo, DataStore> volumeMap, final VirtualMachineTO vmTo, final Host srcHost, final Host destHost) {
final AsyncCallFuture<CommandResult> future = new AsyncCallFuture<>();
final CommandResult res = new CommandResult();
try {
// Check to make sure there are no snapshot operations on a volume
// and
// put it in the migrating state.
final List<VolumeInfo> volumesMigrating = new ArrayList<>();
for (final Map.Entry<VolumeInfo, DataStore> entry : volumeMap.entrySet()) {
final VolumeInfo volume = entry.getKey();
if (!snapshotMgr.canOperateOnVolume(volume)) {
s_logger.debug("Snapshots are being created on a volume. Volumes cannot be migrated now.");
res.setResult("Snapshots are being created on a volume. Volumes cannot be migrated now.");
future.complete(res);
// to be put back in ready state.
for (final VolumeInfo volumeMigrating : volumesMigrating) {
volumeMigrating.processEvent(Event.OperationFailed);
}
return future;
} else {
volume.processEvent(Event.MigrationRequested);
volumesMigrating.add(volume);
}
}
final MigrateVmWithVolumesContext<CommandResult> context = new MigrateVmWithVolumesContext<>(null, future, volumeMap);
final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().migrateVmWithVolumesCallBack(null, null)).setContext(context);
motionSrv.copyAsync(volumeMap, vmTo, srcHost, destHost, caller);
} catch (final Exception e) {
s_logger.debug("Failed to copy volume", e);
res.setResult(e.toString());
future.complete(res);
}
return future;
}
use of com.cloud.storage.command.CommandResult in project cosmic by MissionCriticalCloud.
the class CloudStackPrimaryDataStoreDriverImpl method deleteAsync.
@Override
public void deleteAsync(final DataStore dataStore, final DataObject data, final AsyncCompletionCallback<CommandResult> callback) {
final DeleteCommand cmd = new DeleteCommand(data.getTO());
final CommandResult result = new CommandResult();
try {
EndPoint ep = null;
if (data.getType() == DataObjectType.VOLUME) {
ep = epSelector.select(data, StorageAction.DELETEVOLUME);
} else {
ep = epSelector.select(data);
}
if (ep == null) {
final String errMsg = "No remote endpoint to send DeleteCommand, check if host or ssvm is down?";
s_logger.error(errMsg);
result.setResult(errMsg);
} else {
final Answer answer = ep.sendMessage(cmd);
if (answer != null && !answer.getResult()) {
result.setResult(answer.getDetails());
}
}
} catch (final Exception ex) {
s_logger.debug("Unable to destoy volume" + data.getId(), ex);
result.setResult(ex.toString());
}
callback.complete(result);
}
use of com.cloud.storage.command.CommandResult in project cosmic by MissionCriticalCloud.
the class CloudStackPrimaryDataStoreDriverImpl method revertSnapshot.
@Override
public void revertSnapshot(final SnapshotInfo snapshot, final SnapshotInfo snapshotOnPrimaryStore, final AsyncCompletionCallback<CommandResult> callback) {
final SnapshotObjectTO snapshotTO = (SnapshotObjectTO) snapshot.getTO();
final RevertSnapshotCommand cmd = new RevertSnapshotCommand(snapshotTO);
final CommandResult result = new CommandResult();
try {
final EndPoint ep = epSelector.select(snapshotOnPrimaryStore);
if (ep == null) {
final String errMsg = "No remote endpoint to send RevertSnapshotCommand, check if host or ssvm is down?";
s_logger.error(errMsg);
result.setResult(errMsg);
} else {
final Answer answer = ep.sendMessage(cmd);
if (answer != null && !answer.getResult()) {
result.setResult(answer.getDetails());
}
}
} catch (final Exception ex) {
s_logger.debug("Unable to revert snapshot " + snapshot.getId(), ex);
result.setResult(ex.toString());
}
callback.complete(result);
}
Aggregations