Search in sources :

Example 1 with ConnectorFactory

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

the class ConnectorManager method discoverConnectors.

/**
	 * Lists local connectors and makes sure that appropriate ConnectorType
	 * objects for them exist in repository.
	 * 
	 * It will never delete any repository object, even if the corresponding
	 * connector cannot be found. The connector may temporarily removed, may be
	 * present on a different node, manual upgrade may be needed etc.
	 * 
	 * @return set of discovered connectors (new connectors found)
	 * @throws CommunicationException
	 */
//	@SuppressWarnings("unchecked")
public Set<ConnectorType> discoverConnectors(ConnectorHostType hostType, OperationResult parentResult) throws CommunicationException {
    OperationResult result = parentResult.createSubresult(ConnectorManager.class.getName() + ".discoverConnectors");
    result.addParam("host", hostType);
    // it
    if (hostType != null && hostType.getOid() == null) {
        throw new SystemException("Discovery attempt with non-persistent " + hostType);
    }
    Set<ConnectorType> discoveredConnectors = new HashSet<ConnectorType>();
    for (ConnectorFactory connectorFactory : getConnectorFactories()) {
        Set<ConnectorType> foundConnectors;
        try {
            foundConnectors = connectorFactory.listConnectors(hostType, result);
        } catch (CommunicationException ex) {
            result.recordFatalError("Discovery failed: " + ex.getMessage(), ex);
            throw new CommunicationException("Discovery failed: " + ex.getMessage(), ex);
        }
        if (foundConnectors == null) {
            LOGGER.trace("Connector factory {} discovered null connectors, skipping", connectorFactory);
            continue;
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Got {} connectors from {}: {}", new Object[] { foundConnectors.size(), hostType, foundConnectors });
        }
        for (ConnectorType foundConnector : foundConnectors) {
            LOGGER.trace("Found connector {}", foundConnector);
            boolean inRepo = true;
            try {
                inRepo = isInRepo(foundConnector, result);
            } catch (SchemaException e1) {
                LOGGER.error("Unexpected schema problem while checking existence of " + ObjectTypeUtil.toShortString(foundConnector), e1);
                result.recordPartialError("Unexpected schema problem while checking existence of " + ObjectTypeUtil.toShortString(foundConnector), e1);
            // But continue otherwise ...
            }
            if (!inRepo) {
                LOGGER.trace("Connector {} not in the repository, \"dicovering\" it", foundConnector);
                // itself
                if (hostType != null && foundConnector.getConnectorHost() == null) {
                    foundConnector.setConnectorHost(hostType);
                }
                if (foundConnector.getSchema() == null) {
                    LOGGER.warn("Connector {} haven't provided configuration schema", foundConnector);
                }
                // Sanitize framework-supplied OID
                if (StringUtils.isNotEmpty(foundConnector.getOid())) {
                    LOGGER.warn("Provisioning framework " + foundConnector.getFramework() + " supplied OID for connector " + ObjectTypeUtil.toShortString(foundConnector));
                    foundConnector.setOid(null);
                }
                // Store the connector object
                String oid;
                try {
                    prismContext.adopt(foundConnector);
                    oid = repositoryService.addObject(foundConnector.asPrismObject(), null, result);
                } catch (ObjectAlreadyExistsException e) {
                    // We don't specify the OID, therefore this should never
                    // happen
                    // Convert to runtime exception
                    LOGGER.error("Got ObjectAlreadyExistsException while not expecting it: " + e.getMessage(), e);
                    result.recordFatalError("Got ObjectAlreadyExistsException while not expecting it: " + e.getMessage(), e);
                    throw new SystemException("Got ObjectAlreadyExistsException while not expecting it: " + e.getMessage(), e);
                } catch (SchemaException e) {
                    // If there is a schema error it must be a bug. Convert to
                    // runtime exception
                    LOGGER.error("Got SchemaException while not expecting it: " + e.getMessage(), e);
                    result.recordFatalError("Got SchemaException while not expecting it: " + e.getMessage(), e);
                    throw new SystemException("Got SchemaException while not expecting it: " + e.getMessage(), e);
                }
                foundConnector.setOid(oid);
                discoveredConnectors.add(foundConnector);
                LOGGER.info("Discovered new connector " + foundConnector);
            }
        }
    }
    result.recordSuccess();
    return discoveredConnectors;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) ConnectorFactory(com.evolveum.midpoint.provisioning.ucf.api.ConnectorFactory) SystemException(com.evolveum.midpoint.util.exception.SystemException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) HashSet(java.util.HashSet)

Example 2 with ConnectorFactory

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

the class TestConnectorManager method test100ListConnectorFactories.

