use of org.ovirt.engine.core.common.action.RemoveSnapshotSingleDiskParameters in project ovirt-engine by oVirt.
the class RemoveDiskSnapshotsCommand method buildRemoveSnapshotSingleDiskLiveParameters.
private RemoveSnapshotSingleDiskParameters buildRemoveSnapshotSingleDiskLiveParameters(Guid imageId, int completedChildren) {
DiskImage dest = diskImageDao.getAllSnapshotsForParent(imageId).get(0);
RemoveSnapshotSingleDiskParameters parameters = new RemoveSnapshotSingleDiskParameters(imageId, getVmId());
parameters.setDestinationImageId(dest.getImageId());
parameters.setEntityInfo(getParameters().getEntityInfo());
parameters.setParentParameters(getParameters());
parameters.setParentCommand(getActionType());
parameters.setCommandType(ActionType.RemoveSnapshotSingleDiskLive);
parameters.setVdsId(getVm().getRunOnVds());
parameters.setSessionId(getParameters().getSessionId());
parameters.setEndProcedure(EndProcedure.COMMAND_MANAGED);
return parameters;
}
use of org.ovirt.engine.core.common.action.RemoveSnapshotSingleDiskParameters in project ovirt-engine by oVirt.
the class RemoveDiskSnapshotsCommand method buildRemoveSnapshotSingleDiskParameters.
private ImagesContainterParametersBase buildRemoveSnapshotSingleDiskParameters(Guid imageId) {
RemoveSnapshotSingleDiskParameters parameters = new RemoveSnapshotSingleDiskParameters(imageId, getVmId());
DiskImage dest = diskImageDao.getAllSnapshotsForParent(imageId).get(0);
parameters.setDestinationImageId(dest.getImageId());
parameters.setEntityInfo(getParameters().getEntityInfo());
parameters.setParentParameters(getParameters());
parameters.setParentCommand(getActionType());
parameters.setWipeAfterDelete(dest.isWipeAfterDelete());
parameters.setSessionId(getParameters().getSessionId());
parameters.setVmSnapshotId(diskImageDao.getSnapshotById(imageId).getVmSnapshotId());
parameters.setEndProcedure(EndProcedure.COMMAND_MANAGED);
return parameters;
}
use of org.ovirt.engine.core.common.action.RemoveSnapshotSingleDiskParameters in project ovirt-engine by oVirt.
the class RemoveSnapshotCommand method removeImages.
private void removeImages() {
List<CinderDisk> cinderDisks = new ArrayList<>();
for (final DiskImage source : getSourceImages()) {
if (source.getDiskStorageType() == DiskStorageType.CINDER) {
cinderDisks.add((CinderDisk) source);
continue;
}
// The following is ok because we have tested in the validate that the vm
// is not a template and the vm is not in preview mode and that
// this is not the active snapshot.
List<DiskImage> images = diskImageDao.getAllSnapshotsForParent(source.getImageId());
DiskImage dest = null;
if (!images.isEmpty()) {
dest = images.get(0);
}
if (getSnapshotActionType() == ActionType.RemoveSnapshotSingleDiskLive) {
commandCoordinatorUtil.executeAsyncCommand(getSnapshotActionType(), buildRemoveSnapshotSingleDiskParameters(source, dest, getSnapshotActionType()), cloneContextAndDetachFromParent());
} else {
RemoveSnapshotSingleDiskParameters parameters = buildRemoveSnapshotSingleDiskParameters(source, dest, getSnapshotActionType());
ActionReturnValue actionReturnValueturnValue = runInternalActionWithTasksContext(getSnapshotActionType(), parameters);
getTaskIdList().addAll(actionReturnValueturnValue.getInternalVdsmTaskIdList());
}
List<Guid> quotasToRemoveFromCache = new ArrayList<>();
quotasToRemoveFromCache.add(source.getQuotaId());
if (dest != null) {
quotasToRemoveFromCache.add(dest.getQuotaId());
}
getQuotaManager().removeQuotaFromCache(getStoragePoolId(), quotasToRemoveFromCache);
}
if (!cinderDisks.isEmpty()) {
handleCinderSnapshotDisks(cinderDisks);
}
}
use of org.ovirt.engine.core.common.action.RemoveSnapshotSingleDiskParameters in project ovirt-engine by oVirt.
the class RemoveSnapshotCommand method buildRemoveSnapshotSingleDiskParameters.
private RemoveSnapshotSingleDiskParameters buildRemoveSnapshotSingleDiskParameters(final DiskImage source, DiskImage dest, ActionType snapshotActionType) {
RemoveSnapshotSingleDiskParameters parameters = new RemoveSnapshotSingleDiskParameters(source.getImageId(), getVmId());
parameters.setStorageDomainId(source.getStorageIds().get(0));
parameters.setDestinationImageId(dest != null ? dest.getImageId() : null);
parameters.setEntityInfo(getParameters().getEntityInfo());
parameters.setParentParameters(getParameters());
parameters.setParentCommand(getActionType());
parameters.setCommandType(snapshotActionType);
parameters.setVdsId(getVm().getRunOnVds());
parameters.setEndProcedure(EndProcedure.COMMAND_MANAGED);
return parameters;
}
use of org.ovirt.engine.core.common.action.RemoveSnapshotSingleDiskParameters in project ovirt-engine by oVirt.
the class DestroyImageCommand method executeCommand.
@Override
protected void executeCommand() {
getParameters().setEntityInfo(new EntityInfo(VdcObjectType.Disk, getParameters().getImageGroupId()));
VDSReturnValue vdsReturnValue = null;
try {
vdsReturnValue = runVdsCommand(VDSCommandType.DestroyImage, createVDSParameters());
} catch (EngineException e) {
log.error("Failed to delete image {}/{}", getParameters().getImageGroupId(), getParameters().getImageList().stream().findFirst().get(), e);
if (!getParameters().isLiveMerge()) {
throw e;
}
}
if (vdsReturnValue != null && vdsReturnValue.getCreationInfo() != null) {
Guid taskId = persistAsyncTaskPlaceHolder(getParameters().getParentCommand());
Guid result = createTask(taskId, vdsReturnValue.getCreationInfo(), getParameters().getParentCommand(), VdcObjectType.Storage, getParameters().getStorageDomainId());
getTaskIdList().add(result);
log.info("Successfully started task to remove orphaned volumes resulting from live merge");
} else {
log.info("Retrying deleting image {}/{}", getParameters().getImageGroupId(), getParameters().getImageList().stream().findFirst().get());
MergeStatusReturnValue returnValue = new MergeStatusReturnValue(VmBlockJobType.COMMIT, new HashSet<>(getParameters().getImageList()));
getReturnValue().setActionReturnValue(returnValue);
// At this point, we know that this command was executed during live merge and it is safe to do
// the casting in the next line.
((RemoveSnapshotSingleDiskParameters) getParameters().getParentParameters()).setNextCommandStep(RemoveSnapshotSingleDiskStep.DESTROY_IMAGE);
}
setSucceeded(true);
setCommandStatus(CommandStatus.SUCCEEDED);
}
Aggregations