Search in sources :

Example 56 with OrgType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType in project midpoint by Evolveum.

the class AbstractOrgClosureTest method _test300AddRemoveOrgs.

protected void _test300AddRemoveOrgs() throws Exception {
    OperationResult opResult = new OperationResult("===[ test300AddRemoveOrgs ]===");
    int totalRounds = 0;
    OrgClosureStatistics stat = new OrgClosureStatistics();
    // OrgType node removal + addition
    long totalTimeNodeRemovals = 0, totalTimeNodeAdditions = 0;
    for (int level = 0; level < getConfiguration().getNodeRoundsForLevel().length; level++) {
        for (int round = 0; round < getConfiguration().getNodeRoundsForLevel()[level]; round++) {
            // removal
            List<String> levelOids = orgsByLevels.get(level);
            if (levelOids.isEmpty()) {
                continue;
            }
            int index = (int) Math.floor(Math.random() * levelOids.size());
            String oid = levelOids.get(index);
            OrgType org = repositoryService.getObject(OrgType.class, oid, null, opResult).asObjectable();
            System.out.println("Removing org #" + totalRounds + " (" + level + "/" + round + "): " + org.getOid() + " (parents: " + getParentsOids(org.asPrismObject()) + ")");
            long start = System.currentTimeMillis();
            removeOrg(org.getOid(), opResult);
            long timeRemoval = System.currentTimeMillis() - start;
            System.out.println(" ... done in " + timeRemoval + " ms" + getNetDurationMessage());
            stat.recordExtended(baseHelper.getConfiguration().getHibernateDialect(), allOrgCreated.size(), allUsersCreated.size(), closureSize, "AddRemoveOrgs", level, false, getNetDuration());
            totalTimeNodeRemovals += getNetDuration();
            checkClosure(getVertices());
            // addition
            System.out.println("Re-adding org #" + totalRounds);
            start = System.currentTimeMillis();
            reAddOrg(org, opResult);
            long timeAddition = System.currentTimeMillis() - start;
            System.out.println(" ... done in " + timeAddition + "ms" + getNetDurationMessage());
            stat.recordExtended(baseHelper.getConfiguration().getHibernateDialect(), allOrgCreated.size(), allUsersCreated.size(), closureSize, "AddRemoveOrgs", level, true, getNetDuration());
            checkClosure(getVertices());
            totalTimeNodeAdditions += getNetDuration();
            totalRounds++;
        }
    }
    if (totalRounds > 0) {
        System.out.println("Avg time for an arbitrary node removal: " + ((double) totalTimeNodeRemovals / totalRounds) + " ms");
        System.out.println("Avg time for an arbitrary node re-addition: " + ((double) totalTimeNodeAdditions / totalRounds) + " ms");
        LOGGER.info("===================================================");
        LOGGER.info("Statistics for org node removal/addition:");
        stat.dump(LOGGER, baseHelper.getConfiguration().getHibernateDialect(), allOrgCreated.size(), allUsersCreated.size(), closureSize, "AddRemoveOrgs");
    }
}
Also used : OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 57 with OrgType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType in project midpoint by Evolveum.

the class AbstractOrgClosureTest method scanChildren.

protected void scanChildren(int level, String parentOid, OperationResult opResult) throws SchemaException, ObjectNotFoundException {
    if (level > maxLevel) {
        maxLevel = level;
    }
    List<String> children = getChildren(parentOid);
    for (String childOid : children) {
        if (alreadyKnown(childOid)) {
            continue;
        }
        objectCount++;
        System.out.println("#" + objectCount + ": parent level = " + level + ", childOid = " + childOid);
        ObjectType objectType = repositoryService.getObject(ObjectType.class, childOid, null, opResult).asObjectable();
        if (objectType instanceof OrgType) {
            allOrgCreated.add((OrgType) objectType);
            registerOrgToLevels(level + 1, objectType.getOid());
            // children will be registered to graph later
            registerObject(objectType, false);
            scanChildren(level + 1, objectType.getOid(), opResult);
        } else if (objectType instanceof UserType) {
            allUsersCreated.add((UserType) objectType);
            registerUserToLevels(level + 1, objectType.getOid());
        } else {
            throw new IllegalStateException("Object with unexpected type: " + objectType);
        }
    }
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) RObjectType(com.evolveum.midpoint.repo.sql.data.common.other.RObjectType) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 58 with OrgType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType in project midpoint by Evolveum.

the class OrgClosureConcurrencyTest method _test200AddRemoveLinksMT.

