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;
}
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);
}
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);
}
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);
}
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");
}
Aggregations