use of com.evolveum.midpoint.task.api.TaskRunResult in project midpoint by Evolveum.
the class ModelOperationTaskHandler method run.
@Override
public TaskRunResult run(Task task) {
OperationResult result = task.getResult().createSubresult(DOT_CLASS + "run");
TaskRunResult runResult = new TaskRunResult();
LensContextType contextType = task.getModelOperationContext();
if (contextType == null) {
LOGGER.trace("No model context found, skipping the model operation execution.");
if (result.isUnknown()) {
result.computeStatus();
}
runResult.setRunResultStatus(TaskRunResult.TaskRunResultStatus.FINISHED);
} else {
LensContext context;
try {
context = LensContext.fromLensContextType(contextType, prismContext, provisioningService, task, result);
} catch (SchemaException e) {
throw new SystemException("Cannot recover model context from task " + task + " due to schema exception", e);
} catch (ObjectNotFoundException | ConfigurationException | ExpressionEvaluationException e) {
throw new SystemException("Cannot recover model context from task " + task, e);
} catch (CommunicationException e) {
// todo wait and retry
throw new SystemException("Cannot recover model context from task " + task, e);
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Context to be executed = {}", context.debugDump());
}
try {
// here we brutally remove all the projection contexts -- because if we are continuing after rejection of a role/resource assignment
// that resulted in such projection contexts, we DO NOT want them to appear in the context any more
context.rot();
Iterator<LensProjectionContext> projectionIterator = context.getProjectionContextsIterator();
while (projectionIterator.hasNext()) {
LensProjectionContext projectionContext = projectionIterator.next();
if (projectionContext.getPrimaryDelta() != null && !projectionContext.getPrimaryDelta().isEmpty()) {
// don't remove client requested actions!
continue;
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Removing projection context {}", projectionContext.getHumanReadableName());
}
projectionIterator.remove();
}
if (task.getChannel() == null) {
task.setChannel(context.getChannel());
}
clockwork.run(context, task, result);
task.setModelOperationContext(context.toLensContextType());
task.savePendingModifications(result);
if (result.isUnknown()) {
result.computeStatus();
}
runResult.setRunResultStatus(TaskRunResult.TaskRunResultStatus.FINISHED);
} catch (RuntimeException | CommonException e) {
String message = "An exception occurred within model operation, in task " + task;
LoggingUtils.logUnexpectedException(LOGGER, message, e);
result.recordPartialError(message, e);
// TODO: here we do not know whether the error is temporary or permanent (in the future we could discriminate on the basis of particular exception caught)
runResult.setRunResultStatus(TaskRunResult.TaskRunResultStatus.TEMPORARY_ERROR);
}
}
task.getResult().recomputeStatus();
runResult.setOperationResult(task.getResult());
return runResult;
}
use of com.evolveum.midpoint.task.api.TaskRunResult in project midpoint by Evolveum.
the class ImportAccountsFromResourceTaskHandler method importSingleShadow.
/**
* Imports a single shadow. Synchronously. The task is NOT switched to background by default.
*/
public boolean importSingleShadow(String shadowOid, Task task, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, shadowOid, null, task, parentResult);
PrismObject<ResourceType> resource = provisioningService.getObject(ResourceType.class, ShadowUtil.getResourceOid(shadow), null, task, parentResult);
// Create a result handler just for one object. Invoke the handle() method manually.
TaskRunResult runResult = new TaskRunResult();
SynchronizeAccountResultHandler resultHandler = createHandler(resource.asObjectable(), shadow, runResult, task, parentResult);
if (resultHandler == null) {
return false;
}
// This is required for proper error reporting
resultHandler.setStopOnError(true);
boolean cont = initializeRun(resultHandler, runResult, task, parentResult);
if (!cont) {
return false;
}
cont = resultHandler.handle(shadow, parentResult);
if (!cont) {
return false;
}
finish(resultHandler, runResult, task, parentResult);
return true;
}
Aggregations