use of com.evolveum.midpoint.provisioning.api.ResourceOperationDescription in project midpoint by Evolveum.
the class SimpleResourceObjectNotifier method getBody.
@Override
protected String getBody(Event event, GeneralNotifierType generalNotifierType, String transport, Task task, OperationResult result) {
boolean techInfo = Boolean.TRUE.equals(generalNotifierType.isShowTechnicalInformation());
StringBuilder body = new StringBuilder();
ResourceObjectEvent resourceObjectEvent = (ResourceObjectEvent) event;
FocusType owner = (FocusType) resourceObjectEvent.getRequesteeObject();
ResourceOperationDescription rod = resourceObjectEvent.getAccountOperationDescription();
ObjectDelta<ShadowType> delta = (ObjectDelta<ShadowType>) rod.getObjectDelta();
boolean isAccount = resourceObjectEvent.isShadowKind(ShadowKindType.ACCOUNT);
String objectTypeDescription = isAccount ? "account" : "resource object";
String userOrOwner = owner instanceof UserType ? "User" : "Owner";
body.append("Notification about ").append(objectTypeDescription).append("-related operation\n\n");
if (isAccount) {
if (owner != null) {
body.append(userOrOwner).append(": ").append(resourceObjectEvent.getRequesteeDisplayName());
body.append(" (").append(owner.getName()).append(", oid ").append(owner.getOid()).append(")\n");
} else {
body.append(userOrOwner).append(": unknown\n");
}
}
body.append("Notification created on: " + new Date() + "\n\n");
body.append("Resource: " + resourceObjectEvent.getResourceName() + " (oid " + resourceObjectEvent.getResourceOid() + ")\n");
boolean named;
if (rod.getCurrentShadow() != null && rod.getCurrentShadow().asObjectable().getName() != null) {
if (isAccount) {
body.append("Account: " + rod.getCurrentShadow().asObjectable().getName() + "\n");
} else {
body.append("Resource object: " + rod.getCurrentShadow().asObjectable().getName() + " (kind: " + rod.getCurrentShadow().asObjectable().getKind() + ")\n");
}
named = true;
} else {
named = false;
}
body.append("\n");
if (isAccount) {
body.append((named ? "The" : "An") + " account ");
} else {
body.append((named ? "The" : "A") + " resource object ");
}
switch(resourceObjectEvent.getOperationStatus()) {
case SUCCESS:
body.append("has been successfully ");
break;
case IN_PROGRESS:
body.append("has been ATTEMPTED to be ");
break;
case FAILURE:
body.append("FAILED to be ");
break;
}
final boolean watchSynchronizationAttributes = isWatchSynchronizationAttributes((SimpleResourceObjectNotifierType) generalNotifierType);
final boolean watchAuxiliaryAttributes = isWatchAuxiliaryAttributes(generalNotifierType);
if (delta.isAdd()) {
body.append("created on the resource with attributes:\n");
body.append(resourceObjectEvent.getContentAsFormattedList(watchSynchronizationAttributes, watchAuxiliaryAttributes));
body.append("\n");
} else if (delta.isModify()) {
body.append("modified on the resource. Modified attributes are:\n");
body.append(resourceObjectEvent.getContentAsFormattedList(watchSynchronizationAttributes, watchAuxiliaryAttributes));
body.append("\n");
} else if (delta.isDelete()) {
body.append("removed from the resource.\n\n");
}
if (resourceObjectEvent.getOperationStatus() == OperationStatus.IN_PROGRESS) {
body.append("The operation will be retried.\n\n");
} else if (resourceObjectEvent.getOperationStatus() == OperationStatus.FAILURE) {
body.append("Error: " + resourceObjectEvent.getAccountOperationDescription().getResult().getMessage() + "\n\n");
}
body.append("\n\n");
functions.addRequesterAndChannelInformation(body, event, result);
if (techInfo) {
body.append("----------------------------------------\n");
body.append("Technical information:\n\n");
body.append(rod.debugDump(2));
}
return body.toString();
}
use of com.evolveum.midpoint.provisioning.api.ResourceOperationDescription in project midpoint by Evolveum.
the class SchemaExceptionHandler method handleError.
@Override
public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Exception ex, boolean doDiscovery, boolean compensate, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException, SecurityViolationException {
if (!doDiscovery) {
parentResult.recordFatalError(ex);
if (ex instanceof SchemaException) {
throw (SchemaException) ex;
} else {
throw new SchemaException(ex.getMessage(), ex);
}
}
ObjectDelta delta = null;
switch(op) {
case ADD:
delta = ObjectDelta.createAddDelta(shadow.asPrismObject());
break;
case DELETE:
delta = ObjectDelta.createDeleteDelta(shadow.getClass(), shadow.getOid(), prismContext);
break;
case MODIFY:
Collection<? extends ItemDelta> modifications = null;
if (shadow.getObjectChange() != null) {
ObjectDeltaType deltaType = shadow.getObjectChange();
modifications = DeltaConvertor.toModifications(deltaType.getItemDelta(), shadow.asPrismObject().getDefinition());
}
delta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, shadow.getClass(), prismContext);
break;
}
if (op != FailedOperation.GET) {
// Task task = taskManager.createTaskInstance();
ResourceOperationDescription operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, parentResult);
changeNotificationDispatcher.notifyFailure(operationDescription, task, parentResult);
}
if (shadow.getOid() == null) {
parentResult.recordFatalError("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
throw new SchemaException("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
}
Collection<ItemDelta> modification = createAttemptModification(shadow, null);
try {
ConstraintsChecker.onShadowModifyOperation(modification);
cacheRepositoryService.modifyObject(shadow.asPrismObject().getCompileTimeClass(), shadow.getOid(), modification, parentResult);
} catch (Exception e) {
//this should not happen. But if it happens, we should return original exception
// throw new SchemaException("Schema violation during processing shadow: "
// + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
}
parentResult.recordFatalError("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
throw new SchemaException("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
}
use of com.evolveum.midpoint.provisioning.api.ResourceOperationDescription in project midpoint by Evolveum.
the class SecurityViolationHandler method handleError.
@Override
public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Exception ex, boolean doDiscovery, boolean compensate, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException, SecurityViolationException {
if (!doDiscovery) {
parentResult.recordFatalError(ex);
if (ex instanceof SecurityViolationException) {
throw (SecurityViolationException) ex;
} else {
throw new SecurityViolationException(ex.getMessage(), ex);
}
}
ObjectDelta delta = null;
switch(op) {
case ADD:
delta = ObjectDelta.createAddDelta(shadow.asPrismObject());
break;
case DELETE:
delta = ObjectDelta.createDeleteDelta(shadow.getClass(), shadow.getOid(), prismContext);
break;
case MODIFY:
Collection<? extends ItemDelta> modifications = null;
if (shadow.getObjectChange() != null) {
ObjectDeltaType deltaType = shadow.getObjectChange();
modifications = DeltaConvertor.toModifications(deltaType.getItemDelta(), shadow.asPrismObject().getDefinition());
}
delta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, shadow.getClass(), prismContext);
break;
}
if (op != FailedOperation.GET) {
// Task task = taskManager.createTaskInstance();
ResourceOperationDescription operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, parentResult);
changeNotificationDispatcher.notifyFailure(operationDescription, task, parentResult);
}
if (shadow.getOid() == null) {
throw new SecurityViolationException("Security violation during processing shadow " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
}
Collection<ItemDelta> modification = createAttemptModification(shadow, null);
try {
ConstraintsChecker.onShadowModifyOperation(modification);
cacheRepositoryService.modifyObject(shadow.asPrismObject().getCompileTimeClass(), shadow.getOid(), modification, parentResult);
} catch (Exception e) {
//this should not happen. But if it happens, we should return original exception
}
throw new SecurityViolationException("Security violation during processing shadow " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
}
use of com.evolveum.midpoint.provisioning.api.ResourceOperationDescription in project midpoint by Evolveum.
the class CommunicationExceptionHandler method handleError.
@Override
public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Exception ex, boolean doDiscovery, boolean compensate, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException {
if (!doDiscovery) {
parentResult.recordFatalError(ex);
if (ex instanceof CommunicationException) {
throw (CommunicationException) ex;
} else {
throw new CommunicationException(ex.getMessage(), ex);
}
}
Validate.notNull(shadow, "Shadow must not be null.");
OperationResult operationResult = parentResult.createSubresult("com.evolveum.midpoint.provisioning.consistency.impl.CommunicationExceptionHandler.handleError." + op.name());
operationResult.addParam("shadow", shadow);
operationResult.addParam("currentOperation", op);
operationResult.addParam("exception", ex.getMessage());
// first modify last availability status in the resource, so by others
// operations, we can know that it is down
resourceManager.modifyResourceAvailabilityStatus(shadow.getResource().asPrismObject(), AvailabilityStatusType.DOWN, operationResult);
if ((!isPostpone(shadow.getResource()) || !compensate) && !FailedOperation.GET.equals(op)) {
LOGGER.trace("Postponing operation turned off.");
operationResult.recordFatalError(ex.getMessage(), ex);
throw new CommunicationException(ex.getMessage(), ex);
}
// Task task = null;
ObjectDelta delta = null;
ResourceOperationDescription operationDescription = null;
switch(op) {
case ADD:
// if it is first time, just store the whole account to the repo
LOGGER.trace("Postponing ADD operation for {}", ObjectTypeUtil.toShortString(shadow));
ResourceType resource = shadow.getResource();
if (shadow.getFailedOperationType() == null) {
// ResourceType resource = shadow.getResource();
if (shadow.getName() == null) {
shadow.setName(new PolyStringType(ShadowUtil.determineShadowName(shadow.asPrismObject())));
}
if (shadow.getResourceRef() == null || shadow.getResourceRef().getOid() == null) {
if (resource != null) {
shadow.getResourceRef().setOid(shadow.getResource().getOid());
}
}
if (shadow.getResourceRef() != null && resource != null) {
shadow.setResource(null);
}
shadow.setAttemptNumber(getAttemptNumber(shadow));
shadow.setFailedOperationType(FailedOperationTypeType.ADD);
ConstraintsChecker.onShadowAddOperation(shadow);
// Unlike addObject calls during normal provisioning, here we preserve all activation information, including e.g. administrativeStatus.
// It is needed for shadow creation during error recovery.
String oid = cacheRepositoryService.addObject(shadow.asPrismObject(), null, operationResult);
shadow.setOid(oid);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Stored new shadow for unfinished operation:\n{}", shadow.asPrismObject().debugDump(1));
}
// if it is seccond time ,just increade the attempt number
} else {
if (FailedOperationTypeType.ADD == shadow.getFailedOperationType()) {
Collection<? extends ItemDelta> attemptdelta = createAttemptModification(shadow, null);
ConstraintsChecker.onShadowModifyOperation(attemptdelta);
cacheRepositoryService.modifyObject(ShadowType.class, shadow.getOid(), attemptdelta, operationResult);
}
}
// error
for (OperationResult subRes : parentResult.getSubresults()) {
subRes.muteError();
}
operationResult.computeStatus();
parentResult.recordHandledError("Could not create object=" + shadow.getName().getOrig() + " on the resource, because " + ObjectTypeUtil.toShortString(resource) + // there will be something like ": Add object failed" appended, so the final dot was a bit ugly here
" is unreachable at the moment. Shadow is stored in the repository and the resource object will be created when the resource goes online");
// task = taskManager.createTaskInstance();
delta = ObjectDelta.createAddDelta(shadow.asPrismObject());
operationDescription = createOperationDescription(shadow, ex, resource, delta, task, operationResult);
changeNotificationDispatcher.notifyInProgress(operationDescription, task, parentResult);
return shadow;
case MODIFY:
if (shadow.getFailedOperationType() == null || shadow.getFailedOperationType() == FailedOperationTypeType.MODIFY) {
shadow.setFailedOperationType(FailedOperationTypeType.MODIFY);
Collection<ItemDelta> modifications = createShadowModification(shadow);
ConstraintsChecker.onShadowModifyOperation(modifications);
getCacheRepositoryService().modifyObject(ShadowType.class, shadow.getOid(), modifications, operationResult);
delta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, shadow.asPrismObject().getCompileTimeClass(), prismContext);
// operationResult.recordSuccess();
// return shadow;
} else {
if (FailedOperationTypeType.ADD == shadow.getFailedOperationType()) {
if (shadow.getObjectChange() != null && shadow.getOid() != null) {
Collection<? extends ItemDelta> deltas = DeltaConvertor.toModifications(shadow.getObjectChange().getItemDelta(), shadow.asPrismObject().getDefinition());
ConstraintsChecker.onShadowModifyOperation(deltas);
cacheRepositoryService.modifyObject(ShadowType.class, shadow.getOid(), deltas, operationResult);
delta = ObjectDelta.createModifyDelta(shadow.getOid(), deltas, shadow.asPrismObject().getCompileTimeClass(), prismContext);
// return shadow;
// operationResult.recordSuccess();
}
}
}
for (OperationResult subRes : parentResult.getSubresults()) {
subRes.muteError();
}
operationResult.computeStatus();
parentResult.recordHandledError("Could not apply modifications to " + ObjectTypeUtil.toShortString(shadow) + " on the " + ObjectTypeUtil.toShortString(shadow.getResource()) + ", because resource is unreachable. Modifications will be applied when the resource goes online");
// task = taskManager.createTaskInstance();
//
operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, operationResult);
changeNotificationDispatcher.notifyInProgress(operationDescription, task, parentResult);
return shadow;
case DELETE:
shadow.setFailedOperationType(FailedOperationTypeType.DELETE);
Collection<ItemDelta> modifications = createShadowModification(shadow);
ConstraintsChecker.onShadowModifyOperation(modifications);
getCacheRepositoryService().modifyObject(ShadowType.class, shadow.getOid(), modifications, operationResult);
for (OperationResult subRes : parentResult.getSubresults()) {
subRes.muteError();
}
parentResult.recordHandledError("Could not delete " + ObjectTypeUtil.getShortTypeName(shadow) + " from the resource " + ObjectTypeUtil.toShortString(shadow.getResource()) + ", because resource is unreachable. Resource object will be delete when the resource goes online");
// operationResult.recordSuccess();
operationResult.computeStatus();
// task = taskManager.createTaskInstance();
// task.setChannel(QNameUtil.qNameToUri(SchemaConstants.CHANGE_CHANNEL_DISCOVERY));
delta = ObjectDelta.createDeleteDelta(shadow.asPrismObject().getCompileTimeClass(), shadow.getOid(), prismContext);
operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, operationResult);
changeNotificationDispatcher.notifyInProgress(operationDescription, task, parentResult);
return shadow;
case GET:
// result..
for (OperationResult subRes : parentResult.getSubresults()) {
subRes.muteError();
}
operationResult.recordPartialError("Could not get " + ObjectTypeUtil.toShortString(shadow) + " from the resource " + ObjectTypeUtil.toShortString(shadow.getResource()) + ", because resource is unreachable. Returning shadow from the repository");
shadow.setFetchResult(operationResult.createOperationResultType());
// operationResult.computeStatus();
return shadow;
default:
throw new CommunicationException(ex);
}
}
Aggregations