use of com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance in project midpoint by Evolveum.
the class ConnectorManager method dispose.
public void dispose() {
Iterator<Entry<ConfiguredConnectorCacheKey, ConfiguredConnectorInstanceEntry>> i = connectorInstanceCache.entrySet().iterator();
while (i.hasNext()) {
Entry<ConfiguredConnectorCacheKey, ConfiguredConnectorInstanceEntry> connectorInstanceCacheEntry = i.next();
ConnectorInstance connectorInstance = connectorInstanceCacheEntry.getValue().getConnectorInstance();
i.remove();
connectorInstance.dispose();
}
}
use of com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance in project midpoint by Evolveum.
the class ConnectorManager method getOrCreateConnectorInstanceCacheEntry.
/**
* Returns connector cache entry with connector instance. The entry may come from the cache or it may be just
* created and not yet cached. In the latter case the connector instance is not yet configured. This is indicated
* by cacheEntry.configuration == null.
*
* No attempt is made to configure the connector instance here. Therefore un-configured or miss-configured
* connector may be returned.
* This is exposed mostly to allow proper handling of errors in the testConnection methods of ResourceManager.
*/
ConfiguredConnectorInstanceEntry getOrCreateConnectorInstanceCacheEntry(ConnectorSpec connectorSpec, OperationResult result) throws ObjectNotFoundException, SchemaException {
ConfiguredConnectorCacheKey cacheKey = connectorSpec.getCacheKey();
ConfiguredConnectorInstanceEntry connectorInstanceCacheEntry = connectorInstanceCache.get(cacheKey);
if (connectorInstanceCacheEntry != null) {
if (!connectorSpec.getConnectorOid().equals(connectorInstanceCacheEntry.getConnectorOid())) {
// This is the case that connectorRef in resource has changed. In this case we can do quite a destructive
// changes. The operations in progress may be affected.
LOGGER.debug("CRITICAL MISS in connector cache: found entry, but connector does not match. Disposing of old connector: {}", connectorInstanceCacheEntry);
connectorInstanceCache.remove(cacheKey);
connectorInstanceCacheEntry.getConnectorInstance().dispose();
} else {
LOGGER.trace("HIT in connector cache: returning configured connector {} from cache", connectorSpec);
return connectorInstanceCacheEntry;
}
}
LOGGER.debug("MISS in connector cache: creating new connector {}", connectorSpec);
// No usable connector in cache. Let's create it.
ConnectorInstance connectorInstance = createConnectorInstance(connectorSpec, result);
ConfiguredConnectorInstanceEntry cacheEntry = new ConfiguredConnectorInstanceEntry();
cacheEntry.setConnectorOid(connectorSpec.getConnectorOid());
// Do NOT set up configuration to cache entry here. The connector is not yet configured.
cacheEntry.setConnectorInstance(connectorInstance);
return cacheEntry;
}
use of com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance in project midpoint by Evolveum.
the class ProvisioningContext method getConnector.
public <T extends CapabilityType> ConnectorInstance getConnector(Class<T> operationCapabilityClass, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
ConnectorInstance connector = connectorMap.get(operationCapabilityClass);
if (connector != null) {
return connector;
}
ConnectorInstance newConnector = getConnectorInstance(operationCapabilityClass, result);
connectorMap.put(operationCapabilityClass, newConnector);
return newConnector;
}
use of com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance in project midpoint by Evolveum.
the class TestDummySchemaless method resourceStaticSchemaResourceAndConnectorCaching.
private void resourceStaticSchemaResourceAndConnectorCaching() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = createOperationResult();
// re-read the resource before tests so we have a clean slate, e.g. configuration properly parsed (no raw elements)
resourceStaticSchema = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_STATIC_SCHEMA_OID, null, task, result);
ConnectorInstance currentConnectorInstance = resourceManager.getConfiguredConnectorInstance(resourceStaticSchema, ReadCapabilityType.class, false, result);
IntegrationTestTools.displayXml("Initialized static schema resource", resourceStaticSchema);
rememberCounter(InternalCounters.RESOURCE_SCHEMA_FETCH_COUNT);
rememberCounter(InternalCounters.CONNECTOR_SCHEMA_PARSE_COUNT);
rememberCounter(InternalCounters.CONNECTOR_CAPABILITIES_FETCH_COUNT);
rememberCounter(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT);
rememberCounter(InternalCounters.CONNECTOR_INSTANCE_CONFIGURATION_COUNT);
rememberCounter(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT);
rememberSchemaMetadata(resourceStaticSchema);
rememberConnectorInstance(currentConnectorInstance);
rememberResourceCacheStats();
ConnectorInstance configuredConnectorInstance = resourceManager.getConfiguredConnectorInstance(resourceStaticSchema, ReadCapabilityType.class, false, result);
assertNotNull("No configuredConnectorInstance", configuredConnectorInstance);
ResourceSchema resourceSchemaBefore = ResourceSchemaFactory.getRawSchema(resourceStaticSchema);
assertNotNull("No resource schema", resourceSchemaBefore);
assertStaticSchemaSanity(resourceSchemaBefore);
// WHEN
when();
PrismObject<ResourceType> resourceAgain = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_STATIC_SCHEMA_OID, null, task, result);
// THEN
then();
assertSuccess(result);
ResourceType resourceTypeAgain = resourceAgain.asObjectable();
assertNotNull("No connector ref", resourceTypeAgain.getConnectorRef());
assertNotNull("No connector ref OID", resourceTypeAgain.getConnectorRef().getOid());
PrismContainer<Containerable> configurationContainer = resourceStaticSchema.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
PrismContainer<Containerable> configurationContainerAgain = resourceAgain.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
assertTrue("Configurations not equivalent", configurationContainer.equivalent(configurationContainerAgain));
// Check resource schema caching
ResourceSchema resourceSchemaAgain = ResourceSchemaFactory.getRawSchema(resourceAgain);
assertNotNull("No resource schema (again)", resourceSchemaAgain);
assertSame("Resource schema was not cached", resourceSchemaBefore, resourceSchemaAgain);
// Check capabilities caching
CapabilitiesType capabilitiesType = resourceStaticSchema.asObjectable().getCapabilities();
assertNotNull("No capabilities fetched from provisioning", capabilitiesType);
CachingMetadataType capCachingMetadataType = capabilitiesType.getCachingMetadata();
assertNotNull("No capabilities caching metadata fetched from provisioning", capCachingMetadataType);
CachingMetadataType capCachingMetadataTypeAgain = resourceTypeAgain.getCapabilities().getCachingMetadata();
assertEquals("Capabilities caching metadata serial number has changed", capCachingMetadataType.getSerialNumber(), capCachingMetadataTypeAgain.getSerialNumber());
assertEquals("Capabilities caching metadata timestamp has changed", capCachingMetadataType.getRetrievalTimestamp(), capCachingMetadataTypeAgain.getRetrievalTimestamp());
// Rough test if everything is fine
resourceStaticSchema.asObjectable().setFetchResult(null);
resourceAgain.asObjectable().setFetchResult(null);
ObjectDelta<ResourceType> dummyResourceDiff = DiffUtil.diff(resourceStaticSchema, resourceAgain);
displayDumpable("Dummy resource diff", dummyResourceDiff);
assertTrue("The resource read again is not the same as the original. diff:" + dummyResourceDiff, dummyResourceDiff.isEmpty());
// Now we stick our nose deep inside the provisioning impl. But we need
// to make sure that the
// configured connector is properly cached
ConnectorInstance configuredConnectorInstanceAgain = resourceManager.getConfiguredConnectorInstance(resourceAgain, ReadCapabilityType.class, false, result);
assertNotNull("No configuredConnectorInstance (again)", configuredConnectorInstanceAgain);
assertSame("Connector instance was not cached", configuredConnectorInstance, configuredConnectorInstanceAgain);
// Check if the connector still works.
OperationResult testResult = createOperationResult("test");
configuredConnectorInstanceAgain.test(testResult);
testResult.computeStatus();
TestUtil.assertSuccess("Connector test failed", testResult);
// Test connection should also refresh the connector by itself. So check if it has been refreshed
ConnectorInstance configuredConnectorInstanceAfterTest = resourceManager.getConfiguredConnectorInstance(resourceAgain, ReadCapabilityType.class, false, result);
assertNotNull("No configuredConnectorInstance (again)", configuredConnectorInstanceAfterTest);
assertSame("Connector instance was not cached", configuredConnectorInstanceAgain, configuredConnectorInstanceAfterTest);
assertSteadyResource();
}
Aggregations