Search in sources :

Example 26 with ObjectAlreadyExistsException

use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.

the class ReconciliationLauncher method launch.

/**
 * Launch an import. Calling this method will start import in a new
 * thread, possibly on a different node.
 */
public void launch(ResourceType resource, QName objectclass, Task task, OperationResult parentResult) {
    LOGGER.info("Launching reconciliation for resource {} as asynchronous task", ObjectTypeUtil.toShortString(resource));
    OperationResult result = parentResult.createSubresult(ReconciliationLauncher.class.getName() + ".launch");
    result.addParam("resource", resource);
    result.addParam("objectclass", objectclass);
    // Set handler URI so we will be called back
    task.setHandlerUri(ModelPublicConstants.RECONCILIATION_TASK_HANDLER_URI);
    PolyStringType polyString = new PolyStringType("Reconciling " + resource.getName());
    task.setName(polyString);
    ObjectReferenceType resourceRef = ObjectTypeUtil.createObjectRef(resource, prismContext);
    // Not strictly necessary but nice to do (activity would fill-in these when started)
    task.setObjectRef(resourceRef.clone());
    task.addArchetypeInformationIfMissing(SystemObjectsType.ARCHETYPE_RECONCILIATION_TASK.value());
    try {
        // @formatter:off
        task.setRootActivityDefinition(new ActivityDefinitionType(PrismContext.get()).beginWork().beginReconciliation().beginResourceObjects().resourceRef(resourceRef.clone()).objectclass(objectclass).<ReconciliationWorkDefinitionType>end().<WorkDefinitionsType>end().end());
        // @formatter:on
        // just to be sure (if the task was already persistent)
        task.flushPendingModifications(result);
    } catch (ObjectNotFoundException e) {
        LOGGER.error("Task object not found, expecting it to exist (task {})", task, e);
        result.recordFatalError("Task object not found", e);
        throw new IllegalStateException("Task object not found, expecting it to exist", e);
    } catch (ObjectAlreadyExistsException e) {
        LOGGER.error("Task object wasn't updated (task {})", task, e);
        result.recordFatalError("Task object wasn't updated", e);
        throw new IllegalStateException("Task object wasn't updated", e);
    } catch (SchemaException e) {
        LOGGER.error("Error dealing with schema (task {})", task, e);
        result.recordFatalError("Error dealing with schema", e);
        throw new IllegalStateException("Error dealing with schema", e);
    }
    task.addArchetypeInformationIfMissing(SystemObjectsType.ARCHETYPE_RECONCILIATION_TASK.value());
    // Switch task to background. This will start new thread and call
    // the run(task) method.
    // Note: the thread may be actually started on a different node
    taskManager.switchToBackground(task, result);
    result.setBackgroundTaskOid(task.getOid());
    result.computeStatus("Reconciliation launch failed");
    LOGGER.trace("Reconciliation for resource {} switched to background, control thread returning with task {}", ObjectTypeUtil.toShortString(resource), task);
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 27 with ObjectAlreadyExistsException

use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.

the class AbstractInternalModelIntegrationTest method initSystem.

@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
    logger.trace("initSystem");
    super.initSystem(initTask, initResult);
    // We want logging config from logback-test.xml and not from system config object (unless suppressed)
    InternalsConfig.setAvoidLoggingChange(isAvoidLoggingChange());
    mockClockworkHook = new MockClockworkHook();
    hookRegistry.registerChangeHook(MOCK_CLOCKWORK_HOOK_URL, mockClockworkHook);
    modelService.postInit(initResult);
    // System Configuration
    try {
        repoAddObjectFromFile(SYSTEM_CONFIGURATION_FILE, initResult);
    } catch (ObjectAlreadyExistsException e) {
        throw new ObjectAlreadyExistsException("System configuration already exists in repository;" + "looks like the previous test haven't cleaned it up", e);
    }
    repoAddObjectFromFile(SECURITY_POLICY_FILE, initResult);
    // Administrator
    repoAddObjectFromFile(ROLE_SUPERUSER_FILE, initResult);
    userAdministrator = repoAddObjectFromFile(USER_ADMINISTRATOR_FILE, initResult);
    login(userAdministrator);
    // User Templates
    repoAddObjectFromFile(USER_TEMPLATE_FILE, initResult);
    // Resources
    initDummyResourcePirate(null, RESOURCE_DUMMY_FILE, RESOURCE_DUMMY_OID, initTask, initResult);
    // We need to create Barbossa's account in exactly the shape that is given by his existing assignments
    // otherwise any substantial change will trigger reconciliation and the recon changes will interfere with
    // the tests
    DummyAccount account = new DummyAccount(ACCOUNT_HBARBOSSA_DUMMY_USERNAME);
    account.setEnabled(true);
    account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Hector Barbossa");
    account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, "Caribbean");
    account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Pirate Brethren, Inc.");
    account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "Undead Monkey");
    account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, "rum");
    account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME, "Arr!");
    getDummyResource().addAccount(account);
    getDummyResourceController().addAccount(ACCOUNT_HERMAN_DUMMY_USERNAME, "Herman Toothrot", "Monkey Island");
    getDummyResourceController().addAccount(ACCOUNT_GUYBRUSH_DUMMY_USERNAME, "Guybrush Threepwood", "Melee Island");
    // Accounts
    repoAddObjectFromFile(ACCOUNT_HBARBOSSA_DUMMY_FILE, initResult);
    repoAddObjectFromFile(ACCOUNT_SHADOW_GUYBRUSH_DUMMY_FILE, initResult);
    repoAddObjectFromFile(ACCOUNT_SHADOW_ELAINE_DUMMY_FILE, initResult);
    // Users
    userTypeJack = repoAddObjectFromFile(USER_JACK_FILE, UserType.class, initResult).asObjectable();
    userTypeBarbossa = repoAddObjectFromFile(USER_BARBOSSA_FILE, UserType.class, initResult).asObjectable();
    userTypeGuybrush = repoAddObjectFromFile(USER_GUYBRUSH_FILE, UserType.class, initResult).asObjectable();
    userTypeElaine = repoAddObjectFromFile(USER_ELAINE_FILE, UserType.class, initResult).asObjectable();
}
Also used : MockClockworkHook(com.evolveum.midpoint.model.impl.util.mock.MockClockworkHook) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount)

