public ApplicationQueueManager getApplicationQueueManager( final EntityManager entityManager, final LegacyQueueManager legacyQueueManager, final JobScheduler jobScheduler, final MetricsFactory metricsService, final Properties properties ) { ApplicationQueueManager manager = cache.getIfPresent(entityManager.getApplicationId()); if(manager != null){ if(logger.isTraceEnabled()){ logger.trace("Returning push queue manager from cache for application: {}", entityManager.getApplicationId()); } return manager; }else { if(logger.isTraceEnabled()) { logger.trace("Push queue manager not found in cache, loading for application: {}", entityManager.getApplicationId()); } manager = new ApplicationQueueManagerImpl( jobScheduler, entityManager, legacyQueueManager, metricsService, properties ); cache.put(entityManager.getApplicationId(), manager); return manager; } }
application = em.getApplication(); if(application == null){ Exception e = new RuntimeException("application id {"+em.getApplicationId()+"} is returning null"); logger.error("Failed to get application",e); throw e;
.getInstance(ApplicationQueueManagerCache.class).invalidate(em.getApplicationId()); } catch (Exception e) { logger.info("notifier testConnection() failed", e);
@Ignore( "Pending https://issues.apache.org/jira/browse/USERGRID-1120. ") // needs to have elasticsearch refreshes implemented @Test public void testIncrementAndDecrement() throws Exception { logger.info( "CounterIT.testIncrementAndDecrement" ); EntityManager em = app.getEntityManager(); assertNotNull( em ); final UUID applicationId = em.getApplicationId(); Map<String, Long> counters = em.getEntityCounters( applicationId ); assertEquals( null, counters.get( "application.collection.users" ) ); UUID uuid = UUIDUtils.newTimeUUID(); // UUID.(); Map<String, Object> userProperties = new HashMap<String, Object>(); userProperties.put( "name", "test-name" ); userProperties.put( "username", "test-username" ); userProperties.put( "email", "test-email" ); User user = ( User ) em.create( uuid, "user", userProperties ).toTypedEntity(); logger.debug( "user={}", user ); em.refreshIndex(); counters = em.getEntityCounters( applicationId ); assertEquals( new Long( 1 ), counters.get( "application.collection.users" ) ); em.delete( user ); em.refreshIndex(); counters = em.getEntityCounters( applicationId ); assertEquals( new Long( 0 ), counters.get( "application.collection.users" ) ); }
emDefaultApp.getApplicationId(), "connfails", null, Level.ALL_PROPERTIES).getEntities(); assertTrue( !importedThings.isEmpty()); assertEquals( 1, importedThings.size() ); emDefaultApp.getApplicationId(), "qtmagics", null, Level.ALL_PROPERTIES).getEntities(); assertTrue(!importedThings.isEmpty()); assertEquals(5, importedThings.size()); emDefaultApp.getApplicationId(), "badjsons", null, Level.ALL_PROPERTIES).getEntities(); assertTrue(!importedThings.isEmpty()); assertEquals( 4, importedThings.size() ); emDefaultApp.getApplicationId(), "things", null, Level.ALL_PROPERTIES).getEntities(); assertTrue(!importedThings.isEmpty()); assertEquals( 10, importedThings.size() );
/** * Go around EntityManager and execute query directly against Core Persistence. * Results may include stale index entries. */ private CandidateResults queryCollectionCp( final String collName, final String type, final String query ) { EntityManager em = app.getEntityManager(); EntityIndexFactory eif = SpringResource.getInstance().getBean( Injector.class ).getInstance( EntityIndexFactory.class ); ApplicationScope as = new ApplicationScopeImpl( new SimpleId( em.getApplicationId(), TYPE_APPLICATION ) ); IndexLocationStrategyFactory indexLocationStrategyFactory = SpringResource.getInstance().getBean( Injector.class ).getInstance(IndexLocationStrategyFactory.class); EntityIndex ei = eif.createEntityIndex(indexLocationStrategyFactory.getIndexLocationStrategy(as)); final Id rootId = createId(em.getApplicationId(), TYPE_APPLICATION); SearchEdge is = CpNamingUtils.createCollectionSearchEdge( rootId, collName ); return ei.search( is, SearchTypes.fromTypes( type ), query, 1000, 0, false ); }
/** /** * Go around EntityManager and get directly from Core Persistence. */ private org.apache.usergrid.persistence.model.entity.Entity getCpEntity( EntityRef eref ) { EntityManager em = app.getEntityManager(); EntityCollectionManagerFactory ecmf = SpringResource.getInstance().getBean( Injector.class ).getInstance( EntityCollectionManagerFactory.class ); EntityCollectionManager ecm = ecmf.createCollectionManager( new ApplicationScopeImpl( new SimpleId(em.getApplicationId(), "application" ) ) ); return ecm.load( new SimpleId( eref.getUuid(), eref.getType() ) ) .toBlocking().lastOrDefault( null ); }
/** * Create test entities of a specified type. * First two entities are connected. */ private void createTestEntities(final EntityManager em, Map<UUID, Entity> thingsMap, List<Entity> things, final String type) throws Exception { logger.debug("\n\nCreating new {} collection in application {}\n", type, em.getApplication().getName()); setup.getEntityIndex().refresh(em.getApplicationId()); List<Entity> created = new ArrayList<>(); for (int i = 0; i < 10; i++) { final int count = i; Entity e = em.create(type, new HashMap<String, Object>() {{ put("name", em.getApplication().getName() + "-" + type + "-" + count); put("originalAppId", em.getApplication().getUuid()); put("originalAppName", em.getApplication().getName()); }}); thingsMap.put(e.getUuid(), e); things.add(e); created.add(e); } // first two things are related to each other em.createConnection(new SimpleEntityRef(type, created.get(0).getUuid()), "related", new SimpleEntityRef(type, created.get(1).getUuid())); em.createConnection(new SimpleEntityRef(type, created.get(1).getUuid()), "related", new SimpleEntityRef(type, created.get(0).getUuid())); setup.getEntityIndex().refresh(em.getApplicationId()); }
deleteIndex(em.getApplicationId()); reIndexService.getBuilder().withApplicationId(em.getApplicationId()).withCollection("catherders"); waitForRebuild(em.getApplicationId().toString(), status.getCollectionName(), reIndexService);
setup.getEntityIndex().refresh(em.getApplicationId());
.withApplicationId( em.getApplicationId() ) .withCollection(collectionName) .withEndTimestamp(timeFirstPutDone);
deleteIndex(em.getApplicationId()); reIndexService.getBuilder().withApplicationId(em.getApplicationId()).withStartTimestamp( updatedTimestamp);
setup.getEntityIndex().waitForQueueDrainAndRefresh(em.getApplicationId(), 500); setup.getEntityIndex().waitForQueueDrainAndRefresh(em.getApplicationId(), 500); em.addUserToRole( user.getUuid(), "logged-in" );
em.getApplicationId(), "things", null, Level.ALL_PROPERTIES).getEntities();
ApplicationScope appScope = CpNamingUtils.getApplicationScope(entityManager.getApplicationId()); Observable<Id> ids = this.app.getApplicationService().deleteAllEntities(appScope, 5);
emDefaultApp.getApplicationId(), "things", query, Level.ALL_PROPERTIES).getEntities();
deleteIndex(em.getApplicationId()); reIndexService.getBuilder().withApplicationId(em.getApplicationId());
throw new RuntimeException("Max retries reached"); setup.getEntityIndex().refresh(em.getApplicationId());
deleteIndex(em.getApplicationId()); reIndexService.getBuilder().withApplicationId(em.getApplicationId());