use of org.ovirt.engine.core.common.action.ImagesContainterParametersBase in project ovirt-engine by oVirt.
the class CreateAllTemplateDisksCommand method buildCloneCinderDiskCommandParameters.
private ImagesContainterParametersBase buildCloneCinderDiskCommandParameters(CinderDisk cinderDisk) {
ImagesContainterParametersBase createParams = new ImagesContainterParametersBase(cinderDisk.getImageId());
DiskImage templateDisk = getParameters().getDiskInfoDestinationMap().get(cinderDisk.getId());
createParams.setDiskAlias(templateDisk.getDiskAlias());
createParams.setStorageDomainId(templateDisk.getStorageIds().get(0));
createParams.setParentCommand(getActionType());
createParams.setParentParameters(getParameters());
createParams.setVmSnapshotId(vmSnapshotId);
return createParams;
}
use of org.ovirt.engine.core.common.action.ImagesContainterParametersBase in project ovirt-engine by oVirt.
the class RemoveAllCinderSnapshotDisksCommand method getCinderDiskSnapshotParameter.
private ImagesContainterParametersBase getCinderDiskSnapshotParameter(CinderDisk cinderDisk) {
ImagesContainterParametersBase removeCinderSnapshotParams = new ImagesContainterParametersBase(cinderDisk.getImageId());
removeCinderSnapshotParams.setDestinationImageId(cinderDisk.getImageId());
removeCinderSnapshotParams.setStorageDomainId(cinderDisk.getStorageIds().get(0));
removeCinderSnapshotParams.setParentCommand(getActionType());
removeCinderSnapshotParams.setParentParameters(getParameters());
removeCinderSnapshotParams.setEndProcedure(EndProcedure.COMMAND_MANAGED);
return removeCinderSnapshotParams;
}
use of org.ovirt.engine.core.common.action.ImagesContainterParametersBase in project ovirt-engine by oVirt.
the class TryBackToAllSnapshotsOfVmCommand method tryBackAllCinderDisks.
protected boolean tryBackAllCinderDisks(List<CinderDisk> cinderDisks, Guid newSnapshotId) {
for (CinderDisk disk : cinderDisks) {
ImagesContainterParametersBase params = buildCinderChildCommandParameters(disk, newSnapshotId);
ActionReturnValue actionReturnValue = runInternalAction(ActionType.TryBackToCinderSnapshot, params, cloneContextAndDetachFromParent());
if (!actionReturnValue.getSucceeded()) {
log.error("Error cloning Cinder disk for preview. '{}': {}", disk.getDiskAlias());
getReturnValue().setFault(actionReturnValue.getFault());
return false;
}
}
return true;
}
use of org.ovirt.engine.core.common.action.ImagesContainterParametersBase in project ovirt-engine by oVirt.
the class TryBackToAllSnapshotsOfVmCommand method executeVmCommand.
@Override
protected void executeVmCommand() {
final boolean restoreMemory = isRestoreMemory();
final Guid newActiveSnapshotId = Guid.newGuid();
final Snapshot snapshotToBePreviewed = getDstSnapshot();
final Snapshot previousActiveSnapshot = snapshotDao.get(getVmId(), SnapshotType.ACTIVE);
final Guid previousActiveSnapshotId = previousActiveSnapshot.getId();
final List<DiskImage> images = getImagesToPreview();
// Images list without those that are excluded from preview
final List<DiskImage> filteredImages = (List<DiskImage>) CollectionUtils.subtract(images, getImagesExcludedFromPreview(images, previousActiveSnapshotId, newActiveSnapshotId));
if (log.isInfoEnabled()) {
log.info("Previewing snapshot {} with the disks:\n{}", getSnapshotName(), filteredImages.stream().map(disk -> String.format("%s (%s) to imageId %s", disk.getName(), disk.getId().toString(), disk.getImageId().toString())).collect(Collectors.joining("\n")));
}
final List<CinderDisk> cinderDisks = new ArrayList<>();
TransactionSupport.executeInNewTransaction(() -> {
getCompensationContext().snapshotEntity(previousActiveSnapshot);
snapshotDao.remove(previousActiveSnapshotId);
getSnapshotsManager().addSnapshot(previousActiveSnapshotId, "Active VM before the preview", SnapshotStatus.LOCKED, SnapshotType.PREVIEW, getVm(), true, previousActiveSnapshot.getMemoryDiskId(), previousActiveSnapshot.getMetadataDiskId(), null, null, null, getCompensationContext());
getSnapshotsManager().addActiveSnapshot(newActiveSnapshotId, getVm(), SnapshotStatus.OK, restoreMemory ? snapshotToBePreviewed.getMemoryDiskId() : null, restoreMemory ? snapshotToBePreviewed.getMetadataDiskId() : null, snapshotToBePreviewed.getCreationDate(), images, getCompensationContext());
// being executed in the same transaction so we can restore the vm config and end the command.
if (!filteredImages.isEmpty()) {
getCompensationContext().stateChanged();
} else {
vmStaticDao.incrementDbGeneration(getVm().getId());
restoreVmConfigFromSnapshot();
}
return null;
});
initializeSnapshotsLeasesParams();
if (!filteredImages.isEmpty()) {
vmHandler.lockVm(getVm().getDynamicData(), getCompensationContext());
freeLock();
TransactionSupport.executeInNewTransaction(new TransactionMethod<Void>() {
@Override
public Void runInTransaction() {
for (DiskImage image : filteredImages) {
if (image.getDiskStorageType() == DiskStorageType.CINDER) {
cinderDisks.add((CinderDisk) image);
continue;
}
ActionReturnValue actionReturnValue = runInternalActionWithTasksContext(ActionType.TryBackToSnapshot, buildTryBackToSnapshotParameters(newActiveSnapshotId, image));
if (actionReturnValue.getSucceeded()) {
getTaskIdList().addAll(actionReturnValue.getInternalVdsmTaskIdList());
} else if (actionReturnValue.getFault() != null) {
// if we have a fault, forward it to the user
throw new EngineException(actionReturnValue.getFault().getError(), actionReturnValue.getFault().getMessage());
} else {
log.error("Cannot create snapshot");
throw new EngineException(EngineError.IRS_IMAGE_STATUS_ILLEGAL);
}
}
if (getParameters().getLeaseAction() == LeaseAction.CREATE_NEW_LEASE) {
if (!addVmLease(getParameters().getDstLeaseDomainId(), getVm().getId(), false)) {
log.error("Failed to create lease for VM '{}' on storage domain '{}'", getVm().getName(), getParameters().getDstLeaseDomainId());
throw new EngineException(EngineError.FailedToCreateLease);
}
}
if (!cinderDisks.isEmpty() && !tryBackAllCinderDisks(cinderDisks, newActiveSnapshotId)) {
throw new EngineException(EngineError.CINDER_ERROR, "Failed to preview a snapshot!");
}
return null;
}
private ImagesContainterParametersBase buildTryBackToSnapshotParameters(final Guid newActiveSnapshotId, DiskImage image) {
ImagesContainterParametersBase params = new ImagesContainterParametersBase(image.getImageId());
params.setParentCommand(ActionType.TryBackToAllSnapshotsOfVm);
params.setVmSnapshotId(newActiveSnapshotId);
params.setEntityInfo(getParameters().getEntityInfo());
params.setParentParameters(getParameters());
params.setQuotaId(image.getQuotaId());
return params;
}
});
} else {
// if there are no disks to restore, no compensation context is saved and the VM Configuration
// (including clusterCompatibilityVersionOrigin) is already restored at this point. Otherwise,
// if disks are being restored, the VM Configuration is restored later in endSuccessfully()
updateClusterCompatibilityVersionToOldCluster(true);
}
setSucceeded(true);
}
use of org.ovirt.engine.core.common.action.ImagesContainterParametersBase in project ovirt-engine by oVirt.
the class RemoveSnapshotCommand method endVmCommand.
@Override
protected void endVmCommand() {
initializeObjectState();
if (getParameters().getTaskGroupSuccess()) {
snapshotDao.remove(getParameters().getSnapshotId());
} else {
List<String> failedToRemoveDisks = new ArrayList<>();
Snapshot snapshot = snapshotDao.get(getParameters().getSnapshotId());
for (ActionParametersBase parameters : getParameters().getImagesParameters()) {
ImagesContainterParametersBase imagesParams = parameters instanceof ImagesContainterParametersBase ? (ImagesContainterParametersBase) parameters : null;
if (imagesParams == null) {
// instances of ImagesContainterParametersBase objects.
continue;
}
if (imagesParams.getTaskGroupSuccess()) {
snapshot = imagesHandler.prepareSnapshotConfigWithoutImageSingleImage(snapshot, imagesParams.getImageId(), ovfManager);
} else {
log.error("Could not delete image '{}' from snapshot '{}'", imagesParams.getImageId(), getParameters().getSnapshotId());
DiskImage diskImage = diskImageDao.getSnapshotById(imagesParams.getImageId());
failedToRemoveDisks.add(diskImage.getDiskAlias());
}
}
// Remove memory volume and update the dao.
// Note: on failure, we can treat memory volume deletion as deleting an image
// and remove it from the snapshot entity (rollback isn't applicable).
snapshot.setMemoryDiskId(null);
snapshot.setMetadataDiskId(null);
snapshotDao.update(snapshot);
if (!failedToRemoveDisks.isEmpty()) {
addCustomValue("DiskAliases", StringUtils.join(failedToRemoveDisks, ", "));
auditLogDirector.log(this, AuditLogType.USER_REMOVE_SNAPSHOT_FINISHED_FAILURE_PARTIAL_SNAPSHOT);
}
snapshotDao.updateStatus(getParameters().getSnapshotId(), SnapshotStatus.OK);
}
super.endVmCommand();
}
Aggregations