Search in sources :

Example 1 with WorkBucketType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketType in project midpoint by Evolveum.

the class RepoConcurrencyTest method test150WorkBucketsReplace.

/**
 * Here we test concurrent work bucket delegation using
 * {@link RepositoryService#modifyObjectDynamically(Class, String, Collection, ModificationsSupplier, RepoModifyOptions, OperationResult)}
 * method.
 */
@Test
public void test150WorkBucketsReplace() throws Exception {
    int THREADS = 8;
    long DURATION = 30_000L;
    TaskType task = new TaskType(prismContext).name("test150").beginActivityState().beginActivity().beginBucketing().bucketsProcessingRole(BucketsProcessingRoleType.COORDINATOR).<ActivityStateType>end().<TaskActivityStateType>end().end();
    OperationResult result = new OperationResult("test150WorkBucketsReplace");
    String oid = plainRepositoryService.addObject(task.asPrismObject(), null, result);
    displayValue("object added", oid);
    logger.info("Starting worker threads");
    List<WorkerThread> threads = new ArrayList<>();
    for (int i = 0; i < THREADS; i++) {
        final int threadIndex = i;
        WorkerThread thread = new WorkerThread(i) {

            @Override
            void runOnce(OperationResult result) throws Exception {
                ModificationsSupplier<TaskType> modificationSupplier = task -> prismContext.deltaFor(TaskType.class).item(TaskType.F_ACTIVITY_STATE, F_ACTIVITY, F_BUCKETING, F_BUCKET).replaceRealValues(getBucketsToReplace(task)).asItemDeltas();
                plainRepositoryService.modifyObjectDynamically(TaskType.class, oid, null, modificationSupplier, null, result);
            }

            private List<WorkBucketType> getBucketsToReplace(TaskType task) {
                List<WorkBucketType> currentBuckets = getCurrentBuckets(task);
                List<WorkBucketType> newBuckets = CloneUtil.cloneCollectionMembers(currentBuckets);
                newBuckets.add(getNextBucket(currentBuckets));
                return newBuckets;
            }

            private WorkBucketType getNextBucket(List<WorkBucketType> currentBuckets) {
                return new WorkBucketType(prismContext).sequentialNumber(getLastBucketNumber(currentBuckets) + 1).state(WorkBucketStateType.DELEGATED).workerRef(String.valueOf(threadIndex), TaskType.COMPLEX_TYPE);
            }

            private List<WorkBucketType> getCurrentBuckets(TaskType task) {
                return task.getActivityState().getActivity().getBucketing().getBucket();
            }

            private int getLastBucketNumber(List<WorkBucketType> buckets) {
                return buckets.stream().mapToInt(WorkBucketType::getSequentialNumber).max().orElse(0);
            }

            @Override
            String description() {
                return "Bucket computer thread #" + threadIndex;
            }
        };
        thread.start();
        threads.add(thread);
    }
    waitForThreads(threads, DURATION);
    PrismObject<TaskType> taskAfter = plainRepositoryService.getObject(TaskType.class, oid, null, result);
    displayValue("task after", taskAfter);
    assertCorrectBucketSequence(taskAfter.asObjectable().getActivityState().getActivity().getBucketing().getBucket());
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.testng.annotations.Test) F_BUCKET(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivityBucketingStateType.F_BUCKET) DebugUtil(com.evolveum.midpoint.util.DebugUtil) ModificationsSupplier(com.evolveum.midpoint.repo.api.RepositoryService.ModificationsSupplier) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) SupportedDatabase(com.evolveum.midpoint.repo.sqlbase.SupportedDatabase) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JdbcRepositoryConfiguration(com.evolveum.midpoint.repo.sqlbase.JdbcRepositoryConfiguration) SqlRepoTestUtil(com.evolveum.midpoint.repo.sql.testing.SqlRepoTestUtil) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) CloneUtil(com.evolveum.midpoint.prism.util.CloneUtil) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) XmlTypeConverter(com.evolveum.midpoint.prism.xml.XmlTypeConverter) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Collection(java.util.Collection) F_BUCKETING(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivityStateType.F_BUCKETING) Collectors(java.util.stream.Collectors) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) List(java.util.List) RepoModifyOptions(com.evolveum.midpoint.repo.api.RepoModifyOptions) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ContextConfiguration(org.springframework.test.context.ContextConfiguration) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) F_ACTIVITY(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivityStateType.F_ACTIVITY) QName(javax.xml.namespace.QName) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ArrayList(java.util.ArrayList) List(java.util.List) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) Test(org.testng.annotations.Test)

