Search in sources :

Example 26 with ConnectorType

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

the class TestSanity method test000Integrity.

/**
     * Test integrity of the test setup.
     *
     * @throws SchemaException
     * @throws ObjectNotFoundException
     * @throws CommunicationException
     */
@Test
public void test000Integrity() throws Exception {
    final String TEST_NAME = "test000Integrity";
    TestUtil.displayTestTile(this, TEST_NAME);
    assertNotNull(modelWeb);
    assertNotNull(modelService);
    assertNotNull(repositoryService);
    assertTrue(isSystemInitialized());
    assertNotNull(taskManager);
    assertNotNull(prismContext);
    SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
    assertNotNull(schemaRegistry);
    // This is defined in extra schema. So this effectively checks whether the extra schema was loaded
    PrismPropertyDefinition shipStateDefinition = schemaRegistry.findPropertyDefinitionByElementName(MY_SHIP_STATE);
    assertNotNull("No my:shipState definition", shipStateDefinition);
    assertEquals("Wrong maxOccurs in my:shipState definition", 1, shipStateDefinition.getMaxOccurs());
    assertNoRepoCache();
    Task task = taskManager.createTaskInstance(TestSanity.class.getName() + ".test000Integrity");
    OperationResult result = task.getResult();
    // Check if OpenDJ resource was imported correctly
    PrismObject<ResourceType> openDjResource = repositoryService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, result);
    display("Imported OpenDJ resource (repository)", openDjResource);
    AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, openDjResource.getOid());
    assertNoRepoCache();
    String ldapConnectorOid = openDjResource.asObjectable().getConnectorRef().getOid();
    PrismObject<ConnectorType> ldapConnector = repositoryService.getObject(ConnectorType.class, ldapConnectorOid, null, result);
    display("LDAP Connector: ", ldapConnector);
    // TODO: test if OpenDJ and Derby are running
    repositoryService.getObject(GenericObjectType.class, SAMPLE_CONFIGURATION_OBJECT_OID, null, result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 27 with ConnectorType

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

the class ConsistencyTest method test000Integrity.

/**
	 * Test integrity of the test setup.
	 */
@Test
public void test000Integrity() throws Exception {
    final String TEST_NAME = "test000Integrity";
    TestUtil.displayTestTile(this, TEST_NAME);
    assertNotNull(modelWeb);
    assertNotNull(modelService);
    assertNotNull(repositoryService);
    assertTrue(isSystemInitialized());
    assertNotNull(taskManager);
    assertNotNull(prismContext);
    SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
    assertNotNull(schemaRegistry);
    // This is defined in extra schema. So this effectively checks whether
    // the extra schema was loaded
    PrismPropertyDefinition shipStateDefinition = schemaRegistry.findPropertyDefinitionByElementName(MY_SHIP_STATE);
    assertNotNull("No my:shipState definition", shipStateDefinition);
    assertEquals("Wrong maxOccurs in my:shipState definition", 1, shipStateDefinition.getMaxOccurs());
    assertNoRepoCache();
    OperationResult result = new OperationResult(ConsistencyTest.class.getName() + "." + TEST_NAME);
    // Check if OpenDJ resource was imported correctly
    PrismObject<ResourceType> openDjResource = repositoryService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, result);
    display("Imported OpenDJ resource (repository)", openDjResource);
    AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, openDjResource.getOid());
    assertNoRepoCache();
    String ldapConnectorOid = openDjResource.asObjectable().getConnectorRef().getOid();
    PrismObject<ConnectorType> ldapConnector = repositoryService.getObject(ConnectorType.class, ldapConnectorOid, null, result);
    display("LDAP Connector: ", ldapConnector);
}
Also used : ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 28 with ConnectorType

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

the class ConnectorManager method isInRepo.

