Search in sources :

Example 31 with Step

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

the class CoCoAsyncTaskHelper method createTask.

/**
 * Use this method in order to create task in the AsyncTaskManager in a safe way. If you use
 * this method within a certain command, make sure that the command implemented the
 * ConcreteCreateTask method.
 *
 * @param asyncTaskCreationInfo
 *            info to send to AsyncTaskManager when creating the task.
 * @param parentCommand
 *            ActionType of the command that its EndAction we want to invoke when tasks are finished.
 * @param entitiesMap
 *            Map of entities that are associated with the task
 * @return Guid of the created task.
 */
public Guid createTask(Guid taskId, CommandBase<?> command, AsyncTaskCreationInfo asyncTaskCreationInfo, ActionType parentCommand, String description, Map<Guid, VdcObjectType> entitiesMap) {
    Step taskStep = ExecutionHandler.getInstance().addTaskStep(command.getExecutionContext(), StepEnum.getStepNameByTaskType(asyncTaskCreationInfo.getTaskType()), description, command.getCommandStepSubjectEntities());
    command.getExecutionContext().setStep(taskStep);
    if (taskStep != null) {
        asyncTaskCreationInfo.setStepId(taskStep.getId());
    }
    SPMAsyncTask task = concreteCreateTask(taskId, command, asyncTaskCreationInfo, parentCommand);
    task.setEntitiesMap(entitiesMap);
    AsyncTaskUtils.addOrUpdateTaskInDB(coco.get(), task);
    asyncTaskManager.get().lockAndAddTaskToManager(task);
    Guid vdsmTaskId = task.getVdsmTaskId();
    ExecutionHandler.getInstance().updateStepExternalId(taskStep, vdsmTaskId, ExternalSystemType.VDSM);
    return vdsmTaskId;
}
Also used : Step(org.ovirt.engine.core.common.job.Step) Guid(org.ovirt.engine.core.compat.Guid)

Example 32 with Step

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

the class StepDaoTest method updateStepProgress.

@Test
public void updateStepProgress() {
    Integer newProgress = 74;
    Step s = dao.get(FixturesTool.STEP_ID);
    assertNotEquals("New progress should be different than the current", newProgress, s.getProgress());
    updateStepProgress(FixturesTool.STEP_ID, newProgress);
    s = dao.get(FixturesTool.STEP_ID);
    assertEquals("New progress should be the same as the current", newProgress, s.getProgress());
}
Also used : Step(org.ovirt.engine.core.common.job.Step) Test(org.junit.Test)

Example 33 with Step

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

the class StepDaoTest method diskNullFinishedStepProgress.

@Test
public void diskNullFinishedStepProgress() {
    Guid entityId = FixturesTool.FLOATING_DISK_ID;
    prepareProgressTest(entityId);
    List<Guid> stepIds = Arrays.asList(FixturesTool.STEP_ID, FixturesTool.STEP_ID_2);
    stepIds.forEach(x -> {
        Step s = dao.get(x);
        s.setProgress(null);
        s.setStatus(JobExecutionStatus.FINISHED);
        dao.update(s);
    });
    BaseDisk diskImage = getDiskDao().get(entityId);
    assertProgress(80, diskImage);
}
Also used : BaseDisk(org.ovirt.engine.core.common.businessentities.storage.BaseDisk) Guid(org.ovirt.engine.core.compat.Guid) Step(org.ovirt.engine.core.common.job.Step) Test(org.junit.Test)

Example 34 with Step

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

the class StepDaoTest method startedStepsByStepSubjectEntityNoStepsHaveStep.

@Test
public void startedStepsByStepSubjectEntityNoStepsHaveStep() {
    StepSubjectEntity subjectEntity = prepareStartedStepsByStepSubjectEntityTest();
    List<Step> steps = dao.getStartedStepsByStepSubjectEntity(subjectEntity);
    assertEquals(1, steps.size());
    assertEquals(subjectEntity.getStepId(), steps.get(0).getId());
}
Also used : Step(org.ovirt.engine.core.common.job.Step) StepSubjectEntity(org.ovirt.engine.core.common.job.StepSubjectEntity) Test(org.junit.Test)

Example 35 with Step

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

the class StepDaoTest method prepareStartedStepsByStepSubjectEntityTest.

private StepSubjectEntity prepareStartedStepsByStepSubjectEntityTest() {
    Guid entityId = Guid.newGuid();
    VdcObjectType entityType = VdcObjectType.EXECUTION_HOST;
    StepSubjectEntity subjectEntity = new StepSubjectEntity(FixturesTool.STEP_ID, entityType, entityId);
    getStepSubjectEntityDao().saveAll(Arrays.asList(subjectEntity));
    Step s = dao.get(FixturesTool.STEP_ID);
    s.setStatus(JobExecutionStatus.STARTED);
    dao.update(s);
    return subjectEntity;
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) Step(org.ovirt.engine.core.common.job.Step) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) StepSubjectEntity(org.ovirt.engine.core.common.job.StepSubjectEntity)

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