From 2ea8c1534b0685b779dd42bdd6892635ae49bf79 Mon Sep 17 00:00:00 2001 From: Cihat Keser Date: Wed, 1 Apr 2015 23:27:59 +0200 Subject: [PATCH] bugfix: undocumented (but supported till now) way of passing requested info sections to NodesInfo API has been dropped on the ES side. Adjusted NodesInfo class to use the official way of passing those args. --- .../java/io/searchbox/cluster/NodesInfo.java | 48 ++++++++++++------- .../io/searchbox/cluster/NodesInfoTest.java | 8 ++-- 2 files changed, 36 insertions(+), 20 deletions(-) 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()); } }