private boolean isInRepo(ConnectorType connectorType, OperationResult result) throws SchemaException {
    ObjectQuery query = QueryBuilder.queryFor(ConnectorType.class, prismContext).item(SchemaConstants.C_CONNECTOR_FRAMEWORK).eq(connectorType.getFramework()).and().item(SchemaConstants.C_CONNECTOR_CONNECTOR_TYPE).eq(connectorType.getConnectorType()).build();
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Looking for connector in repository:\n{}", query.debugDump());
    }
    List<PrismObject<ConnectorType>> foundConnectors;
    try {
        foundConnectors = repositoryService.searchObjects(ConnectorType.class, query, null, result);
    } 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);
    }
    if (foundConnectors.size() == 0) {
        // Nothing found, the connector is not in the repo
        return false;
    }
    String foundOid = null;
    for (PrismObject<ConnectorType> foundConnector : foundConnectors) {
        if (compareConnectors(connectorType.asPrismObject(), foundConnector)) {
            if (foundOid != null) {
                // More than one connector matches. Inconsistent repo state. Log error.
                result.recordPartialError("Found more than one connector that matches " + connectorType.getFramework() + " : " + connectorType.getConnectorType() + " : " + connectorType.getVersion() + ". OIDs " + foundConnector.getOid() + " and " + foundOid + ". Inconsistent database state.");
                LOGGER.error("Found more than one connector that matches " + connectorType.getFramework() + " : " + connectorType.getConnectorType() + " : " + connectorType.getVersion() + ". OIDs " + foundConnector.getOid() + " and " + foundOid + ". Inconsistent database state.");
                // But continue working otherwise. This is probably not critical.
                return true;
            }
            foundOid = foundConnector.getOid();
        }
    }
    return (foundOid != null);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 29 with ConnectorType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType 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)

Example 30 with ConnectorType

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

the class ConnectorManager method getConnectorTypeReadOnly.

public ConnectorType getConnectorTypeReadOnly(ConnectorSpec connectorSpec, OperationResult result) throws ObjectNotFoundException, SchemaException {
    if (connectorSpec.getConnectorOid() == null) {
        result.recordFatalError("Connector OID missing in " + connectorSpec);
        throw new ObjectNotFoundException("Connector OID missing in " + connectorSpec);
    }
    String connOid = connectorSpec.getConnectorOid();
    ConnectorType connectorType = connectorTypeCache.get(connOid);
    if (connectorType == null) {
        Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createReadOnly());
        PrismObject<ConnectorType> repoConnector = repositoryService.getObject(ConnectorType.class, connOid, options, result);
        connectorType = repoConnector.asObjectable();
        connectorTypeCache.put(connOid, connectorType);
    } else {
        String currentConnectorVersion = repositoryService.getVersion(ConnectorType.class, connOid, result);
        if (!currentConnectorVersion.equals(connectorType.getVersion())) {
            Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createReadOnly());
            PrismObject<ConnectorType> repoConnector = repositoryService.getObject(ConnectorType.class, connOid, options, result);
            connectorType = repoConnector.asObjectable();
            connectorTypeCache.put(connOid, connectorType);
        }
    }
    if (connectorType.getConnectorHost() == null && connectorType.getConnectorHostRef() != null) {
        // We need to resolve the connector host
        String connectorHostOid = connectorType.getConnectorHostRef().getOid();
        PrismObject<ConnectorHostType> connectorHost = repositoryService.getObject(ConnectorHostType.class, connectorHostOid, null, result);
        connectorType.setConnectorHost(connectorHost.asObjectable());
    }
    PrismObject<ConnectorType> connector = connectorType.asPrismObject();
    Object userDataEntry = connector.getUserData(USER_DATA_KEY_PARSED_CONNECTOR_SCHEMA);
    if (userDataEntry == null) {
        InternalMonitor.recordConnectorSchemaParse();
        PrismSchema connectorSchema = ConnectorTypeUtil.parseConnectorSchema(connectorType, prismContext);
        if (connectorSchema == null) {
            throw new SchemaException("No connector schema in " + connectorType);
        }
        connector.setUserData(USER_DATA_KEY_PARSED_CONNECTOR_SCHEMA, connectorSchema);
    }
    return connectorType;
}
Also used : ConnectorHostType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorHostType) PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Aggregations

ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)39 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)21 Test (org.testng.annotations.Test)17 PrismObject (com.evolveum.midpoint.prism.PrismObject)13 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)13 Task (com.evolveum.midpoint.task.api.Task)12 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)12 PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)8 AbstractIntegrationTest (com.evolveum.midpoint.test.AbstractIntegrationTest)8 SystemException (com.evolveum.midpoint.util.exception.SystemException)8 QName (javax.xml.namespace.QName)7 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)6 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)6 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)4 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)4 ConnectorConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType)4 ConnectorHostType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorHostType)4 XmlSchemaType (com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType)4 Element (org.w3c.dom.Element)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3