use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class RefreshHelper method refreshShadowRetryOperations.
private RefreshShadowOperation refreshShadowRetryOperations(ProvisioningContext ctx, PrismObject<ShadowType> repoShadow, List<PendingOperationType> sortedOperations, ProvisioningOperationOptions options, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException, EncryptionException {
ShadowType shadowType = repoShadow.asObjectable();
OperationResult retryResult = new OperationResult(OP_REFRESH_RETRY);
if (ShadowUtil.isDead(shadowType)) {
RefreshShadowOperation rso = new RefreshShadowOperation();
retryResult.recordSuccess();
rso.setRefreshedShadow(repoShadow);
rso.setRefreshResult(retryResult);
return rso;
}
Duration retryPeriod = ProvisioningUtil.getRetryPeriod(ctx);
Collection<ObjectDeltaOperation<ShadowType>> executedDeltas = new ArrayList<>();
for (PendingOperationType pendingOperation : sortedOperations) {
if (!needsRetry(pendingOperation)) {
continue;
}
// We really want to get "now" here. Retrying operation may take some time. We want good timestamps that do not lie.
XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
if (!isAfterRetryPeriod(pendingOperation, retryPeriod, now)) {
if (PendingOperationTypeType.RETRY != pendingOperation.getType()) {
continue;
}
if (!ProvisioningOperationOptions.isForceRetry(options)) {
continue;
}
}
LOGGER.trace("Going to retry operation {} on {}", pendingOperation, repoShadow);
// Record attempt number and timestamp before the operation
// TODO: later use this as an optimistic lock to make sure that two threads won't retry the operation at the same time
// TODO: move to a better place
ObjectDelta<ShadowType> shadowDelta = repoShadow.createModifyDelta();
ItemPath containerPath = pendingOperation.asPrismContainerValue().getPath();
int attemptNumber = pendingOperation.getAttemptNumber() + 1;
PropertyDelta<Integer> attemptNumberDelta = shadowDelta.createPropertyModification(containerPath.append(PendingOperationType.F_ATTEMPT_NUMBER));
attemptNumberDelta.setRealValuesToReplace(attemptNumber);
shadowDelta.addModification(attemptNumberDelta);
PropertyDelta<XMLGregorianCalendar> lastAttemptTimestampDelta = shadowDelta.createPropertyModification(containerPath.append(PendingOperationType.F_LAST_ATTEMPT_TIMESTAMP));
lastAttemptTimestampDelta.setRealValuesToReplace(now);
shadowDelta.addModification(lastAttemptTimestampDelta);
PropertyDelta<OperationResultStatusType> resultStatusDelta = shadowDelta.createPropertyModification(containerPath.append(PendingOperationType.F_RESULT_STATUS));
resultStatusDelta.setRealValuesToReplace(OperationResultStatusType.IN_PROGRESS);
shadowDelta.addModification(resultStatusDelta);
shadowManager.modifyShadowAttributes(ctx, repoShadow, shadowDelta.getModifications(), parentResult);
shadowDelta.applyTo(repoShadow);
ObjectDeltaType pendingDeltaType = pendingOperation.getDelta();
ObjectDelta<ShadowType> pendingDelta = DeltaConvertor.createObjectDelta(pendingDeltaType, prismContext);
ProvisioningOperationState<? extends AsynchronousOperationResult> opState = ProvisioningOperationState.fromPendingOperation(repoShadow, pendingOperation);
LOGGER.debug("Retrying operation {} on {}, attempt #{}", pendingDelta, repoShadow, attemptNumber);
ObjectDeltaOperation<ShadowType> objectDeltaOperation = new ObjectDeltaOperation<>(pendingDelta);
OperationResult result = parentResult.createSubresult(OP_OPERATION_RETRY);
try {
retryOperation(ctx, pendingDelta, opState, task, result);
repoShadow = opState.getRepoShadow();
result.computeStatus();
if (result.isError()) {
retryResult.setStatus(result.getStatus());
}
// TODO maybe add whole "result" as subresult to the retryResult?
result.muteError();
} catch (CommunicationException | GenericFrameworkException | ObjectAlreadyExistsException | SchemaException | ObjectNotFoundException | ConfigurationException | SecurityViolationException e) {
// This is final failure: the error is not handled.
// Therefore the operation is now completed - finished with an error.
// But we do not want to stop the task. Just log the error.
LOGGER.error("Operation {} on {} ended up with an error after {} retries: {}", pendingDelta, repoShadow, attemptNumber, e.getMessage(), e);
// The retry itself was a success. Operation that was retried might have failed.
// And that is recorded in the shadow. But we have successfully retried the operation.
result.recordHandledError(e);
retryResult.recordFatalError("Operation " + pendingDelta + " on " + repoShadow + " ended with an error after " + attemptNumber + " retries: " + e.getMessage());
} catch (Throwable e) {
// This is unexpected error during retry. This means that there was other
// failure that we did not expected. This is likely to be bug - or maybe wrong
// error handling. This means that the retry was a failure.
result.recordFatalError(e);
retryResult.recordFatalError(e);
} finally {
// Status should be set by now, we just want to close the result
result.computeStatusIfUnknown();
}
objectDeltaOperation.setExecutionResult(result);
executedDeltas.add(objectDeltaOperation);
}
RefreshShadowOperation rso = new RefreshShadowOperation();
rso.setExecutedDeltas(executedDeltas);
rso.setRefreshedShadow(repoShadow);
parentResult.computeStatus();
rso.setRefreshResult(retryResult);
LOGGER.trace("refreshShadowOperation {}", rso.debugDumpLazily());
return rso;
}
use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class ObjectChangesExecutorImpl method executeChangesSync.
private Collection<ObjectDeltaOperation<? extends ObjectType>> executeChangesSync(Collection<ObjectDelta<? extends ObjectType>> deltas, ModelExecuteOptions options, Task task, OperationResult result) {
try {
MidPointApplication application = MidPointApplication.get();
ModelService service = application.getModel();
Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = service.executeChanges(deltas, options, task, result);
result.computeStatusIfUnknown();
return executedDeltas;
} catch (CommonException | RuntimeException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Error executing changes", e);
if (!result.isFatalError()) {
// just to be sure the exception is recorded into the result
result.recordFatalError(e.getMessage(), e);
}
}
return null;
}
use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class ProgressReporter 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();
}
if (isWriteOpResultForProgressActivity()) {
si.setOperationResult(result);
}
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<ProgressReportActivityDto.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 ProgressReportActivityDto.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);
}
}
}
}
use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class RObjectDeltaOperation method fromRepo.
public static ObjectDeltaOperation fromRepo(RObjectDeltaOperation operation, PrismContext prismContext) throws DtoTranslationException {
ObjectDeltaOperation odo = new ObjectDeltaOperation();
try {
if (operation.getDelta() != null) {
ObjectDeltaType delta = prismContext.parserFor(operation.getDelta()).parseRealValue(ObjectDeltaType.class);
odo.setObjectDelta(DeltaConvertor.createObjectDelta(delta, prismContext));
}
if (operation.getFullResult() != null) {
OperationResultType resultType = prismContext.parserFor(operation.getFullResult()).parseRealValue(OperationResultType.class);
odo.setExecutionResult(OperationResult.createOperationResult(resultType));
}
odo.setObjectName(RPolyString.fromRepo(operation.getObjectName()));
odo.setResourceOid(operation.getResourceOid());
odo.setResourceName(RPolyString.fromRepo(operation.getResourceName()));
} catch (Exception ex) {
throw new DtoTranslationException(ex.getMessage(), ex);
}
return odo;
}
use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.
the class DummyAuditService method assertAnyRequestDeltas.
public void assertAnyRequestDeltas() {
AuditEventRecord requestRecord = getRequestRecord();
Collection<ObjectDeltaOperation<? extends ObjectType>> requestDeltas = requestRecord.getDeltas();
assert requestDeltas != null && !requestDeltas.isEmpty() : "Expected some deltas in audit request record but found none";
}
Aggregations