use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class RestoreAllSnapshotsCommand method restoreAllCinderDisks.
protected boolean restoreAllCinderDisks(List<CinderDisk> cinderDisksToRestore, List<CinderDisk> cinderDisksToRemove, List<CinderDisk> cinderVolumesToRemove, Guid removedSnapshotId) {
Future<ActionReturnValue> future = commandCoordinatorUtil.executeAsyncCommand(ActionType.RestoreAllCinderSnapshots, buildCinderChildCommandParameters(cinderDisksToRestore, cinderDisksToRemove, cinderVolumesToRemove, removedSnapshotId), cloneContextAndDetachFromParent());
try {
ActionReturnValue actionReturnValue = future.get();
if (!actionReturnValue.getSucceeded()) {
getReturnValue().setFault(actionReturnValue.getFault());
log.error("Error while restoring Cinder snapshot");
return false;
}
} catch (InterruptedException | ExecutionException e) {
log.error("Error deleting Cinder volumes for restore snapshot", e);
return false;
}
return true;
}
use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class RemoveSnapshotSingleDiskLiveCommand method performNextOperation.
@Override
public boolean performNextOperation(int completedChildCount) {
// Steps are executed such that:
// a) all logic before the command runs is idempotent
// b) the command is the last action in the step
// This allows for recovery after a crash at any point during command execution.
log.debug("Proceeding with execution of RemoveSnapshotSingleDiskLiveCommand");
if (getParameters().getCommandStep() == null) {
getParameters().setCommandStep(getInitialMergeStepForImage(getParameters().getImageId()));
getParameters().setChildCommands(new HashMap<>());
}
// Upon recovery or after invoking a new child command, our map may be missing an entry
syncChildCommandList(getParameters());
Guid currentChildId = getCurrentChildId(getParameters());
ActionReturnValue actionReturnValue = null;
if (currentChildId != null) {
actionReturnValue = commandCoordinatorUtil.getCommandReturnValue(currentChildId);
getParameters().setCommandStep(getParameters().getNextCommandStep());
}
log.info("Executing Live Merge command step '{}'", getParameters().getCommandStep());
Pair<ActionType, ? extends ActionParametersBase> nextCommand = null;
switch(getParameters().getCommandStep()) {
case EXTEND:
nextCommand = new Pair<>(ActionType.MergeExtend, buildMergeParameters());
getParameters().setNextCommandStep(RemoveSnapshotSingleDiskStep.MERGE);
break;
case MERGE:
nextCommand = new Pair<>(ActionType.Merge, buildMergeParameters());
getParameters().setNextCommandStep(RemoveSnapshotSingleDiskStep.MERGE_STATUS);
break;
case MERGE_STATUS:
nextCommand = new Pair<>(ActionType.MergeStatus, buildMergeParameters());
getParameters().setNextCommandStep(RemoveSnapshotSingleDiskStep.DESTROY_IMAGE);
break;
case DESTROY_IMAGE:
if (actionReturnValue != null) {
getParameters().setMergeStatusReturnValue(actionReturnValue.getActionReturnValue());
} else if (getParameters().getMergeStatusReturnValue() == null) {
// If the images were already merged, just add the orphaned image
getParameters().setMergeStatusReturnValue(synthesizeMergeStatusReturnValue());
}
nextCommand = buildDestroyCommand(ActionType.DestroyImage, getActionType(), new ArrayList<>(getParameters().getMergeStatusReturnValue().getImagesToRemove()));
getParameters().setNextCommandStep(RemoveSnapshotSingleDiskStep.REDUCE_IMAGE);
break;
case REDUCE_IMAGE:
nextCommand = buildReduceImageCommand();
getParameters().setNextCommandStep(RemoveSnapshotSingleDiskStep.COMPLETE);
break;
case COMPLETE:
setCommandStatus(CommandStatus.SUCCEEDED);
break;
}
persistCommand(getParameters().getParentCommand(), true);
if (nextCommand != null) {
commandCoordinatorUtil.executeAsyncCommand(nextCommand.getFirst(), nextCommand.getSecond(), cloneContextAndDetachFromParent());
// Add the child, but wait, it's a race! child will start, task may spawn, get polled, and we won't have the child id
return true;
} else {
return false;
}
}
use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class RestoreAllSnapshotsCommand method removeUnusedImages.
private void removeUnusedImages(List<CinderDisk> cinderVolumesToRemove) {
Set<Guid> imageIdsUsedByActiveSnapshot = new HashSet<>();
for (DiskImage diskImage : getImagesList()) {
imageIdsUsedByActiveSnapshot.add(diskImage.getId());
}
List<DiskImage> imagesToRemove = new ArrayList<>();
for (Guid snapshotToRemove : snapshotsToRemove) {
List<DiskImage> snapshotDiskImages = diskImageDao.getAllSnapshotsForVmSnapshot(snapshotToRemove);
imagesToRemove.addAll(snapshotDiskImages);
}
Set<Guid> removeInProcessImageIds = new HashSet<>();
for (DiskImage diskImage : imagesToRemove) {
if (imageIdsUsedByActiveSnapshot.contains(diskImage.getId()) || removeInProcessImageIds.contains(diskImage.getId())) {
continue;
}
List<DiskImage> diskImagesFromPreviewSnap = imagesFromPreviewSnapshot.stream().filter(diskImageFromPreview -> diskImageFromPreview.getImageId().equals(diskImage.getImageId())).collect(Collectors.toList());
if (!diskImagesFromPreviewSnap.isEmpty() && diskImagesFromPreviewSnap.get(0).getDiskStorageType() == DiskStorageType.CINDER) {
cinderVolumesToRemove.add((CinderDisk) diskImagesFromPreviewSnap.get(0));
continue;
}
ActionReturnValue retValue = runAsyncTask(ActionType.RemoveImage, new RemoveImageParameters(diskImage.getImageId()));
if (retValue.getSucceeded()) {
removeInProcessImageIds.add(diskImage.getImageId());
} else {
log.error("Failed to remove image '{}'", diskImage.getImageId());
}
}
}
use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class UpdateVmDiskCommandTest method testAmendFailedWithPropertyChange.
@Test
public void testAmendFailedWithPropertyChange() {
DiskImage oldDisk = createDiskImage();
oldDisk.setVolumeFormat(VolumeFormat.COW);
oldDisk.setQcowCompat(QcowCompat.QCOW2_V2);
oldDisk.setDiskAlias("Test");
oldDisk.setDiskDescription("Test_Desc");
when(diskDao.get(diskImageGuid)).thenReturn(oldDisk);
DiskImage newDisk = DiskImage.copyOf(oldDisk);
newDisk.setQcowCompat(QcowCompat.QCOW2_V3);
newDisk.setDiskAlias("New Disk Alias");
command.getParameters().setDiskInfo(newDisk);
initializeCommand();
ActionReturnValue ret = new ActionReturnValue();
ret.setSucceeded(false);
ArrayList<String> msgList = new ArrayList<>();
msgList.add(EngineMessage.ACTION_TYPE_FAILED_AMEND_NOT_SUPPORTED_BY_DC_VERSION.toString());
ret.setValidationMessages(msgList);
when(backend.runInternalAction(eq(ActionType.AmendImageGroupVolumes), any(), any())).thenReturn(ret);
mockVdsCommandSetVolumeDescription();
mockGetAllSnapshotsForDisk(Collections.singletonList(oldDisk));
command.executeVmCommand();
verify(command, times(1)).amendDiskImage();
verify(command, times(1)).setVolumeDescription(any(), any());
}
use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class AttachStorageDomainToPoolCommandTest method statusSetInMap.
@Test
public void statusSetInMap() {
cmd.init();
Guid storageDomainId = cmd.getStorageDomainId();
Guid poolId = cmd.getStoragePoolId();
doNothing().when(cmd).attemptToActivateDomain();
doReturn(Collections.singletonList(new Pair<>(Guid.newGuid(), true))).when(cmd).connectHostsInUpToDomainStorageServer();
StoragePool pool = new StoragePool();
pool.setId(poolId);
pool.setStatus(StoragePoolStatus.Up);
when(storagePoolDao.get(any())).thenReturn(pool);
when(isoMapDao.get(any())).thenReturn(map);
when(storageDomainDao.getForStoragePool(any(), any())).thenReturn(new StorageDomain());
when(storageDomainStaticDao.get(any())).thenReturn(new StorageDomainStatic());
doReturn(pool.getId()).when(cmd).getStoragePoolIdFromVds();
ActionReturnValue actionReturnValue = new ActionReturnValue();
actionReturnValue.setSucceeded(true);
when(backendInternal.runInternalAction(any(), any(), any())).thenReturn(actionReturnValue);
StorageDomainStatic storageDomain = new StorageDomainStatic();
storageDomain.setId(Guid.newGuid());
storageDomain.setStorageDomainType(StorageDomainType.ImportExport);
mockGetStorageDomainInfoVdsCommand(storageDomain);
mockAttachStorageDomainVdsCommand();
when(vdsDao.get(any())).thenReturn(vds);
doReturn(Collections.emptyList()).when(cmd).getEntitiesFromStorageOvfDisk(storageDomainId, pool.getId());
doReturn(Collections.emptyList()).when(cmd).getAllOVFDisks(storageDomainId, pool.getId());
doAnswer(invocation -> {
map = (StoragePoolIsoMap) invocation.getArguments()[0];
return null;
}).when(isoMapDao).save(any());
cmd.setCompensationContext(mock(CompensationContext.class));
cmd.executeCommand();
assertNotNull(map);
assertEquals(StorageDomainStatus.Maintenance, map.getStatus());
}
Aggregations