use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.
the class ReconciliationTaskHandler method performResourceReconciliation.
// returns false in case of execution interruption
private boolean performResourceReconciliation(PrismObject<ResourceType> resource, ObjectClassComplexTypeDefinition objectclassDef, ReconciliationTaskResult reconResult, Task coordinatorTask, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
boolean interrupted;
OperationResult opResult = result.createSubresult(OperationConstants.RECONCILIATION + ".resourceReconciliation");
// Instantiate result handler. This will be called with every search
// result in the following iterative search
SynchronizeAccountResultHandler handler = new SynchronizeAccountResultHandler(resource.asObjectable(), objectclassDef, "reconciliation", coordinatorTask, changeNotificationDispatcher, taskManager);
handler.setSourceChannel(SchemaConstants.CHANGE_CHANNEL_RECON);
handler.setStopOnError(false);
coordinatorTask.setExpectedTotal(null);
try {
ObjectQuery query = objectclassDef.createShadowSearchQuery(resource.getOid());
OperationResult searchResult = new OperationResult(OperationConstants.RECONCILIATION + ".searchIterative");
handler.createWorkerThreads(coordinatorTask, searchResult);
// note that progress is incremented within the handler, as it extends AbstractSearchIterativeResultHandler
provisioningService.searchObjectsIterative(ShadowType.class, query, null, handler, coordinatorTask, searchResult);
handler.completeProcessing(coordinatorTask, searchResult);
interrupted = !coordinatorTask.canRun();
opResult.computeStatus();
String message = "Processed " + handler.getProgress() + " account(s), got " + handler.getErrors() + " error(s)";
if (interrupted) {
message += "; was interrupted during processing";
}
if (handler.getProgress() > 0) {
message += ". Average time for one object: " + handler.getAverageTime() + " ms (wall clock time average: " + handler.getWallAverageTime() + " ms).";
}
OperationResultStatus resultStatus = OperationResultStatus.SUCCESS;
if (handler.getErrors() > 0) {
resultStatus = OperationResultStatus.PARTIAL_ERROR;
}
opResult.recordStatus(resultStatus, message);
LOGGER.info("Finished resource part of {} reconciliation: {}", resource, message);
reconResult.setResourceReconCount(handler.getProgress());
reconResult.setResourceReconErrors(handler.getErrors());
} catch (ConfigurationException | SecurityViolationException | SchemaException | CommunicationException | ObjectNotFoundException | ExpressionEvaluationException | RuntimeException | Error e) {
opResult.recordFatalError(e);
throw e;
}
return !interrupted;
}
use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.
the class SynchronizationServiceImpl method notifyChange.
@Override
public void notifyChange(ResourceObjectShadowChangeDescription change, Task task, OperationResult parentResult) {
validate(change);
Validate.notNull(parentResult, "Parent operation result must not be null.");
boolean logDebug = isLogDebug(change);
if (logDebug) {
LOGGER.debug("SYNCHRONIZATION: received change notification {}", change);
} else {
LOGGER.trace("SYNCHRONIZATION: received change notification {}", change);
}
OperationResult subResult = parentResult.createSubresult(NOTIFY_CHANGE);
PrismObject<? extends ShadowType> currentShadow = change.getCurrentShadow();
PrismObject<? extends ShadowType> applicableShadow = currentShadow;
if (applicableShadow == null) {
// We need this e.g. in case of delete
applicableShadow = change.getOldShadow();
}
SynchronizationEventInformation eventInfo = new SynchronizationEventInformation(applicableShadow, change.getSourceChannel(), task);
try {
ResourceType resourceType = change.getResource().asObjectable();
PrismObject<SystemConfigurationType> configuration = systemObjectCache.getSystemConfiguration(subResult);
ObjectSynchronizationType synchronizationPolicy = determineSynchronizationPolicy(resourceType, applicableShadow, configuration, task, subResult);
if (LOGGER.isTraceEnabled()) {
String policyDesc = null;
if (synchronizationPolicy != null) {
if (synchronizationPolicy.getName() == null) {
policyDesc = "(kind=" + synchronizationPolicy.getKind() + ", intent=" + synchronizationPolicy.getIntent() + ", objectclass=" + synchronizationPolicy.getObjectClass() + ")";
} else {
policyDesc = synchronizationPolicy.getName();
}
}
LOGGER.trace("SYNCHRONIZATION determined policy: {}", policyDesc);
}
if (synchronizationPolicy == null) {
String message = "SYNCHRONIZATION no matching policy for " + applicableShadow + " (" + applicableShadow.asObjectable().getObjectClass() + ") " + " on " + resourceType + ", ignoring change from channel " + change.getSourceChannel();
LOGGER.debug(message);
subResult.recordStatus(OperationResultStatus.NOT_APPLICABLE, message);
eventInfo.setNoSynchronizationPolicy();
eventInfo.record(task);
return;
}
if (!isSynchronizationEnabled(synchronizationPolicy)) {
String message = "SYNCHRONIZATION is not enabled for " + resourceType + " ignoring change from channel " + change.getSourceChannel();
LOGGER.debug(message);
subResult.recordStatus(OperationResultStatus.NOT_APPLICABLE, message);
eventInfo.setSynchronizationNotEnabled();
eventInfo.record(task);
return;
}
// defined in task
if (!satisfyTaskConstraints(synchronizationPolicy, task)) {
LOGGER.trace("SYNCHRONIZATION skipping {} because it does not match kind/intent defined in task", new Object[] { applicableShadow });
subResult.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Skipped because it does not match objectClass/kind/intent");
eventInfo.setDoesNotMatchTaskSpecification();
eventInfo.record(task);
return;
}
if (isProtected((PrismObject<ShadowType>) currentShadow)) {
if (StringUtils.isNotBlank(synchronizationPolicy.getIntent())) {
List<PropertyDelta<?>> modifications = SynchronizationUtils.createSynchronizationTimestampsDelta(currentShadow);
PropertyDelta<String> intentDelta = PropertyDelta.createModificationReplaceProperty(ShadowType.F_INTENT, currentShadow.getDefinition(), synchronizationPolicy.getIntent());
modifications.add(intentDelta);
try {
repositoryService.modifyObject(ShadowType.class, currentShadow.getOid(), modifications, subResult);
task.recordObjectActionExecuted(currentShadow, ChangeType.MODIFY, null);
} catch (Throwable t) {
task.recordObjectActionExecuted(currentShadow, ChangeType.MODIFY, t);
} finally {
task.markObjectActionExecutedBoundary();
}
}
subResult.recordSuccess();
eventInfo.record(task);
LOGGER.debug("SYNCHRONIZATION: DONE (dry run) for protected shadow {}", currentShadow);
return;
}
Class<? extends FocusType> focusType = determineFocusClass(synchronizationPolicy, resourceType);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Synchronization is enabled, focus class: {}, found applicable policy: {}", focusType, Utils.getPolicyDesc(synchronizationPolicy));
}
SynchronizationSituation situation = determineSituation(focusType, change, synchronizationPolicy, configuration.asObjectable(), task, subResult);
if (logDebug) {
LOGGER.debug("SYNCHRONIZATION: SITUATION: '{}', currentOwner={}, correlatedOwner={}", situation.getSituation().value(), situation.getCurrentOwner(), situation.getCorrelatedOwner());
} else {
LOGGER.trace("SYNCHRONIZATION: SITUATION: '{}', currentOwner={}, correlatedOwner={}", situation.getSituation().value(), situation.getCurrentOwner(), situation.getCorrelatedOwner());
}
eventInfo.setOriginalSituation(situation.getSituation());
// overwritten
eventInfo.setNewSituation(situation.getSituation());
if (change.isUnrelatedChange() || Utils.isDryRun(task)) {
PrismObject object = null;
if (change.getCurrentShadow() != null) {
object = change.getCurrentShadow();
} else if (change.getOldShadow() != null) {
object = change.getOldShadow();
}
Collection modifications = SynchronizationUtils.createSynchronizationSituationAndDescriptionDelta(object, situation.getSituation(), task.getChannel(), false);
if (StringUtils.isNotBlank(synchronizationPolicy.getIntent())) {
modifications.add(PropertyDelta.createModificationReplaceProperty(ShadowType.F_INTENT, object.getDefinition(), synchronizationPolicy.getIntent()));
}
try {
repositoryService.modifyObject(ShadowType.class, object.getOid(), modifications, subResult);
task.recordObjectActionExecuted(object, ChangeType.MODIFY, null);
} catch (Throwable t) {
task.recordObjectActionExecuted(object, ChangeType.MODIFY, t);
} finally {
task.markObjectActionExecutedBoundary();
}
subResult.recordSuccess();
eventInfo.record(task);
LOGGER.debug("SYNCHRONIZATION: DONE (dry run/unrelated) for {}", object);
return;
}
// must be here, because when the reaction has no action, the
// situation will be not set.
PrismObject<ShadowType> newCurrentShadow = saveSyncMetadata((PrismObject<ShadowType>) currentShadow, situation, change, synchronizationPolicy, task, parentResult);
if (newCurrentShadow != null) {
change.setCurrentShadow(newCurrentShadow);
}
SynchronizationSituationType newSituation = reactToChange(focusType, change, synchronizationPolicy, situation, resourceType, logDebug, configuration, task, subResult);
eventInfo.setNewSituation(newSituation);
eventInfo.record(task);
subResult.computeStatus();
} catch (SystemException ex) {
// avoid unnecessary re-wrap
eventInfo.setException(ex);
eventInfo.record(task);
subResult.recordFatalError(ex);
throw ex;
} catch (Exception ex) {
eventInfo.setException(ex);
eventInfo.record(task);
subResult.recordFatalError(ex);
throw new SystemException(ex);
} finally {
task.markObjectActionExecutedBoundary();
// if (LOGGER.isTraceEnabled()) {
// LOGGER.trace(subResult.dump());
// }
}
LOGGER.debug("SYNCHRONIZATION: DONE for {}", currentShadow);
}
use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.
the class TriggerScannerTaskHandler method removeTrigger.
private void removeTrigger(PrismObject<ObjectType> object, PrismContainerValue<TriggerType> triggerCVal, Task task, PrismContainerDefinition<TriggerType> triggerContainerDef) {
ContainerDelta<TriggerType> triggerDelta = triggerContainerDef.createEmptyDelta(new ItemPath(F_TRIGGER));
triggerDelta.addValuesToDelete(triggerCVal.clone());
Collection<? extends ItemDelta> modifications = MiscSchemaUtil.createCollection(triggerDelta);
// This is detached result. It will not take part of the task result. We do not really care.
OperationResult result = new OperationResult(TriggerScannerTaskHandler.class.getName() + ".removeTrigger");
try {
repositoryService.modifyObject(object.getCompileTimeClass(), object.getOid(), modifications, result);
result.computeStatus();
task.recordObjectActionExecuted(object, ChangeType.MODIFY, null);
} catch (ObjectNotFoundException e) {
// Object is gone. Ergo there are no triggers left. Ergo the trigger was removed.
// Ergo this is not really an error.
task.recordObjectActionExecuted(object, ChangeType.MODIFY, e);
LOGGER.trace("Unable to remove trigger from {}: {} (but this is probably OK)", object, e.getMessage(), e);
} catch (SchemaException | ObjectAlreadyExistsException e) {
task.recordObjectActionExecuted(object, ChangeType.MODIFY, e);
LOGGER.error("Unable to remove trigger from {}: {}", object, e.getMessage(), e);
} catch (Throwable t) {
task.recordObjectActionExecuted(object, ChangeType.MODIFY, t);
throw t;
} finally {
// maybe OK (absolute correctness is not quite important here)
task.markObjectActionExecutedBoundary();
}
}
use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.
the class TestRefinedSchema method test122DetermineObjectClassKindIntentModel.
@Test
public void test122DetermineObjectClassKindIntentModel() throws Exception {
final String TEST_NAME = "test122DetermineObjectClassKindIntentModel";
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(refinedSchemaModel, task);
// THEN
display("Object class", objectClass);
display("Object class (toString)", objectClass.toString());
deleteObject(TaskType.class, TASK_RECONCILE_DUMMY_KIND_INTENT_OID);
assertLayerRefinedObjectClass(objectClass, RESOURCE_DUMMY_PRIVILEGE_OBJECTCLASS_QNAME, ShadowKindType.ENTITLEMENT, "privilege", LayerType.MODEL);
}
use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.
the class TestRefinedSchema method test110DetermineObjectClassObjectClass.
@Test
public void test110DetermineObjectClassObjectClass() throws Exception {
final String TEST_NAME = "test110DetermineObjectClassObjectClass";
TestUtil.displayTestTile(this, TEST_NAME);
OperationResult result = new OperationResult(TestRefinedSchema.class.getName() + "." + TEST_NAME);
importObjectFromFile(TASK_RECONCILE_DUMMY_OBJECTCLASS_FILE);
Task task = taskManager.getTask(TASK_RECONCILE_DUMMY_OBJECTCLASS_OID, result);
display("Task", task);
// WHEN
ObjectClassComplexTypeDefinition objectClass = Utils.determineObjectClass(refinedSchema, task);
// THEN
display("Object class", objectClass);
deleteObject(TaskType.class, TASK_RECONCILE_DUMMY_OBJECTCLASS_OID);
assertObjectClass(objectClass, RESOURCE_DUMMY_ACCOUNT_OBJECTCLASS_QNAME);
}
Aggregations