Skip to content

Commit

Permalink
sample usage
Browse files Browse the repository at this point in the history
  • Loading branch information
idegtiarenko committed Jan 17, 2024
1 parent f4c27cf commit 3f8fe37
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.elasticsearch.cluster.routing.RoutingNodes;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.TestShardRouting;
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider;
import org.elasticsearch.common.UUIDs;
Expand All @@ -44,6 +43,7 @@
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.TestShardRouting.aShardRouting;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.oneOf;
Expand Down Expand Up @@ -434,8 +434,8 @@ private void runMoveShardRolesTest(ShardRouting.Role primaryRole, ShardRouting.R
var shardId = new ShardId(indexMetadata.getIndex(), 0);

var indexRoutingTable = IndexRoutingTable.builder(indexMetadata.getIndex())
.addShard(TestShardRouting.newShardRouting(shardId, "node-1", null, true, STARTED, primaryRole))
.addShard(TestShardRouting.newShardRouting(shardId, "node-2", null, false, STARTED, replicaRole))
.addShard(aShardRouting(shardId, "node-1", true, STARTED).withRole(primaryRole).build())
.addShard(aShardRouting(shardId, "node-2", false, STARTED).withRole(replicaRole).build())
.build();

var node1 = newNode("node-1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.stream.Collectors;

import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_CREATION_DATE;
import static org.elasticsearch.cluster.routing.TestShardRouting.aShardRouting;
import static org.elasticsearch.test.ESTestCase.indexSettings;
import static org.elasticsearch.test.ESTestCase.randomAlphaOfLength;
import static org.elasticsearch.test.ESTestCase.randomFrom;
Expand Down Expand Up @@ -399,15 +400,7 @@ public static ClusterState stateWithAssignedPrimariesAndReplicas(
);
for (int replica = 0; replica < replicaRoles.size(); replica++) {
indexShardRoutingBuilder.addShard(
TestShardRouting.newShardRouting(
index,
i,
newNode(replica + 1).getId(),
null,
false,
ShardRoutingState.STARTED,
replicaRoles.get(replica)
)
aShardRouting(index, i, newNode(replica + 1).getId(), false, ShardRoutingState.STARTED).withRole(replicaRoles.get(replica)).build()
);
}
indexRoutingTableBuilder.addIndexShard(indexShardRoutingBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
*/
public class TestShardRouting {

public static Builder aSharRouting(String index, int shardId, String currentNodeId, boolean primary, ShardRoutingState state) {
public static Builder aShardRouting(String index, int shardId, String currentNodeId, boolean primary, ShardRoutingState state) {
return new Builder(new ShardId(index, IndexMetadata.INDEX_UUID_NA_VALUE, shardId), currentNodeId, primary, state);
}

public static Builder aSharRouting(ShardId shardId, String currentNodeId, boolean primary, ShardRoutingState state) {
public static Builder aShardRouting(ShardId shardId, String currentNodeId, boolean primary, ShardRoutingState state) {
return new Builder(shardId, currentNodeId, primary, state);
}

Expand Down Expand Up @@ -218,27 +218,7 @@ public static ShardRouting newShardRouting(
currentNodeId,
relocatingNodeId,
primary,
state,
ShardRouting.Role.DEFAULT
);
}

public static ShardRouting newShardRouting(
String index,
int shardId,
String currentNodeId,
String relocatingNodeId,
boolean primary,
ShardRoutingState state,
ShardRouting.Role role
) {
return newShardRouting(
new ShardId(index, IndexMetadata.INDEX_UUID_NA_VALUE, shardId),
currentNodeId,
relocatingNodeId,
primary,
state,
role
state
);
}

Expand All @@ -248,17 +228,6 @@ public static ShardRouting newShardRouting(
String relocatingNodeId,
boolean primary,
ShardRoutingState state
) {
return newShardRouting(shardId, currentNodeId, relocatingNodeId, primary, state, ShardRouting.Role.DEFAULT);
}

public static ShardRouting newShardRouting(
ShardId shardId,
String currentNodeId,
String relocatingNodeId,
boolean primary,
ShardRoutingState state,
ShardRouting.Role role
) {
return new ShardRouting(
shardId,
Expand All @@ -271,7 +240,7 @@ public static ShardRouting newShardRouting(
buildRelocationFailureInfo(state),
buildAllocationId(state),
-1,
role
ShardRouting.Role.DEFAULT
);
}

Expand Down

0 comments on commit 3f8fe37

Please sign in to comment.