update for new 6.3.2.4 version

This commit is contained in:
Jörg Prante 2020-04-06 11:16:33 +02:00
parent 1912c018d5
commit 7b71bf9481
54 changed files with 262 additions and 209 deletions

1
.gitignore vendored
View file

@ -11,4 +11,5 @@
/.project /.project
/.gradle /.gradle
build build
out
plugins plugins

View file

@ -29,7 +29,7 @@ public interface BulkProcessor extends Closeable, Flushable {
/** /**
* A listener for the execution. * A listener for the execution.
*/ */
public interface Listener { interface Listener {
/** /**
* Callback before the bulk is executed. * Callback before the bulk is executed.

View file

@ -317,7 +317,7 @@ public interface ExtendedClient extends Flushable, Closeable {
/** /**
* Force segment merge of an index. * Force segment merge of an index.
* @param indexDefinition th eindex definition * @param indexDefinition the index definition
* @return this * @return this
*/ */
boolean forceMerge(IndexDefinition indexDefinition); boolean forceMerge(IndexDefinition indexDefinition);

View file

@ -2,5 +2,5 @@ package org.xbib.elx.api;
public interface ReadClientProvider<C extends ReadClient> { public interface ReadClientProvider<C extends ReadClient> {
C getReadClient(); C getReadClient();
} }

View file

@ -2,6 +2,7 @@ package org.xbib.elx.common;
import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.elasticsearch.ElasticsearchTimeoutException; import org.elasticsearch.ElasticsearchTimeoutException;
@ -194,16 +195,17 @@ public abstract class AbstractExtendedClient implements ExtendedClient {
@Override @Override
public AbstractExtendedClient init(Settings settings) throws IOException { public AbstractExtendedClient init(Settings settings) throws IOException {
logger.log(Level.INFO, "initializing with settings = " + settings.toDelimitedString(','));
if (client == null) { if (client == null) {
client = createClient(settings); client = createClient(settings);
} }
if (bulkMetric == null) { if (bulkMetric == null) {
this.bulkMetric = new DefaultBulkMetric(); bulkMetric = new DefaultBulkMetric();
this.bulkMetric.init(settings); bulkMetric.init(settings);
} }
if (bulkController == null) { if (bulkController == null) {
this.bulkController = new DefaultBulkController(this, bulkMetric); bulkController = new DefaultBulkController(this, bulkMetric);
this.bulkController.init(settings); bulkController.init(settings);
} }
return this; return this;
} }
@ -235,8 +237,7 @@ public abstract class AbstractExtendedClient implements ExtendedClient {
public String getClusterName() { public String getClusterName() {
ensureActive(); ensureActive();
try { try {
ClusterStateRequest clusterStateRequest = new ClusterStateRequest(); ClusterStateRequest clusterStateRequest = new ClusterStateRequest().clear();
clusterStateRequest.clear();
ClusterStateResponse clusterStateResponse = ClusterStateResponse clusterStateResponse =
client.execute(ClusterStateAction.INSTANCE, clusterStateRequest).actionGet(); client.execute(ClusterStateAction.INSTANCE, clusterStateRequest).actionGet();
return clusterStateResponse.getClusterName().value(); return clusterStateResponse.getClusterName().value();

View file

@ -1,5 +1,8 @@
package org.xbib.elx.common; package org.xbib.elx.common;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -16,6 +19,8 @@ import java.util.ServiceLoader;
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public class ClientBuilder { public class ClientBuilder {
private static final Logger logger = LogManager.getLogger(ClientBuilder.class);
private final ElasticsearchClient client; private final ElasticsearchClient client;
private final Settings.Builder settingsBuilder; private final Settings.Builder settingsBuilder;
@ -97,6 +102,10 @@ public class ClientBuilder {
if (provider == null) { if (provider == null) {
throw new IllegalArgumentException("no provider"); throw new IllegalArgumentException("no provider");
} }
return (C) providerMap.get(provider).getExtendedClient().setClient(client).init(settingsBuilder.build()); Settings settings = settingsBuilder.build();
logger.log(Level.INFO, "settings = " + settings.toDelimitedString(','));
return (C) providerMap.get(provider).getExtendedClient()
.setClient(client)
.init(settings);
} }
} }

View file

@ -49,6 +49,8 @@ public class DefaultBulkController implements BulkController {
private AtomicBoolean active; private AtomicBoolean active;
private boolean enableBulkLogging;
public DefaultBulkController(ExtendedClient client, BulkMetric bulkMetric) { public DefaultBulkController(ExtendedClient client, BulkMetric bulkMetric) {
this.client = client; this.client = client;
this.bulkMetric = bulkMetric; this.bulkMetric = bulkMetric;
@ -76,11 +78,8 @@ public class DefaultBulkController implements BulkController {
ByteSizeValue maxVolumePerRequest = settings.getAsBytesSize(Parameters.MAX_VOLUME_PER_REQUEST.name(), ByteSizeValue maxVolumePerRequest = settings.getAsBytesSize(Parameters.MAX_VOLUME_PER_REQUEST.name(),
ByteSizeValue.parseBytesSizeValue(Parameters.DEFAULT_MAX_VOLUME_PER_REQUEST.getString(), ByteSizeValue.parseBytesSizeValue(Parameters.DEFAULT_MAX_VOLUME_PER_REQUEST.getString(),
"maxVolumePerRequest")); "maxVolumePerRequest"));
if (logger.isInfoEnabled()) { this.enableBulkLogging = settings.getAsBoolean(Parameters.ENABLE_BULK_LOGGING.name(),
logger.info("bulk processor up with maxActionsPerRequest = {} maxConcurrentRequests = {} " + Parameters.ENABLE_BULK_LOGGING.getValue());
"flushIngestInterval = {} maxVolumePerRequest = {}",
maxActionsPerRequest, maxConcurrentRequests, flushIngestInterval, maxVolumePerRequest);
}
this.bulkListener = new BulkListener(); this.bulkListener = new BulkListener();
this.bulkProcessor = DefaultBulkProcessor.builder(client.getClient(), bulkListener) this.bulkProcessor = DefaultBulkProcessor.builder(client.getClient(), bulkListener)
.setBulkActions(maxActionsPerRequest) .setBulkActions(maxActionsPerRequest)
@ -89,6 +88,12 @@ public class DefaultBulkController implements BulkController {
.setBulkSize(maxVolumePerRequest) .setBulkSize(maxVolumePerRequest)
.build(); .build();
this.active.set(true); this.active.set(true);
if (logger.isInfoEnabled()) {
logger.info("bulk processor up with maxActionsPerRequest = {} maxConcurrentRequests = {} " +
"flushIngestInterval = {} maxVolumePerRequest = {} bulk logging = {} logger debug = {} from settings = {}",
maxActionsPerRequest, maxConcurrentRequests, flushIngestInterval, maxVolumePerRequest,
enableBulkLogging, logger.isDebugEnabled(), settings.toDelimitedString(','));
}
} }
@Override @Override
@ -115,6 +120,9 @@ public class DefaultBulkController implements BulkController {
@Override @Override
public void index(IndexRequest indexRequest) { public void index(IndexRequest indexRequest) {
ensureActiveAndBulk(); ensureActiveAndBulk();
if (!active.get()) {
throw new IllegalStateException("inactive");
}
try { try {
if (bulkMetric != null) { if (bulkMetric != null) {
bulkMetric.getCurrentIngest().inc(indexRequest.index(), indexRequest.type(), indexRequest.id()); bulkMetric.getCurrentIngest().inc(indexRequest.index(), indexRequest.type(), indexRequest.id());
@ -237,7 +245,7 @@ public class DefaultBulkController implements BulkController {
private class BulkListener implements DefaultBulkProcessor.Listener { private class BulkListener implements DefaultBulkProcessor.Listener {
private final Logger logger = LogManager.getLogger("org.xbib.elx.BulkProcessor.Listener"); private final Logger logger = LogManager.getLogger(BulkListener.class.getName());
private Throwable lastBulkError = null; private Throwable lastBulkError = null;
@ -252,7 +260,7 @@ public class DefaultBulkController implements BulkController {
bulkMetric.getCurrentIngestNumDocs().inc(n); bulkMetric.getCurrentIngestNumDocs().inc(n);
bulkMetric.getTotalIngestSizeInBytes().inc(request.estimatedSizeInBytes()); bulkMetric.getTotalIngestSizeInBytes().inc(request.estimatedSizeInBytes());
} }
if (logger.isDebugEnabled()) { if (enableBulkLogging && logger.isDebugEnabled()) {
logger.debug("before bulk [{}] [actions={}] [bytes={}] [concurrent requests={}]", logger.debug("before bulk [{}] [actions={}] [bytes={}] [concurrent requests={}]",
executionId, executionId,
request.numberOfActions(), request.numberOfActions(),
@ -282,7 +290,7 @@ public class DefaultBulkController implements BulkController {
} }
} }
} }
if (bulkMetric != null && logger.isDebugEnabled()) { if (enableBulkLogging && logger.isDebugEnabled() && bulkMetric != null) {
logger.debug("after bulk [{}] [succeeded={}] [failed={}] [{}ms] {} concurrent requests", logger.debug("after bulk [{}] [succeeded={}] [failed={}] [{}ms] {} concurrent requests",
executionId, executionId,
bulkMetric.getSucceeded().getCount(), bulkMetric.getSucceeded().getCount(),
@ -291,7 +299,7 @@ public class DefaultBulkController implements BulkController {
l); l);
} }
if (n > 0) { if (n > 0) {
if (logger.isErrorEnabled()) { if (enableBulkLogging && logger.isErrorEnabled()) {
logger.error("bulk [{}] failed with {} failed items, failure message = {}", logger.error("bulk [{}] failed with {} failed items, failure message = {}",
executionId, n, response.buildFailureMessage()); executionId, n, response.buildFailureMessage());
} }
@ -309,7 +317,7 @@ public class DefaultBulkController implements BulkController {
} }
lastBulkError = failure; lastBulkError = failure;
active.set(false); active.set(false);
if (logger.isErrorEnabled()) { if (enableBulkLogging && logger.isErrorEnabled()) {
logger.error("after bulk [" + executionId + "] error", failure); logger.error("after bulk [" + executionId + "] error", failure);
} }
} }

View file

@ -124,7 +124,7 @@ public class DefaultBulkProcessor implements BulkProcessor {
closed = true; closed = true;
if (scheduledFuture != null) { if (scheduledFuture != null) {
FutureUtils.cancel(scheduledFuture); FutureUtils.cancel(scheduledFuture);
this.scheduler.shutdown(); scheduler.shutdown();
} }
if (bulkRequest.numberOfActions() > 0) { if (bulkRequest.numberOfActions() > 0) {
execute(); execute();

View file

@ -2,6 +2,8 @@ package org.xbib.elx.common;
public enum Parameters { public enum Parameters {
ENABLE_BULK_LOGGING(false),
DEFAULT_MAX_ACTIONS_PER_REQUEST(1000), DEFAULT_MAX_ACTIONS_PER_REQUEST(1000),
DEFAULT_MAX_CONCURRENT_REQUESTS(Runtime.getRuntime().availableProcessors()), DEFAULT_MAX_CONCURRENT_REQUESTS(Runtime.getRuntime().availableProcessors()),
@ -18,10 +20,16 @@ public enum Parameters {
FLUSH_INTERVAL("flush_interval"); FLUSH_INTERVAL("flush_interval");
boolean flag;
int num; int num;
String string; String string;
Parameters(boolean flag) {
this.flag = flag;
}
Parameters(int num) { Parameters(int num) {
this.num = num; this.num = num;
} }
@ -30,6 +38,10 @@ public enum Parameters {
this.string = string; this.string = string;
} }
boolean getValue() {
return flag;
}
int getNum() { int getNum() {
return num; return num;
} }

View file

@ -1,4 +1,4 @@
/** /**
* * I/O helpers for Elasticsearch client extensions.
*/ */
package org.xbib.elx.common.io; package org.xbib.elx.common.io;

View file

@ -1,4 +1,4 @@
/** /**
* * Common classes for Elasticsearch client extensions.
*/ */
package org.xbib.elx.common; package org.xbib.elx.common;

View file

@ -1,4 +1,4 @@
/** /**
* * Utilities for Elasticsearch client extensions.
*/ */
package org.xbib.elx.common.util; package org.xbib.elx.common.util;

View file

@ -71,15 +71,14 @@ class AliasTest {
indexRequest = new CreateIndexRequest("test20160103"); indexRequest = new CreateIndexRequest("test20160103");
client.execute(CreateIndexAction.INSTANCE, indexRequest).actionGet(); client.execute(CreateIndexAction.INSTANCE, indexRequest).actionGet();
IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest(); IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
String[] indices = new String[]{"test20160101", "test20160102", "test20160103"}; String[] indices = new String[] { "test20160101", "test20160102", "test20160103" };
String[] aliases = new String[]{alias}; String[] aliases = new String[] { alias };
IndicesAliasesRequest.AliasActions aliasAction = IndicesAliasesRequest.AliasActions aliasAction =
new IndicesAliasesRequest.AliasActions(IndicesAliasesRequest.AliasActions.Type.ADD) new IndicesAliasesRequest.AliasActions(IndicesAliasesRequest.AliasActions.Type.ADD)
.indices(indices) .indices(indices)
.aliases(aliases); .aliases(aliases);
indicesAliasesRequest.addAliasAction(aliasAction); indicesAliasesRequest.addAliasAction(aliasAction);
client.execute(IndicesAliasesAction.INSTANCE, indicesAliasesRequest).actionGet(); client.execute(IndicesAliasesAction.INSTANCE, indicesAliasesRequest).actionGet();
GetAliasesRequest getAliasesRequest = new GetAliasesRequest(); GetAliasesRequest getAliasesRequest = new GetAliasesRequest();
getAliasesRequest.aliases(alias); getAliasesRequest.aliases(alias);
GetAliasesResponse getAliasesResponse = GetAliasesResponse getAliasesResponse =

View file

@ -86,7 +86,7 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
logger.info("starting cluster with helper " + helper + " at " + helper.getHome()); logger.info("starting cluster with helper " + helper + " at " + helper.getHome());
helper.startNode("1"); helper.startNode("1");
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().transport(true); NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().transport(true);
NodesInfoResponse response = helper.client("1"). execute(NodesInfoAction.INSTANCE, nodesInfoRequest).actionGet(); NodesInfoResponse response = helper.client("1").execute(NodesInfoAction.INSTANCE, nodesInfoRequest).actionGet();
TransportAddress address = response.getNodes().get(0).getTransport().getAddress().publishAddress(); TransportAddress address = response.getNodes().get(0).getTransport().getAddress().publishAddress();
String host = address.address().getHostName(); String host = address.address().getHostName();
int port = address.address().getPort(); int port = address.address().getPort();
@ -158,7 +158,7 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
return helper; return helper;
} }
class Helper { static class Helper {
String home; String home;

View file

@ -1,6 +1,15 @@
import org.apache.tools.ant.taskdefs.condition.Os
dependencies{ dependencies{
compile project(':elx-common') compile project(':elx-common')
compile "org.xbib.elasticsearch:transport-netty4:${rootProject.property('elasticsearch-server.version')}" compile "org.xbib.elasticsearch:transport-netty4:${rootProject.property('elasticsearch-server.version')}"
compile "org.xbib:netty-http-client:${project.property('xbib-netty-http.version')}" compile "org.xbib:netty-http-client:${project.property('xbib-netty-http.version')}"
runtime "org.bouncycastle:bcpkix-jdk15on:${project.property('bouncycastle.version')}"
if (Os.isFamily(Os.FAMILY_MAC)) {
runtime "io.netty:netty-tcnative-boringssl-static:${project.property('tcnative-legacy-macosx.version')}"
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
runtime "io.netty:netty-tcnative-boringssl-static:${project.property('tcnative.version')}"
runtime "org.xbib:netty-http-epoll:${project.property('xbib-netty-http.version')}"
}
testCompile "org.xbib.elasticsearch:elasticsearch-analysis-common:${rootProject.property('elasticsearch-server.version')}" testCompile "org.xbib.elasticsearch:elasticsearch-analysis-common:${rootProject.property('elasticsearch-server.version')}"
} }

View file

@ -6,7 +6,7 @@ import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
@ -23,7 +23,7 @@ public class HttpGetMappingsAction extends HttpAction<GetMappingsRequest, GetMap
} }
@Override @Override
protected RequestBuilder createHttpRequest(String url, GetMappingsRequest request) { protected Request.Builder createHttpRequest(String url, GetMappingsRequest request) {
String index = request.indices() != null ? "/" + String.join(",", request.indices()) : ""; String index = request.indices() != null ? "/" + String.join(",", request.indices()) : "";
return newGetRequest(url, index + "/_mapping"); return newGetRequest(url, index + "/_mapping");
} }

View file

@ -18,7 +18,6 @@ import org.elasticsearch.threadpool.ThreadPool;
import org.xbib.elx.common.AbstractExtendedClient; import org.xbib.elx.common.AbstractExtendedClient;
import org.xbib.net.URL; import org.xbib.net.URL;
import org.xbib.netty.http.client.Client; import org.xbib.netty.http.client.Client;
import org.xbib.netty.http.client.ClientBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -75,7 +74,7 @@ public class ExtendedHttpClient extends AbstractExtendedClient implements Elasti
httpAction.setSettings(settings); httpAction.setSettings(settings);
actionMap.put(httpAction.getActionInstance(), httpAction); actionMap.put(httpAction.getActionInstance(), httpAction);
} }
ClientBuilder clientBuilder = Client.builder(); Client.Builder clientBuilder = Client.builder();
if (settings.hasValue("debug")) { if (settings.hasValue("debug")) {
clientBuilder.enableDebug(); clientBuilder.enableDebug();
} }

View file

@ -22,9 +22,9 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
import org.xbib.netty.http.client.Request; import org.xbib.net.URL;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import org.xbib.netty.http.client.transport.Transport; import org.xbib.netty.http.client.api.Transport;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -56,17 +56,17 @@ public abstract class HttpAction<R extends ActionRequest, T extends ActionRespon
listener.onFailure(validationException); listener.onFailure(validationException);
return; return;
} }
RequestBuilder httpRequestBuilder = Request.Builder httpRequestBuilder =
createHttpRequest(httpActionContext.getUrl(), httpActionContext.getRequest()); createHttpRequest(httpActionContext.getUrl(), httpActionContext.getRequest());
Request httpRequest = httpRequestBuilder.build(); Request httpRequest = httpRequestBuilder.build();
httpRequest.setResponseListener(fullHttpResponse -> { httpRequest.setResponseListener(fullHttpResponse -> {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.log(Level.DEBUG, "got response: " + fullHttpResponse.status().code() + logger.log(Level.DEBUG, "got response: " + fullHttpResponse.getStatus().getCode() +
" headers = " + fullHttpResponse.headers().entries() + " headers = " + fullHttpResponse.getHeaders() +
" content = " + fullHttpResponse.content().toString(StandardCharsets.UTF_8)); " content = " + fullHttpResponse.getBody().toString(StandardCharsets.UTF_8));
} }
httpActionContext.setHttpResponse(fullHttpResponse); httpActionContext.setHttpResponse(fullHttpResponse);
if (fullHttpResponse.status().equals(HttpResponseStatus.OK)) { if (fullHttpResponse.getStatus().getCode() == HttpResponseStatus.OK.code()) {
listener.onResponse(parseToResponse(httpActionContext)); listener.onResponse(parseToResponse(httpActionContext));
} else { } else {
ElasticsearchStatusException statusException = parseToError(httpActionContext); ElasticsearchStatusException statusException = parseToError(httpActionContext);
@ -88,68 +88,68 @@ public abstract class HttpAction<R extends ActionRequest, T extends ActionRespon
} }
} }
protected RequestBuilder newGetRequest(String url, String path) { protected Request.Builder newGetRequest(String url, String path) {
return newRequest(HttpMethod.GET, url, path); return newRequest(HttpMethod.GET, url, path);
} }
protected RequestBuilder newGetRequest(String url, String path, BytesReference content) { protected Request.Builder newGetRequest(String url, String path, BytesReference content) {
return newRequest(HttpMethod.GET, url, path, content); return newRequest(HttpMethod.GET, url, path, content);
} }
protected RequestBuilder newHeadRequest(String url, String path) { protected Request.Builder newHeadRequest(String url, String path) {
return newRequest(HttpMethod.HEAD, url, path); return newRequest(HttpMethod.HEAD, url, path);
} }
protected RequestBuilder newPostRequest(String url, String path) { protected Request.Builder newPostRequest(String url, String path) {
return newRequest(HttpMethod.POST, url, path); return newRequest(HttpMethod.POST, url, path);
} }
protected RequestBuilder newPostRequest(String url, String path, BytesReference content) { protected Request.Builder newPostRequest(String url, String path, BytesReference content) {
return newRequest(HttpMethod.POST, url, path, content); return newRequest(HttpMethod.POST, url, path, content);
} }
protected RequestBuilder newPostRequest(String url, String path, String content) { protected Request.Builder newPostRequest(String url, String path, String content) {
return newRequest(HttpMethod.POST, url, path, content); return newRequest(HttpMethod.POST, url, path, content);
} }
protected RequestBuilder newPutRequest(String url, String path) { protected Request.Builder newPutRequest(String url, String path) {
return newRequest(HttpMethod.PUT, url, path); return newRequest(HttpMethod.PUT, url, path);
} }
protected RequestBuilder newPutRequest(String url, String path, String content) { protected Request.Builder newPutRequest(String url, String path, String content) {
return newRequest(HttpMethod.PUT, url, path, content); return newRequest(HttpMethod.PUT, url, path, content);
} }
protected RequestBuilder newPutRequest(String url, String path, BytesReference content) { protected Request.Builder newPutRequest(String url, String path, BytesReference content) {
return newRequest(HttpMethod.PUT, url, path, content); return newRequest(HttpMethod.PUT, url, path, content);
} }
protected RequestBuilder newDeleteRequest(String url, String path) { protected Request.Builder newDeleteRequest(String url, String path) {
return newRequest(HttpMethod.DELETE, url, path); return newRequest(HttpMethod.DELETE, url, path);
} }
protected RequestBuilder newDeleteRequest(String url, String path, BytesReference content) { protected Request.Builder newDeleteRequest(String url, String path, BytesReference content) {
return newRequest(HttpMethod.DELETE, url, path, content); return newRequest(HttpMethod.DELETE, url, path, content);
} }
protected RequestBuilder newRequest(HttpMethod method, String baseUrl, String path) { protected Request.Builder newRequest(HttpMethod method, String baseUrl, String path) {
return Request.builder(method).url(baseUrl).uri(path); return Request.builder(method).url(URL.from(baseUrl).resolve(path));
} }
protected RequestBuilder newRequest(HttpMethod method, String baseUrl, String path, BytesReference content) { protected Request.Builder newRequest(HttpMethod method, String baseUrl, String path, BytesReference content) {
return Request.builder(method).url(baseUrl).uri(path).content(content.toBytesRef().bytes, APPLICATION_JSON); return Request.builder(method).url(URL.from(baseUrl).resolve(path)).content(content.toBytesRef().bytes, APPLICATION_JSON);
} }
protected RequestBuilder newRequest(HttpMethod method, String baseUrl, String path, String content) { protected Request.Builder newRequest(HttpMethod method, String baseUrl, String path, String content) {
return Request.builder(method).url(baseUrl).uri(path).content(content, APPLICATION_JSON); return Request.builder(method).url(URL.from(baseUrl).resolve(path)).content(content, APPLICATION_JSON);
} }
protected RequestBuilder newRequest(HttpMethod method, String baseUrl, String path, ByteBuf byteBuf) { protected Request.Builder newRequest(HttpMethod method, String baseUrl, String path, ByteBuf byteBuf) {
return Request.builder(method).url(baseUrl).uri(path).content(byteBuf, APPLICATION_JSON); return Request.builder(method).url(URL.from(baseUrl).resolve(path)).content(byteBuf, APPLICATION_JSON);
} }
protected T parseToResponse(HttpActionContext<R, T> httpActionContext) { protected T parseToResponse(HttpActionContext<R, T> httpActionContext) {
String mediaType = httpActionContext.getHttpResponse().headers().get(HttpHeaderNames.CONTENT_TYPE); String mediaType = httpActionContext.getHttpResponse().getHeaders().getHeader(HttpHeaderNames.CONTENT_TYPE);
XContentType xContentType = XContentType.fromMediaTypeOrFormat(mediaType); XContentType xContentType = XContentType.fromMediaTypeOrFormat(mediaType);
if (xContentType == null) { if (xContentType == null) {
throw new IllegalStateException("unsupported content-type: " + mediaType); throw new IllegalStateException("unsupported content-type: " + mediaType);
@ -157,7 +157,7 @@ public abstract class HttpAction<R extends ActionRequest, T extends ActionRespon
try (XContentParser parser = xContentType.xContent() try (XContentParser parser = xContentType.xContent()
.createParser(httpActionContext.getExtendedHttpClient().getRegistry(), .createParser(httpActionContext.getExtendedHttpClient().getRegistry(),
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
httpActionContext.getHttpResponse().content().toString(StandardCharsets.UTF_8))) { httpActionContext.getHttpResponse().getBody().toString(StandardCharsets.UTF_8))) {
return entityParser().apply(parser); return entityParser().apply(parser);
} catch (IOException e) { } catch (IOException e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
@ -169,7 +169,7 @@ public abstract class HttpAction<R extends ActionRequest, T extends ActionRespon
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON) try (XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(httpActionContext.getExtendedHttpClient().getRegistry(), .createParser(httpActionContext.getExtendedHttpClient().getRegistry(),
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
httpActionContext.getHttpResponse().content().toString(StandardCharsets.UTF_8))) { httpActionContext.getHttpResponse().getBody().toString(StandardCharsets.UTF_8))) {
return errorParser().apply(parser); return errorParser().apply(parser);
} catch (IOException e) { } catch (IOException e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
@ -181,7 +181,7 @@ public abstract class HttpAction<R extends ActionRequest, T extends ActionRespon
return BytesRestResponse::errorFromXContent; return BytesRestResponse::errorFromXContent;
} }
protected abstract RequestBuilder createHttpRequest(String baseUrl, R request) throws IOException; protected abstract Request.Builder createHttpRequest(String baseUrl, R request) throws IOException;
protected abstract CheckedFunction<XContentParser, T, IOException> entityParser(); protected abstract CheckedFunction<XContentParser, T, IOException> entityParser();

View file

@ -1,9 +1,9 @@
package org.xbib.elx.http; package org.xbib.elx.http;
import io.netty.handler.codec.http.FullHttpResponse;
import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionResponse;
import org.xbib.netty.http.client.transport.Transport; import org.xbib.netty.http.client.api.Transport;
import org.xbib.netty.http.common.HttpResponse;
/** /**
* HTTP action context. * HTTP action context.
@ -21,7 +21,7 @@ public class HttpActionContext<R extends ActionRequest, T extends ActionResponse
private Transport httpClientTransport; private Transport httpClientTransport;
private FullHttpResponse httpResponse; private HttpResponse httpResponse;
HttpActionContext(ExtendedHttpClient extendedHttpClient, R request, String url) { HttpActionContext(ExtendedHttpClient extendedHttpClient, R request, String url) {
this.extendedHttpClient = extendedHttpClient; this.extendedHttpClient = extendedHttpClient;
@ -49,12 +49,12 @@ public class HttpActionContext<R extends ActionRequest, T extends ActionResponse
return httpClientTransport; return httpClientTransport;
} }
public HttpActionContext<R, T> setHttpResponse(FullHttpResponse fullHttpResponse) { public HttpActionContext<R, T> setHttpResponse(HttpResponse httpResponse) {
this.httpResponse = fullHttpResponse; this.httpResponse = httpResponse;
return this; return this;
} }
public FullHttpResponse getHttpResponse() { public HttpResponse getHttpResponse() {
return httpResponse; return httpResponse;
} }
} }

View file

@ -7,7 +7,7 @@ import org.elasticsearch.action.ActionListener;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.BaseFuture; import org.elasticsearch.common.util.concurrent.BaseFuture;
import org.elasticsearch.common.util.concurrent.UncategorizedExecutionException; import org.elasticsearch.common.util.concurrent.UncategorizedExecutionException;
import org.xbib.netty.http.client.transport.Transport; import org.xbib.netty.http.client.api.Transport;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;

View file

@ -6,7 +6,7 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
@ -18,7 +18,7 @@ public class HttpClusterHealthAction extends HttpAction<ClusterHealthRequest, Cl
} }
@Override @Override
protected RequestBuilder createHttpRequest(String url, ClusterHealthRequest request) { protected Request.Builder createHttpRequest(String url, ClusterHealthRequest request) {
return newGetRequest(url, "/_cluster/health"); return newGetRequest(url, "/_cluster/health");
} }

View file

@ -23,7 +23,7 @@ import org.elasticsearch.threadpool.ThreadPoolInfo;
import org.elasticsearch.transport.TransportInfo; import org.elasticsearch.transport.TransportInfo;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.elx.http.HttpActionContext; import org.xbib.elx.http.HttpActionContext;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
@ -53,7 +53,7 @@ public class HttpNodesInfoAction extends HttpAction<NodesInfoRequest, NodesInfoR
* @return HTTP request * @return HTTP request
*/ */
@Override @Override
protected RequestBuilder createHttpRequest(String url, NodesInfoRequest request) { protected Request.Builder createHttpRequest(String url, NodesInfoRequest request) {
StringBuilder path = new StringBuilder("/_nodes"); StringBuilder path = new StringBuilder("/_nodes");
if (request.nodesIds() != null) { if (request.nodesIds() != null) {
String nodeIds = String.join(",", request.nodesIds()); String nodeIds = String.join(",", request.nodesIds());
@ -104,13 +104,17 @@ public class HttpNodesInfoAction extends HttpAction<NodesInfoRequest, NodesInfoR
return new NodesInfoResponse(); return new NodesInfoResponse();
} }
/**
* Broken.
*/
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected NodesInfoResponse createResponse(HttpActionContext<NodesInfoRequest, NodesInfoResponse> httpContext) { protected NodesInfoResponse createResponse(HttpActionContext<NodesInfoRequest, NodesInfoResponse> httpContext) {
Map<String, Object> map = null; Map<String, Object> map = null;
String string = (String)map.get("cluster_name"); //String string = (String)map.get("cluster_name");
ClusterName clusterName = new ClusterName(string); ClusterName clusterName = new ClusterName("");
List<NodeInfo> nodeInfoList = new LinkedList<>(); List<NodeInfo> nodeInfoList = new LinkedList<>();
map = (Map<String, Object>)map.get("nodes"); //map = (Map<String, Object>)map.get("nodes");
for (Map.Entry<String, Object> entry : map.entrySet()) { for (Map.Entry<String, Object> entry : map.entrySet()) {
String nodeId = entry.getKey(); String nodeId = entry.getKey();
String ephemeralId = null; String ephemeralId = null;

View file

@ -9,7 +9,7 @@ import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
@ -24,7 +24,7 @@ public class HttpClusterUpdateSettingsAction extends HttpAction<ClusterUpdateSet
} }
@Override @Override
protected RequestBuilder createHttpRequest(String url, ClusterUpdateSettingsRequest request) { protected Request.Builder createHttpRequest(String url, ClusterUpdateSettingsRequest request) {
try { try {
XContentBuilder builder = jsonBuilder(); XContentBuilder builder = jsonBuilder();
builder.startObject().startObject("persistent"); builder.startObject().startObject("persistent");

View file

@ -19,7 +19,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedObjectNotFoundException; import org.elasticsearch.common.xcontent.NamedObjectNotFoundException;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -48,7 +48,7 @@ public class HttpClusterStateAction extends HttpAction<ClusterStateRequest, Clus
} }
@Override @Override
protected RequestBuilder createHttpRequest(String url, ClusterStateRequest request) { protected Request.Builder createHttpRequest(String url, ClusterStateRequest request) {
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
if (request.metaData()) { if (request.metaData()) {
list.add("metadata"); list.add("metadata");

View file

@ -11,7 +11,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
@ -23,7 +23,7 @@ public class HttpIndicesAliasesAction extends HttpAction<IndicesAliasesRequest,
} }
@Override @Override
protected RequestBuilder createHttpRequest(String url, IndicesAliasesRequest request) { protected Request.Builder createHttpRequest(String url, IndicesAliasesRequest request) {
try { try {
XContentBuilder builder = JsonXContent.contentBuilder(); XContentBuilder builder = JsonXContent.contentBuilder();
request.toXContent(builder, ToXContent.EMPTY_PARAMS); request.toXContent(builder, ToXContent.EMPTY_PARAMS);

View file

@ -9,7 +9,7 @@ import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -20,7 +20,7 @@ import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpect
public class HttpGetAliasAction extends HttpAction<GetAliasesRequest, GetAliasesResponse> { public class HttpGetAliasAction extends HttpAction<GetAliasesRequest, GetAliasesResponse> {
@Override @Override
protected RequestBuilder createHttpRequest(String url, GetAliasesRequest request) { protected Request.Builder createHttpRequest(String url, GetAliasesRequest request) {
// beware of this inconsistency, request.indices() always return empty array // beware of this inconsistency, request.indices() always return empty array
String index = request.indices() != null ? String.join(",", request.indices()) + "/" : ""; String index = request.indices() != null ? String.join(",", request.indices()) + "/" : "";
String aliases = request.aliases() != null ? String.join(",", request.aliases()) + "/" : ""; String aliases = request.aliases() != null ? String.join(",", request.aliases()) + "/" : "";

View file

@ -10,7 +10,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
@ -22,7 +22,7 @@ public class HttpCreateIndexAction extends HttpAction<CreateIndexRequest, Create
} }
@Override @Override
protected RequestBuilder createHttpRequest(String url, CreateIndexRequest createIndexRequest) throws IOException { protected Request.Builder createHttpRequest(String url, CreateIndexRequest createIndexRequest) throws IOException {
XContentBuilder builder = XContentFactory.jsonBuilder(); XContentBuilder builder = XContentFactory.jsonBuilder();
builder = createIndexRequest.toXContent(builder, ToXContent.EMPTY_PARAMS); builder = createIndexRequest.toXContent(builder, ToXContent.EMPTY_PARAMS);
return newPutRequest(url, "/" + createIndexRequest.index(), BytesReference.bytes(builder)); return newPutRequest(url, "/" + createIndexRequest.index(), BytesReference.bytes(builder));

View file

@ -6,7 +6,7 @@ import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
@ -18,7 +18,7 @@ public class HttpDeleteIndexAction extends HttpAction<DeleteIndexRequest, Delete
} }
@Override @Override
protected RequestBuilder createHttpRequest(String url, DeleteIndexRequest deleteIndexRequest) { protected Request.Builder createHttpRequest(String url, DeleteIndexRequest deleteIndexRequest) {
return newDeleteRequest(url, "/" + String.join(",", deleteIndexRequest.indices())); return newDeleteRequest(url, "/" + String.join(",", deleteIndexRequest.indices()));
} }

View file

@ -9,7 +9,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.elx.http.HttpActionContext; import org.xbib.elx.http.HttpActionContext;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
@ -21,7 +21,7 @@ public class HttpIndicesExistsAction extends HttpAction<IndicesExistsRequest, In
} }
@Override @Override
protected RequestBuilder createHttpRequest(String url, IndicesExistsRequest request) { protected Request.Builder createHttpRequest(String url, IndicesExistsRequest request) {
String index = String.join(",", request.indices()); String index = String.join(",", request.indices());
return newHeadRequest(url, index); return newHeadRequest(url, index);
} }

View file

@ -6,7 +6,7 @@ import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
@ -18,7 +18,7 @@ public class HttpRefreshIndexAction extends HttpAction<RefreshRequest, RefreshRe
} }
@Override @Override
protected RequestBuilder createHttpRequest(String url, RefreshRequest request) { protected Request.Builder createHttpRequest(String url, RefreshRequest request) {
String index = request.indices() != null ? String.join(",", request.indices()) + "/" : ""; String index = request.indices() != null ? String.join(",", request.indices()) + "/" : "";
return newPostRequest(url, "/" + index + "_refresh"); return newPostRequest(url, "/" + index + "_refresh");
} }

View file

@ -9,7 +9,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParserUtils; import org.elasticsearch.common.xcontent.XContentParserUtils;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
@ -23,7 +23,7 @@ public class HttpGetSettingsAction extends HttpAction<GetSettingsRequest, GetSet
} }
@Override @Override
protected RequestBuilder createHttpRequest(String url, GetSettingsRequest request) { protected Request.Builder createHttpRequest(String url, GetSettingsRequest request) {
// beware, request.indices() is always an empty array // beware, request.indices() is always an empty array
String index = request.indices() != null ? String.join(",", request.indices()) + "/" : ""; String index = request.indices() != null ? String.join(",", request.indices()) + "/" : "";
return newGetRequest(url, index + "_settings"); return newGetRequest(url, index + "_settings");

View file

@ -10,7 +10,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
@ -23,7 +23,7 @@ public class HttpUpdateSettingsAction extends HttpAction<UpdateSettingsRequest,
} }
@Override @Override
protected RequestBuilder createHttpRequest(String url, UpdateSettingsRequest request) { protected Request.Builder createHttpRequest(String url, UpdateSettingsRequest request) {
try { try {
XContentBuilder builder = XContentFactory.jsonBuilder(); XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject(); builder.startObject();

View file

@ -13,7 +13,7 @@ import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
@ -25,7 +25,7 @@ public class HttpBulkAction extends HttpAction<BulkRequest, BulkResponse> {
} }
@Override @Override
protected RequestBuilder createHttpRequest(String url, BulkRequest request) throws IOException { protected Request.Builder createHttpRequest(String url, BulkRequest request) throws IOException {
StringBuilder bulkContent = new StringBuilder(); StringBuilder bulkContent = new StringBuilder();
for (DocWriteRequest<?> actionRequest : request.requests()) { for (DocWriteRequest<?> actionRequest : request.requests()) {
if (actionRequest instanceof IndexRequest) { if (actionRequest instanceof IndexRequest) {

View file

@ -7,7 +7,7 @@ import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
@ -19,7 +19,7 @@ public class HttpExistsAction extends HttpAction<GetRequest, GetResponse> {
} }
@Override @Override
protected RequestBuilder createHttpRequest(String url, GetRequest request) { protected Request.Builder createHttpRequest(String url, GetRequest request) {
return newHeadRequest(url, "/" + request.index() + "/" + request.type() + "/" + request.id()); return newHeadRequest(url, "/" + request.index() + "/" + request.type() + "/" + request.id());
} }

View file

@ -7,7 +7,7 @@ import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
@ -19,7 +19,7 @@ public class HttpGetAction extends HttpAction<GetRequest, GetResponse> {
} }
@Override @Override
protected RequestBuilder createHttpRequest(String url, GetRequest request) { protected Request.Builder createHttpRequest(String url, GetRequest request) {
return newGetRequest(url, "/" + request.index() + "/" + request.type() + "/" + request.id()); return newGetRequest(url, "/" + request.index() + "/" + request.type() + "/" + request.id());
} }

View file

@ -7,7 +7,7 @@ import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
@ -19,7 +19,7 @@ public class HttpIndexAction extends HttpAction<IndexRequest, IndexResponse> {
} }
@Override @Override
protected RequestBuilder createHttpRequest(String url, IndexRequest request) { protected Request.Builder createHttpRequest(String url, IndexRequest request) {
return newPutRequest(url, "/" + request.index() + "/" + request.type() + "/" + request.id(), return newPutRequest(url, "/" + request.index() + "/" + request.type() + "/" + request.id(),
request.source()); request.source());
} }

View file

@ -7,7 +7,7 @@ import org.elasticsearch.action.main.MainResponse;
import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
@ -19,7 +19,7 @@ public class HttpMainAction extends HttpAction<MainRequest, MainResponse> {
} }
@Override @Override
protected RequestBuilder createHttpRequest(String url, MainRequest request) { protected Request.Builder createHttpRequest(String url, MainRequest request) {
return newGetRequest(url, "/"); return newGetRequest(url, "/");
} }

View file

@ -6,7 +6,7 @@ import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
@ -18,7 +18,7 @@ public class HttpSearchAction extends HttpAction<SearchRequest, SearchResponse>
} }
@Override @Override
protected RequestBuilder createHttpRequest(String url, SearchRequest request) { protected Request.Builder createHttpRequest(String url, SearchRequest request) {
// request.indices() always empty array // request.indices() always empty array
String index = request.indices() != null ? String.join(",", request.indices()) + "/" : ""; String index = request.indices() != null ? String.join(",", request.indices()) + "/" : "";
return newPostRequest(url, index + "_search", request.source().toString()); return newPostRequest(url, index + "_search", request.source().toString());

View file

@ -11,7 +11,7 @@ import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.xbib.elx.http.HttpAction; import org.xbib.elx.http.HttpAction;
import org.xbib.netty.http.client.RequestBuilder; import org.xbib.netty.http.client.api.Request;
import java.io.IOException; import java.io.IOException;
@ -23,7 +23,7 @@ public class HttpUpdateAction extends HttpAction<UpdateRequest, UpdateResponse>
} }
@Override @Override
protected RequestBuilder createHttpRequest(String url, UpdateRequest updateRequest) { protected Request.Builder createHttpRequest(String url, UpdateRequest updateRequest) {
try { try {
// The Java API allows update requests with different content types // The Java API allows update requests with different content types
// set for the partial document and the upsert document. This client // set for the partial document and the upsert document. This client

View file

@ -6,7 +6,7 @@
</Console> </Console>
</appenders> </appenders>
<Loggers> <Loggers>
<Root level="info"> <Root level="debug">
<AppenderRef ref="Console" /> <AppenderRef ref="Console" />
</Root> </Root>
</Loggers> </Loggers>

View file

@ -1,4 +1,4 @@
/** /**
* * Node client extensions.
*/ */
package org.xbib.elx.node; package org.xbib.elx.node;

View file

@ -141,7 +141,7 @@ class ClientTest {
void testThreadedRandomDocs() throws Exception { void testThreadedRandomDocs() throws Exception {
int maxthreads = Runtime.getRuntime().availableProcessors(); int maxthreads = Runtime.getRuntime().availableProcessors();
Long maxActionsPerRequest = MAX_ACTIONS_PER_REQUEST; Long maxActionsPerRequest = MAX_ACTIONS_PER_REQUEST;
final Long actions = ACTIONS; final long actions = ACTIONS;
logger.info("maxthreads={} maxactions={} maxloop={}", maxthreads, maxActionsPerRequest, actions); logger.info("maxthreads={} maxactions={} maxloop={}", maxthreads, maxActionsPerRequest, actions);
final ExtendedNodeClient client = ClientBuilder.builder(helper.client("1")) final ExtendedNodeClient client = ClientBuilder.builder(helper.client("1"))
.provider(ExtendedNodeClientProvider.class) .provider(ExtendedNodeClientProvider.class)
@ -169,13 +169,13 @@ class ClientTest {
}); });
} }
logger.info("waiting for latch..."); logger.info("waiting for latch...");
if (latch.await(60L, TimeUnit.SECONDS)) { if (latch.await(30L, TimeUnit.SECONDS)) {
logger.info("flush..."); logger.info("flush...");
client.flush(); client.flush();
client.waitForResponses(60L, TimeUnit.SECONDS); client.waitForResponses(30L, TimeUnit.SECONDS);
logger.info("got all responses, executor service shutdown..."); logger.info("got all responses, executor service shutdown...");
executorService.shutdown(); executorService.shutdown();
executorService.awaitTermination(60L, TimeUnit.SECONDS); executorService.awaitTermination(30L, TimeUnit.SECONDS);
logger.info("pool is shut down"); logger.info("pool is shut down");
} else { } else {
logger.warn("latch timeout"); logger.warn("latch timeout");

View file

@ -45,22 +45,22 @@ class IndexPruneTest {
.put("index.number_of_shards", 1) .put("index.number_of_shards", 1)
.put("index.number_of_replicas", 0) .put("index.number_of_replicas", 0)
.build(); .build();
client.newIndex("test1", settings); client.newIndex("test_prune1", settings);
client.shiftIndex("test", "test1", Collections.emptyList()); client.shiftIndex("test_prune", "test_prune1", Collections.emptyList());
client.newIndex("test2", settings); client.newIndex("test_prune2", settings);
client.shiftIndex("test", "test2", Collections.emptyList()); client.shiftIndex("test_prune", "test_prune2", Collections.emptyList());
client.newIndex("test3", settings); client.newIndex("test_prune3", settings);
client.shiftIndex("test", "test3", Collections.emptyList()); client.shiftIndex("test_prune", "test_prune3", Collections.emptyList());
client.newIndex("test4", settings); client.newIndex("test_prune4", settings);
client.shiftIndex("test", "test4", Collections.emptyList()); client.shiftIndex("test_prune", "test_prune4", Collections.emptyList());
IndexPruneResult indexPruneResult = IndexPruneResult indexPruneResult =
client.pruneIndex("test", "test4", 2, 2, true); client.pruneIndex("test_prune", "test_prune4", 2, 2, true);
assertTrue(indexPruneResult.getDeletedIndices().contains("test1")); assertTrue(indexPruneResult.getDeletedIndices().contains("test_prune1"));
assertTrue(indexPruneResult.getDeletedIndices().contains("test2")); assertTrue(indexPruneResult.getDeletedIndices().contains("test_prune2"));
assertFalse(indexPruneResult.getDeletedIndices().contains("test3")); assertFalse(indexPruneResult.getDeletedIndices().contains("test_prune3"));
assertFalse(indexPruneResult.getDeletedIndices().contains("test4")); assertFalse(indexPruneResult.getDeletedIndices().contains("test_prune4"));
List<Boolean> list = new ArrayList<>(); List<Boolean> list = new ArrayList<>();
for (String index : Arrays.asList("test1", "test2", "test3", "test4")) { for (String index : Arrays.asList("test_prune1", "test_prune2", "test_prune3", "test_prune4")) {
IndicesExistsRequest indicesExistsRequest = new IndicesExistsRequest(); IndicesExistsRequest indicesExistsRequest = new IndicesExistsRequest();
indicesExistsRequest.indices(index); indicesExistsRequest.indices(index);
IndicesExistsResponse indicesExistsResponse = IndicesExistsResponse indicesExistsResponse =

View file

@ -41,21 +41,21 @@ class IndexShiftTest {
.put("index.number_of_shards", 1) .put("index.number_of_shards", 1)
.put("index.number_of_replicas", 0) .put("index.number_of_replicas", 0)
.build(); .build();
client.newIndex("test1234", settings); client.newIndex("test_shift", settings);
for (int i = 0; i < 1; i++) { for (int i = 0; i < 1; i++) {
client.index("test1234", helper.randomString(1), false, client.index("test_shift", helper.randomString(1), false,
"{ \"name\" : \"" + helper.randomString(32) + "\"}"); "{ \"name\" : \"" + helper.randomString(32) + "\"}");
} }
client.flush(); client.flush();
client.waitForResponses(30L, TimeUnit.SECONDS); client.waitForResponses(30L, TimeUnit.SECONDS);
IndexShiftResult indexShiftResult = IndexShiftResult indexShiftResult =
client.shiftIndex("test", "test1234", Arrays.asList("a", "b", "c")); client.shiftIndex("test", "test_shift", Arrays.asList("a", "b", "c"));
assertTrue(indexShiftResult.getNewAliases().contains("a")); assertTrue(indexShiftResult.getNewAliases().contains("a"));
assertTrue(indexShiftResult.getNewAliases().contains("b")); assertTrue(indexShiftResult.getNewAliases().contains("b"));
assertTrue(indexShiftResult.getNewAliases().contains("c")); assertTrue(indexShiftResult.getNewAliases().contains("c"));
assertTrue(indexShiftResult.getMovedAliases().isEmpty()); assertTrue(indexShiftResult.getMovedAliases().isEmpty());
Map<String, String> aliases = client.getAliases("test1234"); Map<String, String> aliases = client.getAliases("test_shift");
assertTrue(aliases.containsKey("a")); assertTrue(aliases.containsKey("a"));
assertTrue(aliases.containsKey("b")); assertTrue(aliases.containsKey("b"));
assertTrue(aliases.containsKey("c")); assertTrue(aliases.containsKey("c"));
@ -68,15 +68,15 @@ class IndexShiftTest {
assertTrue(aliases.containsKey("c")); assertTrue(aliases.containsKey("c"));
assertTrue(aliases.containsKey("test")); assertTrue(aliases.containsKey("test"));
client.newIndex("test5678", settings); client.newIndex("test_shift2", settings);
for (int i = 0; i < 1; i++) { for (int i = 0; i < 1; i++) {
client.index("test5678", helper.randomString(1), false, client.index("test_shift2", helper.randomString(1), false,
"{ \"name\" : \"" + helper.randomString(32) + "\"}"); "{ \"name\" : \"" + helper.randomString(32) + "\"}");
} }
client.flush(); client.flush();
client.waitForResponses(30L, TimeUnit.SECONDS); client.waitForResponses(30L, TimeUnit.SECONDS);
indexShiftResult = client.shiftIndex("test", "test5678", Arrays.asList("d", "e", "f"), indexShiftResult = client.shiftIndex("test", "test_shift2", Arrays.asList("d", "e", "f"),
(request, index, alias) -> request.addAliasAction(IndicesAliasesRequest.AliasActions.add() (request, index, alias) -> request.addAliasAction(IndicesAliasesRequest.AliasActions.add()
.index(index).alias(alias).filter(QueryBuilders.termQuery("my_key", alias))) .index(index).alias(alias).filter(QueryBuilders.termQuery("my_key", alias)))
); );
@ -87,7 +87,7 @@ class IndexShiftTest {
assertTrue(indexShiftResult.getMovedAliases().contains("b")); assertTrue(indexShiftResult.getMovedAliases().contains("b"));
assertTrue(indexShiftResult.getMovedAliases().contains("c")); assertTrue(indexShiftResult.getMovedAliases().contains("c"));
aliases = client.getAliases("test5678"); aliases = client.getAliases("test_shift2");
assertTrue(aliases.containsKey("a")); assertTrue(aliases.containsKey("a"));
assertTrue(aliases.containsKey("b")); assertTrue(aliases.containsKey("b"));
assertTrue(aliases.containsKey("c")); assertTrue(aliases.containsKey("c"));

View file

@ -34,20 +34,20 @@ class SmokeTest {
.build(); .build();
try { try {
assertEquals(helper.getClusterName(), client.getClusterName()); assertEquals(helper.getClusterName(), client.getClusterName());
client.newIndex("test"); client.newIndex("test_smoke");
client.index("test", "1", true, "{ \"name\" : \"Hello World\"}"); // single doc ingest client.index("test_smoke", "1", true, "{ \"name\" : \"Hello World\"}"); // single doc ingest
client.flush(); client.flush();
client.waitForResponses(30, TimeUnit.SECONDS); client.waitForResponses(30, TimeUnit.SECONDS);
client.checkMapping("test"); client.checkMapping("test_smoke");
client.update("test", "1", "{ \"name\" : \"Another name\"}"); client.update("test_smoke", "1", "{ \"name\" : \"Another name\"}");
client.delete("test", "1"); client.delete("test_smoke", "1");
client.flush(); client.flush();
client.waitForResponses(30, TimeUnit.SECONDS); client.waitForResponses(30, TimeUnit.SECONDS);
client.waitForRecovery("test", 10L, TimeUnit.SECONDS); client.waitForRecovery("test_smoke", 10L, TimeUnit.SECONDS);
client.delete("test", "1"); client.delete("test_smoke", "1");
client.flush(); client.flush();
client.deleteIndex("test"); client.deleteIndex("test_smoke");
IndexDefinition indexDefinition = client.buildIndexDefinitionFromSettings("test", Settings.builder() IndexDefinition indexDefinition = client.buildIndexDefinitionFromSettings("test_smoke", Settings.builder()
.build()); .build());
assertEquals(0, indexDefinition.getReplicaLevel()); assertEquals(0, indexDefinition.getReplicaLevel());
client.newIndex(indexDefinition); client.newIndex(indexDefinition);

View file

@ -157,7 +157,7 @@ public class TestExtension implements ParameterResolver, BeforeEachCallback, Aft
return helper; return helper;
} }
class Helper { static class Helper {
String home; String home;

View file

@ -1,5 +1,6 @@
package org.xbib.elx.transport; package org.xbib.elx.transport;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version; import org.elasticsearch.Version;
@ -48,11 +49,11 @@ public class ExtendedTransportClient extends AbstractExtendedClient {
+ " " + System.getProperty("java.vm.version") + " " + System.getProperty("java.vm.version")
+ " Elasticsearch " + Version.CURRENT.toString(); + " Elasticsearch " + Version.CURRENT.toString();
Settings transportClientSettings = getTransportClientSettings(settings); Settings transportClientSettings = getTransportClientSettings(settings);
XContentBuilder settingsBuilder = XContentFactory.jsonBuilder().startObject(); //XContentBuilder settingsBuilder = XContentFactory.jsonBuilder().startObject();
XContentBuilder effectiveSettingsBuilder = XContentFactory.jsonBuilder().startObject(); XContentBuilder effectiveSettingsBuilder = XContentFactory.jsonBuilder().startObject();
logger.info("creating transport client on {} with custom settings {} and effective settings {}", logger.log(Level.INFO, "creating transport client on {} with settings {}",
systemIdentifier, systemIdentifier,
Strings.toString(settings.toXContent(settingsBuilder, ToXContent.EMPTY_PARAMS).endObject()), //Strings.toString(settings.toXContent(settingsBuilder, ToXContent.EMPTY_PARAMS).endObject()),
Strings.toString(transportClientSettings.toXContent(effectiveSettingsBuilder, Strings.toString(transportClientSettings.toXContent(effectiveSettingsBuilder,
ToXContent.EMPTY_PARAMS).endObject())); ToXContent.EMPTY_PARAMS).endObject()));
return new MyTransportClient(transportClientSettings, Collections.singletonList(Netty4Plugin.class)); return new MyTransportClient(transportClientSettings, Collections.singletonList(Netty4Plugin.class));
@ -138,11 +139,14 @@ public class ExtendedTransportClient extends AbstractExtendedClient {
private Settings getTransportClientSettings(Settings settings) { private Settings getTransportClientSettings(Settings settings) {
return Settings.builder() return Settings.builder()
// "cluster.name"
.put(ClusterName.CLUSTER_NAME_SETTING.getKey(), .put(ClusterName.CLUSTER_NAME_SETTING.getKey(),
settings.get(ClusterName.CLUSTER_NAME_SETTING.getKey())) settings.get(ClusterName.CLUSTER_NAME_SETTING.getKey()))
// "processors"
.put(EsExecutors.PROCESSORS_SETTING.getKey(), .put(EsExecutors.PROCESSORS_SETTING.getKey(),
settings.get(EsExecutors.PROCESSORS_SETTING.getKey(), settings.get(EsExecutors.PROCESSORS_SETTING.getKey(),
String.valueOf(Runtime.getRuntime().availableProcessors()))) String.valueOf(Runtime.getRuntime().availableProcessors())))
// "transport.type"
.put(NetworkModule.TRANSPORT_TYPE_KEY, .put(NetworkModule.TRANSPORT_TYPE_KEY,
Netty4Plugin.NETTY_TRANSPORT_NAME) Netty4Plugin.NETTY_TRANSPORT_NAME)
.build(); .build();
@ -154,7 +158,7 @@ public class ExtendedTransportClient extends AbstractExtendedClient {
} }
} }
class MyTransportClient extends TransportClient { static class MyTransportClient extends TransportClient {
MyTransportClient(Settings settings, Collection<Class<? extends Plugin>> plugins) { MyTransportClient(Settings settings, Collection<Class<? extends Plugin>> plugins) {
super(settings, plugins); super(settings, plugins);

View file

@ -1,5 +1,6 @@
package org.xbib.elx.transport.test; package org.xbib.elx.transport.test;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsAction; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsAction;
@ -37,9 +38,9 @@ class ClientTest {
private static final Logger logger = LogManager.getLogger(ClientTest.class.getName()); private static final Logger logger = LogManager.getLogger(ClientTest.class.getName());
private static final Long ACTIONS = 1000L; private static final Long ACTIONS = 10000L;
private static final Long MAX_ACTIONS_PER_REQUEST = 100L; private static final Long MAX_ACTIONS_PER_REQUEST = 10000L;
private final TestExtension.Helper helper; private final TestExtension.Helper helper;
@ -51,9 +52,9 @@ class ClientTest {
void testSingleDoc() throws Exception { void testSingleDoc() throws Exception {
final ExtendedTransportClient client = ClientBuilder.builder() final ExtendedTransportClient client = ClientBuilder.builder()
.provider(ExtendedTransportClientProvider.class) .provider(ExtendedTransportClientProvider.class)
.put(helper.getTransportSettings())
.put(Parameters.MAX_ACTIONS_PER_REQUEST.name(), MAX_ACTIONS_PER_REQUEST) .put(Parameters.MAX_ACTIONS_PER_REQUEST.name(), MAX_ACTIONS_PER_REQUEST)
.put(Parameters.FLUSH_INTERVAL.name(), TimeValue.timeValueSeconds(30)) .put(Parameters.FLUSH_INTERVAL.name(), TimeValue.timeValueSeconds(30))
.put(helper.getTransportSettings())
.build(); .build();
try { try {
client.newIndex("test"); client.newIndex("test");
@ -76,8 +77,8 @@ class ClientTest {
void testNewIndex() throws Exception { void testNewIndex() throws Exception {
final ExtendedTransportClient client = ClientBuilder.builder() final ExtendedTransportClient client = ClientBuilder.builder()
.provider(ExtendedTransportClientProvider.class) .provider(ExtendedTransportClientProvider.class)
.put(Parameters.FLUSH_INTERVAL.name(), TimeValue.timeValueSeconds(5))
.put(helper.getTransportSettings()) .put(helper.getTransportSettings())
.put(Parameters.FLUSH_INTERVAL.name(), TimeValue.timeValueSeconds(5))
.build(); .build();
client.newIndex("test"); client.newIndex("test");
client.close(); client.close();
@ -87,8 +88,8 @@ class ClientTest {
void testMapping() throws Exception { void testMapping() throws Exception {
final ExtendedTransportClient client = ClientBuilder.builder() final ExtendedTransportClient client = ClientBuilder.builder()
.provider(ExtendedTransportClientProvider.class) .provider(ExtendedTransportClientProvider.class)
.put(Parameters.FLUSH_INTERVAL.name(), TimeValue.timeValueSeconds(5))
.put(helper.getTransportSettings()) .put(helper.getTransportSettings())
.put(Parameters.FLUSH_INTERVAL.name(), TimeValue.timeValueSeconds(5))
.build(); .build();
XContentBuilder builder = JsonXContent.contentBuilder() XContentBuilder builder = JsonXContent.contentBuilder()
.startObject() .startObject()
@ -114,9 +115,9 @@ class ClientTest {
long numactions = ACTIONS; long numactions = ACTIONS;
final ExtendedTransportClient client = ClientBuilder.builder() final ExtendedTransportClient client = ClientBuilder.builder()
.provider(ExtendedTransportClientProvider.class) .provider(ExtendedTransportClientProvider.class)
.put(helper.getTransportSettings())
.put(Parameters.MAX_ACTIONS_PER_REQUEST.name(), MAX_ACTIONS_PER_REQUEST) .put(Parameters.MAX_ACTIONS_PER_REQUEST.name(), MAX_ACTIONS_PER_REQUEST)
.put(Parameters.FLUSH_INTERVAL.name(), TimeValue.timeValueSeconds(60)) .put(Parameters.FLUSH_INTERVAL.name(), TimeValue.timeValueSeconds(60))
.put(helper.getTransportSettings())
.build(); .build();
try { try {
client.newIndex("test"); client.newIndex("test");
@ -144,6 +145,7 @@ class ClientTest {
searchRequest.indices("test"); searchRequest.indices("test");
searchRequest.source(builder); searchRequest.source(builder);
SearchResponse searchResponse = client.getClient().execute(SearchAction.INSTANCE, searchRequest).actionGet(); SearchResponse searchResponse = client.getClient().execute(SearchAction.INSTANCE, searchRequest).actionGet();
logger.log(Level.INFO, searchResponse.toString());
assertEquals(numactions, searchResponse.getHits().getTotalHits()); assertEquals(numactions, searchResponse.getHits().getTotalHits());
client.close(); client.close();
} }
@ -153,14 +155,15 @@ class ClientTest {
void testThreadedRandomDocs() throws Exception { void testThreadedRandomDocs() throws Exception {
int maxthreads = Runtime.getRuntime().availableProcessors(); int maxthreads = Runtime.getRuntime().availableProcessors();
Long maxActionsPerRequest = MAX_ACTIONS_PER_REQUEST; Long maxActionsPerRequest = MAX_ACTIONS_PER_REQUEST;
final Long actions = ACTIONS; final long actions = ACTIONS;
logger.info("maxthreads={} maxactions={} maxloop={}", maxthreads, maxActionsPerRequest, actions); logger.info("maxthreads={} maxactions={} maxloop={}", maxthreads, maxActionsPerRequest, actions);
final ExtendedTransportClient client = ClientBuilder.builder() final ExtendedTransportClient client = ClientBuilder.builder()
.provider(ExtendedTransportClientProvider.class) .provider(ExtendedTransportClientProvider.class)
.put(helper.getTransportSettings())
.put(Parameters.MAX_CONCURRENT_REQUESTS.name(), maxthreads * 2) .put(Parameters.MAX_CONCURRENT_REQUESTS.name(), maxthreads * 2)
.put(Parameters.MAX_ACTIONS_PER_REQUEST.name(), maxActionsPerRequest) .put(Parameters.MAX_ACTIONS_PER_REQUEST.name(), maxActionsPerRequest)
.put(Parameters.FLUSH_INTERVAL.name(), TimeValue.timeValueSeconds(60)) .put(Parameters.FLUSH_INTERVAL.name(), TimeValue.timeValueSeconds(60))
.put(helper.getTransportSettings()) .put(Parameters.ENABLE_BULK_LOGGING.name(), "true")
.build(); .build();
try { try {
Settings settings = Settings.builder() Settings settings = Settings.builder()
@ -182,13 +185,13 @@ class ClientTest {
}); });
} }
logger.info("waiting for latch..."); logger.info("waiting for latch...");
if (latch.await(60L, TimeUnit.SECONDS)) { if (latch.await(30L, TimeUnit.SECONDS)) {
logger.info("flush..."); logger.info("flush...");
client.flush(); client.flush();
client.waitForResponses(60L, TimeUnit.SECONDS); client.waitForResponses(30L, TimeUnit.SECONDS);
logger.info("got all responses, executor service shutdown..."); logger.info("got all responses, executor service shutdown...");
executorService.shutdown(); executorService.shutdown();
executorService.awaitTermination(60L, TimeUnit.SECONDS); executorService.awaitTermination(30L, TimeUnit.SECONDS);
logger.info("pool is shut down"); logger.info("pool is shut down");
} else { } else {
logger.warn("latch timeout"); logger.warn("latch timeout");
@ -212,6 +215,7 @@ class ClientTest {
searchRequest.indices("test"); searchRequest.indices("test");
searchRequest.source(builder); searchRequest.source(builder);
SearchResponse searchResponse = client.getClient().execute(SearchAction.INSTANCE, searchRequest).actionGet(); SearchResponse searchResponse = client.getClient().execute(SearchAction.INSTANCE, searchRequest).actionGet();
logger.log(Level.INFO, searchResponse.toString());
assertEquals(maxthreads * actions, searchResponse.getHits().getTotalHits()); assertEquals(maxthreads * actions, searchResponse.getHits().getTotalHits());
client.close(); client.close();
} }

View file

@ -45,20 +45,20 @@ class DuplicateIDTest {
.put(helper.getTransportSettings()) .put(helper.getTransportSettings())
.build(); .build();
try { try {
client.newIndex("test"); client.newIndex("test_dup");
for (int i = 0; i < ACTIONS; i++) { for (int i = 0; i < ACTIONS; i++) {
client.index("test", helper.randomString(1), false, client.index("test_dup", helper.randomString(1), false,
"{ \"name\" : \"" + helper.randomString(32) + "\"}"); "{ \"name\" : \"" + helper.randomString(32) + "\"}");
} }
client.flush(); client.flush();
client.waitForResponses(30L, TimeUnit.SECONDS); client.waitForResponses(30L, TimeUnit.SECONDS);
client.refreshIndex("test"); client.refreshIndex("test_dup");
SearchSourceBuilder builder = new SearchSourceBuilder(); SearchSourceBuilder builder = new SearchSourceBuilder();
builder.query(QueryBuilders.matchAllQuery()); builder.query(QueryBuilders.matchAllQuery());
builder.size(0); builder.size(0);
SearchRequest searchRequest = new SearchRequest(); SearchRequest searchRequest = new SearchRequest();
searchRequest.indices("test"); searchRequest.indices("test_dup");
searchRequest.types("test"); searchRequest.types("test_dup");
searchRequest.source(builder); searchRequest.source(builder);
SearchResponse searchResponse = SearchResponse searchResponse =
helper.client("1").execute(SearchAction.INSTANCE, searchRequest).actionGet(); helper.client("1").execute(SearchAction.INSTANCE, searchRequest).actionGet();

View file

@ -46,22 +46,22 @@ class IndexPruneTest {
.put("index.number_of_shards", 1) .put("index.number_of_shards", 1)
.put("index.number_of_replicas", 0) .put("index.number_of_replicas", 0)
.build(); .build();
client.newIndex("test1", settings); client.newIndex("test_prune1", settings);
client.shiftIndex("test", "test1", Collections.emptyList()); client.shiftIndex("test_prune", "test_prune1", Collections.emptyList());
client.newIndex("test2", settings); client.newIndex("test_prune2", settings);
client.shiftIndex("test", "test2", Collections.emptyList()); client.shiftIndex("test_prune", "test_prune2", Collections.emptyList());
client.newIndex("test3", settings); client.newIndex("test_prune3", settings);
client.shiftIndex("test", "test3", Collections.emptyList()); client.shiftIndex("test_prune", "test_prune3", Collections.emptyList());
client.newIndex("test4", settings); client.newIndex("test_prune4", settings);
client.shiftIndex("test", "test4", Collections.emptyList()); client.shiftIndex("test_prune", "test_prune4", Collections.emptyList());
IndexPruneResult indexPruneResult = IndexPruneResult indexPruneResult =
client.pruneIndex("test", "test4", 2, 2, true); client.pruneIndex("test_prune", "test_prune4", 2, 2, true);
assertTrue(indexPruneResult.getDeletedIndices().contains("test1")); assertTrue(indexPruneResult.getDeletedIndices().contains("test_prune1"));
assertTrue(indexPruneResult.getDeletedIndices().contains("test2")); assertTrue(indexPruneResult.getDeletedIndices().contains("test_prune2"));
assertFalse(indexPruneResult.getDeletedIndices().contains("test3")); assertFalse(indexPruneResult.getDeletedIndices().contains("test_prune3"));
assertFalse(indexPruneResult.getDeletedIndices().contains("test4")); assertFalse(indexPruneResult.getDeletedIndices().contains("test_prune4"));
List<Boolean> list = new ArrayList<>(); List<Boolean> list = new ArrayList<>();
for (String index : Arrays.asList("test1", "test2", "test3", "test4")) { for (String index : Arrays.asList("test_prune1", "test_prune2", "test_prune3", "test_prune4")) {
IndicesExistsRequest indicesExistsRequest = new IndicesExistsRequest(); IndicesExistsRequest indicesExistsRequest = new IndicesExistsRequest();
indicesExistsRequest.indices(index); indicesExistsRequest.indices(index);
IndicesExistsResponse indicesExistsResponse = IndicesExistsResponse indicesExistsResponse =

View file

@ -42,38 +42,38 @@ class IndexShiftTest {
.put("index.number_of_shards", 1) .put("index.number_of_shards", 1)
.put("index.number_of_replicas", 0) .put("index.number_of_replicas", 0)
.build(); .build();
client.newIndex("test1234", settings); client.newIndex("test_shift1234", settings);
for (int i = 0; i < 1; i++) { for (int i = 0; i < 1; i++) {
client.index("test1234", helper.randomString(1), false, client.index("test_shift1234", helper.randomString(1), false,
"{ \"name\" : \"" + helper.randomString(32) + "\"}"); "{ \"name\" : \"" + helper.randomString(32) + "\"}");
} }
client.flush(); client.flush();
client.waitForResponses(30L, TimeUnit.SECONDS); client.waitForResponses(30L, TimeUnit.SECONDS);
IndexShiftResult indexShiftResult = IndexShiftResult indexShiftResult =
client.shiftIndex("test", "test1234", Arrays.asList("a", "b", "c")); client.shiftIndex("test_shift", "test_shift1234", Arrays.asList("a", "b", "c"));
assertTrue(indexShiftResult.getNewAliases().contains("a")); assertTrue(indexShiftResult.getNewAliases().contains("a"));
assertTrue(indexShiftResult.getNewAliases().contains("b")); assertTrue(indexShiftResult.getNewAliases().contains("b"));
assertTrue(indexShiftResult.getNewAliases().contains("c")); assertTrue(indexShiftResult.getNewAliases().contains("c"));
assertTrue(indexShiftResult.getMovedAliases().isEmpty()); assertTrue(indexShiftResult.getMovedAliases().isEmpty());
Map<String, String> aliases = client.getAliases("test1234"); Map<String, String> aliases = client.getAliases("test_shift1234");
assertTrue(aliases.containsKey("a")); assertTrue(aliases.containsKey("a"));
assertTrue(aliases.containsKey("b")); assertTrue(aliases.containsKey("b"));
assertTrue(aliases.containsKey("c")); assertTrue(aliases.containsKey("c"));
assertTrue(aliases.containsKey("test")); assertTrue(aliases.containsKey("test_shift"));
String resolved = client.resolveAlias("test"); String resolved = client.resolveAlias("test_shift");
aliases = client.getAliases(resolved); aliases = client.getAliases(resolved);
assertTrue(aliases.containsKey("a")); assertTrue(aliases.containsKey("a"));
assertTrue(aliases.containsKey("b")); assertTrue(aliases.containsKey("b"));
assertTrue(aliases.containsKey("c")); assertTrue(aliases.containsKey("c"));
assertTrue(aliases.containsKey("test")); assertTrue(aliases.containsKey("test_shift"));
client.newIndex("test5678", settings); client.newIndex("test_shift5678", settings);
for (int i = 0; i < 1; i++) { for (int i = 0; i < 1; i++) {
client.index("test5678", helper.randomString(1), false, client.index("test_shift5678", helper.randomString(1), false,
"{ \"name\" : \"" + helper.randomString(32) + "\"}"); "{ \"name\" : \"" + helper.randomString(32) + "\"}");
} }
client.flush(); client.flush();
client.waitForResponses(30L, TimeUnit.SECONDS); client.waitForResponses(30L, TimeUnit.SECONDS);
indexShiftResult = client.shiftIndex("test", "test5678", Arrays.asList("d", "e", "f"), indexShiftResult = client.shiftIndex("test_shift", "test_shift5678", Arrays.asList("d", "e", "f"),
(request, index, alias) -> request.addAliasAction(IndicesAliasesRequest.AliasActions.add() (request, index, alias) -> request.addAliasAction(IndicesAliasesRequest.AliasActions.add()
.index(index).alias(alias).filter(QueryBuilders.termQuery("my_key", alias))) .index(index).alias(alias).filter(QueryBuilders.termQuery("my_key", alias)))
); );
@ -83,14 +83,14 @@ class IndexShiftTest {
assertTrue(indexShiftResult.getMovedAliases().contains("a")); assertTrue(indexShiftResult.getMovedAliases().contains("a"));
assertTrue(indexShiftResult.getMovedAliases().contains("b")); assertTrue(indexShiftResult.getMovedAliases().contains("b"));
assertTrue(indexShiftResult.getMovedAliases().contains("c")); assertTrue(indexShiftResult.getMovedAliases().contains("c"));
aliases = client.getAliases("test5678"); aliases = client.getAliases("test_shift5678");
assertTrue(aliases.containsKey("a")); assertTrue(aliases.containsKey("a"));
assertTrue(aliases.containsKey("b")); assertTrue(aliases.containsKey("b"));
assertTrue(aliases.containsKey("c")); assertTrue(aliases.containsKey("c"));
assertTrue(aliases.containsKey("d")); assertTrue(aliases.containsKey("d"));
assertTrue(aliases.containsKey("e")); assertTrue(aliases.containsKey("e"));
assertTrue(aliases.containsKey("f")); assertTrue(aliases.containsKey("f"));
resolved = client.resolveAlias("test"); resolved = client.resolveAlias("test_shift");
aliases = client.getAliases(resolved); aliases = client.getAliases(resolved);
assertTrue(aliases.containsKey("a")); assertTrue(aliases.containsKey("a"));
assertTrue(aliases.containsKey("b")); assertTrue(aliases.containsKey("b"));

View file

@ -35,15 +35,15 @@ class SmokeTest {
.build(); .build();
try { try {
assertEquals(helper.getClusterName(), client.getClusterName()); assertEquals(helper.getClusterName(), client.getClusterName());
client.newIndex("test"); client.newIndex("test_smoke");
client.index("test", "1", true, "{ \"name\" : \"Hello World\"}"); // single doc ingest client.index("test_smoke", "1", true, "{ \"name\" : \"Hello World\"}"); // single doc ingest
client.update("test", "1", "{ \"name\" : \"Another name\"}"); client.update("test_smoke", "1", "{ \"name\" : \"Another name\"}");
client.delete("test", "1"); client.delete("test_smoke", "1");
client.flush(); client.flush();
client.waitForResponses(30, TimeUnit.SECONDS); client.waitForResponses(30, TimeUnit.SECONDS);
client.checkMapping("test"); client.checkMapping("test_smoke");
client.deleteIndex("test"); client.deleteIndex("test_smoke");
IndexDefinition indexDefinition = client.buildIndexDefinitionFromSettings("test", Settings.builder() IndexDefinition indexDefinition = client.buildIndexDefinitionFromSettings("test_smoke", Settings.builder()
.build()); .build());
assertEquals(0, indexDefinition.getReplicaLevel()); assertEquals(0, indexDefinition.getReplicaLevel());
client.newIndex(indexDefinition); client.newIndex(indexDefinition);

View file

@ -6,7 +6,7 @@
</Console> </Console>
</appenders> </appenders>
<Loggers> <Loggers>
<Root level="info"> <Root level="debug">
<AppenderRef ref="Console" /> <AppenderRef ref="Console" />
</Root> </Root>
</Loggers> </Loggers>

View file

@ -1,13 +1,16 @@
group = org.xbib group = org.xbib
name = elx name = elx
version = 6.3.2.3 version = 6.3.2.4
profile = default profile = default
release = 0 release = 0
elasticsearch-server.version = 6.3.2.3 elasticsearch-server.version = 6.3.2.4
log4j.version = 2.11.1 log4j.version = 2.12.1
xbib-metrics.version = 1.2.0 xbib-metrics.version = 2.0.0
xbib-netty-http.version = 4.1.35.0 xbib-netty-http.version = 4.1.48.0
tcnative.version = 2.0.29.Final
tcnative-legacy-macosx.version = 2.0.26.Final
bouncycastle.version = 1.64
# test # test
junit.version = 5.4.2 junit.version = 5.4.2