Search in sources :

Example 1 with OperationResultStatus

use of com.evolveum.midpoint.schema.result.OperationResultStatus in project midpoint by Evolveum.

the class DefaultGuiProgressListener method updateStatusItemState.

private void updateStatusItemState(ProgressReportActivityDto si, ProgressInformation progressInformation, ModelContext modelContext) {
    si.setActivityType(progressInformation.getActivityType());
    si.setResourceShadowDiscriminator(progressInformation.getResourceShadowDiscriminator());
    if (progressInformation.getResourceShadowDiscriminator() != null) {
        String resourceOid = progressInformation.getResourceShadowDiscriminator().getResourceOid();
        String resourceName = resourceOid != null ? getResourceName(resourceOid) : "";
        si.setResourceName(resourceName);
    }
    if (progressInformation.getStateType() == null) {
        si.setStatus(null);
    } else if (progressInformation.getStateType() == ENTERING) {
        si.setStatus(OperationResultStatusType.IN_PROGRESS);
    } else {
        OperationResult result = progressInformation.getOperationResult();
        if (result != null) {
            OperationResultStatus status = result.getStatus();
            if (status == OperationResultStatus.UNKNOWN) {
                status = result.getComputeStatus();
            }
            si.setStatus(status.createStatusType());
        } else {
            si.setStatus(OperationResultStatusType.UNKNOWN);
        }
    }
    // information about modifications on a resource
    if (progressInformation.getActivityType() == RESOURCE_OBJECT_OPERATION && progressInformation.getStateType() == EXITING && progressInformation.getResourceShadowDiscriminator() != null && progressInformation.getResourceShadowDiscriminator().getResourceOid() != null) {
        ModelProjectionContext mpc = modelContext.findProjectionContext(progressInformation.getResourceShadowDiscriminator());
        if (mpc != null) {
            // it shouldn't be null!
            // operations performed (TODO aggregate them somehow?)
            List<ResourceOperationResult> resourceOperationResultList = new ArrayList<>();
            List<? extends ObjectDeltaOperation> executedDeltas = mpc.getExecutedDeltas();
            for (ObjectDeltaOperation executedDelta : executedDeltas) {
                ObjectDelta delta = executedDelta.getObjectDelta();
                if (delta != null) {
                    OperationResult r = executedDelta.getExecutionResult();
                    OperationResultStatus status = r.getStatus();
                    if (status == OperationResultStatus.UNKNOWN) {
                        status = r.getComputeStatus();
                    }
                    resourceOperationResultList.add(new ResourceOperationResult(delta.getChangeType(), status));
                }
            }
            si.setResourceOperationResultList(resourceOperationResultList);
            // object name
            PrismObject<ShadowType> object = mpc.getObjectNew();
            if (object == null) {
                object = mpc.getObjectOld();
            }
            String name = null;
            if (object != null) {
                if (object.asObjectable().getName() != null) {
                    name = PolyString.getOrig(object.asObjectable().getName());
                } else {
                    // determine from attributes
                    ResourceAttribute nameAttribute = ShadowUtil.getNamingAttribute(object);
                    if (nameAttribute != null) {
                        name = String.valueOf(nameAttribute.getAnyRealValue());
                    }
                }
            }
            if (name != null) {
                si.setResourceObjectName(name);
            }
        }
    }
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceOperationResult(com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) ResourceOperationResult(com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult)

Example 2 with OperationResultStatus

use of com.evolveum.midpoint.schema.result.OperationResultStatus in project midpoint by Evolveum.

the class AssignmentProcessor method processAssignmentsProjections.

/**
     * Processing all the assignments to determine which projections should be added, deleted or kept as they are.
     * Generic method for all projection types (theoretically). 
     */
@SuppressWarnings("unchecked")
public <O extends ObjectType> void processAssignmentsProjections(LensContext<O> context, XMLGregorianCalendar now, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, PolicyViolationException, CommunicationException, ConfigurationException, SecurityViolationException {
    LensFocusContext<O> focusContext = context.getFocusContext();
    if (focusContext == null) {
        return;
    }
    if (!FocusType.class.isAssignableFrom(focusContext.getObjectTypeClass())) {
        // We can do this only for FocusType.
        return;
    }
    //    	if (ModelExecuteOptions.isLimitPropagation(context.getOptions()) && SchemaConstants.CHANGE_CHANNEL_DISCOVERY.equals(QNameUtil.uriToQName(context.getChannel()))){
    //    		//do not execute assignment if the execution was triggered by compensation mechanism and limitPropagation is set
    //    		return;
    //    	}
    OperationResult result = parentResult.createSubresult(AssignmentProcessor.class.getName() + ".processAssignmentsProjections");
    try {
        processAssignmentsProjectionsWithFocus((LensContext<? extends FocusType>) context, now, task, result);
    } catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException | PolicyViolationException | CommunicationException | ConfigurationException | SecurityViolationException | RuntimeException | Error e) {
        result.recordFatalError(e);
        throw e;
    }
    OperationResultStatus finalStatus = OperationResultStatus.SUCCESS;
    String message = null;
    int errors = 0;
    for (OperationResult subresult : result.getSubresults()) {
        if (subresult.isError()) {
            errors++;
            if (message == null) {
                message = subresult.getMessage();
            } else {
                message = errors + " errors";
            }
            finalStatus = OperationResultStatus.PARTIAL_ERROR;
        }
    }
    result.setStatus(finalStatus);
    result.setMessage(message);
    result.cleanupResult();
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException)

Example 3 with OperationResultStatus

use of com.evolveum.midpoint.schema.result.OperationResultStatus 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;
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus)

