Search in sources :

Example 11 with SpannerEntryManager

use of io.jans.orm.cloud.spanner.impl.SpannerEntryManager in project jans by JanssenProject.

the class SpannerUserSearchSample method main.

public static void main(String[] args) throws InterruptedException {
    // Prepare sample connection details
    final SpannerEntryManagerSample sqlEntryManagerSample = new SpannerEntryManagerSample();
    final SpannerEntryManager sqlEntryManager = sqlEntryManagerSample.createSpannerEntryManager();
    int countUsers = 2000000;
    int threadCount = 200;
    int threadIterationCount = 200;
    Filter filter = Filter.createEqualityFilter(Filter.createLowercaseFilter("uid"), String.format("user%06d", countUsers));
    boolean foundUser = sqlEntryManager.contains("ou=people,o=jans", SimpleUser.class, filter);
    if (!foundUser) {
        addTestUsers(sqlEntryManager, countUsers);
    }
    long totalStart = System.currentTimeMillis();
    try {
        ExecutorService executorService = Executors.newFixedThreadPool(threadCount, daemonThreadFactory());
        for (int i = 0; i < threadCount; i++) {
            activeCount.incrementAndGet();
            final int count = i;
            executorService.execute(new Runnable() {

                @Override
                public void run() {
                    long start = System.currentTimeMillis();
                    for (int j = 0; j < threadIterationCount; j++) {
                        long userUid = Math.round(Math.random() * countUsers);
                        String uid = "user" + userUid;
                        /*String.format("user%06d", userUid);*/
                        try {
                            Filter filter = Filter.createEqualityFilter(Filter.createLowercaseFilter("uid"), StringHelper.toLowerCase(uid));
                            // Filter filter = Filter.createEqualityFilter("uid", uid);
                            List<SimpleUser> foundUsers = sqlEntryManager.findEntries("ou=people,o=jans", SimpleUser.class, filter);
                            if (foundUsers.size() > 0) {
                                successResult.incrementAndGet();
                            } else {
                                LOG.warn("Failed to find user: " + uid);
                                failedResult.incrementAndGet();
                            }
                        } catch (Throwable e) {
                            errorResult.incrementAndGet();
                            System.out.println("ERROR !!!, thread: " + count + ", uid: " + uid + ", error:" + e.getMessage());
                            e.printStackTrace();
                        }
                    }
                    long end = System.currentTimeMillis();
                    long duration = end - start;
                    LOG.info("Thread " + count + " execution time: " + duration);
                    totalTime.addAndGet(duration);
                    activeCount.decrementAndGet();
                }
            });
        }
        while (activeCount.get() != 0) {
            Thread.sleep(1000L);
        }
    } finally {
        sqlEntryManager.destroy();
    }
    long totalEnd = System.currentTimeMillis();
    long duration = totalEnd - totalStart;
    LOG.info("Total execution time: " + duration + " after execution: " + (threadCount * threadIterationCount));
    System.out.println(String.format("successResult: '%d', failedResult: '%d', errorResult: '%d'", successResult.get(), failedResult.get(), errorResult.get()));
}
Also used : SimpleUser(io.jans.orm.cloud.spanner.model.SimpleUser) Filter(io.jans.orm.search.filter.Filter) SpannerEntryManagerSample(io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample) ExecutorService(java.util.concurrent.ExecutorService) List(java.util.List) SpannerEntryManager(io.jans.orm.cloud.spanner.impl.SpannerEntryManager)

Example 12 with SpannerEntryManager

use of io.jans.orm.cloud.spanner.impl.SpannerEntryManager in project jans by JanssenProject.

the class SpannerCustomObjectAttributesSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    SpannerEntryManagerSample sqlEntryManagerSample = new SpannerEntryManagerSample();
    // Create SQL entry manager
    SpannerEntryManager sqlEntryManager = sqlEntryManagerSample.createSpannerEntryManager();
    // Add dummy user
    SimpleUser newUser = new SimpleUser();
    newUser.setDn(String.format("inum=%s,ou=people,o=jans", System.currentTimeMillis()));
    newUser.setUserId("sample_user_" + System.currentTimeMillis());
    newUser.setUserPassword("test");
    newUser.getCustomAttributes().add(new CustomObjectAttribute("address", Arrays.asList("London", "Texas", "Kiev")));
    newUser.getCustomAttributes().add(new CustomObjectAttribute("jansGuid", "test_value"));
    newUser.getCustomAttributes().add(new CustomObjectAttribute("birthdate", new Date()));
    newUser.getCustomAttributes().add(new CustomObjectAttribute("jansActive", false));
    // Require cusom attribute in table with age: INT type
    newUser.getCustomAttributes().add(new CustomObjectAttribute("scimCustomThird", 18));
    newUser.setUserRole(UserRole.ADMIN);
    newUser.setMemberOf(Arrays.asList("group_1", "group_2", "group_3"));
    sqlEntryManager.persist(newUser);
    LOG.info("Added User '{}' with uid '{}' and key '{}'", newUser, newUser.getUserId(), newUser.getDn());
    // Find added dummy user
    SimpleUser foundUser = sqlEntryManager.find(SimpleUser.class, newUser.getDn());
    LOG.info("Found User '{}' with uid '{}' and key '{}'", foundUser, foundUser.getUserId(), foundUser.getDn());
    LOG.info("Custom attributes '{}'", foundUser.getCustomAttributes());
    for (CustomObjectAttribute customAttribute : foundUser.getCustomAttributes()) {
        if (customAttribute.getValue() instanceof Date) {
            LOG.info("Found date custom attribute '{}' with value '{}'", customAttribute.getName(), customAttribute.getValue());
        } else if (customAttribute.getValue() instanceof Integer) {
            LOG.info("Found integer custom attribute '{}' with value '{}'", customAttribute.getName(), customAttribute.getValue());
        } else if (customAttribute.getValue() instanceof Boolean) {
            LOG.info("Found boolean custom attribute '{}' with value '{}'", customAttribute.getName(), customAttribute.getValue());
        } else if (customAttribute.getValues().size() > 1) {
            LOG.info("Found list custom attribute '{}' with value '{}', multiValued: {}", customAttribute.getName(), customAttribute.getValues(), customAttribute.isMultiValued());
        }
    }
    for (Iterator<CustomObjectAttribute> it = foundUser.getCustomAttributes().iterator(); it.hasNext(); ) {
        CustomObjectAttribute attr = (CustomObjectAttribute) it.next();
        if (StringHelper.equalsIgnoreCase(attr.getName(), "jansGuid")) {
            attr.setValue("");
            break;
        }
    }
    sqlEntryManager.merge(foundUser);
    // Find updated dummy user
    SimpleUser foundUser2 = sqlEntryManager.find(SimpleUser.class, newUser.getDn());
    LOG.info("Found User '{}' with uid '{}' and key '{}'", foundUser2, foundUser2.getUserId(), foundUser2.getDn());
    LOG.info("Custom attributes after merge '{}'", foundUser2.getCustomAttributes());
    for (CustomObjectAttribute customAttribute : foundUser2.getCustomAttributes()) {
        if (customAttribute.getValue() instanceof Date) {
            LOG.info("Found date custom attribute '{}' with value '{}'", customAttribute.getName(), customAttribute.getValue());
        } else if (customAttribute.getValue() instanceof Integer) {
            LOG.info("Found integer custom attribute '{}' with value '{}'", customAttribute.getName(), customAttribute.getValue());
        } else if (customAttribute.getValue() instanceof Boolean) {
            LOG.info("Found boolean custom attribute '{}' with value '{}'", customAttribute.getName(), customAttribute.getValue());
        } else if (customAttribute.getValues().size() > 1) {
            LOG.info("Found list custom attribute '{}' with value '{}', multiValued: {}", customAttribute.getName(), customAttribute.getValues(), customAttribute.isMultiValued());
        }
    }
    // Find added dummy user by numeric attribute
    Filter filter = Filter.createGreaterOrEqualFilter("scimCustomThird", 16);
    List<SimpleUser> foundUsers = sqlEntryManager.findEntries("ou=people,o=jans", SimpleUser.class, filter);
    if (foundUsers.size() > 0) {
        foundUser = foundUsers.get(0);
        LOG.info("Found User '{}' by filter '{}' with uid '{}' and key '{}'", foundUser, filter, foundUser, foundUser);
    } else {
        LOG.error("Can't find User by filter '{}'", filter);
    }
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute) SimpleUser(io.jans.orm.cloud.spanner.model.SimpleUser) Filter(io.jans.orm.search.filter.Filter) SpannerEntryManagerSample(io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample) Date(java.util.Date) SpannerEntryManager(io.jans.orm.cloud.spanner.impl.SpannerEntryManager)

