Skip to content

Low level client update #974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d2b3110
new transport
l-trotta Mar 10, 2025
42def67
fix multibufferentity
l-trotta Mar 11, 2025
85382fe
client builder refactor
l-trotta Mar 13, 2025
1adfa2b
temp
l-trotta Mar 25, 2025
1e072c0
temp
l-trotta Mar 25, 2025
288b3a5
temp
l-trotta Mar 25, 2025
6bb2f0a
original tests
l-trotta Mar 25, 2025
7a8e2d2
new tests
l-trotta Mar 25, 2025
894bea9
fixing tests
l-trotta Mar 25, 2025
49b4348
flatten low level client folder structure
l-trotta Mar 25, 2025
ae24edc
Move things around, remove duplicated tests
swallez Mar 26, 2025
8d86780
naming refactor
l-trotta Mar 26, 2025
27c73c2
Add ElasticsearchTestClient that randomly chooses an implementation
swallez Mar 26, 2025
a37327a
regen from latest spec
l-trotta Mar 26, 2025
0730514
test fixes
l-trotta Mar 26, 2025
4343f00
esql test config fix
l-trotta Mar 26, 2025
bab3805
porting low level client unit tests
l-trotta Mar 26, 2025
1652ffa
low level client tests to junit 5
l-trotta Mar 26, 2025
b20a8f3
Randomize client implementation, remove cloud-id on Rest5, add tests …
swallez Mar 27, 2025
ff4cf79
Refine client builder
swallez Mar 28, 2025
a2229b0
todos and timeouts fix
l-trotta Mar 28, 2025
cb707cb
checkstyle fixes
l-trotta Mar 28, 2025
f5a6e0a
remove maven local + remove legacy test
l-trotta Mar 28, 2025
df29a4b
Add insecure SSLContext
swallez Mar 28, 2025
3267e11
temp rebase fix
l-trotta Mar 28, 2025
295ece6
Reduce public API surface
swallez Mar 28, 2025
c955080
Extract HttpRequest.Node (future-proof this class for later use)
swallez Mar 28, 2025
4556613
Remove Node.boundHosts: it's mostly useless in the container era
swallez Mar 29, 2025
507707e
Port RestClient's sniffer to Rest5Client
swallez Mar 30, 2025
c1a8656
Move Node back to its original location. TransportHttpClient is self-…
swallez Mar 30, 2025
6304e32
Refactor client builder to transport configuration
swallez Mar 30, 2025
f21b866
Allow extensions of ElasticsearchTransportConfig
swallez Mar 31, 2025
4f6fb2d
Remove calls to AccessController which is deprecated for removal
swallez Mar 31, 2025
021eccf
Fix licenseReport
swallez Mar 31, 2025
3f47989
Revert "temp rebase fix"
l-trotta Mar 31, 2025
cd4964a
[codegen] update to latest spec and generator
l-trotta Mar 31, 2025
11ae0f5
fixing tests
l-trotta Mar 31, 2025
b1287e6
regen
l-trotta Mar 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@
package co.elastic.clients.transport.rest_client;

import co.elastic.clients.transport.TransportHttpClientTest;
import co.elastic.clients.transport.rest5_client.Rest5ClientHttpClient;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;

