Search in sources :

Example 36 with Step

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

the class StepDaoTest method generateNewEntity.

@Override
protected Step generateNewEntity() {
    Step step = new Step(StepEnum.EXECUTING);
    step.setJobId(EXISTING_JOB_ID);
    step.setStepNumber(1);
    step.setDescription("Execution step");
    step.setCorrelationId("Some correlation id");
    return step;
}
Also used : Step(org.ovirt.engine.core.common.job.Step)

Example 37 with Step

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

the class StepDaoTest method startedStepsByStepSubjectEntityOtherStatuses.

@Test
public void startedStepsByStepSubjectEntityOtherStatuses() {
    StepSubjectEntity subjectEntity = prepareStartedStepsByStepSubjectEntityTest();
    Step step = dao.get(FixturesTool.STEP_ID);
    Arrays.stream(JobExecutionStatus.values()).filter(status -> status != JobExecutionStatus.STARTED).forEach(status -> {
        step.setStatus(status);
        dao.update(step);
        assertNoStartedStepsForSubjectEntity(subjectEntity);
    });
}
Also used : BaseDisk(org.ovirt.engine.core.common.businessentities.storage.BaseDisk) StepSubjectEntity(org.ovirt.engine.core.common.job.StepSubjectEntity) JobExecutionStatus(org.ovirt.engine.core.common.job.JobExecutionStatus) Arrays(java.util.Arrays) StepEnum(org.ovirt.engine.core.common.job.StepEnum) Assert.assertNotNull(org.junit.Assert.assertNotNull) Date(java.util.Date) Guid(org.ovirt.engine.core.compat.Guid) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ExternalSystemType(org.ovirt.engine.core.common.job.ExternalSystemType) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Assert.assertThat(org.junit.Assert.assertThat) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.emptyCollectionOf(org.hamcrest.Matchers.emptyCollectionOf) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) SubjectEntity(org.ovirt.engine.core.common.businessentities.SubjectEntity) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Step(org.ovirt.engine.core.common.job.Step) Step(org.ovirt.engine.core.common.job.Step) StepSubjectEntity(org.ovirt.engine.core.common.job.StepSubjectEntity) Test(org.junit.Test)

Example 38 with Step

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

the class ExecutionHandler method addStep.

/**
 * Adds a {@link Step} entity by the provided context. A {@link Step} will not be created if
 * {@code ExecutionContext.isMonitored()} returns false.
 *
 * @param context
 *            The context of the execution which defines visibility and execution method.
 * @param stepName
 *            The name of the step.
 * @param description
 *            A presentation name for the step. If not provided, the presentation name is resolved by the
 *            {@code stepName}.
 * @param isExternal
 *        Indicates if the step is invoked by a plug-in
 */
public Step addStep(ExecutionContext context, StepEnum stepName, String description, boolean isExternal) {
    if (context == null) {
        return null;
    }
    Step step = null;
    if (context.isMonitored()) {
        if (description == null) {
            description = ExecutionMessageDirector.getInstance().getStepMessage(stepName);
        }
        try {
            Job job = context.getJob();
            if (context.getExecutionMethod() == ExecutionMethod.AsJob && job != null) {
                step = job.addStep(stepName, description);
                try {
                    step.setExternal(isExternal);
                    jobRepository.saveStep(step);
                } catch (Exception e) {
                    log.error("Failed to save new step '{}' for job '{}', '{}': {}", stepName.name(), job.getId(), job.getActionType().name(), e.getMessage());
                    log.debug("Exception", e);
                    job.getSteps().remove(step);
                    step = null;
                }
            } else {
                Step contextStep = context.getStep();
                if (context.getExecutionMethod() == ExecutionMethod.AsStep && contextStep != null) {
                    step = addSubStep(contextStep, stepName, description, Collections.emptyList());
                    step.setExternal(isExternal);
                }
            }
        } catch (Exception e) {
            log.error("Exception", e);
        }
    }
    return step;
}
Also used : Step(org.ovirt.engine.core.common.job.Step) Job(org.ovirt.engine.core.common.job.Job)

Example 39 with Step

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

the class ExecutionHandler method endJob.

