Search in sources :

Example 41 with ObjectClassComplexTypeDefinition

use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.

the class LiveSyncTaskHandler method runInternal.

private TaskRunResult runInternal(Task task) {
    LOGGER.trace("LiveSyncTaskHandler.run starting");
    long progress = task.getProgress();
    OperationResult opResult = new OperationResult(OperationConstants.LIVE_SYNC);
    TaskRunResult runResult = new TaskRunResult();
    runResult.setOperationResult(opResult);
    String resourceOid = task.getObjectOid();
    if (resourceOid == null) {
        LOGGER.error("Live Sync: No resource OID specified in the task");
        opResult.recordFatalError("No resource OID specified in the task");
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    }
    ResourceType resource = null;
    try {
        resource = provisioningService.getObject(ResourceType.class, resourceOid, null, task, opResult).asObjectable();
    } catch (ObjectNotFoundException ex) {
        LOGGER.error("Live Sync: Resource {} not found: {}", new Object[] { resourceOid, ex.getMessage(), ex });
        // This is bad. The resource does not exist. Permanent problem.
        opResult.recordFatalError("Resource not found " + resourceOid, ex);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    } catch (SchemaException ex) {
        LOGGER.error("Live Sync: Error dealing with schema: {}", ex.getMessage(), ex);
        // Not sure about this. But most likely it is a misconfigured resource or connector
        // It may be worth to retry. Error is fatal, but may not be permanent.
        opResult.recordFatalError("Error dealing with schema: " + ex.getMessage(), ex);
        runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
        return runResult;
    } catch (RuntimeException ex) {
        LOGGER.error("Live Sync: Internal Error: {}", ex.getMessage(), ex);
        // Can be anything ... but we can't recover from that.
        // It is most likely a programming error. Does not make much sense to retry.
        opResult.recordFatalError("Internal Error: " + ex.getMessage(), ex);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    } catch (CommunicationException ex) {
        LOGGER.error("Live Sync: Error getting resource {}: {}", new Object[] { resourceOid, ex.getMessage(), ex });
        opResult.recordFatalError("Error getting resource " + resourceOid + ": " + ex.getMessage(), ex);
        runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
        return runResult;
    } catch (ConfigurationException ex) {
        LOGGER.error("Live Sync: Error getting resource {}: {}", new Object[] { resourceOid, ex.getMessage(), ex });
        opResult.recordFatalError("Error getting resource " + resourceOid + ": " + ex.getMessage(), ex);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    } catch (SecurityViolationException ex) {
        LOGGER.error("Live Sync: Error getting resource {}: {}", new Object[] { resourceOid, ex.getMessage(), ex });
        opResult.recordFatalError("Error getting resource " + resourceOid + ": " + ex.getMessage(), ex);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    } catch (ExpressionEvaluationException ex) {
        LOGGER.error("Live Sync: Error getting resource {}: {}", new Object[] { resourceOid, ex.getMessage(), ex });
        opResult.recordFatalError("Error getting resource " + resourceOid + ": " + ex.getMessage(), ex);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    }
    if (resource == null) {
        LOGGER.error("Live Sync: No resource specified");
        opResult.recordFatalError("No resource specified");
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    }
    RefinedResourceSchema refinedSchema;
    try {
        refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource, LayerType.MODEL, prismContext);
    } catch (SchemaException e) {
        LOGGER.error("Live Sync: Schema error during processing account definition: {}", e.getMessage());
        opResult.recordFatalError("Schema error during processing account definition: " + e.getMessage(), e);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    }
    if (refinedSchema == null) {
        opResult.recordFatalError("No refined schema defined. Probably some configuration problem.");
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        LOGGER.error("Live Sync: No refined schema defined. Probably some configuration problem.");
        return runResult;
    }
    ObjectClassComplexTypeDefinition objectClass;
    try {
        objectClass = Utils.determineObjectClass(refinedSchema, task);
    } catch (SchemaException e) {
        LOGGER.error("Live Sync: schema error: {}", e.getMessage());
        opResult.recordFatalError(e);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    }
    if (objectClass == null) {
        LOGGER.debug("Syncing all object classes");
    }
    ResourceShadowDiscriminator coords = new ResourceShadowDiscriminator(resourceOid, objectClass == null ? null : objectClass.getTypeName());
    int changesProcessed;
    try {
        // MAIN PART
        // Calling synchronize(..) in provisioning.
        // This will detect the changes and notify model about them.
        // It will use extension of task to store synchronization state
        Utils.clearRequestee(task);
        changesProcessed = provisioningService.synchronize(coords, task, opResult);
        progress += changesProcessed;
    } catch (ObjectNotFoundException ex) {
        LOGGER.error("Live Sync: A required object does not exist, OID: {}", ex.getOid());
        LOGGER.error("Exception stack trace", ex);
        // This is bad. The resource or task or something like that does not exist. Permanent problem.
        opResult.recordFatalError("A required object does not exist, OID: " + ex.getOid(), ex);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        runResult.setProgress(progress);
        return runResult;
    } catch (CommunicationException ex) {
        LOGGER.error("Live Sync: Communication error:", ex);
        // Error, but not critical. Just try later.
        opResult.recordPartialError("Communication error: " + ex.getMessage(), ex);
        runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
        runResult.setProgress(progress);
        return runResult;
    } catch (SchemaException ex) {
        LOGGER.error("Live Sync: Error dealing with schema:", ex);
        // Not sure about this. But most likely it is a misconfigured resource or connector
        // It may be worth to retry. Error is fatal, but may not be permanent.
        opResult.recordFatalError("Error dealing with schema: " + ex.getMessage(), ex);
        runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
        runResult.setProgress(progress);
        return runResult;
    } catch (RuntimeException ex) {
        LOGGER.error("Live Sync: Internal Error:", ex);
        // Can be anything ... but we can't recover from that.
        // It is most likely a programming error. Does not make much sense to retry.
        opResult.recordFatalError("Internal Error: " + ex.getMessage(), ex);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        runResult.setProgress(progress);
        return runResult;
    } catch (ConfigurationException ex) {
        LOGGER.error("Live Sync: Configuration error:", ex);
        // Not sure about this. But most likely it is a misconfigured resource or connector
        // It may be worth to retry. Error is fatal, but may not be permanent.
        opResult.recordFatalError("Configuration error: " + ex.getMessage(), ex);
        runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
        runResult.setProgress(progress);
        return runResult;
    } catch (SecurityViolationException ex) {
        LOGGER.error("Recompute: Security violation: {}", ex.getMessage(), ex);
        opResult.recordFatalError("Security violation: " + ex.getMessage(), ex);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        runResult.setProgress(progress);
        return runResult;
    } catch (ExpressionEvaluationException ex) {
        LOGGER.error("Recompute: Expression error: {}", ex.getMessage(), ex);
        opResult.recordFatalError("Expression error: " + ex.getMessage(), ex);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        runResult.setProgress(progress);
        return runResult;
    }
    opResult.computeStatus("Live sync run has failed");
    opResult.createSubresult(OperationConstants.LIVE_SYNC_STATISTICS).recordStatus(OperationResultStatus.SUCCESS, "Changes processed: " + changesProcessed);
    // This "run" is finished. But the task goes on ...
    runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
    // Might collide with increasing progress in provisioning module, e.g. when an exception is thrown. But that's OK for now.
    runResult.setProgress(progress);
    LOGGER.trace("LiveSyncTaskHandler.run stopping (resource {})", resourceOid);
    return runResult;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) TaskRunResult(com.evolveum.midpoint.task.api.TaskRunResult) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema)

