use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class AbstractLdapHierarchyTest method reconcileAllOrgs.
protected void reconcileAllOrgs() throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
final Task task = createTask("reconcileAllOrgs");
OperationResult result = task.getResult();
ResultHandler<OrgType> handler = new ResultHandler<OrgType>() {
@Override
public boolean handle(PrismObject<OrgType> object, OperationResult parentResult) {
try {
display("reconciling " + object);
reconcileOrg(object.getOid(), task, parentResult);
} catch (SchemaException | PolicyViolationException | ExpressionEvaluationException | ObjectNotFoundException | ObjectAlreadyExistsException | CommunicationException | ConfigurationException | SecurityViolationException e) {
throw new SystemException(e.getMessage(), e);
}
return true;
}
};
display("Reconciling all orgs");
modelService.searchObjectsIterative(OrgType.class, null, handler, null, task, result);
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ObjectNotFoundHandler 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, ExpressionEvaluationException {
if (!doDiscovery) {
parentResult.recordFatalError(ex);
if (ex instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException) ex;
} else {
throw new ObjectNotFoundException(ex.getMessage(), ex);
}
}
OperationResult result = parentResult.createSubresult("com.evolveum.midpoint.provisioning.consistency.impl.ObjectNotFoundHandler.handleError." + op.name());
result.addParam("shadow", shadow);
result.addParam("currentOperation", op);
if (ex.getMessage() != null) {
result.addParam("exception", ex.getMessage());
}
LOGGER.trace("Start compensating object not found situation while execution operation: {}", op.name(), ex);
// Task task = taskManager.createTaskInstance();
ObjectDelta delta = null;
switch(op) {
case DELETE:
LOGGER.debug("DISCOVERY: cannot find object {}. The operation in progress is DELETE, therefore just deleting the shadow", shadow);
LOGGER.trace("Deleting shadow from the repository.");
for (OperationResult subResult : parentResult.getSubresults()) {
subResult.muteError();
}
try {
cacheRepositoryService.deleteObject(ShadowType.class, shadow.getOid(), result);
} catch (ObjectNotFoundException e) {
LOGGER.debug("Cannot delete {} in consistency compensation (discovery): {} - this is probably harmless", shadow, e.getMessage());
}
String message = "Object was not found on the " + ObjectTypeUtil.toShortString(shadow.getResource()) + ". Shadow deleted from the repository to equalize the state on the resource and in the repository.";
parentResult.recordHandledError(message);
LOGGER.trace("Shadow deleted from the repository. Inconsistencies are now removed.");
result.computeStatus();
// parentResult status can be recomputed by the caller method
result.setStatus(OperationResultStatus.HANDLED_ERROR);
delta = ObjectDelta.createDeleteDelta(shadow.getClass(), shadow.getOid(), prismContext);
ResourceOperationDescription operationDescritpion = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, result);
changeNotificationDispatcher.notifySuccess(operationDescritpion, task, result);
LOGGER.debug("DISCOVERY: cannot find object {}: DELETE operation handler done", shadow);
return shadow;
case MODIFY:
LOGGER.debug("DISCOVERY: cannot find object {}. The operation in progress is MODIFY, therefore initiating synchronization", shadow);
LOGGER.trace("Starting discovery to find out if the object should exist or not.");
OperationResult handleErrorResult = result.createSubresult("com.evolveum.midpoint.provisioning.consistency.impl.ObjectNotFoundHandler.handleError.discovery");
handleErrorResult.addContext(OperationResult.CONTEXT_RESOURCE, shadow.getResource());
ObjectDeltaType shadowModifications = shadow.getObjectChange();
Collection<? extends ItemDelta> modifications = DeltaConvertor.toModifications(shadowModifications.getItemDelta(), shadow.asPrismObject().getDefinition());
shadow.setDead(true);
Collection<? extends ItemDelta> deadDeltas = PropertyDelta.createModificationReplacePropertyCollection(ShadowType.F_DEAD, shadow.asPrismObject().getDefinition(), true);
ConstraintsChecker.onShadowModifyOperation(deadDeltas);
cacheRepositoryService.modifyObject(ShadowType.class, shadow.getOid(), deadDeltas, result);
ResourceObjectShadowChangeDescription change = createResourceObjectShadowChangeDescription(shadow, result);
try {
changeNotificationDispatcher.notifyChange(change, task, handleErrorResult);
} catch (RuntimeException e) {
handleErrorResult.recordFatalError(e);
result.computeStatus();
throw e;
}
handleErrorResult.computeStatus();
String oidVal = null;
String oid = findCreatedAccountOid(handleErrorResult, oidVal);
if (oid != null) {
LOGGER.trace("Found new oid {} as a return param from model. Probably the new shadow was created.", oid);
LOGGER.debug("DISCOVERY: object {} re-created, applying pending changes", shadow);
LOGGER.trace("Modifying re-created object by applying pending changes:\n{}", DebugUtil.debugDump(modifications));
try {
ProvisioningOperationOptions options = new ProvisioningOperationOptions();
options.setCompletePostponed(false);
options.setDoNotDiscovery(true);
provisioningService.modifyObject(ShadowType.class, oid, modifications, null, options, task, result);
parentResult.recordHandledError("Object was recreated and modifications were applied to newly created object.");
} catch (ObjectNotFoundException e) {
parentResult.recordHandledError("Modifications were not applied, because shadow was deleted by discovery. Repository state were refreshed and unused shadow was deleted.");
}
} else {
LOGGER.debug("DISCOVERY: object {} deleted, application of pending changes skipped", shadow);
parentResult.recordHandledError("Object was deleted by discovery. Modification were not applied.");
}
// We do not need the old shadow any more. Even if the object was re-created it has a new shadow now.
try {
cacheRepositoryService.deleteObject(ShadowType.class, shadow.getOid(), parentResult);
} catch (ObjectNotFoundException e) {
// delete the old shadow that was probably deleted from the
// user, or the new one was assigned
LOGGER.debug("Cannot delete {} in consistency compensation (discovery): {} - this is probably harmless", shadow, e.getMessage());
}
result.computeStatus();
if (parentResult.isHandledError()) {
// Ugly hack. We shouldn't set parentResult status in the first place, as it can be overriden by computeStatus/recomputeStatus called in the parent.
result.setStatus(OperationResultStatus.HANDLED_ERROR);
}
if (oid != null) {
shadowModifications.setOid(oid);
shadow.setOid(oid);
}
LOGGER.debug("DISCOVERY: cannot find object {}: MODIFY operation handler done", shadow);
return shadow;
case GET:
if (!compensate) {
LOGGER.trace("DISCOVERY: cannot find object {}, GET operation: handling skipped because discovery is disabled", shadow);
result.recordFatalError(ex.getMessage(), ex);
throw new ObjectNotFoundException(ex.getMessage(), ex);
}
LOGGER.debug("DISCOVERY: cannot find object {}. The operation in progress is GET, therefore initiating synchronization", shadow);
OperationResult handleGetErrorResult = result.createSubresult("com.evolveum.midpoint.provisioning.consistency.impl.ObjectNotFoundHandler.handleError.discovery");
handleGetErrorResult.addContext(OperationResult.CONTEXT_RESOURCE, shadow.getResource());
Collection<? extends ItemDelta> deadModification = PropertyDelta.createModificationReplacePropertyCollection(ShadowType.F_DEAD, shadow.asPrismObject().getDefinition(), true);
ConstraintsChecker.onShadowModifyOperation(deadModification);
try {
cacheRepositoryService.modifyObject(ShadowType.class, shadow.getOid(), deadModification, result);
} catch (ObjectNotFoundException e) {
// The shadow is not there. So we cannot mark it as dead.
LOGGER.debug("Cannot modify shadow {} in consistency compensation (discovery): {} - this is probably harmless", shadow, e.getMessage());
}
shadow.setDead(true);
ResourceObjectShadowChangeDescription getChange = createResourceObjectShadowChangeDescription(shadow, result);
if (task == null) {
task = taskManager.createTaskInstance();
}
try {
changeNotificationDispatcher.notifyChange(getChange, task, handleGetErrorResult);
} catch (RuntimeException e) {
LOGGER.trace("DISCOVERY: synchronization invoked for {} ended with an error {}", shadow, e);
handleGetErrorResult.recordFatalError(e);
result.computeStatus();
throw e;
}
// String oidVal = null;
handleGetErrorResult.computeStatus();
LOGGER.trace("DISCOVERY: synchronization invoked for {} finished with status {}", shadow, handleGetErrorResult.getStatus());
oid = findCreatedAccountOid(handleGetErrorResult, null);
try {
LOGGER.trace("DISCOVERY: deleting {}", shadow);
cacheRepositoryService.deleteObject(ShadowType.class, shadow.getOid(), result);
} catch (ObjectNotFoundException e) {
// delete the old shadow that was probably deleted from the
// user, or the new one was assigned
LOGGER.debug("Cannot delete {} in consistency compensation (discovery): {} - this is probably harmless", shadow, e.getMessage());
}
for (OperationResult subResult : parentResult.getSubresults()) {
subResult.muteError();
}
if (oid != null) {
PrismObject newShadow;
try {
LOGGER.trace("DISCOVERY: retrieving shadow {}", oid);
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createDoNotDiscovery());
newShadow = provisioningService.getObject(shadow.getClass(), oid, options, task, result);
LOGGER.trace("DISCOVERY: retrieved {}", newShadow);
} catch (ObjectNotFoundException e) {
String msg = "Strange thing did happen: new shadow (" + oid + ") was supposedly created for old shadow " + shadow + ", however the new shadow was not found: " + e.getMessage();
LOGGER.error(msg);
result.recordFatalError(msg, e);
parentResult.recordFatalError(msg);
throw new ObjectNotFoundException(msg, ex);
} finally {
result.computeStatus();
}
LOGGER.debug("DISCOVERY: object {} re-created as {}. GET operation handler done: returning new shadow", shadow, newShadow);
shadow = (T) newShadow.asObjectable();
parentResult.recordHandledError("Object was re-created by the discovery.");
// parentResult status can be recomputed by the caller method
result.setStatus(OperationResultStatus.HANDLED_ERROR);
return shadow;
} else {
parentResult.recordHandledError("Object was deleted by the discovery and the invalid link was removed from the user.");
result.computeStatus();
// parentResult status can be recomputed by the caller method
result.setStatus(OperationResultStatus.HANDLED_ERROR);
LOGGER.debug("DISCOVERY: object {} was deleted. GET operation handler done: throwing ObjectNotFoundException", shadow);
throw new ObjectNotFoundException(ex.getMessage(), ex);
}
default:
throw new ObjectNotFoundException(ex.getMessage(), ex);
}
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ProvisioningServiceImpl method getConnectorOperationalStatus.
@Override
public List<ConnectorOperationalStatus> getConnectorOperationalStatus(String resourceOid, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
OperationResult result = parentResult.createMinorSubresult(ProvisioningService.class.getName() + ".getConnectorOperationalStatus");
result.addParam("resourceOid", resourceOid);
result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
PrismObject<ResourceType> resource;
try {
resource = resourceManager.getResource(resourceOid, null, task, result);
} catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, ex.getMessage(), ex);
throw ex;
}
List<ConnectorOperationalStatus> stats;
try {
stats = resourceManager.getConnectorOperationalStatus(resource, result);
} catch (ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Getting operations status from connector for resource " + resourceOid + " failed: " + ex.getMessage(), ex);
throw ex;
}
result.computeStatus();
result.cleanupResult();
return stats;
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ResourceManager method testConnectionConnector.
public void testConnectionConnector(ConnectorSpec connectorSpec, Map<String, Collection<Object>> capabilityMap, Task task, OperationResult parentResult) {
// === test INITIALIZATION ===
OperationResult initResult = parentResult.createSubresult(ConnectorTestOperation.CONNECTOR_INITIALIZATION.getOperation());
ConnectorInstance connector;
try {
// TODO: this returns configured instance. Then there is another configuration down below.
// this means double configuration of the connector. TODO: clean this up
connector = connectorManager.getConfiguredConnectorInstance(connectorSpec, true, initResult);
initResult.recordSuccess();
} catch (ObjectNotFoundException e) {
// The connector was not found. The resource definition is either
// wrong or the connector is not
// installed.
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
initResult.recordFatalError("The connector was not found: " + e.getMessage(), e);
return;
} catch (SchemaException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
initResult.recordFatalError("Schema error while dealing with the connector definition: " + e.getMessage(), e);
return;
} catch (RuntimeException | Error e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
initResult.recordFatalError("Unexpected runtime error: " + e.getMessage(), e);
return;
} catch (CommunicationException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
initResult.recordFatalError("Communication error: " + e.getMessage(), e);
return;
} catch (ConfigurationException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
initResult.recordFatalError("Configuration error: " + e.getMessage(), e);
return;
}
LOGGER.debug("Testing connection using {}", connectorSpec);
// === test CONFIGURATION ===
OperationResult configResult = parentResult.createSubresult(ConnectorTestOperation.CONNECTOR_CONFIGURATION.getOperation());
try {
PrismObject<ResourceType> resource = connectorSpec.getResource();
PrismObjectDefinition<ResourceType> newResourceDefinition = resource.getDefinition().clone();
applyConnectorSchemaToResource(connectorSpec, newResourceDefinition, resource, task, configResult);
PrismContainerValue<ConnectorConfigurationType> connectorConfiguration = connectorSpec.getConnectorConfiguration().getValue();
connector.configure(connectorConfiguration, configResult);
configResult.recordSuccess();
} catch (CommunicationException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
configResult.recordFatalError("Communication error", e);
return;
} catch (GenericFrameworkException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
configResult.recordFatalError("Generic error", e);
return;
} catch (SchemaException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
configResult.recordFatalError("Schema error", e);
return;
} catch (ConfigurationException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
configResult.recordFatalError("Configuration error", e);
return;
} catch (ObjectNotFoundException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
configResult.recordFatalError("Object not found", e);
return;
} catch (ExpressionEvaluationException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
configResult.recordFatalError("Expression error", e);
return;
} catch (RuntimeException | Error e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
configResult.recordFatalError("Unexpected runtime error", e);
return;
}
// === test CONNECTION ===
// delegate the main part of the test to the connector
connector.test(parentResult);
parentResult.computeStatus();
if (!parentResult.isAcceptable()) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.DOWN, parentResult);
// messages.
return;
} else {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.UP, parentResult);
}
OperationResult capabilitiesResult = parentResult.createSubresult(ConnectorTestOperation.CONNECTOR_CAPABILITIES.getOperation());
try {
InternalMonitor.recordConnectorCapabilitiesFetchCount();
Collection<Object> capabilities = connector.fetchCapabilities(capabilitiesResult);
capabilityMap.put(connectorSpec.getConnectorName(), capabilities);
capabilitiesResult.recordSuccess();
} catch (CommunicationException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
capabilitiesResult.recordFatalError("Communication error", e);
return;
} catch (GenericFrameworkException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
capabilitiesResult.recordFatalError("Generic error", e);
return;
} catch (ConfigurationException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
capabilitiesResult.recordFatalError("Configuration error", e);
return;
} catch (RuntimeException | Error e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
capabilitiesResult.recordFatalError("Unexpected runtime error", e);
return;
}
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ResourceManager method applyConnectorSchemaToResource.
/**
* Apply proper definition (connector schema) to the resource.
*/
private void applyConnectorSchemaToResource(ConnectorSpec connectorSpec, PrismObjectDefinition<ResourceType> resourceDefinition, PrismObject<ResourceType> resource, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
ConnectorType connectorType = connectorManager.getConnectorTypeReadOnly(connectorSpec, result);
PrismSchema connectorSchema = connectorManager.getConnectorSchema(connectorType);
if (connectorSchema == null) {
throw new SchemaException("No connector schema in " + connectorType);
}
PrismContainerDefinition<ConnectorConfigurationType> configurationContainerDefinition = ConnectorTypeUtil.findConfigurationContainerDefinition(connectorType, connectorSchema);
if (configurationContainerDefinition == null) {
throw new SchemaException("No configuration container definition in schema of " + connectorType);
}
configurationContainerDefinition = configurationContainerDefinition.clone();
PrismContainer<ConnectorConfigurationType> configurationContainer = connectorSpec.getConnectorConfiguration();
// the element is global in the connector schema. therefore it does not have correct maxOccurs
if (configurationContainer != null) {
configurationContainerDefinition.adoptElementDefinitionFrom(configurationContainer.getDefinition());
configurationContainer.applyDefinition(configurationContainerDefinition, true);
try {
configurationContainer.accept(visitable -> {
if ((visitable instanceof PrismProperty<?>)) {
try {
evaluateExpression((PrismProperty<?>) visitable, resource, task, result);
} catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException e) {
throw new TunnelException(e);
}
}
});
} catch (TunnelException te) {
Throwable e = te.getCause();
if (e instanceof SchemaException) {
throw (SchemaException) e;
} else if (e instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException) e;
} else if (e instanceof ExpressionEvaluationException) {
throw (ExpressionEvaluationException) e;
} else if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else if (e instanceof Error) {
throw (Error) e;
} else {
throw new SystemException(e);
}
}
} else {
configurationContainerDefinition.adoptElementDefinitionFrom(resourceDefinition.findContainerDefinition(ResourceType.F_CONNECTOR_CONFIGURATION));
}
if (connectorSpec.getConnectorName() == null) {
// Default connector, for compatibility
// It does not make sense to update this for any other connectors.
// We cannot have one definition for addiitionalConnector[1]/connectorConfiguraiton and
// different definition for addiitionalConnector[2]/connectorConfiguraiton in the object definition.
// The way to go is to set up definitions on the container level.
resourceDefinition.replaceDefinition(ResourceType.F_CONNECTOR_CONFIGURATION, configurationContainerDefinition);
}
}
Aggregations