use of com.evolveum.midpoint.util.exception.CommunicationException in project midpoint by Evolveum.
the class ProvisioningServiceImpl method addObject.
@Override
public <T extends ObjectType> String addObject(PrismObject<T> object, OperationProvisioningScriptsType scripts, ProvisioningOperationOptions options, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, SchemaException, CommunicationException, ObjectNotFoundException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
Validate.notNull(object, "Object to add must not be null.");
Validate.notNull(parentResult, "Operation result must not be null.");
if (InternalsConfig.encryptionChecks) {
CryptoUtil.checkEncrypted(object);
}
OperationResult result = parentResult.createSubresult(ProvisioningService.class.getName() + ".addObject");
result.addParam("object", object);
result.addParam("scripts", scripts);
result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
String oid = null;
if (object.canRepresent(ShadowType.class)) {
try {
// calling shadow cache to add object
oid = getShadowCache(Mode.STANDARD).addShadow((PrismObject<ShadowType>) object, scripts, null, options, task, result);
LOGGER.trace("**PROVISIONING: Added shadow object {}", oid);
result.computeStatus();
} catch (GenericFrameworkException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't add object " + object + ". Reason: " + ex.getMessage(), ex);
throw new CommunicationException(ex.getMessage(), ex);
} catch (SchemaException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't add object. Schema violation: " + ex.getMessage(), ex);
throw new SchemaException("Couldn't add object. Schema violation: " + ex.getMessage(), ex);
} catch (ObjectAlreadyExistsException ex) {
result.computeStatus();
if (!result.isSuccess() && !result.isHandledError()) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't add object. Object already exist: " + ex.getMessage(), ex);
} else {
result.recordSuccess();
}
result.cleanupResult(ex);
throw new ObjectAlreadyExistsException("Couldn't add object. Object already exists: " + ex.getMessage(), ex);
} catch (ConfigurationException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't add object. Configuration error: " + ex.getMessage(), ex);
throw ex;
} catch (SecurityViolationException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't add object. Security violation: " + ex.getMessage(), ex);
throw ex;
} catch (ExpressionEvaluationException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't add object. Expression error: " + ex.getMessage(), ex);
throw ex;
} catch (RuntimeException | Error ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't add object. Runtime error: " + ex.getMessage(), ex);
throw ex;
}
} else {
RepoAddOptions addOptions = null;
if (ProvisioningOperationOptions.isOverwrite(options)) {
addOptions = RepoAddOptions.createOverwrite();
}
oid = cacheRepositoryService.addObject(object, addOptions, result);
result.computeStatus();
}
result.cleanupResult();
return oid;
}
use of com.evolveum.midpoint.util.exception.CommunicationException 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.util.exception.CommunicationException 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.util.exception.CommunicationException in project midpoint by Evolveum.
the class ConnectorManager method createConfiguredConnectorInstance.
private ConnectorInstance createConfiguredConnectorInstance(ConnectorSpec connectorSpec, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException {
ConnectorType connectorType = getConnectorTypeReadOnly(connectorSpec, result);
ConnectorFactory connectorFactory = determineConnectorFactory(connectorType);
ConnectorInstance connector = null;
try {
connector = connectorFactory.createConnectorInstance(connectorType, ResourceTypeUtil.getResourceNamespace(connectorSpec.getResource()), connectorSpec.toString());
} catch (ObjectNotFoundException e) {
result.recordFatalError(e.getMessage(), e);
throw new ObjectNotFoundException(e.getMessage(), e);
}
PrismContainerValue<ConnectorConfigurationType> connectorConfigurationVal = connectorSpec.getConnectorConfiguration().getValue();
if (connectorConfigurationVal == null) {
SchemaException e = new SchemaException("No connector configuration in " + connectorSpec);
result.recordFatalError(e);
throw e;
}
try {
connector.configure(connectorConfigurationVal, result);
ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(connectorSpec.getResource(), prismContext);
Collection<Object> capabilities = ResourceTypeUtil.getNativeCapabilitiesCollection(connectorSpec.getResource().asObjectable());
connector.initialize(resourceSchema, capabilities, ResourceTypeUtil.isCaseIgnoreAttributeNames(connectorSpec.getResource().asObjectable()), result);
InternalMonitor.recordConnectorInstanceInitialization();
} catch (GenericFrameworkException e) {
// Not expected. Transform to system exception
result.recordFatalError("Generic provisioning framework error", e);
throw new SystemException("Generic provisioning framework error: " + e.getMessage(), e);
} catch (CommunicationException e) {
result.recordFatalError(e);
throw e;
} catch (ConfigurationException e) {
result.recordFatalError(e);
throw e;
}
// This log message should be INFO level. It happens only occasionally.
// If it happens often, it may be an
// indication of a problem. Therefore it is good for admin to see it.
LOGGER.info("Created new connector instance for {}: {} v{}", connectorSpec, connectorType.getConnectorType(), connectorType.getConnectorVersion());
return connector;
}
use of com.evolveum.midpoint.util.exception.CommunicationException 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