use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class ConnectorManager method addConnectorToRepo.
/**
* @return true if connector was not present in repo and was added to it
*/
private boolean addConnectorToRepo(ConnectorType foundConnector, OperationResult result, ConnectorHostType hostType) {
LOGGER.trace("Connector {} not in the repository, adding", foundConnector);
if (foundConnector.getSchema() == null) {
LOGGER.warn("Connector {} haven't provided configuration schema", foundConnector);
}
// Sanitize framework-supplied OID
if (StringUtils.isNotEmpty(foundConnector.getOid())) {
LOGGER.warn("Provisioning framework {} supplied OID for connector {}", foundConnector.getFramework(), foundConnector);
foundConnector.setOid(null);
}
// Store the connector object
String oid;
try {
prismContext.adopt(foundConnector);
oid = repositoryService.addObject(foundConnector.asPrismObject(), null, result);
} catch (ObjectAlreadyExistsException e) {
if (isInRepo(foundConnector, hostType, result)) {
return false;
}
throw new SystemException("Connector was not present in repository, but add failed", e);
} catch (SchemaException e) {
// If there is a schema error it must be a bug. Convert to
// runtime exception
LOGGER.error("Got SchemaException while not expecting it: {}", e.getMessage(), e);
result.recordFatalError("Got SchemaException while not expecting it: " + e.getMessage(), e);
throw new SystemException("Got SchemaException while not expecting it: " + e.getMessage(), e);
}
foundConnector.setOid(oid);
// have access to repository, therefore it cannot resolve it for itself
if (hostType != null) {
foundConnector.getConnectorHostRef().asReferenceValue().setObject(hostType.asPrismObject());
}
return true;
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class ManualConnectorInstance method createTicketDelete.
@Override
protected String createTicketDelete(ResourceObjectDefinition objectDefinition, PrismObject<ShadowType> shadow, Collection<? extends ResourceAttribute<?>> identifiers, String resourceOid, Task task, OperationResult result) throws SchemaException {
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("delete", description, resourceOid, shadowName, shadow.getOid(), objectDeltaType, task, result);
} catch (ObjectAlreadyExistsException e) {
// should not happen
throw new SystemException(e.getMessage(), e);
}
return aCase.getOid();
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class SubtaskHelper method switchExecutionToChildren.
void switchExecutionToChildren(Collection<Task> children, OperationResult result) throws ActivityRunException {
try {
RunningTask runningTask = getRunningTask();
runningTask.makeWaitingForOtherTasks(TaskUnpauseActionType.EXECUTE_IMMEDIATELY);
runningTask.flushPendingModifications(result);
for (Task child : children) {
if (child.isSuspended()) {
getBeans().taskManager.resumeTask(child.getOid(), result);
LOGGER.debug("Started prepared child {}", child);
}
}
} catch (SchemaException | ObjectNotFoundException | ObjectAlreadyExistsException e) {
throw new ActivityRunException("Couldn't switch execution to activity subtask", FATAL_ERROR, PERMANENT_ERROR, e);
}
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class TestRepositoryCache method test300ModifyInIterativeSearch.
/**
* MID-6250
*/
@Test
public void test300ModifyInIterativeSearch() throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException {
given();
PrismContext prismContext = getPrismContext();
OperationResult result = createOperationResult();
clearStatistics();
clearCaches();
String name = "testModifyInIterativeSearch";
String changedDescription = "changed";
PrismObject<ArchetypeType> archetype = new ArchetypeType(prismContext).name(name).asPrismObject();
repositoryCache.addObject(archetype, null, result);
when();
ObjectQuery query = prismContext.queryFor(ArchetypeType.class).item(ArchetypeType.F_NAME).eqPoly(name).matchingOrig().build();
List<ItemDelta<?, ?>> deltas = prismContext.deltaFor(ArchetypeType.class).item(ArchetypeType.F_DESCRIPTION).replace(changedDescription).asItemDeltas();
AtomicInteger found = new AtomicInteger(0);
ResultHandler<ArchetypeType> handler = (object, result1) -> {
try {
repositoryCache.modifyObject(ArchetypeType.class, object.getOid(), deltas, result1);
} catch (ObjectNotFoundException | SchemaException | ObjectAlreadyExistsException e) {
throw new AssertionError(e);
}
found.incrementAndGet();
return true;
};
repositoryCache.searchObjectsIterative(ArchetypeType.class, query, handler, null, false, result);
dumpStatistics();
assertThat(found.get()).as("objects found").isEqualTo(1);
PrismObject<ArchetypeType> singleObjectAfter = repositoryCache.getObject(ArchetypeType.class, archetype.getOid(), null, result);
List<PrismObject<ArchetypeType>> listAfter = repositoryCache.searchObjects(ArchetypeType.class, query, null, result);
then();
assertThat(singleObjectAfter.asObjectable().getDescription()).as("description in getObject result (after change)").isEqualTo(changedDescription);
assertThat(listAfter.size()).as("objects found after").isEqualTo(1);
assertThat(listAfter.get(0).asObjectable().getDescription()).as("description in searchObjects result (after change)").isEqualTo(changedDescription);
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class TestRepositoryCache method test320SearchObjectsIterativeSlow.
/**
* MID-6250
*/
@Test
public void test320SearchObjectsIterativeSlow() throws ObjectAlreadyExistsException, SchemaException, ObjectNotFoundException {
OperationResult result = createOperationResult();
deleteExistingObjects(ArchetypeType.class, result);
clearStatistics();
clearCaches();
generateObjects(ArchetypeType.class, 5, result);
when();
SearchResultList<PrismObject<ArchetypeType>> retrieved = new SearchResultList<>();
AtomicBoolean delayed = new AtomicBoolean(false);
ResultHandler<ArchetypeType> handler = (object, parentResult) -> {
retrieved.add(object.clone());
object.asObjectable().setDescription("garbage: " + Math.random());
if (!delayed.getAndSet(true)) {
try {
// larger than default staleness limit of 1000 ms
Thread.sleep(1500);
} catch (InterruptedException e) {
throw new AssertionError(e);
}
}
return true;
};
repositoryCache.searchObjectsIterative(ArchetypeType.class, null, handler, null, true, result);
then();
dumpStatistics();
assertObjectIsCached(retrieved.get(0).getOid());
assertVersionIsCached(retrieved.get(0).getOid());
for (int i = 1; i < retrieved.size(); i++) {
assertObjectIsNotCached(retrieved.get(i).getOid());
assertVersionIsNotCached(retrieved.get(i).getOid());
}
assertQueryIsNotCached(ArchetypeType.class, null);
Map<String, CachePerformanceCollector.CacheData> map = CachePerformanceCollector.INSTANCE.getGlobalPerformanceMap();
CachePerformanceCollector.CacheData data = map.get("all.ArchetypeType");
// 4 objects + 1 search result
assertThat(data.skippedStaleData.get()).as("stale data counter").isEqualTo(5);
}
Aggregations