Example 28 with ObjectAlreadyExistsException

use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.

the class TestAssignmentErrors method test222UserAssignAccountDeletedShadowRecomputeNoSync.

/**
 * Assign account to user, delete the account shadow (not the account), recompute the user.
 * We expect an error.
 * <p>
 * This is tried on the red dummy resource where there is no synchronization.
 */
// TODO: after fixing uniqueness check in ProjectionValueProcessor, change the test little bit
// see git commit: 7052f9628a76815d27a119090a97ec57fbdebaec
@Test
public void test222UserAssignAccountDeletedShadowRecomputeNoSync() throws Exception {
    // GIVEN
    PrismObject<UserType> user = setupUserAssignAccountDeletedShadowRecompute(RESOURCE_DUMMY_RED_OID, RESOURCE_DUMMY_RED_NAME, USER_BFET_NAME, USER_BFET_FULLNAME);
    Task task = createPlainTask();
    OperationResult result = task.getResult();
    try {
        // WHEN
        recomputeUser(user.getOid(), task, result);
        AssertJUnit.fail("Unexpected success");
    } catch (ObjectAlreadyExistsException e) {
        // this is expected
        result.computeStatus();
        TestUtil.assertFailure(result);
    }
    user = getUser(user.getOid());
    display("User after", user);
    assertNoLinkedAccount(user);
    // and again ...
    task = createPlainTask();
    result = task.getResult();
    try {
        // WHEN
        recomputeUser(user.getOid(), task, result);
        AssertJUnit.fail("Unexpected success");
    } catch (ObjectAlreadyExistsException e) {
        // this is expected
        result.computeStatus();
        TestUtil.assertFailure(result);
    }
    user = getUser(user.getOid());
    display("User after", user);
    assertNoLinkedAccount(user);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 29 with ObjectAlreadyExistsException

use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.

the class CertHelper method appendStatistics.

public void appendStatistics(StringBuilder sb, AccessCertificationCampaignType campaign, Task task, OperationResult result) {
    AccessCertificationCasesStatisticsType stat;
    try {
        stat = certificationManager.getCampaignStatistics(campaign.getOid(), false, task, result);
    } catch (ObjectNotFoundException | SchemaException | SecurityViolationException | ObjectAlreadyExistsException | ExpressionEvaluationException | RuntimeException | CommunicationException | ConfigurationException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get campaign statistics", e);
        sb.append("Couldn't get campaign statistics because of ").append(e);
        return;
    }
    int all = stat.getMarkedAsAccept() + stat.getMarkedAsRevoke() + stat.getMarkedAsReduce() + stat.getMarkedAsNotDecide() + stat.getWithoutResponse();
    sb.append("Number of cases:\t").append(all);
    sb.append("\nMarked as ACCEPT:\t").append(stat.getMarkedAsAccept());
    sb.append("\nMarked as REVOKE:\t").append(stat.getMarkedAsRevoke()).append(" (remedied: ").append(stat.getMarkedAsRevokeAndRemedied()).append(")");
    sb.append("\nMarked as REDUCE:\t").append(stat.getMarkedAsReduce()).append(" (remedied: ").append(stat.getMarkedAsReduceAndRemedied()).append(")");
    sb.append("\nMarked as NOT DECIDED:\t").append(stat.getMarkedAsNotDecide());
    sb.append("\nNo response:\t\t").append(stat.getWithoutResponse());
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) AccessCertificationCasesStatisticsType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCasesStatisticsType) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 30 with ObjectAlreadyExistsException

