Search in sources :

Example 26 with ConnectorInstance

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();
    }
}
Also used : Entry(java.util.Map.Entry) ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) AbstractManagedConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.connectors.AbstractManagedConnectorInstance) AbstractManualConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.connectors.AbstractManualConnectorInstance)

Example 27 with ConnectorInstance

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;
}
Also used : ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) AbstractManagedConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.connectors.AbstractManagedConnectorInstance) AbstractManualConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.connectors.AbstractManualConnectorInstance)

Example 28 with ConnectorInstance

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;
}
Also used : ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance)

Example 29 with ConnectorInstance

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();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Containerable(com.evolveum.midpoint.prism.Containerable)

Aggregations

ConnectorInstance (com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance)29 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)10 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)10 GenericConnectorException (com.evolveum.midpoint.provisioning.api.GenericConnectorException)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 Test (org.testng.annotations.Test)5 AbstractManagedConnectorInstance (com.evolveum.midpoint.provisioning.ucf.api.connectors.AbstractManagedConnectorInstance)4 AbstractManualConnectorInstance (com.evolveum.midpoint.provisioning.ucf.api.connectors.AbstractManualConnectorInstance)4 ResourceObjectIdentification (com.evolveum.midpoint.schema.processor.ResourceObjectIdentification)4 Task (com.evolveum.midpoint.task.api.Task)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)4 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)3 Containerable (com.evolveum.midpoint.prism.Containerable)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)3 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)3 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)3 QName (javax.xml.namespace.QName)3 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)2