public static void assertExceptionSanity(ObjectAlreadyExistsException e) { LOGGER.debug("Exception (expected) {}", e, e); System.out.println("Exception (expected)"); System.out.println(ExceptionUtils.getFullStackTrace(e)); assert !e.getMessage().isEmpty() : "Empty exception message"; assert e.getMessage().length() < MAX_EXCEPTION_MESSAGE_LENGTH : "Exception message too long (" +e.getMessage().length()+" characters): "+e.getMessage(); }
public void deleteWorkersAndWorkState(String coordinatorTaskOid, long subtasksWaitTime, OperationResult result) throws SchemaException, ObjectNotFoundException { Task coordinatorTask = taskManager.getTask(coordinatorTaskOid, result); if (coordinatorTask.getKind() != TaskKindType.COORDINATOR) { throw new IllegalArgumentException("Task is not a coordinator task: " + coordinatorTask); } if (coordinatorTask.getExecutionStatus() == TaskExecutionStatus.WAITING) { throw new IllegalStateException("Couldn't delete workers and work state while operation is in progress (coordinator state is WAITING): " + coordinatorTask); } if (coordinatorTask.getExecutionStatus() == TaskExecutionStatus.RUNNABLE && coordinatorTask.getNodeAsObserved() != null) { throw new IllegalStateException("Couldn't delete workers and work state while operation is in progress (coordinator " + "state is RUNNABLE and it is executing on " + coordinatorTask.getNodeAsObserved() + "): " + coordinatorTask); } List<Task> subtasks = coordinatorTask.listSubtasks(true, result); taskManager.suspendAndDeleteTasks(TaskUtil.tasksToOids(subtasks), subtasksWaitTime, true, result); List<ItemDelta<?, ?>> itemDeltas = prismContext.deltaFor(TaskType.class) .item(TaskType.F_WORK_STATE).replace() .asItemDeltas(); try { taskManager.modifyTask(coordinatorTaskOid, itemDeltas, result); } catch (ObjectAlreadyExistsException e) { throw new IllegalStateException("Unexpected exception: " + e.getMessage(), e); } } }
taskManager.addTask((PrismObject<TaskType>) object, result); } catch (ObjectAlreadyExistsException ex) { result.recordFatalError(ex.getMessage(), ex); throw ex; } catch (SchemaException ex) { object.setOid(oid); } catch(ObjectAlreadyExistsException ex){ result.recordFatalError(ex.getMessage()+" while adding "+object+(contextDesc==null?"":" "+contextDesc), ex); throw ex; } catch(SchemaException ex){
protected List<PrismObject> repoAddObjectsFromFile(File file, OperationResult parentResult) throws SchemaException, ObjectAlreadyExistsException, IOException { OperationResult result = parentResult.createSubresult(AbstractIntegrationTest.class.getName() + ".addObjectsFromFile"); result.addParam("file", file.getPath()); LOGGER.trace("addObjectsFromFile: {}", file); List<PrismObject> objects = (List) prismContext.parserFor(file).parseObjects(); for (PrismObject object: objects) { try { repoAddObject(object, result); } catch (ObjectAlreadyExistsException e) { throw new ObjectAlreadyExistsException(e.getMessage()+" while adding "+object+" from file "+file, e); } catch (SchemaException e) { new SchemaException(e.getMessage()+" while adding "+object+" from file "+file, e); } catch (EncryptionException e) { new EncryptionException(e.getMessage()+" while adding "+object+" from file "+file, e); } } result.recordSuccess(); return objects; }
@SuppressWarnings("unchecked") public Collection<ItemDelta> updateShadow(ProvisioningContext ctx, PrismObject<ShadowType> resourceShadow, Collection<? extends ItemDelta> aprioriDeltas, OperationResult result) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException { PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, resourceShadow.getOid(), null, result); Collection<ItemDelta> repoShadowChanges = new ArrayList<>(); computeUpdateShadowAttributeChanges(ctx, repoShadowChanges, resourceShadow, repoShadow); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Updating repo shadow {}:\n{}", resourceShadow.getOid(), DebugUtil.debugDump(repoShadowChanges)); } try { repositoryService.modifyObject(ShadowType.class, resourceShadow.getOid(), repoShadowChanges, result); } catch (ObjectAlreadyExistsException e) { // We are not renaming the object here. This should not happen. throw new SystemException(e.getMessage(), e); } return repoShadowChanges; }
protected <T extends ObjectType> List<PrismObject<T>> repoAddObjectsFromFile(File file, Class<T> type, OperationResult parentResult) throws SchemaException, ObjectAlreadyExistsException, IOException { OperationResult result = parentResult.createSubresult(AbstractIntegrationTest.class.getName() + ".addObjectsFromFile"); result.addParam("file", file.getPath()); LOGGER.trace("addObjectsFromFile: {}", file); List<PrismObject<T>> objects = (List) prismContext.parserFor(file).parseObjects(); for (PrismObject<T> object: objects) { try { repoAddObject(object, result); } catch (ObjectAlreadyExistsException e) { throw new ObjectAlreadyExistsException(e.getMessage()+" while adding "+object+" from file "+file, e); } catch (SchemaException e) { new SchemaException(e.getMessage()+" while adding "+object+" from file "+file, e); } catch (EncryptionException e) { new EncryptionException(e.getMessage()+" while adding "+object+" from file "+file, e); } } result.recordSuccess(); return objects; }
parentResult.recordFatalError("Can't add " + foundShadow + " to the repository. Reason: " + e.getMessage(), e); throw new IllegalStateException(e.getMessage(), e);
@SuppressWarnings("rawtypes") private void saveAccountResult(ResourceObjectShadowChangeDescription shadowChangeDescription, Change change, OperationResult notifyChangeResult, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException { Collection<? extends ItemDelta> shadowModification = createShadowResultModification(change, notifyChangeResult); String oid = getOidFromChange(change); // maybe better error handling is needed try { ConstraintsChecker.onShadowModifyOperation(shadowModification); repositoryService.modifyObject(ShadowType.class, oid, shadowModification, parentResult); } catch (SchemaException ex) { parentResult.recordPartialError("Couldn't modify object: schema violation: " + ex.getMessage(), ex); // throw ex; } catch (ObjectNotFoundException ex) { parentResult.recordWarning("Couldn't modify object: object not found: " + ex.getMessage(), ex); // throw ex; } catch (ObjectAlreadyExistsException ex) { parentResult.recordPartialError( "Couldn't modify object: object already exists: " + ex.getMessage(), ex); // throw ex; } }
public PrismObject<ShadowType> markShadowExists(PrismObject<ShadowType> repoShadow, OperationResult parentResult) throws SchemaException { List<ItemDelta<?, ?>> shadowChanges = prismContext.deltaFor(ShadowType.class) .item(ShadowType.F_EXISTS).replace(true) .asItemDeltas(); LOGGER.trace("Marking shadow {} as existent", repoShadow); try { repositoryService.modifyObject(ShadowType.class, repoShadow.getOid(), shadowChanges, parentResult); } catch (ObjectAlreadyExistsException e) { // Should not happen, this is not a rename new SystemException(e.getMessage(), e); } catch (ObjectNotFoundException e) { // Cannot be more dead LOGGER.trace("Attempt to mark shadow {} as existent found that no such shadow exists", repoShadow); return null; } ObjectDeltaUtil.applyTo(repoShadow, shadowChanges); return repoShadow; }
private void suspendTaskInternal(Task task, OperationResult result) throws SchemaException, ObjectNotFoundException { if (task.getOid() == null) { // this should not occur; so we can treat it in such a brutal way throw new IllegalArgumentException("Only persistent tasks can be suspended/closed (for now); task " + task + " is transient."); } else { if (task.getExecutionStatus() == TaskExecutionStatus.WAITING || task.getExecutionStatus() == TaskExecutionStatus.RUNNABLE) { try { List<ItemDelta<?, ?>> itemDeltas = prismContext.deltaFor(TaskType.class) .item(TaskType.F_EXECUTION_STATUS).replace(TaskExecutionStatusType.SUSPENDED) .item(TaskType.F_STATE_BEFORE_SUSPEND).replace(task.getExecutionStatus().toTaskType()) .asItemDeltas(); ((TaskQuartzImpl) task).applyDeltasImmediate(itemDeltas, result); } catch (ObjectAlreadyExistsException e) { throw new SystemException("Unexpected ObjectAlreadyExistsException while suspending a task: " + e.getMessage(), e); } } executionManager.pauseTaskJob(task, result); // even if this will not succeed, by setting the execution status to SUSPENDED we hope the task // thread will exit on next iteration (does not apply to single-run tasks, of course) } }
public PrismObject<ShadowType> markShadowTombstone(PrismObject<ShadowType> repoShadow, OperationResult parentResult) throws SchemaException { if (repoShadow == null) { return null; } List<ItemDelta<?, ?>> shadowChanges = prismContext.deltaFor(ShadowType.class) .item(ShadowType.F_DEAD).replace(true) .item(ShadowType.F_EXISTS).replace(false) .asItemDeltas(); LOGGER.trace("Marking shadow {} as tombstone", repoShadow); try { repositoryService.modifyObject(ShadowType.class, repoShadow.getOid(), shadowChanges, parentResult); } catch (ObjectAlreadyExistsException e) { // Should not happen, this is not a rename new SystemException(e.getMessage(), e); } catch (ObjectNotFoundException e) { // Cannot be more dead LOGGER.trace("Attempt to mark shadow {} as tombstone found that no such shadow exists", repoShadow); return null; } ObjectDeltaUtil.applyTo(repoShadow, shadowChanges); return repoShadow; }
result.recordFatalError("Couldn't resume task: " + t.getMessage(), t); throw new IllegalStateException("Unexpected exception while resuming task " + task + ": " + t.getMessage(), t); } catch (Throwable t) { result.recordFatalError("Couldn't resume task: " + t.getMessage(), t);
result.computeStatus(); if (!result.isSuccess() && !result.isHandledError()) { ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't add object. Object already exist: " + ex.getMessage(), ex); } else { result.recordSuccess(); throw new ObjectAlreadyExistsException("Couldn't add object. Object already exists: " + ex.getMessage(), ex); } catch (EncryptionException e) {
throw new SystemException(e.getMessage(), e); } catch (ObjectAlreadyExistsException e) { ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't modify object: object after modification would conflict with another existing object: " + e.getMessage(), e); throw e;
"Couldn't add shadow object to the repository. Shadow object already exist. Reason: " + ex.getMessage(), ex); throw new ObjectAlreadyExistsException( "Couldn't add shadow object to the repository. Shadow object already exist. Reason: " + ex.getMessage(), ex);
@Override protected String createTicketDelete(ObjectClassComplexTypeDefinition objectClass, PrismObject<ShadowType> shadow, Collection<? extends ResourceAttribute<?>> identifiers, String resourceOid, OperationResult result) throws ObjectNotFoundException, CommunicationException, GenericFrameworkException, SchemaException, ConfigurationException { LOGGER.debug("Creating case to delete account {}", identifiers); String shadowName = shadow.getName().toString(); String description = "Please delete resource account: "+shadowName; ObjectDeltaType objectDeltaType = new ObjectDeltaType(); objectDeltaType.setChangeType(ChangeTypeType.DELETE); objectDeltaType.setObjectType(ShadowType.COMPLEX_TYPE); ItemDeltaType itemDeltaType = new ItemDeltaType(); itemDeltaType.setPath(new ItemPathType(ItemPath.create("kind"))); itemDeltaType.setModificationType(ModificationTypeType.DELETE); objectDeltaType.setOid(shadow.getOid()); objectDeltaType.getItemDelta().add(itemDeltaType); PrismObject<CaseType> acase; try { acase = addCase(description, resourceOid, shadow.getOid(), objectDeltaType, result); } catch (ObjectAlreadyExistsException e) { // should not happen throw new SystemException(e.getMessage(), e); } return acase.getOid(); }
LOGGER.error("Unexpected repository behavior: Object already exists: {}", e.getMessage(), e); throw new SystemException( "Unexpected repository behavior: Object already exists: " + e.getMessage(), e);
} catch (ObjectAlreadyExistsException e) { parentResult.recordFatalError(e); throw new SystemException(e.getMessage(), e);
} catch (ObjectAlreadyExistsException e) { LOGGER.info("Exception (maybe expected): {}: {}", e.getClass().getSimpleName(), e.getMessage()); } finally { RepositoryCache.exit();
} catch (ObjectAlreadyExistsException e) { LOGGER.info("Exception (maybe expected): {}: {}", e.getClass().getSimpleName(), e.getMessage());