Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit 1874903

Browse files
author
Cihat Keser
committed
Implemented cluster State action.
1 parent 6a47332 commit 1874903

File tree

3 files changed

+141
-1
lines changed

3 files changed

+141
-1
lines changed
+69-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,77 @@
11
package io.searchbox.cluster;
22

3+
import io.searchbox.AbstractAction;
4+
35
/**
46
* @author Dogukan Sonmez
7+
* @author cihat keser
58
*/
9+
public class State extends AbstractAction {
10+
11+
public State(Builder builder) {
12+
super(builder);
13+
setURI(buildURI());
14+
}
15+
16+
@Override
17+
protected String buildURI() {
18+
StringBuilder sb = new StringBuilder(super.buildURI());
19+
sb.append("/_cluster/state");
20+
return sb.toString();
21+
}
22+
23+
@Override
24+
public String getRestMethodName() {
25+
return "GET";
26+
}
27+
28+
public static class Builder extends AbstractAction.Builder<State, Builder> {
29+
30+
/**
31+
* Set to true to filter out the routing_table part of the response.
32+
*/
33+
public Builder filterRoutingTable(boolean value) {
34+
return setParameter("filter_routing_table", value);
35+
}
36+
37+
/**
38+
* Set to true to filter out the metadata part of the response.
39+
*/
40+
public Builder filterMetadata(boolean value) {
41+
return setParameter("filter_metadata", value);
42+
}
43+
44+
/**
45+
* Set to true to filter out the blocks part of the response.
46+
*/
47+
public Builder filterBlocks(boolean value) {
48+
return setParameter("filter_blocks", value);
49+
}
50+
51+
/**
52+
* When not filtering metadata, a comma separated list of indices to include in the response.
53+
*/
54+
public Builder filterIndices(String value) {
55+
return setParameter("filter_indices", value);
56+
}
57+
58+
/**
59+
* Set to true to filter out the nodes part of the response.
60+
*/
61+
public Builder filterNodes(boolean value) {
62+
return setParameter("filter_nodes", value);
63+
}
664

65+
/**
66+
* For debugging purposes, you can retrieve the cluster state local to a particular node.
67+
*/
68+
public Builder local(boolean value) {
69+
return setParameter("local", value);
70+
}
771

8-
public class State {
72+
@Override
73+
public State build() {
74+
return new State(this);
75+
}
76+
}
977
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package io.searchbox.cluster;
2+
3+
import com.github.tlrx.elasticsearch.test.annotations.ElasticsearchIndex;
4+
import com.github.tlrx.elasticsearch.test.annotations.ElasticsearchNode;
5+
import com.github.tlrx.elasticsearch.test.support.junit.runners.ElasticsearchRunner;
6+
import com.google.gson.JsonObject;
7+
import io.searchbox.client.JestResult;
8+
import io.searchbox.common.AbstractIntegrationTest;
9+
import org.junit.Test;
10+
import org.junit.runner.RunWith;
11+
12+
import java.io.IOException;
13+
14+
import static junit.framework.Assert.*;
15+
16+
/**
17+
* @author cihat keser
18+
*/
19+
@RunWith(ElasticsearchRunner.class)
20+
@ElasticsearchNode
21+
public class StateIntegrationTest extends AbstractIntegrationTest {
22+
23+
@Test
24+
@ElasticsearchIndex
25+
public void clusterState() throws IOException {
26+
JestResult result = client.execute(new State.Builder().build());
27+
assertNotNull(result);
28+
assertTrue(result.isSucceeded());
29+
30+
JsonObject resultJson = result.getJsonObject();
31+
assertNotNull(resultJson);
32+
assertNotNull(resultJson.getAsJsonObject("nodes"));
33+
assertNotNull(resultJson.getAsJsonObject("routing_table"));
34+
assertNotNull(resultJson.getAsJsonObject("metadata"));
35+
assertNotNull(resultJson.getAsJsonObject("blocks"));
36+
}
37+
38+
@Test
39+
@ElasticsearchIndex
40+
public void clusterStateWithFilterMetadata() throws IOException {
41+
JestResult result = client.execute(new State.Builder().filterMetadata(true).build());
42+
assertNotNull(result);
43+
assertTrue(result.isSucceeded());
44+
45+
JsonObject resultJson = result.getJsonObject();
46+
assertNotNull(resultJson);
47+
assertNotNull(resultJson.getAsJsonObject("nodes"));
48+
assertNotNull(resultJson.getAsJsonObject("routing_table"));
49+
assertNull(resultJson.getAsJsonObject("metadata"));
50+
assertNotNull(resultJson.getAsJsonObject("blocks"));
51+
}
52+
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.searchbox.cluster;
2+
3+
import io.searchbox.Action;
4+
import org.junit.Test;
5+
6+
import static org.junit.Assert.assertEquals;
7+
8+
/**
9+
* @author cihat keser
10+
*/
11+
public class StateTest {
12+
13+
@Test
14+
public void testUriGeneration() {
15+
Action action = new State.Builder().build();
16+
assertEquals("/_cluster/state", action.getURI());
17+
}
18+
19+
}

0 commit comments

Comments
 (0)