Search in sources :

Example 1 with Operation

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;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ScriptExecutionException(com.evolveum.midpoint.util.exception.ScriptExecutionException) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Operation(com.evolveum.midpoint.schema.statistics.Operation) ValidationResult(com.evolveum.midpoint.model.api.validator.ValidationResult) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ValidationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValidationResultType)

Example 2 with Operation

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();
}
Also used : QualifiedItemProcessingOutcomeType(com.evolveum.midpoint.xml.ns._public.common.common_3.QualifiedItemProcessingOutcomeType) CommonMockActivityHelper(com.evolveum.midpoint.repo.common.tasks.handlers.CommonMockActivityHelper) IterativeOperationStartInfo(com.evolveum.midpoint.schema.statistics.IterativeOperationStartInfo) Operation(com.evolveum.midpoint.schema.statistics.Operation) IterationItemInformation(com.evolveum.midpoint.schema.statistics.IterationItemInformation) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with Operation

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;
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) Operation(com.evolveum.midpoint.schema.statistics.Operation) CommonException(com.evolveum.midpoint.util.exception.CommonException) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)

Example 4 with Operation

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());
    }
}
Also used : PrismObjectValue(com.evolveum.midpoint.prism.PrismObjectValue) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Operation(com.evolveum.midpoint.schema.statistics.Operation) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 5 with Operation

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();
        }
    }
}
Also used : PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Operation(com.evolveum.midpoint.schema.statistics.Operation) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Aggregations

Operation (com.evolveum.midpoint.schema.statistics.Operation)11 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)5 IterationItemInformation (com.evolveum.midpoint.schema.statistics.IterationItemInformation)5 IterativeOperationStartInfo (com.evolveum.midpoint.schema.statistics.IterativeOperationStartInfo)5 PipelineData (com.evolveum.midpoint.model.impl.scripting.PipelineData)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 ScriptExecutionException (com.evolveum.midpoint.util.exception.ScriptExecutionException)3 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 PrismValue (com.evolveum.midpoint.prism.PrismValue)2 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2 RunningTask (com.evolveum.midpoint.task.api.RunningTask)2 TimeBoundary (com.evolveum.midpoint.task.quartzimpl.util.TimeBoundary)2 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 QualifiedItemProcessingOutcomeType (com.evolveum.midpoint.xml.ns._public.common.common_3.QualifiedItemProcessingOutcomeType)2 NotNull (org.jetbrains.annotations.NotNull)2 ValidationResult (com.evolveum.midpoint.model.api.validator.ValidationResult)1 PrismObjectValue (com.evolveum.midpoint.prism.PrismObjectValue)1 Protector (com.evolveum.midpoint.prism.crypto.Protector)1