/**
     * We randomly select a set of links to be removed.
     * Then we remove them, using a given set of threads.
     * After all threads are done, we will check the closure table consistency.
     *
     * And after that, we will do the reverse, re-adding all the links previously removed.
     * In the end, we again check the consistency.
     */
protected void _test200AddRemoveLinksMT(final boolean random) throws Exception {
    OperationResult opResult = new OperationResult("===[ test200AddRemoveLinksMT ]===");
    info("test200AddRemoveLinks starting with random = " + random);
    final Set<Edge> edgesToRemove = Collections.synchronizedSet(new HashSet<Edge>());
    final Set<Edge> edgesToAdd = Collections.synchronizedSet(new HashSet<Edge>());
    final List<Throwable> exceptions = Collections.synchronizedList(new ArrayList<Throwable>());
    // parentRef link removal + addition
    for (int level = 0; level < getConfiguration().getLinkRoundsForLevel().length; level++) {
        int rounds = getConfiguration().getLinkRoundsForLevel()[level];
        List<String> levelOids = orgsByLevels.get(level);
        int retries = 0;
        for (int round = 0; round < rounds; round++) {
            int index = (int) Math.floor(Math.random() * levelOids.size());
            String oid = levelOids.get(index);
            OrgType org = repositoryService.getObject(OrgType.class, oid, null, opResult).asObjectable();
            // check if it has no parents (shouldn't occur here!)
            if (org.getParentOrgRef().isEmpty()) {
                throw new IllegalStateException("No parents in " + org);
            }
            int i = (int) Math.floor(Math.random() * org.getParentOrgRef().size());
            ObjectReferenceType parentOrgRef = org.getParentOrgRef().get(i);
            Edge edge = new Edge(oid, parentOrgRef.getOid());
            if (edgesToRemove.contains(edge)) {
                round--;
                if (++retries == 1000) {
                    // primitive attempt to break potential cycles when there is not enough edges to process
                    throw new IllegalStateException("Too many retries");
                } else {
                    continue;
                }
            }
            edgesToRemove.add(edge);
            edgesToAdd.add(edge);
        }
    }
    int numberOfRunners = THREADS;
    info("Edges to remove/add (" + edgesToRemove.size() + ": " + edgesToRemove);
    info("Number of runners: " + numberOfRunners);
    final List<Thread> runners = Collections.synchronizedList(new ArrayList<Thread>());
    for (int i = 0; i < numberOfRunners; i++) {
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                try {
                    while (true) {
                        Edge edge = getNext(edgesToRemove, random);
                        if (edge == null) {
                            break;
                        }
                        LOGGER.info("Removing {}", edge);
                        removeEdge(edge);
                        int remaining;
                        synchronized (OrgClosureConcurrencyTest.this) {
                            edgesToRemove.remove(edge);
                            remaining = edgesToRemove.size();
                        }
                        info(Thread.currentThread().getName() + " removed " + edge + "; remaining: " + remaining);
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                    exceptions.add(e);
                } finally {
                    runners.remove(Thread.currentThread());
                }
            }
        };
        Thread t = new Thread(runnable);
        runners.add(t);
        t.start();
    }
    waitForRunnersCompletion(runners);
    if (!edgesToRemove.isEmpty()) {
        throw new AssertionError("Edges to remove is not empty, see the console or log: " + edgesToRemove);
    }
    if (!exceptions.isEmpty()) {
        throw new AssertionError("Found exceptions: " + exceptions);
    }
    checkClosure(orgGraph.vertexSet());
    info("Consistency after removal OK");
    for (int i = 0; i < numberOfRunners; i++) {
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                try {
                    while (true) {
                        Edge edge = getNext(edgesToAdd, random);
                        if (edge == null) {
                            break;
                        }
                        LOGGER.info("Adding {}", edge);
                        addEdge(edge);
                        int remaining;
                        synchronized (OrgClosureConcurrencyTest.this) {
                            edgesToAdd.remove(edge);
                            remaining = edgesToAdd.size();
                        }
                        info(Thread.currentThread().getName() + " re-added " + edge + "; remaining: " + remaining);
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                    exceptions.add(e);
                } finally {
                    runners.remove(Thread.currentThread());
                }
            }
        };
        Thread t = new Thread(runnable);
        runners.add(t);
        t.start();
    }
    waitForRunnersCompletion(runners);
    if (!edgesToAdd.isEmpty()) {
        throw new AssertionError("Edges to add is not empty, see the console or log: " + edgesToAdd);
    }
    if (!exceptions.isEmpty()) {
        throw new AssertionError("Found exceptions: " + exceptions);
    }
    checkClosure(orgGraph.vertexSet());
    info("Consistency after re-adding OK");
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) Edge(com.evolveum.midpoint.repo.sql.helpers.OrgClosureManager.Edge)