Example 42 with ObjectClassComplexTypeDefinition

use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.

the class TestRefinedSchema method test124DetermineObjectClassKindIntentObjectClassModel.

@Test
public void test124DetermineObjectClassKindIntentObjectClassModel() throws Exception {
    final String TEST_NAME = "test124DetermineObjectClassKindIntentObjectClassModel";
    TestUtil.displayTestTile(this, TEST_NAME);
    OperationResult result = new OperationResult(TestRefinedSchema.class.getName() + "." + TEST_NAME);
    importObjectFromFile(TASK_RECONCILE_DUMMY_KIND_INTENT_OBJECTCLASS_FILE);
    Task task = taskManager.getTask(TASK_RECONCILE_DUMMY_KIND_INTENT_OBJECTCLASS_OID, result);
    display("Task", task);
    // WHEN
    ObjectClassComplexTypeDefinition objectClass = Utils.determineObjectClass(refinedSchemaModel, task);
    // THEN
    display("Object class", objectClass);
    display("Object class (toString)", objectClass.toString());
    deleteObject(TaskType.class, TASK_RECONCILE_DUMMY_KIND_INTENT_OBJECTCLASS_OID);
    assertLayerRefinedObjectClass(objectClass, RESOURCE_DUMMY_PRIVILEGE_OBJECTCLASS_QNAME, ShadowKindType.ENTITLEMENT, "privilege", LayerType.MODEL);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) Test(org.testng.annotations.Test)