Example 13 with SpannerEntryManager

use of io.jans.orm.cloud.spanner.impl.SpannerEntryManager in project jans by JanssenProject.

the class SpannerIdpAuthConfSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    SpannerEntryManagerSample sqlEntryManagerSample = new SpannerEntryManagerSample();
    // Create SQL entry manager
    SpannerEntryManager sqlEntryManager = sqlEntryManagerSample.createSpannerEntryManager();
    JansConfiguration jansConfiguration = sqlEntryManager.find(JansConfiguration.class, "ou=configuration,o=jans");
    LOG.info("Found jansConfiguration: " + jansConfiguration);
}
Also used : JansConfiguration(io.jans.orm.cloud.spanner.model.JansConfiguration) SpannerEntryManagerSample(io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample) SpannerEntryManager(io.jans.orm.cloud.spanner.impl.SpannerEntryManager)

Example 14 with SpannerEntryManager

use of io.jans.orm.cloud.spanner.impl.SpannerEntryManager in project jans by JanssenProject.

the class ManualSpannerEntryManagerTest method createSpannerEntryManager.

public SpannerEntryManager createSpannerEntryManager() throws IOException {
    SpannerEntryManagerFactory sqlEntryManagerFactory = new SpannerEntryManagerFactory();
    sqlEntryManagerFactory.create();
    SpannerEntryManager sqlEntryManager = sqlEntryManagerFactory.createEntryManager(loadProperties());
    System.out.println("Created SpannerEntryManager: " + sqlEntryManager);
    return sqlEntryManager;
}
Also used : SpannerEntryManagerFactory(io.jans.orm.cloud.spanner.impl.SpannerEntryManagerFactory) SpannerEntryManager(io.jans.orm.cloud.spanner.impl.SpannerEntryManager)

Aggregations

SpannerEntryManager (io.jans.orm.cloud.spanner.impl.SpannerEntryManager)14 SpannerEntryManagerSample (io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample)12 Filter (io.jans.orm.search.filter.Filter)8 Date (java.util.Date)5 SimpleUser (io.jans.orm.cloud.spanner.model.SimpleUser)4 CustomObjectAttribute (io.jans.orm.model.base.CustomObjectAttribute)3 SpannerEntryManagerFactory (io.jans.orm.cloud.spanner.impl.SpannerEntryManagerFactory)2 SimpleSession (io.jans.orm.cloud.spanner.model.SimpleSession)2 SimpleSessionState (io.jans.orm.cloud.spanner.model.SimpleSessionState)2 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)2 CustomAttribute (io.jans.orm.model.base.CustomAttribute)2 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 JansConfiguration (io.jans.orm.cloud.spanner.model.JansConfiguration)1 SimpleAttribute (io.jans.orm.cloud.spanner.model.SimpleAttribute)1 SimpleCacheEntry (io.jans.orm.cloud.spanner.model.SimpleCacheEntry)1 SimpleClient (io.jans.orm.cloud.spanner.model.SimpleClient)1 SimpleCustomStringUser (io.jans.orm.cloud.spanner.model.SimpleCustomStringUser)1 SimpleGrant (io.jans.orm.cloud.spanner.model.SimpleGrant)1 SimpleToken (io.jans.orm.cloud.spanner.model.SimpleToken)1