Search in sources :

Example 6 with ActivityPath

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

the class ReleaseBucketsOperation method computeReleaseModifications.

@NotNull
private Collection<ItemDelta<?, ?>> computeReleaseModifications(@NotNull TaskType task) {
    assert workerTaskOid != null;
    List<WorkBucketType> bucketsToRelease = new ArrayList<>();
    List<WorkBucketType> currentBuckets = BucketingUtil.getBuckets(task.getActivityState(), activityPath);
    if (sequentialNumber != null) {
        WorkBucketType bucket = BucketingUtil.findBucketByNumberRequired(currentBuckets, sequentialNumber);
        checkBucketReadyOrDelegated(bucket);
        bucketsToRelease.add(bucket);
    } else {
        currentBuckets.stream().filter(b -> BucketingUtil.isDelegatedTo(b, workerTaskOid)).forEach(bucketsToRelease::add);
    }
    LOGGER.trace("Releasing buckets {} in {} (delegated to {})", bucketsToRelease, task, workerTaskOid);
    ItemPath statePath = ActivityStateUtil.getStateItemPath(task.getActivityState(), activityPath);
    return bucketsStateChangeDeltas(statePath, bucketsToRelease, WorkBucketStateType.READY, null);
}
Also used : BucketingConstants(com.evolveum.midpoint.schema.util.task.work.BucketingConstants) CommonTaskBeans(com.evolveum.midpoint.repo.common.activity.run.CommonTaskBeans) ActivityPath(com.evolveum.midpoint.schema.util.task.ActivityPath) ActivityStateUtil(com.evolveum.midpoint.schema.util.task.ActivityStateUtil) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) ActivityBucketManagementStatistics(com.evolveum.midpoint.repo.common.activity.run.state.ActivityBucketManagementStatistics) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) Trace(com.evolveum.midpoint.util.logging.Trace) BucketingUtil(com.evolveum.midpoint.schema.util.task.BucketingUtil) DebugUtil(com.evolveum.midpoint.util.DebugUtil) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) List(java.util.List) WorkBucketType(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketType) SystemException(com.evolveum.midpoint.util.exception.SystemException) ModifyObjectResult(com.evolveum.midpoint.repo.api.ModifyObjectResult) WorkBucketStateType(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType) NotNull(org.jetbrains.annotations.NotNull) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ArrayList(java.util.ArrayList) WorkBucketType(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with ActivityPath

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

the class ActivityState method getParentActivityState.

// endregion
// region Navigation
/**
 * Returns the state of the _parent activity_, e.g. operations completion sub-activity -> reconciliation activity.
 *
 * Note: the caller must know the work state type name. This can be resolved somehow in the future, e.g. by requiring
 * that the work state already exists.
 */
@NotNull
public ActivityState getParentActivityState(@NotNull QName workStateTypeName, OperationResult result) throws SchemaException, ObjectNotFoundException {
    ActivityPath activityPath = getActivityPath();
    argCheck(!activityPath.isEmpty(), "Root activity has no parent");
    return getActivityStateUpwards(activityPath.allExceptLast(), getTask(), workStateTypeName, beans, result);
}
Also used : ActivityPath(com.evolveum.midpoint.schema.util.task.ActivityPath) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with ActivityPath

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

the class NodeDownCleaner method releaseAllBucketsOfWorker.

/**
 * We don't want this task to hold its buckets forever. So let's release them.
 *
 * (There's a slight risk if the task is restarted in the meanwhile, i.e. before learning that node is down and this
 * moment. But let us live with this risk for now.)
 */
private void releaseAllBucketsOfWorker(OperationResult result) throws ObjectNotFoundException, SchemaException {
    TaskActivityStateType state = task.getActivitiesStateOrClone();
    if (state == null || state.getTaskRole() != TaskRoleType.WORKER) {
        return;
    }
    if (parent == null) {
        LOGGER.warn("No parent for worker {} (root {}) ?", task, root);
        return;
    }
    ActivityPath activityPath = ActivityPath.fromBean(Objects.requireNonNull(state.getLocalRoot(), "No local root in " + task));
    LOGGER.info("Returning all buckets from {} (coordinator {})", task, parent);
    beans.bucketingManager.releaseAllWorkBucketsFromWorker(parent.getOid(), task.getOid(), activityPath, null, result);
}
Also used : ActivityPath(com.evolveum.midpoint.schema.util.task.ActivityPath) TaskActivityStateType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskActivityStateType)

Example 9 with ActivityPath

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

the class TestWorkerTasks method test140UpdateWorkerTasks.

/**
 * Checks if worker tasks are correctly updated by the reconciliation.
 *
 * Scenario:
 *
 * 1. four worker tasks are created and started
 * 2. some workers are broken: #2 is renamed, #3 is renamed + made scavenger, #4 is made scavenger
 * 3. reconciliation is started, fixing the things
 */
@Test
public void test140UpdateWorkerTasks() throws Exception {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    assumeNoExtraClusterNodes(result);
    when("starting worker tasks");
    Task root = taskAdd(TASK_140_WORKERS_UPDATE, result);
    try {
        waitForChildrenBeRunning(root, 4, result);
        then("starting worker tasks");
        String w1correct = "Worker DefaultNode:1 for root activity in task-140";
        String w2correct = "Worker DefaultNode:2 for root activity in task-140";
        String w3correct = "Worker DefaultNode:3 for root activity in task-140";
        String w4correct = "Worker DefaultNode:4 for root activity in task-140";
        assertFourWorkers(root, "after starting worker", w1correct, w2correct, w3correct, w4correct, true, false, false, false, DN, DN, DN, DN, 4, result);
        // ---------------------------------------------------------------------------------------- rename worker explicitly
        when("change workers explicitly");
        List<? extends Task> subtasks = root.listSubtasks(result);
        assertThat(subtasks).as("subtasks").hasSize(4);
        Task w2 = findTaskByName(subtasks, w2correct);
        Task w3 = findTaskByName(subtasks, w3correct);
        Task w4 = findTaskByName(subtasks, w4correct);
        String w2broken = "Broken 2";
        String w3broken = "Broken 3";
        w2.setName(w2broken);
        w2.flushPendingModifications(result);
        w3.setName(w3broken);
        setScavenger(w3, true);
        w3.flushPendingModifications(result);
        setScavenger(w4, true);
        w4.flushPendingModifications(result);
        then("change workers explicitly");
        assertFourWorkers(root, "after changing workers", w1correct, w2broken, w3broken, w4correct, true, false, true, true, DN, DN, DN, DN, 4, result);
        // ---------------------------------------------------------------------------------------- reconcile workers
        when("reconcile workers");
        Map<ActivityPath, WorkersReconciliationResultType> resultMap = activityManager.reconcileWorkers(root.getOid(), result);
        then("reconcile workers");
        assertFourWorkers(root, "after reconciliation", w1correct, w2correct, w3correct, w4correct, true, false, false, false, DN, DN, DN, DN, 4, result);
        assertReconResult("after reconciliation", resultMap, 1, 1, 2, 0, 0, 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)

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