Skip to content

Low level client update (#974) #975

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 1 commit into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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);
}
}
43 changes: 30 additions & 13 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 @@ -282,15 +294,16 @@ licenseReport {
class SpdxReporter(val dest: File) : ReportRenderer {
// License names to their SPDX identifier
val spdxIds = mapOf(
"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",
"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",
"Eclipse Public License - v 2.0" to "EPL-2.0",
"GNU General Public License, version 2 with the GNU Classpath Exception" to "GPL-2.0 WITH Classpath-exception-2.0",
"COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0" to "CDDL-1.0"
"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",
"Eclipse Public License - v 2.0" to "EPL-2.0",
"GNU General Public License, version 2 with the GNU Classpath Exception" to "GPL-2.0 WITH Classpath-exception-2.0",
"COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0" to "CDDL-1.0"
)

private fun quote(str: String): String {
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