adding test
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/4b7b1220 Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/4b7b1220 Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/4b7b1220 Branch: refs/heads/two-dot-o-dev Commit: 4b7b12203c62c6f6985d5fa21a7e042a24dfc353 Parents: 7976e1d Author: Shawn Feldman <[email protected]> Authored: Thu Mar 26 15:02:13 2015 -0600 Committer: Shawn Feldman <[email protected]> Committed: Thu Mar 26 15:02:13 2015 -0600 ---------------------------------------------------------------------- .../persistence/index/IndexIdentifier.java | 41 ++-------- .../persistence/index/IndexIdentifierImpl.java | 65 ++++++++++++++++ .../persistence/index/guice/IndexModule.java | 2 +- .../index/impl/EsEntityIndexImpl.java | 2 - .../migration/EsIndexDataMigrationImpl.java | 52 ------------- .../index/migration/LegacyIndexIdentifier.java | 78 ++++++++++++++++++++ .../index/guice/TestIndexModule.java | 26 ++++++- 7 files changed, 174 insertions(+), 92 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4b7b1220/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 48c48f3..22b82de 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 @@ -17,46 +17,15 @@ * * directory of this distribution. * */ - package org.apache.usergrid.persistence.index; -import com.google.inject.Inject; - /** - * Class is used to generate an index name and alias name + * Classy class class. */ -public class IndexIdentifier{ - private final IndexFig config; - - @Inject - public IndexIdentifier(IndexFig config) { - this.config = config; - } - - /** - * Get the alias name - * @return - */ - public IndexAlias getAlias() { - return new IndexAlias(config,config.getIndexPrefix()); - } - - /** - * Get index name, send in additional parameter to add incremental indexes - * @param suffix - * @return - */ - public String getIndex(String suffix) { - if (suffix != null) { - return config.getIndexPrefix() + "_" + suffix; - } else { - return config.getIndexPrefix(); - } - } - +public interface IndexIdentifier { + IndexAlias getAlias(); - public String toString() { - return "index id"+config.getIndexPrefix(); - } + String getIndex(String suffix); + String toString(); } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4b7b1220/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifierImpl.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifierImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifierImpl.java new file mode 100644 index 0000000..1d18733 --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifierImpl.java @@ -0,0 +1,65 @@ +/* + * + * * Licensed to the Apache Software Foundation (ASF) under one or more + * * contributor license agreements. The ASF licenses this file to You + * * under the Apache License, Version 2.0 (the "License"); you may not + * * use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. For additional information regarding + * * copyright in this work, please see the NOTICE file in the top level + * * directory of this distribution. + * + */ + +package org.apache.usergrid.persistence.index; + +import com.google.inject.Inject; + +/** + * Class is used to generate an index name and alias name + */ +public class IndexIdentifierImpl implements IndexIdentifier { + private final IndexFig config; + + @Inject + public IndexIdentifierImpl(IndexFig config) { + this.config = config; + } + + /** + * Get the alias name + * @return + */ + @Override + public IndexAlias getAlias() { + return new IndexAlias(config,config.getIndexPrefix()); + } + + /** + * Get index name, send in additional parameter to add incremental indexes + * @param suffix + * @return + */ + @Override + public String getIndex(String suffix) { + if (suffix != null) { + return config.getIndexPrefix() + "_" + suffix; + } else { + return config.getIndexPrefix(); + } + } + + + @Override + public String toString() { + return "index id"+config.getIndexPrefix(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4b7b1220/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/guice/IndexModule.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/guice/IndexModule.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/guice/IndexModule.java index 7ecce54..aba49f6 100644 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/guice/IndexModule.java +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/guice/IndexModule.java @@ -56,7 +56,7 @@ public abstract class IndexModule extends AbstractModule { bind(EntityIndexFactory.class).to( EsEntityIndexFactoryImpl.class ); bind(AliasedEntityIndex.class).to(EsEntityIndexImpl.class); bind(EntityIndex.class).to(EsEntityIndexImpl.class); - bind(IndexIdentifier.class); + bind(IndexIdentifier.class).to(IndexIdentifierImpl.class); bind(IndexBufferProducer.class).to(EsIndexBufferProducerImpl.class); http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4b7b1220/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 844260f..a22ef38 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 @@ -141,8 +141,6 @@ public class EsEntityIndexImpl implements AliasedEntityIndex,VersionedData { } - - @Override public void addIndex(final String indexSuffix,final int numberOfShards, final int numberOfReplicas, final String writeConsistency) { try { http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4b7b1220/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/EsIndexDataMigrationImpl.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/EsIndexDataMigrationImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/EsIndexDataMigrationImpl.java index 13e6526..d6e3812 100644 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/EsIndexDataMigrationImpl.java +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/EsIndexDataMigrationImpl.java @@ -64,7 +64,6 @@ public class EsIndexDataMigrationImpl implements DataMigration<ApplicationScope> @Override public int migrate(int currentVersion, MigrationDataProvider<ApplicationScope> migrationDataProvider, ProgressObserver observer) { - final AtomicInteger integer = new AtomicInteger(); final AdminClient adminClient = provider.getClient().admin(); migrationDataProvider.getData().flatMap(applicationScope -> { @@ -77,7 +76,6 @@ public class EsIndexDataMigrationImpl implements DataMigration<ApplicationScope> aliasesRequestBuilder = adminClient.indices().prepareAliases(); // add read alias aliasesRequestBuilder.addAlias(index, indexIdentifier.getAlias().getReadAlias()); - integer.incrementAndGet(); }) .doOnError(error -> log.error("failed to migrate index", error)) .toBlocking().lastOrDefault(null); @@ -94,55 +92,5 @@ public class EsIndexDataMigrationImpl implements DataMigration<ApplicationScope> public int getMaxVersion() { return dataVersion.getImplementationVersion(); } - /** - * Class is used to generate an index name and alias name the old way via app name - */ - public class LegacyIndexIdentifier{ - private final IndexFig config; - private final ApplicationScope applicationScope; - public LegacyIndexIdentifier(IndexFig config, ApplicationScope applicationScope) { - this.config = config; - this.applicationScope = applicationScope; - } - - /** - * Get the alias name - * @return - */ - public IndexAlias getAlias() { - return new IndexAlias(config,getIndexBase()); - } - - /** - * Get index name, send in additional parameter to add incremental indexes - * @param suffix - * @return - */ - public String getIndex(String suffix) { - if (suffix != null) { - return getIndexBase() + "_" + suffix; - } else { - return getIndexBase(); - } - } - - /** - * returns the base name for index which will be used to add an alias and index - * @return - */ - private String getIndexBase() { - StringBuilder sb = new StringBuilder(); - sb.append(config.getIndexPrefix()).append(IndexingUtils.SEPARATOR); - IndexingUtils.idString(sb, applicationScope.getApplication()); - return sb.toString(); - } - - - - public String toString() { - return "application: " + applicationScope.getApplication().getUuid(); - } - - } } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4b7b1220/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/LegacyIndexIdentifier.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/LegacyIndexIdentifier.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/LegacyIndexIdentifier.java new file mode 100644 index 0000000..5ab3ac1 --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/LegacyIndexIdentifier.java @@ -0,0 +1,78 @@ +/* + * + * * Licensed to the Apache Software Foundation (ASF) under one or more + * * contributor license agreements. The ASF licenses this file to You + * * under the Apache License, Version 2.0 (the "License"); you may not + * * use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. For additional information regarding + * * copyright in this work, please see the NOTICE file in the top level + * * directory of this distribution. + * + */ +package org.apache.usergrid.persistence.index.migration; + +import org.apache.usergrid.persistence.core.scope.ApplicationScope; +import org.apache.usergrid.persistence.index.IndexAlias; +import org.apache.usergrid.persistence.index.IndexFig; +import org.apache.usergrid.persistence.index.IndexIdentifier; +import org.apache.usergrid.persistence.index.impl.IndexingUtils; + +/** + * Class is used to generate an index name and alias name the old way via app name + */ +public class LegacyIndexIdentifier implements IndexIdentifier { + private final IndexFig config; + private final ApplicationScope applicationScope; + + public LegacyIndexIdentifier(IndexFig config, ApplicationScope applicationScope) { + this.config = config; + this.applicationScope = applicationScope; + } + + /** + * Get the alias name + * @return + */ + public IndexAlias getAlias() { + return new IndexAlias(config,getIndexBase()); + } + + /** + * Get index name, send in additional parameter to add incremental indexes + * @param suffix + * @return + */ + public String getIndex(String suffix) { + if (suffix != null) { + return getIndexBase() + "_" + suffix; + } else { + return getIndexBase(); + } + } + + /** + * returns the base name for index which will be used to add an alias and index + * @return + */ + private String getIndexBase() { + StringBuilder sb = new StringBuilder(); + sb.append(config.getIndexPrefix()).append(IndexingUtils.SEPARATOR); + IndexingUtils.idString(sb, applicationScope.getApplication()); + return sb.toString(); + } + + + + public String toString() { + return "application: " + applicationScope.getApplication().getUuid(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4b7b1220/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/guice/TestIndexModule.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/guice/TestIndexModule.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/guice/TestIndexModule.java index 0c57b36..6488b16 100644 --- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/guice/TestIndexModule.java +++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/guice/TestIndexModule.java @@ -19,10 +19,22 @@ package org.apache.usergrid.persistence.index.guice; +import com.amazonaws.services.opsworks.model.App; +import com.google.inject.Inject; import com.google.inject.TypeLiteral; +import org.apache.usergrid.persistence.core.metrics.MetricsFactory; import org.apache.usergrid.persistence.core.migration.data.MigrationDataProvider; import org.apache.usergrid.persistence.core.scope.ApplicationScope; import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl; +import org.apache.usergrid.persistence.index.EntityIndex; +import org.apache.usergrid.persistence.index.IndexBufferProducer; +import org.apache.usergrid.persistence.index.IndexFig; +import org.apache.usergrid.persistence.index.IndexIdentifier; +import org.apache.usergrid.persistence.index.impl.EsEntityIndexImpl; +import org.apache.usergrid.persistence.index.impl.EsIndexCache; +import org.apache.usergrid.persistence.index.impl.EsProvider; +import org.apache.usergrid.persistence.index.migration.EsIndexDataMigrationImpl; +import org.apache.usergrid.persistence.index.migration.LegacyIndexIdentifier; import org.apache.usergrid.persistence.model.entity.SimpleId; import org.safehaus.guicyfig.GuicyFigModule; @@ -53,11 +65,23 @@ public class TestIndexModule extends TestModule { } public static class TestAllApplicationsObservable implements MigrationDataProvider<ApplicationScope>{ + final ApplicationScope appScope = new ApplicationScopeImpl(new SimpleId(UUID.randomUUID(),"application")); + + @Inject + public TestAllApplicationsObservable(final IndexFig config, + final IndexBufferProducer indexBatchBufferProducer, final EsProvider provider, + final EsIndexCache indexCache, final MetricsFactory metricsFactory, + final IndexFig indexFig){ + LegacyIndexIdentifier legacyIndexIdentifier = new LegacyIndexIdentifier(indexFig,appScope); + EntityIndex entityIndex = new EsEntityIndexImpl(config,indexBatchBufferProducer,provider,indexCache,metricsFactory,indexFig,legacyIndexIdentifier); + entityIndex.addIndex(null, 1, 0, indexFig.getWriteConsistencyLevel()); + } + @Override public Observable<ApplicationScope> getData() { ApplicationScope[] scopes = new ApplicationScope[]{ - new ApplicationScopeImpl(new SimpleId(UUID.randomUUID(),"application")) + appScope }; return Observable.from(scopes); }
