Skip to content

Commit 06164fb

Browse files
l-trottaswallez
andauthored
Low level client update (#974)
* new transport * fix multibufferentity * client builder refactor * temp * temp * temp * original tests * new tests * fixing tests * flatten low level client folder structure * Move things around, remove duplicated tests * naming refactor * Add ElasticsearchTestClient that randomly chooses an implementation * regen from latest spec * test fixes * esql test config fix * porting low level client unit tests * low level client tests to junit 5 * Randomize client implementation, remove cloud-id on Rest5, add tests for overloaded methods * Refine client builder * todos and timeouts fix * checkstyle fixes * remove maven local + remove legacy test * Add insecure SSLContext * temp rebase fix * Reduce public API surface * Extract HttpRequest.Node (future-proof this class for later use) * Remove Node.boundHosts: it's mostly useless in the container era * Port RestClient's sniffer to Rest5Client * Move Node back to its original location. TransportHttpClient is self-contained * Refactor client builder to transport configuration * Allow extensions of ElasticsearchTransportConfig * Remove calls to AccessController which is deprecated for removal * Fix licenseReport * Revert "temp rebase fix" This reverts commit 48f2b57. * [codegen] update to latest spec and generator * fixing tests * regen --------- Co-authored-by: Sylvain Wallez <sylvain@elastic.co>
1 parent c8fa833 commit 06164fb

File tree

116 files changed

+15314
-366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+15314
-366
lines changed

example-transports/src/test/java/co/elastic/clients/transport/rest_client/RestTransportClientTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,21 @@
2020
package co.elastic.clients.transport.rest_client;
2121

2222
import co.elastic.clients.transport.TransportHttpClientTest;
23+
import co.elastic.clients.transport.rest5_client.Rest5ClientHttpClient;
2324
import org.apache.http.HttpHost;
2425
import org.elasticsearch.client.RestClient;
2526

26-
public class RestTransportClientTest extends TransportHttpClientTest<RestClientHttpClient> {
27+
public class RestTransportClientTest extends TransportHttpClientTest<Rest5ClientHttpClient> {
2728

2829
public RestTransportClientTest() {
2930
super(createClient());
3031
}
3132

32-
private static RestClientHttpClient createClient() {
33+
private static Rest5ClientHttpClient createClient() {
3334
RestClient restClient = RestClient.builder(
3435
new HttpHost(server.getAddress().getAddress(), server.getAddress().getPort(), "http")
3536
).build();
3637

37-
return new RestClientHttpClient(restClient);
38+
return new Rest5ClientHttpClient(restClient);
3839
}
3940
}

java-client/build.gradle.kts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ checkstyle {
3838
}
3939

4040
java {
41-
targetCompatibility = JavaVersion.VERSION_1_8
42-
sourceCompatibility = JavaVersion.VERSION_1_8
41+
targetCompatibility = JavaVersion.VERSION_17
42+
sourceCompatibility = JavaVersion.VERSION_17
4343

4444
withJavadocJar()
4545
withSourcesJar()
@@ -200,14 +200,16 @@ signing {
200200
dependencies {
201201
// Compile and test with the last 7.x version to make sure transition scenarios where
202202
// the Java API client coexists with a 7.x HLRC work fine
203-
val elasticsearchVersion = "8.10.0"
203+
val elasticsearchVersion = "8.17.0"
204204
val jacksonVersion = "2.17.0"
205205
val openTelemetryVersion = "1.29.0"
206206

207207
// Apache 2.0
208208
// https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low.html
209209
api("org.elasticsearch.client", "elasticsearch-rest-client", elasticsearchVersion)
210210

211+
api("org.apache.httpcomponents.client5","httpclient5","5.4")
212+
211213
// Apache 2.0
212214
// https://search.maven.org/artifact/com.google.code.findbugs/jsr305
213215
api("com.google.code.findbugs:jsr305:3.0.2")
@@ -271,6 +273,16 @@ dependencies {
271273
// Apache-2.0
272274
// https://github.com/awaitility/awaitility
273275
testImplementation("org.awaitility", "awaitility", "4.2.0")
276+
277+
// MIT
278+
// https://github.com/mockito/mockito
279+
testImplementation("org.mockito","mockito-core","5.12.0")
280+
281+
// Apache-2.0
282+
// https://github.com/elastic/mocksocket
283+
testImplementation("org.elasticsearch","mocksocket","1.2")
284+
285+
274286
}
275287

276288

@@ -285,6 +297,7 @@ class SpdxReporter(val dest: File) : ReportRenderer {
285297
"The Apache License, Version 2.0" to "Apache-2.0",
286298
"Apache License, Version 2.0" to "Apache-2.0",
287299
"The Apache Software License, Version 2.0" to "Apache-2.0",
300+
"MIT License" to "MIT",
288301
"BSD Zero Clause License" to "0BSD",
289302
"Eclipse Public License 2.0" to "EPL-2.0",
290303
"Eclipse Public License v. 2.0" to "EPL-2.0",
@@ -311,7 +324,11 @@ class SpdxReporter(val dest: File) : ReportRenderer {
311324
val depName = dep.group + ":" + dep.name
312325

313326
val info = LicenseDataCollector.multiModuleLicenseInfo(dep)
314-
val depUrl = info.moduleUrls.first()
327+
val depUrl = if (depName.startsWith("org.apache.httpcomponents")) {
328+
"https://hc.apache.org/"
329+
} else {
330+
info.moduleUrls.first()
331+
}
315332

316333
val licenseIds = info.licenses.mapNotNull { license ->
317334
license.name?.let {

java-client/src/main/java/co/elastic/clients/elasticsearch/ElasticsearchAsyncClient.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
import co.elastic.clients.elasticsearch.watcher.ElasticsearchWatcherAsyncClient;
147147
import co.elastic.clients.elasticsearch.xpack.ElasticsearchXpackAsyncClient;
148148
import co.elastic.clients.transport.ElasticsearchTransport;
149+
import co.elastic.clients.transport.ElasticsearchTransportConfig;
149150
import co.elastic.clients.transport.Endpoint;
150151
import co.elastic.clients.transport.JsonEndpoint;
151152
import co.elastic.clients.transport.Transport;
@@ -179,6 +180,23 @@
179180
*/
180181
public class ElasticsearchAsyncClient extends ApiClient<ElasticsearchTransport, ElasticsearchAsyncClient> {
181182

183+
/**
184+
* Creates a client from a {@link ElasticsearchTransportConfig.Default}}
185+
* configuration created with an inline lambda expression.
186+
*/
187+
public static ElasticsearchAsyncClient of(
188+
Function<ElasticsearchTransportConfig.Builder, ElasticsearchTransportConfig.Builder> fn) {
189+
return new ElasticsearchAsyncClient(
190+
fn.apply(new ElasticsearchTransportConfig.Builder()).build().buildTransport());
191+
}
192+
193+
/**
194+
* Creates a client from an {@link ElasticsearchTransportConfig}.
195+
*/
196+
public ElasticsearchAsyncClient(ElasticsearchTransportConfig config) {
197+
this(config.buildTransport());
198+
}
199+
182200
public ElasticsearchAsyncClient(ElasticsearchTransport transport) {
183201
super(transport, null);
184202
}

java-client/src/main/java/co/elastic/clients/elasticsearch/ElasticsearchClient.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
import co.elastic.clients.elasticsearch.watcher.ElasticsearchWatcherClient;
148148
import co.elastic.clients.elasticsearch.xpack.ElasticsearchXpackClient;
149149
import co.elastic.clients.transport.ElasticsearchTransport;
150+
import co.elastic.clients.transport.ElasticsearchTransportConfig;
150151
import co.elastic.clients.transport.Endpoint;
151152
import co.elastic.clients.transport.JsonEndpoint;
152153
import co.elastic.clients.transport.Transport;
@@ -180,6 +181,22 @@
180181
*/
181182
public class ElasticsearchClient extends ApiClient<ElasticsearchTransport, ElasticsearchClient> {
182183

184+
/**
185+
* Creates a client from a {@link ElasticsearchTransportConfig.Default}}
186+
* configuration created with an inline lambda expression.
187+
*/
188+
public static ElasticsearchClient of(
189+
Function<ElasticsearchTransportConfig.Builder, ElasticsearchTransportConfig.Builder> fn) {
190+
return new ElasticsearchClient(fn.apply(new ElasticsearchTransportConfig.Builder()).build().buildTransport());
191+
}
192+
193+
/**
194+
* Creates a client from an {@link ElasticsearchTransportConfig}.
195+
*/
196+
public ElasticsearchClient(ElasticsearchTransportConfig config) {
197+
this(config.buildTransport());
198+
}
199+
183200
public ElasticsearchClient(ElasticsearchTransport transport) {
184201
super(transport, null);
185202
}

java-client/src/main/java/co/elastic/clients/transport/DefaultTransportOptions.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ public Function<List<String>, Boolean> onWarnings() {
100100
return onWarnings;
101101
}
102102

103+
@Override
104+
public void updateToken(String token) {
105+
this.headers.put("Authorization", "Bearer " + token);
106+
}
107+
108+
103109
@Override
104110
public boolean keepResponseBodyOnException() {
105111
return keepResponseBodyOnException;

java-client/src/main/java/co/elastic/clients/transport/ElasticsearchTransportBase.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,9 @@ public abstract class ElasticsearchTransportBase implements ElasticsearchTranspo
7777
}
7878
}
7979

80-
private final TransportHttpClient httpClient;
81-
private final Instrumentation instrumentation;
82-
83-
@Override
84-
public void close() throws IOException {
85-
httpClient.close();
86-
}
87-
88-
private final JsonpMapper mapper;
80+
protected final TransportHttpClient httpClient;
81+
protected final Instrumentation instrumentation;
82+
protected final JsonpMapper mapper;
8983
protected final TransportOptions transportOptions;
9084

9185
public ElasticsearchTransportBase(TransportHttpClient httpClient, TransportOptions options,
@@ -113,6 +107,20 @@ public ElasticsearchTransportBase(
113107
this.instrumentation = instrumentation;
114108
}
115109

110+
/** INTERNAL, used only for tests. */
111+
protected ElasticsearchTransportBase cloneWith(
112+
@Nullable TransportOptions options,
113+
@Nullable JsonpMapper mapper,
114+
@Nullable Instrumentation instrumentation
115+
) {
116+
throw new UnsupportedOperationException();
117+
}
118+
119+
@Override
120+
public void close() throws IOException {
121+
httpClient.close();
122+
}
123+
116124
@Override
117125
public final JsonpMapper jsonpMapper() {
118126
return mapper;
@@ -123,6 +131,10 @@ public final TransportOptions options() {
123131
return transportOptions;
124132
}
125133

134+
public TransportHttpClient httpClient() {
135+
return httpClient;
136+
}
137+
126138
@Override
127139
public final <RequestT, ResponseT, ErrorT> ResponseT performRequest(
128140
RequestT request,

0 commit comments

Comments
 (0)