use of com.evolveum.midpoint.schema.result.AsynchronousOperationResult in project midpoint by Evolveum.
the class ObjectAlreadyExistHandler method discoverConflictingShadow.
private void discoverConflictingShadow(ProvisioningContext ctx, PrismObject<ShadowType> newShadow, ProvisioningOperationOptions options, ProvisioningOperationState<? extends AsynchronousOperationResult> opState, Exception cause, OperationResult failedOperationResult, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException, SecurityViolationException {
OperationResult result = parentResult.createSubresult(OP_DISCOVERY);
try {
ObjectQuery query = createQueryBySecondaryIdentifier(newShadow.asObjectable(), prismContext);
final List<PrismObject<ShadowType>> conflictingRepoShadows = findConflictingShadowsInRepo(query, result);
PrismObject<ShadowType> oldShadow = selectLiveShadow(conflictingRepoShadows);
if (oldShadow != null) {
shadowCaretaker.applyAttributesDefinition(ctx, oldShadow);
}
LOGGER.trace("DISCOVERY: looking for conflicting shadow for {}", ShadowUtil.shortDumpShadowLazily(newShadow));
final List<PrismObject<ShadowType>> conflictingResourceShadows = findConflictingShadowsOnResource(query, task, result);
PrismObject<ShadowType> conflictingShadow = selectLiveShadow(conflictingResourceShadows);
LOGGER.trace("DISCOVERY: found conflicting shadow for {}:\n{}", newShadow, conflictingShadow == null ? " no conflicting shadow" : conflictingShadow.debugDumpLazily(1));
LOGGER.debug("DISCOVERY: discovered new shadow {}", ShadowUtil.shortDumpShadowLazily(conflictingShadow));
LOGGER.trace("Processing \"already exists\" error for shadow:\n{}\nConflicting repo shadow:\n{}\nConflicting resource shadow:\n{}", newShadow.debugDumpLazily(1), oldShadow == null ? " null" : oldShadow.debugDumpLazily(1), conflictingShadow == null ? " null" : conflictingShadow.debugDumpLazily(1));
if (conflictingShadow != null) {
// Original object and found object share the same object class, therefore they must
// also share a kind. We can use this short-cut.
conflictingShadow.asObjectable().setKind(newShadow.asObjectable().getKind());
ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription();
change.setResource(ctx.getResource().asPrismObject());
change.setSourceChannel(QNameUtil.qNameToUri(SchemaConstants.CHANNEL_DISCOVERY));
change.setShadowedResourceObject(conflictingShadow);
change.setShadowExistsInRepo(true);
eventDispatcher.notifyChange(change, task, result);
}
} finally {
result.computeStatus();
}
}
use of com.evolveum.midpoint.schema.result.AsynchronousOperationResult in project midpoint by Evolveum.
the class CommunicationExceptionHandler method handleDeleteError.
@Override
public OperationResultStatus handleDeleteError(ProvisioningContext ctx, PrismObject<ShadowType> repoShadow, ProvisioningOperationOptions options, ProvisioningOperationState<AsynchronousOperationResult> opState, Exception cause, OperationResult failedOperationResult, Task task, OperationResult parentResult) throws SchemaException, CommunicationException, ObjectNotFoundException, ConfigurationException, ExpressionEvaluationException {
OperationResult result = parentResult.createSubresult(OPERATION_HANDLE_DELETE_ERROR);
result.addParam("exception", cause.getMessage());
try {
String stateChangeReason = "deleting " + repoShadow + " ended with communication problem, " + cause.getMessage();
markResourceDown(ctx.getResourceOid(), stateChangeReason, result, task);
handleRetriesAndAttempts(ctx, opState, options, cause, result);
return postponeDelete(ctx, repoShadow, opState, failedOperationResult, result);
} catch (Throwable t) {
result.recordFatalError(t);
throw t;
} finally {
result.computeStatusIfUnknown();
}
}
use of com.evolveum.midpoint.schema.result.AsynchronousOperationResult in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method deleteObject.
@Override
public AsynchronousOperationResult deleteObject(ObjectClassComplexTypeDefinition objectClass, Collection<Operation> additionalOperations, Collection<? extends ResourceAttribute<?>> identifiers, StateReporter reporter, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, GenericFrameworkException, SchemaException {
Validate.notNull(objectClass, "No objectclass");
OperationResult result = parentResult.createSubresult(ConnectorInstance.class.getName() + ".deleteObject");
result.addCollectionOfSerializablesAsParam("identifiers", identifiers);
ObjectClass objClass = connIdNameMapper.objectClassToIcf(objectClass, getSchemaNamespace(), connectorType, legacySchema);
Uid uid;
try {
uid = getUid(objectClass, identifiers);
} catch (SchemaException e) {
result.recordFatalError(e);
throw e;
}
checkAndExecuteAdditionalOperation(reporter, additionalOperations, BeforeAfterType.BEFORE, result);
OperationResult icfResult = result.createSubresult(ConnectorFacade.class.getName() + ".delete");
icfResult.addArbitraryObjectAsParam("uid", uid);
icfResult.addArbitraryObjectAsParam("objectClass", objClass);
icfResult.addContext("connector", connIdConnectorFacade.getClass());
try {
InternalMonitor.recordConnectorOperation("delete");
recordIcfOperationStart(reporter, ProvisioningOperation.ICF_DELETE, objectClass, uid);
connIdConnectorFacade.delete(objClass, uid, new OperationOptionsBuilder().build());
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_DELETE, objectClass, null, uid);
icfResult.recordSuccess();
} catch (Throwable ex) {
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_DELETE, objectClass, ex, uid);
String desc = this.getHumanReadableName() + " while deleting object identified by ICF UID '" + uid.getUidValue() + "'";
Throwable midpointEx = processIcfException(ex, desc, icfResult);
result.computeStatus("Removing attribute values failed");
// exception
if (midpointEx instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException) midpointEx;
} else if (midpointEx instanceof CommunicationException) {
throw (CommunicationException) midpointEx;
} else if (midpointEx instanceof GenericFrameworkException) {
throw (GenericFrameworkException) midpointEx;
} else if (midpointEx instanceof SchemaException) {
// Schema exception during delete? It must be a missing UID
throw new IllegalArgumentException(midpointEx.getMessage(), midpointEx);
} else if (midpointEx instanceof RuntimeException) {
throw (RuntimeException) midpointEx;
} else if (midpointEx instanceof Error) {
throw (Error) midpointEx;
} else {
throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
}
}
checkAndExecuteAdditionalOperation(reporter, additionalOperations, BeforeAfterType.AFTER, result);
result.computeStatus();
return AsynchronousOperationResult.wrap(result);
}
use of com.evolveum.midpoint.schema.result.AsynchronousOperationResult in project midpoint by Evolveum.
the class ShadowCache method deleteShadow.
public void deleteShadow(PrismObject<ShadowType> shadow, ProvisioningOperationOptions options, OperationProvisioningScriptsType scripts, Task task, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, ObjectNotFoundException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
Validate.notNull(shadow, "Object to delete must not be null.");
Validate.notNull(parentResult, "Operation result must not be null.");
InternalMonitor.recordShadowChangeOperation();
ProvisioningContext ctx = ctxFactory.create(shadow, task, parentResult);
try {
ctx.assertDefinition();
} catch (ObjectNotFoundException ex) {
// although the resource does not exists..
if (ProvisioningOperationOptions.isForce(options)) {
parentResult.muteLastSubresultError();
shadowManager.deleteShadow(ctx, shadow, null, parentResult);
parentResult.recordHandledError("Resource defined in shadow does not exists. Shadow was deleted from the repository.");
return;
} else {
throw ex;
}
}
applyAttributesDefinition(ctx, shadow);
LOGGER.trace("Deleting object {} from the resource {}.", shadow, ctx.getResource());
AsynchronousOperationResult asyncReturnValue = null;
if (shadow.asObjectable().getFailedOperationType() == null || (shadow.asObjectable().getFailedOperationType() != null && FailedOperationTypeType.ADD != shadow.asObjectable().getFailedOperationType())) {
try {
asyncReturnValue = resouceObjectConverter.deleteResourceObject(ctx, shadow, scripts, parentResult);
} catch (Exception ex) {
try {
handleError(ctx, ex, shadow, FailedOperation.DELETE, null, isDoDiscovery(ctx.getResource(), options), isCompensate(options), parentResult);
} catch (ObjectAlreadyExistsException e) {
parentResult.recordFatalError(e);
throw new SystemException(e.getMessage(), e);
}
return;
}
}
LOGGER.trace("Detele object with oid {} form repository.", shadow.getOid());
try {
shadowManager.deleteShadow(ctx, shadow, asyncReturnValue == null ? null : asyncReturnValue.getOperationResult(), parentResult);
} catch (ObjectNotFoundException ex) {
parentResult.recordFatalError("Can't delete object " + shadow + ". Reason: " + ex.getMessage(), ex);
throw new ObjectNotFoundException("An error occured while deleting resource object " + shadow + "whith identifiers " + shadow + ": " + ex.getMessage(), ex);
}
ObjectDelta<ShadowType> delta = ObjectDelta.createDeleteDelta(shadow.getCompileTimeClass(), shadow.getOid(), prismContext);
ResourceOperationDescription operationDescription = createSuccessOperationDescription(ctx, shadow, delta, parentResult);
if (asyncReturnValue != null && asyncReturnValue.isInProgress()) {
operationListener.notifyInProgress(operationDescription, task, parentResult);
} else {
operationListener.notifySuccess(operationDescription, task, parentResult);
}
LOGGER.trace("Object deleted from repository successfully.");
parentResult.computeStatus();
resourceManager.modifyResourceAvailabilityStatus(ctx.getResource().asPrismObject(), AvailabilityStatusType.UP, parentResult);
}
use of com.evolveum.midpoint.schema.result.AsynchronousOperationResult in project midpoint by Evolveum.
the class AbstractManualConnectorInstance method deleteObject.
@Override
public AsynchronousOperationResult deleteObject(ResourceObjectDefinition objectDefinition, PrismObject<ShadowType> shadow, Collection<? extends ResourceAttribute<?>> identifiers, UcfExecutionContext ctx, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, GenericFrameworkException, SchemaException, ConfigurationException {
OperationResult result = parentResult.createSubresult(OPERATION_DELETE);
InternalMonitor.recordConnectorOperation("delete");
InternalMonitor.recordConnectorModification("delete");
String ticketIdentifier;
try {
ticketIdentifier = createTicketDelete(objectDefinition, shadow, identifiers, ctx.getResourceOid(), ctx.getTask(), result);
} catch (ObjectNotFoundException | CommunicationException | GenericFrameworkException | SchemaException | ConfigurationException | RuntimeException | Error e) {
result.recordFatalError(e);
throw e;
}
result.recordInProgress();
result.setAsynchronousOperationReference(ticketIdentifier);
AsynchronousOperationResult ret = AsynchronousOperationResult.wrap(result);
ret.setOperationType(PendingOperationTypeType.MANUAL);
return ret;
}
Aggregations