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

Commit

Permalink
bugfix: undocumented (but supported till now) way of passing requeste…
Browse files Browse the repository at this point in the history
…d info sections to NodesInfo API has been dropped on the ES side. Adjusted NodesInfo class to use the official way of passing those args.
  • Loading branch information
Cihat Keser committed Apr 1, 2015
1 parent e67f6ab commit 2ea8c15
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
48 changes: 32 additions & 16 deletions jest-common/src/main/java/io/searchbox/cluster/NodesInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String> 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();
}

Expand All @@ -31,46 +36,57 @@ public String getRestMethodName() {

public static class Builder extends AbstractMultiINodeActionBuilder<NodesInfo, Builder> {

Set<String> requestedInfo = new HashSet<String>();

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;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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());
}

}

0 comments on commit 2ea8c15

Please sign in to comment.