You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by mr...@apache.org on 2016/06/15 16:25:08 UTC
[15/50] [abbrv] usergrid git commit: Merge branch 'release-2.1.1'
into usergrid-1283-mgmt-app-init
Merge branch 'release-2.1.1' into usergrid-1283-mgmt-app-init
Conflicts:
stack/services/src/main/java/org/apache/usergrid/services/ServiceManager.java
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/6daba1d7
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/6daba1d7
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/6daba1d7
Branch: refs/heads/master
Commit: 6daba1d7d3dd9ce65644229af87f0440cee53117
Parents: 8ebc28d 0970e1d
Author: Dave Johnson <sn...@apache.org>
Authored: Wed May 25 10:08:06 2016 -0400
Committer: Dave Johnson <sn...@apache.org>
Committed: Wed May 25 10:08:06 2016 -0400
----------------------------------------------------------------------
.../main/resources/usergrid-default.properties | 5 --
.../corepersistence/CpEntityManager.java | 3 -
.../corepersistence/CpEntityManagerFactory.java | 72 +++++++++-----------
.../usergrid/services/ServiceManager.java | 27 ++++----
4 files changed, 46 insertions(+), 61 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/6daba1d7/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/6daba1d7/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index 924dd10,91a936d..f92fc9e
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@@ -141,66 -142,12 +141,79 @@@ public class CpEntityManagerFactory imp
this.connectionService = injector.getInstance( ConnectionService.class );
this.indexSchemaCacheFactory = injector.getInstance( IndexSchemaCacheFactory.class );
- // this line always needs to be last due to the temporary circular dependency until spring is removed
-
- this.applicationIdCache = injector.getInstance(ApplicationIdCacheFactory.class).getInstance(
- getManagementEntityManager() );
-
- //this line always needs to be last due to the temporary cicular dependency until spring is removed
+ int entityManagerCacheSize = 100;
+ try {
+ entityManagerCacheSize = Integer.parseInt(
+ cassandraService.getProperties().getProperty( ENTITY_MANAGER_CACHE_SIZE, "100" ));
+ } catch ( Exception e ) {
+ logger.error("Error parsing " + ENTITY_MANAGER_CACHE_SIZE + " using " + entityManagerCacheSize, e );
+ }
- this.applicationIdCache = injector.getInstance(ApplicationIdCacheFactory.class).getInstance(
- getManagementEntityManager() );
+ entityManagers = CacheBuilder.newBuilder()
+ .maximumSize(entityManagerCacheSize)
+ .build(new CacheLoader<UUID, EntityManager>() {
+ public EntityManager load( UUID appId ) { // no checked exception
+
- // get entity manager and ensure it can get its own application
-
++ // create new entity manager and pre-fetch its application
+ EntityManager entityManager = _getEntityManager( appId );
+ Application app = null;
+ Exception exception = null;
+ try {
+ app = entityManager.getApplication();
+ } catch (Exception e) {
+ exception = e;
+ }
+
+ // the management app is a special case
+
+ if ( CpNamingUtils.MANAGEMENT_APPLICATION_ID.equals( appId ) ) {
+
- if ( app != null && entityManager != null ) {
-
++ if ( app != null ) {
+ // we successfully fetched up the management app, cache it for a rainy day
+ managementAppEntityManager = entityManager;
+
- } else if ( entityManager == null && managementAppEntityManager != null ) {
-
++ } else if ( managementAppEntityManager != null ) {
+ // failed to fetch management app, use cached one
+ entityManager = managementAppEntityManager;
-
- } else {
-
- // fetch failed and we have nothing cached, we must be bootstrapping
- logger.info("managementAppEntityManager is null, bootstrapping in progress");
+ }
++ }
- } else { // not the management app, so blow up if app cannot be fetched
-
- if (app == null) {
- throw new RuntimeException( "Error getting application " + appId, exception );
- }
++ if (app == null) {
++ throw new RuntimeException( "Error getting application " + appId, exception );
+ }
+
+ return entityManager;
+ }
+ });
++
++ // hold up construction until we can access the management app
++ int maxRetries = 1000;
++ int retries = 0;
++ boolean managementAppFound = false;
++ Set<Class> seenBefore = new HashSet<>(100);
++ while ( !managementAppFound && retries++ < maxRetries ) {
++ try {
++ getEntityManager( getManagementAppId() ).getApplication();
++ managementAppFound = true;
++
++ } catch ( Throwable t ) {
++ if ( seenBefore.contains( t.getClass() )) { // don't log full stack trace if we've seen same before
++ logger.error("Error {} getting management app on try {}", t.getClass().getSimpleName(), retries);
++ } else {
++ logger.error("Error getting management app on try {}", t.getClass().getSimpleName(), t);
++ }
++ }
++ }
++
++ if ( !managementAppFound ) {
++ // exception here will prevent WAR from being deployed
++ throw new RuntimeException( "Unable to get management app after " + retries + " retries" );
++ }
++
++ // this line always needs to be last due to the temporary circular dependency until spring is removed
++ applicationIdCache = injector.getInstance(ApplicationIdCacheFactory.class)
++ .getInstance( getManagementEntityManager() );
}
@@@ -255,7 -187,7 +252,6 @@@
}
--
@Override
public EntityManager getEntityManager(UUID applicationId) {
try {
http://git-wip-us.apache.org/repos/asf/usergrid/blob/6daba1d7/stack/services/src/main/java/org/apache/usergrid/services/ServiceManager.java
----------------------------------------------------------------------
diff --cc stack/services/src/main/java/org/apache/usergrid/services/ServiceManager.java
index 993bf35,a9892f5..e5ef407
--- a/stack/services/src/main/java/org/apache/usergrid/services/ServiceManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/ServiceManager.java
@@@ -17,32 -17,32 +17,29 @@@
package org.apache.usergrid.services;
--import java.lang.reflect.Modifier;
--import java.util.*;
--import java.util.concurrent.ExecutionException;
--import java.util.concurrent.TimeUnit;
--
--import org.slf4j.Logger;
--import org.slf4j.LoggerFactory;
--import org.springframework.context.ApplicationContext;
++import com.google.common.cache.CacheBuilder;
++import com.google.common.cache.CacheLoader;
++import com.google.common.cache.LoadingCache;
++import org.apache.commons.lang.StringUtils;
import org.apache.usergrid.batch.service.SchedulerService;
import org.apache.usergrid.locking.LockManager;
import org.apache.usergrid.mq.QueueManager;
import org.apache.usergrid.persistence.Entity;
import org.apache.usergrid.persistence.EntityManager;
import org.apache.usergrid.persistence.EntityRef;
--import org.apache.usergrid.persistence.cassandra.CassandraService;
import org.apache.usergrid.persistence.entities.Application;
import org.apache.usergrid.services.ServiceParameter.IdParameter;
import org.apache.usergrid.services.applications.ApplicationsService;
import org.apache.usergrid.services.exceptions.UndefinedServiceEntityTypeException;
import org.apache.usergrid.utils.ListUtils;
++import org.slf4j.Logger;
++import org.slf4j.LoggerFactory;
++import org.springframework.context.ApplicationContext;
--import org.apache.commons.lang.StringUtils;
--
--import com.google.common.cache.CacheBuilder;
--import com.google.common.cache.CacheLoader;
--import com.google.common.cache.LoadingCache;
++import java.lang.reflect.Modifier;
++import java.util.*;
++import java.util.concurrent.ExecutionException;
++import java.util.concurrent.TimeUnit;
import static org.apache.usergrid.persistence.SimpleEntityRef.ref;
import static org.apache.usergrid.utils.InflectionUtils.pluralize;