Example 59 with OrgType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType in project midpoint by Evolveum.

the class AbstractOrgClosureTest method addOrgParent.

// TODO generalzie to addObjectParent
protected void addOrgParent(OrgType org, ObjectReferenceType parentOrgRef, boolean useReplace, OperationResult opResult) throws Exception {
    List<ItemDelta> modifications = new ArrayList<>();
    PrismReferenceValue existingValue = parentOrgRef.asReferenceValue();
    ItemDelta itemDelta;
    if (!useReplace) {
        itemDelta = ReferenceDelta.createModificationAdd(OrgType.class, OrgType.F_PARENT_ORG_REF, prismContext, existingValue.clone());
    } else {
        List<PrismReferenceValue> newValues = new ArrayList<>();
        for (ObjectReferenceType ort : org.getParentOrgRef()) {
            newValues.add(ort.asReferenceValue().clone());
        }
        newValues.add(existingValue.clone());
        PrismObjectDefinition objectDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(OrgType.class);
        itemDelta = ReferenceDelta.createModificationReplace(new ItemPath(OrgType.F_PARENT_ORG_REF), objectDefinition, newValues);
    }
    modifications.add(itemDelta);
    repositoryService.modifyObject(OrgType.class, org.getOid(), modifications, opResult);
    orgGraph.addEdge(org.getOid(), existingValue.getOid());
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 60 with OrgType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType in project midpoint by Evolveum.

the class TestScriptHooks method test110JackAddOrganization.

@Test
public void test110JackAddOrganization() throws Exception {
    final String TEST_NAME = "test110JackAddOrganization";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestScriptHooks.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
    dummyAuditService.clear();
    StaticHookRecorder.reset();
    // WHEN
    modifyUserAdd(USER_JACK_OID, UserType.F_ORGANIZATION, task, result, new PolyString("Pirate Brethren"));
    // THEN
    result.computeStatus();
    TestUtil.assertSuccess(result);
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    display("User after change execution", userJack);
    assertUserJack(userJack);
    String accountOid = getSingleLinkOid(userJack);
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
    display("Shadow (repo)", accountShadow);
    assertAccountShadowRepo(accountShadow, accountOid, ACCOUNT_JACK_DUMMY_USERNAME, resourceDummyHookType);
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
    display("Shadow (model)", accountModel);
    assertAccountShadowModel(accountModel, accountOid, ACCOUNT_JACK_DUMMY_USERNAME, resourceDummyHookType);
    // Check account in dummy resource
    assertDummyAccount(RESOURCE_DUMMY_HOOK_NAME, ACCOUNT_JACK_DUMMY_USERNAME, "Jack Sparrow", true);
    PrismObject<OrgType> brethrenOrg = searchObjectByName(OrgType.class, "Pirate Brethren", task, result);
    assertNotNull("Brethren org was not created", brethrenOrg);
    display("Brethren org", brethrenOrg);
    assertAssignedOrg(userJack, brethrenOrg);
    display("StaticHookRecorder", StaticHookRecorder.dump());
    StaticHookRecorder.assertInvocationCount("org", 1);
    StaticHookRecorder.assertInvocationCount("foo", 10);
    StaticHookRecorder.assertInvocationCount("bar", 10);
    StaticHookRecorder.assertInvocationCount("bar-user", 1);
// TODO
//        // Check audit
//        display("Audit", dummyAuditService);
//        dummyAuditService.assertRecords(4);
//        dummyAuditService.assertAnyRequestDeltas();
//        dummyAuditService.assertExecutionDeltas(1,1);
//        dummyAuditService.asserHasDelta(1,ChangeType.ADD, OrgType.class);
//        dummyAuditService.assertExecutionDeltas(3,1);
//        dummyAuditService.asserHasDelta(3,ChangeType.MODIFY, UserType.class);
//        dummyAuditService.assertExecutionSuccess();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Aggregations

OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)123 Test (org.testng.annotations.Test)70 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)69 Task (com.evolveum.midpoint.task.api.Task)69 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)31 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)26 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)23 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)22 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)15 PrismObject (com.evolveum.midpoint.prism.PrismObject)13 ArrayList (java.util.ArrayList)13 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)11 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)11 Entry (org.opends.server.types.Entry)10 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)9 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)8 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)8 QName (javax.xml.namespace.QName)8 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)7 SelectableBean (com.evolveum.midpoint.web.component.util.SelectableBean)7