/**
 * Finalizes a {@code Job} execution by a given context in which the job was performed and by the exit status of
 * the step. If the {@code Job} execution continues beyond the scope of the command, the {@code Job.isAsyncJob()}
 * should be set to {@code true}. If {@code ExecutionMethod.AsStep} is defined, the current active step can end the
 * running {@code Job} by setting the {@link ExecutionContext#shouldEndJob()} to
 * {@code true}.
 *
 * @param context
 *            The context of the execution which defines how the job should be ended
 * @param exitStatus
 *            Indicates if the execution described by the job ended successfully or not.
 */
public void endJob(ExecutionContext context, boolean exitStatus) {
    if (context == null) {
        return;
    }
    Job job = context.getJob();
    try {
        if (context.isMonitored()) {
            if (context.getExecutionMethod() == ExecutionMethod.AsJob && job != null) {
                if (context.shouldEndJob() || !(job.isAsyncJob() && exitStatus)) {
                    context.setCompleted(true);
                    endJob(exitStatus, job);
                }
            } else {
                Step step = context.getStep();
                if (context.getExecutionMethod() == ExecutionMethod.AsStep && step != null) {
                    if (context.shouldEndJob()) {
                        if (job == null) {
                            job = jobRepository.getJob(step.getJobId());
                        }
                        if (job != null) {
                            context.setCompleted(true);
                            endJob(exitStatus, job);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error("Exception", e);
    }
}
Also used : Step(org.ovirt.engine.core.common.job.Step) Job(org.ovirt.engine.core.common.job.Job)

Example 40 with Step

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

the class ExecutionHandler method startFinalizingStep.

/**
 * Method should be called when finalizing the command. The execution step is being ended with success and the
 * finalization step is started.
 *
 * @param executionContext
 *            The context of the job
 * @return A created instance of the Finalizing step
 */
public Step startFinalizingStep(ExecutionContext executionContext) {
    if (executionContext == null) {
        return null;
    }
    Step step = null;
    try {
        if (executionContext.getExecutionMethod() == ExecutionMethod.AsJob) {
            Job job = executionContext.getJob();
            if (job != null) {
                Step executingStep = job.getStep(StepEnum.EXECUTING);
                Step finalizingStep = job.addStep(StepEnum.FINALIZING, ExecutionMessageDirector.getInstance().getStepMessage(StepEnum.FINALIZING));
                if (executingStep != null) {
                    executingStep.markStepEnded(true);
                    jobRepository.updateExistingStepAndSaveNewStep(executingStep, finalizingStep);
                } else {
                    jobRepository.saveStep(finalizingStep);
                }
            }
        } else if (executionContext.getExecutionMethod() == ExecutionMethod.AsStep) {
            Step parentStep = executionContext.getStep();
            if (parentStep != null) {
                Step executingStep = parentStep.getStep(StepEnum.EXECUTING);
                Step finalizingStep = parentStep.addStep(StepEnum.FINALIZING, ExecutionMessageDirector.getInstance().getStepMessage(StepEnum.FINALIZING));
                if (executingStep != null) {
                    executingStep.markStepEnded(true);
                    jobRepository.updateExistingStepAndSaveNewStep(executingStep, finalizingStep);
                } else {
                    jobRepository.saveStep(finalizingStep);
                }
            }
        }
    } catch (Exception e) {
        log.error("Exception", e);
    }
    return step;
}
Also used : Step(org.ovirt.engine.core.common.job.Step) Job(org.ovirt.engine.core.common.job.Job)

Aggregations

Step (org.ovirt.engine.core.common.job.Step)52 ExecutionContext (org.ovirt.engine.core.bll.job.ExecutionContext)14 Guid (org.ovirt.engine.core.compat.Guid)12 HashMap (java.util.HashMap)8 Job (org.ovirt.engine.core.common.job.Job)8 Date (java.util.Date)7 Test (org.junit.Test)6 CommandContext (org.ovirt.engine.core.bll.context.CommandContext)6 ArrayList (java.util.ArrayList)5 JobExecutionStatus (org.ovirt.engine.core.common.job.JobExecutionStatus)5 List (java.util.List)4 VdcObjectType (org.ovirt.engine.core.common.VdcObjectType)4 GlusterAsyncTask (org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask)4 StepSubjectEntity (org.ovirt.engine.core.common.job.StepSubjectEntity)4 Map (java.util.Map)3 StepEnum (org.ovirt.engine.core.common.job.StepEnum)3 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Inject (javax.inject.Inject)2