Example 2 with WorkBucketType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketType in project midpoint by Evolveum.

the class RepoConcurrencyTest method test140WorkBucketsAdd.

/**
 * Here we test concurrent work bucket creation using
 * {@link RepositoryService#modifyObjectDynamically(Class, String, Collection, ModificationsSupplier, RepoModifyOptions, OperationResult)}
 * method.
 */
@Test
public void test140WorkBucketsAdd() throws Exception {
    int THREADS = 8;
    long DURATION = 30_000L;
    TaskType task = new TaskType(prismContext).name("test140").beginActivityState().beginActivity().beginBucketing().bucketsProcessingRole(BucketsProcessingRoleType.COORDINATOR).<ActivityStateType>end().<TaskActivityStateType>end().end();
    OperationResult result = new OperationResult("test140WorkBucketsAdd");
    String oid = plainRepositoryService.addObject(task.asPrismObject(), null, result);
    displayValue("object added", oid);
    logger.info("Starting worker threads");
    List<WorkerThread> threads = new ArrayList<>();
    for (int i = 0; i < THREADS; i++) {
        final int threadIndex = i;
        WorkerThread thread = new WorkerThread(i) {

            @Override
            void runOnce(OperationResult result) throws Exception {
                ModificationsSupplier<TaskType> modificationSupplier = task -> prismContext.deltaFor(TaskType.class).item(TaskType.F_ACTIVITY_STATE, F_ACTIVITY, F_BUCKETING, F_BUCKET).add(getNextBucket(task)).asItemDeltas();
                plainRepositoryService.modifyObjectDynamically(TaskType.class, oid, null, modificationSupplier, null, result);
            }

            private WorkBucketType getNextBucket(TaskType task) {
                int lastBucketNumber = task.getActivityState() != null ? getLastBucketNumber(task.getActivityState().getActivity().getBucketing().getBucket()) : 0;
                return new WorkBucketType(prismContext).sequentialNumber(lastBucketNumber + 1).state(WorkBucketStateType.DELEGATED).workerRef(String.valueOf(threadIndex), TaskType.COMPLEX_TYPE);
            }

            private int getLastBucketNumber(List<WorkBucketType> buckets) {
                return buckets.stream().mapToInt(WorkBucketType::getSequentialNumber).max().orElse(0);
            }

            @Override
            String description() {
                return "Bucket computer thread #" + threadIndex;
            }
        };
        thread.start();
        threads.add(thread);
    }
    waitForThreads(threads, DURATION);
    PrismObject<TaskType> taskAfter = plainRepositoryService.getObject(TaskType.class, oid, null, result);
    displayValue("task after", taskAfter);
    assertCorrectBucketSequence(taskAfter.asObjectable().getActivityState().getActivity().getBucketing().getBucket());
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.testng.annotations.Test) F_BUCKET(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivityBucketingStateType.F_BUCKET) DebugUtil(com.evolveum.midpoint.util.DebugUtil) ModificationsSupplier(com.evolveum.midpoint.repo.api.RepositoryService.ModificationsSupplier) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) SupportedDatabase(com.evolveum.midpoint.repo.sqlbase.SupportedDatabase) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JdbcRepositoryConfiguration(com.evolveum.midpoint.repo.sqlbase.JdbcRepositoryConfiguration) SqlRepoTestUtil(com.evolveum.midpoint.repo.sql.testing.SqlRepoTestUtil) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) CloneUtil(com.evolveum.midpoint.prism.util.CloneUtil) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) XmlTypeConverter(com.evolveum.midpoint.prism.xml.XmlTypeConverter) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Collection(java.util.Collection) F_BUCKETING(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivityStateType.F_BUCKETING) Collectors(java.util.stream.Collectors) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) List(java.util.List) RepoModifyOptions(com.evolveum.midpoint.repo.api.RepoModifyOptions) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ContextConfiguration(org.springframework.test.context.ContextConfiguration) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) F_ACTIVITY(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivityStateType.F_ACTIVITY) QName(javax.xml.namespace.QName) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ArrayList(java.util.ArrayList) List(java.util.List) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) Test(org.testng.annotations.Test)