Example 4 with OperationResultStatus

use of com.evolveum.midpoint.schema.result.OperationResultStatus in project midpoint by Evolveum.

the class ResourceController method updateLastAvailabilityState.

public static void updateLastAvailabilityState(ResourceState state, AvailabilityStatusType lastAvailabilityStatus) {
    OperationResultStatus lastAvailability = OperationResultStatus.UNKNOWN;
    if (lastAvailabilityStatus == null) {
        if (state.getOverall().equals(OperationResultStatus.SUCCESS)) {
            lastAvailability = OperationResultStatus.SUCCESS;
        } else if ((state.getOverall().equals(OperationResultStatus.PARTIAL_ERROR) || state.getOverall().equals(OperationResultStatus.FATAL_ERROR) || state.getOverall().equals(OperationResultStatus.HANDLED_ERROR))) {
            lastAvailability = OperationResultStatus.PARTIAL_ERROR;
        }
        state.setLastAvailability(lastAvailability);
        return;
    }
    if (state.getOverall().equals(OperationResultStatus.SUCCESS) && !lastAvailabilityStatus.equals(AvailabilityStatusType.UP)) {
        lastAvailability = OperationResultStatus.SUCCESS;
    } else if ((state.getOverall().equals(OperationResultStatus.PARTIAL_ERROR) || state.getOverall().equals(OperationResultStatus.FATAL_ERROR) || state.getOverall().equals(OperationResultStatus.HANDLED_ERROR)) && !lastAvailabilityStatus.equals(AvailabilityStatusType.DOWN)) {
        lastAvailability = OperationResultStatus.PARTIAL_ERROR;
    }
    if (!lastAvailability.equals(OperationResultStatus.UNKNOWN)) {
        state.setLastAvailability(lastAvailability);
        return;
    }
    switch(lastAvailabilityStatus) {
        case UP:
            lastAvailability = OperationResultStatus.SUCCESS;
            break;
        case DOWN:
            lastAvailability = OperationResultStatus.PARTIAL_ERROR;
            break;
    }
    state.setLastAvailability(lastAvailability);
}
Also used : OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus)

Example 5 with OperationResultStatus

use of com.evolveum.midpoint.schema.result.OperationResultStatus in project midpoint by Evolveum.

the class ResourceObjectConverter method refreshOperationStatus.

public OperationResultStatus refreshOperationStatus(ProvisioningContext ctx, PrismObject<ShadowType> shadow, String asyncRef, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    OperationResult result = parentResult.createSubresult(OPERATION_REFRESH_OPERATION_STATUS);
    ResourceType resource;
    ConnectorInstance connector;
    try {
        resource = ctx.getResource();
        // TODO: not really correct. But good enough for now.
        connector = ctx.getConnector(UpdateCapabilityType.class, result);
    } catch (ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException | ExpressionEvaluationException | RuntimeException | Error e) {
        result.recordFatalError(e);
        throw e;
    }
    OperationResultStatus status = null;
    if (connector instanceof AsynchronousOperationQueryable) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("PROVISIONING REFRESH operation on {}, object: {}", resource, shadow);
        }
        try {
            status = ((AsynchronousOperationQueryable) connector).queryOperationStatus(asyncRef, result);
        } catch (ObjectNotFoundException | SchemaException e) {
            result.recordFatalError(e);
            throw e;
        }
        result.recordSuccess();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("PROVISIONING REFRESH successful, returned status: {}", status);
        }
    } else {
        LOGGER.trace("Ignoring refresh of shadow {}, because the connector is not async");
        result.recordNotApplicableIfUnknown();
    }
    return status;
}
Also used : UpdateCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.UpdateCapabilityType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) AsynchronousOperationQueryable(com.evolveum.midpoint.schema.result.AsynchronousOperationQueryable)

Aggregations

OperationResultStatus (com.evolveum.midpoint.schema.result.OperationResultStatus)14 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)9 AsynchronousOperationResult (com.evolveum.midpoint.schema.result.AsynchronousOperationResult)2 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 ArrayList (java.util.ArrayList)2 ShadowDiscriminatorObjectDelta (com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta)1 ModelProjectionContext (com.evolveum.midpoint.model.api.context.ModelProjectionContext)1 TestRbac (com.evolveum.midpoint.model.intest.rbac.TestRbac)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)1 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)1 AsynchronousOperationQueryable (com.evolveum.midpoint.schema.result.AsynchronousOperationQueryable)1 Task (com.evolveum.midpoint.task.api.Task)1 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)1 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)1 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)1