Skip to content

Commit

Permalink
Fix "no sync policy" treatment in LiveSync
Browse files Browse the repository at this point in the history
Processing of such resource objects was originally considered to be
erroneous, so live sync task stopped when they were encountered.
But, in fact, these should be simply ignored.

So we added "not applicable" to the list of accepted operation result
statuses.

This resolves MID-5999.

Cherry-picked and adapted from 3e4e0be.
  • Loading branch information
mederly committed Mar 10, 2020
1 parent f0eb801 commit 6a6dd40
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 79 deletions.

Large diffs are not rendered by default.

@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2019 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<resource oid="3908fabe-8608-4db0-93ee-e06c5691eb8f"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3">

<name>Dummy Resource No Policy</name>
<connectorRef type="c:ConnectorType">
<filter>
<q:and>
<q:equal>
<q:path>connectorType</q:path>
<q:value>com.evolveum.icf.dummy.connector.DummyConnector</q:value>
</q:equal>
<q:equal>
<q:path>connectorVersion</q:path>
<q:value>2.0</q:value>
</q:equal>
</q:and>
</filter>
</connectorRef>
<connectorConfiguration xmlns:icfi="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/bundle/com.evolveum.icf.dummy/com.evolveum.icf.dummy.connector.DummyConnector"
xmlns:icfc="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/connector-schema-3">
<icfc:configurationProperties>
<icfi:instanceId>noPolicy</icfi:instanceId>
</icfc:configurationProperties>
</connectorConfiguration>

<schemaHandling>
<objectType>
<displayName>Default Account</displayName>
<default>true</default>
<objectClass>ri:AccountObjectClass</objectClass>
<attribute>
<ref>icfs:name</ref>
<inbound>
<target>
<path>name</path>
</target>
</inbound>
</attribute>
</objectType>
</schemaHandling>

<synchronization>
<!-- no policy! -->
</synchronization>
</resource>
27 changes: 27 additions & 0 deletions model/model-intest/src/test/resources/sync/task-no-policy.xml
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2019 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<task oid="b2aa4e0a-1fce-499d-8502-ece187b24ae4"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:ext="http://midpoint.evolveum.com/xml/ns/public/model/extension-3"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3">

<name>Live Sync No Policy</name>

<extension>
<ext:objectclass>ri:AccountObjectClass</ext:objectclass>
</extension>

<taskIdentifier>b2aa4e0a-1fce-499d-8502-ece187b24ae4</taskIdentifier>
<ownerRef oid="00000000-0000-0000-0000-000000000002"/>
<executionStatus>runnable</executionStatus>

<handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/synchronization/task/live-sync/handler-3</handlerUri>
<objectRef oid="3908fabe-8608-4db0-93ee-e06c5691eb8f" type="ResourceType"/> <!-- no-policy -->
<recurrence>single</recurrence>
</task>
Expand Up @@ -172,7 +172,7 @@ public void execute(ProcessChangeRequest request, Task workerTask, Task coordina

notifyChangeResult.computeStatus("Error in notify change operation.");

if (notifyChangeResult.isSuccess() || notifyChangeResult.isHandledError()) {
if (notifyChangeResult.isSuccess() || notifyChangeResult.isHandledError() || notifyChangeResult.isNotApplicable()) {
// Do not delete dead shadows. Keep dead shadow around because they contain results
// of the synchronization. Usual shadow refresh process should delete them eventually.
// TODO: review. Maybe make this configuration later on.
Expand Down Expand Up @@ -387,7 +387,7 @@ private void validateResult(OperationResult result, Task task, TaskPartitionDefi
SecurityViolationException, PolicyViolationException, ExpressionEvaluationException, ObjectAlreadyExistsException,
PreconditionViolationException {

if (result.isSuccess() || result.isHandledError()) {
if (result.isSuccess() || result.isHandledError() || result.isNotApplicable()) {
return;
}

Expand Down
Expand Up @@ -121,7 +121,7 @@ public void test010Sanity() throws Exception {

Task syncTask = taskManager.getTaskPlain(SYNC_TASK_OID, result);
AssertJUnit.assertNotNull(syncTask);
assertSyncToken(syncTask, 0, result);
assertSyncToken(syncTask, 0);
}

@Test
Expand All @@ -130,7 +130,7 @@ public void test100SyncAddWill() throws Exception {

Task syncTask = taskManager.getTaskPlain(SYNC_TASK_OID, result);
AssertJUnit.assertNotNull(syncTask);
assertSyncToken(syncTask, 0, result);
assertSyncToken(syncTask, 0);
((SynchronizationServiceMock) syncServiceMock).reset();

// create add change in embedded LDAP
Expand Down Expand Up @@ -189,7 +189,7 @@ public void test500SyncAddProtected() throws Exception {

Task syncTask = taskManager.getTaskPlain(SYNC_TASK_OID, result);
AssertJUnit.assertNotNull(syncTask);
assertSyncToken(syncTask, 1, result);
assertSyncToken(syncTask, 1);
((SynchronizationServiceMock) syncServiceMock).reset();

// create add change in embedded LDAP
Expand Down
Expand Up @@ -1419,17 +1419,17 @@ protected void assertFilter(ObjectFilter filter, Class<? extends ObjectFilter> e
protected void assertSyncToken(String syncTaskOid, Object expectedValue) throws ObjectNotFoundException, SchemaException {
OperationResult result = new OperationResult(AbstractIntegrationTest.class.getName() + ".assertSyncToken");
Task task = taskManager.getTaskPlain(syncTaskOid, result);
assertSyncToken(task, expectedValue, result);
assertSyncToken(task, expectedValue);
result.computeStatus();
TestUtil.assertSuccess(result);
}

protected void assertSyncToken(String syncTaskOid, Object expectedValue, OperationResult result) throws ObjectNotFoundException, SchemaException {
Task task = taskManager.getTaskPlain(syncTaskOid, result);
assertSyncToken(task, expectedValue, result);
assertSyncToken(task, expectedValue);
}

protected void assertSyncToken(Task task, Object expectedValue, OperationResult result) throws ObjectNotFoundException, SchemaException {
protected void assertSyncToken(Task task, Object expectedValue) {
PrismProperty<Object> syncTokenProperty = task.getExtensionPropertyOrClone(SchemaConstants.SYNC_TOKEN);
if (expectedValue == null && syncTokenProperty == null) {
return;
Expand Down
Expand Up @@ -49,7 +49,7 @@ protected void assertSynchronizationStatisticsAfterImport(Task taskAfter) throws
SynchronizationInformationType syncInfo = taskAfter.getStoredOperationStats().getSynchronizationInformation();
dumpSynchronizationInformation(syncInfo);

assertSyncToken(taskAfter, 4, taskAfter.getResult());
assertSyncToken(taskAfter, 4);

assertEquals(syncInfo.getCountUnmatched(), 5);
assertEquals(syncInfo.getCountDeleted(), 0);
Expand Down Expand Up @@ -80,7 +80,7 @@ protected void assertSynchronizationStatisticsAfterSecondImport(Task taskAfter)
SynchronizationInformationType syncInfo = taskAfter.getStoredOperationStats().getSynchronizationInformation();
dumpSynchronizationInformation(syncInfo);

assertSyncToken(taskAfter, 4, taskAfter.getResult());
assertSyncToken(taskAfter, 4);

assertEquals(syncInfo.getCountUnmatched(), 5);
assertEquals(syncInfo.getCountDeleted(), 0);
Expand Down
Expand Up @@ -47,7 +47,7 @@ protected void assertSynchronizationStatisticsAfterImport(Task taskAfter) throws
SynchronizationInformationType syncInfo = taskAfter.getStoredOperationStats().getSynchronizationInformation();
dumpSynchronizationInformation(syncInfo);

assertSyncToken(taskAfter, 4, taskAfter.getResult());
assertSyncToken(taskAfter, 4);

// user5, user6, user7, user8, user9 (why not user4? -- because token is preset to 4)
assertEquals(syncInfo.getCountUnmatchedAfter(), 5);
Expand Down Expand Up @@ -77,7 +77,7 @@ protected void assertSynchronizationStatisticsAfterSecondImport(Task taskAfter)
SynchronizationInformationType syncInfo = taskAfter.getStoredOperationStats().getSynchronizationInformation();
dumpSynchronizationInformation(syncInfo);

assertSyncToken(taskAfter, 4, taskAfter.getResult());
assertSyncToken(taskAfter, 4);

// user5, user6, user7, user8, user9
assertEquals(syncInfo.getCountUnmatchedAfter(), 5);
Expand Down

0 comments on commit 6a6dd40

Please sign in to comment.