usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdun...@apache.org
Subject usergrid git commit: Caching changes. Test fixes needed.
Date Mon, 11 Apr 2016 02:47:03 GMT
Repository: usergrid
Updated Branches:
  refs/heads/caching [created] f339fecb5


Caching changes. Test fixes needed.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/f339fecb
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/f339fecb
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/f339fecb

Branch: refs/heads/caching
Commit: f339fecb5455da89f9d3f379297de9cfe88a5d6d
Parents: 74de4bc
Author: Mike Dunker <mdunker@apigee.com>
Authored: Sun Apr 10 19:46:41 2016 -0700
Committer: Mike Dunker <mdunker@apigee.com>
Committed: Sun Apr 10 19:46:41 2016 -0700

----------------------------------------------------------------------
 .../org/apache/usergrid/rest/RootResource.java  |  16 +-
 .../organizations/OrganizationsResource.java    |   2 +-
 .../applications/ApplicationsResource.java      |   2 +-
 .../organizations/OrganizationResource.java     |   9 +-
 .../OAuth2AccessTokenSecurityFilter.java        |   2 +-
 .../usergrid/management/ManagementService.java  |   2 +
 .../cassandra/ManagementServiceImpl.java        | 290 ++++++++++++-------
 .../management/export/ExportServiceImpl.java    |   2 +-
 .../apache/usergrid/security/shiro/Realm.java   |  11 +
 9 files changed, 220 insertions(+), 116 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/f339fecb/stack/rest/src/main/java/org/apache/usergrid/rest/RootResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/RootResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/RootResource.java