Example 43 with ObjectClassComplexTypeDefinition

use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.

the class ResourceValidatorImpl method checkSchemaHandlingObjectType.

private void checkSchemaHandlingObjectType(ResourceValidationContext ctx, ItemPath path, ResourceObjectTypeDefinitionType objectType) {
    checkDuplicateItems(ctx, path, objectType);
    checkObjectClass(ctx, path, objectType);
    ObjectClassComplexTypeDefinition ocdef = null;
    if (ctx.resourceSchema != null && objectType.getObjectClass() != null) {
        ocdef = ctx.resourceSchema.findObjectClassDefinition(objectType.getObjectClass());
        checkObjectClassDefinition(ctx, path, objectType, ocdef);
    }
    int i = 1;
    for (ResourceAttributeDefinitionType attributeDef : objectType.getAttribute()) {
        checkSchemaHandlingAttribute(ctx, ocdef, path.append(new ItemPath(ResourceObjectTypeDefinitionType.F_ATTRIBUTE, i)), objectType, attributeDef);
        i++;
    }
    i = 1;
    for (ResourceObjectAssociationType associationDef : objectType.getAssociation()) {
        checkSchemaHandlingAssociation(ctx, ocdef, path.append(new ItemPath(ResourceObjectTypeDefinitionType.F_ATTRIBUTE, i)), objectType, associationDef);
        i++;
    }
    if (objectType.getActivation() != null) {
        ItemPath actPath = path.append(ResourceObjectTypeDefinitionType.F_ACTIVATION);
        checkBidirectionalMapping(ctx, actPath, ResourceActivationDefinitionType.F_ADMINISTRATIVE_STATUS, objectType, objectType.getActivation().getAdministrativeStatus());
        checkBidirectionalMapping(ctx, actPath, ResourceActivationDefinitionType.F_EXISTENCE, objectType, objectType.getActivation().getExistence());
        checkBidirectionalMapping(ctx, actPath, ResourceActivationDefinitionType.F_LOCKOUT_STATUS, objectType, objectType.getActivation().getLockoutStatus());
        checkBidirectionalMapping(ctx, actPath, ResourceActivationDefinitionType.F_VALID_FROM, objectType, objectType.getActivation().getValidFrom());
        checkBidirectionalMapping(ctx, actPath, ResourceActivationDefinitionType.F_VALID_TO, objectType, objectType.getActivation().getValidTo());
    }
    if (objectType.getCredentials() != null) {
        ItemPath credPath = path.append(ResourceObjectTypeDefinitionType.F_CREDENTIALS);
        checkPasswordMapping(ctx, credPath, ResourceCredentialsDefinitionType.F_PASSWORD, objectType, objectType.getCredentials().getPassword());
    }
    checkDependencies(ctx, path, objectType);
}
Also used : ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 44 with ObjectClassComplexTypeDefinition

