Search in sources :

Example 6 with ConnectorConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType in project midpoint by Evolveum.

the class ResourceManager method testConnectionConnector.

public void testConnectionConnector(ConnectorSpec connectorSpec, Map<String, Collection<Object>> capabilityMap, Task task, OperationResult parentResult) {
    // === test INITIALIZATION ===
    OperationResult initResult = parentResult.createSubresult(ConnectorTestOperation.CONNECTOR_INITIALIZATION.getOperation());
    ConnectorInstance connector;
    try {
        // TODO: this returns configured instance. Then there is another configuration down below.
        // this means double configuration of the connector. TODO: clean this up
        connector = connectorManager.getConfiguredConnectorInstance(connectorSpec, true, initResult);
        initResult.recordSuccess();
    } catch (ObjectNotFoundException e) {
        // The connector was not found. The resource definition is either
        // wrong or the connector is not
        // installed.
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        initResult.recordFatalError("The connector was not found: " + e.getMessage(), e);
        return;
    } catch (SchemaException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        initResult.recordFatalError("Schema error while dealing with the connector definition: " + e.getMessage(), e);
        return;
    } catch (RuntimeException | Error e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        initResult.recordFatalError("Unexpected runtime error: " + e.getMessage(), e);
        return;
    } catch (CommunicationException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        initResult.recordFatalError("Communication error: " + e.getMessage(), e);
        return;
    } catch (ConfigurationException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        initResult.recordFatalError("Configuration error: " + e.getMessage(), e);
        return;
    }
    LOGGER.debug("Testing connection using {}", connectorSpec);
    // === test CONFIGURATION ===
    OperationResult configResult = parentResult.createSubresult(ConnectorTestOperation.CONNECTOR_CONFIGURATION.getOperation());
    try {
        PrismObject<ResourceType> resource = connectorSpec.getResource();
        PrismObjectDefinition<ResourceType> newResourceDefinition = resource.getDefinition().clone();
        applyConnectorSchemaToResource(connectorSpec, newResourceDefinition, resource, task, configResult);
        PrismContainerValue<ConnectorConfigurationType> connectorConfiguration = connectorSpec.getConnectorConfiguration().getValue();
        connector.configure(connectorConfiguration, configResult);
        configResult.recordSuccess();
    } catch (CommunicationException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        configResult.recordFatalError("Communication error", e);
        return;
    } catch (GenericFrameworkException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        configResult.recordFatalError("Generic error", e);
        return;
    } catch (SchemaException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        configResult.recordFatalError("Schema error", e);
        return;
    } catch (ConfigurationException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        configResult.recordFatalError("Configuration error", e);
        return;
    } catch (ObjectNotFoundException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        configResult.recordFatalError("Object not found", e);
        return;
    } catch (ExpressionEvaluationException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        configResult.recordFatalError("Expression error", e);
        return;
    } catch (RuntimeException | Error e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        configResult.recordFatalError("Unexpected runtime error", e);
        return;
    }
    // === test CONNECTION ===
    // delegate the main part of the test to the connector
    connector.test(parentResult);
    parentResult.computeStatus();
    if (!parentResult.isAcceptable()) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.DOWN, parentResult);
        // messages.
        return;
    } else {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.UP, parentResult);
    }
    OperationResult capabilitiesResult = parentResult.createSubresult(ConnectorTestOperation.CONNECTOR_CAPABILITIES.getOperation());
    try {
        InternalMonitor.recordConnectorCapabilitiesFetchCount();
        Collection<Object> capabilities = connector.fetchCapabilities(capabilitiesResult);
        capabilityMap.put(connectorSpec.getConnectorName(), capabilities);
        capabilitiesResult.recordSuccess();
    } catch (CommunicationException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        capabilitiesResult.recordFatalError("Communication error", e);
        return;
    } catch (GenericFrameworkException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        capabilitiesResult.recordFatalError("Generic error", e);
        return;
    } catch (ConfigurationException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        capabilitiesResult.recordFatalError("Configuration error", e);
        return;
    } catch (RuntimeException | Error e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        capabilitiesResult.recordFatalError("Unexpected runtime error", e);
        return;
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 7 with ConnectorConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType in project midpoint by Evolveum.

the class ResourceManager method applyConnectorSchemaToResource.

/**
	 * Apply proper definition (connector schema) to the resource.
	 */
private void applyConnectorSchemaToResource(ConnectorSpec connectorSpec, PrismObjectDefinition<ResourceType> resourceDefinition, PrismObject<ResourceType> resource, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    ConnectorType connectorType = connectorManager.getConnectorTypeReadOnly(connectorSpec, result);
    PrismSchema connectorSchema = connectorManager.getConnectorSchema(connectorType);
    if (connectorSchema == null) {
        throw new SchemaException("No connector schema in " + connectorType);
    }
    PrismContainerDefinition<ConnectorConfigurationType> configurationContainerDefinition = ConnectorTypeUtil.findConfigurationContainerDefinition(connectorType, connectorSchema);
    if (configurationContainerDefinition == null) {
        throw new SchemaException("No configuration container definition in schema of " + connectorType);
    }
    configurationContainerDefinition = configurationContainerDefinition.clone();
    PrismContainer<ConnectorConfigurationType> configurationContainer = connectorSpec.getConnectorConfiguration();
    // the element is global in the connector schema. therefore it does not have correct maxOccurs
    if (configurationContainer != null) {
        configurationContainerDefinition.adoptElementDefinitionFrom(configurationContainer.getDefinition());
        configurationContainer.applyDefinition(configurationContainerDefinition, true);
        try {
            configurationContainer.accept(visitable -> {
                if ((visitable instanceof PrismProperty<?>)) {
                    try {
                        evaluateExpression((PrismProperty<?>) visitable, resource, task, result);
                    } catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException e) {
                        throw new TunnelException(e);
                    }
                }
            });
        } catch (TunnelException te) {
            Throwable e = te.getCause();
            if (e instanceof SchemaException) {
                throw (SchemaException) e;
            } else if (e instanceof ObjectNotFoundException) {
                throw (ObjectNotFoundException) e;
            } else if (e instanceof ExpressionEvaluationException) {
                throw (ExpressionEvaluationException) e;
            } else if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else if (e instanceof Error) {
                throw (Error) e;
            } else {
                throw new SystemException(e);
            }
        }
    } else {
        configurationContainerDefinition.adoptElementDefinitionFrom(resourceDefinition.findContainerDefinition(ResourceType.F_CONNECTOR_CONFIGURATION));
    }
    if (connectorSpec.getConnectorName() == null) {
        // Default connector, for compatibility
        // It does not make sense to update this for any other connectors.
        // We cannot have one definition for addiitionalConnector[1]/connectorConfiguraiton and
        // different definition for addiitionalConnector[2]/connectorConfiguraiton in the object definition.
        // The way to go is to set up definitions on the container level.
        resourceDefinition.replaceDefinition(ResourceType.F_CONNECTOR_CONFIGURATION, configurationContainerDefinition);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) TunnelException(com.evolveum.midpoint.util.exception.TunnelException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 8 with ConnectorConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType in project midpoint by Evolveum.

the class TestUcfDummyMulti method test020CreateConfiguredConnector.

@Test
public void test020CreateConfiguredConnector() throws Exception {
    final String TEST_NAME = "test020CreateConfiguredConnector";
    TestUtil.displayTestTile(TEST_NAME);
    cc = connectorFactory.createConnectorInstance(connectorType, ResourceTypeUtil.getResourceNamespace(resourceType), "test connector");
    assertNotNull("Failed to instantiate connector", cc);
    OperationResult result = new OperationResult(TestUcfDummyMulti.class.getName() + "." + TEST_NAME);
    PrismContainerValue<ConnectorConfigurationType> configContainer = resourceType.getConnectorConfiguration().asPrismContainerValue();
    display("Configuration container", configContainer);
    // WHEN
    cc.configure(configContainer, result);
    // THEN
    result.computeStatus();
    TestUtil.assertSuccess(result);
    resourceSchema = cc.fetchResourceSchema(null, result);
    assertNotNull("No resource schema", resourceSchema);
}
Also used : ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 9 with ConnectorConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType in project midpoint by Evolveum.

the class TestUcfDummyMulti method test000PrismContextSanity.

@Test
public void test000PrismContextSanity() throws Exception {
    final String TEST_NAME = "test000PrismContextSanity";
    TestUtil.displayTestTile(TEST_NAME);
    SchemaRegistry schemaRegistry = PrismTestUtil.getPrismContext().getSchemaRegistry();
    PrismSchema schemaIcfc = schemaRegistry.findSchemaByNamespace(SchemaConstants.NS_ICF_CONFIGURATION);
    assertNotNull("ICFC schema not found in the context (" + SchemaConstants.NS_ICF_CONFIGURATION + ")", schemaIcfc);
    PrismContainerDefinition<ConnectorConfigurationType> configurationPropertiesDef = schemaIcfc.findContainerDefinitionByElementName(SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_PROPERTIES_ELEMENT_QNAME);
    assertNotNull("icfc:configurationProperties not found in icfc schema (" + SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_PROPERTIES_ELEMENT_QNAME + ")", configurationPropertiesDef);
    PrismSchema schemaIcfs = schemaRegistry.findSchemaByNamespace(SchemaConstants.NS_ICF_SCHEMA);
    assertNotNull("ICFS schema not found in the context (" + SchemaConstants.NS_ICF_SCHEMA + ")", schemaIcfs);
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) Test(org.testng.annotations.Test)

Example 10 with ConnectorConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType in project midpoint by Evolveum.

the class TestUcfDummy method test030ResourceSchema.

@Test
public void test030ResourceSchema() throws Exception {
    final String TEST_NAME = "test030ResourceSchema";
    TestUtil.displayTestTile(TEST_NAME);
    OperationResult result = new OperationResult(TestUcfDummy.class + "." + TEST_NAME);
    cc = connectorFactory.createConnectorInstance(connectorType, ResourceTypeUtil.getResourceNamespace(resourceType), "test connector");
    assertNotNull("Failed to instantiate connector", cc);
    PrismContainerValue<ConnectorConfigurationType> configContainer = resourceType.getConnectorConfiguration().asPrismContainerValue();
    display("Configuration container", configContainer);
    cc.configure(configContainer, result);
    // WHEN
    resourceSchema = cc.fetchResourceSchema(null, result);
    // THEN
    display("Generated resource schema", resourceSchema);
    assertEquals("Unexpected number of definitions", 4, resourceSchema.getDefinitions().size());
    dummyResourceCtl.assertDummyResourceSchemaSanityExtended(resourceSchema, resourceType, true);
    Document xsdSchemaDom = resourceSchema.serializeToXsd();
    assertNotNull("No serialized resource schema", xsdSchemaDom);
    display("Serialized XSD resource schema", DOMUtil.serializeDOMToString(xsdSchemaDom));
    // Try to re-parse
    ResourceSchema reparsedResourceSchema = ResourceSchemaImpl.parse(DOMUtil.getFirstChildElement(xsdSchemaDom), "serialized schema", PrismTestUtil.getPrismContext());
    display("Re-parsed resource schema", reparsedResourceSchema);
    assertEquals("Unexpected number of definitions in re-parsed schema", 4, reparsedResourceSchema.getDefinitions().size());
    dummyResourceCtl.assertDummyResourceSchemaSanityExtended(reparsedResourceSchema, resourceType, true);
}
Also used : ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Document(org.w3c.dom.Document) Test(org.testng.annotations.Test)

Aggregations

ConnectorConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType)14 Test (org.testng.annotations.Test)7 PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)4 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)4 QName (javax.xml.namespace.QName)4 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)3 SystemException (com.evolveum.midpoint.util.exception.SystemException)3 Element (org.w3c.dom.Element)3 ConnectorInstance (com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance)2 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)2 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)2 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)2 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)2 ArrayList (java.util.ArrayList)2 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)1 PrismContext (com.evolveum.midpoint.prism.PrismContext)1