Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
adding test
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn Feldman committed Mar 26, 2015
1 parent 7976e1d commit 4b7b122
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 92 deletions.
Expand Up @@ -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();
}
@@ -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();
}

}
Expand Up @@ -56,7 +56,7 @@ protected void configure() {
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);
Expand Down
Expand Up @@ -141,8 +141,6 @@ public EsEntityIndexImpl( final IndexFig config,

}



@Override
public void addIndex(final String indexSuffix,final int numberOfShards, final int numberOfReplicas, final String writeConsistency) {
try {
Expand Down
Expand Up @@ -64,7 +64,6 @@ public EsIndexDataMigrationImpl(AliasedEntityIndex entityIndex, EsProvider provi

@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 -> {
Expand All @@ -77,7 +76,6 @@ public int migrate(int currentVersion, MigrationDataProvider<ApplicationScope> m
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);
Expand All @@ -94,55 +92,5 @@ public boolean supports(int currentVersion) {
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();
}

}
}
@@ -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();
}

}
Expand Up @@ -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;

Expand Down Expand Up @@ -53,11 +65,23 @@ public void configureMigrationProvider(){
}
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);
}
Expand Down

0 comments on commit 4b7b122

Please sign in to comment.