public class RestTransportClientTest extends TransportHttpClientTest<RestClientHttpClient> {
public class RestTransportClientTest extends TransportHttpClientTest<Rest5ClientHttpClient> {

public RestTransportClientTest() {
super(createClient());
}

private static RestClientHttpClient createClient() {
private static Rest5ClientHttpClient createClient() {
RestClient restClient = RestClient.builder(
new HttpHost(server.getAddress().getAddress(), server.getAddress().getPort(), "http")
).build();

return new RestClientHttpClient(restClient);
return new Rest5ClientHttpClient(restClient);
}
}
25 changes: 21 additions & 4 deletions java-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ checkstyle {
}

java {
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_17

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

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

api("org.apache.httpcomponents.client5","httpclient5","5.4")

// Apache 2.0
// https://search.maven.org/artifact/com.google.code.findbugs/jsr305
api("com.google.code.findbugs:jsr305:3.0.2")
Expand Down Expand Up @@ -271,6 +273,16 @@ dependencies {
// Apache-2.0
// https://github.com/awaitility/awaitility
testImplementation("org.awaitility", "awaitility", "4.2.0")

// MIT
// https://github.com/mockito/mockito
testImplementation("org.mockito","mockito-core","5.12.0")

// Apache-2.0
// https://github.com/elastic/mocksocket
testImplementation("org.elasticsearch","mocksocket","1.2")


}


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

val info = LicenseDataCollector.multiModuleLicenseInfo(dep)
val depUrl = info.moduleUrls.first()
val depUrl = if (depName.startsWith("org.apache.httpcomponents")) {
"https://hc.apache.org/"
} else {
info.moduleUrls.first()
}

val licenseIds = info.licenses.mapNotNull { license ->
license.name?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
import co.elastic.clients.elasticsearch.watcher.ElasticsearchWatcherAsyncClient;
import co.elastic.clients.elasticsearch.xpack.ElasticsearchXpackAsyncClient;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.ElasticsearchTransportConfig;
import co.elastic.clients.transport.Endpoint;
import co.elastic.clients.transport.JsonEndpoint;
import co.elastic.clients.transport.Transport;
Expand Down Expand Up @@ -179,6 +180,23 @@
*/
public class ElasticsearchAsyncClient extends ApiClient<ElasticsearchTransport, ElasticsearchAsyncClient> {

/**
* Creates a client from a {@link ElasticsearchTransportConfig.Default}}
* configuration created with an inline lambda expression.
*/
public static ElasticsearchAsyncClient of(
Function<ElasticsearchTransportConfig.Builder, ElasticsearchTransportConfig.Builder> fn) {
return new ElasticsearchAsyncClient(
fn.apply(new ElasticsearchTransportConfig.Builder()).build().buildTransport());
}

/**
* Creates a client from an {@link ElasticsearchTransportConfig}.
*/
public ElasticsearchAsyncClient(ElasticsearchTransportConfig config) {
this(config.buildTransport());
}

public ElasticsearchAsyncClient(ElasticsearchTransport transport) {
super(transport, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
import co.elastic.clients.elasticsearch.watcher.ElasticsearchWatcherClient;
import co.elastic.clients.elasticsearch.xpack.ElasticsearchXpackClient;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.ElasticsearchTransportConfig;
import co.elastic.clients.transport.Endpoint;
import co.elastic.clients.transport.JsonEndpoint;
import co.elastic.clients.transport.Transport;
Expand Down Expand Up @@ -180,6 +181,22 @@
*/
public class ElasticsearchClient extends ApiClient<ElasticsearchTransport, ElasticsearchClient> {

/**
* Creates a client from a {@link ElasticsearchTransportConfig.Default}}
* configuration created with an inline lambda expression.
*/
public static ElasticsearchClient of(
Function<ElasticsearchTransportConfig.Builder, ElasticsearchTransportConfig.Builder> fn) {
return new ElasticsearchClient(fn.apply(new ElasticsearchTransportConfig.Builder()).build().buildTransport());
}

/**
* Creates a client from an {@link ElasticsearchTransportConfig}.
*/
public ElasticsearchClient(ElasticsearchTransportConfig config) {
this(config.buildTransport());
}

public ElasticsearchClient(ElasticsearchTransport transport) {
super(transport, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public Function<List<String>, Boolean> onWarnings() {
return onWarnings;
}

@Override
public void updateToken(String token) {
this.headers.put("Authorization", "Bearer " + token);
}


@Override
public boolean keepResponseBodyOnException() {
return keepResponseBodyOnException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,9 @@ public abstract class ElasticsearchTransportBase implements ElasticsearchTranspo
}
}

private final TransportHttpClient httpClient;
private final Instrumentation instrumentation;

@Override
public void close() throws IOException {
httpClient.close();
}

private final JsonpMapper mapper;
protected final TransportHttpClient httpClient;
protected final Instrumentation instrumentation;
protected final JsonpMapper mapper;
protected final TransportOptions transportOptions;

public ElasticsearchTransportBase(TransportHttpClient httpClient, TransportOptions options,
Expand Down Expand Up @@ -113,6 +107,20 @@ public ElasticsearchTransportBase(
this.instrumentation = instrumentation;
}

/** INTERNAL, used only for tests. */
protected ElasticsearchTransportBase cloneWith(
@Nullable TransportOptions options,
@Nullable JsonpMapper mapper,
@Nullable Instrumentation instrumentation
) {
throw new UnsupportedOperationException();
}

@Override
public void close() throws IOException {
httpClient.close();
}

@Override
public final JsonpMapper jsonpMapper() {
return mapper;
Expand All @@ -123,6 +131,10 @@ public final TransportOptions options() {
return transportOptions;
}

public TransportHttpClient httpClient() {
return httpClient;
}

@Override
public final <RequestT, ResponseT, ErrorT> ResponseT performRequest(
RequestT request,
Expand Down
Loading
Loading