Example 3 with WorkBucketType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketType in project midpoint by Evolveum.

the class TestBucketingStatic method test210GetReleaseCompleteSequenceForWorkers.

/**
 * Check a sequence of get / release / complete operations on coordinator + 5 worker tasks.
 */
@Test
public void test210GetReleaseCompleteSequenceForWorkers() throws Exception {
    OperationResult result = createOperationResult();
    // suspended
    taskAdd(TASK_210_COORDINATOR, result);
    // suspended
    taskAdd(TASK_210_WORKER_1, result);
    // suspended
    taskAdd(TASK_210_WORKER_2, result);
    // suspended
    taskAdd(TASK_210_WORKER_3, result);
    // suspended
    taskAdd(TASK_210_WORKER_4, result);
    // suspended
    taskAdd(TASK_210_WORKER_5, result);
    Task coordinator = taskManager.getTaskPlain(TASK_210_COORDINATOR.oid, result);
    String oidC = TASK_210_COORDINATOR.oid;
    String oidW1 = TASK_210_WORKER_1.oid;
    String oidW2 = TASK_210_WORKER_2.oid;
    String oidW3 = TASK_210_WORKER_3.oid;
    String oidW4 = TASK_210_WORKER_4.oid;
    String oidW5 = TASK_210_WORKER_5.oid;
    when();
    WorkBucketType bucket1 = getWorkBucket(coordinator, oidW1, result);
    WorkBucketType bucket2 = getWorkBucket(coordinator, oidW2, result);
    WorkBucketType bucket3 = getWorkBucket(coordinator, oidW3, result);
    WorkBucketType bucket4 = getWorkBucket(coordinator, oidW4, result);
    // should be the same as bucket4 (the same worker)
    WorkBucketType bucket4a = getWorkBucket(coordinator, oidW4, result);
    then();
    displayValue("1st allocated bucket", bucket1);
    displayValue("2nd allocated bucket", bucket2);
    displayValue("3rd allocated bucket", bucket3);
    displayValue("4th allocated bucket", bucket4);
    displayValue("4+th allocated bucket", bucket4a);
    coordinator.refresh(result);
    displayDumpable("coordinator task after 4+1x allocation", coordinator);
    assertNumericBucket(bucket1, null, 1, 0, 1);
    assertNumericBucket(bucket2, null, 2, 1, 2);
    assertNumericBucket(bucket3, null, 3, 2, 3);
    assertNumericBucket(bucket4, null, 4, 3, 4);
    assertNumericBucket(bucket4a, null, 4, 3, 4);
    List<WorkBucketType> buckets = new ArrayList<>(getBuckets(coordinator));
    sortBucketsBySequentialNumber(buckets);
    assertEquals(4, buckets.size());
    assertNumericBucket(buckets.get(0), WorkBucketStateType.DELEGATED, 1, 0, 1);
    assertNumericBucket(buckets.get(1), WorkBucketStateType.DELEGATED, 2, 1, 2);
    assertNumericBucket(buckets.get(2), WorkBucketStateType.DELEGATED, 3, 2, 3);
    assertNumericBucket(buckets.get(3), WorkBucketStateType.DELEGATED, 4, 3, 4);
    when("complete bucket #2");
    bucketingManager.completeWorkBucket(oidC, oidW2, ActivityPath.empty(), 2, null, null, result);
    then("complete bucket #2");
    coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
    displayDumpable("coordinator after completion of 2nd bucket", coordinator);
    buckets = new ArrayList<>(getBuckets(coordinator));
    sortBucketsBySequentialNumber(buckets);
    assertEquals(4, buckets.size());
    assertNumericBucket(buckets.get(0), WorkBucketStateType.DELEGATED, 1, 0, 1);
    assertNumericBucket(buckets.get(1), WorkBucketStateType.COMPLETE, 2, 1, 2);
    assertNumericBucket(buckets.get(2), WorkBucketStateType.DELEGATED, 3, 2, 3);
    assertNumericBucket(buckets.get(3), WorkBucketStateType.DELEGATED, 4, 3, 4);
    when("complete bucket #1");
    bucketingManager.completeWorkBucket(oidC, oidW1, ActivityPath.empty(), 1, null, null, result);
    WorkBucketType bucket = getWorkBucket(coordinator, oidW1, result);
    then("complete bucket #1");
    coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
    displayDumpable("coordinator after completion of 1st bucket and fetching next one", coordinator);
    assertNumericBucket(bucket, null, 5, 4, 5);
    buckets = new ArrayList<>(getBuckets(coordinator));
    sortBucketsBySequentialNumber(buckets);
    assertEquals(4, buckets.size());
    assertNumericBucket(buckets.get(0), WorkBucketStateType.COMPLETE, 2, 1, 2);
    assertNumericBucket(buckets.get(1), WorkBucketStateType.DELEGATED, 3, 2, 3);
    assertNumericBucket(buckets.get(2), WorkBucketStateType.DELEGATED, 4, 3, 4);
    assertNumericBucket(buckets.get(3), WorkBucketStateType.DELEGATED, 5, 4, 5);
    when("no more buckets");
    WorkBucketType nothing = getWorkBucket(coordinator, oidW5, result);
    then("no more buckets");
    assertNull("Found bucket even if none should be found", nothing);
    when("release bucket #4");
    bucketingManager.releaseWorkBucket(oidC, oidW4, ActivityPath.empty(), 4, null, result);
    then("release bucket #4");
    coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
    displayDumpable("coordinator after releasing of 4th bucket", coordinator);
    buckets = new ArrayList<>(getBuckets(coordinator));
    sortBucketsBySequentialNumber(buckets);
    assertEquals(4, buckets.size());
    assertNumericBucket(buckets.get(0), WorkBucketStateType.COMPLETE, 2, 1, 2);
    assertNumericBucket(buckets.get(1), WorkBucketStateType.DELEGATED, 3, 2, 3);
    assertNumericBucket(buckets.get(2), READY, 4, 3, 4);
    assertNumericBucket(buckets.get(3), WorkBucketStateType.DELEGATED, 5, 4, 5);
    when("complete bucket #3");
    bucketingManager.completeWorkBucket(oidC, oidW3, ActivityPath.empty(), 3, null, null, result);
    bucket = getWorkBucket(coordinator, oidW5, result);
    then("complete bucket #3");
    coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
    displayDumpable("coordinator after completion of 3rd bucket and getting next one", coordinator);
    assertNumericBucket(bucket, null, 4, 3, 4);
    buckets = new ArrayList<>(getBuckets(coordinator));
    sortBucketsBySequentialNumber(buckets);
    assertEquals(3, buckets.size());
    assertNumericBucket(buckets.get(0), WorkBucketStateType.COMPLETE, 3, 2, 3);
    assertNumericBucket(buckets.get(1), WorkBucketStateType.DELEGATED, 4, 3, 4);
    assertNumericBucket(buckets.get(2), WorkBucketStateType.DELEGATED, 5, 4, 5);
    when("complete bucket #5");
    bucketingManager.completeWorkBucket(oidC, oidW1, ActivityPath.empty(), 5, null, null, result);
    taskManager.closeTask(oidW5, result);
    then("complete bucket #5");
    coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
    displayDumpable("coordinator after completion of 5th bucket and closing worker5", coordinator);
    buckets = new ArrayList<>(getOrCreateBuckets(coordinator.getWorkState().getActivity()));
    assertEquals(2, buckets.size());
    assertNumericBucket(buckets.get(0), WorkBucketStateType.DELEGATED, 4, 3, 4);
    assertNumericBucket(buckets.get(1), WorkBucketStateType.COMPLETE, 5, 4, 5);
    when("reclaiming mis-allocated bucket");
    bucket = getWorkBucket(coordinator, oidW1, b -> b.withFreeBucketWaitTime(-1).withIsScavenger(true), result);
    assertThat(bucket).isNotNull();
    then("reclaiming mis-allocated bucket");
    coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
    displayDumpable("coordinator after reclaiming mis-allocated bucket", coordinator);
    assertNumericBucket(bucket, null, 4, 3, 4);
    buckets = new ArrayList<>(getBuckets(coordinator));
    assertEquals(2, buckets.size());
    assertNumericBucket(buckets.get(0), WorkBucketStateType.DELEGATED, 4, 3, 4);
    assertNumericBucket(buckets.get(1), WorkBucketStateType.COMPLETE, 5, 4, 5);
    when("complete bucket #4");
    bucketingManager.completeWorkBucket(oidC, oidW1, ActivityPath.empty(), 4, null, null, result);
    then("complete bucket #4");
    coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
    displayDumpable("coordinator after completion of 4th bucket", coordinator);
    buckets = new ArrayList<>(getBuckets(coordinator));
    assertEquals(1, buckets.size());
    assertNumericBucket(buckets.get(0), WorkBucketStateType.COMPLETE, 5, 4, 5);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) AssertJUnit(org.testng.AssertJUnit) Arrays(java.util.Arrays) CommonTaskBeans(com.evolveum.midpoint.repo.common.activity.run.CommonTaskBeans) ActivityPath(com.evolveum.midpoint.schema.util.task.ActivityPath) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) GetBucketOperationOptionsBuilder(com.evolveum.midpoint.repo.common.activity.run.buckets.GetBucketOperationOptions.GetBucketOperationOptionsBuilder) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) BucketingUtil(com.evolveum.midpoint.schema.util.task.BucketingUtil) DebugUtil(com.evolveum.midpoint.util.DebugUtil) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) BucketFactory(com.evolveum.midpoint.repo.common.activity.run.buckets.segmentation.BucketFactory) COMPLETE(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.COMPLETE) BucketingConfigurationOverrides(com.evolveum.midpoint.repo.common.activity.run.buckets.BucketingConfigurationOverrides) AbstractRepoCommonTest(com.evolveum.midpoint.repo.common.AbstractRepoCommonTest) PrismContext(com.evolveum.midpoint.prism.PrismContext) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ActivityDistributionDefinition(com.evolveum.midpoint.repo.common.activity.definition.ActivityDistributionDefinition) BucketingManager(com.evolveum.midpoint.repo.common.activity.run.buckets.BucketingManager) BucketContentFactory(com.evolveum.midpoint.repo.common.activity.run.buckets.segmentation.BucketContentFactory) PrismAsserts(com.evolveum.midpoint.prism.util.PrismAsserts) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) Task(com.evolveum.midpoint.task.api.Task) StringBucketContentFactory(com.evolveum.midpoint.repo.common.activity.run.buckets.segmentation.StringBucketContentFactory) File(java.io.File) Consumer(java.util.function.Consumer) List(java.util.List) TestResource(com.evolveum.midpoint.test.TestResource) READY(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.READY) ContextConfiguration(org.springframework.test.context.ContextConfiguration) PostConstruct(javax.annotation.PostConstruct) BucketingUtil.sortBucketsBySequentialNumber(com.evolveum.midpoint.schema.util.task.BucketingUtil.sortBucketsBySequentialNumber) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) NotNull(org.jetbrains.annotations.NotNull) BucketContentFactoryGenerator(com.evolveum.midpoint.repo.common.activity.run.buckets.segmentation.BucketContentFactoryGenerator) Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test) AbstractRepoCommonTest(com.evolveum.midpoint.repo.common.AbstractRepoCommonTest)

