diff --git a/build.gradle b/build.gradle index 95c2701..0c69d48 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,9 @@ plugins { id "org.sonarqube" version "2.2" - id "org.ajoberstar.github-pages" version "1.6.0-rc.1" id "org.xbib.gradle.plugin.jbake" version "1.2.1" } -group = 'org.xbib' -version = '5.0.1.1' - printf "Host: %s\nOS: %s %s %s\nJVM: %s %s %s %s\nGroovy: %s\nGradle: %s\n" + "Build: group: ${project.group} name: ${project.name} version: ${project.version}\n", InetAddress.getLocalHost(), @@ -28,9 +24,15 @@ apply plugin: 'findbugs' apply plugin: 'pmd' apply plugin: 'checkstyle' apply plugin: "jacoco" -apply plugin: 'org.ajoberstar.github-pages' -apply from: 'gradle/ext.gradle' +ext { + user = 'xbib' + name = 'elasticsearch-extras-client' + description = 'Some extras implemented for using Elasticsearch clients (node and transport)' + scmUrl = 'https://github.com/' + user + '/' + name + scmConnection = 'scm:git:git://github.com/' + user + '/' + name + '.git' + scmDeveloperConnection = 'scm:git:git://github.com/' + user + '/' + name + '.git' +} sourceSets { integrationTest { @@ -56,7 +58,7 @@ configurations { dependencies { compile "org.xbib:metrics:1.0.0" - compile("org.elasticsearch.client:transport:5.0.1") { + compile("org.elasticsearch.client:transport:5.1.1") { exclude group: 'org.elasticsearch', module: 'securesm' exclude group: 'org.elasticsearch.plugin', module: 'transport-netty3-client' exclude group: 'org.elasticsearch.plugin', module: 'reindex-client' diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..60e7e76 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,3 @@ +group = org.xbib +name = elasticsearch-extras-client +version = 5.1.1.0 diff --git a/gradle/ext.gradle b/gradle/ext.gradle deleted file mode 100644 index 7bb7c73..0000000 --- a/gradle/ext.gradle +++ /dev/null @@ -1,8 +0,0 @@ -ext { - user = 'xbib' - name = 'elasticsearch-extras-client' - description = 'Some extras implemented for using Elasticsearch clients (node and transport)' - scmUrl = 'https://github.com/' + user + '/' + name - scmConnection = 'scm:git:git://github.com/' + user + '/' + name + '.git' - scmDeveloperConnection = 'scm:git:git://github.com/' + user + '/' + name + '.git' -} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 6ffa237..51288f9 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2a06e59..d56c0fe 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Nov 01 14:46:00 CET 2016 +#Sun Dec 04 10:06:25 CET 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-all.zip diff --git a/gradlew b/gradlew index 9aa616c..4453cce 100755 --- a/gradlew +++ b/gradlew @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh ############################################################################## ## @@ -154,16 +154,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save ( ) { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then cd "$(dirname "$0")" fi -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/settings.gradle b/settings.gradle index ef50653..89f4110 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -rootProject.name = 'elasticsearch-extras-client' +rootProject.name = name diff --git a/src/integration-test/java/org/xbib/elasticsearch/NodeTestBase.java b/src/integration-test/java/org/xbib/elasticsearch/NodeTestBase.java index 86bb6dc..618fa06 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/NodeTestBase.java +++ b/src/integration-test/java/org/xbib/elasticsearch/NodeTestBase.java @@ -22,7 +22,11 @@ import org.junit.Before; import org.xbib.elasticsearch.extras.client.NetworkUtils; import java.io.IOException; -import java.nio.file.*; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.HashMap; import java.util.Map; diff --git a/src/integration-test/java/org/xbib/elasticsearch/extras/client/SimpleTest.java b/src/integration-test/java/org/xbib/elasticsearch/extras/client/SimpleTest.java index f32e321..c3fe074 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/extras/client/SimpleTest.java +++ b/src/integration-test/java/org/xbib/elasticsearch/extras/client/SimpleTest.java @@ -11,6 +11,7 @@ import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequestBuilder; import org.elasticsearch.action.index.IndexAction; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.support.WriteRequest; +import org.elasticsearch.client.Client; import org.elasticsearch.common.settings.Settings; import org.junit.Test; import org.xbib.elasticsearch.NodeTestBase; @@ -20,27 +21,17 @@ import org.xbib.elasticsearch.NodeTestBase; */ public class SimpleTest extends NodeTestBase { - protected Settings getNodeSettings() { - return Settings.builder() - .put("cluster.name", getClusterName()) - .put("discovery.type", "local") - .put("transport.type", "local") - .put("http.enabled", false) - .put("path.home", getHome()) - .put("node.max_local_storage_nodes", 5) - .build(); - } - @Test public void test() throws Exception { + Client client = client("1"); try { DeleteIndexRequestBuilder deleteIndexRequestBuilder = - new DeleteIndexRequestBuilder(client("1"), DeleteIndexAction.INSTANCE, "test"); + new DeleteIndexRequestBuilder(client, DeleteIndexAction.INSTANCE, "test"); deleteIndexRequestBuilder.execute().actionGet(); } catch (Exception e) { // ignore } - CreateIndexRequestBuilder createIndexRequestBuilder = new CreateIndexRequestBuilder(client("1"), + CreateIndexRequestBuilder createIndexRequestBuilder = new CreateIndexRequestBuilder(client, CreateIndexAction.INSTANCE) .setIndex("test") .setSettings(Settings.builder() @@ -50,7 +41,7 @@ public class SimpleTest extends NodeTestBase { .build()); createIndexRequestBuilder.execute().actionGet(); - IndexRequestBuilder indexRequestBuilder = new IndexRequestBuilder(client("1"), IndexAction.INSTANCE); + IndexRequestBuilder indexRequestBuilder = new IndexRequestBuilder(client, IndexAction.INSTANCE); indexRequestBuilder .setIndex("test") .setType("test") @@ -60,7 +51,7 @@ public class SimpleTest extends NodeTestBase { .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) .execute() .actionGet(); - String doc = client("1").prepareSearch("test") + String doc = client.prepareSearch("test") .setTypes("test") .setQuery(matchQuery("field", "1%2fPJJP3JV2C24iDfEu9XpHBaYxXh%2fdHTbmchB35SDznXO2g8Vz4D7GTIvY54iMiX_149c95f02a8")) diff --git a/src/integration-test/java/org/xbib/elasticsearch/extras/client/WildcardTest.java b/src/integration-test/java/org/xbib/elasticsearch/extras/client/WildcardTest.java index 327b619..9b16eda 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/extras/client/WildcardTest.java +++ b/src/integration-test/java/org/xbib/elasticsearch/extras/client/WildcardTest.java @@ -6,7 +6,6 @@ import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery; import org.elasticsearch.action.support.WriteRequest; import org.elasticsearch.client.Client; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.QueryBuilder; import org.junit.Test; import org.xbib.elasticsearch.NodeTestBase; @@ -18,33 +17,23 @@ import java.io.IOException; */ public class WildcardTest extends NodeTestBase { - protected Settings getNodeSettings() { - return Settings.builder() - .put("cluster.name", getClusterName()) - .put("discovery.type", "local") - .put("transport.type", "local") - .put("http.enabled", false) - .put("path.home", getHome()) - .put("node.max_local_storage_nodes", 5) - .build(); - } - @Test public void testWildcard() throws Exception { - index(client("1"), "1", "010"); - index(client("1"), "2", "0*0"); + Client client = client("1"); + index(client, "1", "010"); + index(client, "2", "0*0"); // exact - validateCount(client("1"), queryStringQuery("010").defaultField("field"), 1); - validateCount(client("1"), queryStringQuery("0\\*0").defaultField("field"), 1); + validateCount(client, queryStringQuery("010").defaultField("field"), 1); + validateCount(client, queryStringQuery("0\\*0").defaultField("field"), 1); // pattern - validateCount(client("1"), queryStringQuery("0*0").defaultField("field"), 1); // 2? - validateCount(client("1"), queryStringQuery("0?0").defaultField("field"), 1); // 2? - validateCount(client("1"), queryStringQuery("0**0").defaultField("field"), 1); // 2? - validateCount(client("1"), queryStringQuery("0??0").defaultField("field"), 0); - validateCount(client("1"), queryStringQuery("*10").defaultField("field"), 1); - validateCount(client("1"), queryStringQuery("*1*").defaultField("field"), 1); - validateCount(client("1"), queryStringQuery("*\\*0").defaultField("field"), 0); // 1? - validateCount(client("1"), queryStringQuery("*\\**").defaultField("field"), 0); // 1? + validateCount(client, queryStringQuery("0*0").defaultField("field"), 1); // 2? + validateCount(client, queryStringQuery("0?0").defaultField("field"), 1); // 2? + validateCount(client, queryStringQuery("0**0").defaultField("field"), 1); // 2? + validateCount(client, queryStringQuery("0??0").defaultField("field"), 0); + validateCount(client, queryStringQuery("*10").defaultField("field"), 1); + validateCount(client, queryStringQuery("*1*").defaultField("field"), 1); + validateCount(client, queryStringQuery("*\\*0").defaultField("field"), 0); // 1? + validateCount(client, queryStringQuery("*\\**").defaultField("field"), 0); // 1? } private void index(Client client, String id, String fieldValue) throws IOException { diff --git a/src/main/java/org/xbib/elasticsearch/extras/client/BulkProcessor.java b/src/main/java/org/xbib/elasticsearch/extras/client/BulkProcessor.java index b15c243..56a72e5 100644 --- a/src/main/java/org/xbib/elasticsearch/extras/client/BulkProcessor.java +++ b/src/main/java/org/xbib/elasticsearch/extras/client/BulkProcessor.java @@ -147,7 +147,7 @@ public class BulkProcessor implements Closeable { * @param request request * @return his bulk processor */ - public BulkProcessor add(ActionRequest request) { + public BulkProcessor add(ActionRequest request) { return add(request, null); } @@ -158,7 +158,7 @@ public class BulkProcessor implements Closeable { * @param payload payload * @return his bulk processor */ - public BulkProcessor add(ActionRequest request, @Nullable Object payload) { + public BulkProcessor add(ActionRequest request, @Nullable Object payload) { internalAdd(request, payload); return this; } @@ -169,7 +169,7 @@ public class BulkProcessor implements Closeable { } } - private synchronized void internalAdd(ActionRequest request, @Nullable Object payload) { + private synchronized void internalAdd(ActionRequest request, @Nullable Object payload) { ensureOpen(); bulkRequest.add(request, payload); executeIfNeeded(); diff --git a/src/main/java/org/xbib/elasticsearch/extras/client/transport/TransportClient.java b/src/main/java/org/xbib/elasticsearch/extras/client/transport/TransportClient.java index d0c377d..fc83ae0 100644 --- a/src/main/java/org/xbib/elasticsearch/extras/client/transport/TransportClient.java +++ b/src/main/java/org/xbib/elasticsearch/extras/client/transport/TransportClient.java @@ -40,6 +40,7 @@ import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.node.Node; import org.elasticsearch.node.internal.InternalSettingsPreparer; import org.elasticsearch.plugins.ActionPlugin; +import org.elasticsearch.plugins.NetworkPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.plugins.SearchPlugin; @@ -48,6 +49,7 @@ import org.elasticsearch.threadpool.ExecutorBuilder; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.FutureTransportResponseHandler; import org.elasticsearch.transport.TcpTransport; +import org.elasticsearch.transport.Transport; import org.elasticsearch.transport.TransportRequestOptions; import org.elasticsearch.transport.TransportService; @@ -355,7 +357,7 @@ public class TransportClient extends AbstractClient { @Override @SuppressWarnings({"unchecked", "rawtypes"}) - protected , S extends ActionResponse, T extends ActionRequestBuilder> + protected > void doExecute(Action action, final R request, final ActionListener listener) { final TransportActionNodeProxy proxyAction = proxy.getProxies().get(action); if (proxyAction == null) { @@ -425,10 +427,11 @@ public class TransportClient extends AbstractClient { additionalSettings.addAll(builder.getRegisteredSettings()); } SettingsModule settingsModule = new SettingsModule(settings, additionalSettings, additionalSettingsFilter); - NetworkModule networkModule = new NetworkModule(networkService, settings, true); - SearchModule searchModule = new SearchModule(settings, true, pluginsService.filterPlugins(SearchPlugin.class)); + + SearchModule searchModule = new SearchModule(settings, true, + pluginsService.filterPlugins(SearchPlugin.class)); List entries = new ArrayList<>(); - entries.addAll(networkModule.getNamedWriteables()); + entries.addAll(NetworkModule.getNamedWriteables()); entries.addAll(searchModule.getNamedWriteables()); entries.addAll(pluginsService.filterPlugins(Plugin.class).stream() .flatMap(p -> p.getNamedWriteables().stream()) @@ -440,27 +443,34 @@ public class TransportClient extends AbstractClient { for (Module pluginModule : pluginsService.createGuiceModules()) { modules.add(pluginModule); } - modules.add(networkModule); modules.add(b -> b.bind(ThreadPool.class).toInstance(threadPool)); - ActionModule actionModule = new ActionModule(false, true, settings, null, settingsModule.getClusterSettings(), + ActionModule actionModule = new ActionModule(false, true, + settings, null, settingsModule.getClusterSettings(), pluginsService.filterPlugins(ActionPlugin.class)); modules.add(actionModule); - pluginsService.processModules(modules); CircuitBreakerService circuitBreakerService = Node.createCircuitBreakerService(settingsModule.getSettings(), settingsModule.getClusterSettings()); - resourcesToClose.add(circuitBreakerService); BigArrays bigArrays = new BigArrays(settings, circuitBreakerService); + resourcesToClose.add(circuitBreakerService); resourcesToClose.add(bigArrays); modules.add(settingsModule); + NetworkModule networkModule = new NetworkModule(settings, true, + pluginsService.filterPlugins(NetworkPlugin.class), threadPool, + bigArrays, circuitBreakerService, namedWriteableRegistry, networkService); + final Transport transport = networkModule.getTransportSupplier().get(); + final TransportService transportService = new TransportService(settings, transport, threadPool, + networkModule.getTransportInterceptor(), null); modules.add((b -> { b.bind(BigArrays.class).toInstance(bigArrays); b.bind(PluginsService.class).toInstance(pluginsService); b.bind(CircuitBreakerService.class).toInstance(circuitBreakerService); b.bind(NamedWriteableRegistry.class).toInstance(namedWriteableRegistry); + b.bind(Transport.class).toInstance(transport); + b.bind(TransportService.class).toInstance(transportService); + b.bind(NetworkService.class).toInstance(networkService); })); Injector injector = modules.createInjector(); - final TransportService transportService = injector.getInstance(TransportService.class); final ProxyActionMap proxy = new ProxyActionMap(settings, transportService, actionModule.getActions().values().stream() .map(ActionPlugin.ActionHandler::getAction).collect(Collectors.toList()));