Search in sources :

Example 11 with ConnectorInstance

use of com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance in project midpoint by Evolveum.

the class ConnectorManager method createConnectorInstance.

private ConnectorInstance createConnectorInstance(ConnectorSpec connectorSpec, OperationResult result) throws ObjectNotFoundException, SchemaException {
    ConnectorType connectorBean = getConnector(connectorSpec, result);
    ConnectorFactory connectorFactory = determineConnectorFactory(connectorBean);
    ConnectorInstance connectorInstance;
    try {
        InternalMonitor.recordCount(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT);
        connectorInstance = connectorFactory.createConnectorInstance(connectorBean, connectorSpec.getResource().getName().toString(), connectorSpec.toString());
        // FIXME temporary -- remove when no longer needed (MID-5931)
        if (connectorInstance instanceof AbstractManagedConnectorInstance) {
            ((AbstractManagedConnectorInstance) connectorInstance).setResourceOid(connectorSpec.getResource().getOid());
        }
    } catch (ObjectNotFoundException e) {
        result.recordFatalError(e.getMessage(), e);
        throw new ObjectNotFoundException(e.getMessage(), e);
    }
    // This log message should be INFO level. It happens only occasionally.
    // If it happens often, it may be an
    // indication of a problem. Therefore it is good for admin to see it.
    LOGGER.info("Created new connector instance for {}: {} v{}", connectorSpec, connectorBean.getConnectorType(), connectorBean.getConnectorVersion());
    return connectorInstance;
}
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) ConnectorFactory(com.evolveum.midpoint.provisioning.ucf.api.ConnectorFactory) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) AbstractManagedConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.connectors.AbstractManagedConnectorInstance)

Example 12 with ConnectorInstance

use of com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance in project midpoint by Evolveum.

the class TestOpenDj method test004ResourceAndConnectorCaching.

@Test
public void test004ResourceAndConnectorCaching() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    resource = provisioningService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, task, result);
    resourceBean = resource.asObjectable();
    ConnectorInstance configuredConnectorInstance = resourceManager.getConfiguredConnectorInstance(resource, ReadCapabilityType.class, false, result);
    assertNotNull("No configuredConnectorInstance", configuredConnectorInstance);
    ResourceSchema resourceSchema = ResourceSchemaFactory.getRawSchema(resource);
    assertNotNull("No resource schema", resourceSchema);
    // WHEN
    PrismObject<ResourceType> resourceAgain = provisioningService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, task, result);
    // THEN
    ResourceType resourceTypeAgain = resourceAgain.asObjectable();
    assertNotNull("No connector ref", resourceTypeAgain.getConnectorRef());
    assertNotNull("No connector ref OID", resourceTypeAgain.getConnectorRef().getOid());
    PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    PrismContainer<Containerable> configurationContainerAgain = resourceAgain.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    assertTrue("Configurations not equivalent", configurationContainer.equivalent(configurationContainerAgain));
    assertEquals("Configurations not equals", configurationContainerAgain, configurationContainer);
    ResourceSchema resourceSchemaAgain = ResourceSchemaFactory.getRawSchema(resourceAgain);
    assertNotNull("No resource schema (again)", resourceSchemaAgain);
    assertEquals("Schema serial number mismatch", resourceBean.getSchema().getCachingMetadata().getSerialNumber(), resourceTypeAgain.getSchema().getCachingMetadata().getSerialNumber());
    assertSame("Resource schema was not cached", resourceSchema, resourceSchemaAgain);
    // 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);
    assertSame("Connector instance was not cached", configuredConnectorInstance, configuredConnectorInstanceAgain);
    assertShadows(1);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 13 with ConnectorInstance

use of com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance in project midpoint by Evolveum.

the class ResourceObjectReferenceResolver method fetchResourceObject.

