Search in sources :

Example 36 with ConnectorType

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

the class TestDummyLegacy method test103NativeTestResource.

@Test
public void test103NativeTestResource() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    // Check that there is no schema before test (pre-condition)
    ResourceType resourceBefore = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_NATIVE_OID, null, result).asObjectable();
    assertNotNull("No connector ref", resourceBefore.getConnectorRef());
    assertNotNull("No connector ref OID", resourceBefore.getConnectorRef().getOid());
    ConnectorType connector = repositoryService.getObject(ConnectorType.class, resourceBefore.getConnectorRef().getOid(), null, result).asObjectable();
    assertNotNull(connector);
    XmlSchemaType xmlSchemaTypeBefore = resourceBefore.getSchema();
    Element resourceXsdSchemaElementBefore = ResourceTypeUtil.getResourceXsdSchema(resourceBefore);
    AssertJUnit.assertNull("Found schema before test connection. Bad test setup?", resourceXsdSchemaElementBefore);
    // WHEN
    OperationResult testResult = provisioningService.testResource(RESOURCE_DUMMY_NATIVE_OID, task);
    // THEN
    display("Test result", testResult);
    OperationResult connectorResult = assertSingleConnectorTestResult(testResult);
    assertTestResourceSuccess(connectorResult, ConnectorTestOperation.CONNECTOR_INITIALIZATION);
    assertTestResourceSuccess(connectorResult, ConnectorTestOperation.CONNECTOR_CONFIGURATION);
    assertTestResourceSuccess(connectorResult, ConnectorTestOperation.CONNECTOR_CONNECTION);
    assertTestResourceSuccess(connectorResult, ConnectorTestOperation.CONNECTOR_CAPABILITIES);
    assertSuccess(connectorResult);
    assertTestResourceSuccess(testResult, ConnectorTestOperation.RESOURCE_SCHEMA);
    assertSuccess(testResult);
    PrismObject<ResourceType> resourceRepoAfter = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_NATIVE_OID, null, result);
    ResourceType resourceTypeRepoAfter = resourceRepoAfter.asObjectable();
    display("Resource after test", resourceTypeRepoAfter);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) Element(org.w3c.dom.Element) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) Test(org.testng.annotations.Test)

Example 37 with ConnectorType

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

the class TestDummyLegacy method test203LegacyTestResource.

@Test
public void test203LegacyTestResource() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    // Check that there is no schema before test (pre-condition)
    ResourceType resourceBefore = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_LEGACY_OID, null, result).asObjectable();
    assertNotNull("No connector ref", resourceBefore.getConnectorRef());
    assertNotNull("No connector ref OID", resourceBefore.getConnectorRef().getOid());
    ConnectorType connector = repositoryService.getObject(ConnectorType.class, resourceBefore.getConnectorRef().getOid(), null, result).asObjectable();
    assertNotNull(connector);
    XmlSchemaType xmlSchemaTypeBefore = resourceBefore.getSchema();
    Element resourceXsdSchemaElementBefore = ResourceTypeUtil.getResourceXsdSchema(resourceBefore);
    AssertJUnit.assertNull("Found schema before test connection. Bad test setup?", resourceXsdSchemaElementBefore);
    // WHEN
    OperationResult testResult = provisioningService.testResource(RESOURCE_DUMMY_LEGACY_OID, task);
    // THEN
    display("Test result", testResult);
    OperationResult connectorResult = assertSingleConnectorTestResult(testResult);
    assertTestResourceSuccess(connectorResult, ConnectorTestOperation.CONNECTOR_INITIALIZATION);
    assertTestResourceSuccess(connectorResult, ConnectorTestOperation.CONNECTOR_CONFIGURATION);
    assertTestResourceSuccess(connectorResult, ConnectorTestOperation.CONNECTOR_CONNECTION);
    assertTestResourceSuccess(connectorResult, ConnectorTestOperation.CONNECTOR_CAPABILITIES);
    assertSuccess(connectorResult);
    assertTestResourceSuccess(testResult, ConnectorTestOperation.RESOURCE_SCHEMA);
    assertSuccess(testResult);
    PrismObject<ResourceType> resourceRepoAfter = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_LEGACY_OID, null, result);
    ResourceType resourceTypeRepoAfter = resourceRepoAfter.asObjectable();
    display("Resource after test", resourceTypeRepoAfter);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) Element(org.w3c.dom.Element) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) Test(org.testng.annotations.Test)

Example 38 with ConnectorType

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

the class DiscoverConnectorsExecutor method determineConnectorMappings.

