Skip to content

Commit

Permalink
Stop caching connectors with ad-hoc configuration
Browse files Browse the repository at this point in the history
When a connector is instantiated for a "custom" resource object
(i.e., one that was not retrieved from repository, but provided to
ProvisioningService by the caller), we no longer put it into the
connector instance cache (MID-8020).

Also, this commit reorders initial test methods in AbstractLdapTest
in conntests to the state where they used to fail exactly because
the above bug. So, this effectively reverts point #1
in dd57025.

Resolves MID-8020.
  • Loading branch information
mederly committed Sep 29, 2022
1 parent 253c038 commit 20c691e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,6 @@ public Object executeScript(
return null;
}

@Override
public @NotNull OperationResult testResource(
@NotNull String resourceOid,
@NotNull Task task,
@NotNull OperationResult parentResult) {
throw new UnsupportedOperationException();
}

@Override
public @NotNull OperationResult testResource(
@NotNull PrismObject<ResourceType> resource,
Expand All @@ -169,22 +161,6 @@ public Object executeScript(
return null;
}

@Override
public @NotNull OperationResult testResource(
@NotNull PrismObject<ResourceType> resource,
@NotNull Task task,
OperationResult parentResult) {
throw new UnsupportedOperationException();
}

@Override
public @NotNull OperationResult testPartialConfiguration(
@NotNull PrismObject<ResourceType> resource,
@NotNull Task task,
@NotNull OperationResult parentResult) {
throw new UnsupportedOperationException();
}

@Override
public @NotNull DiscoveredConfiguration discoverConfiguration(
@NotNull PrismObject<ResourceType> resource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ResourceTestOptions extends AbstractOptions implements Serializable
/** Full or partial? */
private final TestMode testMode;

/** Whether to update cached (in-definition) capabilities and schema. */
/** Whether to update repo-cached (in-definition) capabilities and schema. */
private final ResourceCompletionMode resourceCompletionMode;

/**
Expand All @@ -35,29 +35,37 @@ public class ResourceTestOptions extends AbstractOptions implements Serializable
*/
private final Boolean updateInMemory;

/**
* If `true`, the connector is not cached (even if completion is requested). This is to avoid caching resource objects
* that have been provided by the client, i.e. that are not fetched right from the repository. See MID-8020.
*/
private final boolean doNotCacheConnector;

public static final ResourceTestOptions DEFAULT = new ResourceTestOptions();

public ResourceTestOptions() {
this(null, null, null, null);
this(null, null, null, null, false);
}

public ResourceTestOptions(
private ResourceTestOptions(
TestMode testMode,
ResourceCompletionMode resourceCompletionMode,
Boolean updateInRepository,
Boolean updateInMemory) {
Boolean updateInMemory,
boolean doNotCacheConnector) {
this.testMode = testMode;
this.resourceCompletionMode = resourceCompletionMode;
this.updateInRepository = updateInRepository;
this.updateInMemory = updateInMemory;
this.doNotCacheConnector = doNotCacheConnector;
}

public TestMode getTestMode() {
return testMode;
}

public ResourceTestOptions testMode(TestMode testMode) {
return new ResourceTestOptions(testMode, resourceCompletionMode, updateInRepository, updateInMemory);
return new ResourceTestOptions(testMode, resourceCompletionMode, updateInRepository, updateInMemory, doNotCacheConnector);
}

public static ResourceTestOptions partial() {
Expand All @@ -73,23 +81,31 @@ public ResourceCompletionMode getResourceCompletionMode() {
}

public ResourceTestOptions resourceCompletionMode(ResourceCompletionMode resourceCompletionMode) {
return new ResourceTestOptions(testMode, resourceCompletionMode, updateInRepository, updateInMemory);
return new ResourceTestOptions(testMode, resourceCompletionMode, updateInRepository, updateInMemory, doNotCacheConnector);
}

public Boolean isUpdateInRepository() {
return updateInRepository;
}

public ResourceTestOptions updateInRepository(Boolean updateInRepository) {
return new ResourceTestOptions(testMode, resourceCompletionMode, updateInRepository, updateInMemory);
return new ResourceTestOptions(testMode, resourceCompletionMode, updateInRepository, updateInMemory, doNotCacheConnector);
}

public Boolean isUpdateInMemory() {
return updateInMemory;
}

public ResourceTestOptions updateInMemory(Boolean updateInMemory) {
return new ResourceTestOptions(testMode, resourceCompletionMode, updateInRepository, updateInMemory);
return new ResourceTestOptions(testMode, resourceCompletionMode, updateInRepository, updateInMemory, doNotCacheConnector);
}

public boolean isDoNotCacheConnector() {
return doNotCacheConnector;
}

public ResourceTestOptions doNotCacheConnector() {
return new ResourceTestOptions(testMode, resourceCompletionMode, updateInRepository, updateInMemory, true);
}

// Note: the object is immutable, so actually there's no need to use this method.
Expand Down Expand Up @@ -117,6 +133,7 @@ public void shortDump(StringBuilder sb) {
appendVal(sb, "resourceCompletionMode", resourceCompletionMode);
appendFlag(sb, "updateInRepository", updateInRepository);
appendFlag(sb, "updateInMemory", updateInMemory);
appendFlag(sb, "doNotCacheConnector", doNotCacheConnector);
removeLastComma(sb);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ public Object executeScript(String resourceOid, ProvisioningScriptType script, T
options = options.updateInRepository(false);
}

options = options.doNotCacheConnector(); // MID-8020
return testResourceInternal(resource, options, task, result);
} catch (Throwable t) {
result.recordFatalError(t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,9 @@ public void execute(OperationResult result) throws TestFailedException {
testConnector(result);
if (options.isFullMode()) {
fetchConnectorCapabilities(result);
cacheConfiguredConnector();
if (!options.isDoNotCacheConnector()) {
cacheConfiguredConnector();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,19 +339,13 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
}

@Test
public void test010PartialConfigurationResourceObject() throws Exception {
public void test010Connection() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
PrismObject<ResourceType> resourceFromRepo = getObject(ResourceType.class, getResourceOid());
ResourceType resource = new ResourceType()
.name("newResource")
.connectorRef(resourceFromRepo.asObjectable().getConnectorRef())
.connectorConfiguration(resourceFromRepo.asObjectable().getConnectorConfiguration());

OperationResult testResult = provisioningService.testPartialConfiguration(resource.asPrismObject(), task, result);
OperationResult testResult = provisioningService.testResource(getResourceOid(), task, task.getResult());

display("Test partial configuration of resource result", testResult);
TestUtil.assertSuccess("Test partial configuration of resource failed", testResult);
display("Test connection result", testResult);
TestUtil.assertSuccess("Test connection failed", testResult);

if (isAssertOpenFiles()) {
// Set lsof baseline only after the first connection.
Expand All @@ -360,16 +354,22 @@ public void test010PartialConfigurationResourceObject() throws Exception {
displayDumpable("lsof baseline", lsof);
}

displayXml("Resource after test connection", resource.asPrismObject());

assertNull("Resource was saved to repo, during partial configuration test", findObjectByName(ResourceType.class, "newResource"));
resource = getObject(ResourceType.class, getResourceOid());
displayXml("Resource after test connection", resource);
}

@Test
public void test011Connection() throws Exception {
public void test011ConnectionResourceObject() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
PrismObject<ResourceType> resourceFromRepo = getObject(ResourceType.class, getResourceOid());
ResourceType resource = new ResourceType()
.name("newResource")
.connectorRef(resourceFromRepo.asObjectable().getConnectorRef())
.connectorConfiguration(resourceFromRepo.asObjectable().getConnectorConfiguration())
.schema(resourceFromRepo.asObjectable().getSchema());

OperationResult testResult = provisioningService.testResource(getResourceOid(), task, task.getResult());
OperationResult testResult = provisioningService.testResource(resource.asPrismObject(), task, result);

display("Test connection result", testResult);
TestUtil.assertSuccess("Test connection failed", testResult);
Expand All @@ -381,25 +381,25 @@ public void test011Connection() throws Exception {
displayDumpable("lsof baseline", lsof);
}

resource = getObject(ResourceType.class, getResourceOid());
displayXml("Resource after test connection", resource);
displayXml("Resource after test connection", resource.asPrismObject());

assertNull("Resource was saved to repo, during partial configuration test", findObjectByName(ResourceType.class, "newResource"));
}

@Test
public void test012ConnectionResourceObject() throws Exception {
public void test012PartialConfigurationResourceObject() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
PrismObject<ResourceType> resourceFromRepo = getObject(ResourceType.class, getResourceOid());
ResourceType resource = new ResourceType()
.name("newResource")
.connectorRef(resourceFromRepo.asObjectable().getConnectorRef())
.connectorConfiguration(resourceFromRepo.asObjectable().getConnectorConfiguration())
.schema(resourceFromRepo.asObjectable().getSchema());
.connectorConfiguration(resourceFromRepo.asObjectable().getConnectorConfiguration());

OperationResult testResult = provisioningService.testResource(resource.asPrismObject(), task, result);
OperationResult testResult = provisioningService.testPartialConfiguration(resource.asPrismObject(), task, result);

display("Test connection result", testResult);
TestUtil.assertSuccess("Test connection failed", testResult);
display("Test partial configuration of resource result", testResult);
TestUtil.assertSuccess("Test partial configuration of resource failed", testResult);

if (isAssertOpenFiles()) {
// Set lsof baseline only after the first connection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ public void test020Schema() throws Exception {
}
assertEquals("Unexpected number of schema definitions (limited by generation constraints)", expectedDefinitions, resourceSchema.getDefinitions().size());

assertLdapConnectorReasonableInstances();
// Not checking the number of connector instances: the previous operation might have been "test partial configuration"
// that leaves no cached connector instances.
}

@Test
Expand Down

0 comments on commit 20c691e

Please sign in to comment.