Search in sources :

Example 1 with RunningLightweightTask

use of com.evolveum.midpoint.task.api.RunningLightweightTask in project midpoint by Evolveum.

the class ProcessingCoordinator method createWorkerThreads.

public void createWorkerThreads() {
    if (threadsCount == 0) {
        return;
    }
    assert workerSpecificResults != null;
    // remove subtasks that could have been created previously
    coordinatorTask.deleteLightweightAsynchronousSubtasks();
    for (int i = 0; i < threadsCount; i++) {
        // we intentionally do not put worker specific result under main operation result until the handler is done
        // (because of concurrency issues - adding subresults vs e.g. putting main result into the task)
        OperationResult workerSpecificResult = new OperationResult(OP_HANDLE_ASYNCHRONOUSLY);
        workerSpecificResult.addContext("subtaskIndex", i + 1);
        workerSpecificResults.add(workerSpecificResult);
        RunningLightweightTask subtask = coordinatorTask.createSubtask(new WorkerHandler(workerSpecificResult));
        subtask.setCategory(coordinatorTask.getCategory());
        subtask.setResult(new OperationResult(OP_EXECUTE_WORKER, OperationResultStatus.IN_PROGRESS, (String) null));
        subtask.setName("Worker thread " + (i + 1) + " of " + threadsCount);
        subtask.setExecutionEnvironment(CloneUtil.clone(coordinatorTask.getExecutionEnvironment()));
        subtask.startLightweightHandler();
        LOGGER.trace("Worker subtask {} created", subtask);
    }
}
Also used : RunningLightweightTask(com.evolveum.midpoint.task.api.RunningLightweightTask) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 2 with RunningLightweightTask

use of com.evolveum.midpoint.task.api.RunningLightweightTask in project midpoint by Evolveum.

the class TestTaskManagerBasic method test260LightweightSubtasksSuspension.

@Test
public void test260LightweightSubtasksSuspension() throws Exception {
    given();
    OperationResult result = createOperationResult();
    when();
    add(TASK_WITH_THREADS_TO_SUSPEND, result);
    waitForTaskStart(TASK_WITH_THREADS_TO_SUSPEND.oid, result, 15000, 500);
    TaskQuartzImpl task = getTaskWithResult(TASK_WITH_THREADS_TO_SUSPEND.oid, result);
    displayDumpable("taskAfterStart", task);
    // assertEquals(TaskExecutionStateType.RUNNING, task.getExecutionState()); // todo
    assertEquals(TaskSchedulingStateType.READY, task.getSchedulingState());
    // check the thread
    JobExecutionContext found = findJobForTask(task);
    JobExecutor executor = (JobExecutor) found.getJobInstance();
    assertNotNull("No job executor", executor);
    Thread thread = executor.getExecutingThread();
    assertNotNull("No executing thread", thread);
    // now let us suspend it - the handler should stop, as well as the subtasks
    boolean stopped = taskManager.suspendTask(task, 10000L, result);
    then();
    task.refresh(result);
    assertTrue("Task is not stopped", stopped);
    assertSuspended(task);
    Collection<? extends RunningLightweightTask> subtasks = mockParallelTaskHandler.getLastTaskExecuted().getLightweightAsynchronousSubtasks();
    assertEquals("Wrong number of subtasks", MockParallelTaskHandler.NUM_SUBTASKS, subtasks.size());
    for (RunningLightweightTask subtask : subtasks) {
        assertEquals("Wrong subtask state", TaskExecutionStateType.CLOSED, subtask.getExecutionState());
        MockParallelTaskHandler.MyLightweightTaskHandler handler = (MockParallelTaskHandler.MyLightweightTaskHandler) subtask.getLightweightTaskHandler();
        assertTrue("Handler has not run", handler.hasRun());
        assertTrue("Handler has not exited", handler.hasExited());
    }
}
Also used : JobExecutor(com.evolveum.midpoint.task.quartzimpl.run.JobExecutor) RunningLightweightTask(com.evolveum.midpoint.task.api.RunningLightweightTask) JobExecutionContext(org.quartz.JobExecutionContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 3 with RunningLightweightTask

use of com.evolveum.midpoint.task.api.RunningLightweightTask in project midpoint by Evolveum.

the class TestTaskManagerBasic method test250TaskWithThreads.

/**
 * Tests task with lightweight subtasks.
 */
@Test
public void test250TaskWithThreads() throws Exception {
    given();
    OperationResult result = createOperationResult();
    when();
    add(TASK_WITH_THREADS, result);
    checkTreadSafety(TASK_WITH_THREADS.oid, 1000L, result);
    waitUntilDone(TASK_WITH_THREADS.oid, result, 15000, 100);
    waitForTaskClose(TASK_WITH_THREADS.oid, result, 15000, 100);
    then();
    Task task = getTaskWithResult(TASK_WITH_THREADS.oid, result);
    displayDumpable("Task after", task);
    Collection<? extends RunningLightweightTask> subtasks = mockParallelTaskHandler.getLastTaskExecuted().getLightweightAsynchronousSubtasks();
    assertEquals("Wrong number of subtasks", MockParallelTaskHandler.NUM_SUBTASKS, subtasks.size());
    for (RunningLightweightTask subtask : subtasks) {
        assertEquals("Wrong subtask state", TaskExecutionStateType.CLOSED, subtask.getExecutionState());
        MockParallelTaskHandler.MyLightweightTaskHandler handler = (MockParallelTaskHandler.MyLightweightTaskHandler) subtask.getLightweightTaskHandler();
        assertTrue("Handler has not run in " + subtask, handler.hasRun());
        assertTrue("Handler has not exited in " + subtask, handler.hasExited());
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RunningLightweightTask(com.evolveum.midpoint.task.api.RunningLightweightTask) RunningLightweightTask(com.evolveum.midpoint.task.api.RunningLightweightTask) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 RunningLightweightTask (com.evolveum.midpoint.task.api.RunningLightweightTask)3 Test (org.testng.annotations.Test)2 Task (com.evolveum.midpoint.task.api.Task)1 JobExecutor (com.evolveum.midpoint.task.quartzimpl.run.JobExecutor)1 JobExecutionContext (org.quartz.JobExecutionContext)1