use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.

the class ResourceValidatorImpl method checkSchemaHandlingAttribute.

private void checkSchemaHandlingAttribute(ResourceValidationContext ctx, ObjectClassComplexTypeDefinition ocdef, ItemPath path, ResourceObjectTypeDefinitionType objectType, ResourceAttributeDefinitionType attributeDef) {
    QName ref = itemRefToName(attributeDef.getRef());
    checkSchemaHandlingItem(ctx, path, objectType, attributeDef);
    ResourceAttributeDefinition<?> rad = null;
    // TODO rewrite using CompositeRefinedObjectClassDefinition
    if (ref != null) {
        boolean caseIgnoreAttributeNames = ResourceTypeUtil.isCaseIgnoreAttributeNames(ctx.resourceObject.asObjectable());
        if (ocdef != null) {
            rad = ocdef.findAttributeDefinition(ref, caseIgnoreAttributeNames);
        }
        if (rad == null) {
            for (QName auxOcName : objectType.getAuxiliaryObjectClass()) {
                ObjectClassComplexTypeDefinition auxOcDef = ctx.resourceSchema.findObjectClassDefinition(auxOcName);
                if (auxOcDef != null) {
                    rad = auxOcDef.findAttributeDefinition(ref, caseIgnoreAttributeNames);
                    if (rad != null) {
                        break;
                    }
                }
            }
        }
        if (rad == null) {
            ctx.validationResult.add(Issue.Severity.ERROR, CAT_SCHEMA_HANDLING, C_UNKNOWN_ATTRIBUTE_NAME, getString(ctx.bundle, CLASS_DOT + C_UNKNOWN_ATTRIBUTE_NAME, getName(objectType), ref, objectType.getObjectClass()), ctx.resourceRef, path.append(ResourceItemDefinitionType.F_REF));
        }
    }
    checkItemRef(ctx, path, objectType, attributeDef, C_NO_ATTRIBUTE_REF);
    checkMatchingRule(ctx, path, objectType, attributeDef, ref, rad);
}
Also used : QName(javax.xml.namespace.QName) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)

Example 45 with ObjectClassComplexTypeDefinition

use of com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition in project midpoint by Evolveum.

the class TestRefinedSchema method test112DetermineObjectClassKindIntent.

@Test
public void test112DetermineObjectClassKindIntent() throws Exception {
    final String TEST_NAME = "test112DetermineObjectClassKindIntent";
    TestUtil.displayTestTile(this, TEST_NAME);
    OperationResult result = new OperationResult(TestRefinedSchema.class.getName() + "." + TEST_NAME);
    importObjectFromFile(TASK_RECONCILE_DUMMY_KIND_INTENT_FILE);
    Task task = taskManager.getTask(TASK_RECONCILE_DUMMY_KIND_INTENT_OID, result);
    display("Task", task);
    // WHEN
    ObjectClassComplexTypeDefinition objectClass = Utils.determineObjectClass(refinedSchema, task);
    // THEN
    display("Object class", objectClass);
    deleteObject(TaskType.class, TASK_RECONCILE_DUMMY_KIND_INTENT_OID);
    assertRefinedObjectClass(objectClass, RESOURCE_DUMMY_PRIVILEGE_OBJECTCLASS_QNAME, ShadowKindType.ENTITLEMENT, "privilege");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) Test(org.testng.annotations.Test)

Aggregations

ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)53 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)18 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)17 Test (org.testng.annotations.Test)17 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)16 QName (javax.xml.namespace.QName)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)15 ArrayList (java.util.ArrayList)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)8 Task (com.evolveum.midpoint.task.api.Task)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)5 Containerable (com.evolveum.midpoint.prism.Containerable)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)4 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)3 ResultHandler (com.evolveum.midpoint.provisioning.ucf.api.ResultHandler)3 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)3