private void determineConnectorMappings(Map<String, String> rebindMap, ConnectorType connectorType, ExecutionContext context, OperationResult result) throws ScriptExecutionException {
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Finding obsolete versions for connector: {}", connectorType.asPrismObject().debugDump());
    }
    ObjectQuery query = prismContext.queryFor(ConnectorType.class).item(SchemaConstants.C_CONNECTOR_FRAMEWORK).eq(connectorType.getFramework()).and().item(SchemaConstants.C_CONNECTOR_CONNECTOR_TYPE).eq(connectorType.getConnectorType()).build();
    List<PrismObject<ConnectorType>> foundConnectors;
    try {
        foundConnectors = modelService.searchObjects(ConnectorType.class, query, null, null, result);
    } catch (SchemaException | ConfigurationException | ObjectNotFoundException | CommunicationException | SecurityViolationException | ExpressionEvaluationException e) {
        throw new ScriptExecutionException("Couldn't get connectors of type: " + connectorType.getConnectorType() + ": " + e.getMessage(), e);
    }
    for (PrismObject<ConnectorType> foundConnector : foundConnectors) {
        ConnectorType foundConnectorType = foundConnector.asObjectable();
        // TODO temporary hack. fix it after MID-3355 is implemented.
        if (connectorType.getConnectorHostRef() != null && connectorType.getConnectorHostRef().asReferenceValue().getObject() != null) {
            String connectorHostOid = connectorType.getConnectorHostRef().getOid();
            connectorType.getConnectorHostRef().asReferenceValue().setObject(null);
            connectorType.getConnectorHostRef().setOid(connectorHostOid);
        }
        if (connectorType.getConnectorHostRef().equals(foundConnectorType.getConnectorHostRef()) && foundConnectorType.getConnectorVersion() != null && !foundConnectorType.getConnectorVersion().equals(connectorType.getConnectorVersion())) {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Found obsolete connector:\n{}", foundConnectorType.asPrismObject().debugDump(1));
            }
            rebindMap.put(foundConnectorType.getOid(), connectorType.getOid());
        }
    }
}
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) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ScriptExecutionException(com.evolveum.midpoint.util.exception.ScriptExecutionException) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 39 with ConnectorType

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

the class DiscoverConnectorsExecutor method execute.

@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException, SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, SecurityViolationException, ExpressionEvaluationException {
    boolean rebind = expressionHelper.getArgumentAsBoolean(expression.getParameter(), PARAM_REBIND_RESOURCES, input, context, false, PARAM_REBIND_RESOURCES, globalResult);
    PipelineData output = PipelineData.createEmpty();
    for (PipelineItem item : input.getData()) {
        PrismValue value = item.getValue();
        OperationResult result = operationsHelper.createActionResult(item, this, globalResult);
        context.checkTaskStop();
        if (value instanceof PrismObjectValue && ((PrismObjectValue) value).asObjectable() instanceof ConnectorHostType) {
            PrismObject<ConnectorHostType> connectorHostTypePrismObject = ((PrismObjectValue) value).asPrismObject();
            Set<ConnectorType> newConnectors;
            Operation op = operationsHelper.recordStart(context, connectorHostTypePrismObject.asObjectable());
            Throwable exception = null;
            try {
                newConnectors = modelService.discoverConnectors(connectorHostTypePrismObject.asObjectable(), context.getTask(), result);
                operationsHelper.recordEnd(context, op, null, result);
            } catch (CommunicationException | SecurityViolationException | SchemaException | ConfigurationException | ObjectNotFoundException | ExpressionEvaluationException | RuntimeException e) {
                operationsHelper.recordEnd(context, op, e, result);
                exception = processActionException(e, NAME, value, context);
                newConnectors = Collections.emptySet();
            }
            context.println((exception != null ? "Attempted to discover " : "Discovered " + newConnectors.size()) + " new connector(s) from " + connectorHostTypePrismObject + exceptionSuffix(exception));
            for (ConnectorType connectorType : newConnectors) {
                output.addValue(connectorType.asPrismObject().getValue(), item.getResult(), item.getVariables());
            }
            try {
                if (rebind) {
                    rebindConnectors(newConnectors, context, result);
                }
            } catch (ScriptExecutionException e) {
                // noinspection ThrowableNotThrown
                // TODO better message
                processActionException(e, NAME, value, context);
            }
        } else {
            // noinspection ThrowableNotThrown
            processActionException(new ScriptExecutionException("Input item is not a PrismObject<ConnectorHost>"), NAME, value, context);
        }
        operationsHelper.trimAndCloneResult(result, item.getResult());
    }
    // TODO configurable output (either connector hosts or discovered connectors)
    return output;
}
Also used : ConnectorHostType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorHostType) 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) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ScriptExecutionException(com.evolveum.midpoint.util.exception.ScriptExecutionException) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Operation(com.evolveum.midpoint.schema.statistics.Operation) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 40 with ConnectorType

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

the class TestConnectorDiscovery method testSearchConnectorAnd.

@Test
public void testSearchConnectorAnd() throws SchemaException {
    OperationResult result = createOperationResult();
    ObjectQuery query = prismContext.queryFor(ConnectorType.class).item(SchemaConstants.C_CONNECTOR_FRAMEWORK).eq(SchemaConstants.ICF_FRAMEWORK_URI).and().item(SchemaConstants.C_CONNECTOR_CONNECTOR_TYPE).eq(IntegrationTestTools.LDAP_CONNECTOR_TYPE).build();
    System.out.println("Query:\n" + query.debugDump());
    List<PrismObject<ConnectorType>> connectors = repositoryService.searchObjects(ConnectorType.class, query, null, result);
    assertEquals("Unexpected number of results", 1, connectors.size());
    PrismObject<ConnectorType> ldapConnector = connectors.get(0);
    assertEquals("Type does not match", IntegrationTestTools.LDAP_CONNECTOR_TYPE, ldapConnector.asObjectable().getConnectorType());
    assertEquals("Framework does not match", SchemaConstants.ICF_FRAMEWORK_URI, ldapConnector.asObjectable().getFramework());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) Test(org.testng.annotations.Test)

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