Reroute extends GenericResultAbstractAction { protected Reroute(Builder builder) { super(builder); List<Map> actions = new LinkedList<>(); for (RerouteCommand rerouteCommand : builder.commandList) { String type = rerouteCommand.getType(); Map<String, Object> data = rerouteCommand.getData(); actions.add(ImmutableMap.of(type, data)); } this.payload = ImmutableMap.<String, Object>of("commands", actions); } protected  Reroute(Builder builder); @Override String getRestMethodName();  }
@Test public void reroute() throws JSONException { List<RerouteCommand> moveCommands = new LinkedList<RerouteCommand>(); moveCommands.add(new RerouteMove("index1", 1, "node1", "node2")); moveCommands.add(new RerouteCancel("index2", 1, "node2", true)); moveCommands.add(new RerouteAllocateReplica("index3", 1, "node3")); Reroute reroute = new Reroute.Builder(moveCommands).build(); assertEquals("/_cluster/reroute", reroute.getURI(ElasticsearchVersion.UNKNOWN)); assertEquals("POST", reroute.getRestMethodName()); String expectedData = "{ \"commands\": [" + "{ \"move\": { \"index\": \"index1\", \"shard\": 1, \"from_node\": \"node1\", \"to_node\": \"node2\" } }, " + "{ \"cancel\": { \"index\": \"index2\", \"shard\": 1, \"node\": \"node2\", \"allow_primary\": true } }," + "{ \"allocate_replica\": { \"index\": \"index3\", \"shard\": 1, \"node\": \"node3\" } }" + "] }"; JSONAssert.assertEquals(expectedData, reroute.getData(new Gson()), false); }