Skip to content

Commit

Permalink
Merge pull request searchbox-io#7 from logzio/add-cat-recovery
Browse files Browse the repository at this point in the history
Add cat recovery
  • Loading branch information
ofir76 authored Apr 11, 2018
2 parents dfbb61b + 42d2ba6 commit e3af9b9
Show file tree
Hide file tree
Showing 159 changed files with 927 additions and 548 deletions.
2 changes: 1 addition & 1 deletion jest-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<parent>
<groupId>io.searchbox</groupId>
<artifactId>jest-parent</artifactId>
<version>5.3.4-Logzio-2</version>
<version>5.3.4-Logzio-3</version>
</parent>

<dependencies>
Expand Down
32 changes: 19 additions & 13 deletions jest-common/src/main/java/io/searchbox/action/AbstractAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.google.gson.JsonSyntaxException;
import io.searchbox.annotations.JestId;
import io.searchbox.client.JestResult;
import io.searchbox.client.config.ElasticsearchVersion;
import io.searchbox.params.Parameters;
import io.searchbox.strings.StringUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -45,7 +46,6 @@ public abstract class AbstractAction<T extends JestResult> implements Action<T>
private final ConcurrentMap<String, Object> headerMap = new ConcurrentHashMap<String, Object>();
private final Multimap<String, Object> parameterMap = LinkedHashMultimap.create();
private final Set<String> cleanApiParameters = new LinkedHashSet<String>();
private String URI;

public AbstractAction() {
}
Expand Down Expand Up @@ -139,8 +139,8 @@ public Map<String, Object> getHeaders() {
}

