cleanup MetaData#Builder construction

have a better method name, and only allow to create a copy of the builder based on existing meta data when constructing the builder
This commit is contained in:
Shay Banon 2013-11-02 01:04:33 +01:00
parent acc5f584d4
commit d111e169a4
50 changed files with 341 additions and 409 deletions

View File

@ -225,7 +225,7 @@ public class TransportClusterUpdateSettingsAction extends TransportMasterNodeOpe
return currentState;
}
MetaData.Builder metaData = MetaData.builder().metaData(currentState.metaData())
MetaData.Builder metaData = MetaData.builder(currentState.metaData())
.persistentSettings(persistentSettings.build())
.transientSettings(transientSettings.build());

View File

@ -34,7 +34,6 @@ import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
/**
*
@ -93,9 +92,11 @@ public class TransportClusterStateAction extends TransportMasterNodeOperationAct
builder.blocks(currentState.blocks());
}
if (!request.filterMetaData()) {
MetaData.Builder mdBuilder = newMetaDataBuilder();
MetaData.Builder mdBuilder;
if (request.filteredIndices().length == 0 && request.filteredIndexTemplates().length == 0) {
mdBuilder.metaData(currentState.metaData());
mdBuilder = MetaData.builder(currentState.metaData());
} else {
mdBuilder = MetaData.builder();
}
if (request.filteredIndices().length > 0) {

View File

@ -125,7 +125,7 @@ public class TransportDeleteWarmerAction extends TransportMasterNodeOperationAct
@Override
public ClusterState execute(ClusterState currentState) {
MetaData.Builder mdBuilder = MetaData.builder().metaData(currentState.metaData());
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
boolean globalFoundAtLeastOne = false;
for (String index : request.indices()) {

View File

@ -144,7 +144,7 @@ public class TransportPutWarmerAction extends TransportMasterNodeOperationAction
}
// now replace it on the metadata
MetaData.Builder mdBuilder = MetaData.builder().metaData(currentState.metaData());
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
for (String index : concreteIndices) {
IndexMetaData indexMetaData = metaData.index(index);

View File

@ -99,7 +99,7 @@ public class MetaData implements Iterable<IndexMetaData> {
public static final ClusterBlock CLUSTER_READ_ONLY_BLOCK = new ClusterBlock(6, "cluster read-only (api)", false, false, RestStatus.FORBIDDEN, ClusterBlockLevel.WRITE, ClusterBlockLevel.METADATA);
public static final MetaData EMPTY_META_DATA = newMetaDataBuilder().build();
public static final MetaData EMPTY_META_DATA = builder().build();
private final long version;
@ -920,9 +920,8 @@ public class MetaData implements Iterable<IndexMetaData> {
return new Builder();
}
public static Builder newMetaDataBuilder() {
return new Builder();
public static Builder builder(MetaData metaData) {
return new Builder(metaData);
}
public static class Builder {
@ -933,19 +932,20 @@ public class MetaData implements Iterable<IndexMetaData> {
private Settings persistentSettings = ImmutableSettings.Builder.EMPTY_SETTINGS;
private MapBuilder<String, IndexMetaData> indices = newMapBuilder();
private MapBuilder<String, IndexTemplateMetaData> templates = newMapBuilder();
private MapBuilder<String, Custom> customs = newMapBuilder();
public Builder metaData(MetaData metaData) {
public Builder() {
}
public Builder(MetaData metaData) {
this.transientSettings = metaData.transientSettings;
this.persistentSettings = metaData.persistentSettings;
this.version = metaData.version;
this.indices.putAll(metaData.indices);
this.templates.putAll(metaData.templates);
this.customs.putAll(metaData.customs);
return this;
}
public Builder put(IndexMetaData.Builder indexMetaDataBuilder) {

View File

@ -76,7 +76,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import static com.google.common.collect.Maps.newHashMap;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.*;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
/**
@ -311,8 +310,7 @@ public class MetaDataCreateIndexService extends AbstractComponent {
throw e;
}
MetaData newMetaData = newMetaDataBuilder()
.metaData(currentState.metaData())
MetaData newMetaData = MetaData.builder(currentState.metaData())
.put(indexMetaData, false)
.build();

View File

@ -44,7 +44,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
/**
*
@ -126,8 +125,7 @@ public class MetaDataDeleteIndexService extends AbstractComponent {
RoutingTable.Builder routingTableBuilder = RoutingTable.builder().routingTable(currentState.routingTable());
routingTableBuilder.remove(request.index);
MetaData newMetaData = newMetaDataBuilder()
.metaData(currentState.metaData())
MetaData newMetaData = MetaData.builder(currentState.metaData())
.remove(request.index)
.build();

View File

@ -48,7 +48,6 @@ import java.util.Map;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
/**
*
@ -103,7 +102,7 @@ public class MetaDataIndexAliasesService extends AbstractComponent {
}
boolean changed = false;
MetaData.Builder builder = newMetaDataBuilder().metaData(currentState.metaData());
MetaData.Builder builder = MetaData.builder(currentState.metaData());
for (AliasAction aliasAction : request.actions) {
IndexMetaData indexMetaData = builder.get(aliasAction.index());
if (indexMetaData == null) {

View File

@ -113,8 +113,7 @@ public class MetaDataIndexStateService extends AbstractComponent {
logger.info("closing indices [{}]", indicesAsString);
MetaData.Builder mdBuilder = MetaData.builder()
.metaData(currentState.metaData());
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
ClusterBlocks.Builder blocksBuilder = ClusterBlocks.builder()
.blocks(currentState.blocks());
for (String index : indicesToClose) {
@ -185,8 +184,7 @@ public class MetaDataIndexStateService extends AbstractComponent {
logger.info("opening indices [{}]", indicesAsString);
MetaData.Builder mdBuilder = MetaData.builder()
.metaData(currentState.metaData());
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
ClusterBlocks.Builder blocksBuilder = ClusterBlocks.builder()
.blocks(currentState.blocks());
for (String index : indicesToOpen) {

View File

@ -85,7 +85,7 @@ public class MetaDataIndexTemplateService extends AbstractComponent {
}
throw new IndexTemplateMissingException(request.name);
}
MetaData.Builder metaData = MetaData.builder().metaData(currentState.metaData());
MetaData.Builder metaData = MetaData.builder(currentState.metaData());
for (String templateName : templateNames) {
metaData.removeTemplate(templateName);
}
@ -161,8 +161,7 @@ public class MetaDataIndexTemplateService extends AbstractComponent {
if (request.create && currentState.metaData().templates().containsKey(request.name)) {
throw new IndexTemplateAlreadyExistsException(request.name);
}
MetaData.Builder builder = MetaData.builder().metaData(currentState.metaData())
.put(template);
MetaData.Builder builder = MetaData.builder(currentState.metaData()).put(template);
return ClusterState.builder().state(currentState).metaData(builder).build();
}

View File

@ -56,7 +56,6 @@ import java.util.concurrent.BlockingQueue;
import static com.google.common.collect.Maps.newHashMap;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.index.mapper.DocumentMapper.MergeFlags.mergeFlags;
/**
@ -142,7 +141,7 @@ public class MetaDataMappingService extends AbstractComponent {
}
boolean dirty = false;
MetaData.Builder mdBuilder = newMetaDataBuilder().metaData(currentState.metaData());
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
for (Map.Entry<String, List<MappingTask>> entry : tasksPerIndex.entrySet()) {
String index = entry.getKey();
List<MappingTask> tasks = entry.getValue();
@ -334,7 +333,7 @@ public class MetaDataMappingService extends AbstractComponent {
throw new IndexMissingException(new Index("_all"));
}
MetaData.Builder builder = newMetaDataBuilder().metaData(currentState.metaData());
MetaData.Builder builder = MetaData.builder(currentState.metaData());
boolean changed = false;
String latestIndexWithout = null;
for (String indexName : request.indices()) {
@ -492,7 +491,7 @@ public class MetaDataMappingService extends AbstractComponent {
return currentState;
}
MetaData.Builder builder = newMetaDataBuilder().metaData(currentState.metaData());
MetaData.Builder builder = MetaData.builder(currentState.metaData());
for (String indexName : request.indices) {
IndexMetaData indexMetaData = currentState.metaData().index(indexName);
if (indexMetaData == null) {

View File

@ -232,7 +232,7 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
public ClusterState execute(ClusterState currentState) {
String[] actualIndices = currentState.metaData().concreteIndices(request.indices());
RoutingTable.Builder routingTableBuilder = RoutingTable.builder().routingTable(currentState.routingTable());
MetaData.Builder metaDataBuilder = MetaData.newMetaDataBuilder().metaData(currentState.metaData());
MetaData.Builder metaDataBuilder = MetaData.builder(currentState.metaData());
// allow to change any settings to a close index, and only allow dynamic settings to be changed
// on an open index

View File

@ -330,7 +330,7 @@ public class InternalClusterService extends AbstractLifecycleComponent<ClusterSe
builder.routingTable(RoutingTable.builder().routingTable(newClusterState.routingTable()).version(newClusterState.routingTable().version() + 1));
}
if (previousClusterState.metaData() != newClusterState.metaData()) {
builder.metaData(MetaData.builder().metaData(newClusterState.metaData()).version(newClusterState.metaData().version() + 1));
builder.metaData(MetaData.builder(newClusterState.metaData()).version(newClusterState.metaData().version() + 1));
}
newClusterState = builder.build();
@ -356,7 +356,7 @@ public class InternalClusterService extends AbstractLifecycleComponent<ClusterSe
// have a fresh instances of routing and metadata to remove the chance that version might be the same
Builder builder = ClusterState.builder().state(newClusterState);
builder.routingTable(RoutingTable.builder().routingTable(newClusterState.routingTable()));
builder.metaData(MetaData.builder().metaData(newClusterState.metaData()));
builder.metaData(MetaData.builder(newClusterState.metaData()));
newClusterState = builder.build();
logger.debug("got first state from fresh master [{}]", newClusterState.nodes().masterNodeId());
} else if (newClusterState.version() < previousClusterState.version()) {

View File

@ -601,7 +601,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> implemen
builder.metaData(currentState.metaData());
} else {
// if its not the same version, only copy over new indices or ones that changed the version
MetaData.Builder metaDataBuilder = MetaData.builder().metaData(newState.metaData()).removeAllIndices();
MetaData.Builder metaDataBuilder = MetaData.builder(newState.metaData()).removeAllIndices();
for (IndexMetaData indexMetaData : newState.metaData()) {
IndexMetaData currentIndexMetaData = currentState.metaData().index(indexMetaData.index());
if (currentIndexMetaData == null || currentIndexMetaData.version() != indexMetaData.version()) {

View File

@ -43,7 +43,6 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
/**
*
@ -248,8 +247,7 @@ public class GatewayService extends AbstractLifecycleComponent<GatewayService> i
.blocks(recoveredState.blocks())
.removeGlobalBlock(STATE_NOT_RECOVERED_BLOCK);
MetaData.Builder metaDataBuilder = newMetaDataBuilder()
.metaData(recoveredState.metaData());
MetaData.Builder metaDataBuilder = MetaData.builder(recoveredState.metaData());
if (recoveredState.metaData().settings().getAsBoolean(MetaData.SETTING_READ_ONLY, false) || currentState.metaData().settings().getAsBoolean(MetaData.SETTING_READ_ONLY, false)) {
blocks.addGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK);

View File

@ -135,7 +135,6 @@ public class LocalGateway extends AbstractLifecycleComponent<Gateway> implements
}
}
MetaData.Builder metaDataBuilder = MetaData.builder();
ObjectFloatOpenHashMap<String> indices = new ObjectFloatOpenHashMap<String>();
MetaData electedGlobalState = null;
int found = 0;
@ -158,7 +157,7 @@ public class LocalGateway extends AbstractLifecycleComponent<Gateway> implements
return;
}
// update the global state, and clean the indices, we elect them in the next phase
metaDataBuilder.metaData(electedGlobalState).removeAllIndices();
MetaData.Builder metaDataBuilder = MetaData.builder(electedGlobalState).removeAllIndices();
final boolean[] states = indices.allocated;
final Object[] keys = indices.keys;
for (int i = 0; i < states.length; i++) {

View File

@ -120,8 +120,7 @@ public class LocalAllocateDangledIndices extends AbstractComponent {
if (currentState.blocks().disableStatePersistence()) {
return currentState;
}
MetaData.Builder metaData = MetaData.builder()
.metaData(currentState.metaData());
MetaData.Builder metaData = MetaData.builder(currentState.metaData());
ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks());
RoutingTable.Builder routingTableBuilder = RoutingTable.builder().routingTable(currentState.routingTable());

View File

@ -387,7 +387,7 @@ public class LocalGatewayMetaState extends AbstractComponent implements ClusterS
private void writeGlobalState(String reason, MetaData metaData, @Nullable MetaData previousMetaData) throws Exception {
logger.trace("[_global] writing state, reason [{}]", reason);
// create metadata to write with just the global state
MetaData globalMetaData = MetaData.builder().metaData(metaData).removeAllIndices().build();
MetaData globalMetaData = MetaData.builder(metaData).removeAllIndices().build();
XContentBuilder builder = XContentFactory.contentBuilder(format);
builder.startObject();
@ -442,10 +442,12 @@ public class LocalGatewayMetaState extends AbstractComponent implements ClusterS
}
private MetaData loadState() throws Exception {
MetaData.Builder metaDataBuilder = MetaData.builder();
MetaData globalMetaData = loadGlobalState();
MetaData.Builder metaDataBuilder;
if (globalMetaData != null) {
metaDataBuilder.metaData(globalMetaData);
metaDataBuilder = MetaData.builder(globalMetaData);
} else {
metaDataBuilder = MetaData.builder();
}
Set<String> indices = nodeEnv.findAllIndices();
@ -618,7 +620,7 @@ public class LocalGatewayMetaState extends AbstractComponent implements ClusterS
logger.info("found old metadata state, loading metadata from [{}] and converting to new metadata location and strucutre...", metaDataFile.getAbsolutePath());
writeGlobalState("upgrade", MetaData.builder().metaData(metaData).version(version).build(), null);
writeGlobalState("upgrade", MetaData.builder(metaData).version(version).build(), null);
for (IndexMetaData indexMetaData : metaData) {
IndexMetaData.Builder indexMetaDataBuilder = IndexMetaData.newIndexMetaDataBuilder(indexMetaData).version(version);
// set the created version to 0.18

View File

@ -28,9 +28,7 @@ import java.io.IOException;
import static org.elasticsearch.cluster.metadata.AliasMetaData.newAliasMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
@ -41,7 +39,7 @@ public class ToAndFromJsonMetaDataTests extends ElasticsearchTestCase {
@Test
public void testSimpleJsonFromAndTo() throws IOException {
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1")
.numberOfShards(1)
.numberOfReplicas(2))

View File

@ -19,14 +19,12 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
public class AddIncrementallyTests extends ElasticsearchTestCase {
private final ESLogger logger = Loggers.getLogger(AddIncrementallyTests.class);
@ -79,7 +77,7 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
public void testMinimalRelocations() {
ImmutableSettings.Builder settings = settingsBuilder();
settings.put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString())
.put("cluster.routing.allocation.node_concurrent_recoveries", 2);
.put("cluster.routing.allocation.node_concurrent_recoveries", 2);
AllocationService service = new AllocationService(settings.build());
ClusterState clusterState = initCluster(service, 1, 3, 3, 1);
@ -94,7 +92,7 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
logger.info("now, start one more node, check that rebalancing will happen because we set it to always");
DiscoveryNodes.Builder nodes = newNodesBuilder().putAll(clusterState.nodes());
nodes.put(newNode("node2"));
nodes.put(newNode("node2"));
clusterState = newClusterStateBuilder().state(clusterState).nodes(nodes.build()).build();
RoutingTable routingTable = service.reroute(clusterState).routingTable();
@ -149,8 +147,8 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
public void testMinimalRelocationsNoLimit() {
ImmutableSettings.Builder settings = settingsBuilder();
settings.put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString())
.put("cluster.routing.allocation.node_concurrent_recoveries", 100)
.put("cluster.routing.allocation.node_initial_primaries_recoveries", 100);
.put("cluster.routing.allocation.node_concurrent_recoveries", 100)
.put("cluster.routing.allocation.node_initial_primaries_recoveries", 100);
AllocationService service = new AllocationService(settings.build());
ClusterState clusterState = initCluster(service, 1, 3, 3, 1);
@ -165,7 +163,7 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
logger.info("now, start one more node, check that rebalancing will happen because we set it to always");
DiscoveryNodes.Builder nodes = newNodesBuilder().putAll(clusterState.nodes());
nodes.put(newNode("node2"));
nodes.put(newNode("node2"));
clusterState = newClusterStateBuilder().state(clusterState).nodes(nodes.build()).build();
RoutingTable routingTable = service.reroute(clusterState).routingTable();
@ -270,8 +268,8 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
}
private ClusterState initCluster(AllocationService service, int numberOfNodes, int numberOfIndices, int numberOfShards,
int numberOfReplicas) {
MetaData.Builder metaDataBuilder = newMetaDataBuilder();
int numberOfReplicas) {
MetaData.Builder metaDataBuilder = MetaData.builder();
RoutingTable.Builder routingTableBuilder = routingTable();
for (int i = 0; i < numberOfIndices; i++) {
@ -325,14 +323,14 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
}
private ClusterState addIndex(ClusterState clusterState, AllocationService service, int indexOrdinal, int numberOfShards,
int numberOfReplicas) {
MetaData.Builder metaDataBuilder = newMetaDataBuilder().metaData(clusterState.getMetaData());
int numberOfReplicas) {
MetaData.Builder metaDataBuilder = MetaData.builder(clusterState.getMetaData());
RoutingTable.Builder routingTableBuilder = routingTable().routingTable(clusterState.routingTable());
IndexMetaData.Builder index = newIndexMetaDataBuilder("test" + indexOrdinal).numberOfShards(numberOfShards).numberOfReplicas(
numberOfReplicas);
metaDataBuilder = metaDataBuilder.put(index);
routingTableBuilder.addAsNew(index.build());
IndexMetaData.Builder index = newIndexMetaDataBuilder("test" + indexOrdinal).numberOfShards(numberOfShards).numberOfReplicas(
numberOfReplicas);
metaDataBuilder = metaDataBuilder.put(index);
routingTableBuilder.addAsNew(index.build());
MetaData metaData = metaDataBuilder.build();
RoutingTable routingTable = routingTableBuilder.build();
@ -399,7 +397,7 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
logger.info("complete rebalancing");
RoutingTable prev = routingTable;
while(true) {
while (true) {
routingTable = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
routingNodes = clusterState.routingNodes();

View File

@ -29,13 +29,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -49,7 +47,7 @@ public class AllocatePostApiFlagTests extends ElasticsearchTestCase {
AllocationService allocation = new AllocationService(settingsBuilder().put("cluster.routing.allocation.concurrent_recoveries", 10).build());
logger.info("creating an index with 1 shard, no replica");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(0))
.build();
RoutingTable routingTable = routingTable()

View File

@ -42,14 +42,12 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -63,7 +61,7 @@ public class AllocationCommandsTests extends ElasticsearchTestCase {
AllocationService allocation = new AllocationService(settingsBuilder().put("cluster.routing.allocation.concurrent_recoveries", 10).build());
logger.info("creating an index with 1 shard, no replica");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(0))
.build();
RoutingTable routingTable = routingTable()
@ -110,7 +108,7 @@ public class AllocationCommandsTests extends ElasticsearchTestCase {
.build());
logger.info("--> building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
RoutingTable routingTable = routingTable()
@ -191,7 +189,7 @@ public class AllocationCommandsTests extends ElasticsearchTestCase {
.build());
logger.info("--> building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
RoutingTable routingTable = routingTable()

View File

@ -32,7 +32,6 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
@ -56,7 +55,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'moveShardOnceNewNodeWithAttributeAdded1'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -125,7 +124,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'moveShardOnceNewNodeWithAttributeAdded2'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -200,7 +199,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'moveShardOnceNewNodeWithAttributeAdded3'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(5).numberOfReplicas(1))
.build();
@ -298,7 +297,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'moveShardOnceNewNodeWithAttributeAdded4'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(5).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(5).numberOfReplicas(1))
.build();
@ -381,6 +380,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("--> do another reroute, make sure nothing moves");
assertThat(strategy.reroute(clusterState).routingTable(), sameInstance(clusterState.routingTable()));
}
@Test
public void moveShardOnceNewNodeWithAttributeAdded5() {
AllocationService strategy = new AllocationService(settingsBuilder()
@ -391,7 +391,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'moveShardOnceNewNodeWithAttributeAdded5'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(2))
.build();
@ -470,7 +470,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'moveShardOnceNewNodeWithAttributeAdded6'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(3))
.build();
@ -552,7 +552,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'fullAwareness1'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -620,7 +620,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'fullAwareness2'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -694,7 +694,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'fullAwareness3'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(5).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(5).numberOfReplicas(1))
.build();
@ -776,7 +776,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'testUnbalancedZones'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(5).numberOfReplicas(1))
.build();
@ -817,7 +817,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
assertThat(clusterState.routingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(8));
assertThat(clusterState.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(2));
assertThat(clusterState.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo("A-1"));
logger.info("--> starting inizializing shards on the new node");
logger.info("--> starting initializing shards on the new node");
routingTable = strategy.applyStartedShards(clusterState, clusterState.routingNodes().shardsWithState(INITIALIZING)).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();

View File

@ -44,14 +44,12 @@ import java.util.List;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
public class BalanceConfigurationTests extends ElasticsearchTestCase {
@ -83,10 +81,10 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
assertIndexBalance(logger, clusterState.getRoutingNodes(), numberOfNodes, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
clusterState = addNode(clusterState, strategy);
assertIndexBalance(logger, clusterState.getRoutingNodes(), numberOfNodes+1, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
assertIndexBalance(logger, clusterState.getRoutingNodes(), numberOfNodes + 1, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
clusterState = removeNodes(clusterState, strategy);
assertIndexBalance(logger, clusterState.getRoutingNodes(), (numberOfNodes+1)-(numberOfNodes+1)/2, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
assertIndexBalance(logger, clusterState.getRoutingNodes(), (numberOfNodes + 1) - (numberOfNodes + 1) / 2, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
}
@ -111,10 +109,10 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
assertReplicaBalance(logger, clusterState.getRoutingNodes(), numberOfNodes, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
clusterState = addNode(clusterState, strategy);
assertReplicaBalance(logger, clusterState.getRoutingNodes(), numberOfNodes+1, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
assertReplicaBalance(logger, clusterState.getRoutingNodes(), numberOfNodes + 1, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
clusterState = removeNodes(clusterState, strategy);
assertReplicaBalance(logger, clusterState.getRoutingNodes(), (numberOfNodes+1)-(numberOfNodes+1)/2, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
assertReplicaBalance(logger, clusterState.getRoutingNodes(), (numberOfNodes + 1) - (numberOfNodes + 1) / 2, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
}
@ -139,18 +137,18 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
assertPrimaryBalance(logger, clusterstate.getRoutingNodes(), numberOfNodes, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
clusterstate = addNode(clusterstate, strategy);
assertPrimaryBalance(logger, clusterstate.getRoutingNodes(), numberOfNodes+1, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
assertPrimaryBalance(logger, clusterstate.getRoutingNodes(), numberOfNodes + 1, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
clusterstate = removeNodes(clusterstate, strategy);
assertPrimaryBalance(logger, clusterstate.getRoutingNodes(), numberOfNodes+1-(numberOfNodes+1)/2, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
assertPrimaryBalance(logger, clusterstate.getRoutingNodes(), numberOfNodes + 1 - (numberOfNodes + 1) / 2, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
}
private ClusterState initCluster(AllocationService strategy) {
MetaData.Builder metaDataBuilder = newMetaDataBuilder();
MetaData.Builder metaDataBuilder = MetaData.builder();
RoutingTable.Builder routingTableBuilder = routingTable();
for (int i = 0; i < numberOfIndices; i++) {
IndexMetaData.Builder index = newIndexMetaDataBuilder("test"+i).numberOfShards(numberOfShards).numberOfReplicas(numberOfReplicas);
IndexMetaData.Builder index = newIndexMetaDataBuilder("test" + i).numberOfShards(numberOfShards).numberOfReplicas(numberOfReplicas);
metaDataBuilder = metaDataBuilder.put(index);
}
@ -163,10 +161,10 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
RoutingTable routingTable = routingTableBuilder.build();
logger.info("start "+numberOfNodes+" nodes");
logger.info("start " + numberOfNodes + " nodes");
DiscoveryNodes.Builder nodes = newNodesBuilder();
for (int i = 0; i < numberOfNodes; i++) {
nodes.put(newNode("node"+i));
nodes.put(newNode("node" + i));
}
ClusterState clusterState = newClusterStateBuilder().nodes(nodes).metaData(metaData).routingTable(routingTable).build();
routingTable = strategy.reroute(clusterState).routingTable();
@ -187,7 +185,7 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
logger.info("complete rebalancing");
RoutingTable prev = routingTable;
while(true) {
while (true) {
routingTable = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
routingNodes = clusterState.routingNodes();
@ -202,7 +200,7 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
private ClusterState addNode(ClusterState clusterState, AllocationService strategy) {
logger.info("now, start 1 more node, check that rebalancing will happen because we set it to always");
clusterState = newClusterStateBuilder().state(clusterState).nodes(newNodesBuilder().putAll(clusterState.nodes())
.put(newNode("node"+numberOfNodes)))
.put(newNode("node" + numberOfNodes)))
.build();
RoutingTable routingTable = strategy.reroute(clusterState).routingTable();
@ -212,7 +210,7 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
// move initializing to started
RoutingTable prev = routingTable;
while(true) {
while (true) {
routingTable = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
routingNodes = clusterState.routingNodes();
@ -225,11 +223,11 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
}
private ClusterState removeNodes(ClusterState clusterState, AllocationService strategy) {
logger.info("Removing half the nodes ("+(numberOfNodes+1)/2+")");
logger.info("Removing half the nodes (" + (numberOfNodes + 1) / 2 + ")");
DiscoveryNodes.Builder nodes = newNodesBuilder().putAll(clusterState.nodes());
for(int i=(numberOfNodes+1)/2; i<=numberOfNodes; i++){
nodes.remove("node"+i);
for (int i = (numberOfNodes + 1) / 2; i <= numberOfNodes; i++) {
nodes.remove("node" + i);
}
clusterState = newClusterStateBuilder().state(clusterState).nodes(nodes.build()).build();
@ -252,7 +250,7 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
logger.info("complete rebalancing");
RoutingTable prev = routingTable;
while(true) {
while (true) {
routingTable = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
routingNodes = clusterState.routingNodes();
@ -266,10 +264,10 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
private void assertReplicaBalance(ESLogger logger, RoutingNodes nodes, int numberOfNodes, int numberOfIndices, int numberOfReplicas, int numberOfShards, float treshold) {
final int numShards = numberOfIndices * numberOfShards * (numberOfReplicas+1);
final float avgNumShards = (float)(numShards) / (float)(numberOfNodes);
final int minAvgNumberOfShards = Math.round(Math.round(Math.floor(avgNumShards-treshold)));
final int maxAvgNumberOfShards = Math.round(Math.round(Math.ceil(avgNumShards+treshold)));
final int numShards = numberOfIndices * numberOfShards * (numberOfReplicas + 1);
final float avgNumShards = (float) (numShards) / (float) (numberOfNodes);
final int minAvgNumberOfShards = Math.round(Math.round(Math.floor(avgNumShards - treshold)));
final int maxAvgNumberOfShards = Math.round(Math.round(Math.ceil(avgNumShards + treshold)));
for (RoutingNode node : nodes) {
// logger.info(node.nodeId() + ": " + node.shardsWithState(INITIALIZING, STARTED).size() + " shards ("+minAvgNumberOfShards+" to "+maxAvgNumberOfShards+")");
@ -280,12 +278,12 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
private void assertIndexBalance(ESLogger logger, RoutingNodes nodes, int numberOfNodes, int numberOfIndices, int numberOfReplicas, int numberOfShards, float treshold) {
final int numShards = numberOfShards * (numberOfReplicas+1);
final float avgNumShards = (float)(numShards) / (float)(numberOfNodes);
final int minAvgNumberOfShards = Math.round(Math.round(Math.floor(avgNumShards-treshold)));
final int maxAvgNumberOfShards = Math.round(Math.round(Math.ceil(avgNumShards+treshold)));
final int numShards = numberOfShards * (numberOfReplicas + 1);
final float avgNumShards = (float) (numShards) / (float) (numberOfNodes);
final int minAvgNumberOfShards = Math.round(Math.round(Math.floor(avgNumShards - treshold)));
final int maxAvgNumberOfShards = Math.round(Math.round(Math.ceil(avgNumShards + treshold)));
for(String index : nodes.getRoutingTable().indicesRouting().keySet()) {
for (String index : nodes.getRoutingTable().indicesRouting().keySet()) {
for (RoutingNode node : nodes) {
// logger.info(node.nodeId() +":"+index+ ": " + node.shardsWithState(index, INITIALIZING, STARTED).size() + " shards ("+minAvgNumberOfShards+" to "+maxAvgNumberOfShards+")");
assertThat(node.shardsWithState(index, STARTED).size(), Matchers.greaterThanOrEqualTo(minAvgNumberOfShards));
@ -297,15 +295,15 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
private void assertPrimaryBalance(ESLogger logger, RoutingNodes nodes, int numberOfNodes, int numberOfIndices, int numberOfReplicas, int numberOfShards, float treshold) {
final int numShards = numberOfShards;
final float avgNumShards = (float)(numShards) / (float)(numberOfNodes);
final int minAvgNumberOfShards = Math.round(Math.round(Math.floor(avgNumShards-treshold)));
final int maxAvgNumberOfShards = Math.round(Math.round(Math.ceil(avgNumShards+treshold)));
final float avgNumShards = (float) (numShards) / (float) (numberOfNodes);
final int minAvgNumberOfShards = Math.round(Math.round(Math.floor(avgNumShards - treshold)));
final int maxAvgNumberOfShards = Math.round(Math.round(Math.ceil(avgNumShards + treshold)));
for(String index : nodes.getRoutingTable().indicesRouting().keySet()) {
for (String index : nodes.getRoutingTable().indicesRouting().keySet()) {
for (RoutingNode node : nodes) {
int primaries = 0;
for(ShardRouting shard : node.shardsWithState(index, STARTED)) {
primaries += shard.primary()?1:0;
for (ShardRouting shard : node.shardsWithState(index, STARTED)) {
primaries += shard.primary() ? 1 : 0;
}
// logger.info(node.nodeId() + ": " + primaries + " primaries ("+minAvgNumberOfShards+" to "+maxAvgNumberOfShards+")");
assertThat(primaries, Matchers.greaterThanOrEqualTo(minAvgNumberOfShards));
@ -365,96 +363,96 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
new NodeSettingsService(ImmutableSettings.Builder.EMPTY_SETTINGS)), new ShardsAllocators(settings.build(),
new NoneGatewayAllocator(), new ShardsAllocator() {
@Override
public boolean rebalance(RoutingAllocation allocation) {
return false;
}
@Override
public boolean rebalance(RoutingAllocation allocation) {
return false;
}
@Override
public boolean move(MutableShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
return false;
}
@Override
public boolean move(MutableShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
return false;
}
@Override
public void applyStartedShards(StartedRerouteAllocation allocation) {
@Override
public void applyStartedShards(StartedRerouteAllocation allocation) {
}
}
@Override
public void applyFailedShards(FailedRerouteAllocation allocation) {
}
@Override
public void applyFailedShards(FailedRerouteAllocation allocation) {
}
/*
* // this allocator tries to rebuild this scenario where a rebalance is
* // triggered solely by the primary overload on node [1] where a shard
* // is rebalanced to node 0
routing_nodes:
-----node_id[0][V]
--------[test][0], node[0], [R], s[STARTED]
--------[test][4], node[0], [R], s[STARTED]
-----node_id[1][V]
--------[test][0], node[1], [P], s[STARTED]
--------[test][1], node[1], [P], s[STARTED]
--------[test][3], node[1], [R], s[STARTED]
-----node_id[2][V]
--------[test][1], node[2], [R], s[STARTED]
--------[test][2], node[2], [R], s[STARTED]
--------[test][4], node[2], [P], s[STARTED]
-----node_id[3][V]
--------[test][2], node[3], [P], s[STARTED]
--------[test][3], node[3], [P], s[STARTED]
---- unassigned
*/
@Override
public boolean allocateUnassigned(RoutingAllocation allocation) {
List<MutableShardRouting> unassigned = allocation.routingNodes().unassigned();
boolean changed = !unassigned.isEmpty();
for (MutableShardRouting sr : unassigned) {
switch (sr.id()) {
case 0:
if (sr.primary()) {
allocation.routingNodes().node("node1").add(sr);
} else {
allocation.routingNodes().node("node0").add(sr);
}
break;
case 1:
if (sr.primary()) {
allocation.routingNodes().node("node1").add(sr);
} else {
allocation.routingNodes().node("node2").add(sr);
}
break;
case 2:
if (sr.primary()) {
allocation.routingNodes().node("node3").add(sr);
} else {
allocation.routingNodes().node("node2").add(sr);
}
break;
case 3:
if (sr.primary()) {
allocation.routingNodes().node("node3").add(sr);
} else {
allocation.routingNodes().node("node1").add(sr);
}
break;
case 4:
if (sr.primary()) {
allocation.routingNodes().node("node2").add(sr);
} else {
allocation.routingNodes().node("node0").add(sr);
}
break;
/*
* // this allocator tries to rebuild this scenario where a rebalance is
* // triggered solely by the primary overload on node [1] where a shard
* // is rebalanced to node 0
routing_nodes:
-----node_id[0][V]
--------[test][0], node[0], [R], s[STARTED]
--------[test][4], node[0], [R], s[STARTED]
-----node_id[1][V]
--------[test][0], node[1], [P], s[STARTED]
--------[test][1], node[1], [P], s[STARTED]
--------[test][3], node[1], [R], s[STARTED]
-----node_id[2][V]
--------[test][1], node[2], [R], s[STARTED]
--------[test][2], node[2], [R], s[STARTED]
--------[test][4], node[2], [P], s[STARTED]
-----node_id[3][V]
--------[test][2], node[3], [P], s[STARTED]
--------[test][3], node[3], [P], s[STARTED]
---- unassigned
*/
@Override
public boolean allocateUnassigned(RoutingAllocation allocation) {
List<MutableShardRouting> unassigned = allocation.routingNodes().unassigned();
boolean changed = !unassigned.isEmpty();
for (MutableShardRouting sr : unassigned) {
switch (sr.id()) {
case 0:
if (sr.primary()) {
allocation.routingNodes().node("node1").add(sr);
} else {
allocation.routingNodes().node("node0").add(sr);
}
}
unassigned.clear();
return changed;
break;
case 1:
if (sr.primary()) {
allocation.routingNodes().node("node1").add(sr);
} else {
allocation.routingNodes().node("node2").add(sr);
}
break;
case 2:
if (sr.primary()) {
allocation.routingNodes().node("node3").add(sr);
} else {
allocation.routingNodes().node("node2").add(sr);
}
break;
case 3:
if (sr.primary()) {
allocation.routingNodes().node("node3").add(sr);
} else {
allocation.routingNodes().node("node1").add(sr);
}
break;
case 4:
if (sr.primary()) {
allocation.routingNodes().node("node2").add(sr);
} else {
allocation.routingNodes().node("node0").add(sr);
}
break;
}
}), ClusterInfoService.EMPTY);
MetaData.Builder metaDataBuilder = newMetaDataBuilder();
}
unassigned.clear();
return changed;
}
}), ClusterInfoService.EMPTY);
MetaData.Builder metaDataBuilder = MetaData.builder();
RoutingTable.Builder routingTableBuilder = routingTable();
IndexMetaData.Builder indexMeta = newIndexMetaDataBuilder("test").numberOfShards(5).numberOfReplicas(1);
metaDataBuilder = metaDataBuilder.put(indexMeta);
@ -465,7 +463,7 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
RoutingTable routingTable = routingTableBuilder.build();
DiscoveryNodes.Builder nodes = newNodesBuilder();
for (int i = 0; i < 4; i++) {
DiscoveryNode node = newNode("node"+i);
DiscoveryNode node = newNode("node" + i);
nodes.put(node);
}