Example 4 with WorkBucketType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketType 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 5 with WorkBucketType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketType in project midpoint by Evolveum.

the class GetBucketOperationAttempt method offerExistingBuckets.

/**
 * Offers existing buckets for processing:
 *
 * - skipping first N-1 of them,
 * - giving the N-th for use,
 * - not touching the rest.
 *
 * If numberOfBucketsToGet is non-zero at exit, then all existing buckets were consumed.
 */
private void offerExistingBuckets(Stream<WorkBucketType> buckets) {
    Iterator<WorkBucketType> iterator = buckets.iterator();
    while (iterator.hasNext()) {
        WorkBucketType bucket = iterator.next();
        if (numberOfBucketsToGet == 0) {
            // leaving remaining existing buckets intact
            return;
        } else if (numberOfBucketsToGet == 1) {
            markExistingBucketToUse(bucket);
        } else {
            markExistingBucketSkipped(bucket);
        }
        numberOfBucketsToGet--;
    }
}
Also used : WorkBucketType(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketType)

Aggregations

ArrayList (java.util.ArrayList)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 DebugUtil (com.evolveum.midpoint.util.DebugUtil)4 List (java.util.List)4 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)3 File (java.io.File)3 Collection (java.util.Collection)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 NotNull (org.jetbrains.annotations.NotNull)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 DirtiesContext (org.springframework.test.annotation.DirtiesContext)3 ContextConfiguration (org.springframework.test.context.ContextConfiguration)3 Test (org.testng.annotations.Test)3 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)2 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)2 CloneUtil (com.evolveum.midpoint.prism.util.CloneUtil)2