Search in sources :

Example 36 with ObjectAlreadyExistsException

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;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 37 with ObjectAlreadyExistsException

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();
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 38 with ObjectAlreadyExistsException

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);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RunningTask(com.evolveum.midpoint.task.api.RunningTask) Task(com.evolveum.midpoint.task.api.Task) RunningTask(com.evolveum.midpoint.task.api.RunningTask) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 39 with ObjectAlreadyExistsException

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);
}
Also used : BeforeSuite(org.testng.annotations.BeforeSuite) com.evolveum.midpoint.schema(com.evolveum.midpoint.schema) java.util(java.util) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) QueryKey(com.evolveum.midpoint.repo.cache.local.QueryKey) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Autowired(org.springframework.beans.factory.annotation.Autowired) OperationPerformanceInformation(com.evolveum.midpoint.repo.api.perf.OperationPerformanceInformation) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) PerformanceInformation(com.evolveum.midpoint.repo.api.perf.PerformanceInformation) PrettyPrinter(com.evolveum.midpoint.util.PrettyPrinter) StringUtils(org.apache.commons.lang3.StringUtils) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) GlobalObjectCache(com.evolveum.midpoint.repo.cache.global.GlobalObjectCache) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) PrismTestUtil(com.evolveum.midpoint.prism.util.PrismTestUtil) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) REPOSITORY_IMPL_NAME(com.evolveum.midpoint.repo.sqale.SqaleRepositoryService.REPOSITORY_IMPL_NAME) PrismContext(com.evolveum.midpoint.prism.PrismContext) CachePerformanceInformationUtil(com.evolveum.midpoint.schema.statistics.CachePerformanceInformationUtil) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) GlobalQueryCache(com.evolveum.midpoint.repo.cache.global.GlobalQueryCache) PrismTestUtil.getPrismContext(com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext) RepositoryPerformanceInformationUtil(com.evolveum.midpoint.schema.statistics.RepositoryPerformanceInformationUtil) AbstractSpringTest(com.evolveum.midpoint.test.util.AbstractSpringTest) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) CachePerformanceCollector(com.evolveum.midpoint.util.caching.CachePerformanceCollector) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) ArchetypeType(com.evolveum.midpoint.xml.ns._public.common.common_3.ArchetypeType) PrismObject(com.evolveum.midpoint.prism.PrismObject) AssertJUnit.fail(org.testng.AssertJUnit.fail) InfraTestMixin(com.evolveum.midpoint.test.util.InfraTestMixin) AtomicLong(java.util.concurrent.atomic.AtomicLong) GlobalVersionCache(com.evolveum.midpoint.repo.cache.global.GlobalVersionCache) MidPointConstants(com.evolveum.midpoint.schema.constants.MidPointConstants) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ContextConfiguration(org.springframework.test.context.ContextConfiguration) PostConstruct(javax.annotation.PostConstruct) PrismTestUtil.displayCollection(com.evolveum.midpoint.prism.util.PrismTestUtil.displayCollection) GlobalCacheObjectValue(com.evolveum.midpoint.repo.cache.global.GlobalCacheObjectValue) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) NotNull(org.jetbrains.annotations.NotNull) SqaleRepositoryService(com.evolveum.midpoint.repo.sqale.SqaleRepositoryService) PrismContext(com.evolveum.midpoint.prism.PrismContext) PrismTestUtil.getPrismContext(com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) PrismObject(com.evolveum.midpoint.prism.PrismObject) ArchetypeType(com.evolveum.midpoint.xml.ns._public.common.common_3.ArchetypeType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.testng.annotations.Test) AbstractSpringTest(com.evolveum.midpoint.test.util.AbstractSpringTest)

Example 40 with ObjectAlreadyExistsException

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);
}
Also used : BeforeSuite(org.testng.annotations.BeforeSuite) com.evolveum.midpoint.schema(com.evolveum.midpoint.schema) java.util(java.util) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) QueryKey(com.evolveum.midpoint.repo.cache.local.QueryKey) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Autowired(org.springframework.beans.factory.annotation.Autowired) OperationPerformanceInformation(com.evolveum.midpoint.repo.api.perf.OperationPerformanceInformation) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) PerformanceInformation(com.evolveum.midpoint.repo.api.perf.PerformanceInformation) PrettyPrinter(com.evolveum.midpoint.util.PrettyPrinter) StringUtils(org.apache.commons.lang3.StringUtils) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) GlobalObjectCache(com.evolveum.midpoint.repo.cache.global.GlobalObjectCache) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) PrismTestUtil(com.evolveum.midpoint.prism.util.PrismTestUtil) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) REPOSITORY_IMPL_NAME(com.evolveum.midpoint.repo.sqale.SqaleRepositoryService.REPOSITORY_IMPL_NAME) PrismContext(com.evolveum.midpoint.prism.PrismContext) CachePerformanceInformationUtil(com.evolveum.midpoint.schema.statistics.CachePerformanceInformationUtil) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) GlobalQueryCache(com.evolveum.midpoint.repo.cache.global.GlobalQueryCache) PrismTestUtil.getPrismContext(com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext) RepositoryPerformanceInformationUtil(com.evolveum.midpoint.schema.statistics.RepositoryPerformanceInformationUtil) AbstractSpringTest(com.evolveum.midpoint.test.util.AbstractSpringTest) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) CachePerformanceCollector(com.evolveum.midpoint.util.caching.CachePerformanceCollector) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) ArchetypeType(com.evolveum.midpoint.xml.ns._public.common.common_3.ArchetypeType) PrismObject(com.evolveum.midpoint.prism.PrismObject) AssertJUnit.fail(org.testng.AssertJUnit.fail) InfraTestMixin(com.evolveum.midpoint.test.util.InfraTestMixin) AtomicLong(java.util.concurrent.atomic.AtomicLong) GlobalVersionCache(com.evolveum.midpoint.repo.cache.global.GlobalVersionCache) MidPointConstants(com.evolveum.midpoint.schema.constants.MidPointConstants) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ContextConfiguration(org.springframework.test.context.ContextConfiguration) PostConstruct(javax.annotation.PostConstruct) PrismTestUtil.displayCollection(com.evolveum.midpoint.prism.util.PrismTestUtil.displayCollection) GlobalCacheObjectValue(com.evolveum.midpoint.repo.cache.global.GlobalCacheObjectValue) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) NotNull(org.jetbrains.annotations.NotNull) SqaleRepositoryService(com.evolveum.midpoint.repo.sqale.SqaleRepositoryService) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArchetypeType(com.evolveum.midpoint.xml.ns._public.common.common_3.ArchetypeType) CachePerformanceCollector(com.evolveum.midpoint.util.caching.CachePerformanceCollector) Test(org.testng.annotations.Test) AbstractSpringTest(com.evolveum.midpoint.test.util.AbstractSpringTest)

Aggregations

ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)142 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)84 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)76 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)69 SystemException (com.evolveum.midpoint.util.exception.SystemException)50 PrismObject (com.evolveum.midpoint.prism.PrismObject)39 Test (org.testng.annotations.Test)36 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)31 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)29 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)28 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)27 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)24 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)24 RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)22 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)22 QName (javax.xml.namespace.QName)22 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)20 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)17 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)17 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)17