use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ResourceManager method testConnection.
public void testConnection(PrismObject<ResourceType> resource, Task task, OperationResult parentResult) {
List<ConnectorSpec> allConnectorSpecs;
try {
allConnectorSpecs = getAllConnectorSpecs(resource);
} catch (SchemaException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
parentResult.recordFatalError("Configuration error: " + e.getMessage(), e);
return;
}
Map<String, Collection<Object>> capabilityMap = new HashMap<>();
for (ConnectorSpec connectorSpec : allConnectorSpecs) {
OperationResult connectorTestResult = parentResult.createSubresult(ConnectorTestOperation.CONNECTOR_TEST.getOperation());
connectorTestResult.addParam(OperationResult.PARAM_NAME, connectorSpec.getConnectorName());
connectorTestResult.addParam(OperationResult.PARAM_OID, connectorSpec.getConnectorOid());
testConnectionConnector(connectorSpec, capabilityMap, task, connectorTestResult);
connectorTestResult.computeStatus();
}
// === test SCHEMA ===
OperationResult schemaResult = parentResult.createSubresult(ConnectorTestOperation.RESOURCE_SCHEMA.getOperation());
ResourceSchema schema = null;
try {
schema = fetchResourceSchema(resource, capabilityMap, task, schemaResult);
} catch (CommunicationException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Communication error: " + e.getMessage(), e);
return;
} catch (GenericFrameworkException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Generic error: " + e.getMessage(), e);
return;
} catch (ConfigurationException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Configuration error: " + e.getMessage(), e);
return;
} catch (ObjectNotFoundException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Configuration error: " + e.getMessage(), e);
return;
} catch (SchemaException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Configuration error: " + e.getMessage(), e);
return;
}
if (schema == null || schema.isEmpty()) {
// If there is a static schema in resource definition this may still be OK
try {
schema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
} catch (SchemaException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError(e);
return;
}
if (schema == null || schema.isEmpty()) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Connector does not support schema and no static schema available");
return;
}
}
// capability.
try {
resource = completeResource(resource, schema, true, capabilityMap, null, task, schemaResult);
} catch (ObjectNotFoundException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Object not found (unexpected error, probably a bug): " + e.getMessage(), e);
return;
} catch (SchemaException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Schema processing error (probably connector bug): " + e.getMessage(), e);
return;
} catch (CommunicationException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Communication error: " + e.getMessage(), e);
return;
} catch (ConfigurationException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Configuration error: " + e.getMessage(), e);
return;
} catch (ExpressionEvaluationException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Expression error: " + e.getMessage(), e);
return;
}
schemaResult.recordSuccess();
// TODO: connector sanity (e.g. refined schema, at least one account type, identifiers
// in schema, etc.)
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ProvisioningServiceImpl method synchronize.
@SuppressWarnings("rawtypes")
@Override
public int synchronize(ResourceShadowDiscriminator shadowCoordinates, Task task, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
Validate.notNull(shadowCoordinates, "Coordinates oid must not be null.");
String resourceOid = shadowCoordinates.getResourceOid();
Validate.notNull(resourceOid, "Resource oid must not be null.");
Validate.notNull(task, "Task must not be null.");
Validate.notNull(parentResult, "Operation result must not be null.");
OperationResult result = parentResult.createSubresult(ProvisioningService.class.getName() + ".synchronize");
result.addParam(OperationResult.PARAM_OID, resourceOid);
result.addParam(OperationResult.PARAM_TASK, task.toString());
int processedChanges = 0;
try {
// Resolve resource
PrismObject<ResourceType> resource = getObject(ResourceType.class, resourceOid, null, task, result);
ResourceType resourceType = resource.asObjectable();
LOGGER.trace("**PROVISIONING: Start synchronization of resource {} ", resourceType);
// getting token form task
PrismProperty tokenProperty = getTokenProperty(shadowCoordinates, task, result);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("**PROVISIONING: Got token property: {} from the task extension.", SchemaDebugUtil.prettyPrint(tokenProperty));
}
processedChanges = getShadowCache(Mode.STANDARD).synchronize(shadowCoordinates, tokenProperty, task, result);
LOGGER.debug("Synchronization of {} done, token {}, {} changes", resource, tokenProperty, processedChanges);
} catch (ObjectNotFoundException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Synchronization error: object not found: " + e.getMessage(), e);
throw e;
} catch (CommunicationException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Synchronization error: communication problem: " + e.getMessage(), e);
throw e;
} catch (ObjectAlreadyExistsException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Synchronization error: object already exists problem: " + e.getMessage(), e);
throw new SystemException(e);
} catch (GenericFrameworkException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Synchronization error: generic connector framework error: " + e.getMessage(), e);
throw new GenericConnectorException(e.getMessage(), e);
} catch (SchemaException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Synchronization error: schema problem: " + e.getMessage(), e);
throw e;
} catch (SecurityViolationException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Synchronization error: security violation: " + e.getMessage(), e);
throw e;
} catch (ConfigurationException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Synchronization error: configuration problem: " + e.getMessage(), e);
throw e;
} catch (RuntimeException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Synchronization error: unexpected problem: " + e.getMessage(), e);
throw e;
} catch (ExpressionEvaluationException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Synchronization error: expression error: " + e.getMessage(), e);
throw e;
}
result.recordSuccess();
result.cleanupResult();
return processedChanges;
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ProvisioningServiceImpl method countObjects.
public <T extends ObjectType> Integer countObjects(Class<T> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
OperationResult result = parentResult.createMinorSubresult(ProvisioningService.class.getName() + ".countObjects");
result.addParam("objectType", type);
result.addParam("query", query);
result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
ObjectFilter filter = null;
if (query != null) {
filter = ObjectQueryUtil.simplify(query.getFilter());
query = query.cloneEmpty();
query.setFilter(filter);
}
if (filter != null && filter instanceof NoneFilter) {
result.recordSuccessIfUnknown();
result.cleanupResult();
LOGGER.trace("Finished counting. Nothing to do. Filter is NONE");
return 0;
}
GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
if (!ShadowType.class.isAssignableFrom(type) || GetOperationOptions.isNoFetch(rootOptions) || GetOperationOptions.isRaw(rootOptions)) {
int count = getCacheRepositoryService().countObjects(type, query, parentResult);
result.computeStatus();
result.recordSuccessIfUnknown();
result.cleanupResult();
return count;
}
Integer count;
try {
count = getShadowCache(Mode.STANDARD).countObjects(query, task, result);
result.computeStatus();
} catch (ConfigurationException | CommunicationException | ObjectNotFoundException | SchemaException | ExpressionEvaluationException | RuntimeException | Error e) {
ProvisioningUtil.recordFatalError(LOGGER, result, null, e);
throw e;
} finally {
result.cleanupResult();
}
return count;
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ProvisioningServiceImpl method deleteObject.
@Override
public <T extends ObjectType> void deleteObject(Class<T> type, String oid, ProvisioningOperationOptions options, OperationProvisioningScriptsType scripts, Task task, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
Validate.notNull(oid, "Oid of object to delete must not be null.");
Validate.notNull(parentResult, "Operation result must not be null.");
LOGGER.trace("**PROVISIONING: Start to delete object with oid {}", oid);
OperationResult result = parentResult.createSubresult(ProvisioningService.class.getName() + ".deleteObject");
result.addParam("oid", oid);
result.addParam("scripts", scripts);
result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
//TODO: is critical when shadow does not exits anymore?? do we need to log it?? if not, change null to allowNotFound options
PrismObject<T> object = getRepoObject(type, oid, null, result);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("**PROVISIONING: Object from repository to delete:\n{}", object.debugDump());
}
if (object.canRepresent(ShadowType.class) && !ProvisioningOperationOptions.isRaw(options)) {
try {
getShadowCache(Mode.STANDARD).deleteShadow((PrismObject<ShadowType>) object, options, scripts, task, result);
} catch (CommunicationException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: communication problem: " + e.getMessage(), e);
throw new CommunicationException(e.getMessage(), e);
} catch (GenericFrameworkException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: generic error in the connector: " + e.getMessage(), e);
throw new CommunicationException(e.getMessage(), e);
} catch (SchemaException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: schema problem: " + e.getMessage(), e);
throw new SchemaException(e.getMessage(), e);
} catch (ConfigurationException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: configuration problem: " + e.getMessage(), e);
throw e;
} catch (SecurityViolationException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: security violation: " + e.getMessage(), e);
throw e;
} catch (ExpressionEvaluationException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: expression errror: " + e.getMessage(), e);
throw e;
} catch (RuntimeException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: " + e.getMessage(), e);
throw new SystemException(e);
}
} else if (object.canRepresent(ResourceType.class)) {
resourceManager.deleteResource(oid, options, task, result);
} else {
try {
getCacheRepositoryService().deleteObject(type, oid, result);
} catch (ObjectNotFoundException ex) {
result.recordFatalError(ex);
result.cleanupResult(ex);
throw ex;
}
}
LOGGER.trace("**PROVISIONING: Finished deleting object.");
result.computeStatus();
result.cleanupResult();
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ProvisioningServiceImpl method getObject.
@SuppressWarnings("unchecked")
@Override
public <T extends ObjectType> PrismObject<T> getObject(Class<T> type, String oid, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
Validate.notNull(oid, "Oid of object to get must not be null.");
Validate.notNull(parentResult, "Operation result must not be null.");
// Result type for this operation
OperationResult result = parentResult.createMinorSubresult(ProvisioningService.class.getName() + ".getObject");
result.addParam(OperationResult.PARAM_OID, oid);
result.addParam(OperationResult.PARAM_TYPE, type);
result.addCollectionOfSerializablesAsParam("options", options);
result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
PrismObject<T> resultingObject = null;
if (ResourceType.class.isAssignableFrom(type)) {
if (GetOperationOptions.isRaw(rootOptions)) {
try {
resultingObject = (PrismObject<T>) cacheRepositoryService.getObject(ResourceType.class, oid, null, result);
} catch (ObjectNotFoundException | SchemaException ex) {
// catching an exception is important because otherwise the result is UNKNOWN
result.recordFatalError(ex);
throw ex;
}
try {
applyDefinition(resultingObject, task, result);
} catch (ObjectNotFoundException ex) {
// this is almost OK, we use raw for debug pages, so we want
// to return resource and it can be fixed
result.muteLastSubresultError();
ProvisioningUtil.logWarning(LOGGER, result, "Bad connector reference defined for resource: " + ex.getMessage(), ex);
} catch (SchemaException ex) {
result.muteLastSubresultError();
ProvisioningUtil.logWarning(LOGGER, result, "Schema violation: " + ex.getMessage(), ex);
} catch (ConfigurationException ex) {
result.muteLastSubresultError();
ProvisioningUtil.logWarning(LOGGER, result, "Configuration problem: " + ex.getMessage(), ex);
}
} else {
// schema
try {
resultingObject = (PrismObject<T>) resourceManager.getResource(oid, SelectorOptions.findRootOptions(options), task, result);
} catch (ObjectNotFoundException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Resource object not found", ex);
throw ex;
} catch (SchemaException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Schema violation", ex);
throw ex;
} catch (CommunicationException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Error communicating with resource", ex);
throw ex;
} catch (ConfigurationException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Bad resource configuration", ex);
throw ex;
} catch (ExpressionEvaluationException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Expression error", ex);
throw ex;
}
}
} else {
// Not resource
PrismObject<T> repositoryObject = getRepoObject(type, oid, rootOptions, result);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Retrieved repository object:\n{}", repositoryObject.debugDump());
}
if (repositoryObject.canRepresent(ShadowType.class)) {
try {
resultingObject = (PrismObject<T>) getShadowCache(Mode.STANDARD).getShadow(oid, (PrismObject<ShadowType>) (repositoryObject), options, task, result);
} catch (ObjectNotFoundException e) {
if (!GetOperationOptions.isAllowNotFound(rootOptions)) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
} else {
result.muteLastSubresultError();
result.computeStatus();
}
throw e;
} catch (CommunicationException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
throw e;
} catch (SchemaException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
throw e;
} catch (ConfigurationException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
throw e;
} catch (SecurityViolationException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
throw e;
} catch (SystemException e) {
// Do NOT wrap this into SystemException again
ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
throw e;
} catch (RuntimeException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
throw new SystemException(e);
}
} else {
resultingObject = repositoryObject;
}
}
result.computeStatus();
if (!GetOperationOptions.isRaw(rootOptions)) {
resultingObject = resultingObject.cloneIfImmutable();
resultingObject.asObjectable().setFetchResult(result.createOperationResultType());
}
result.cleanupResult();
validateObject(resultingObject);
return resultingObject;
}
Aggregations