usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject [11/41] incubator-usergrid git commit: Fix broken tests that could not be run multiple times without deleting all data from C* and ES after each run.
Date Wed, 10 Dec 2014 17:14:00 GMT
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/26774448/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImpl.java
b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImpl.java
index b9cc851..a9719b7 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImpl.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImpl.java
@@ -65,7 +65,9 @@ public class DataMigrationManagerImpl implements DataMigrationManager {
     @Inject
     public DataMigrationManagerImpl( final MigrationInfoSerialization migrationInfoSerialization,
                                      final Set<DataMigration> migrations ) {
-        Preconditions.checkNotNull( migrationInfoSerialization, "migrationInfoSerialization
must not be null" );
+
+        Preconditions.checkNotNull( migrationInfoSerialization, 
+                "migrationInfoSerialization must not be null" );
         Preconditions.checkNotNull( migrations, "migrations must not be null" );
 
         this.migrationInfoSerialization = migrationInfoSerialization;
@@ -87,9 +89,9 @@ public class DataMigrationManagerImpl implements DataMigrationManager {
                 final Class<? extends DataMigration> currentClass = migration.getClass();
 
 
-                throw new DataMigrationException(
-                        String.format( "Data migrations must be unique.  Both classes %s
and %s have version %d",
-                                existingClass, currentClass, version ) );
+                throw new DataMigrationException( String.format( 
+                        "Data migrations must be unique.  Both classes %s and %s have version
%d", 
+                        existingClass, currentClass, version ) );
             }
 
             migrationTreeMap.put( version, migration );
@@ -112,7 +114,8 @@ public class DataMigrationManagerImpl implements DataMigrationManager
{
                 migrationTreeMap.lastKey() );
 
         //we have our migrations to run, execute them
-        final NavigableMap<Integer, DataMigration> migrationsToRun = migrationTreeMap.tailMap(
currentVersion, false );
+        final NavigableMap<Integer, DataMigration> migrationsToRun = 
+                migrationTreeMap.tailMap( currentVersion, false );
 
         CassandraProgressObserver observer = new CassandraProgressObserver();
 
@@ -185,7 +188,8 @@ public class DataMigrationManagerImpl implements DataMigrationManager
{
     public void resetToVersion( final int version ) {
         final int highestAllowed = migrationTreeMap.lastKey();
 
-        Preconditions.checkArgument( version <= highestAllowed, "You cannot set a version
higher than the max of " + highestAllowed);
+        Preconditions.checkArgument( version <= highestAllowed, 
+                "You cannot set a version higher than the max of " + highestAllowed);
         Preconditions.checkArgument( version >= 0, "You must specify a version of 0 or
greater" );
 
         migrationInfoSerialization.setVersion( version );
@@ -221,7 +225,8 @@ public class DataMigrationManagerImpl implements DataMigrationManager
{
         @Override
         public void failed( final int migrationVersion, final String reason ) {
 
-            final String storedMessage = String.format( "Failed to migrate, reason is appended.
 Error '%s'", reason );
+            final String storedMessage = String.format( 
+                    "Failed to migrate, reason is appended.  Error '%s'", reason );
 
 
             update( migrationVersion, storedMessage );
@@ -240,13 +245,14 @@ public class DataMigrationManagerImpl implements DataMigrationManager
{
             throwable.printStackTrace( new PrintWriter( stackTrace ) );
 
 
-            final String storedMessage = String.format( "Failed to migrate, reason is appended.
 Error '%s' %s", reason,
-                    stackTrace.toString() );
+            final String storedMessage = String.format( 
+                "Failed to migrate, reason is appended.  Error '%s' %s", reason, stackTrace.toString()
);
 
             update( migrationVersion, storedMessage );
 
 
-            LOG.error( "Unable to migrate version {} due to reason {}.", migrationVersion,
reason, throwable );
+            LOG.error( "Unable to migrate version {} due to reason {}.", 
+                    migrationVersion, reason, throwable );
 
             failed = true;
 
@@ -256,7 +262,8 @@ public class DataMigrationManagerImpl implements DataMigrationManager
{
 
         @Override
         public void update( final int migrationVersion, final String message ) {
-            final String formattedOutput = String.format( "Migration version %d.  %s", migrationVersion,
message );
+            final String formattedOutput = String.format( 
+                    "Migration version %d.  %s", migrationVersion, message );
 
             //Print this to the info log
             LOG.info( formattedOutput );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/26774448/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
index 86b5611..f23dc36 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
@@ -85,4 +85,8 @@ public class IndexIdentifier{
         }
     }
 
+    public String toString() {
+        return "application: " + applicationScope.getApplication().getUuid();
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/26774448/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 d546092..eb050d6 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
@@ -21,7 +21,6 @@ package org.apache.usergrid.persistence.index.impl;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 import java.util.UUID;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -120,7 +119,9 @@ public class EsEntityIndexImpl implements EntityIndex {
 
 
     @Inject
-    public EsEntityIndexImpl( @Assisted final ApplicationScope appScope, final IndexFig config,
final EsProvider provider ) {
+    public EsEntityIndexImpl( @Assisted final ApplicationScope appScope, final IndexFig config,

+            final EsProvider provider ) {
+
         ValidationUtils.validateApplicationScope( appScope );
         this.applicationScope = appScope;
         this.esProvider = provider;
@@ -153,9 +154,14 @@ public class EsEntityIndexImpl implements EntityIndex {
             //Create index
             try {
                 final AdminClient admin = esProvider.getClient().admin();
-                Settings settings = ImmutableSettings.settingsBuilder().put("index.number_of_shards",
numberOfShards)
-                        .put("index.number_of_replicas", numberOfReplicas).build();
-                final CreateIndexResponse cir = admin.indices().prepareCreate(indexName).setSettings(settings).execute().actionGet();
+                Settings settings = ImmutableSettings.settingsBuilder()
+                        .put("index.number_of_shards", numberOfShards)
+                        .put("index.number_of_replicas", numberOfReplicas)
+                        .build();
+                final CreateIndexResponse cir = admin.indices().prepareCreate(indexName)
+                        .setSettings(settings)
+                        .execute()
+                        .actionGet();
                 logger.info("Created new Index Name [{}] ACK=[{}]", indexName, cir.isAcknowledged());
             } catch (IndexAlreadyExistsException e) {
                 logger.info("Index Name [{}] already exists", indexName);
@@ -178,19 +184,27 @@ public class EsEntityIndexImpl implements EntityIndex {
             Boolean isAck;
             String indexName = indexIdentifier.getIndex(indexSuffix);
             final AdminClient adminClient = esProvider.getClient().admin();
+
             //remove write alias, can only have one
-            ImmutableOpenMap<String,List<AliasMetaData>> aliasMap = adminClient.indices().getAliases(new
GetAliasesRequest(alias.getWriteAlias())).actionGet().getAliases();
+            ImmutableOpenMap<String,List<AliasMetaData>> aliasMap = adminClient.indices()
+                    .getAliases(new GetAliasesRequest(alias.getWriteAlias())).actionGet().getAliases();
             String[] indexNames = aliasMap.keys().toArray(String.class);
+
             for(String currentIndex : indexNames){
-                isAck = adminClient.indices().prepareAliases().removeAlias(currentIndex,alias.getWriteAlias()).execute().actionGet().isAcknowledged();
-                logger.info("Removed Index Name [{}] from Alias=[{}] ACK=[{}]",currentIndex,
alias, isAck);
+                isAck = adminClient.indices().prepareAliases().removeAlias(currentIndex,
+                        alias.getWriteAlias()).execute().actionGet().isAcknowledged();
 
+                logger.info("Removed Index Name [{}] from Alias=[{}] ACK=[{}]",currentIndex,
alias, isAck);
             }
+
             //add read alias
-            isAck = adminClient.indices().prepareAliases().addAlias(indexName, alias.getReadAlias()).execute().actionGet().isAcknowledged();
+            isAck = adminClient.indices().prepareAliases().addAlias(
+                    indexName, alias.getReadAlias()).execute().actionGet().isAcknowledged();
             logger.info("Created new read Alias Name [{}] ACK=[{}]", alias, isAck);
+
             //add write alias
-            isAck = adminClient.indices().prepareAliases().addAlias(indexName, alias.getWriteAlias()).execute().actionGet().isAcknowledged();
+            isAck = adminClient.indices().prepareAliases().addAlias(
+                    indexName, alias.getWriteAlias()).execute().actionGet().isAcknowledged();
             logger.info("Created new write Alias Name [{}] ACK=[{}]", alias, isAck);
 
         } catch (Exception e) {
@@ -217,17 +231,19 @@ public class EsEntityIndexImpl implements EntityIndex {
             public boolean doOp() {
                 final String tempId = UUIDGenerator.newTimeUUID().toString();
 
-                esProvider.getClient().prepareIndex( alias.getWriteAlias(), VERIFY_TYPE,
tempId ).setSource( DEFAULT_PAYLOAD )
-                          .get();
+                esProvider.getClient().prepareIndex( alias.getWriteAlias(), VERIFY_TYPE,
tempId )
+                        .setSource( DEFAULT_PAYLOAD ).get();
 
-                logger.info( "Successfully created new document with docId {} in index {}
and type {}", tempId,
-                        alias, VERIFY_TYPE );
+                logger.info( "Successfully created new document with docId {} "
+                        + "in index {} and type {}", tempId, alias, VERIFY_TYPE );
 
                 // delete all types, this way if we miss one it will get cleaned up
-                esProvider.getClient().prepareDeleteByQuery( alias.getWriteAlias() ).setTypes(VERIFY_TYPE)
-                          .setQuery( MATCH_ALL_QUERY_BUILDER ).get();
+                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 {} and type {}",

+                        alias, VERIFY_TYPE );
 
 
                 return true;
@@ -279,10 +295,10 @@ public class EsEntityIndexImpl implements EntityIndex {
         SearchResponse searchResponse;
 
         if ( query.getCursor() == null ) {
-            SearchRequestBuilder srb = esProvider.getClient().prepareSearch( alias.getReadAlias()
).setTypes(entityTypes)
-                                                 .setScroll(cursorTimeout + "m").setQuery(qb);
-
-
+            SearchRequestBuilder srb = esProvider.getClient().prepareSearch( alias.getReadAlias()
)
+                    .setTypes(entityTypes)
+                    .setScroll(cursorTimeout + "m")
+                    .setQuery(qb);
 
             final FilterBuilder fb = query.createFilterBuilder();
 
@@ -333,8 +349,8 @@ public class EsEntityIndexImpl implements EntityIndex {
 
 
             if ( logger.isDebugEnabled() ) {
-                logger.debug( "Searching index {}\n  scope{} \n type {}\n   query {} ", new
Object[] {
-                        this.alias, context, entityTypes, srb
+                logger.debug( "Searching index {}\n  scope{} \n type {}\n   query {} ", 
+                        new Object[] { this.alias, context, entityTypes, srb
                 } );
 
             }
@@ -424,7 +440,8 @@ public class EsEntityIndexImpl implements EntityIndex {
             @Override
             public boolean doOp() {
                 try {
-                    esProvider.getClient().admin().indices().prepareRefresh( alias.getWriteAlias()
).execute().actionGet();
+                    esProvider.getClient().admin().indices().prepareRefresh( alias.getWriteAlias()
)
+                            .execute().actionGet();
                     logger.debug( "Refreshed index: " + alias);
 
                     return true;
@@ -460,12 +477,14 @@ public class EsEntityIndexImpl implements EntityIndex {
         final String context = IndexingUtils.createContextName(scope);
         final SearchTypes searchTypes = SearchTypes.fromTypes( id.getType() );
 
-        final QueryBuilder queryBuilder = QueryBuilders.termQuery( IndexingUtils.ENTITY_CONTEXT_FIELDNAME,
context );
+        final QueryBuilder queryBuilder = 
+                QueryBuilders.termQuery( IndexingUtils.ENTITY_CONTEXT_FIELDNAME, context
);
 
 
-        final SearchRequestBuilder srb =
-                esProvider.getClient().prepareSearch( alias.getReadAlias() ).setTypes(searchTypes.getTypeNames())
-                          .setScroll(cursorTimeout + "m").setQuery(queryBuilder);
+        final SearchRequestBuilder srb = esProvider.getClient().prepareSearch( alias.getReadAlias()
)
+                .setTypes(searchTypes.getTypeNames())
+                .setScroll(cursorTimeout + "m")
+                .setQuery(queryBuilder);
 
 
 
@@ -554,9 +573,8 @@ public class EsEntityIndexImpl implements EntityIndex {
     public Health getIndexHealth() {
 
         try {
-            ClusterHealthResponse chr = esProvider.getClient().admin().cluster()
-                                                  .health(new ClusterHealthRequest(new String[]{indexIdentifier.getIndex(null)}))
-                                                  .get();
+            ClusterHealthResponse chr = esProvider.getClient().admin().cluster().health(
+                    new ClusterHealthRequest(new String[]{indexIdentifier.getIndex(null)})).get();
             return Health.valueOf( chr.getStatus().name() );
         }
         catch ( Exception ex ) {


Mime
View raw message