PrismObject<ShadowType> fetchResourceObject(ProvisioningContext ctx, Collection<? extends ResourceAttribute<?>> identifiers, AttributesToReturn attributesToReturn, @Nullable PrismObject<ShadowType> repoShadow, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
    ConnectorInstance connector = ctx.getConnector(ReadCapabilityType.class, parentResult);
    ResourceObjectDefinition objectDefinition = ctx.getObjectDefinitionRequired();
    try {
        ReadCapabilityType readCapability = ctx.getEffectiveCapability(ReadCapabilityType.class);
        if (readCapability == null) {
            throw new UnsupportedOperationException("Resource does not support 'read' operation: " + ctx.toHumanReadableDescription());
        }
        if (Boolean.TRUE.equals(readCapability.isCachingOnly())) {
            return repoShadow;
        }
        ResourceObjectIdentification identification = ResourceObjectIdentification.create(objectDefinition, identifiers);
        ResourceObjectIdentification resolvedIdentification = resolvePrimaryIdentifiers(ctx, identification, parentResult);
        resolvedIdentification.validatePrimaryIdentifiers();
        return connector.fetchObject(resolvedIdentification, attributesToReturn, ctx.getUcfExecutionContext(), parentResult);
    } catch (ObjectNotFoundException e) {
        // Not finishing the result because we did not create it! (The same for other catch clauses.)
        parentResult.recordFatalErrorNotFinish("Object not found. Identifiers: " + identifiers + ". Reason: " + e.getMessage(), e);
        throw new ObjectNotFoundException("Object not found. identifiers=" + identifiers + ", objectclass=" + PrettyPrinter.prettyPrint(objectDefinition.getTypeName()) + ": " + e.getMessage(), e, repoShadow != null ? repoShadow.getOid() : null);
    } catch (CommunicationException e) {
        parentResult.recordFatalErrorNotFinish("Error communication with the connector " + connector + ": " + e.getMessage(), e);
        throw e;
    } catch (GenericFrameworkException e) {
        parentResult.recordFatalErrorNotFinish("Generic error in the connector " + connector + ". Reason: " + e.getMessage(), e);
        throw new GenericConnectorException("Generic error in the connector " + connector + ". Reason: " + e.getMessage(), e);
    } catch (SchemaException ex) {
        parentResult.recordFatalErrorNotFinish("Can't get resource object, schema error: " + ex.getMessage(), ex);
        throw ex;
    } catch (ExpressionEvaluationException ex) {
        parentResult.recordFatalErrorNotFinish("Can't get resource object, expression error: " + ex.getMessage(), ex);
        throw ex;
    } catch (ConfigurationException e) {
        parentResult.recordFatalErrorNotFinish(e);
        throw e;
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) ReadCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ReadCapabilityType) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) ResourceObjectIdentification(com.evolveum.midpoint.schema.processor.ResourceObjectIdentification) GenericConnectorException(com.evolveum.midpoint.provisioning.api.GenericConnectorException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 14 with ConnectorInstance

use of com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance in project midpoint by Evolveum.

the class AbstractProvisioningIntegrationTest method assertConnectorInstanceUnchanged.

protected void assertConnectorInstanceUnchanged(PrismObject<ResourceType> resource) throws SchemaException {
    if (lastConfiguredConnectorInstance == null) {
        return;
    }
    ConnectorInstance currentConfiguredConnectorInstance = resourceManager.getConfiguredConnectorInstanceFromCache(resource, ReadCapabilityType.class);
    assertSame("Connector instance has changed", lastConfiguredConnectorInstance, currentConfiguredConnectorInstance);
}
Also used : ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance)

Example 15 with ConnectorInstance

use of com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance in project midpoint by Evolveum.

the class ProvisioningContext method getConnectorInstance.

private <T extends CapabilityType> ConnectorInstance getConnectorInstance(Class<T> operationCapabilityClass, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    OperationResult connectorResult = parentResult.createMinorSubresult(ProvisioningContext.class.getName() + ".getConnectorInstance");
    try {
        ConnectorInstance connector = resourceManager.getConfiguredConnectorInstance(getResource().asPrismObject(), operationCapabilityClass, false, parentResult);
        connectorResult.recordSuccess();
        return connector;
    } catch (ObjectNotFoundException | SchemaException e) {
        connectorResult.recordPartialError("Could not get connector instance " + getDesc() + ": " + e.getMessage(), e);
        // throw ObjectNotFoundException here.
        throw new ConfigurationException(e.getMessage(), e);
    } catch (CommunicationException | ConfigurationException | SystemException e) {
        connectorResult.recordPartialError("Could not get connector instance " + getDesc() + ": " + e.getMessage(), e);
        throw e;
    }
}
Also used : ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

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