@Override
public String getURI() {
String finalUri = URI;
public String getURI(ElasticsearchVersion elasticsearchVersion) {
String finalUri = buildURI(elasticsearchVersion);
if (!parameterMap.isEmpty() || !cleanApiParameters.isEmpty()) {
try {
finalUri += buildQueryString();
Expand All @@ -153,10 +153,6 @@ public String getURI() {
return finalUri;
}

protected void setURI(String URI) {
this.URI = URI;
}

@Override
public String getData(Gson gson) {
if (payload == null) {
Expand All @@ -173,14 +169,20 @@ public String getPathToResult() {
return null;
}

protected String buildURI() {
protected String buildURI(ElasticsearchVersion elasticsearchVersion) {
StringBuilder sb = new StringBuilder();

try {
if (!StringUtils.isBlank(indexName)) {
if (StringUtils.isNotBlank(indexName)) {
sb.append(URLEncoder.encode(indexName, CHARSET));

if (!StringUtils.isBlank(typeName)) {
String commandExtension = getURLCommandExtension(elasticsearchVersion);

if (StringUtils.isNotBlank(commandExtension)) {
sb.append("/").append(URLEncoder.encode(commandExtension, CHARSET));
}

if (StringUtils.isNotBlank(typeName)) {
sb.append("/").append(URLEncoder.encode(typeName, CHARSET));
}
}
Expand All @@ -193,6 +195,10 @@ protected String buildURI() {
return sb.toString();
}

protected String getURLCommandExtension(ElasticsearchVersion elasticsearchVersion) {
return null;
}

protected String buildQueryString() throws UnsupportedEncodingException {
StringBuilder queryString = new StringBuilder();

Expand All @@ -217,14 +223,14 @@ protected String buildQueryString() throws UnsupportedEncodingException {
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("uri", getURI())
.add("uri", getURI(ElasticsearchVersion.UNKNOWN))
.add("method", getRestMethodName())
.toString();
}

@Override
public int hashCode() {
return Objects.hash(getURI(), getRestMethodName(), getHeaders(), payload);
return Objects.hash(getURI(ElasticsearchVersion.UNKNOWN), getRestMethodName(), getHeaders(), payload);
}

@Override
Expand All @@ -240,7 +246,7 @@ public boolean equals(Object obj) {
}

AbstractAction rhs = (AbstractAction) obj;
return Objects.equals(getURI(), rhs.getURI())
return Objects.equals(getURI(ElasticsearchVersion.UNKNOWN), rhs.getURI(ElasticsearchVersion.UNKNOWN))
&& Objects.equals(getRestMethodName(), rhs.getRestMethodName())
&& Objects.equals(getHeaders(), rhs.getHeaders())
&& Objects.equals(payload, rhs.payload);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.searchbox.action;

import io.searchbox.client.JestResult;
import io.searchbox.client.config.ElasticsearchVersion;
import io.searchbox.strings.StringUtils;

import java.io.UnsupportedEncodingException;
Expand Down Expand Up @@ -36,10 +37,10 @@ public String getId() {
}

@Override
protected String buildURI() {
StringBuilder sb = new StringBuilder(super.buildURI());
protected String buildURI(ElasticsearchVersion elasticsearchVersion) {
StringBuilder sb = new StringBuilder(super.buildURI(elasticsearchVersion));

if (!StringUtils.isBlank(id)) {
if (StringUtils.isNotBlank(id)) {
try {
sb.append("/").append(URLEncoder.encode(id, CHARSET));
} catch (UnsupportedEncodingException e) {
Expand Down
5 changes: 3 additions & 2 deletions jest-common/src/main/java/io/searchbox/action/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.Gson;
import io.searchbox.client.JestResult;
import io.searchbox.client.config.ElasticsearchVersion;

import java.util.Map;

Expand All @@ -10,10 +11,10 @@
*/
public interface Action<T extends JestResult> {

String getURI();

String getRestMethodName();

String getURI(ElasticsearchVersion elasticsearchVersion);

String getData(Gson gson);

String getPathToResult();
Expand Down
7 changes: 7 additions & 0 deletions jest-common/src/main/java/io/searchbox/client/JestResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,11 @@ protected String[] getKeys() {
return pathToResult == null ? null : pathToResult.split("/");
}

@Override
public String toString() {
return "Result: " + getJsonString()
+ ", isSucceeded: " + isSucceeded()
+ ", response code: " + getResponseCode()
+ ", error message: " + getErrorMessage();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.searchbox.client.config;

public enum ElasticsearchVersion {

UNKNOWN,
V2,
V55
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.searchbox.action.AbstractAction;
import io.searchbox.action.GenericResultAbstractAction;
import io.searchbox.client.config.ElasticsearchVersion;

/**
* Retrieve cluster wide settings.
Expand All @@ -12,11 +13,10 @@ public class GetSettings extends GenericResultAbstractAction {

protected GetSettings(Builder builder) {
super(builder);
setURI(buildURI());
}

protected String buildURI() {
return super.buildURI() + "/_cluster/settings";
protected String buildURI(ElasticsearchVersion elasticsearchVersion) {
return super.buildURI(elasticsearchVersion) + "/_cluster/settings";
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions jest-common/src/main/java/io/searchbox/cluster/Health.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.base.Preconditions;
import io.searchbox.action.AbstractMultiIndexActionBuilder;
import io.searchbox.action.GenericResultAbstractAction;
import io.searchbox.client.config.ElasticsearchVersion;
import io.searchbox.strings.StringUtils;

import java.io.UnsupportedEncodingException;
Expand Down Expand Up @@ -43,15 +44,14 @@ public String getKey() {

protected Health(Builder builder) {
super(builder);
setURI(buildURI());
}

@Override
protected String buildURI() {
protected String buildURI(ElasticsearchVersion elasticsearchVersion) {
StringBuilder sb = new StringBuilder("/_cluster/health/");

try {
if (!StringUtils.isBlank(indexName)) {
if (StringUtils.isNotBlank(indexName)) {
sb.append(URLEncoder.encode(indexName, CHARSET));
}
} catch (UnsupportedEncodingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.JsonObject;
import io.searchbox.action.AbstractMultiINodeActionBuilder;
import io.searchbox.action.GenericResultAbstractAction;
import io.searchbox.client.config.ElasticsearchVersion;

/**
* Allows to get the current hot threads on each node in the cluster.
Expand All @@ -15,12 +16,11 @@ public class NodesHotThreads extends GenericResultAbstractAction {

protected NodesHotThreads(Builder builder) {
super(builder);
setURI(buildURI());
}

@Override
protected String buildURI() {
return super.buildURI() + "/_nodes/" +
protected String buildURI(ElasticsearchVersion elasticsearchVersion) {
return super.buildURI(elasticsearchVersion) + "/_nodes/" +
nodes +
"/hot_threads";
}
Expand Down
6 changes: 3 additions & 3 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,7 @@

import io.searchbox.action.AbstractMultiINodeActionBuilder;
import io.searchbox.action.GenericResultAbstractAction;
import io.searchbox.client.config.ElasticsearchVersion;

/**
* @author Dogukan Sonmez
Expand All @@ -11,11 +12,10 @@ public class NodesInfo extends GenericResultAbstractAction {

protected NodesInfo(Builder builder) {
super(builder);
setURI(buildURI());
}

protected String buildURI() {
return super.buildURI() + "/_nodes/" + nodes;
protected String buildURI(ElasticsearchVersion elasticsearchVersion) {
return super.buildURI(elasticsearchVersion) + "/_nodes/" + nodes;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.searchbox.action.AbstractMultiINodeActionBuilder;
import io.searchbox.action.GenericResultAbstractAction;
import io.searchbox.client.config.ElasticsearchVersion;

/**
* @author Dogukan Sonmez
Expand All @@ -11,12 +12,11 @@ public class NodesShutdown extends GenericResultAbstractAction {

protected NodesShutdown(Builder builder) {
super(builder);
setURI(buildURI());
}

@Override
protected String buildURI() {
return super.buildURI() + "/_nodes/" +
protected String buildURI(ElasticsearchVersion elasticsearchVersion) {
return super.buildURI(elasticsearchVersion) + "/_nodes/" +
nodes +
"/_shutdown";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.searchbox.action.AbstractMultiINodeActionBuilder;
import io.searchbox.action.GenericResultAbstractAction;
import io.searchbox.client.config.ElasticsearchVersion;

/**
* @author Dogukan Sonmez
Expand All @@ -11,12 +12,11 @@ public class NodesStats extends GenericResultAbstractAction {

protected NodesStats(Builder builder) {
super(builder);
setURI(buildURI());
}

@Override
protected String buildURI() {
return super.buildURI() + "/_nodes/" +
protected String buildURI(ElasticsearchVersion elasticsearchVersion) {
return super.buildURI(elasticsearchVersion) + "/_nodes/" +
nodes +
"/stats";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import io.searchbox.action.AbstractAction;
import io.searchbox.action.GenericResultAbstractAction;
import io.searchbox.client.config.ElasticsearchVersion;

public class PendingClusterTasks extends GenericResultAbstractAction {
protected PendingClusterTasks(Builder builder) {
super(builder);
setURI(buildURI());
}

@Override
protected String buildURI() {
return super.buildURI() + "/_cluster/pending_tasks";
protected String buildURI(ElasticsearchVersion elasticsearchVersion) {
return super.buildURI(elasticsearchVersion) + "/_cluster/pending_tasks";
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions jest-common/src/main/java/io/searchbox/cluster/Reroute.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.ImmutableMap;
import io.searchbox.action.AbstractAction;
import io.searchbox.action.GenericResultAbstractAction;
import io.searchbox.client.config.ElasticsearchVersion;
import io.searchbox.cluster.reroute.RerouteCommand;

import java.util.Collection;
Expand All @@ -14,7 +15,6 @@ public class Reroute extends GenericResultAbstractAction {

protected Reroute(Builder builder) {
super(builder);
setURI(buildURI());

List<Map> actions = new LinkedList<>();
for (RerouteCommand rerouteCommand : builder.commandList) {
Expand All @@ -26,8 +26,8 @@ protected Reroute(Builder builder) {
}

@Override
protected String buildURI() {
return super.buildURI() + "/_cluster/reroute";
protected String buildURI(ElasticsearchVersion elasticsearchVersion) {
return super.buildURI(elasticsearchVersion) + "/_cluster/reroute";
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions jest-common/src/main/java/io/searchbox/cluster/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.searchbox.action.AbstractAction;
import io.searchbox.action.GenericResultAbstractAction;
import io.searchbox.client.config.ElasticsearchVersion;

/**
* @author Dogukan Sonmez
Expand All @@ -11,12 +12,11 @@ public class State extends GenericResultAbstractAction {

protected State(Builder builder) {
super(builder);
setURI(buildURI());
}

@Override
protected String buildURI() {
return super.buildURI() + "/_cluster/state";
protected String buildURI(ElasticsearchVersion elasticsearchVersion) {
return super.buildURI(elasticsearchVersion) + "/_cluster/state";
}

@Override
Expand Down
Loading

0 comments on commit e3af9b9

Please sign in to comment.