diff --git a/build.gradle b/build.gradle index 33d34f8..95c2701 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'org.xbib' -version = '5.0.1.0' +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", @@ -56,7 +56,13 @@ configurations { dependencies { compile "org.xbib:metrics:1.0.0" - compile "org.elasticsearch.client:transport:5.0.1" + compile("org.elasticsearch.client:transport:5.0.1") { + exclude group: 'org.elasticsearch', module: 'securesm' + exclude group: 'org.elasticsearch.plugin', module: 'transport-netty3-client' + exclude group: 'org.elasticsearch.plugin', module: 'reindex-client' + exclude group: 'org.elasticsearch.plugin', module: 'percolator-client' + exclude group: 'org.elasticsearch.plugin', module: 'lang-mustache-client' + } compile "org.apache.logging.log4j:log4j-api:2.7" testCompile "junit:junit:4.12" testCompile "org.apache.logging.log4j:log4j-core:2.7" diff --git a/src/integration-test/java/org/xbib/elasticsearch/NodeTestBase.java b/src/integration-test/java/org/xbib/elasticsearch/NodeTestBase.java index f68a729..86bb6dc 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/NodeTestBase.java +++ b/src/integration-test/java/org/xbib/elasticsearch/NodeTestBase.java @@ -34,7 +34,7 @@ import java.util.concurrent.atomic.AtomicInteger; */ public class NodeTestBase { - protected static final Logger logger = LogManager.getLogger("test"); + private static final Logger logger = LogManager.getLogger("test"); private static final Random random = new Random(); diff --git a/src/integration-test/java/org/xbib/elasticsearch/AliasTest.java b/src/integration-test/java/org/xbib/elasticsearch/extras/client/AliasTest.java similarity index 95% rename from src/integration-test/java/org/xbib/elasticsearch/AliasTest.java rename to src/integration-test/java/org/xbib/elasticsearch/extras/client/AliasTest.java index 0c683c1..81a84d9 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/AliasTest.java +++ b/src/integration-test/java/org/xbib/elasticsearch/extras/client/AliasTest.java @@ -1,4 +1,4 @@ -package org.xbib.elasticsearch; +package org.xbib.elasticsearch.extras.client; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -14,6 +14,7 @@ import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.common.Strings; import org.junit.Test; +import org.xbib.elasticsearch.NodeTestBase; import java.io.IOException; import java.util.Collections; @@ -72,10 +73,8 @@ public class AliasTest extends NodeTestBase { Set result = new TreeSet<>(Collections.reverseOrder()); for (ObjectCursor indexName : getAliasesResponse.getAliases().keys()) { Matcher m = pattern.matcher(indexName.value); - if (m.matches()) { - if (alias.equals(m.group(1))) { - result.add(indexName.value); - } + if (m.matches() && alias.equals(m.group(1))) { + result.add(indexName.value); } } Iterator it = result.iterator(); diff --git a/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeClusterBlockTest.java b/src/integration-test/java/org/xbib/elasticsearch/extras/client/ClusterBlockTest.java similarity index 88% rename from src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeClusterBlockTest.java rename to src/integration-test/java/org/xbib/elasticsearch/extras/client/ClusterBlockTest.java index 2b79ddc..07e492f 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeClusterBlockTest.java +++ b/src/integration-test/java/org/xbib/elasticsearch/extras/client/ClusterBlockTest.java @@ -1,4 +1,6 @@ -package org.xbib.elasticsearch.extras.client.node; +package org.xbib.elasticsearch.extras.client; + +import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -11,14 +13,12 @@ import org.junit.Before; import org.junit.Test; import org.xbib.elasticsearch.NodeTestBase; -import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; - /** * */ -public class BulkNodeClusterBlockTest extends NodeTestBase { +public class ClusterBlockTest extends NodeTestBase { - private static final Logger logger = LogManager.getLogger(BulkNodeClusterBlockTest.class.getName()); + private static final Logger logger = LogManager.getLogger(ClusterBlockTest.class.getName()); @Before public void startNodes() { diff --git a/src/integration-test/java/org/xbib/elasticsearch/SearchTest.java b/src/integration-test/java/org/xbib/elasticsearch/extras/client/SearchTest.java similarity index 96% rename from src/integration-test/java/org/xbib/elasticsearch/SearchTest.java rename to src/integration-test/java/org/xbib/elasticsearch/extras/client/SearchTest.java index efed10c..93a7ca7 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/SearchTest.java +++ b/src/integration-test/java/org/xbib/elasticsearch/extras/client/SearchTest.java @@ -1,4 +1,4 @@ -package org.xbib.elasticsearch; +package org.xbib.elasticsearch.extras.client; import static org.elasticsearch.client.Requests.indexRequest; import static org.elasticsearch.client.Requests.refreshRequest; @@ -15,6 +15,7 @@ import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.sort.SortOrder; import org.junit.Test; +import org.xbib.elasticsearch.NodeTestBase; /** * diff --git a/src/integration-test/java/org/xbib/elasticsearch/SimpleTest.java b/src/integration-test/java/org/xbib/elasticsearch/extras/client/SimpleTest.java similarity index 94% rename from src/integration-test/java/org/xbib/elasticsearch/SimpleTest.java rename to src/integration-test/java/org/xbib/elasticsearch/extras/client/SimpleTest.java index 70f1373..f32e321 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/SimpleTest.java +++ b/src/integration-test/java/org/xbib/elasticsearch/extras/client/SimpleTest.java @@ -1,4 +1,4 @@ -package org.xbib.elasticsearch; +package org.xbib.elasticsearch.extras.client; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; @@ -13,6 +13,7 @@ import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.support.WriteRequest; import org.elasticsearch.common.settings.Settings; import org.junit.Test; +import org.xbib.elasticsearch.NodeTestBase; /** * @@ -39,7 +40,8 @@ public class SimpleTest extends NodeTestBase { } catch (Exception e) { // ignore } - CreateIndexRequestBuilder createIndexRequestBuilder = new CreateIndexRequestBuilder(client("1"), CreateIndexAction.INSTANCE) + CreateIndexRequestBuilder createIndexRequestBuilder = new CreateIndexRequestBuilder(client("1"), + CreateIndexAction.INSTANCE) .setIndex("test") .setSettings(Settings.builder() .put("index.analysis.analyzer.default.filter.0", "lowercase") diff --git a/src/integration-test/java/org/xbib/elasticsearch/WildcardTest.java b/src/integration-test/java/org/xbib/elasticsearch/extras/client/WildcardTest.java similarity index 97% rename from src/integration-test/java/org/xbib/elasticsearch/WildcardTest.java rename to src/integration-test/java/org/xbib/elasticsearch/extras/client/WildcardTest.java index d412654..327b619 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/WildcardTest.java +++ b/src/integration-test/java/org/xbib/elasticsearch/extras/client/WildcardTest.java @@ -1,4 +1,4 @@ -package org.xbib.elasticsearch; +package org.xbib.elasticsearch.extras.client; import static org.elasticsearch.client.Requests.indexRequest; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; @@ -9,6 +9,7 @@ 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; import java.io.IOException; diff --git a/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeClientTest.java b/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeClientTest.java index a1165ff..4a295a7 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeClientTest.java +++ b/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeClientTest.java @@ -6,14 +6,12 @@ import static org.junit.Assert.assertFalse; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.util.ExecutorServices; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsAction; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.action.search.SearchAction; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.client.transport.NoNodeAvailableException; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.query.QueryBuilders; @@ -28,7 +26,6 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; /** @@ -68,7 +65,7 @@ public class BulkNodeClientTest extends NodeTestBase { } @Test - public void testMappingNodeClient() throws Exception { + public void testBulkNodeClientMapping() throws Exception { final BulkNodeClient client = ClientBuilder.builder() .put(ClientBuilder.FLUSH_INTERVAL, TimeValue.timeValueSeconds(5)) .setMetric(new SimpleBulkMetric()) @@ -98,7 +95,7 @@ public class BulkNodeClientTest extends NodeTestBase { } @Test - public void testSingleDocNodeClient() { + public void testBulkNodeClientSingleDoc() { final BulkNodeClient client = ClientBuilder.builder() .put(ClientBuilder.MAX_ACTIONS_PER_REQUEST, MAX_ACTIONS) .put(ClientBuilder.FLUSH_INTERVAL, TimeValue.timeValueSeconds(30)) @@ -127,7 +124,7 @@ public class BulkNodeClientTest extends NodeTestBase { } @Test - public void testRandomDocsNodeClient() throws Exception { + public void testBulkNodeClientRandomDocs() throws Exception { long numactions = NUM_ACTIONS; final BulkNodeClient client = ClientBuilder.builder() .put(ClientBuilder.MAX_ACTIONS_PER_REQUEST, MAX_ACTIONS) @@ -155,7 +152,7 @@ public class BulkNodeClientTest extends NodeTestBase { } @Test - public void testThreadedRandomDocsNodeClient() throws Exception { + public void testBulkNodeClientThreadedRandomDocs() throws Exception { int maxthreads = Runtime.getRuntime().availableProcessors(); Long maxactions = MAX_ACTIONS; final Long maxloop = NUM_ACTIONS; diff --git a/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeDuplicateIDTest.java b/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeDuplicateIDTest.java index d7e9a30..cb32cac 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeDuplicateIDTest.java +++ b/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeDuplicateIDTest.java @@ -1,5 +1,10 @@ package org.xbib.elasticsearch.extras.client.node; +import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.action.search.SearchAction; @@ -12,9 +17,6 @@ import org.xbib.elasticsearch.extras.client.ClientBuilder; import org.xbib.elasticsearch.extras.client.SimpleBulkControl; import org.xbib.elasticsearch.extras.client.SimpleBulkMetric; -import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; -import static org.junit.Assert.*; - /** * */ diff --git a/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeIndexAliasTest.java b/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeIndexAliasTest.java index a6f00a4..1c3b3fd 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeIndexAliasTest.java +++ b/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeIndexAliasTest.java @@ -1,5 +1,7 @@ package org.xbib.elasticsearch.extras.client.node; +import static org.junit.Assert.assertFalse; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder; @@ -17,8 +19,6 @@ import java.util.Arrays; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertFalse; - /** * */ diff --git a/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeReplicaTest.java b/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeReplicaTest.java index 637a28e..b0d8100 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeReplicaTest.java +++ b/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeReplicaTest.java @@ -1,5 +1,9 @@ package org.xbib.elasticsearch.extras.client.node; +import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.action.admin.indices.stats.CommonStats; @@ -22,16 +26,12 @@ import org.xbib.elasticsearch.extras.client.SimpleBulkMetric; import java.util.Map; -import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - /** * */ public class BulkNodeReplicaTest extends NodeTestBase { - private final static Logger logger = LogManager.getLogger(BulkNodeReplicaTest.class.getName()); + private static final Logger logger = LogManager.getLogger(BulkNodeReplicaTest.class.getName()); @Test public void testReplicaLevel() throws Exception { @@ -80,7 +80,8 @@ public class BulkNodeReplicaTest extends NodeTestBase { long hits = searchRequestBuilder.execute().actionGet().getHits().getTotalHits(); logger.info("query total hits={}", hits); assertEquals(2468, hits); - IndicesStatsRequestBuilder indicesStatsRequestBuilder = new IndicesStatsRequestBuilder(client.client(), IndicesStatsAction.INSTANCE) + IndicesStatsRequestBuilder indicesStatsRequestBuilder = new IndicesStatsRequestBuilder(client.client(), + IndicesStatsAction.INSTANCE) .all(); IndicesStatsResponse response = indicesStatsRequestBuilder.execute().actionGet(); for (Map.Entry m : response.getIndices().entrySet()) { diff --git a/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeUpdateReplicaLevelTest.java b/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeUpdateReplicaLevelTest.java index 7f43457..6d5cbe1 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeUpdateReplicaLevelTest.java +++ b/src/integration-test/java/org/xbib/elasticsearch/extras/client/node/BulkNodeUpdateReplicaLevelTest.java @@ -1,5 +1,8 @@ package org.xbib.elasticsearch.extras.client.node; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.client.transport.NoNodeAvailableException; @@ -11,9 +14,6 @@ import org.xbib.elasticsearch.extras.client.ClientBuilder; import org.xbib.elasticsearch.extras.client.SimpleBulkControl; import org.xbib.elasticsearch.extras.client.SimpleBulkMetric; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - /** * */ diff --git a/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportClientTest.java b/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportClientTest.java index 4b6dc41..205aa88 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportClientTest.java +++ b/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportClientTest.java @@ -1,10 +1,20 @@ package org.xbib.elasticsearch.extras.client.transport; +import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsAction; +import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; +import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.action.search.SearchAction; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.client.transport.NoNodeAvailableException; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.junit.Before; import org.junit.Test; @@ -12,6 +22,7 @@ import org.xbib.elasticsearch.NodeTestBase; import org.xbib.elasticsearch.extras.client.ClientBuilder; import org.xbib.elasticsearch.extras.client.SimpleBulkControl; import org.xbib.elasticsearch.extras.client.SimpleBulkMetric; +import org.xbib.elasticsearch.extras.client.node.BulkNodeClient; import java.io.IOException; import java.util.concurrent.CountDownLatch; @@ -20,14 +31,13 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - /** * */ public class BulkTransportClientTest extends NodeTestBase { + private static final Logger logger = LogManager.getLogger(BulkTransportClientTest.class.getName()); + private static final Long MAX_ACTIONS = 1000L; private static final Long NUM_ACTIONS = 1234L; @@ -43,7 +53,7 @@ public class BulkTransportClientTest extends NodeTestBase { } @Test - public void testBulkClientIndexCreation() throws IOException { + public void testBulkTransportClientNewIndex() throws IOException { logger.info("firing up BulkTransportClient"); final BulkTransportClient client = ClientBuilder.builder() .put(getClientSettings()) @@ -75,7 +85,38 @@ public class BulkTransportClientTest extends NodeTestBase { } @Test - public void testSingleDocBulkClient() throws IOException { + public void testBulkTransportClientMapping() throws Exception { + final BulkTransportClient client = ClientBuilder.builder() + .put(getClientSettings()) + .put(ClientBuilder.FLUSH_INTERVAL, TimeValue.timeValueSeconds(5)) + .setMetric(new SimpleBulkMetric()) + .setControl(new SimpleBulkControl()) + .toBulkTransportClient(); + XContentBuilder builder = jsonBuilder() + .startObject() + .startObject("test") + .startObject("properties") + .startObject("location") + .field("type", "geo_point") + .endObject() + .endObject() + .endObject() + .endObject(); + client.mapping("test", builder.string()); + client.newIndex("test"); + GetMappingsRequest getMappingsRequest = new GetMappingsRequest().indices("test"); + GetMappingsResponse getMappingsResponse = + client.client().execute(GetMappingsAction.INSTANCE, getMappingsRequest).actionGet(); + logger.info("mappings={}", getMappingsResponse.getMappings()); + if (client.hasThrowable()) { + logger.error("error", client.getThrowable()); + } + assertFalse(client.hasThrowable()); + client.shutdown(); + } + + @Test + public void testBulkTransportClientSingleDoc() throws IOException { logger.info("firing up BulkTransportClient"); final BulkTransportClient client = ClientBuilder.builder() .put(getClientSettings()) @@ -111,7 +152,7 @@ public class BulkTransportClientTest extends NodeTestBase { } @Test - public void testRandomDocsBulkClient() { + public void testBulkTransportClientRandomDocs() { long numactions = NUM_ACTIONS; final BulkTransportClient client = ClientBuilder.builder() .put(getClientSettings()) @@ -147,7 +188,7 @@ public class BulkTransportClientTest extends NodeTestBase { } @Test - public void testThreadedRandomDocsBulkClient() { + public void testBulkTransportClientThreadedRandomDocs() { int maxthreads = Runtime.getRuntime().availableProcessors(); long maxactions = MAX_ACTIONS; final long maxloop = NUM_ACTIONS; diff --git a/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportDuplicateIDTest.java b/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportDuplicateIDTest.java index 574928c..148215a 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportDuplicateIDTest.java +++ b/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportDuplicateIDTest.java @@ -1,5 +1,12 @@ package org.xbib.elasticsearch.extras.client.transport; +import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.elasticsearch.action.search.SearchAction; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.client.transport.NoNodeAvailableException; @@ -10,17 +17,16 @@ import org.xbib.elasticsearch.extras.client.ClientBuilder; import org.xbib.elasticsearch.extras.client.SimpleBulkControl; import org.xbib.elasticsearch.extras.client.SimpleBulkMetric; -import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; -import static org.junit.Assert.*; - /** * */ public class BulkTransportDuplicateIDTest extends NodeTestBase { - private final static Long MAX_ACTIONS = 1000L; + private static final Logger logger = LogManager.getLogger(BulkTransportDuplicateIDTest.class.getName()); - private final static Long NUM_ACTIONS = 12345L; + private static final Long MAX_ACTIONS = 1000L; + + private static final Long NUM_ACTIONS = 12345L; @Test public void testDuplicateDocIDs() throws Exception { diff --git a/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportReplicaTest.java b/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportReplicaTest.java index 386f212..ffad2c7 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportReplicaTest.java +++ b/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportReplicaTest.java @@ -1,6 +1,17 @@ package org.xbib.elasticsearch.extras.client.transport; -import org.elasticsearch.action.admin.indices.stats.*; +import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.elasticsearch.action.admin.indices.stats.CommonStats; +import org.elasticsearch.action.admin.indices.stats.IndexShardStats; +import org.elasticsearch.action.admin.indices.stats.IndexStats; +import org.elasticsearch.action.admin.indices.stats.IndicesStatsAction; +import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder; +import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; import org.elasticsearch.action.search.SearchAction; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.client.transport.NoNodeAvailableException; @@ -15,15 +26,13 @@ import org.xbib.elasticsearch.extras.client.SimpleBulkMetric; import java.util.Map; -import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - /** * */ public class BulkTransportReplicaTest extends NodeTestBase { + private static final Logger logger = LogManager.getLogger(BulkTransportClientTest.class.getName()); + @Test public void testReplicaLevel() throws Exception { diff --git a/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportUpdateReplicaLevelTest.java b/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportUpdateReplicaLevelTest.java index 331ac11..abcf7a5 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportUpdateReplicaLevelTest.java +++ b/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportUpdateReplicaLevelTest.java @@ -1,5 +1,8 @@ package org.xbib.elasticsearch.extras.client.transport; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.client.transport.NoNodeAvailableException; @@ -11,9 +14,6 @@ import org.xbib.elasticsearch.extras.client.ClientBuilder; import org.xbib.elasticsearch.extras.client.SimpleBulkControl; import org.xbib.elasticsearch.extras.client.SimpleBulkMetric; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - /** * */ diff --git a/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/package-info.java b/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/package-info.java new file mode 100644 index 0000000..f55c996 --- /dev/null +++ b/src/integration-test/java/org/xbib/elasticsearch/extras/client/transport/package-info.java @@ -0,0 +1,4 @@ +/** + * Classes for testing extras for transport client. + */ +package org.xbib.elasticsearch.extras.client.transport; diff --git a/src/integration-test/java/org/xbib/elasticsearch/package-info.java b/src/integration-test/java/org/xbib/elasticsearch/package-info.java index 2958ce1..3c6e5c6 100644 --- a/src/integration-test/java/org/xbib/elasticsearch/package-info.java +++ b/src/integration-test/java/org/xbib/elasticsearch/package-info.java @@ -1,4 +1,4 @@ /** * Test classes for testing Elasticsearch. */ -package org.xbib.elasticsearch; \ No newline at end of file +package org.xbib.elasticsearch; diff --git a/src/integration-test/java/suites/ListenerSuite.java b/src/integration-test/java/suites/ListenerSuite.java index c02d371..4101890 100644 --- a/src/integration-test/java/suites/ListenerSuite.java +++ b/src/integration-test/java/suites/ListenerSuite.java @@ -6,6 +6,9 @@ import org.junit.runners.Suite; import org.junit.runners.model.InitializationError; import org.junit.runners.model.RunnerBuilder; +/** + * + */ public class ListenerSuite extends Suite { private final TestListener listener = new TestListener(); diff --git a/src/integration-test/java/suites/MiscTestSuite.java b/src/integration-test/java/suites/MiscTestSuite.java index ea23630..f832e88 100644 --- a/src/integration-test/java/suites/MiscTestSuite.java +++ b/src/integration-test/java/suites/MiscTestSuite.java @@ -2,10 +2,10 @@ package suites; import org.junit.runner.RunWith; import org.junit.runners.Suite; -import org.xbib.elasticsearch.AliasTest; -import org.xbib.elasticsearch.SearchTest; -import org.xbib.elasticsearch.SimpleTest; -import org.xbib.elasticsearch.WildcardTest; +import org.xbib.elasticsearch.extras.client.AliasTest; +import org.xbib.elasticsearch.extras.client.SearchTest; +import org.xbib.elasticsearch.extras.client.SimpleTest; +import org.xbib.elasticsearch.extras.client.WildcardTest; /** * diff --git a/src/integration-test/java/suites/package-info.java b/src/integration-test/java/suites/package-info.java new file mode 100644 index 0000000..a878170 --- /dev/null +++ b/src/integration-test/java/suites/package-info.java @@ -0,0 +1,4 @@ +/** + * Test suites. + */ +package suites; diff --git a/src/main/java/org/xbib/elasticsearch/extras/client/AbstractClient.java b/src/main/java/org/xbib/elasticsearch/extras/client/AbstractClient.java index f4ce3aa..ec25b81 100644 --- a/src/main/java/org/xbib/elasticsearch/extras/client/AbstractClient.java +++ b/src/main/java/org/xbib/elasticsearch/extras/client/AbstractClient.java @@ -1,9 +1,9 @@ package org.xbib.elasticsearch.extras.client; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.elasticsearch.ElasticsearchTimeoutException; import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; diff --git a/src/main/java/org/xbib/elasticsearch/extras/client/node/BulkNodeClient.java b/src/main/java/org/xbib/elasticsearch/extras/client/node/BulkNodeClient.java index 17a0779..bac6bca 100644 --- a/src/main/java/org/xbib/elasticsearch/extras/client/node/BulkNodeClient.java +++ b/src/main/java/org/xbib/elasticsearch/extras/client/node/BulkNodeClient.java @@ -101,6 +101,9 @@ public class BulkNodeClient extends AbstractClient implements ClientMethods { metric.start(); } BulkProcessor.Listener listener = new BulkProcessor.Listener() { + + private final Logger logger = LogManager.getLogger(BulkNodeClient.class.getName() + ".Listener"); + @Override public void beforeBulk(long executionId, BulkRequest request) { long l = -1; diff --git a/src/main/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportClient.java b/src/main/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportClient.java index be51e62..3d159ab 100644 --- a/src/main/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportClient.java +++ b/src/main/java/org/xbib/elasticsearch/extras/client/transport/BulkTransportClient.java @@ -27,7 +27,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.env.Environment; import org.elasticsearch.transport.Netty4Plugin; import org.xbib.elasticsearch.extras.client.AbstractClient; import org.xbib.elasticsearch.extras.client.BulkControl; @@ -54,8 +53,6 @@ public class BulkTransportClient extends AbstractClient implements ClientMethods private static final Logger logger = LogManager.getLogger(BulkTransportClient.class.getName()); - private static final Settings DEFAULT_SETTINGS = Settings.builder().put("transport.type.default", "local").build(); - private int maxActionsPerRequest = DEFAULT_MAX_ACTIONS_PER_REQUEST; private int maxConcurrentRequests = DEFAULT_MAX_CONCURRENT_REQUESTS; @@ -95,6 +92,9 @@ public class BulkTransportClient extends AbstractClient implements ClientMethods } resetSettings(); BulkProcessor.Listener listener = new BulkProcessor.Listener() { + + private final Logger logger = LogManager.getLogger(BulkTransportClient.class.getName() + ".Listener"); + @Override public void beforeBulk(long executionId, BulkRequest request) { long l = -1L; @@ -170,7 +170,7 @@ public class BulkTransportClient extends AbstractClient implements ClientMethods builder.setBulkSize(maxVolumePerRequest); } this.bulkProcessor = builder.build(); - // aut-connect here + // auto-connect here try { Collection addrs = findAddresses(settings); if (!connect(addrs, settings.getAsBoolean("autodiscover", false))) { 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 2ded1ab..d0c377d 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 @@ -91,15 +91,14 @@ public class TransportClient extends AbstractClient { private final Object mutex = new Object(); - private volatile List listedNodes = Collections.emptyList(); - private volatile List nodes = Collections.emptyList(); + private volatile List listedNodes = Collections.emptyList(); + private volatile List filteredNodes = Collections.emptyList(); private volatile boolean closed; - /** * Creates a new TransportClient with the given settings and plugins. * @param settings settings @@ -197,37 +196,44 @@ public class TransportClient extends AbstractClient { return this; } + /** + * Adds a list of transport addresses that will be used to connect to. + * The Node this transport address represents will be used if its possible to connect to it. + * If it is unavailable, it will be automatically connected to once it is up. + * In order to get the list of all the current connected nodes, please see {@link #connectedNodes()}. + * + * @param transportAddresses transport addressses + * @return this transport client + */ public TransportClient addTransportAddresses(Collection transportAddresses) { synchronized (mutex) { if (closed) { throw new IllegalStateException("transport client is closed, can't add addresses"); } - List filtered = new ArrayList<>(transportAddresses.size()); - for (TransportAddress transportAddress : transportAddresses) { + Set discoveryNodeList = new HashSet<>(); + discoveryNodeList.addAll(listedNodes); + logger.debug("before adding: nodes={} listednodes={} transportAddresses={}", + nodes, listedNodes, transportAddresses); + for (TransportAddress newTransportAddress : transportAddresses) { boolean found = false; - for (DiscoveryNode otherNode : listedNodes) { - if (otherNode.getAddress().equals(transportAddress)) { + for (DiscoveryNode discoveryNode : discoveryNodeList) { + logger.debug("checking existing address [{}] against new [{}]", + discoveryNode.getAddress(), newTransportAddress); + if (discoveryNode.getAddress().sameHost(newTransportAddress)) { found = true; - logger.debug("address [{}] already exists with [{}], ignoring...", transportAddress, otherNode); + logger.debug("address [{}] already connected, ignoring", newTransportAddress, discoveryNode); break; } } if (!found) { - filtered.add(transportAddress); + DiscoveryNode node = new DiscoveryNode("#transport#-" + tempNodeId.incrementAndGet(), + newTransportAddress, + Version.CURRENT.minimumCompatibilityVersion()); + logger.debug("adding address [{}]", node); + discoveryNodeList.add(node); } } - if (filtered.isEmpty()) { - return this; - } - List discoveryNodeList = new ArrayList<>(); - discoveryNodeList.addAll(listedNodes()); - for (TransportAddress transportAddress : filtered) { - DiscoveryNode node = new DiscoveryNode("#transport#-" + tempNodeId.incrementAndGet(), transportAddress, - Version.CURRENT.minimumCompatibilityVersion()); - logger.debug("adding address [{}]", node); - discoveryNodeList.add(node); - } - listedNodes = Collections.unmodifiableList(discoveryNodeList); + listedNodes = Collections.unmodifiableList(new ArrayList<>(discoveryNodeList)); connect(); } return this; @@ -265,13 +271,16 @@ public class TransportClient extends AbstractClient { return; } closed = true; + logger.debug("disconnecting from nodes {}", nodes); for (DiscoveryNode node : nodes) { transportService.disconnectFromNode(node); } + nodes = Collections.emptyList(); + logger.debug("disconnecting from listed nodes {}", listedNodes); for (DiscoveryNode listedNode : listedNodes) { transportService.disconnectFromNode(listedNode); } - nodes = Collections.emptyList(); + listedNodes = Collections.emptyList(); } injector.getInstance(TransportService.class).close(); for (Class plugin : injector.getInstance(PluginsService.class).getGuiceServiceClasses()) { @@ -290,7 +299,7 @@ public class TransportClient extends AbstractClient { for (DiscoveryNode listedNode : listedNodes) { if (!transportService.nodeConnected(listedNode)) { try { - logger.trace("connecting to listed node (light) [{}]", listedNode); + logger.debug("connecting to listed node (light) [{}]", listedNode); transportService.connectToNodeLight(listedNode); } catch (Exception e) { logger.debug("failed to connect to node [{}], removed from nodes list", e, listedNode); @@ -309,7 +318,7 @@ public class TransportClient extends AbstractClient { } }).txGet(); if (!clusterName.equals(livenessResponse.getClusterName())) { - logger.warn("node {} not part of the cluster {}, ignoring...", listedNode, clusterName); + logger.warn("node {} not part of the cluster {}, ignoring", listedNode, clusterName); newFilteredNodes.add(listedNode); } else if (livenessResponse.getDiscoveryNode() != null) { DiscoveryNode nodeWithInfo = livenessResponse.getDiscoveryNode(); @@ -323,7 +332,7 @@ public class TransportClient extends AbstractClient { newNodes.add(listedNode); } } catch (Exception e) { - logger.info("failed to get node info for {}, disconnecting...", e, listedNode); + logger.info("failed to get node info for {}, disconnecting", e, listedNode); transportService.disconnectFromNode(listedNode); } } @@ -331,7 +340,7 @@ public class TransportClient extends AbstractClient { DiscoveryNode node = it.next(); if (!transportService.nodeConnected(node)) { try { - logger.trace("connecting to node [{}]", node); + logger.debug("connecting to new node [{}]", node); transportService.connectToNode(node); } catch (Exception e) { it.remove(); @@ -340,6 +349,7 @@ public class TransportClient extends AbstractClient { } } this.nodes = Collections.unmodifiableList(new ArrayList<>(newNodes)); + logger.debug("connected to {} nodes", nodes.size()); this.filteredNodes = Collections.unmodifiableList(new ArrayList<>(newFilteredNodes)); } @@ -392,10 +402,13 @@ public class TransportClient extends AbstractClient { } - private static ClientTemplate buildTemplate(Settings providedSettings, Settings defaultSettings, + private static ClientTemplate buildTemplate(Settings givenSettings, Settings defaultSettings, Collection> plugins) { + Settings providedSettings = givenSettings; if (!Node.NODE_NAME_SETTING.exists(providedSettings)) { - providedSettings = Settings.builder().put(providedSettings).put(Node.NODE_NAME_SETTING.getKey(), "_client_").build(); + providedSettings = Settings.builder().put(providedSettings) + .put(Node.NODE_NAME_SETTING.getKey(), "_client_") + .build(); } final PluginsService pluginsService = newPluginService(providedSettings, plugins); final Settings settings = Settings.builder().put(defaultSettings).put(pluginsService.updatedSettings()).build(); @@ -423,7 +436,7 @@ public class TransportClient extends AbstractClient { NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(entries); ModulesBuilder modules = new ModulesBuilder(); - // plugin modules must be added here, before others or we can get crazy injection errors... + // plugin modules must be added here, before others or we can get crazy injection errors for (Module pluginModule : pluginsService.createGuiceModules()) { modules.add(pluginModule); } @@ -457,8 +470,7 @@ public class TransportClient extends AbstractClient { resourcesToClose.addAll(pluginLifecycleComponents); transportService.start(); transportService.acceptIncomingRequests(); - ClientTemplate transportClient = new ClientTemplate(injector, pluginLifecycleComponents, - proxy, namedWriteableRegistry); + ClientTemplate transportClient = new ClientTemplate(injector, proxy); resourcesToClose.clear(); return transportClient; } finally { @@ -482,16 +494,12 @@ public class TransportClient extends AbstractClient { private static final class ClientTemplate { final Injector injector; - private final List pluginLifecycleComponents; private final ProxyActionMap proxy; - private final NamedWriteableRegistry namedWriteableRegistry; - private ClientTemplate(Injector injector, List pluginLifecycleComponents, - ProxyActionMap proxy, NamedWriteableRegistry namedWriteableRegistry) { + private ClientTemplate(Injector injector, + ProxyActionMap proxy) { this.injector = injector; - this.pluginLifecycleComponents = pluginLifecycleComponents; this.proxy = proxy; - this.namedWriteableRegistry = namedWriteableRegistry; } Settings getSettings() {