diff --git a/jest-common/src/main/java/io/searchbox/cluster/NodesInfo.java b/jest-common/src/main/java/io/searchbox/cluster/NodesInfo.java index 96b3d68c8..55b96d324 100644 --- a/jest-common/src/main/java/io/searchbox/cluster/NodesInfo.java +++ b/jest-common/src/main/java/io/searchbox/cluster/NodesInfo.java @@ -2,6 +2,11 @@ import io.searchbox.action.AbstractMultiINodeActionBuilder; import io.searchbox.action.GenericResultAbstractAction; +import org.apache.commons.lang3.StringUtils; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; /** * @author Dogukan Sonmez @@ -12,15 +17,15 @@ public class NodesInfo extends GenericResultAbstractAction { public NodesInfo(Builder builder) { super(builder); setPathToResult("nodes"); - setURI(buildURI()); + setURI(buildURI(builder.requestedInfo)); } - @Override - protected String buildURI() { + protected String buildURI(Collection requestedInfo) { StringBuilder sb = new StringBuilder(super.buildURI()); - sb.append("/_nodes") - .append("/") - .append(nodes); + sb.append("/_nodes").append("/").append(nodes); + if (!requestedInfo.isEmpty()) { + sb.append("/").append(StringUtils.join(requestedInfo, ",")); + } return sb.toString(); } @@ -31,46 +36,57 @@ public String getRestMethodName() { public static class Builder extends AbstractMultiINodeActionBuilder { + Set requestedInfo = new HashSet(); + public Builder settings(boolean value) { - return setParameter("settings", value); + return setRequestedInfoSection("settings", value); } public Builder os(boolean value) { - return setParameter("os", value); + return setRequestedInfoSection("os", value); } public Builder process(boolean value) { - return setParameter("process", value); + return setRequestedInfoSection("process", value); } public Builder jvm(boolean value) { - return setParameter("jvm", value); + return setRequestedInfoSection("jvm", value); } public Builder threadPool(boolean value) { - return setParameter("thread_pool", value); + return setRequestedInfoSection("thread_pool", value); } public Builder network(boolean value) { - return setParameter("network", value); + return setRequestedInfoSection("network", value); } public Builder transport(boolean value) { - return setParameter("transport", value); + return setRequestedInfoSection("transport", value); } public Builder http(boolean value) { - return setParameter("http", value); + return setRequestedInfoSection("http", value); } - public Builder plugin(boolean value) { - return setParameter("plugin", value); + public Builder plugins(boolean value) { + return setRequestedInfoSection("plugins", value); } @Override public NodesInfo build() { return new NodesInfo(this); } + + private Builder setRequestedInfoSection(String section, boolean set) { + if (set) { + requestedInfo.add(section); + } else if (requestedInfo.contains(section)) { + requestedInfo.remove(section); + } + return this; + } } } diff --git a/jest-common/src/test/java/io/searchbox/cluster/NodesInfoTest.java b/jest-common/src/test/java/io/searchbox/cluster/NodesInfoTest.java index 50efa0cda..4d5a4bcac 100644 --- a/jest-common/src/test/java/io/searchbox/cluster/NodesInfoTest.java +++ b/jest-common/src/test/java/io/searchbox/cluster/NodesInfoTest.java @@ -24,13 +24,13 @@ public void getURIWithOnlyOneNode() { @Test public void getURIWithOneNodeAndOneInfo() { NodesInfo nodesInfo = new NodesInfo.Builder().addNode("twitter").os(true).build(); - assertEquals("/_nodes/twitter?os=true", nodesInfo.getURI()); + assertEquals("/_nodes/twitter/os", nodesInfo.getURI()); } @Test public void getURIWithOnlyOneType() { NodesInfo nodesInfo = new NodesInfo.Builder().os(true).build(); - assertEquals("/_nodes/_all?os=true", nodesInfo.getURI()); + assertEquals("/_nodes/_all/os", nodesInfo.getURI()); } @Test @@ -42,7 +42,7 @@ public void getURIWithOnlyMultipleNode() { @Test public void getURIWithOnlyMultipleType() { NodesInfo nodesInfo = new NodesInfo.Builder().os(true).process(true).build(); - assertEquals("/_nodes/_all?process=true&os=true", nodesInfo.getURI()); + assertEquals("/_nodes/_all/process,os", nodesInfo.getURI()); } @Test @@ -53,7 +53,7 @@ public void getURIWithMultipleNodeAndTypes() { .os(true) .process(true) .build(); - assertEquals("/_nodes/twitter,jest?process=true&os=true", nodesInfo.getURI()); + assertEquals("/_nodes/twitter,jest/process,os", nodesInfo.getURI()); } }