@Test
public void test100ListConnectorFactories() throws Exception {
    final String TEST_NAME = "test100ListConnectorFactories";
    TestUtil.displayTestTile(TEST_NAME);
    OperationResult result = new OperationResult(TestConnectorDiscovery.class.getName() + "." + TEST_NAME);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    Collection<ConnectorFactory> connectorFactories = connectorManager.getConnectorFactories();
    // THEN
    TestUtil.displayThen(TEST_NAME);
    assertNotNull("Null connector factories", connectorFactories);
    assertFalse("No connector factories found", connectorFactories.isEmpty());
    display("Found " + connectorFactories.size() + " connector factories");
    result.computeStatus();
    TestUtil.assertSuccess(result);
    for (ConnectorFactory connectorFactory : connectorFactories) {
        display("Found connector factory " + connectorFactory, connectorFactory);
    }
    PrismAsserts.assertEqualsUnordered("Wrong connector factories", connectorFactories.stream().map(x -> x.getClass().getName()), "com.evolveum.midpoint.provisioning.ucf.impl.connid.ConnectorFactoryConnIdImpl", "com.evolveum.midpoint.provisioning.ucf.impl.builtin.ConnectorFactoryBuiltinImpl");
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) ConnectorFactory(com.evolveum.midpoint.provisioning.ucf.api.ConnectorFactory) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) Trace(com.evolveum.midpoint.util.logging.Trace) IntegrationTestTools(com.evolveum.midpoint.test.IntegrationTestTools) TestUtil(com.evolveum.midpoint.test.util.TestUtil) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) PrismAsserts(com.evolveum.midpoint.prism.util.PrismAsserts) Collection(java.util.Collection) AssertJUnit.assertFalse(org.testng.AssertJUnit.assertFalse) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) IntegrationTestTools.display(com.evolveum.midpoint.test.IntegrationTestTools.display) QueryBuilder(com.evolveum.midpoint.prism.query.builder.QueryBuilder) List(java.util.List) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ProvisioningService(com.evolveum.midpoint.provisioning.api.ProvisioningService) AssertJUnit.assertNotNull(org.testng.AssertJUnit.assertNotNull) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ConnectorFactory(com.evolveum.midpoint.provisioning.ucf.api.ConnectorFactory) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) Test(org.testng.annotations.Test)

Example 3 with ConnectorFactory

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

the class ConnectorManager method getConnectorFactories.

public Collection<ConnectorFactory> getConnectorFactories() {
    if (connectorFactories == null) {
        String[] connectorFactoryBeanNames = springContext.getBeanNamesForType(ConnectorFactory.class);
        LOGGER.debug("Connector factories bean names: {}", Arrays.toString(connectorFactoryBeanNames));
        if (connectorFactoryBeanNames == null) {
            return null;
        }
        connectorFactories = new ArrayList<>(connectorFactoryBeanNames.length);
        for (String connectorFactoryBeanName : connectorFactoryBeanNames) {
            Object bean = springContext.getBean(connectorFactoryBeanName);
            if (bean instanceof ConnectorFactory) {
                connectorFactories.add((ConnectorFactory) bean);
            } else {
                LOGGER.error("Bean {} is not instance of ConnectorFactory, it is {}, skipping", connectorFactoryBeanName, bean.getClass());
            }
        }
    }
    return connectorFactories;
}
Also used : ConnectorFactory(com.evolveum.midpoint.provisioning.ucf.api.ConnectorFactory) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 4 with ConnectorFactory

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

the class ConnectorManager method createConfiguredConnectorInstance.

private ConnectorInstance createConfiguredConnectorInstance(ConnectorSpec connectorSpec, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException {
    ConnectorType connectorType = getConnectorTypeReadOnly(connectorSpec, result);
    ConnectorFactory connectorFactory = determineConnectorFactory(connectorType);
    ConnectorInstance connector = null;
    try {
        connector = connectorFactory.createConnectorInstance(connectorType, ResourceTypeUtil.getResourceNamespace(connectorSpec.getResource()), connectorSpec.toString());
    } catch (ObjectNotFoundException e) {
        result.recordFatalError(e.getMessage(), e);
        throw new ObjectNotFoundException(e.getMessage(), e);
    }
    PrismContainerValue<ConnectorConfigurationType> connectorConfigurationVal = connectorSpec.getConnectorConfiguration().getValue();
    if (connectorConfigurationVal == null) {
        SchemaException e = new SchemaException("No connector configuration in " + connectorSpec);
        result.recordFatalError(e);
        throw e;
    }
    try {
        connector.configure(connectorConfigurationVal, result);
        ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(connectorSpec.getResource(), prismContext);
        Collection<Object> capabilities = ResourceTypeUtil.getNativeCapabilitiesCollection(connectorSpec.getResource().asObjectable());
        connector.initialize(resourceSchema, capabilities, ResourceTypeUtil.isCaseIgnoreAttributeNames(connectorSpec.getResource().asObjectable()), result);
        InternalMonitor.recordConnectorInstanceInitialization();
    } catch (GenericFrameworkException e) {
        // Not expected. Transform to system exception
        result.recordFatalError("Generic provisioning framework error", e);
        throw new SystemException("Generic provisioning framework error: " + e.getMessage(), e);
    } catch (CommunicationException e) {
        result.recordFatalError(e);
        throw e;
    } catch (ConfigurationException e) {
        result.recordFatalError(e);
        throw 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, connectorType.getConnectorType(), connectorType.getConnectorVersion());
    return connector;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) ConnectorFactory(com.evolveum.midpoint.provisioning.ucf.api.ConnectorFactory) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Aggregations

ConnectorFactory (com.evolveum.midpoint.provisioning.ucf.api.ConnectorFactory)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 QueryBuilder (com.evolveum.midpoint.prism.query.builder.QueryBuilder)1 PrismAsserts (com.evolveum.midpoint.prism.util.PrismAsserts)1 ProvisioningService (com.evolveum.midpoint.provisioning.api.ProvisioningService)1 ConnectorInstance (com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance)1 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)1 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)1 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)1 Task (com.evolveum.midpoint.task.api.Task)1 AbstractIntegrationTest (com.evolveum.midpoint.test.AbstractIntegrationTest)1 IntegrationTestTools (com.evolveum.midpoint.test.IntegrationTestTools)1 IntegrationTestTools.display (com.evolveum.midpoint.test.IntegrationTestTools.display)1