Search in sources :

Example 1 with StepEnum

use of org.ovirt.engine.core.common.job.StepEnum in project ovirt-engine by oVirt.

the class GlusterTasksSyncJob method createJobToMonitor.

private void createJobToMonitor(Cluster cluster, GlusterAsyncTask task) {
    if (!isTaskToBeMonitored(task)) {
        // there's no need to monitor jobs that are failed or completed
        return;
    }
    StepEnum step = task.getType().getStep();
    ActionType actionType;
    switch(step) {
        case REBALANCING_VOLUME:
            actionType = ActionType.StartRebalanceGlusterVolume;
            break;
        case REMOVING_BRICKS:
            actionType = ActionType.StartRemoveGlusterVolumeBricks;
            break;
        default:
            actionType = ActionType.Unknown;
    }
    String volumeName = task.getTaskParameters().getVolumeName();
    GlusterVolumeEntity vol = volumeDao.getByName(cluster.getId(), volumeName);
    if (vol == null) {
        log.info("Volume '{}' does not exist yet for task detected from CLI '{}', not adding to engine", volumeName, task);
        return;
    }
    Guid jobId = addJob(cluster, task, actionType, vol);
    Guid execStepId = addExecutingStep(jobId);
    Guid asyncStepId = addAsyncTaskStep(cluster, task, step, execStepId);
    Step asyncStep = stepDao.get(asyncStepId);
    executionHandler.updateStepExternalId(asyncStep, task.getTaskId(), ExternalSystemType.GLUSTER);
    updateVolumeBricksAndLock(cluster, task, vol);
}
Also used : ActionType(org.ovirt.engine.core.common.action.ActionType) StepEnum(org.ovirt.engine.core.common.job.StepEnum) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) Guid(org.ovirt.engine.core.compat.Guid) Step(org.ovirt.engine.core.common.job.Step)

Example 2 with StepEnum

use of org.ovirt.engine.core.common.job.StepEnum in project ovirt-engine by oVirt.

the class ExportOvaCommand method createOvaCreationStepContext.

protected CommandContext createOvaCreationStepContext() {
    CommandContext commandCtx = null;
    StepEnum step = StepEnum.CREATING_OVA;
    try {
        Step ovaCreationStep = executionHandler.addSubStep(getExecutionContext(), getExecutionContext().getJob().getStep(StepEnum.EXECUTING), step, ExecutionMessageDirector.resolveStepMessage(step, Collections.emptyMap()));
        ExecutionContext ctx = new ExecutionContext();
        ctx.setStep(ovaCreationStep);
        ctx.setMonitored(true);
        commandCtx = cloneContext().withoutCompensationContext().withExecutionContext(ctx).withoutLock();
    } catch (RuntimeException e) {
        log.error("Failed to create command context of creating OVA '{}': {}", getVmName(), e.getMessage());
        log.debug("Exception", e);
    }
    return commandCtx;
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) StepEnum(org.ovirt.engine.core.common.job.StepEnum) Step(org.ovirt.engine.core.common.job.Step)

Example 3 with StepEnum

use of org.ovirt.engine.core.common.job.StepEnum in project ovirt-engine by oVirt.

the class VdsCommandsHelper method updateStepMessage.

private void updateStepMessage(CommandBase<?> cmd, Guid vdsForExecution) {
    // As an HSM job can run on any host, we want to display the host running the job when it is
    // chosen. To do so, we look for a corresponding command step with an "_ON_HOST" suffix that
    // is supposed to contain a "vds" placeholder.
    StepEnum stepEnum = null;
    try {
        stepEnum = StepEnum.valueOf(getStepWithHostname(cmd));
    } catch (IllegalArgumentException e) {
        // Ignore this exception and do nothing as no corresponding step_ON_HOST found.
        log.debug("No StepEnum found for " + getStepWithHostname(cmd));
        return;
    }
    Step step = cmd.getExecutionContext().getStep();
    Map<String, String> jobProperties = cmd.getJobMessageProperties();
    jobProperties.put(VdcObjectType.VDS.name().toLowerCase(), vdsDao.get(vdsForExecution).getName());
    step.setDescription(ExecutionMessageDirector.resolveStepMessage(stepEnum, jobProperties));
    stepDao.update(step);
    // Add an audit log entry if a corresponding AuditLogType exists. Note that we expect an AuditLogType
    // with name equals to Step_Enum to exist. If an AuditLogType exists, the arguments in the audit
    // message must match these in the StepEnum message.
    AuditLogType logType = null;
    try {
        logType = AuditLogType.valueOf(getAuditLogType(cmd));
    } catch (IllegalArgumentException e) {
        // Ignore this exception and do nothing as no corresponding AuditLogType found.
        log.debug("No AuditLogType found for " + getAuditLogType(cmd));
        return;
    }
    jobProperties.entrySet().stream().forEach(entry -> cmd.addCustomValue(entry.getKey(), entry.getValue()));
    Injector.get(AuditLogDirector.class).log(cmd, logType);
}
Also used : AuditLogType(org.ovirt.engine.core.common.AuditLogType) StepEnum(org.ovirt.engine.core.common.job.StepEnum) Step(org.ovirt.engine.core.common.job.Step) AuditLogDirector(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector)

Aggregations

Step (org.ovirt.engine.core.common.job.Step)3 StepEnum (org.ovirt.engine.core.common.job.StepEnum)3 CommandContext (org.ovirt.engine.core.bll.context.CommandContext)1 ExecutionContext (org.ovirt.engine.core.bll.job.ExecutionContext)1 AuditLogType (org.ovirt.engine.core.common.AuditLogType)1 ActionType (org.ovirt.engine.core.common.action.ActionType)1 GlusterVolumeEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)1 Guid (org.ovirt.engine.core.compat.Guid)1 AuditLogDirector (org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector)1