Search in sources :

Example 26 with ActionType

use of org.ovirt.engine.core.common.action.ActionType in project ovirt-engine by oVirt.

the class GlusterVolumeSnapshotListModel method scheduleSnapshot.

private void scheduleSnapshot(final GlusterVolumeSnapshotModel snapshotModel, boolean reschedule) {
    GlusterVolumeEntity volumeEntity = getEntity();
    final GlusterVolumeSnapshotSchedule schedule = new GlusterVolumeSnapshotSchedule();
    schedule.setSnapshotNamePrefix(snapshotModel.getSnapshotName().getEntity());
    schedule.setSnapshotDescription(snapshotModel.getDescription().getEntity());
    schedule.setClusterId(volumeEntity.getClusterId());
    schedule.setVolumeId(volumeEntity.getId());
    switch(snapshotModel.getRecurrence().getSelectedItem()) {
        case INTERVAL:
            schedule.setRecurrence(GlusterVolumeSnapshotScheduleRecurrence.INTERVAL);
            schedule.setInterval(Integer.valueOf(snapshotModel.getInterval().getSelectedItem()));
            break;
        case HOURLY:
            schedule.setRecurrence(GlusterVolumeSnapshotScheduleRecurrence.HOURLY);
            break;
        case DAILY:
            schedule.setRecurrence(GlusterVolumeSnapshotScheduleRecurrence.DAILY);
            schedule.setExecutionTime(getExecutionTime(snapshotModel));
            break;
        case WEEKLY:
            schedule.setRecurrence(GlusterVolumeSnapshotScheduleRecurrence.WEEKLY);
            schedule.setExecutionTime(getExecutionTime(snapshotModel));
            StringBuilder sb = new StringBuilder();
            for (DayOfWeek day : snapshotModel.getDaysOfTheWeek().getSelectedItem()) {
                sb.append(day.name().substring(0, 3));
                // $NON-NLS-1$
                sb.append(',');
            }
            schedule.setDays(sb.toString());
            break;
        case MONTHLY:
            schedule.setRecurrence(GlusterVolumeSnapshotScheduleRecurrence.MONTHLY);
            schedule.setExecutionTime(getExecutionTime(snapshotModel));
            schedule.setDays(snapshotModel.getDaysOfMonth().getSelectedItem());
            break;
    }
    Date startAt = snapshotModel.getStartAt().getEntity();
    schedule.setStartDate(startAt);
    schedule.setTimeZone(snapshotModel.getTimeZones().getSelectedItem().getKey());
    if (snapshotModel.getEndByOptions().getSelectedItem() == EndDateOptions.NoEndDate) {
        schedule.setEndByDate(null);
    } else {
        schedule.setEndByDate(snapshotModel.getEndDate().getEntity());
    }
    ScheduleGlusterVolumeSnapshotParameters params = new ScheduleGlusterVolumeSnapshotParameters(schedule, snapshotModel.getDisableCliSchedule().getEntity());
    snapshotModel.startProgress();
    ActionType actionType = null;
    if (reschedule) {
        actionType = ActionType.RescheduleGlusterVolumeSnapshot;
    } else {
        actionType = ActionType.ScheduleGlusterVolumeSnapshot;
    }
    Frontend.getInstance().runAction(actionType, params, result -> {
        GlusterVolumeSnapshotListModel localModel = (GlusterVolumeSnapshotListModel) result.getState();
        snapshotModel.stopProgress();
        localModel.postSnapshotAction(result.getReturnValue());
    }, this, snapshotModel.getDisableCliSchedule().getEntity());
}
Also used : DayOfWeek(org.ovirt.engine.core.compat.DayOfWeek) GlusterVolumeSnapshotSchedule(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule) ActionType(org.ovirt.engine.core.common.action.ActionType) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) Date(java.util.Date) ScheduleGlusterVolumeSnapshotParameters(org.ovirt.engine.core.common.action.gluster.ScheduleGlusterVolumeSnapshotParameters)

Example 27 with ActionType

use of org.ovirt.engine.core.common.action.ActionType in project ovirt-engine by oVirt.

the class RemoveDiskSnapshotsCommand method performNextOperationColdMerge.

private boolean performNextOperationColdMerge(int completedChildren) {
    Guid nextImageId = getParameters().getImageIds().get(completedChildren);
    log.info("Starting child command {} of {}, image '{}'", completedChildren + 1, getParameters().getImageIds().size(), nextImageId);
    ImagesContainterParametersBase parameters = buildRemoveSnapshotSingleDiskParameters(nextImageId);
    ActionType actionType = FeatureSupported.isQemuimgCommitSupported(getStoragePool().getCompatibilityVersion()) ? ActionType.ColdMergeSnapshotSingleDisk : ActionType.RemoveSnapshotSingleDisk;
    commandCoordinatorUtil.executeAsyncCommand(actionType, parameters, cloneContextAndDetachFromParent());
    return true;
}
Also used : ActionType(org.ovirt.engine.core.common.action.ActionType) ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase) Guid(org.ovirt.engine.core.compat.Guid)

Example 28 with ActionType

use of org.ovirt.engine.core.common.action.ActionType 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;
    }
}
Also used : ActionType(org.ovirt.engine.core.common.action.ActionType) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid)

Example 29 with ActionType

use of org.ovirt.engine.core.common.action.ActionType in project ovirt-engine by oVirt.

the class BackendDiskAttachmentResource method update.

@Override
public DiskAttachment update(DiskAttachment attachment) {
    if (attachment.isSetActive()) {
        DiskAttachment attachmentFromDb = get();
        if (!attachmentFromDb.isActive().equals(attachment.isActive())) {
            ActionType actionType = attachment.isActive() ? ActionType.HotPlugDiskToVm : ActionType.HotUnPlugDiskFromVm;
            VmDiskOperationParameterBase params = new VmDiskOperationParameterBase(new DiskVmElement(guid, vmId));
            try {
                doAction(actionType, params);
            } catch (BackendFailureException e) {
                return handleError(e, false);
            }
        }
    }
    return performUpdate(attachment, new AddDiskResolver(), ActionType.UpdateVmDisk, new UpdateParametersProvider());
}
Also used : ActionType(org.ovirt.engine.core.common.action.ActionType) DiskAttachment(org.ovirt.engine.api.model.DiskAttachment) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) VmDiskOperationParameterBase(org.ovirt.engine.core.common.action.VmDiskOperationParameterBase)

Example 30 with ActionType

use of org.ovirt.engine.core.common.action.ActionType in project ovirt-engine by oVirt.

the class ActionTypeDeserializer method deserialize.

@Override
public ActionType deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    String jsonValue = jsonParser.getText();
    ActionType actionType = mappings.get(jsonValue);
    if (actionType == null) {
        actionType = ActionType.Unknown;
    }
    return actionType;
}
Also used : ActionType(org.ovirt.engine.core.common.action.ActionType)

Aggregations

ActionType (org.ovirt.engine.core.common.action.ActionType)58 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)37 ArrayList (java.util.ArrayList)31 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)24 Test (org.junit.Test)23 IFrontendActionAsyncCallback (org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback)16 Guid (org.ovirt.engine.core.compat.Guid)15 List (java.util.List)13 QueryType (org.ovirt.engine.core.common.queries.QueryType)11 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)11 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)11 Frontend (org.ovirt.engine.ui.frontend.Frontend)10 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)10 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)10 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)9 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)9 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)9 Arrays (java.util.Arrays)7 HashSet (java.util.HashSet)7 Set (java.util.Set)7