use of com.evolveum.midpoint.schema.statistics.Operation in project midpoint by Evolveum.
the class ValidateExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
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 ResourceType) {
// noinspection unchecked
PrismObject<ResourceType> resourceTypePrismObject = ((PrismObjectValue<ResourceType>) value).asPrismObject();
ResourceType resourceType = resourceTypePrismObject.asObjectable();
Operation op = operationsHelper.recordStart(context, resourceType);
try {
ValidationResult validationResult = resourceValidator.validate(resourceTypePrismObject, Scope.THOROUGH, null, context.getTask(), result);
PrismContainerDefinition<ValidationResultType> pcd = prismContext.getSchemaRegistry().findContainerDefinitionByElementName(SchemaConstantsGenerated.C_VALIDATION_RESULT);
PrismContainer<ValidationResultType> pc = pcd.instantiate();
// noinspection unchecked
pc.add(validationResult.toValidationResultType().asPrismContainerValue());
context.println("Validated " + resourceTypePrismObject + ": " + validationResult.getIssues().size() + " issue(s)");
operationsHelper.recordEnd(context, op, null, result);
output.add(new PipelineItem(pc.getValue(), item.getResult()));
} catch (SchemaException | RuntimeException e) {
operationsHelper.recordEnd(context, op, e, result);
context.println("Error validation " + resourceTypePrismObject + ": " + e.getMessage());
// noinspection ThrowableNotThrown
processActionException(e, NAME, value, context);
output.add(item);
}
} else {
// noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismObject<ResourceType>"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, item.getResult());
}
return output;
}
use of com.evolveum.midpoint.schema.statistics.Operation in project midpoint by Evolveum.
the class SimpleMockActivityRun method runLocally.
@Override
@NotNull
protected ActivityRunResult runLocally(OperationResult result) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException {
String message = activity.getWorkDefinition().getMessage();
Operation operation = activityState.getLiveItemProcessingStatistics().recordOperationStart(new IterativeOperationStartInfo(new IterationItemInformation(message, null, null, null)));
// to avoid wall clock time of 0 (failing throughput-assuming tests)
MiscUtil.sleepCatchingInterruptedException(10);
LOGGER.info("Message: {}", message);
getRecorder().recordExecution(message);
CommonMockActivityHelper helper = getActivityHandler().getMockHelper();
helper.increaseExecutionCount(activityState, result);
try {
helper.failIfNeeded(this, activity.getWorkDefinition().getInitialFailures());
QualifiedItemProcessingOutcomeType qualifiedOutcome = new QualifiedItemProcessingOutcomeType(getPrismContext()).outcome(ItemProcessingOutcomeType.SUCCESS);
operation.done(qualifiedOutcome, null);
incrementProgress(qualifiedOutcome);
} catch (Exception e) {
QualifiedItemProcessingOutcomeType qualifiedOutcome = new QualifiedItemProcessingOutcomeType(getPrismContext()).outcome(ItemProcessingOutcomeType.FAILURE);
operation.done(qualifiedOutcome, e);
incrementProgress(qualifiedOutcome);
throw e;
}
return standardRunResult();
}
use of com.evolveum.midpoint.schema.statistics.Operation in project midpoint by Evolveum.
the class AccessCertificationCampaignCreationTaskHandler method run.
@Override
public TaskRunResult run(@NotNull RunningTask task) {
LOGGER.trace("Task run starting");
OperationResult opResult = task.getResult().createSubresult(CLASS_DOT + "run");
opResult.setSummarizeSuccesses(true);
TaskRunResult runResult = new TaskRunResult();
String definitionOid = task.getObjectOid();
if (definitionOid == null) {
LOGGER.error("No definition OID specified in the task");
opResult.recordFatalError("No definition OID specified in the task");
runResult.setOperationResultStatus(OperationResultStatus.FATAL_ERROR);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
opResult.addContext("definitionOid", definitionOid);
AccessCertificationCampaignType campaign;
try {
LOGGER.debug("Creating campaign with definition of {}", definitionOid);
campaign = certificationManager.createCampaign(definitionOid, task, opResult);
LOGGER.info("Campaign {} was created.", ObjectTypeUtil.toShortString(campaign));
} catch (Exception e) {
LoggingUtils.logException(LOGGER, "Error while executing 'create campaign' task handler", e);
opResult.recordFatalError("Error while executing 'create campaign' task handler: " + e.getMessage(), e);
runResult.setOperationResultStatus(OperationResultStatus.FATAL_ERROR);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
Operation op = task.recordIterativeOperationStart(campaign.asPrismObject());
try {
certificationManager.openNextStage(campaign.getOid(), task, opResult);
LOGGER.info("Campaign {} was started.", ObjectTypeUtil.toShortString(campaign));
op.succeeded();
opResult.computeStatus();
runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
runResult.setOperationResultStatus(OperationResultStatus.SUCCESS);
runResult.setProgress(task.getLegacyProgress() + 1);
return runResult;
} catch (CommonException | RuntimeException e) {
op.failed(e);
LoggingUtils.logException(LOGGER, "Error while executing 'create campaign' task handler", e);
opResult.recordFatalError("Error while executing 'create campaign' task handler: " + e.getMessage(), e);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
runResult.setOperationResultStatus(OperationResultStatus.FATAL_ERROR);
return runResult;
}
}
use of com.evolveum.midpoint.schema.statistics.Operation in project midpoint by Evolveum.
the class BaseActionExecutor method iterateOverItems.
void iterateOverItems(PipelineData input, ExecutionContext context, OperationResult globalResult, ItemProcessor itemProcessor, ConsoleFailureMessageWriter writer) throws ScriptExecutionException {
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, globalResult);
context.checkTaskStop();
Operation op;
if (value instanceof PrismObjectValue) {
op = operationsHelper.recordStart(context, asObjectType(value));
} else {
op = null;
}
try {
itemProcessor.process(value, item, result);
operationsHelper.recordEnd(context, op, null, result);
} catch (Throwable ex) {
result.recordFatalError(ex);
operationsHelper.recordEnd(context, op, ex, result);
Throwable exception = processActionException(ex, getActionName(), value, context);
writer.write(value, exception);
}
operationsHelper.trimAndCloneResult(result, item.getResult());
}
}
use of com.evolveum.midpoint.schema.statistics.Operation in project midpoint by Evolveum.
the class AbstractObjectBasedActionExecutor method iterateOverObjects.
void iterateOverObjects(PipelineData input, ExecutionContext context, OperationResult globalResult, ObjectProcessor<T> consumer, ConsoleFailureMessageWriter<T> writer) throws ScriptExecutionException {
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, globalResult);
try {
context.checkTaskStop();
PrismObject<T> object = castToObject(value, getObjectType(), context);
if (object != null) {
T objectable = object.asObjectable();
Operation op = operationsHelper.recordStart(context, objectable);
try {
consumer.process(object, item, result);
operationsHelper.recordEnd(context, op, null, result);
} catch (Throwable e) {
result.recordFatalError(e);
operationsHelper.recordEnd(context, op, e, result);
Throwable exception = processActionException(e, getActionName(), value, context);
writer.write(object, exception);
}
}
operationsHelper.trimAndCloneResult(result, item.getResult());
} catch (Throwable t) {
result.recordFatalError(t);
throw t;
} finally {
// just in case (should be already computed)
result.computeStatusIfUnknown();
}
}
}
Aggregations