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());
}
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;
}
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;
}
}
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());
}
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;
}
Aggregations