use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.

the class ShadowIntegrityCheckActivityRun method deleteShadows.

// shadowsToDelete do not contain 'already deleted shadows'
private void deleteShadows(DuplicateShadowsTreatmentInstruction instruction, StringBuilder sb, Task task, OperationResult result) {
    ShadowCheckConfiguration cfg = getConfiguration();
    LOGGER.trace("Going to delete shadows:\n{}", instruction);
    if (instruction == null || instruction.getShadowsToDelete() == null) {
        return;
    }
    Collection<PrismObject<ShadowType>> shadowsToDelete = instruction.getShadowsToDelete();
    String shadowOidToReplaceDeleted = instruction.getShadowOidToReplaceDeletedOnes();
    for (PrismObject<ShadowType> shadowToDelete : shadowsToDelete) {
        LOGGER.info("Deleting redundant shadow{} {}", skippedForDryRun(), ObjectTypeUtil.toShortString(shadowToDelete));
        sb.append("   --> deleted redundant shadow").append(skippedForDryRun()).append(" ").append(ObjectTypeUtil.toShortString(shadowToDelete)).append("\n");
        String oid = shadowToDelete.getOid();
        List<PrismObject<FocusType>> owners;
        if (cfg.checkOwners) {
            owners = shadowToDelete.getUserData(KEY_OWNERS);
        } else {
            owners = searchOwners(shadowToDelete, result);
        }
        if (!cfg.dryRun) {
            try {
                getRepositoryService().deleteObject(ShadowType.class, oid, result);
                task.recordObjectActionExecuted(shadowToDelete, ChangeType.DELETE, null);
                workingState.duplicateShadowsDeleted.add(oid);
            } catch (ObjectNotFoundException e) {
                // suspicious, but not a big deal
                task.recordObjectActionExecuted(shadowToDelete, ChangeType.DELETE, e);
                LoggingUtils.logExceptionAsWarning(LOGGER, "Shadow {} couldn't be deleted, because it does not exist anymore", e, ObjectTypeUtil.toShortString(shadowToDelete));
                continue;
            } catch (RuntimeException e) {
                task.recordObjectActionExecuted(shadowToDelete, ChangeType.DELETE, e);
                LoggingUtils.logUnexpectedException(LOGGER, "Shadow {} couldn't be deleted because of an unexpected exception", e, ObjectTypeUtil.toShortString(shadowToDelete));
                continue;
            }
        }
        if (owners == null || owners.isEmpty()) {
            continue;
        }
        for (PrismObject<FocusType> owner : owners) {
            List<ItemDelta<?, ?>> modifications = new ArrayList<>(2);
            ReferenceDelta deleteDelta = PrismContext.get().deltaFactory().reference().createModificationDelete(FocusType.F_LINK_REF, owner.getDefinition(), PrismContext.get().itemFactory().createReferenceValue(oid, ShadowType.COMPLEX_TYPE));
            modifications.add(deleteDelta);
            if (shadowOidToReplaceDeleted != null) {
                ReferenceDelta addDelta = PrismContext.get().deltaFactory().reference().createModificationAdd(FocusType.F_LINK_REF, owner.getDefinition(), PrismContext.get().itemFactory().createReferenceValue(shadowOidToReplaceDeleted, ShadowType.COMPLEX_TYPE));
                modifications.add(addDelta);
            }
            LOGGER.info("Executing modify delta{} for owner {}:\n{}", skippedForDryRun(), ObjectTypeUtil.toShortString(owner), DebugUtil.debugDump(modifications));
            if (!cfg.dryRun) {
                try {
                    getRepositoryService().modifyObject(owner.asObjectable().getClass(), owner.getOid(), modifications, result);
                    task.recordObjectActionExecuted(owner, ChangeType.MODIFY, null);
                } catch (ObjectNotFoundException | SchemaException | ObjectAlreadyExistsException | RuntimeException e) {
                    task.recordObjectActionExecuted(owner, ChangeType.MODIFY, e);
                    LoggingUtils.logUnexpectedException(LOGGER, "Focal object {} (owner of {}) couldn't be updated", e, ObjectTypeUtil.toShortString(owner), ObjectTypeUtil.toShortString(shadowToDelete));
                }
            }
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

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