add explicit dependencies for Groovy grape usage, explicit class loader handling for Groovy class loading
This commit is contained in:
parent
469ca41001
commit
e79c3f07b2
33 changed files with 87 additions and 62 deletions
|
@ -4,4 +4,16 @@ dependencies {
|
|||
// override old artifacts in ES x-content. We must use jackson smile/cbor/yaml and log4j2 api here.
|
||||
api libs.jackson
|
||||
api libs.log4j.api
|
||||
// add dependencies which are not managed by elasticsearch as a runtime dependency.
|
||||
// So, groovy grapes can load and run smoothly the elx client.
|
||||
implementation libs.lucene
|
||||
implementation libs.lucene.analyzers.common
|
||||
implementation libs.lucene.highlighter
|
||||
implementation libs.lucene.join
|
||||
implementation libs.lucene.queryparser
|
||||
implementation libs.lucene.grouping
|
||||
implementation libs.lucene.misc
|
||||
implementation libs.hppc
|
||||
implementation libs.joda
|
||||
implementation libs.tdigest
|
||||
}
|
||||
|
|
|
@ -3,5 +3,5 @@ package org.xbib.elx.api;
|
|||
@FunctionalInterface
|
||||
public interface AdminClientProvider<C extends AdminClient> {
|
||||
|
||||
C getClient();
|
||||
C getClient(ClassLoader classLoader);
|
||||
}
|
||||
|
|
|
@ -3,5 +3,5 @@ package org.xbib.elx.api;
|
|||
@FunctionalInterface
|
||||
public interface BulkClientProvider<C extends BulkClient> {
|
||||
|
||||
C getClient();
|
||||
C getClient(ClassLoader classLoader);
|
||||
}
|
||||
|
|
|
@ -3,5 +3,5 @@ package org.xbib.elx.api;
|
|||
@FunctionalInterface
|
||||
public interface SearchClientProvider<C extends SearchClient> {
|
||||
|
||||
C getClient();
|
||||
C getClient(ClassLoader classLoader);
|
||||
}
|
||||
|
|
|
@ -24,10 +24,10 @@ public class ClientBuilder {
|
|||
|
||||
private final ElasticsearchClient client;
|
||||
|
||||
private final ClassLoader classLoader;
|
||||
|
||||
private final Settings.Builder settingsBuilder;
|
||||
|
||||
private ClassLoader classLoader;
|
||||
|
||||
private Class<? extends AdminClientProvider> adminClientProvider;
|
||||
|
||||
private Class<? extends BulkClientProvider> bulkClientProvider;
|
||||
|
@ -39,12 +39,7 @@ public class ClientBuilder {
|
|||
}
|
||||
|
||||
public ClientBuilder(ElasticsearchClient client) {
|
||||
this(client, ClassLoader.getSystemClassLoader());
|
||||
}
|
||||
|
||||
public ClientBuilder(ElasticsearchClient client, ClassLoader classLoader) {
|
||||
this.client = client;
|
||||
this.classLoader = classLoader;
|
||||
this.settingsBuilder = Settings.builder();
|
||||
settingsBuilder.put("node.name", "elx-client-" + Version.CURRENT);
|
||||
for (Parameters p : Parameters.values()) {
|
||||
|
@ -68,6 +63,11 @@ public class ClientBuilder {
|
|||
return new ClientBuilder(client);
|
||||
}
|
||||
|
||||
public ClientBuilder setClassLoader(ClassLoader classLoader) {
|
||||
this.classLoader = classLoader;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ClientBuilder setAdminClientProvider(Class<? extends AdminClientProvider> adminClientProvider) {
|
||||
this.adminClientProvider = adminClientProvider;
|
||||
return this;
|
||||
|
@ -148,7 +148,7 @@ public class ClientBuilder {
|
|||
if (adminClientProvider != null) {
|
||||
for (AdminClientProvider provider : ServiceLoader.load(AdminClientProvider.class, classLoader)) {
|
||||
if (provider.getClass().isAssignableFrom(adminClientProvider)) {
|
||||
C c = (C) provider.getClient();
|
||||
C c = (C) provider.getClient(classLoader);
|
||||
c.setClient(client);
|
||||
c.init(settings, null);
|
||||
return c;
|
||||
|
@ -158,7 +158,7 @@ public class ClientBuilder {
|
|||
if (bulkClientProvider != null) {
|
||||
for (BulkClientProvider provider : ServiceLoader.load(BulkClientProvider.class, classLoader)) {
|
||||
if (provider.getClass().isAssignableFrom(bulkClientProvider)) {
|
||||
C c = (C) provider.getClient();
|
||||
C c = (C) provider.getClient(classLoader);
|
||||
c.setClient(client);
|
||||
c.init(settings, null);
|
||||
return c;
|
||||
|
@ -168,7 +168,7 @@ public class ClientBuilder {
|
|||
if (searchClientProvider != null) {
|
||||
for (SearchClientProvider provider : ServiceLoader.load(SearchClientProvider.class, classLoader)) {
|
||||
if (provider.getClass().isAssignableFrom(searchClientProvider)) {
|
||||
C c = (C) provider.getClient();
|
||||
C c = (C) provider.getClient(classLoader);
|
||||
c.setClient(client);
|
||||
c.init(settings, null);
|
||||
return c;
|
||||
|
|
|
@ -73,7 +73,7 @@ public class DefaultIndexDefinition implements IndexDefinition {
|
|||
setEnabled(true);
|
||||
}
|
||||
|
||||
public DefaultIndexDefinition(AdminClient adminClient, String index, String type, Settings settings)
|
||||
public DefaultIndexDefinition(AdminClient adminClient, String index, String type, Settings settings, ClassLoader classLoader)
|
||||
throws IOException {
|
||||
String indexName = settings.get("name", index);
|
||||
String indexType = settings.get("type", type);
|
||||
|
@ -92,8 +92,8 @@ public class DefaultIndexDefinition implements IndexDefinition {
|
|||
setStopBulkRefreshSeconds(settings.getAsInt(Parameters.BULK_STOP_REFRESH_SECONDS.getName(),
|
||||
Parameters.BULK_STOP_REFRESH_SECONDS.getInteger()));
|
||||
if (settings.get("settings") != null && settings.get("mapping") != null) {
|
||||
setSettings(findSettingsFrom(settings.get("settings")));
|
||||
setMappings(findMappingsFrom(settings.get("mapping")));
|
||||
setSettings(findSettingsFrom(settings.get("settings"), classLoader));
|
||||
setMappings(findMappingsFrom(settings.get("mapping"), classLoader));
|
||||
}
|
||||
boolean shift = settings.getAsBoolean("shift", false);
|
||||
setShift(shift);
|
||||
|
@ -307,13 +307,14 @@ public class DefaultIndexDefinition implements IndexDefinition {
|
|||
public int getMinToKeep() {
|
||||
return minToKeep;
|
||||
}
|
||||
private static String findSettingsFrom(String string) throws IOException {
|
||||
|
||||
private static String findSettingsFrom(String string, ClassLoader classLoader) throws IOException {
|
||||
if (string == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
XContentBuilder builder = JsonXContent.contentBuilder();
|
||||
try (InputStream inputStream = findInputStream(string)) {
|
||||
try (InputStream inputStream = findInputStream(string, classLoader)) {
|
||||
if (inputStream != null) {
|
||||
Settings settings = Settings.builder().loadFromStream(string, inputStream, true).build();
|
||||
builder.startObject();
|
||||
|
@ -329,13 +330,13 @@ public class DefaultIndexDefinition implements IndexDefinition {
|
|||
}
|
||||
}
|
||||
|
||||
private static String findMappingsFrom(String string) throws IOException {
|
||||
private static String findMappingsFrom(String string, ClassLoader classLoader) throws IOException {
|
||||
if (string == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
XContentBuilder builder = JsonXContent.contentBuilder();
|
||||
try (InputStream inputStream = findInputStream(string)) {
|
||||
try (InputStream inputStream = findInputStream(string, classLoader)) {
|
||||
if (inputStream != null) {
|
||||
if (string.endsWith(".json")) {
|
||||
Map<String, ?> mappings = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY,
|
||||
|
@ -357,12 +358,12 @@ public class DefaultIndexDefinition implements IndexDefinition {
|
|||
}
|
||||
}
|
||||
|
||||
private static InputStream findInputStream(String string) {
|
||||
private static InputStream findInputStream(String string, ClassLoader classLoader) {
|
||||
if (string == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
URL url = ClassLoader.getSystemClassLoader().getResource(string);
|
||||
URL url = classLoader.getResource(string);
|
||||
if (url == null) {
|
||||
url = new URL(string);
|
||||
}
|
||||
|
|
|
@ -3,8 +3,9 @@ package org.xbib.elx.common;
|
|||
import org.xbib.elx.api.AdminClientProvider;
|
||||
|
||||
public class MockAdminClientProvider implements AdminClientProvider<MockAdminClient> {
|
||||
|
||||
@Override
|
||||
public MockAdminClient getClient() {
|
||||
public MockAdminClient getClient(ClassLoader classLoader) {
|
||||
return new MockAdminClient();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.xbib.elx.api.BulkClientProvider;
|
|||
public class MockBulkClientProvider implements BulkClientProvider<MockBulkClient> {
|
||||
|
||||
@Override
|
||||
public MockBulkClient getClient() {
|
||||
public MockBulkClient getClient(ClassLoader classLoader) {
|
||||
return new MockBulkClient();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.xbib.elx.api.SearchClientProvider;
|
|||
public class MockSearchClientProvider implements SearchClientProvider<MockSearchClient> {
|
||||
|
||||
@Override
|
||||
public MockSearchClient getClient() {
|
||||
public MockSearchClient getClient(ClassLoader classLoader) {
|
||||
return new MockSearchClient();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@ public class HttpAdminClient extends AbstractAdminClient implements Elasticsearc
|
|||
|
||||
private final HttpClientHelper helper;
|
||||
|
||||
public HttpAdminClient() {
|
||||
public HttpAdminClient(ClassLoader classLoader) {
|
||||
super();
|
||||
this.helper = new HttpClientHelper();
|
||||
this.helper = new HttpClientHelper(classLoader);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.xbib.elx.api.AdminClientProvider;
|
|||
public class HttpAdminClientProvider implements AdminClientProvider<HttpAdminClient> {
|
||||
|
||||
@Override
|
||||
public HttpAdminClient getClient() {
|
||||
return new HttpAdminClient();
|
||||
public HttpAdminClient getClient(ClassLoader classLoader) {
|
||||
return new HttpAdminClient(classLoader);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@ public class HttpBulkClient extends AbstractBulkClient implements ElasticsearchC
|
|||
|
||||
private final HttpClientHelper helper;
|
||||
|
||||
public HttpBulkClient() {
|
||||
public HttpBulkClient(ClassLoader classLoader) {
|
||||
super();
|
||||
this.helper = new HttpClientHelper();
|
||||
this.helper = new HttpClientHelper(classLoader);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.xbib.elx.api.BulkClientProvider;
|
|||
public class HttpBulkClientProvider implements BulkClientProvider<HttpBulkClient> {
|
||||
|
||||
@Override
|
||||
public HttpBulkClient getClient() {
|
||||
return new HttpBulkClient();
|
||||
public HttpBulkClient getClient(ClassLoader classLoader) {
|
||||
return new HttpBulkClient(classLoader);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,15 +50,15 @@ public class HttpClientHelper {
|
|||
|
||||
private final AtomicBoolean closed;
|
||||
|
||||
public HttpClientHelper() {
|
||||
this(Collections.emptyList(), Thread.currentThread().getContextClassLoader());
|
||||
public HttpClientHelper(ClassLoader classLoader) {
|
||||
this(Collections.emptyList(), classLoader);
|
||||
}
|
||||
|
||||
public HttpClientHelper(List<NamedXContentRegistry.Entry> namedXContentEntries,
|
||||
ClassLoader classLoader) {
|
||||
this.registry = new NamedXContentRegistry(Stream.of(getNamedXContents().stream(),
|
||||
namedXContentEntries.stream()).flatMap(Function.identity()).collect(Collectors.toList()));
|
||||
this.classLoader = classLoader != null ? classLoader : Thread.currentThread().getContextClassLoader();
|
||||
this.classLoader = classLoader;
|
||||
this.actionMap = new HashMap<>();
|
||||
this.closed = new AtomicBoolean();
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@ public class HttpSearchClient extends AbstractSearchClient implements Elasticsea
|
|||
|
||||
private final HttpClientHelper helper;
|
||||
|
||||
public HttpSearchClient() {
|
||||
public HttpSearchClient(ClassLoader classLoader) {
|
||||
super();
|
||||
this.helper = new HttpClientHelper();
|
||||
this.helper = new HttpClientHelper(classLoader);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.xbib.elx.api.SearchClientProvider;
|
|||
public class HttpSearchClientProvider implements SearchClientProvider<HttpSearchClient> {
|
||||
|
||||
@Override
|
||||
public HttpSearchClient getClient() {
|
||||
return new HttpSearchClient();
|
||||
public HttpSearchClient getClient(ClassLoader classLoader) {
|
||||
return new HttpSearchClient(classLoader);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ class SmokeTest {
|
|||
.put(helper.getClientSettings())
|
||||
.build()) {
|
||||
IndexDefinition indexDefinition =
|
||||
new DefaultIndexDefinition(adminClient, "test_smoke", "doc", Settings.EMPTY);
|
||||
new DefaultIndexDefinition(adminClient, "test_smoke", "doc", Settings.EMPTY, getClass().getClassLoader());
|
||||
assertEquals(1, indexDefinition.getReplicaCount());
|
||||
assertEquals(helper.getClusterName(), adminClient.getClusterName());
|
||||
bulkClient.newIndex(indexDefinition);
|
||||
|
|
|
@ -8,7 +8,7 @@ public class NodeAdminClient extends AbstractAdminClient {
|
|||
|
||||
private final NodeClientHelper helper;
|
||||
|
||||
public NodeAdminClient() {
|
||||
public NodeAdminClient(ClassLoader classLoader) {
|
||||
super();
|
||||
this.helper = new NodeClientHelper();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.xbib.elx.api.AdminClientProvider;
|
|||
public class NodeAdminClientProvider implements AdminClientProvider<NodeAdminClient> {
|
||||
|
||||
@Override
|
||||
public NodeAdminClient getClient() {
|
||||
return new NodeAdminClient();
|
||||
public NodeAdminClient getClient(ClassLoader classLoader) {
|
||||
return new NodeAdminClient(classLoader);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ public class NodeBulkClient extends AbstractBulkClient {
|
|||
|
||||
private final NodeClientHelper helper;
|
||||
|
||||
public NodeBulkClient() {
|
||||
public NodeBulkClient(ClassLoader classLoader) {
|
||||
super();
|
||||
this.helper = new NodeClientHelper();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.xbib.elx.api.BulkClientProvider;
|
|||
public class NodeBulkClientProvider implements BulkClientProvider<NodeBulkClient> {
|
||||
|
||||
@Override
|
||||
public NodeBulkClient getClient() {
|
||||
return new NodeBulkClient();
|
||||
public NodeBulkClient getClient(ClassLoader classLoader) {
|
||||
return new NodeBulkClient(classLoader);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ public class NodeSearchClient extends AbstractSearchClient {
|
|||
|
||||
private final NodeClientHelper helper;
|
||||
|
||||
public NodeSearchClient() {
|
||||
public NodeSearchClient(ClassLoader classLoader) {
|
||||
super();
|
||||
this.helper = new NodeClientHelper();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.xbib.elx.api.SearchClientProvider;
|
|||
public class NodeSearchClientProvider implements SearchClientProvider<NodeSearchClient> {
|
||||
|
||||
@Override
|
||||
public NodeSearchClient getClient() {
|
||||
return new NodeSearchClient();
|
||||
public NodeSearchClient getClient(ClassLoader classLoader) {
|
||||
return new NodeSearchClient(classLoader);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ class SmokeTest {
|
|||
.put(helper.getClientSettings())
|
||||
.build()) {
|
||||
IndexDefinition indexDefinition =
|
||||
new DefaultIndexDefinition(adminClient, "test_smoke", "doc", Settings.EMPTY);
|
||||
new DefaultIndexDefinition(adminClient, "test_smoke", "doc", Settings.EMPTY, getClass().getClassLoader());
|
||||
assertEquals("test_smoke", indexDefinition.getIndex());
|
||||
assertTrue(indexDefinition.getFullIndexName().startsWith("test_smoke"));
|
||||
assertEquals(1, indexDefinition.getReplicaCount());
|
||||
|
|
|
@ -12,7 +12,7 @@ public class TransportAdminClient extends AbstractAdminClient {
|
|||
|
||||
private final TransportClientHelper helper;
|
||||
|
||||
public TransportAdminClient() {
|
||||
public TransportAdminClient(ClassLoader classLoader) {
|
||||
super();
|
||||
this.helper = new TransportClientHelper();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.xbib.elx.api.AdminClientProvider;
|
|||
public class TransportAdminClientProvider implements AdminClientProvider<TransportAdminClient> {
|
||||
|
||||
@Override
|
||||
public TransportAdminClient getClient() {
|
||||
return new TransportAdminClient();
|
||||
public TransportAdminClient getClient(ClassLoader classLoader) {
|
||||
return new TransportAdminClient(classLoader);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ public class TransportBulkClient extends AbstractBulkClient {
|
|||
|
||||
private final TransportClientHelper helper;
|
||||
|
||||
public TransportBulkClient() {
|
||||
public TransportBulkClient(ClassLoader classLoader) {
|
||||
super();
|
||||
this.helper = new TransportClientHelper();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.xbib.elx.api.BulkClientProvider;
|
|||
public class TransportBulkClientProvider implements BulkClientProvider<TransportBulkClient> {
|
||||
|
||||
@Override
|
||||
public TransportBulkClient getClient() {
|
||||
return new TransportBulkClient();
|
||||
public TransportBulkClient getClient(ClassLoader classLoader) {
|
||||
return new TransportBulkClient(classLoader);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ public class TransportSearchClient extends AbstractSearchClient {
|
|||
|
||||
private final TransportClientHelper helper;
|
||||
|
||||
public TransportSearchClient() {
|
||||
public TransportSearchClient(ClassLoader classLoader) {
|
||||
super();
|
||||
this.helper = new TransportClientHelper();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.xbib.elx.api.SearchClientProvider;
|
|||
public class TransportSearchClientProvider implements SearchClientProvider<TransportSearchClient> {
|
||||
|
||||
@Override
|
||||
public TransportSearchClient getClient() {
|
||||
return new TransportSearchClient();
|
||||
public TransportSearchClient getClient(ClassLoader classLoader) {
|
||||
return new TransportSearchClient(classLoader);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ class SmokeTest {
|
|||
.put(helper.getClientSettings())
|
||||
.build()) {
|
||||
IndexDefinition indexDefinition =
|
||||
new DefaultIndexDefinition(adminClient, "test", "doc", Settings.EMPTY);
|
||||
new DefaultIndexDefinition(adminClient, "test", "doc", Settings.EMPTY, getClass().getClassLoader());
|
||||
assertEquals("test", indexDefinition.getIndex());
|
||||
assertTrue(indexDefinition.getFullIndexName().startsWith("test"));
|
||||
assertEquals(1, indexDefinition.getReplicaCount());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
group = org.xbib
|
||||
name = elx
|
||||
version = 7.10.2.21
|
||||
version = 7.10.2.22
|
||||
|
||||
org.gradle.warning.mode = ALL
|
||||
|
|
|
@ -4,6 +4,7 @@ dependencyResolutionManagement {
|
|||
version('gradle', '7.4.2')
|
||||
version('junit', '5.8.2')
|
||||
version('elasticsearch', '7.10.2')
|
||||
version('lucene', '8.7.0')
|
||||
version('log4j', '2.17.1') // ES 7.10.2 uses log4j2 2.11.1
|
||||
library('junit-jupiter-api', 'org.junit.jupiter', 'junit-jupiter-api').versionRef('junit')
|
||||
library('junit-jupiter-params', 'org.junit.jupiter', 'junit-jupiter-params').versionRef('junit')
|
||||
|
@ -15,6 +16,16 @@ dependencyResolutionManagement {
|
|||
library('log4j-slf4j', 'org.apache.logging.log4j', 'log4j-slf4j-impl').versionRef('log4j')
|
||||
library('log4j-jul', 'org.apache.logging.log4j', 'log4j-jul').versionRef('log4j')
|
||||
library('elasticsearch', 'org.elasticsearch', 'elasticsearch').versionRef('elasticsearch')
|
||||
library('lucene', 'org.apache.lucene', 'lucene-core').versionRef('lucene')
|
||||
library('lucene-analyzers-common', 'org.apache.lucene', 'lucene-analyzers-common').versionRef('lucene')
|
||||
library('lucene-highlighter', 'org.apache.lucene', 'lucene-highlighter').versionRef('lucene')
|
||||
library('lucene-join', 'org.apache.lucene', 'lucene-join').versionRef('lucene')
|
||||
library('lucene-queryparser', 'org.apache.lucene', 'lucene-queryparser').versionRef('lucene')
|
||||
library('lucene-grouping', 'org.apache.lucene', 'lucene-grouping').versionRef('lucene')
|
||||
library('lucene-misc', 'org.apache.lucene', 'lucene-misc').versionRef('lucene')
|
||||
library('hppc', 'com.carrotsearch', 'hppc').version('0.8.1')
|
||||
library('joda', 'joda-time', 'joda-time').version('2.10.4')
|
||||
library('tdigest', 'com.tdunning', 't-digest').version('3.2')
|
||||
library('es-plugin-transport-netty4', 'org.elasticsearch.plugin', 'transport-netty4-client').versionRef('elasticsearch')
|
||||
library('jackson', 'com.fasterxml.jackson.core', 'jackson-core').version('2.12.7') // ES 7.10.2 uses Jackson 2.10.4
|
||||
library('netty-http', 'org.xbib', 'netty-http-client').version('4.1.77.0') // ES 7.10.2 uses Netty 4.1.49
|
||||
|
|
Loading…
Reference in a new issue