From 98d20d2766bd53cfd0442fdee53466a6fd9299fd Mon Sep 17 00:00:00 2001 From: Katarina Valalikova Date: Wed, 10 Apr 2019 11:10:35 +0200 Subject: [PATCH] fix for MID-5211 --- .../AbstractSearchIterativeResultHandler.java | 3 - .../quartzimpl/execution/JobExecutor.java | 93 ------------------- .../LightweightPartitioningTaskHandler.java | 43 +++++++-- .../quartzimpl/work/WorkStateManager.java | 6 +- .../testing/story/TestThresholds.java | 5 +- .../story/TestThresholdsLiveSyncFull.java | 2 +- .../story/TestThresholdsLiveSyncSimulate.java | 2 +- .../story/TestThresholdsReconFull.java | 77 ++++++++++++++- .../story/TestThresholdsReconSimulate.java | 2 +- .../thresholds/role-policy-rule-delete.xml | 41 ++++++++ ...task-opendj-reconcile-simulate-execute.xml | 69 ++++++++++++++ 11 files changed, 226 insertions(+), 117 deletions(-) create mode 100644 testing/story/src/test/resources/thresholds/role-policy-rule-delete.xml create mode 100644 testing/story/src/test/resources/thresholds/task-opendj-reconcile-simulate-execute.xml diff --git a/repo/repo-common/src/main/java/com/evolveum/midpoint/repo/common/task/AbstractSearchIterativeResultHandler.java b/repo/repo-common/src/main/java/com/evolveum/midpoint/repo/common/task/AbstractSearchIterativeResultHandler.java index 2ee0f0c3273..3d307c8b38b 100644 --- a/repo/repo-common/src/main/java/com/evolveum/midpoint/repo/common/task/AbstractSearchIterativeResultHandler.java +++ b/repo/repo-common/src/main/java/com/evolveum/midpoint/repo/common/task/AbstractSearchIterativeResultHandler.java @@ -350,8 +350,6 @@ private void processRequest(ProcessingRequest request, RunningTask workerTask, O // The meat cont = handleObject(object, workerTask, result); -// LOGGER.info("###Recon result: {}", result.getStatus()); -// LOGGER.info("###Recon result dump: {}", result.debugDump()); // We do not want to override the result set by handler. This is just a fallback case if (result.isUnknown() || result.isInProgress()) { @@ -462,7 +460,6 @@ private boolean processError(PrismObject object, Task task, Throwable ex, Ope result.recordFatalError("Failed to "+getProcessShortName()+": "+ex.getMessage(), ex); } result.summarize(); - LOGGER.info("stop on error return: {}", !isStopOnError(task, ex, result)); return !isStopOnError(task, ex, result); // return !isStopOnError(); } diff --git a/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/execution/JobExecutor.java b/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/execution/JobExecutor.java index a06ad64705e..21ba4545b2b 100644 --- a/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/execution/JobExecutor.java +++ b/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/execution/JobExecutor.java @@ -665,99 +665,6 @@ private TaskRunResult executeHandler(TaskHandler handler, OperationResult execut waitForTransientChildrenAndCloseThem(executionResult); return runResult; } -// -// private TaskRunResult executePlainTaskHandler(TaskHandler handler) { -// TaskRunResult runResult; -// try { -// LOGGER.trace("Executing handler {}", handler.getClass().getName()); -// runResult = handler.run(task); -// if (runResult == null) { // Obviously an error in task handler -// LOGGER.error("Unable to record run finish: task returned null result"); -// runResult = createFailureTaskRunResult("Unable to record run finish: task returned null result", null); -// } -// } catch (Throwable t) { -// LOGGER.error("Task handler threw unexpected exception: {}: {}; task = {}", t.getClass().getName(), t.getMessage(), task, t); -// runResult = createFailureTaskRunResult("Task handler threw unexpected exception: " + t.getMessage(), t); -// } -// return runResult; -// } -// -// private TaskRunResult executeWorkBucketAwareTaskHandler(WorkBucketAwareTaskHandler handler, OperationResult executionResult) { -// WorkStateManager workStateManager = taskManagerImpl.getWorkStateManager(); -// -// if (task.getWorkState() != null && Boolean.TRUE.equals(task.getWorkState().isAllWorkComplete())) { -// LOGGER.debug("Work is marked as complete; restarting it in task {}", task); -// try { -// List> itemDeltas = taskManagerImpl.getPrismContext().deltaFor(TaskType.class) -// .item(TaskType.F_WORK_STATE).replace() -// .asItemDeltas(); -// task.applyDeltasImmediate(itemDeltas, executionResult); -// } catch (SchemaException | ObjectAlreadyExistsException | ObjectNotFoundException | RuntimeException e) { -// LoggingUtils.logUnexpectedException(LOGGER, "Couldn't remove work state from (completed) task {} -- continuing", e, task); -// } -// } -// -// boolean initialBucket = true; -// TaskWorkBucketProcessingResult runResult = null; -// for (;;) { -// WorkBucketType bucket; -// try { -// try { -// bucket = workStateManager.getWorkBucket(task.getOid(), FREE_BUCKET_WAIT_TIME, () -> task.canRun(), initialBucket, executionResult); -// } catch (InterruptedException e) { -// LOGGER.trace("InterruptedExecution in getWorkBucket for {}", task); -// if (task.canRun()) { -// throw new IllegalStateException("Unexpected InterruptedException: " + e.getMessage(), e); -// } else { -// return createInterruptedTaskRunResult(); -// } -// } -// } catch (Throwable t) { -// LoggingUtils.logUnexpectedException(LOGGER, "Couldn't allocate a work bucket for task {} (coordinator {})", t, task, null); -// return createFailureTaskRunResult("Couldn't allocate a work bucket for task: " + t.getMessage(), t); -// } -// initialBucket = false; -// if (bucket == null) { -// LOGGER.trace("No (next) work bucket within {}, exiting", task); -// runResult = handler.onNoMoreBuckets(task, runResult); -// return runResult != null ? runResult : createSuccessTaskRunResult(); -// } -// try { -// LOGGER.trace("Executing handler {} with work bucket of {} for {}", handler.getClass().getName(), bucket, task); -// runResult = handler.run(task, bucket, runResult); -// LOGGER.trace("runResult is {} for {}", runResult, task); -// if (runResult == null) { // Obviously an error in task handler -// LOGGER.error("Unable to record run finish: task returned null result"); -// //releaseWorkBucketChecked(bucket, executionResult); -// return createFailureTaskRunResult("Unable to record run finish: task returned null result", null); -// } -// } catch (Throwable t) { -// LOGGER.error("Task handler threw unexpected exception: {}: {}; task = {}", t.getClass().getName(), t.getMessage(), task, t); -// //releaseWorkBucketChecked(bucket, executionResult); -// return createFailureTaskRunResult("Task handler threw unexpected exception: " + t.getMessage(), t); -// } -// if (!runResult.isBucketComplete()) { -// return runResult; -// } -// try { -// taskManagerImpl.getWorkStateManager().completeWorkBucket(task.getOid(), bucket.getSequentialNumber(), executionResult); -// } catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException | RuntimeException e) { -// LoggingUtils.logUnexpectedException(LOGGER, "Couldn't complete work bucket for task {}", e, task); -// return createFailureTaskRunResult("Couldn't complete work bucket: " + e.getMessage(), e); -// } -// if (!task.canRun() || !runResult.isShouldContinue()) { -// return runResult; -// } -// } -// } - -// private void releaseWorkBucketChecked(AbstractWorkBucketType bucket, OperationResult executionResult) { -// try { -// taskManagerImpl.getWorkStateManager().releaseWorkBucket(task.getOid(), bucket.getSequentialNumber(), executionResult); -// } catch (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException e) { -// LoggingUtils.logUnexpectedException(LOGGER, "Couldn't release work bucket for task {}", e, task); -// } -// } private OperationResult createOperationResult(String methodName) { return new OperationResult(DOT_CLASS + methodName); diff --git a/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/handlers/LightweightPartitioningTaskHandler.java b/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/handlers/LightweightPartitioningTaskHandler.java index 98da206d219..32b0323efe2 100644 --- a/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/handlers/LightweightPartitioningTaskHandler.java +++ b/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/handlers/LightweightPartitioningTaskHandler.java @@ -26,6 +26,8 @@ import org.springframework.stereotype.Component; import com.evolveum.midpoint.prism.PrismContext; +import com.evolveum.midpoint.prism.delta.ContainerDelta; +import com.evolveum.midpoint.prism.delta.DeltaFactory; import com.evolveum.midpoint.repo.api.CounterManager; import com.evolveum.midpoint.schema.result.OperationResult; import com.evolveum.midpoint.task.api.RunningTask; @@ -37,12 +39,20 @@ import com.evolveum.midpoint.task.api.TaskManager; import com.evolveum.midpoint.task.api.TaskRunResult; import com.evolveum.midpoint.task.api.TaskRunResult.TaskRunResultStatus; +import com.evolveum.midpoint.task.quartzimpl.InternalTaskInterface; import com.evolveum.midpoint.task.quartzimpl.RunningTaskQuartzImpl; import com.evolveum.midpoint.task.quartzimpl.execution.HandlerExecutor; +import com.evolveum.midpoint.task.quartzimpl.work.WorkStateManager; +import com.evolveum.midpoint.util.MiscUtil; +import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException; +import com.evolveum.midpoint.util.exception.ObjectNotFoundException; +import com.evolveum.midpoint.util.exception.SchemaException; import com.evolveum.midpoint.util.logging.Trace; import com.evolveum.midpoint.util.logging.TraceManager; import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskPartitionDefinitionType; import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskPartitionsDefinitionType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskWorkStateType; /** * @author katka @@ -55,10 +65,10 @@ public class LightweightPartitioningTaskHandler implements TaskHandler { private static final String HANDLER_URI = TaskConstants.LIGHTWEIGTH_PARTITIONING_TASK_HANDLER_URI; - @Autowired private PrismContext prismContext; @Autowired private TaskManager taskManager; @Autowired private HandlerExecutor handlerExecutor; @Autowired private CounterManager counterManager; + @Autowired private PrismContext prismContext; @PostConstruct @@ -73,6 +83,9 @@ public TaskRunResult run(RunningTask task, TaskPartitionDefinitionType taskParti runResult.setProgress(task.getProgress()); runResult.setOperationResult(opResult); + if (taskPartition != null && taskPartition.getWorkManagement() != null) { + throw new UnsupportedOperationException("Work management not supoorted in partitions for lightweigth partitioning task"); + } TaskPartitionsDefinitionType partitionsDefinition = task.getWorkManagement().getPartitions(); List partitions = partitionsDefinition.getPartition(); @@ -102,8 +115,8 @@ public TaskRunResult run(RunningTask task, TaskPartitionDefinitionType taskParti partitions.sort(comparator); for (TaskPartitionDefinitionType partition : partitions) { TaskHandler handler = taskManager.getHandler(partition.getHandlerUri()); + LOGGER.trace("Starting to execute handler {} defined in partition {}", handler, partition); TaskRunResult subHandlerResult = handlerExecutor.executeHandler((RunningTaskQuartzImpl) task, partition, handler, opResult); -// TaskRunResult subHandlerResult = handler.run(task, partition); OperationResult subHandlerOpResult = subHandlerResult.getOperationResult(); opResult.addSubresult(subHandlerOpResult); runResult = subHandlerResult; @@ -116,6 +129,14 @@ public TaskRunResult run(RunningTask task, TaskPartitionDefinitionType taskParti if (subHandlerOpResult.isError()) { break; } + + try { + LOGGER.trace("Cleaning up work state in task {}, workState: {}", task, task.getWorkState()); + cleanupWorkState(task, runResult.getOperationResult()); + } catch (ObjectNotFoundException | SchemaException | ObjectAlreadyExistsException e) { + LOGGER.error("Unexpected error during cleaning work state: " + e.getMessage(), e); + throw new IllegalStateException(e); + } } runResult.setProgress(runResult.getProgress() + 1); @@ -125,11 +146,19 @@ public TaskRunResult run(RunningTask task, TaskPartitionDefinitionType taskParti return runResult; } + public void cleanupWorkState(RunningTask runningTask, OperationResult parentResult) + throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException { + ContainerDelta containerDelta = (ContainerDelta) prismContext + .deltaFor(TaskType.class).item(TaskType.F_WORK_STATE).replace().asItemDelta(); + ((InternalTaskInterface) runningTask).applyDeltasImmediate(MiscUtil.createCollection(containerDelta), parentResult); + + } + private boolean canContinue(RunningTask task, TaskRunResult runResult) { if (!task.canRun() || runResult.getRunResultStatus() == TaskRunResultStatus.INTERRUPTED) { // first, if a task was interrupted, we do not want to change its status LOGGER.trace("Task was interrupted, exiting the execution cycle. Task = {}", task); - return true; + return false; } else if (runResult.getRunResultStatus() == TaskRunResultStatus.TEMPORARY_ERROR) { LOGGER.trace("Task encountered temporary error, continuing with the execution cycle. Task = {}", task); return false; @@ -137,7 +166,7 @@ private boolean canContinue(RunningTask task, TaskRunResult runResult) { // in case of RESTART_REQUESTED we have to get (new) current handler and restart it // this is implemented by pushHandler and by Quartz LOGGER.trace("Task returned RESTART_REQUESTED state, exiting the execution cycle. Task = {}", task); - return true; + return false; } else if (runResult.getRunResultStatus() == TaskRunResultStatus.PERMANENT_ERROR) { LOGGER.info("Task encountered permanent error, suspending the task. Task = {}", task); return false; @@ -170,10 +199,4 @@ public String getCategoryName(Task task) { return TaskCategory.UTIL; } - -// private void processErrorCriticality(Task task, TaskPartitionDefinitionType partitionDefinition, Throwable ex, OperationResult result) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, PolicyViolationException, ExpressionEvaluationException, ObjectAlreadyExistsException, PreconditionViolationException { -// CriticalityType criticality = ExceptionUtil.getCriticality(partitionDefinition.getErrorCriticality(), ex, CriticalityType.PARTIAL); -// RepoCommonUtils.processErrorCriticality(task.getTaskType(), criticality, ex, result); -// -// } } diff --git a/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/work/WorkStateManager.java b/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/work/WorkStateManager.java index d6ba6424087..534964276f8 100644 --- a/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/work/WorkStateManager.java +++ b/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/work/WorkStateManager.java @@ -34,6 +34,7 @@ import com.evolveum.midpoint.prism.ItemDefinition; import com.evolveum.midpoint.prism.PrismContext; import com.evolveum.midpoint.prism.PrismObject; +import com.evolveum.midpoint.prism.delta.ContainerDelta; import com.evolveum.midpoint.prism.delta.ItemDelta; import com.evolveum.midpoint.prism.delta.ItemDeltaCollectionsUtil; import com.evolveum.midpoint.prism.path.ItemPath; @@ -46,6 +47,7 @@ import com.evolveum.midpoint.repo.api.VersionPrecondition; import com.evolveum.midpoint.schema.result.OperationResult; import com.evolveum.midpoint.schema.util.TaskWorkStateTypeUtil; +import com.evolveum.midpoint.task.api.RunningTask; import com.evolveum.midpoint.task.api.Task; import com.evolveum.midpoint.task.api.TaskExecutionStatus; import com.evolveum.midpoint.task.api.TaskManager; @@ -60,6 +62,7 @@ import com.evolveum.midpoint.task.quartzimpl.work.segmentation.WorkSegmentationStrategyFactory; import com.evolveum.midpoint.task.quartzimpl.work.segmentation.content.WorkBucketContentHandler; import com.evolveum.midpoint.task.quartzimpl.work.segmentation.content.WorkBucketContentHandlerRegistry; +import com.evolveum.midpoint.util.MiscUtil; import com.evolveum.midpoint.util.backoff.BackoffComputer; import com.evolveum.midpoint.util.backoff.ExponentialBackoffComputer; import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException; @@ -170,7 +173,7 @@ public WorkBucketType getWorkBucket(@NotNull String workerTaskOid, long freeBuck return getWorkBucketMultiNode(ctx, freeBucketWaitTime, result); } } - + private WorkBucketType findSelfAllocatedBucket(Context ctx) { TaskWorkStateType workState = ctx.workerTask.getWorkState(); if (workState == null || workState.getBucket().isEmpty()) { @@ -503,6 +506,7 @@ private void completeWorkBucketStandalone(Context ctx, int sequentialNumber, Ope Collection> modifications = bucketStateChangeDeltas(bucket, WorkBucketStateType.COMPLETE); repositoryService.modifyObject(TaskType.class, ctx.workerTask.getOid(), modifications, null, result); ((InternalTaskInterface) ctx.workerTask).applyModificationsTransient(modifications); + ((InternalTaskInterface) ctx.workerTask).applyDeltasImmediate(modifications, result); compressCompletedBuckets(ctx.workerTask, result); } diff --git a/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholds.java b/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholds.java index 03575e65b7a..638f7634939 100644 --- a/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholds.java +++ b/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholds.java @@ -60,7 +60,7 @@ public abstract class TestThresholds extends AbstractStoryTest { private static final String ROLE_POLICY_RULE_CREATE_OID = "00000000-role-0000-0000-999111111112"; private static final File ROLE_POLICY_RULE_CHANGE_ACTIVATION_FILE = new File(TEST_DIR, "role-policy-rule-change-activation.xml"); - private static final String ROLE_POLICY_RULE_CHANGE_ACTIVATION_OID = "00000000-role-0000-0000-999111111223"; + protected static final String ROLE_POLICY_RULE_CHANGE_ACTIVATION_OID = "00000000-role-0000-0000-999111111223"; private static final File TASK_IMPORT_BASE_USERS_FILE = new File(TEST_DIR, "task-opendj-import-base-users.xml"); private static final String TASK_IMPORT_BASE_USERS_OID = "fa25e6dc-a858-11e7-8ebc-eb2b71ecce1d"; @@ -250,7 +250,7 @@ public void test520changeActivationThreeAccounts() throws Exception { //WHEN displayWhen(TEST_NAME); - OperationResult reconResult = waitForTaskNextRun(getTaskOid(), false, 20000, true); + OperationResult reconResult = waitForTaskResume(getTaskOid(), false, 20000); assertFailure(reconResult); //THEN @@ -258,7 +258,6 @@ public void test520changeActivationThreeAccounts() throws Exception { Task taskAfter = taskManager.getTaskWithResult(getTaskOid(), result); assertTaskExecutionStatus(getTaskOid(), TaskExecutionStatus.SUSPENDED); - assertUsers(getNumberOfUsers() + getProcessedUsers()*2); assertSynchronizationStatisticsActivation(taskAfter); diff --git a/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholdsLiveSyncFull.java b/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholdsLiveSyncFull.java index 39a0c51471b..9bad986b327 100644 --- a/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholdsLiveSyncFull.java +++ b/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholdsLiveSyncFull.java @@ -73,7 +73,7 @@ protected void assertSynchronizationStatisticsAfterImport(Task taskAfter) throws } protected void assertSynchronizationStatisticsActivation(Task taskAfter) { - assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountUnmatched(), 5); + assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountUnmatched(), 3); assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountDeleted(), 0); assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountLinked(), 0); assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountUnlinked(), 0); diff --git a/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholdsLiveSyncSimulate.java b/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholdsLiveSyncSimulate.java index 7684b831bf5..07f203b750f 100644 --- a/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholdsLiveSyncSimulate.java +++ b/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholdsLiveSyncSimulate.java @@ -68,7 +68,7 @@ protected void assertSynchronizationStatisticsAfterImport(Task taskAfter) throws } protected void assertSynchronizationStatisticsActivation(Task taskAfter) { - assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountUnmatched(), 5); + assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountUnmatched(), 3); assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountDeleted(), 0); assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountLinked(), 0); assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountUnlinked(), 0); diff --git a/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholdsReconFull.java b/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholdsReconFull.java index 0b047353502..909290c31bc 100644 --- a/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholdsReconFull.java +++ b/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholdsReconFull.java @@ -16,16 +16,23 @@ package com.evolveum.midpoint.testing.story; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; import java.io.File; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ContextConfiguration; +import org.testng.annotations.Test; +import com.evolveum.midpoint.prism.PrismObject; +import com.evolveum.midpoint.schema.result.OperationResult; import com.evolveum.midpoint.task.api.Task; +import com.evolveum.midpoint.task.api.TaskExecutionStatus; import com.evolveum.midpoint.xml.ns._public.common.common_3.IterativeTaskInformationType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType; import com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationInformationType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType; /** * @author katka @@ -38,7 +45,12 @@ public class TestThresholdsReconFull extends TestThresholds { private static final File TASK_RECONCILE_OPENDJ_FULL_FILE = new File(TEST_DIR, "task-opendj-reconcile-full.xml"); private static final String TASK_RECONCILE_OPENDJ_FULL_OID = "20335c7c-838f-11e8-93a6-4b1dd0ab58e4"; - + private static final File ROLE_POLICY_RULE_DELETE_FILE = new File(TEST_DIR, "role-policy-rule-delete.xml"); + private static final String ROLE_POLICY_RULE_DELETE_OID = "00000000-role-0000-0000-888111111112"; + + private static final File TASK_RECONCILE_OPENDJ_SIMULATE_EXECUTE_FILE = new File(TEST_DIR, "task-opendj-reconcile-simulate-execute.xml"); + private static final String TASK_RECONCILE_OPENDJ_SIMULATE_EXECUTE_OID = "00000000-838f-11e8-93a6-4b1dd0ab58e4"; + @Override protected File getTaskFile() { return TASK_RECONCILE_OPENDJ_FULL_FILE; @@ -53,6 +65,56 @@ protected String getTaskOid() { protected int getProcessedUsers() { return 4; } + + @Override + public void initSystem(Task initTask, OperationResult initResult) throws Exception { + super.initSystem(initTask, initResult); + + repoAddObjectFromFile(ROLE_POLICY_RULE_DELETE_FILE, initResult); + repoAddObjectFromFile(TASK_RECONCILE_OPENDJ_SIMULATE_EXECUTE_FILE, initResult); + } + + @Test + public void test600chageTaskPolicyRule() throws Exception { + final String TEST_NAME = "test600chageTaskPolicyRule"; + displayTestTitle(TEST_NAME); + + //WHEN + Task task = taskManager.createTaskInstance(TEST_NAME); + OperationResult result = task.getResult(); + assignRole(TaskType.class, TASK_RECONCILE_OPENDJ_SIMULATE_EXECUTE_OID, ROLE_POLICY_RULE_DELETE_OID, task, result); + + //THEN + PrismObject taskAfter = getObject(TaskType.class, TASK_RECONCILE_OPENDJ_SIMULATE_EXECUTE_OID); + display("Task after:", taskAfter); + assertAssignments(taskAfter, 1); + assertAssigned(taskAfter, ROLE_POLICY_RULE_DELETE_OID, RoleType.COMPLEX_TYPE); + assertTaskExecutionStatus(TASK_RECONCILE_OPENDJ_SIMULATE_EXECUTE_OID, TaskExecutionStatus.SUSPENDED); + } + + + @Test + public void test610testFullRecon() throws Exception { + final String TEST_NAME = "test610testFullRecon"; + displayTestTitle(TEST_NAME); + OperationResult result = new OperationResult(TEST_NAME); + + //WHEN + displayWhen(TEST_NAME); + OperationResult reconResult = waitForTaskResume(TASK_RECONCILE_OPENDJ_SIMULATE_EXECUTE_OID, true, 20000); + assertSuccess(reconResult); + + //THEN + + Task taskAfter = taskManager.getTaskWithResult(TASK_RECONCILE_OPENDJ_SIMULATE_EXECUTE_OID, result); + + assertTaskExecutionStatus(TASK_RECONCILE_OPENDJ_SIMULATE_EXECUTE_OID, TaskExecutionStatus.RUNNABLE); +// assertUsers(getNumberOfUsers() + getProcessedUsers()*2); + + assertSynchronizationStatisticsFull(taskAfter); + + } + @Override protected void assertSynchronizationStatisticsAfterImport(Task taskAfter) throws Exception { @@ -71,6 +133,13 @@ protected void assertSynchronizationStatisticsAfterImport(Task taskAfter) throws assertEquals(syncInfo.getCountLinkedAfter(), getDefaultUsers() + getProcessedUsers()); assertEquals(syncInfo.getCountUnlinked(), 0); } + + private void assertSynchronizationStatisticsFull(Task taskAfter) throws Exception { + IterativeTaskInformationType infoType = taskAfter.getStoredOperationStats().getIterativeTaskInformation(); + assertEquals(infoType.getTotalFailureCount(), 0); + assertNull(taskAfter.getWorkState(), "Unexpected work state in task."); + + } /* (non-Javadoc) * @see com.evolveum.midpoint.testing.story.TestThresholds#assertSynchronizationStatisticsAfterSecondImport(com.evolveum.midpoint.task.api.Task) @@ -97,14 +166,14 @@ protected void assertSynchronizationStatisticsActivation(Task taskAfter) { IterativeTaskInformationType infoType = taskAfter.getStoredOperationStats().getIterativeTaskInformation(); assertEquals(infoType.getTotalFailureCount(), 1); - assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountUnmatched(), 5); + assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountUnmatched(), 3); assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountDeleted(), 0); - assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountLinked(), getDefaultUsers() + getProcessedUsers()); + assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountLinked(), 14); assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountUnlinked(), 0); assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountUnmatchedAfter(), 0); assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountDeleted(), 0); - assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountLinked(), getDefaultUsers() + getProcessedUsers()); + assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountLinked(), 14); assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountUnlinked(), 0); } diff --git a/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholdsReconSimulate.java b/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholdsReconSimulate.java index 8c7c2bd7038..3d7e372dd22 100644 --- a/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholdsReconSimulate.java +++ b/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestThresholdsReconSimulate.java @@ -98,7 +98,7 @@ protected void assertSynchronizationStatisticsActivation(Task taskAfter) { IterativeTaskInformationType infoType = taskAfter.getStoredOperationStats().getIterativeTaskInformation(); assertEquals(infoType.getTotalFailureCount(), 1); - assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountUnmatched(), 5); + assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountUnmatched(), 3); assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountDeleted(), 0); assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountLinked(), getDefaultUsers() + getProcessedUsers()); assertEquals(taskAfter.getStoredOperationStats().getSynchronizationInformation().getCountUnlinked(), 0); diff --git a/testing/story/src/test/resources/thresholds/role-policy-rule-delete.xml b/testing/story/src/test/resources/thresholds/role-policy-rule-delete.xml new file mode 100644 index 00000000000..5248a589840 --- /dev/null +++ b/testing/story/src/test/resources/thresholds/role-policy-rule-delete.xml @@ -0,0 +1,41 @@ + + + + Stop on delete user (1) + + + Delete user + + + delete + + + + + + + + 1 + + + + + + + 2 + + \ No newline at end of file diff --git a/testing/story/src/test/resources/thresholds/task-opendj-reconcile-simulate-execute.xml b/testing/story/src/test/resources/thresholds/task-opendj-reconcile-simulate-execute.xml new file mode 100644 index 00000000000..57b48105bff --- /dev/null +++ b/testing/story/src/test/resources/thresholds/task-opendj-reconcile-simulate-execute.xml @@ -0,0 +1,69 @@ + + + + + + + + + Reconciliation Simulate Execute: Dummy + + + ri:inetOrgPerson + account + default + + + 00000000-838f-11e8-93a6-4b1dd0ab58e4 + + suspended + + http://midpoint.evolveum.com/xml/ns/public/task/lightweigth-partitioning/handler-3 + + + + + 2 + http://midpoint.evolveum.com/xml/ns/public/model/synchronization/task/reconciliation/handler-3 + execute + + fatal + + + + 1 + http://midpoint.evolveum.com/xml/ns/public/model/synchronization/task/reconciliation/handler-3 + simulate + + fatal + + + + + + + recurring + + 3 + + +