You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2015/01/26 15:24:22 UTC

[23/23] incubator-usergrid git commit: Merge branch 'two-dot-o' into two-dot-o-import

Merge branch 'two-dot-o' into two-dot-o-import

Conflicts:
	stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java


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

Branch: refs/heads/two-dot-o-import
Commit: 1c9c1f43d7e15b1551028461b3887cbec870e60e
Parents: 32484cb 6dc62ed
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Jan 23 11:56:28 2015 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Jan 23 11:56:28 2015 -0500

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java | 56 ++++++++---
 .../HybridEntityManagerFactory.java             |  9 +-
 .../persistence/EntityManagerFactory.java       | 11 ++-
 .../cassandra/EntityManagerFactoryImpl.java     | 11 ++-
 .../cassandra/EntityManagerFactoryImplIT.java   | 71 +++++++++-----
 .../usergrid/persistence/index/EntityIndex.java |  2 +
 .../index/impl/EsEntityIndexBatchImpl.java      | 14 +--
 .../index/impl/EsEntityIndexImpl.java           | 99 ++++++++++----------
 .../persistence/index/impl/EsIndexCache.java    | 12 ++-
 .../rest/applications/ApplicationResource.java  | 32 +++++--
 .../applications/ApplicationDeleteTest.java     | 54 +++++++++++
 .../collection/groups/GroupResourceIT.java      |  2 +-
 12 files changed, 257 insertions(+), 116 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1c9c1f43/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --cc stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index 988c5b5,9e9cebf..a78188a
--- 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
@@@ -187,22 -187,23 +188,23 @@@ public class EsEntityIndexImpl implemen
                  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);
              }
  
-             //add read alias
+             // add read alias
              isAck = adminClient.indices().prepareAliases().addAlias(
                      indexName, alias.getReadAlias()).execute().actionGet().isAcknowledged();
-             logger.info("Created new read Alias Name [{}] ACK=[{}]", alias, isAck);
+             logger.info("Created new read Alias Name [{}] ACK=[{}]", alias.getReadAlias(), isAck);
 -            
 +
-             //add write alias
+             // add write alias
              isAck = adminClient.indices().prepareAliases().addAlias(
                      indexName, alias.getWriteAlias()).execute().actionGet().isAcknowledged();
-             logger.info("Created new write Alias Name [{}] ACK=[{}]", alias, isAck);
+             logger.info("Created new write Alias Name [{}] ACK=[{}]", alias.getWriteAlias(), isAck);
 -            
++
              aliasCache.invalidate(alias);
--            
 -        } catch (Exception e) {
 -            logger.warn("Failed to create alias ", e);
++
 +        } catch (InvalidAliasNameException e) {
 +            logger.warn("Failed to create alias: " + e.getDetailedMessage());
          }
      }
  
@@@ -231,18 -232,19 +233,19 @@@
                  final String tempId = UUIDGenerator.newTimeUUID().toString();
  
                  esProvider.getClient().prepareIndex( alias.getWriteAlias(), VERIFY_TYPE, tempId )
-                         .setSource(DEFAULT_PAYLOAD).get();
+                      .setSource(DEFAULT_PAYLOAD).get();
  
                  logger.info( "Successfully created new document with docId {} "
-                         + "in index {} and type {}", tempId, alias, VERIFY_TYPE );
 -                     + "in index read {} write {} and type {}", 
++                     + "in index read {} write {} and type {}",
+                         tempId, alias.getReadAlias(), alias.getWriteAlias(), VERIFY_TYPE );
  
                  // delete all types, this way if we miss one it will get cleaned up
-                 esProvider.getClient().prepareDeleteByQuery( alias.getWriteAlias() )
-                         .setTypes(VERIFY_TYPE) 
+                 esProvider.getClient().prepareDeleteByQuery( alias.getWriteAlias())
+                         .setTypes(VERIFY_TYPE)
                          .setQuery(MATCH_ALL_QUERY_BUILDER).get();
  
-                 logger.info( "Successfully deleted all documents in index {} and type {}", 
-                         alias, VERIFY_TYPE );
+                 logger.info( "Successfully deleted all documents in index {} read {} write {} and type {}",
+                         alias.getReadAlias(), alias.getWriteAlias(), VERIFY_TYPE );
  
                  return true;
              }
