use of org.ovirt.engine.core.common.action.ImagesContainterParametersBase in project ovirt-engine by oVirt.
the class RestoreAllSnapshotsCommand method executeVmCommand.
@Override
protected void executeVmCommand() {
if (!getImagesList().isEmpty()) {
lockVmWithCompensationIfNeeded();
if (!isInternalExecution()) {
freeLock();
}
}
initializeSnapshotsLeasesDomainIds();
restoreSnapshotAndRemoveObsoleteSnapshots(getSnapshot());
boolean succeeded = removeLeaseIfNeeded();
List<CinderDisk> cinderDisksToRestore = new ArrayList<>();
for (DiskImage image : imagesToRestore) {
if (image.getImageStatus() != ImageStatus.ILLEGAL) {
if (image.getDiskStorageType() == DiskStorageType.CINDER) {
cinderDisksToRestore.add((CinderDisk) image);
continue;
}
ImagesContainterParametersBase params = new RestoreFromSnapshotParameters(image.getImageId(), getVmId(), getSnapshot(), removedSnapshot.getId());
ActionReturnValue returnValue = runAsyncTask(ActionType.RestoreFromSnapshot, params);
// Save the first fault
if (succeeded && !returnValue.getSucceeded()) {
succeeded = false;
getReturnValue().setFault(returnValue.getFault());
}
}
}
List<CinderDisk> cinderVolumesToRemove = new ArrayList<>();
List<CinderDisk> cinderDisksToRemove = new ArrayList<>();
removeUnusedImages(cinderVolumesToRemove);
if (getSnapshot().getType() == SnapshotType.REGULAR) {
snapshotsToRemove.addAll(findSnapshotsWithOnlyIllegalDisks());
setNewerVmConfigurationsAsBroken();
}
removeSnapshotsFromDB();
succeeded = updateLeaseInfoIfNeeded() && succeeded;
if (!getTaskIdList().isEmpty() || !cinderDisksToRestore.isEmpty() || !cinderVolumesToRemove.isEmpty()) {
deleteOrphanedImages(cinderDisksToRemove);
if (!restoreCinderDisks(removedSnapshot.getId(), cinderDisksToRestore, cinderDisksToRemove, cinderVolumesToRemove)) {
log.error("Error to restore Cinder volumes snapshots");
}
} else {
vmStaticDao.incrementDbGeneration(getVm().getId());
snapshotDao.updateStatus(getSnapshot().getId(), SnapshotStatus.OK);
unlockVm();
}
setSucceeded(succeeded);
}
use of org.ovirt.engine.core.common.action.ImagesContainterParametersBase in project ovirt-engine by oVirt.
the class RemoveCinderSnapshotCommandCallback method childCommandsExecutionEnded.
@Override
protected void childCommandsExecutionEnded(CommandBase<?> command, boolean anyFailed, List<Guid> childCmdIds, CommandExecutionStatus status, int completedChildren) {
RemoveCinderSnapshotDiskCommand<ImagesContainterParametersBase> removeCinderSnapshotDiskCommand = (RemoveCinderSnapshotDiskCommand<ImagesContainterParametersBase>) command;
ImagesContainterParametersBase parameters = removeCinderSnapshotDiskCommand.getParameters();
Guid diskId = parameters.getDestinationImageId();
if (!removeCinderSnapshotDiskCommand.getCinderBroker().isSnapshotExist(diskId)) {
// Cinder snapshot has been deleted successfully
setCommandEndStatus(command, false, status, childCmdIds);
return;
}
ImageStatus imageStatus = removeCinderSnapshotDiskCommand.getCinderBroker().getSnapshotStatus(diskId);
DiskImage disk = diskImageDao.getSnapshotById(diskId);
if (imageStatus != null && imageStatus != disk.getImageStatus()) {
switch(imageStatus) {
case ILLEGAL:
setCommandEndStatus(command, true, status, childCmdIds);
break;
}
}
}
use of org.ovirt.engine.core.common.action.ImagesContainterParametersBase in project ovirt-engine by oVirt.
the class RestoreAllCinderSnapshotsCommand method executeVmCommand.
@Override
protected void executeVmCommand() {
for (CinderDisk cinderDisk : getParameters().getCinderDisksToRestore()) {
ImagesContainterParametersBase params = getRestoreFromSnapshotParams(cinderDisk);
restoreCinderDisk(cinderDisk, params);
// In case we want to undo the previewed snapshot.
if (getParameters().getSnapshot().getType() == Snapshot.SnapshotType.STATELESS) {
Guid activeSnapshotId = snapshotDao.get(getParameters().getVmId(), Snapshot.SnapshotType.ACTIVE).getId();
updateCinderDiskSnapshot(cinderDisk.getId(), activeSnapshotId, cinderDisk.getVmSnapshotId());
} else if (getParameters().getSnapshot().getType() != Snapshot.SnapshotType.REGULAR) {
updateCinderDiskSnapshot(cinderDisk.getId(), getParameters().getSnapshot().getId(), null);
}
}
List<CinderDisk> cinderDisksToRemove = getParameters().getCinderDisksToRemove();
for (CinderDisk cinderDisk : cinderDisksToRemove) {
RemoveCinderDiskParameters removeDiskParam = new RemoveCinderDiskParameters(cinderDisk.getImageId());
removeDiskParam.setRemovedVolume(cinderDisk);
removeDiskParam.setParentCommand(getActionType());
removeDiskParam.setStorageDomainId(cinderDisk.getStorageIds().get(0));
removeDiskParam.setParentParameters(getParameters());
removeDiskParam.setEndProcedure(EndProcedure.COMMAND_MANAGED);
Future<ActionReturnValue> future = commandCoordinatorUtil.executeAsyncCommand(ActionType.RemoveCinderDisk, removeDiskParam, cloneContextAndDetachFromParent());
try {
future.get();
} catch (InterruptedException | ExecutionException e) {
log.error("Error removing Cinder disk", e);
}
}
List<CinderDisk> cinderVolumesToRemove = getParameters().getCinderVolumesToRemove();
for (CinderDisk cinderVolume : cinderVolumesToRemove) {
RemoveCinderDiskVolumeParameters removeDiskVolumeParam = new RemoveCinderDiskVolumeParameters(cinderVolume);
removeDiskVolumeParam.setParentCommand(getActionType());
removeDiskVolumeParam.setParentParameters(getParameters());
removeDiskVolumeParam.setEndProcedure(EndProcedure.COMMAND_MANAGED);
Future<ActionReturnValue> future = commandCoordinatorUtil.executeAsyncCommand(ActionType.RemoveCinderDiskVolume, removeDiskVolumeParam, cloneContextAndDetachFromParent());
try {
future.get();
} catch (InterruptedException | ExecutionException e) {
log.error("Error removing Cinder disk", e);
}
}
setSucceeded(true);
}
use of org.ovirt.engine.core.common.action.ImagesContainterParametersBase in project ovirt-engine by oVirt.
the class CreateAllTemplateDisksCommand method addVmTemplateCinderDisks.
private boolean addVmTemplateCinderDisks(Map<Guid, Guid> srcDeviceIdToTargetDeviceIdMapping) {
List<CinderDisk> cinderDisks = getCinderDisks();
if (cinderDisks.isEmpty()) {
return true;
}
// Create Cinder disk templates
Map<Guid, Guid> diskImageMap = new HashMap<>();
for (CinderDisk cinderDisk : cinderDisks) {
ImagesContainterParametersBase params = buildCloneCinderDiskCommandParameters(cinderDisk);
ActionReturnValue returnValue = runInternalAction(ActionType.CloneSingleCinderDisk, params, cloneContext().withoutExecutionContext().withoutLock());
if (!returnValue.getSucceeded()) {
log.error("Error cloning Cinder disk '{}'", cinderDisk.getDiskAlias());
getReturnValue().setFault(returnValue.getFault());
return false;
}
Guid imageId = returnValue.getActionReturnValue();
diskImageMap.put(cinderDisk.getId(), imageId);
}
srcDeviceIdToTargetDeviceIdMapping.putAll(diskImageMap);
return true;
}
use of org.ovirt.engine.core.common.action.ImagesContainterParametersBase in project ovirt-engine by oVirt.
the class CloneSingleCinderDiskCommandCallback method childCommandsExecutionEnded.
@Override
protected void childCommandsExecutionEnded(CommandBase<?> command, boolean anyFailed, List<Guid> childCmdIds, CommandExecutionStatus status, int completedChildren) {
BaseImagesCommand<ImagesContainterParametersBase> cloneCinderDiskCommand = (BaseImagesCommand<ImagesContainterParametersBase>) command;
ImagesContainterParametersBase parameters = cloneCinderDiskCommand.getParameters();
ImageStatus imageStatus = cloneCinderDiskCommand.getCinderBroker().getDiskStatus(parameters.getDestinationImageId());
DiskImage disk = (CinderDisk) diskDao.get(parameters.getContainerId());
if (imageStatus != null && imageStatus != disk.getImageStatus()) {
switch(imageStatus) {
case OK:
setCommandEndStatus(command, false, status, childCmdIds);
break;
case ILLEGAL:
setCommandEndStatus(command, true, status, childCmdIds);
break;
}
}
}
Aggregations