View File

@ -31,13 +31,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
public class ClusterRebalanceRoutingTests extends ElasticsearchTestCase {
@ -48,7 +46,7 @@ public class ClusterRebalanceRoutingTests extends ElasticsearchTestCase {
public void testAlways() {
AllocationService strategy = new AllocationService(settingsBuilder().put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString()).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();
@ -134,7 +132,7 @@ public class ClusterRebalanceRoutingTests extends ElasticsearchTestCase {
public void testClusterPrimariesActive1() {
AllocationService strategy = new AllocationService(settingsBuilder().put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.INDICES_PRIMARIES_ACTIVE.toString()).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();
@ -238,7 +236,7 @@ public class ClusterRebalanceRoutingTests extends ElasticsearchTestCase {
public void testClusterPrimariesActive2() {
AllocationService strategy = new AllocationService(settingsBuilder().put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.INDICES_PRIMARIES_ACTIVE.toString()).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();
@ -322,7 +320,7 @@ public class ClusterRebalanceRoutingTests extends ElasticsearchTestCase {
public void testClusterAllActive1() {
AllocationService strategy = new AllocationService(settingsBuilder().put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.INDICES_ALL_ACTIVE.toString()).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();
@ -445,7 +443,7 @@ public class ClusterRebalanceRoutingTests extends ElasticsearchTestCase {
public void testClusterAllActive2() {
AllocationService strategy = new AllocationService(settingsBuilder().put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.INDICES_ALL_ACTIVE.toString()).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();
@ -529,7 +527,7 @@ public class ClusterRebalanceRoutingTests extends ElasticsearchTestCase {
public void testClusterAllActive3() {
AllocationService strategy = new AllocationService(settingsBuilder().put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.INDICES_ALL_ACTIVE.toString()).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();

View File

@ -30,13 +30,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
@ -53,7 +51,7 @@ public class ConcurrentRebalanceRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(5).numberOfReplicas(1))
.build();

View File

@ -31,13 +31,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -54,7 +52,7 @@ public class DeadNodesAllocationTests extends ElasticsearchTestCase {
.build());
logger.info("--> building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
RoutingTable routingTable = routingTable()
@ -106,7 +104,7 @@ public class DeadNodesAllocationTests extends ElasticsearchTestCase {
.build());
logger.info("--> building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
RoutingTable routingTable = routingTable()
@ -181,7 +179,7 @@ public class DeadNodesAllocationTests extends ElasticsearchTestCase {
.build());
logger.info("--> building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
RoutingTable routingTable = routingTable()

View File

@ -31,14 +31,12 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -56,7 +54,7 @@ public class DisableAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -85,7 +83,7 @@ public class DisableAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -116,7 +114,7 @@ public class DisableAllocationTests extends ElasticsearchTestCase {
AllocationService strategy = new AllocationService(settingsBuilder()
.build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("disabled").settings(ImmutableSettings.builder().put(DisableAllocationDecider.INDEX_ROUTING_ALLOCATION_DISABLE_ALLOCATION, true).put(DisableAllocationDecider.INDEX_ROUTING_ALLOCATION_DISABLE_NEW_ALLOCATION, true)).numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("enabled").numberOfShards(1).numberOfReplicas(1))
.build();

View File

@ -31,14 +31,12 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -54,7 +52,7 @@ public class ElectReplicaAsPrimaryDuringRelocationTests extends ElasticsearchTes
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(2).numberOfReplicas(1))
.build();

View File

@ -32,14 +32,12 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
public class FailedNodeRoutingTests extends ElasticsearchTestCase {
@ -50,7 +48,7 @@ public class FailedNodeRoutingTests extends ElasticsearchTestCase {
public void simpleFailedNodeTest() {
AllocationService strategy = new AllocationService(settingsBuilder().put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString()).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();
@ -110,7 +108,7 @@ public class FailedNodeRoutingTests extends ElasticsearchTestCase {
public void simpleFailedNodeTestNoReassign() {
AllocationService strategy = new AllocationService(settingsBuilder().put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString()).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();

View File

@ -34,13 +34,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
/**
@ -58,7 +56,7 @@ public class FailedShardsRoutingTests extends ElasticsearchTestCase {
.build());
logger.info("--> building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
RoutingTable routingTable = routingTable()
@ -148,7 +146,7 @@ public class FailedShardsRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -229,7 +227,7 @@ public class FailedShardsRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -286,7 +284,7 @@ public class FailedShardsRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -343,7 +341,7 @@ public class FailedShardsRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(2).numberOfReplicas(1))
.build();

View File

@ -35,13 +35,11 @@ import java.util.List;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -59,7 +57,7 @@ public class FilterRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(2).numberOfReplicas(1))
.build();
@ -103,7 +101,7 @@ public class FilterRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").settings(settingsBuilder()
.put("index.number_of_shards", 2)
.put("index.number_of_replicas", 1)
@ -146,7 +144,7 @@ public class FilterRoutingTests extends ElasticsearchTestCase {
logger.info("--> switch between value2 and value4, shards should be relocating");
metaData = newMetaDataBuilder()
metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").settings(settingsBuilder()
.put("index.number_of_shards", 2)
.put("index.number_of_replicas", 1)

View File

@ -32,13 +32,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
@ -59,7 +57,7 @@ public class IndexBalanceTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder().put(newIndexMetaDataBuilder("test").numberOfShards(3).numberOfReplicas(1))
MetaData metaData = MetaData.builder().put(newIndexMetaDataBuilder("test").numberOfShards(3).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test1").numberOfShards(3).numberOfReplicas(1)).build();
RoutingTable routingTable = routingTable().addAsNew(metaData.index("test")).addAsNew(metaData.index("test1")).build();
@ -190,7 +188,7 @@ public class IndexBalanceTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder().put(newIndexMetaDataBuilder("test").numberOfShards(3).numberOfReplicas(1))
MetaData metaData = MetaData.builder().put(newIndexMetaDataBuilder("test").numberOfShards(3).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test1").numberOfShards(3).numberOfReplicas(1)).build();
RoutingTable routingTable = routingTable().addAsNew(metaData.index("test")).addAsNew(metaData.index("test1")).build();
@ -353,7 +351,7 @@ public class IndexBalanceTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder().put(newIndexMetaDataBuilder("test").numberOfShards(3).numberOfReplicas(1)).build();
MetaData metaData = MetaData.builder().put(newIndexMetaDataBuilder("test").numberOfShards(3).numberOfReplicas(1)).build();
RoutingTable routingTable = routingTable().addAsNew(metaData.index("test")).build();
@ -451,7 +449,7 @@ public class IndexBalanceTests extends ElasticsearchTestCase {
logger.info("Add new index 3 shards 1 replica");
prevRoutingTable = routingTable;
metaData = newMetaDataBuilder().metaData(metaData)
metaData = MetaData.builder(metaData)
.put(newIndexMetaDataBuilder("test1").settings(ImmutableSettings.settingsBuilder()
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 3)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)

View File

@ -29,7 +29,6 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
@ -53,7 +52,7 @@ public class PreferPrimaryAllocationTests extends ElasticsearchTestCase {
logger.info("create several indices with no replicas, and wait till all are allocated");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(10).numberOfReplicas(0))
.put(newIndexMetaDataBuilder("test2").numberOfShards(10).numberOfReplicas(0))
.build();
@ -77,7 +76,7 @@ public class PreferPrimaryAllocationTests extends ElasticsearchTestCase {
logger.info("increasing the number of replicas to 1, and perform a reroute (to get the replicas allocation going)");
routingTable = RoutingTable.builder().routingTable(routingTable).updateNumberOfReplicas(1).build();
metaData = MetaData.newMetaDataBuilder().metaData(clusterState.metaData()).updateNumberOfReplicas(1).build();
metaData = MetaData.builder(clusterState.metaData()).updateNumberOfReplicas(1).build();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).metaData(metaData).build();
routingTable = strategy.reroute(clusterState).routingTable();
@ -87,7 +86,7 @@ public class PreferPrimaryAllocationTests extends ElasticsearchTestCase {
assertThat(clusterState.routingNodes().shardsWithState(INITIALIZING).size(), equalTo(2));
logger.info("create a new index");
metaData = newMetaDataBuilder().metaData(clusterState.metaData())
metaData = MetaData.builder(clusterState.metaData())
.put(newIndexMetaDataBuilder("new_index").numberOfShards(4).numberOfReplicas(0))
.build();

View File

@ -30,14 +30,12 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
@ -54,7 +52,7 @@ public class PrimaryElectionRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -105,7 +103,7 @@ public class PrimaryElectionRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(2).numberOfReplicas(1))
.build();

View File

@ -30,14 +30,12 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -57,7 +55,7 @@ public class PrimaryNotRelocatedWhileBeingRecoveredTests extends ElasticsearchTe
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(5).numberOfReplicas(1))
.build();

View File

@ -44,7 +44,6 @@ import java.util.Random;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
@ -60,20 +59,20 @@ public class RandomAllocationDeciderTests extends ElasticsearchTestCase {
* already allocated on a node and balances the cluster to gain optimal
* balance.*/
@Test
public void testRandomDecicions() {
public void testRandomDecisions() {
RandomAllocationDecider randomAllocationDecider = new RandomAllocationDecider(getRandom());
AllocationService strategy = new AllocationService(settingsBuilder().build(), new AllocationDeciders(ImmutableSettings.EMPTY,
new HashSet<AllocationDecider>(Arrays.asList(new SameShardAllocationDecider(ImmutableSettings.EMPTY),
randomAllocationDecider))), new ShardsAllocators(), ClusterInfoService.EMPTY);
int indices = between(1, 20);
Builder metaBuilder = newMetaDataBuilder();
Builder metaBuilder = MetaData.builder();
int maxNumReplicas = 1;
int totalNumShards = 0;
for (int i = 0; i < indices; i++) {
int replicas = between(0, 6);
maxNumReplicas = Math.max(maxNumReplicas, replicas+1);
maxNumReplicas = Math.max(maxNumReplicas, replicas + 1);
int numShards = between(1, 20);
totalNumShards += numShards * (replicas+1);
totalNumShards += numShards * (replicas + 1);
metaBuilder.put(newIndexMetaDataBuilder("INDEX_" + i).numberOfShards(numShards).numberOfReplicas(replicas));
}
@ -124,7 +123,7 @@ public class RandomAllocationDeciderTests extends ElasticsearchTestCase {
ClusterState.Builder stateBuilder = newClusterStateBuilder().state(clusterState);
DiscoveryNodes.Builder newNodesBuilder = newNodesBuilder();
newNodesBuilder.putAll(clusterState.nodes());
for (int j = 0; j < (maxNumReplicas-clusterState.nodes().size()); j++) {
for (int j = 0; j < (maxNumReplicas - clusterState.nodes().size()); j++) {
logger.info("adding node [{}]", nodeIdCounter);
newNodesBuilder.put(newNode("NODE_" + (nodeIdCounter++)));
}
@ -189,20 +188,20 @@ public class RandomAllocationDeciderTests extends ElasticsearchTestCase {
return Decision.YES;
}
switch (random.nextInt(10)) {
case 9:
case 8:
case 7:
case 6:
case 5:
return Decision.NO;
case 4:
return Decision.THROTTLE;
case 3:
case 2:
case 1:
return Decision.YES;
default:
return Decision.ALWAYS;
case 9:
case 8:
case 7:
case 6:
case 5:
return Decision.NO;
case 4:
return Decision.THROTTLE;
case 3:
case 2:
case 1:
return Decision.YES;
default:
return Decision.ALWAYS;
}
}

View File

@ -31,13 +31,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
@ -58,7 +56,7 @@ public class RebalanceAfterActiveTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(5).numberOfReplicas(1))
.build();

View File

@ -30,13 +30,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
@ -53,7 +51,7 @@ public class ReplicaAllocatedAfterPrimaryTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();

View File

@ -14,7 +14,6 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
@ -32,7 +31,7 @@ public class SameShardRoutingTests extends ElasticsearchTestCase {
public void sameHost() {
AllocationService strategy = new AllocationService(settingsBuilder().put(SameShardAllocationDecider.SAME_HOST_SETTING, true).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(2).numberOfReplicas(1))
.build();

View File

@ -31,13 +31,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
public class ShardVersioningTests extends ElasticsearchTestCase {
@ -48,7 +46,7 @@ public class ShardVersioningTests extends ElasticsearchTestCase {
public void simple() {
AllocationService strategy = new AllocationService(settingsBuilder().put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString()).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();

View File

@ -35,13 +35,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -56,7 +54,7 @@ public class ShardsLimitAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").settings(ImmutableSettings.settingsBuilder()
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 4)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
@ -106,7 +104,7 @@ public class ShardsLimitAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").settings(ImmutableSettings.settingsBuilder()
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 5)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
@ -131,7 +129,7 @@ public class ShardsLimitAllocationTests extends ElasticsearchTestCase {
assertThat(clusterState.readOnlyRoutingNodes().numberOfShardsOfType(STARTED), equalTo(5));
logger.info("add another index with 5 shards");
metaData = newMetaDataBuilder().metaData(metaData)
metaData = MetaData.builder(metaData)
.put(newIndexMetaDataBuilder("test1").settings(ImmutableSettings.settingsBuilder()
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 5)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
@ -162,7 +160,7 @@ public class ShardsLimitAllocationTests extends ElasticsearchTestCase {
}
logger.info("update " + ShardsLimitAllocationDecider.INDEX_TOTAL_SHARDS_PER_NODE + " for test, see that things move");
metaData = newMetaDataBuilder().metaData(metaData)
metaData = MetaData.builder(metaData)
.put(newIndexMetaDataBuilder("test").settings(ImmutableSettings.settingsBuilder()
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 5)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)

View File

@ -39,13 +39,11 @@ import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Sets.newHashSet;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
/**
@ -61,7 +59,7 @@ public class SingleShardNoReplicasRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(0))
.build();
@ -163,7 +161,7 @@ public class SingleShardNoReplicasRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(0))
.build();
@ -218,7 +216,7 @@ public class SingleShardNoReplicasRoutingTests extends ElasticsearchTestCase {
final int numberOfIndices = 50;
logger.info("Building initial routing table with " + numberOfIndices + " indices");
MetaData.Builder metaDataBuilder = newMetaDataBuilder();
MetaData.Builder metaDataBuilder = MetaData.builder();
for (int i = 0; i < numberOfIndices; i++) {
metaDataBuilder.put(newIndexMetaDataBuilder("test" + i).numberOfShards(1).numberOfReplicas(0));
}
@ -331,7 +329,7 @@ public class SingleShardNoReplicasRoutingTests extends ElasticsearchTestCase {
final int numberOfIndices = 10;
logger.info("Building initial routing table with " + numberOfIndices + " indices");
MetaData.Builder metaDataBuilder = newMetaDataBuilder();
MetaData.Builder metaDataBuilder = MetaData.builder();
for (int i = 0; i < numberOfIndices; i++) {
metaDataBuilder.put(newIndexMetaDataBuilder("test" + i).numberOfShards(1).numberOfReplicas(0));
}

View File

@ -30,13 +30,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
@ -53,7 +51,7 @@ public class SingleShardOneReplicaRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();

View File

@ -30,13 +30,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
/**
@ -60,7 +58,7 @@ public class TenShardsOneReplicaRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(10).numberOfReplicas(1))
.build();

View File

@ -29,13 +29,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -54,7 +52,7 @@ public class ThrottlingAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(10).numberOfReplicas(1))
.build();
@ -115,7 +113,7 @@ public class ThrottlingAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(5).numberOfReplicas(1))
.build();

View File

@ -11,13 +11,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
/**
@ -33,7 +31,7 @@ public class UpdateNumberOfReplicasTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -85,7 +83,7 @@ public class UpdateNumberOfReplicasTests extends ElasticsearchTestCase {
routingNodes = clusterState.routingNodes();
prevRoutingTable = routingTable;
routingTable = RoutingTable.builder().routingTable(routingTable).updateNumberOfReplicas(2).build();
metaData = MetaData.newMetaDataBuilder().metaData(clusterState.metaData()).updateNumberOfReplicas(2).build();
metaData = MetaData.builder(clusterState.metaData()).updateNumberOfReplicas(2).build();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).metaData(metaData).build();
assertThat(clusterState.metaData().index("test").numberOfReplicas(), equalTo(2));
@ -137,7 +135,7 @@ public class UpdateNumberOfReplicasTests extends ElasticsearchTestCase {
routingNodes = clusterState.routingNodes();
prevRoutingTable = routingTable;
routingTable = RoutingTable.builder().routingTable(routingTable).updateNumberOfReplicas(1).build();
metaData = MetaData.newMetaDataBuilder().metaData(clusterState.metaData()).updateNumberOfReplicas(1).build();
metaData = MetaData.builder(clusterState.metaData()).updateNumberOfReplicas(1).build();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).metaData(metaData).build();
assertThat(clusterState.metaData().index("test").numberOfReplicas(), equalTo(1));

View File

@ -41,7 +41,6 @@ import java.util.Map;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
@ -88,7 +87,7 @@ public class DiskThresholdDeciderTests extends ElasticsearchTestCase {
.put("cluster.routing.allocation.cluster_concurrent_rebalance", -1)
.build(), deciders, new ShardsAllocators(), cis);
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -277,7 +276,7 @@ public class DiskThresholdDeciderTests extends ElasticsearchTestCase {
.put("cluster.routing.allocation.cluster_concurrent_rebalance", -1)
.build(), deciders, new ShardsAllocators(), cis);
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -463,7 +462,7 @@ public class DiskThresholdDeciderTests extends ElasticsearchTestCase {
.put("cluster.routing.allocation.cluster_concurrent_rebalance", -1)
.build(), deciders, new ShardsAllocators(), cis);
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(0))
.build();
@ -525,7 +524,7 @@ public class DiskThresholdDeciderTests extends ElasticsearchTestCase {
.put("cluster.routing.allocation.cluster_concurrent_rebalance", -1)
.build(), deciders, new ShardsAllocators(), cis);
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(0))
.build();

View File

@ -34,9 +34,7 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -46,7 +44,7 @@ public class ClusterSerializationTests extends ElasticsearchTestCase {
@Test
public void testClusterStateSerialization() throws Exception {
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(10).numberOfReplicas(1))
.build();
@ -69,7 +67,7 @@ public class ClusterSerializationTests extends ElasticsearchTestCase {
@Test
public void testRoutingTableSerialization() throws Exception {
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(10).numberOfReplicas(1))
.build();

View File

@ -35,13 +35,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
public class RoutingIteratorTests extends ElasticsearchTestCase {
@ -87,7 +85,7 @@ public class RoutingIteratorTests extends ElasticsearchTestCase {
@Test
public void testIterator1() {
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(2))
.build();
RoutingTable routingTable = routingTable()
@ -121,7 +119,7 @@ public class RoutingIteratorTests extends ElasticsearchTestCase {
@Test
public void testIterator2() {
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();
@ -224,7 +222,7 @@ public class RoutingIteratorTests extends ElasticsearchTestCase {
@Test
public void testRandomRouting() {
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();
@ -258,7 +256,7 @@ public class RoutingIteratorTests extends ElasticsearchTestCase {
.put("cluster.routing.allocation.awareness.attributes", "rack_id,zone")
.build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -307,7 +305,7 @@ public class RoutingIteratorTests extends ElasticsearchTestCase {
.put("cluster.routing.allocation.concurrent_recoveries", 10)
.build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(5).numberOfReplicas(1))
.build();