@@@ -253,7 -255,7 +256,7 @@@
  
  
      /**
--     * Setup ElasticSearch type mappings as a template that applies to all new indexes. 
++     * Setup ElasticSearch type mappings as a template that applies to all new indexes.
       * Applies to all indexes that* start with our prefix.
       */
      private void createMappings() throws IOException {
@@@ -275,13 -277,13 +278,13 @@@
  
      @Override
      public EntityIndexBatch createBatch() {
--        return new EsEntityIndexBatchImpl( 
++        return new EsEntityIndexBatchImpl(
                  applicationScope, esProvider.getClient(), config, 1000, failureMonitor, this );
      }
  
  
      @Override
--    public CandidateResults search( final IndexScope indexScope, final SearchTypes searchTypes, 
++    public CandidateResults search( final IndexScope indexScope, final SearchTypes searchTypes,
              final Query query ) {
  
          final String context = IndexingUtils.createContextName(indexScope);
@@@ -320,8 -322,8 +323,8 @@@
                  }
  
                  // we do not know the type of the "order by" property and so we do not know what
--                // type prefix to use. So, here we add an order by clause for every possible type 
--                // that you can order by: string, number and boolean and we ask ElasticSearch 
++                // type prefix to use. So, here we add an order by clause for every possible type
++                // that you can order by: string, number and boolean and we ask ElasticSearch
                  // to ignore any fields that are not present.
  
                  final String stringFieldName = STRING_PREFIX + sp.getPropertyName();
@@@ -432,17 -433,14 +434,14 @@@
              @Override
              public boolean doOp() {
                  try {
-                     String[]  indexes = getIndexes(AliasType.Read);
-                     Observable.from(indexes).map(new Func1<String, String>() {
-                         @Override
-                         public String call(String index) {
-                             esProvider.getClient().admin().indices().prepareRefresh( index ).execute().actionGet();
-                             return index;
-                         }
-                     }).toBlocking().last();
- 
-                     logger.debug( "Refreshed index: " + alias);
- 
+                     String[] indexes = ArrayUtils.addAll( getIndexes(AliasType.Write), getIndexes(AliasType.Write) );
+                     if ( indexes.length == 0 ) {
 -                        logger.debug( "Not refreshing indexes, none found for app {}", 
++                        logger.debug( "Not refreshing indexes, none found for app {}",
+                                 applicationScope.getApplication().getUuid() );
+                         return true;
+                     }
+                     esProvider.getClient().admin().indices().prepareRefresh( indexes ).execute().actionGet();
+                     logger.debug("Refreshed indexes: {}", StringUtils.join(indexes, ", "));
                      return true;
                  }
                  catch ( IndexMissingException e ) {
@@@ -476,7 -472,7 +473,7 @@@
          final String context = IndexingUtils.createContextName(scope);
          final SearchTypes searchTypes = SearchTypes.fromTypes( id.getType() );
  
--        final QueryBuilder queryBuilder = 
++        final QueryBuilder queryBuilder =
                  QueryBuilders.termQuery( IndexingUtils.ENTITY_CONTEXT_FIELDNAME, context );
  
          final SearchRequestBuilder srb = esProvider.getClient().prepareSearch( alias.getReadAlias() )
@@@ -523,11 -519,11 +520,11 @@@
      @Override
      public void deletePreviousVersions( final Id entityId, final UUID version ) {
  
--        String idString = IndexingUtils.idString( entityId ).toLowerCase(); 
++        String idString = IndexingUtils.idString( entityId ).toLowerCase();
  
          final FilteredQueryBuilder fqb = QueryBuilders.filteredQuery(
-             QueryBuilders.termQuery( ENTITYID_ID_FIELDNAME, idString ),
-             FilterBuilders.rangeFilter( ENTITY_VERSION_FIELDNAME ).lt( version.timestamp() ) 
+                 QueryBuilders.termQuery(ENTITYID_ID_FIELDNAME, idString),
+                 FilterBuilders.rangeFilter(ENTITY_VERSION_FIELDNAME).lt(version.timestamp())
          );
  
          final DeleteByQueryResponse response = esProvider.getClient()
@@@ -545,18 -541,18 +542,18 @@@
      /**
       * Validate the response doesn't contain errors, if it does, fail fast at the first error we encounter
       */
--    private void checkDeleteByQueryResponse( 
++    private void checkDeleteByQueryResponse(
              final QueryBuilder query, final DeleteByQueryResponse response ) {
  
          for ( IndexDeleteByQueryResponse indexDeleteByQueryResponse : response ) {
              final ShardOperationFailedException[] failures = indexDeleteByQueryResponse.getFailures();
  
              for ( ShardOperationFailedException failedException : failures ) {
-                 throw new IndexException( String.format("Unable to delete by query %s.  "
+                 throw new IndexException( String.format("Unable to delete by query %s. "
                          + "Failed with code %d and reason %s on shard %s in index %s",
--                    query.toString(), 
-                     failedException.status(), 
-                     failedException.reason(), 
++                    query.toString(),
+                     failedException.status().getStatus(),
 -                    failedException.reason(), 
++                    failedException.reason(),
                      failedException.shardId(),
                      failedException.index() ) );
              }