Skip to content

Commit

Permalink
Reworked connector instance lifecycle management (MID-5068)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 7, 2019
1 parent 4afd035 commit d80fece
Show file tree
Hide file tree
Showing 34 changed files with 1,294 additions and 810 deletions.
2 changes: 1 addition & 1 deletion build-system/pom.xml
Expand Up @@ -83,7 +83,7 @@
<activiti-spring.version>5.22.0</activiti-spring.version>
<commons-email.version>1.3</commons-email.version>
<xmlsec.version>2.0.6</xmlsec.version>
<connid.version>1.5.0.8</connid.version>
<connid.version>1.5.0.10</connid.version>
<jasper.version>6.5.0</jasper.version>
<derby.version>10.11.1.1</derby.version>
<wro4j.version>1.8.0</wro4j.version>
Expand Down
Expand Up @@ -194,7 +194,7 @@ public void init(Configuration configuration) {
staticVal = this.toString();
}

log.info("Connected to dummy resource instance {0} ({1} connections open)", resource, resource.getConnectionCount());
log.info("Connected connector #{0} to dummy resource instance {1} ({2} connections open)", instanceNumber, resource, resource.getConnectionCount());
}

private static synchronized int getNextInstanceNumber() {
Expand All @@ -210,7 +210,7 @@ private static synchronized int getNextInstanceNumber() {
public void dispose() {
connected = false;
resource.disconnect();
log.info("Disconnected from dummy resource instance {0} ({1} connections still open)", resource, resource.getConnectionCount());
log.info("Disconnected connector #{0} from dummy resource instance {1} ({2} connections still open)", instanceNumber, resource, resource.getConnectionCount());
}

@Override
Expand Down
Expand Up @@ -398,9 +398,13 @@ public synchronized void disconnect() {
connectionCount--;
}

public void assertNoConnections() {
public synchronized void assertNoConnections() {
assert connectionCount == 0 : "Dummy resource: "+connectionCount+" connections still open";
}

public synchronized void assertConnections(int expected) {
assert connectionCount == expected : "Dummy resource: unexpected number of connections, expected: "+expected+", but was "+connectionCount;
}

public synchronized void recordWriteOperation(String operation) {
writeOperationCount++;
Expand Down
Expand Up @@ -29,6 +29,8 @@ public enum InternalCounters {
RESOURCE_REPOSITORY_MODIFY_COUNT("resourceRepositoryModifyCount", "resource repository modify count", InternalOperationClasses.REPOSITORY_OPERATIONS),

CONNECTOR_INSTANCE_INITIALIZATION_COUNT("connectorInstanceInitializationCount", "connector instance initialization count", InternalOperationClasses.CONNECTOR_OPERATIONS),

CONNECTOR_INSTANCE_CONFIGURATION_COUNT("connectorInstanceConfigurationCount", "connector instance configuration count", InternalOperationClasses.CONNECTOR_OPERATIONS),

CONNECTOR_SCHEMA_PARSE_COUNT("connectorSchemaParseCount", "connector schema parse count", InternalOperationClasses.CONNECTOR_OPERATIONS),

Expand Down
Expand Up @@ -137,6 +137,7 @@ public void test131ModifyUserJackAssignAccount() throws Exception {
assertSuccess(result);
XMLGregorianCalendar endTime = clock.currentTimeXMLGregorianCalendar();
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 0); // MID-4779
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_CONFIGURATION_COUNT, 0);
assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 0);

PrismObject<UserType> userJack = getUser(USER_JACK_OID);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -95,7 +95,7 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
@Test
public void test010ListConnectors() throws Exception {
final String TEST_NAME = "test010ListConnectors";
TestUtil.displayTestTitle(this, TEST_NAME);
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
Expand Down Expand Up @@ -133,7 +133,7 @@ public void test010ListConnectors() throws Exception {
@Test
public void test020ImportFakeResource() throws Exception {
final String TEST_NAME = "test020ImportFakeResource";
TestUtil.displayTestTitle(this, TEST_NAME);
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
Expand All @@ -158,7 +158,7 @@ public void test020ImportFakeResource() throws Exception {
@Test
public void test021TestFakeResource() throws Exception {
final String TEST_NAME = "test021TestFakeResource";
TestUtil.displayTestTitle(this, TEST_NAME);
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
Expand All @@ -175,7 +175,7 @@ public void test021TestFakeResource() throws Exception {
@Test
public void test022ListAccountsFakeResource() throws Exception {
final String TEST_NAME = "test022ListAccountsFakeResource";
TestUtil.displayTestTitle(this, TEST_NAME);
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
Expand All @@ -195,7 +195,7 @@ public void test022ListAccountsFakeResource() throws Exception {
@Test
public void test030ImportDummyResource() throws Exception {
final String TEST_NAME = "test030ImportDummyResource";
TestUtil.displayTestTitle(this, TEST_NAME);
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
Expand All @@ -220,7 +220,7 @@ public void test030ImportDummyResource() throws Exception {
@Test
public void test031TestDummyResource() throws Exception {
final String TEST_NAME = "test031TestDummyResource";
TestUtil.displayTestTitle(this, TEST_NAME);
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
Expand All @@ -237,7 +237,7 @@ public void test031TestDummyResource() throws Exception {
@Test
public void test032ListAccountsDummyResource() throws Exception {
final String TEST_NAME = "test032ListAccountsDummyResource";
TestUtil.displayTestTitle(this, TEST_NAME);
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
Expand All @@ -247,9 +247,7 @@ public void test032ListAccountsDummyResource() throws Exception {
Collection<PrismObject<ShadowType>> accounts = listAccounts(resourceDummy, task, result);

// THEN
result.computeStatus();
display("listAccounts result", result);
TestUtil.assertSuccess("listAccounts result", result);
assertSuccess(result);

assertEquals("Unexpected number of accounts: "+accounts, 3, accounts.size());
}
Expand All @@ -261,7 +259,7 @@ public void test032ListAccountsDummyResource() throws Exception {
@Test
public void test100UpgradeModelAddDelete() throws Exception {
final String TEST_NAME = "test100UpgradeModelAddDelete";
TestUtil.displayTestTitle(this, TEST_NAME);
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
Expand All @@ -282,24 +280,21 @@ public void test100UpgradeModelAddDelete() throws Exception {
// Purge the schema. New connector schema is not compatible.
resourceDelta.addModificationReplaceContainer(ResourceType.F_SCHEMA);
display("Delta", resourceDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(resourceDelta);

// WHEN
modelService.executeChanges(deltas, null, task, result);
executeChanges(resourceDelta, null, task, result);

// THEN
result.computeStatus();
display("executeChanges result", result);
TestUtil.assertSuccess("executeChanges result", result);
assertSuccess(result);

assertUpgrade(dummyResourceModelBefore);
assertUpgrade(TEST_NAME, dummyResourceModelBefore);
}


@Test
public void test150DowngradeModelAddDelete() throws Exception {
final String TEST_NAME = "test150DowngradeModelAddDelete";
TestUtil.displayTestTitle(this, TEST_NAME);
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
Expand All @@ -316,23 +311,20 @@ public void test150DowngradeModelAddDelete() throws Exception {
ReferenceDelta connectorRefDeltaAdd = prismContext.deltaFactory().reference().createModificationAdd(ResourceType.F_CONNECTOR_REF,
getResourceDefinition(), connectorDummyFakeOid);
resourceDelta.addModification(connectorRefDeltaAdd);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(resourceDelta);

// WHEN
modelService.executeChanges(deltas, null, task, result);
executeChanges(resourceDelta, null, task, result);

// THEN
result.computeStatus();
display("executeChanges result", result);
TestUtil.assertSuccess("executeChanges result", result);
assertSuccess(result);

assertDowngrade(dummyResourceModelBefore);
}

@Test
public void test200UpgradeModelReplace() throws Exception {
final String TEST_NAME = "test200UpgradeModelReplace";
TestUtil.displayTestTitle(this, TEST_NAME);
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
Expand All @@ -346,24 +338,21 @@ public void test200UpgradeModelReplace() throws Exception {
ReferenceDelta connectorRefDeltaReplace = prismContext.deltaFactory().reference().createModificationReplace(ResourceType.F_CONNECTOR_REF,
getResourceDefinition(), connectorDummyOid);
resourceDelta.addModification(connectorRefDeltaReplace);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(resourceDelta);

// WHEN
modelService.executeChanges(deltas, null, task, result);
executeChanges(resourceDelta, null, task, result);

// THEN
result.computeStatus();
display("executeChanges result", result);
TestUtil.assertSuccess("executeChanges result", result);
assertSuccess("executeChanges result", result);

assertUpgrade(dummyResourceModelBefore);
assertUpgrade(TEST_NAME, dummyResourceModelBefore);
}


@Test
public void test250DowngradeModelReplace() throws Exception {
final String TEST_NAME = "test250DowngradeModelReplace";
TestUtil.displayTestTitle(this, TEST_NAME);
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
Expand All @@ -377,23 +366,20 @@ public void test250DowngradeModelReplace() throws Exception {
ReferenceDelta connectorRefDeltaReplace = prismContext.deltaFactory().reference().createModificationReplace(ResourceType.F_CONNECTOR_REF,
getResourceDefinition(), connectorDummyFakeOid);
resourceDelta.addModification(connectorRefDeltaReplace);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(resourceDelta);

// WHEN
modelService.executeChanges(deltas, null, task, result);
executeChanges(resourceDelta, null, task, result);

// THEN
result.computeStatus();
display("executeChanges result", result);
TestUtil.assertSuccess("executeChanges result", result);
assertSuccess("executeChanges result", result);

assertDowngrade(dummyResourceModelBefore);
}

@Test
public void test300UpgradeRawAddDelete() throws Exception {
final String TEST_NAME = "test300UpgradeRawAddDelete";
TestUtil.displayTestTitle(this, TEST_NAME);
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
Expand All @@ -410,26 +396,23 @@ public void test300UpgradeRawAddDelete() throws Exception {
ReferenceDelta connectorRefDeltaAdd = prismContext.deltaFactory().reference().createModificationAdd(ResourceType.F_CONNECTOR_REF,
getResourceDefinition(), connectorDummyOid);
resourceDelta.addModification(connectorRefDeltaAdd);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(resourceDelta);

ModelExecuteOptions options = ModelExecuteOptions.createRaw();

// WHEN
modelService.executeChanges(deltas, options, task, result);
executeChanges(resourceDelta, options, task, result);

// THEN
result.computeStatus();
display("executeChanges result", result);
TestUtil.assertSuccess("executeChanges result", result);
assertSuccess(result);

assertUpgrade(dummyResourceModelBefore);
assertUpgrade(TEST_NAME, dummyResourceModelBefore);
}


@Test
public void test350DowngradeRawAddDelete() throws Exception {
final String TEST_NAME = "test350DowngradeRawAddDelete";
TestUtil.displayTestTitle(this, TEST_NAME);
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
Expand Down Expand Up @@ -464,7 +447,7 @@ public void test350DowngradeRawAddDelete() throws Exception {
@Test
public void test400UpgradeRawReplace() throws Exception {
final String TEST_NAME = "test400UpgradeRawReplace";
TestUtil.displayTestTitle(this, TEST_NAME);
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
Expand All @@ -490,14 +473,14 @@ public void test400UpgradeRawReplace() throws Exception {
display("executeChanges result", result);
TestUtil.assertSuccess("executeChanges result", result);

assertUpgrade(dummyResourceModelBefore);
assertUpgrade(TEST_NAME, dummyResourceModelBefore);
}


@Test
public void test450DowngradeRawReplace() throws Exception {
final String TEST_NAME = "test450DowngradeRawReplace";
TestUtil.displayTestTitle(this, TEST_NAME);
displayTestTitle(TEST_NAME);

// GIVEN
Task task = createTask(TEST_NAME);
Expand All @@ -511,22 +494,19 @@ public void test450DowngradeRawReplace() throws Exception {
ReferenceDelta connectorRefDeltaReplace = prismContext.deltaFactory().reference().createModificationReplace(ResourceType.F_CONNECTOR_REF,
getResourceDefinition(), connectorDummyFakeOid);
resourceDelta.addModification(connectorRefDeltaReplace);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(resourceDelta);

ModelExecuteOptions options = ModelExecuteOptions.createRaw();

// WHEN
modelService.executeChanges(deltas, options, task, result);
executeChanges(resourceDelta, options, task, result);

// THEN
result.computeStatus();
display("executeChanges result", result);
TestUtil.assertSuccess("executeChanges result", result);
assertSuccess(result);

assertDowngrade(dummyResourceModelBefore);
}

private void assertUpgrade(PrismObject<ResourceType> dummyResourceModelBefore) throws ObjectNotFoundException, SchemaException, SecurityViolationException, ObjectAlreadyExistsException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException {
private void assertUpgrade(final String TEST_NAME, PrismObject<ResourceType> dummyResourceModelBefore) throws ObjectNotFoundException, SchemaException, SecurityViolationException, ObjectAlreadyExistsException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException {
Task task = taskManager.createTaskInstance(TestConnectorDummyFake.class.getName() + ".assertUpgrade");
OperationResult result = task.getResult();

Expand All @@ -538,6 +518,7 @@ private void assertUpgrade(PrismObject<ResourceType> dummyResourceModelBefore) t
assertEquals("Wrong connectorRef in fake resource (repo)", connectorDummyOid,
repoResource.asObjectable().getConnectorRef().getOid());

display("HEREHERE: "+TEST_NAME);
// Check if resource view of the model has changed as well
resourceDummyFake = modelService.getObject(ResourceType.class, RESOURCE_DUMMY_FAKE_OID, null, task, result);
display("Upgraded fake resource (model)", resourceDummyFake);
Expand Down
Expand Up @@ -179,6 +179,7 @@ public void test100AddGroupShadowSwashbucklers() throws Exception {
dummyGroup.getAttributeValue(DummyResourceContoller.DUMMY_GROUP_ATTRIBUTE_DESCRIPTION));

assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 0); // MID-4779
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_CONFIGURATION_COUNT, 0);
assertSteadyResources();
}

Expand Down Expand Up @@ -406,6 +407,7 @@ public void test300AddRoleWimp() throws Exception {
assertNoGroupMembers(dummyGroupAtOrange);

assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 0); // MID-4779
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_CONFIGURATION_COUNT, 0);
assertSteadyResources();
}

Expand Down
Expand Up @@ -241,6 +241,7 @@ public void test099ModifyUserAddAccountFailing() throws Exception {
checkDummyTransportMessages("simpleUserNotifier-FAILURE", 0); // This should be called, but it is not implemented now

assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 0); // MID-4779
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_CONFIGURATION_COUNT, 0);
assertSteadyResources();
}

Expand Down Expand Up @@ -1658,6 +1659,7 @@ public void test148ModifyUserJackUnassignAccountPositiveEnforcement() throws Exc

assertCounterIncrement(InternalCounters.SCRIPT_COMPILE_COUNT, 0);
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 0); // MID-4779
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_CONFIGURATION_COUNT, 0);
assertSteadyResources();

// return resource to the previous state..delete assignment enforcement to prevent next test to fail..
Expand Down Expand Up @@ -1740,6 +1742,7 @@ public void test149ModifyUserJackDeleteAccount() throws Exception {

assertCounterIncrement(InternalCounters.SCRIPT_COMPILE_COUNT, 0);
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 0); // MID-4779
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_CONFIGURATION_COUNT, 0);
assertSteadyResources();
}

Expand Down Expand Up @@ -3332,6 +3335,7 @@ public void test300AddUserJackWithAssignmentBlue() throws Exception {
dummyAuditService.assertExecutionSuccess();

assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 0); // MID-4779
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_CONFIGURATION_COUNT, 0);
assertSteadyResources();
}

Expand Down

0 comments on commit d80fece

Please sign in to comment.