Search in sources :

Example 1 with ActivityPath

use of com.evolveum.midpoint.schema.util.task.ActivityPath in project midpoint by Evolveum.

the class TestValidityRecomputeTaskPartitionedMultipleTasks method assertLastScanTimestamp.

@Override
protected void assertLastScanTimestamp(XMLGregorianCalendar startCal, XMLGregorianCalendar endCal) throws ObjectNotFoundException, SchemaException {
    OperationResult result = getTestOperationResult();
    Task master = taskManager.getTaskPlain(TASK_VALIDITY_SCANNER_OID, result);
    for (Task subtask : master.listSubtasks(result)) {
        ActivityPath localRootPath = ActivityStateUtil.getLocalRootPath(subtask.getActivitiesStateOrClone());
        assertTask(subtask.getOid(), "").activityState(localRootPath).display().itemProcessingStatistics().display().end().end().assertLastScanTimestamp(localRootPath, startCal, endCal);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ActivityPath(com.evolveum.midpoint.schema.util.task.ActivityPath)

Example 2 with ActivityPath

use of com.evolveum.midpoint.schema.util.task.ActivityPath in project midpoint by Evolveum.

the class TestWorkerTasks method test150ChangeClusterNode.

/**
 * Checks if worker tasks are correctly treated when cluster node is changed (brought down + another node starts).
 *
 * Scenario:
 *
 * 1. Cluster has DefaultNode + NodeA. Then two worker tasks are created and started on each node.
 * 2. NodeA is removed from cluster and NodeB is added.
 * 3. Workers reconciliation is started, suspending tasks on NodeA and starting two worker tasks to NodeB.
 */
@Test
public void test150ChangeClusterNode() throws Exception {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    assumeExtraClusterNodes(List.of("NodeA"), result);
    when("starting worker tasks");
    Task root = taskAdd(TASK_150_WORKERS_MOVE, result);
    try {
        waitForChildrenBeRunning(root, 4, result);
        then("starting worker tasks");
        String w1correct = "Worker DefaultNode:1 for root activity in task-150";
        String w2correct = "Worker DefaultNode:2 for root activity in task-150";
        String w3nodeA = "Worker NodeA:1 for root activity in task-150";
        String w4nodeA = "Worker NodeA:2 for root activity in task-150";
        String w3nodeB = "Worker NodeB:1 for root activity in task-150";
        String w4nodeB = "Worker NodeB:2 for root activity in task-150";
        assertFourWorkers(root, "after starting workers", w1correct, w2correct, w3nodeA, w4nodeA, true, false, true, false, DN, DN, NA, NA, 4, result);
        // ---------------------------------------------------------------------------------------- reconfigure cluster
        when("reconfigure cluster");
        assumeExtraClusterNodes(List.of("NodeB"), result);
        // ---------------------------------------------------------------------------------------- reconcile workers
        when("reconcile workers");
        Map<ActivityPath, WorkersReconciliationResultType> resultMap = activityManager.reconcileWorkers(root.getOid(), result);
        then("reconcile workers");
        waitForChildrenBeRunning(root, 4, result);
        then("children are running");
        var asserter = assertFourWorkers(root, "after reconciliation", w1correct, w2correct, w3nodeB, w4nodeB, true, false, true, false, DN, DN, NB, NB, 6, result);
        then("four workers present, two suspended");
        assertTwoWorkersSuspended(asserter, w3nodeA, w4nodeA, true, false, NA, NA);
        then("reconciliation");
        assertReconResult("after reconciliation", resultMap, 2, 0, 0, 2, 2, 0);
    } finally {
        taskManager.suspendTaskTree(root.getOid(), TaskManager.WAIT_INDEFINITELY, result);
        taskManager.deleteTaskTree(root.getOid(), result);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ActivityPath(com.evolveum.midpoint.schema.util.task.ActivityPath) Test(org.testng.annotations.Test) AbstractRepoCommonTest(com.evolveum.midpoint.repo.common.AbstractRepoCommonTest)

Example 3 with ActivityPath

use of com.evolveum.midpoint.schema.util.task.ActivityPath in project midpoint by Evolveum.

the class TestWorkerTasks method test160AddAndDeleteWorkerTasks.

/**
 * Checks if worker tasks are correctly created, suspended, and re-started by the reconciliation.
 *
 * Scenario:
 *
 * 1. Cluster has DefaultNode. Then two worker tasks are created and started on that node.
 * 2. NodeA is added.
 * 3. Workers reconciliation is started, adding two worker tasks for NodeA.
 * 4. NodeA is removed.
 * 5. Workers reconciliation is started, suspending two worker tasks for NodeA.
 * 6. NodeA is re-added.
 * 7. Workers reconciliation is started, starting two worker tasks for NodeA again.
 */
@Test
public void test160AddAndDeleteWorkerTasks() throws Exception {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    assumeNoExtraClusterNodes(result);
    when("starting worker tasks");
    Task root = taskAdd(TASK_160_WORKERS_ADD_DELETE, result);
    try {
        waitForChildrenBeRunning(root, 2, result);
        then("starting worker tasks");
        String w1default = "Worker DefaultNode:1 for root activity in task-160";
        String w2default = "Worker DefaultNode:2 for root activity in task-160";
        assertTwoWorkers(root, "after starting workers", w1default, w2default, true, false, DN, DN, 2, result);
        // ---------------------------------------------------------------------------------------- add node A
        when("add node A");
        assumeExtraClusterNodes(List.of("NodeA"), result);
        // ---------------------------------------------------------------------------------------- reconcile workers
        when("reconcile workers");
        Map<ActivityPath, WorkersReconciliationResultType> resultMap1 = activityManager.reconcileWorkers(root.getOid(), result);
        then("reconcile workers");
        waitForChildrenBeRunning(root, 4, result);
        String w3nodeA = "Worker NodeA:1 for root activity in task-160";
        String w4nodeA = "Worker NodeA:2 for root activity in task-160";
        assertFourWorkers(root, "after reconciliation", w1default, w2default, w3nodeA, w4nodeA, true, false, true, false, DN, DN, NA, NA, 4, result);
        assertReconResult("after reconciliation 1", resultMap1, 2, 0, 0, 0, 2, 0);
        // ---------------------------------------------------------------------------------------- delete node A
        when("delete node A");
        assumeNoExtraClusterNodes(result);
        // ---------------------------------------------------------------------------------------- reconcile workers 2
        when("reconcile workers 2");
        Map<ActivityPath, WorkersReconciliationResultType> resultMap2 = activityManager.reconcileWorkers(root.getOid(), result);
        then("reconcile workers 2");
        var asserter = assertTwoWorkers(root, "after reconciliation 2", w1default, w2default, true, false, DN, DN, 4, result);
        assertTwoWorkersSuspended(asserter, w3nodeA, w4nodeA, true, false, NA, NA);
        assertReconResult("after reconciliation 2", resultMap2, 2, 0, 0, 2, 0, 0);
        // ---------------------------------------------------------------------------------------- re-add node A
        when("re-add node A");
        assumeExtraClusterNodes(List.of("NodeA"), result);
        // ---------------------------------------------------------------------------------------- reconcile workers 3
        when("reconcile workers 3");
        Map<ActivityPath, WorkersReconciliationResultType> resultMap3 = activityManager.reconcileWorkers(root.getOid(), result);
        then("reconcile workers 3");
        waitForChildrenBeRunning(root, 4, result);
        assertFourWorkers(root, "after reconciliation", w1default, w2default, w3nodeA, w4nodeA, true, false, true, false, DN, DN, NA, NA, 4, result);
        assertReconResult("after reconciliation 3", resultMap3, 4, 0, 0, 0, 0, 2);
    } finally {
        taskManager.suspendTaskTree(root.getOid(), TaskManager.WAIT_INDEFINITELY, result);
        taskManager.deleteTaskTree(root.getOid(), result);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ActivityPath(com.evolveum.midpoint.schema.util.task.ActivityPath) Test(org.testng.annotations.Test) AbstractRepoCommonTest(com.evolveum.midpoint.repo.common.AbstractRepoCommonTest)

Example 4 with ActivityPath

use of com.evolveum.midpoint.schema.util.task.ActivityPath in project midpoint by Evolveum.

the class DelegatingActivityRun method createSuspendedChildTask.

private Task createSuspendedChildTask(OperationResult result) throws ActivityRunException {
    try {
        RunningTask parent = getRunningTask();
        TaskType childToCreate = new TaskType(getPrismContext());
        childToCreate.setName(PolyStringType.fromOrig(getChildTaskName(parent)));
        // group?
        childToCreate.setExecutionState(TaskExecutionStateType.SUSPENDED);
        childToCreate.setSchedulingState(TaskSchedulingStateType.SUSPENDED);
        childToCreate.setOwnerRef(CloneUtil.clone(parent.getOwnerRef()));
        childToCreate.setParent(parent.getTaskIdentifier());
        childToCreate.setExecutionEnvironment(CloneUtil.clone(parent.getExecutionEnvironment()));
        ActivityPath localRoot = getActivityPath();
        childToCreate.beginActivityState().localRoot(localRoot.toBean()).taskRole(TaskRoleType.DELEGATE);
        LOGGER.debug("Creating activity subtask {} with local root {}", childToCreate.getName(), localRoot);
        String childOid = getBeans().taskManager.addTask(childToCreate.asPrismObject(), result);
        LOGGER.debug("Created activity subtask {}: {}", childToCreate.getName(), childOid);
        // TODO eliminate this extra read some day
        return getBeans().taskManager.getTaskPlain(childOid, result);
    } catch (Exception e) {
        throw new ActivityRunException("Couldn't create activity child task", FATAL_ERROR, PERMANENT_ERROR, e);
    }
}
Also used : RunningTask(com.evolveum.midpoint.task.api.RunningTask) ActivityPath(com.evolveum.midpoint.schema.util.task.ActivityPath) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 5 with ActivityPath

use of com.evolveum.midpoint.schema.util.task.ActivityPath in project midpoint by Evolveum.

the class ActivityState method getActivityStateDownwards.

@NotNull
private static ActivityState getActivityStateDownwards(@NotNull ActivityPath activityPath, @NotNull Task task, @NotNull QName workStateTypeName, int level, @NotNull CommonTaskBeans beans, OperationResult result) throws SchemaException, ObjectNotFoundException {
    TaskActivityStateType taskActivityState = getTaskActivityStateRequired(task);
    if (level >= MAX_TREE_DEPTH) {
        throw new IllegalStateException("Maximum tree depth reached while looking for activity state in " + task);
    }
    ActivityPath localRootPath = ActivityStateUtil.getLocalRootPath(taskActivityState);
    stateCheck(activityPath.startsWith(localRootPath), "Activity (%s) is not within the local tree (%s)", activityPath, localRootPath);
    ActivityStateType currentWorkState = taskActivityState.getActivity();
    ItemPath currentWorkStatePath = ItemPath.create(TaskType.F_ACTIVITY_STATE, TaskActivityStateType.F_ACTIVITY);
    List<String> localIdentifiers = activityPath.getIdentifiers().subList(localRootPath.size(), activityPath.size());
    for (String identifier : localIdentifiers) {
        stateCheck(currentWorkState != null, "Current work state is not present; path = %s", currentWorkStatePath);
        currentWorkState = ActivityStateUtil.findChildActivityStateRequired(currentWorkState, identifier);
        stateCheck(currentWorkState.getId() != null, "Activity work state without ID: %s", currentWorkState);
        currentWorkStatePath = currentWorkStatePath.append(ActivityStateType.F_ACTIVITY, currentWorkState.getId());
        if (currentWorkState.getWorkState() instanceof DelegationWorkStateType) {
            ObjectReferenceType childRef = ((DelegationWorkStateType) currentWorkState.getWorkState()).getTaskRef();
            Task child = beans.taskManager.getTaskPlain(childRef.getOid(), result);
            return getActivityStateDownwards(activityPath, child, workStateTypeName, level + 1, beans, result);
        }
    }
    LOGGER.trace(" -> resulting work state path: {}", currentWorkStatePath);
    return new OtherActivityState(task, taskActivityState, activityPath, workStateTypeName, beans);
}
Also used : RunningTask(com.evolveum.midpoint.task.api.RunningTask) Task(com.evolveum.midpoint.task.api.Task) ActivityPath(com.evolveum.midpoint.schema.util.task.ActivityPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ActivityPath (com.evolveum.midpoint.schema.util.task.ActivityPath)9 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 Task (com.evolveum.midpoint.task.api.Task)5 AbstractRepoCommonTest (com.evolveum.midpoint.repo.common.AbstractRepoCommonTest)3 NotNull (org.jetbrains.annotations.NotNull)3 Test (org.testng.annotations.Test)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 RunningTask (com.evolveum.midpoint.task.api.RunningTask)2 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 ModifyObjectResult (com.evolveum.midpoint.repo.api.ModifyObjectResult)1 CommonTaskBeans (com.evolveum.midpoint.repo.common.activity.run.CommonTaskBeans)1 ActivityBucketManagementStatistics (com.evolveum.midpoint.repo.common.activity.run.state.ActivityBucketManagementStatistics)1 ActivityStateUtil (com.evolveum.midpoint.schema.util.task.ActivityStateUtil)1 BucketingUtil (com.evolveum.midpoint.schema.util.task.BucketingUtil)1 BucketingConstants (com.evolveum.midpoint.schema.util.task.work.BucketingConstants)1 DebugUtil (com.evolveum.midpoint.util.DebugUtil)1 CommonException (com.evolveum.midpoint.util.exception.CommonException)1 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)1