usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject [01/31] incubator-usergrid git commit: remove createindex calls
Date Mon, 09 Mar 2015 15:25:14 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-405 0c3b4395e -> b6351134e


remove createindex calls


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

Branch: refs/heads/USERGRID-405
Commit: 0c15e9b1241102e23ff9377aeaaf966ee49ed417
Parents: ccc884b
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Wed Mar 4 10:32:33 2015 -0700
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Wed Mar 4 10:32:33 2015 -0700

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java | 25 ++--------------
 .../cassandra/EntityManagerFactoryImplIT.java   |  1 +
 .../index/impl/EsEntityIndexImpl.java           | 31 +++++++++++++-------
 3 files changed, 23 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0c15e9b1/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index 9aa36a0..7a913b0 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -86,10 +86,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     /** Have we already initialized the index for the management app? */
     private AtomicBoolean indexInitialized = new AtomicBoolean(  );
 
-    /** Keep track of applications that already have indexes to avoid redundant re-creation.
*/
-    private static final Set<UUID> applicationIndexesCreated = new HashSet<UUID>();
-
-
     // cache of already instantiated entity managers
     private LoadingCache<UUID, EntityManager> entityManagers
         = CacheBuilder.newBuilder().maximumSize(100).build(new CacheLoader<UUID, EntityManager>()
{
@@ -156,18 +152,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory,
Application
     }
 
 
-//    public ManagerCache getManagerCache() {
-//
-//        if ( managerCache == null ) {
-//            managerCache = injector.getInstance( ManagerCache.class );
-//
-//            dataMigrationManager = injector.getInstance( DataMigrationManager.class );
-//        }
-//        return managerCache;
-//    }
-
-
-
     @Override
     public EntityManager getEntityManager(UUID applicationId) {
         try {
@@ -185,12 +169,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory,
Application
         EntityManager em = new CpEntityManager();
         em.init( this, applicationId );
 
-        // only need to do this once
-        if ( !applicationIndexesCreated.contains( applicationId ) ) {
-            em.createIndex();
-            applicationIndexesCreated.add( applicationId );
-        }
-
         return em;
     }
 
@@ -232,7 +210,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     public UUID initializeApplication( String organizationName, UUID applicationId, String
name,
                                        Map<String, Object> properties ) throws Exception
{
 
-
         EntityManager em = getEntityManager( CpNamingUtils.SYSTEM_APP_ID);
 
         final String appName = buildAppName( organizationName, name );
@@ -279,6 +256,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         }catch(DuplicateUniquePropertyExistsException e){
                        throw new ApplicationAlreadyExistsException( appName );
                    }
+        em.createIndex();
         em.refreshIndex();
 
         // create application entity
@@ -289,6 +267,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         EntityManager appEm = getEntityManager( applicationId );
 
         appEm.create( applicationId, TYPE_APPLICATION, properties );
+        appEm.createIndex();
         appEm.resetRoles();
         appEm.refreshIndex();
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0c15e9b1/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
index 9392d06..dea4967 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
@@ -52,6 +52,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
+@NotThreadSafe
 public class EntityManagerFactoryImplIT extends AbstractCoreIT {
 
     private static final Logger logger = LoggerFactory.getLogger( EntityManagerFactoryImplIT.class
);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0c15e9b1/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index 49026e2..eac3822 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -61,6 +61,7 @@ import org.elasticsearch.index.query.*;
 import org.elasticsearch.indices.IndexAlreadyExistsException;
 import org.elasticsearch.indices.IndexMissingException;
 import org.elasticsearch.indices.InvalidAliasNameException;
+import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesMissingException;
 import org.elasticsearch.search.SearchHit;
 import org.elasticsearch.search.SearchHits;
 import org.elasticsearch.search.sort.FieldSortBuilder;
@@ -192,11 +193,19 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
 
             String[] indexNames = getIndexes(AliasType.Write);
 
-            for (String currentIndex : indexNames){
-                isAck = adminClient.indices().prepareAliases().removeAlias(currentIndex,
+            for (String currentIndex : indexNames) {
+                try {
+                    isAck = adminClient.indices().prepareAliases().removeAlias(currentIndex,
                         alias.getWriteAlias()).execute().actionGet().isAcknowledged();
 
-                logger.info("Removed Index Name [{}] from Alias=[{}] ACK=[{}]", currentIndex,
alias, isAck);
+                    logger.info("Removed Index Name [{}] from Alias=[{}] ACK=[{}]", currentIndex,
alias, isAck);
+                } catch (AliasesMissingException aie) {
+                    logger.info("Alias does not exist Index Name [{}] from Alias=[{}] ACK=[{}]",
currentIndex, alias, aie.getMessage());
+                    continue;
+                }catch(InvalidAliasNameException iane) {
+                    logger.info("Alias does not exist Index Name [{}] from Alias=[{}] ACK=[{}]",
currentIndex, alias, iane.getMessage());
+                    continue;
+                }
             }
 
             // add read alias
@@ -218,7 +227,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
 
     @Override
     public String[] getIndexes(final AliasType aliasType) {
-        return aliasCache.getIndexes(alias,aliasType);
+        return aliasCache.getIndexes(alias, aliasType);
     }
 
 
@@ -270,7 +279,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
     private void createMappings() throws IOException {
 
         XContentBuilder xcb = IndexingUtils.createDoubleStringIndexMapping(
-                XContentFactory.jsonBuilder(), "_default_");
+            XContentFactory.jsonBuilder(), "_default_");
 
         PutIndexTemplateResponse pitr = esProvider.getClient().admin().indices()
                 .preparePutTemplate("usergrid_template")
@@ -299,7 +308,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
         final String context = IndexingUtils.createContextName(indexScope);
         final String[] entityTypes = searchTypes.getTypeNames();
 
-        QueryBuilder qb = query.createQueryBuilder( context );
+        QueryBuilder qb = query.createQueryBuilder(context);
 
 
         SearchResponse searchResponse;
@@ -410,7 +419,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
         final SearchHit[] hits = searchHits.getHits();
         final int length = hits.length;
 
-        logger.debug( "   Hit count: {} Total hits: {}", length, searchHits.getTotalHits()
);
+        logger.debug("   Hit count: {} Total hits: {}", length, searchHits.getTotalHits());
 
         List<CandidateResult> candidates = new ArrayList<>( length );
 
@@ -488,7 +497,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
         //since we don't have paging inputs, there's no point in executing a query for paging.
 
         final String context = IndexingUtils.createContextName(scope);
-        final SearchTypes searchTypes = SearchTypes.fromTypes( id.getType() );
+        final SearchTypes searchTypes = SearchTypes.fromTypes(id.getType());
 
         final QueryBuilder queryBuilder =
                 QueryBuilders.termQuery( IndexingUtils.ENTITY_CONTEXT_FIELDNAME, context
);
@@ -520,7 +529,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
 
         String idString = IndexingUtils.idString(entityId).toLowerCase();
 
-        final TermQueryBuilder tqb = QueryBuilders.termQuery( ENTITYID_ID_FIELDNAME, idString
);
+        final TermQueryBuilder tqb = QueryBuilders.termQuery(ENTITYID_ID_FIELDNAME, idString);
 
         final ListenableActionFuture<DeleteByQueryResponse> response = esProvider.getClient()
             .prepareDeleteByQuery( alias.getWriteAlias() ).setQuery( tqb ).execute();
@@ -528,10 +537,10 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
         response.addListener(new ActionListener<DeleteByQueryResponse>() {
             @Override
             public void onResponse(DeleteByQueryResponse response) {
-                logger.debug( "Deleted entity {}:{} from all index scopes with response status
= {}",
+                logger.debug("Deleted entity {}:{} from all index scopes with response status
= {}",
                     entityId.getType(), entityId.getUuid(), response.status().toString());
 
-                checkDeleteByQueryResponse( tqb, response );
+                checkDeleteByQueryResponse(tqb, response);
             }
 
             @Override


Mime
View raw message