index 75ed567..0147295 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/RootResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/RootResource.java
@@ -324,13 +324,17 @@ public class RootResource extends AbstractContextResource implements
MetricProce
 
             throws Exception {
 
-        UUID applicationId = UUID.fromString( applicationIdStr );
-        UUID organizationId = UUID.fromString( organizationIdStr );
-        if ( applicationId == null || organizationId == null ) {
-            return null;
+        UUID applicationId;
+        UUID organizationId;
+        try {
+            applicationId = UUID.fromString(applicationIdStr);
+            organizationId = UUID.fromString(organizationIdStr);
+            UUID appOrganizationId = management.getOrganizationIdForApplication(applicationId);
+            if ( organizationId != appOrganizationId ) {
+                return null;
+            }
         }
-        BiMap<UUID, String> apps = management.getApplicationsForOrganization( organizationId
);
-        if ( apps.get( applicationId ) == null ) {
+        catch (Exception e) {
             return null;
         }
         return appResourceFor( applicationId );

http://git-wip-us.apache.org/repos/asf/usergrid/blob/f339fecb/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationsResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationsResource.java
index 0348c01..c7db5df 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationsResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/OrganizationsResource.java
@@ -86,7 +86,7 @@ public class OrganizationsResource extends AbstractContextResource {
 
 
             Map<String, Object> jsonOrg = new HashMap<>();
-            Map<String, UUID> apps = management.getApplicationsForOrganization(org.getUuid()).inverse();
+            Map<String, UUID> apps = management.getApplicationsForOrganization(org.getUuid(),
true).inverse();
 
             jsonOrg.put("name", org.getName());
             jsonOrg.put("uuid", org.getUuid());

http://git-wip-us.apache.org/repos/asf/usergrid/blob/f339fecb/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
index 1b999ec..6b442eb 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
@@ -80,7 +80,7 @@ public class ApplicationsResource extends AbstractContextResource {
         ApiResponse response = createApiResponse();
         response.setAction( "get organization application" );
 
-        BiMap<UUID, String> applications = management.getApplicationsForOrganization(
organization.getUuid() );
+        BiMap<UUID, String> applications = management.getApplicationsForOrganization(
organization.getUuid(), true );
         response.setData( applications.inverse() );
 
         return response;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/f339fecb/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java
index 43867e3..08e8661 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java
@@ -101,8 +101,13 @@ public class OrganizationResource extends AbstractContextResource {
         // don't look up app if request is a PUT because a PUT can be used to restore a deleted
app
         if ( httpServletRequest.getMethod().equalsIgnoreCase("PUT") ) {
 
-            BiMap<UUID, String> apps = management.getApplicationsForOrganization(organizationId);
-            if (apps.get(applicationId) == null) {
+            try {
+                UUID appOrgId = management.getOrganizationIdForApplication(applicationId);
+                if (organizationId != appOrgId) {
+                    return null;
+                }
+            }
+            catch (Exception e) {
                 return null;
             }
         }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/f339fecb/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/OAuth2AccessTokenSecurityFilter.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/OAuth2AccessTokenSecurityFilter.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/OAuth2AccessTokenSecurityFilter.java
index 03da0e8..62f84d8 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/OAuth2AccessTokenSecurityFilter.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/OAuth2AccessTokenSecurityFilter.java
@@ -95,7 +95,7 @@ public class OAuth2AccessTokenSecurityFilter extends SecurityFilter implements
C
 
                 AuthPrincipalInfo principal = null;
                 try {
-                    // will update access time in principal if statements below, don't do
it here
+                    // will update access time in principal in statements below, don't do
it here
                     TokenInfo tokenInfo = tokens.getTokenInfo( accessToken, false );
                     principal = tokenInfo.getPrincipal();
                 } catch (BadTokenException e1) {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/f339fecb/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
index 1d74ec3..a57f5b5 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
@@ -179,6 +179,8 @@ public interface ManagementService {
 
 	BiMap<UUID, String> getApplicationsForOrganization( UUID organizationId ) throws Exception;
 
+	BiMap<UUID, String> getApplicationsForOrganization( UUID organizationId, boolean bypassCache
) throws Exception;
+
 	BiMap<UUID, String> getApplicationsForOrganizations( Set<UUID> organizationIds
) throws Exception;
 
 	String getClientIdForApplication( UUID applicationId );

http://git-wip-us.apache.org/repos/asf/usergrid/blob/f339fecb/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index 7b55c84..f35ae27 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -77,6 +77,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import rx.Observable;
 
+import javax.annotation.Nonnull;
 import java.nio.ByteBuffer;
 import java.util.*;
 import java.util.Map.Entry;
@@ -143,7 +144,17 @@ public class ManagementServiceImpl implements ManagementService {
     public static final String REGISTRATION_REQUIRES_EMAIL_CONFIRMATION = "registration_requires_email_confirmation";
     public static final String NOTIFY_ADMIN_OF_NEW_USERS = "notify_admin_of_new_users";
 
-    public static final String ORG_CONFIG_CACHE_PROP = "usergrid.orgconfig.cache.timeout";
+    protected static final String ORG_CONFIG_CACHE_TIMEOUT = "usergrid.orgconfig.cache_timeout";
+    protected static final String ORG_CONFIG_CACHE_SIZE = "usergrid.orgconfig.cache_size";
+
+    protected static final String ORG_ENTITY_FOR_APP_CACHE_TIMEOUT = "usergrid.org.cache_timeout";
+    protected static final String ORG_ENTITY_FOR_APP_CACHE_SIZE = "usergrid.org.cache_size";
+
+    protected static final String APPS_FOR_ORG_CACHE_TIMEOUT = "usergrid.apps_for_org.cache_timeout";
+    protected static final String APPS_FOR_ORG_CACHE_SIZE = "usergrid.apps_for_org.cache_size";
+
+    protected static final String MAX_ORGS = "usergrid.orgs.max";
+    protected static final String ORGS_LIST_TIMEOUT_SECS = "usergrid.orgs_list.timeout_secs";
 
     protected ServiceManagerFactory smf;
 
@@ -192,11 +203,134 @@ public class ManagementServiceImpl implements ManagementService {
         this.emf = emf;
     }
 
-
+    private LoadingCache<UUID, OrganizationConfig> orgConfigByUUIDCache = null;
+    private LoadingCache<UUID, Entity> orgEntityForAppCache = null;
+    private LoadingCache<String, List<OrganizationInfo>> allOrgsListCache = null;
+    private LoadingCache<UUID, BiMap<UUID, String>> appsForOrgCache = null;
     @Autowired
     public void setProperties( Properties properties ) {
         this.properties = new AccountCreationPropsImpl( properties );
         this.orgConfigProperties = new OrganizationConfigPropsImpl( properties );
+        orgConfigByUUIDCache = CacheBuilder.newBuilder().maximumSize( Long.valueOf( properties.getProperty(ORG_CONFIG_CACHE_SIZE,
"1000")) )
+                .expireAfterWrite( Long.valueOf( properties.getProperty(ORG_CONFIG_CACHE_TIMEOUT,
"30000") ), TimeUnit.MILLISECONDS)
+                .build( new CacheLoader<UUID, OrganizationConfig>() {
+                    public OrganizationConfig load(@Nonnull UUID id) {
+
+                        try {
+                            EntityManager em = emf.getEntityManager(smf.getManagementAppId());
+                            Entity entity = em.get(new SimpleEntityRef(Group.ENTITY_TYPE,
id));
+                            if (entity == null) {
+                                return getOrganizationConfigDefaultsOnly();
+                            }
+                            Map<Object, Object> entityProperties = em.getDictionaryAsMap(entity,
ORGANIZATION_CONFIG_DICTIONARY);
+                            return new OrganizationConfig(orgConfigProperties,
+                                    (UUID) entity.getProperty(PROPERTY_UUID),
+                                    (String) entity.getProperty(PROPERTY_PATH),
+                                    entityProperties, false);
+                        } catch (Exception e) {
+                            return getOrganizationConfigDefaultsOnly();
+                        }
+                    }
+                });
+        orgEntityForAppCache = CacheBuilder.newBuilder().maximumSize( Long.valueOf( properties.getProperty(ORG_ENTITY_FOR_APP_CACHE_SIZE,
"1000")) )
+                .expireAfterWrite( Long.valueOf( System.getProperty(ORG_ENTITY_FOR_APP_CACHE_TIMEOUT,
"30000") ), TimeUnit.MILLISECONDS)
+                .build( new CacheLoader<UUID, Entity>() {
+                    public Entity load( @Nonnull UUID applicationInfoId ) {
+                        try {
+                            final EntityManager em = emf.getEntityManager(smf.getManagementAppId());
+
+                            Results r = em.getSourceEntities(
+                                    new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationInfoId),
+                                    ORG_APP_RELATIONSHIP, Group.ENTITY_TYPE, Level.ALL_PROPERTIES);
+
+                            return r.getEntity();
+                        }
+                        catch (Exception e) {
+                            return null;
+                        }
+                    }
+                });
+        // singleton cache allows for easy clearing of cache, unlike Guava's Supplier memoization
+        allOrgsListCache = CacheBuilder.newBuilder().maximumSize(1)
+                .expireAfterWrite( Long.valueOf(properties.getProperty(ORGS_LIST_TIMEOUT_SECS,
"60")), TimeUnit.SECONDS)
+                .build( new CacheLoader<String, List<OrganizationInfo>>() {
+                    public List<OrganizationInfo> load( @Nonnull String ignoredKey
) {
+                        try {
+                            int numOrgs = Integer.valueOf(properties.getProperty(MAX_ORGS,
"10000"));
+                            // still need the bimap to search for existing
+                            BiMap<UUID, String> organizations = HashBiMap.create();
+                            EntityManager em = emf.getEntityManager(smf.getManagementAppId());
+                            Results results = em.getCollection(em.getApplicationRef(),
+                                    Schema.COLLECTION_GROUPS, null, numOrgs, Level.ALL_PROPERTIES,
false);
+                            List<OrganizationInfo> orgs = new ArrayList<>(results.size());
+                            OrganizationInfo orgInfo;
+                            for (Entity entity : results.getEntities()) {
+                                // TODO T.N. temporary hack to deal with duplicate orgs.
Revert this
+                                // commit after migration
+                                String path = (String) entity.getProperty(PROPERTY_PATH);
+
+                                if (organizations.containsValue(path)) {
+                                    path += "DUPLICATE";
+                                }
+                                orgInfo = new OrganizationInfo(entity.getUuid(), path);
+                                orgs.add(orgInfo);
+                                organizations.put(entity.getUuid(), path);
+                            }
+                            return orgs;
+                        }
+                        catch (Exception e) {
+                            // shouldn't have failed
+                            logger.error("Failed to retrieve list of orgs -- broke orgs list
cache");
+                            return new ArrayList<>();
+                        }
+                    }
+                });
+
+        appsForOrgCache = CacheBuilder.newBuilder().maximumSize( Long.valueOf( properties.getProperty(APPS_FOR_ORG_CACHE_SIZE,
"1000")) )
+                .expireAfterWrite( Long.valueOf( System.getProperty(APPS_FOR_ORG_CACHE_TIMEOUT,
"5000") ), TimeUnit.MILLISECONDS)
+                .build( new CacheLoader<UUID, BiMap<UUID, String>>() {
+                    public BiMap<UUID, String> load( @Nonnull UUID organizationGroupId
) {
+                        try {
+                            final BiMap<UUID, String> applications = HashBiMap.create();
+                            final EntityManager em = emf.getEntityManager(smf.getManagementAppId());
+
+                            // query for application_info entities
+                            final Results results = em.getTargetEntities(
+                                    new SimpleEntityRef(Group.ENTITY_TYPE, organizationGroupId),
+                                    ORG_APP_RELATIONSHIP, CpNamingUtils.APPLICATION_INFO,
Level.ALL_PROPERTIES);
+
+                            final PagingResultsIterator itr = new PagingResultsIterator(results);
+
+                            String entityName;
+
+                            while (itr.hasNext()) {
+
+                                final Entity entity = (Entity) itr.next();
+
+                                entityName = entity.getName();
+
+                                if (entityName != null) {
+                                    entityName = entityName.toLowerCase();
+                                }
+
+                                // make sure we return applicationId and not the application_info
UUID
+                                UUID applicationId = entity.getUuid();
+
+                                applications.put(applicationId, entityName);
+                            }
+
+
+                            return applications;
+                        }
+                        catch (Exception e) {
+                            // probably shouldn't have failed, log
+                            logger.info("Failed to retrieve list of apps for org {} for cache",
organizationGroupId);
+                            // return empty list
+                            return HashBiMap.create();
+                        }
+                    }
+                });
+
     }
 
     String orgSysAdminEmail,defaultSysAdminEmail;
@@ -312,7 +446,7 @@ public class ManagementServiceImpl implements ManagementService {
                 organization = created.getOrganization();
             }
 
-            if ( !getApplicationsForOrganization( organization.getUuid() ).containsValue(
test_app_name ) ) {
+            if ( !getApplicationsForOrganization( organization.getUuid(), true ).containsValue(
test_app_name ) ) {
                 try {
                     createApplication( organization.getUuid(), test_app_name );
                 }catch(ApplicationAlreadyExistsException aaee){
@@ -602,8 +736,8 @@ public class ManagementServiceImpl implements ManagementService {
             startOrganizationActivationFlow( organization );
         }
 
-
-
+        // reset orgs list cache
+        allOrgsListCache.invalidateAll();
         return organization;
     }
 
@@ -731,26 +865,17 @@ public class ManagementServiceImpl implements ManagementService {
 
     @Override
     public List<OrganizationInfo> getOrganizations( UUID startResult, int count ) throws
Exception {
-        // still need the bimap to search for existing
-        BiMap<UUID, String> organizations = HashBiMap.create();
-        EntityManager em = emf.getEntityManager(smf.getManagementAppId());
-        Results results = em.getCollection(em.getApplicationRef(),
-            Schema.COLLECTION_GROUPS, startResult, count, Level.ALL_PROPERTIES, false);
-        List<OrganizationInfo> orgs = new ArrayList<>( results.size() );
-        OrganizationInfo orgInfo;
-        for ( Entity entity : results.getEntities() ) {
-            // TODO T.N. temporary hack to deal with duplicate orgs. Revert this
-            // commit after migration
-            String path = ( String ) entity.getProperty( PROPERTY_PATH );
-
-            if ( organizations.containsValue( path ) ) {
-                path += "DUPLICATE";
-            }
-            orgInfo = new OrganizationInfo( entity.getUuid(), path );
-            orgs.add( orgInfo );
-            organizations.put( entity.getUuid(), path );
+        // always use hardcoded value -- singleton cache
+        List<OrganizationInfo> orgs = allOrgsListCache.get("orgs");
+        if (startResult != null) {
+            long startResultTimestamp = startResult.timestamp();
+            orgs.removeIf(o -> o.getUuid().timestamp() <= startResultTimestamp);
+        }
+        if (count < orgs.size()) {
+            return orgs.subList(0, count);
+        } else {
+            return orgs;
         }
-        return orgs;
     }
 
 
@@ -1643,7 +1768,7 @@ public class ManagementServiceImpl implements ManagementService {
         Map<String, Object> jsonOrganization = new HashMap<>();
         jsonOrganization.putAll( JsonUtils.toJsonMap( organization ) );
 
-        BiMap<UUID, String> applications = getApplicationsForOrganization( organization.getUuid()
);
+        BiMap<UUID, String> applications = getApplicationsForOrganization( organization.getUuid(),
true );
         jsonOrganization.put( "applications", applications.inverse() );
 
         List<UserInfo> users = getAdminUsersForOrganization( organization.getUuid()
);
@@ -1867,17 +1992,9 @@ public class ManagementServiceImpl implements ManagementService {
 
 
     protected Entity getOrganizationEntityForApplication( UUID applicationInfoId ) throws
Exception {
-        if ( applicationInfoId == null ) {
-            return null;
-        }
-
-        final EntityManager em = emf.getEntityManager(smf.getManagementAppId());
 
-        Results r = em.getSourceEntities(
-                new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationInfoId),
-                ORG_APP_RELATIONSHIP, Group.ENTITY_TYPE, Level.ALL_PROPERTIES);
+        return applicationInfoId != null ? orgEntityForAppCache.get(applicationInfoId) :
null;
 
-        return r.getEntity();
     }
 
     @Override
@@ -1900,41 +2017,23 @@ public class ManagementServiceImpl implements ManagementService {
 
 
     @Override
-    public BiMap<UUID, String> getApplicationsForOrganization( UUID organizationGroupId
) throws Exception {
+    public BiMap<UUID, String> getApplicationsForOrganization( UUID organizationGroupId
)
+            throws Exception {
+        return getApplicationsForOrganization(organizationGroupId, false);
+    }
+
+
+    @Override
+    public BiMap<UUID, String> getApplicationsForOrganization( UUID organizationGroupId,
boolean bypassCache )
+            throws Exception {
 
         if ( organizationGroupId == null ) {
             return null;
         }
-        final BiMap<UUID, String> applications = HashBiMap.create();
-        final EntityManager em = emf.getEntityManager(smf.getManagementAppId());
-
-        // query for application_info entities
-        final Results results = em.getTargetEntities(
-            new SimpleEntityRef(Group.ENTITY_TYPE, organizationGroupId),
-            ORG_APP_RELATIONSHIP, CpNamingUtils.APPLICATION_INFO, Level.ALL_PROPERTIES);
-
-        final PagingResultsIterator itr = new PagingResultsIterator( results );
-
-        String entityName;
-
-        while ( itr.hasNext() ) {
-
-            final Entity entity = ( Entity ) itr.next();
-
-            entityName = entity.getName();
-
-            if ( entityName != null ) {
-                entityName = entityName.toLowerCase();
-            }
-
-            // make sure we return applicationId and not the application_info UUID
-            UUID applicationId = entity.getUuid();
-
-            applications.put( applicationId, entityName );
+        if (bypassCache) {
+            appsForOrgCache.invalidate(organizationGroupId);
         }
-
-
-        return applications;
+        return appsForOrgCache.get(organizationGroupId);
     }
 
 
@@ -3344,16 +3443,8 @@ public class ManagementServiceImpl implements ManagementService {
     @Override
     public OrganizationConfig getOrganizationConfigByUuid( UUID id ) throws Exception {
 
-        EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
-        Entity entity = em.get( new SimpleEntityRef( Group.ENTITY_TYPE, id ) );
-        if ( entity == null ) {
-            return getOrganizationConfigDefaultsOnly();
-        }
-        Map<Object, Object> entityProperties = em.getDictionaryAsMap(entity, ORGANIZATION_CONFIG_DICTIONARY);
-        return new OrganizationConfig( orgConfigProperties,
-                (UUID)entity.getProperty(PROPERTY_UUID),
-                (String)entity.getProperty(PROPERTY_PATH),
-                entityProperties, false);
+        return id != null ? orgConfigByUUIDCache.get(id) : getOrganizationConfigDefaultsOnly();
+
     }
 
 
@@ -3396,8 +3487,8 @@ public class ManagementServiceImpl implements ManagementService {
     @Override
     public OrganizationConfig getOrganizationConfigForApplication( UUID applicationInfoId
) throws Exception {
 
-        // return from the cache. if the orgconfig cannot be loaded, defaults are loaded
and cached
-        return orgConfigByAppCache.get( applicationInfoId );
+        return getOrganizationConfigByUuid( getOrganizationIdForApplication( applicationInfoId
) );
+
     }
 
 
@@ -3418,45 +3509,36 @@ public class ManagementServiceImpl implements ManagementService {
             }
 
             // evict cache for this key if it exists
-            orgConfigByAppCache.invalidate( organizationConfig.getUuid() );
+            orgConfigByUUIDCache.invalidate( organizationConfig.getUuid() );
 
         }
     }
 
 
-    private LoadingCache<UUID, OrganizationConfig> orgConfigByAppCache =
+    // need to invalidate when org config is changed
+/*    private LoadingCache<UUID, OrganizationConfig> orgConfigByUUIDCache =
         CacheBuilder.newBuilder().maximumSize( 1000 )
-            .expireAfterWrite( Long.valueOf( System.getProperty(ORG_CONFIG_CACHE_PROP, "30000")
) , TimeUnit.MILLISECONDS)
+            .expireAfterWrite( Long.valueOf( System.getProperty(ORG_CONFIG_CACHE_TIMEOUT,
"30000") ), TimeUnit.MILLISECONDS)
             .build( new CacheLoader<UUID, OrganizationConfig>() {
-                public OrganizationConfig load( UUID applicationInfoId ) {
+                public OrganizationConfig load( @Nonnull UUID id ) {
 
                     try {
-
-                        if (applicationInfoId != null && applicationInfoId != CpNamingUtils.MANAGEMENT_APPLICATION_ID)
{
-
-                            final EntityManager em = emf.getEntityManager(smf.getManagementAppId());
-
-                            Results r = em.getSourceEntities(
-                                new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationInfoId),
-                                ORG_APP_RELATIONSHIP, Group.ENTITY_TYPE, Level.ALL_PROPERTIES);
-
-                            Group org = (Group) r.getEntity();
-
-                            if (org != null) {
-                                Map<Object, Object> entityProperties = em.getDictionaryAsMap(org,
ORGANIZATION_CONFIG_DICTIONARY);
-                                return new OrganizationConfig(orgConfigProperties, org.getUuid(),
org.getPath(), entityProperties, false);
-                            }
-
+                        EntityManager em = emf.getEntityManager(smf.getManagementAppId());
+                        Entity entity = em.get(new SimpleEntityRef(Group.ENTITY_TYPE, id));
+                        if (entity == null) {
+                            return getOrganizationConfigDefaultsOnly();
                         }
-
-                        return new OrganizationConfig(orgConfigProperties);
-
-                    }catch (Exception e){
-
-                        return new OrganizationConfig(orgConfigProperties);
-
+                        Map<Object, Object> entityProperties = em.getDictionaryAsMap(entity,
ORGANIZATION_CONFIG_DICTIONARY);
+                        return new OrganizationConfig(orgConfigProperties,
+                                (UUID) entity.getProperty(PROPERTY_UUID),
+                                (String) entity.getProperty(PROPERTY_PATH),
+                                entityProperties, false);
+                    }
+                    catch (Exception e) {
+                        return getOrganizationConfigDefaultsOnly();
                     }
                 }}
-            );
+            );*/
 
+    // need to invalidate if org entity changes
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/f339fecb/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
b/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
index eadc925..e45820a 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
@@ -330,7 +330,7 @@ public class ExportServiceImpl implements ExportService {
         Export export = getExportEntity( jobExecution );
         String appFileName = null;
 
-        BiMap<UUID, String> applications = managementService.getApplicationsForOrganization(
organizationUUID );
+        BiMap<UUID, String> applications = managementService.getApplicationsForOrganization(
organizationUUID, true);
 
         for ( Map.Entry<UUID, String> application : applications.entrySet() ) {
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/f339fecb/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java b/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java
index 4381f01..302ae11 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java
@@ -37,8 +37,11 @@ import org.apache.usergrid.security.tokens.TokenService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.beans.factory.annotation.Value;
 
+import java.util.Properties;
+
 import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_ALLOWED;
 
 
@@ -54,6 +57,7 @@ public class Realm extends AuthorizingRealm {
     private EntityManagerFactory emf;
     private ManagementService management;
     private TokenService tokens;
+    private Properties properties;
 
 
     @Value( "${" + PROPERTIES_SYSADMIN_LOGIN_ALLOWED + "}" )
@@ -128,6 +132,13 @@ public class Realm extends AuthorizingRealm {
         this.management = management;
     }
 
+    @Autowired
+    @Qualifier("properties")
+    public void setProperties( Properties properties ) {
+        this.properties = properties;
+    }
+
+
 
     @Autowired
     public void setTokenService( TokenService tokens ) {


Mime
View raw message