Skip to content
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

BREAKS: Update to ElasticSearch 8.2.0 #368

Merged
merged 1 commit into from
Apr 12, 2023
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 @@ -2,10 +2,3 @@ repositories {
mavenCentral()
maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/" }
}

configurations.all {
resolutionStrategy.dependencySubstitution {
substitute(module("org.codehaus.groovy:groovy"))
.using(module("org.apache.groovy:groovy:4.0.10"))
}
}
6 changes: 6 additions & 0 deletions elasticsearch-bom/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
plugins {
id("io.micronaut.build.internal.bom")
}
micronautBuild {
micronautBuild {
// required because elasticsearch-rest-high-level-client was removed
tasks.named("checkVersionCatalogCompatibility") { onlyIf { false } }
}
}
7 changes: 5 additions & 2 deletions elasticsearch/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ dependencies {

compileOnly(libs.graal.svm)
implementation(mn.micronaut.management)

api(libs.managed.elasticsearch.java)
api(libs.managed.elasticsearch.rest.high.level.client)
api(mn.micronaut.http)

implementation(mn.micronaut.jackson.databind)
Expand All @@ -27,3 +25,8 @@ tasks {
}
}

micronautBuild {
binaryCompatibility {
enabled.set(false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;

import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
Expand All @@ -44,17 +43,6 @@
@Factory
public class DefaultElasticsearchClientFactory {

/**
* Create the {@link RestHighLevelClient} bean for the given configuration.
*
* @param elasticsearchConfiguration The {@link DefaultElasticsearchConfigurationProperties} object
* @return A {@link RestHighLevelClient} bean
*/
@Bean(preDestroy = "close")
RestHighLevelClient restHighLevelClient(DefaultElasticsearchConfigurationProperties elasticsearchConfiguration) {
return new RestHighLevelClient(restClientBuilder(elasticsearchConfiguration));
}

/**
* @param elasticsearchConfiguration The {@link DefaultElasticsearchConfigurationProperties} object
* @return The Elasticsearch Rest Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import io.micronaut.context.annotation.Factory;
import io.micronaut.context.annotation.Requires;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;

import org.elasticsearch.client.RestClient;
import jakarta.inject.Singleton;

/**
Expand All @@ -29,7 +28,7 @@
* @author Puneet Behl
* @since 1.0.0
*/
@Requires(classes = {RestHighLevelClient.class})
@Requires(classes = {RestClient.class})
@Factory
public class DefaultHttpAsyncClientBuilderFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import io.micronaut.elasticsearch.ElasticsearchSettings;
import io.micronaut.context.annotation.Requires;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.RestClient;

import java.lang.annotation.*;

Expand All @@ -31,6 +31,6 @@
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PACKAGE, ElementType.TYPE})
@Requires(property = ElasticsearchSettings.PREFIX)
@Requires(classes = {RestHighLevelClient.class})
@Requires(classes = {RestClient.class})
public @interface RequiresElasticsearch {
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*
* We substitute it with an implementation which does not use serialization.
*
* Forked from Quarkus: https://github.com/quarkusio/quarkus/blob/c9cba824e8812fa3f15474b8382ac5d90f7238aa/extensions/elasticsearch-rest-client/runtime/src/main/java/io/quarkus/elasticsearch/restclient/runtime/graal/Substitute_RestClient.java
* Forked from Quarkus: https://github.com/quarkusio/quarkus/blob/main/extensions/elasticsearch-rest-client-common/runtime/src/main/java/io/quarkus/elasticsearch/restclient/common/runtime/graal/Substitute_RestClient.java
*
* @author Iván López
* @since 2.0.0
Expand Down Expand Up @@ -109,7 +109,7 @@ public NoSerializationBasicAuthCache() {
this(null);
}

protected HttpHost getKey(final HttpHost host) {
private HttpHost getKey(final HttpHost host) {
if (host.getPort() <= 0) {
final int port;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
import org.reactivestreams.Publisher;

import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient;
import co.elastic.clients.elasticsearch.cluster.HealthResponse;
import jakarta.inject.Singleton;
import java.io.IOException;

import static io.micronaut.health.HealthStatus.DOWN;
import static io.micronaut.health.HealthStatus.UP;
import java.util.Locale;

/**
* A {@link HealthIndicator} for Elasticsearch that uses an automatically-configured high-level REST client, injected as a dependency, to communicate
Expand All @@ -39,7 +40,6 @@
*/
@Requires(beans = HealthEndpoint.class)
@Requires(property = HealthEndpoint.PREFIX + ".elasticsearch.enabled", notEquals = "false")
@Requires(property = HealthEndpoint.PREFIX + ".elasticsearch.rest.high.level.enabled", notEquals = "true") // we don't want to clash with the deprecated check
@Singleton
public class ElasticsearchClientHealthIndicator implements HealthIndicator {

Expand All @@ -65,24 +65,41 @@ public ElasticsearchClientHealthIndicator(ElasticsearchAsyncClient client) {
*/
@Override
public Publisher<HealthResult> getResult() {
return (subscriber -> {
final HealthResult.Builder resultBuilder = HealthResult.builder(NAME);
try {
client.cluster().health().handle((health, exception) -> {
if (exception != null) {
subscriber.onNext(resultBuilder.status(DOWN).exception(exception).build());
subscriber.onComplete();
} else {
HealthStatus status = health.status() == co.elastic.clients.elasticsearch._types.HealthStatus.Red ? DOWN : UP;
subscriber.onNext(resultBuilder.status(status).details(health).build());
subscriber.onComplete();
}
return health;
});
} catch (IOException e) {
subscriber.onNext(resultBuilder.status(DOWN).exception(e).build());
subscriber.onComplete();
}
});
return (subscriber -> client.cluster().health()
.handle((health, exception) -> {
final HealthResult.Builder resultBuilder = HealthResult.builder(NAME);
if (exception != null) {
subscriber.onNext(resultBuilder.status(DOWN).exception(exception).build());
subscriber.onComplete();
} else {
HealthStatus status = health.status() == co.elastic.clients.elasticsearch._types.HealthStatus.Red ? DOWN : UP;
subscriber.onNext(resultBuilder.status(status).details(healthResultDetails(health)).build());
subscriber.onComplete();
}
return health;
}));
}

private String healthResultDetails(HealthResponse response) {
return "{"
+ "\"cluster_name\":\"" + response.clusterName() + "\","
+ "\"status\":\"" + response.status().name().toLowerCase(Locale.ENGLISH) + "\","
+ "\"timed_out\":" + response.timedOut() + ","
+ "\"number_of_nodes\":" + response.numberOfNodes() + ","
+ "\"number_of_data_nodes\":" + response.numberOfDataNodes() + ","
+ "\"number_of_pending_tasks\":" + response.numberOfPendingTasks() + ","
+ "\"number_of_in_flight_fetch\":" + response.numberOfInFlightFetch() + ","
+ "\"task_max_waiting_in_queue\":\"" + response.taskMaxWaitingInQueueMillis() + "\","
+ "\"task_max_waiting_in_queue_millis\":" + response.taskMaxWaitingInQueueMillis() + ","
+ "\"active_shards_percent_as_number\":\"" + response.activeShardsPercentAsNumber() + "\","
+ "\"active_primary_shards\":" + response.activePrimaryShards() + ","
+ "\"active_shards\":" + response.activeShards() + ","
+ "\"relocating_shards\":" + response.relocatingShards() + ","
+ "\"initializing_shards\":" + response.initializingShards() + ","
+ "\"unassigned_shards\":" + response.unassignedShards() + ","
+ "\"delayed_unassigned_shards\":" + response.delayedUnassignedShards()
+ "}";
}
}


This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.micronaut.elasticsearch

import co.elastic.clients.elasticsearch.ElasticsearchClient
import io.micronaut.context.ApplicationContext
import io.micronaut.context.annotation.Factory
import io.micronaut.context.annotation.Replaces
Expand All @@ -27,7 +28,6 @@ import org.apache.http.impl.client.BasicCredentialsProvider
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder
import org.apache.http.impl.nio.reactor.IOReactorConfig
import org.elasticsearch.client.NodeSelector
import org.elasticsearch.client.RestHighLevelClient
import spock.lang.Specification

import jakarta.inject.Singleton
Expand All @@ -38,8 +38,7 @@ import jakarta.inject.Singleton
*/
class DefaultElasticsearchConfigurationPropertiesSpec extends Specification {

void "Test Elasticsearch high level rest client configrations"() {

void "Test Elasticsearch rest client configrations"() {
when:
ApplicationContext applicationContext = ApplicationContext.run(

Expand Down Expand Up @@ -108,7 +107,7 @@ class DefaultElasticsearchConfigurationPropertiesSpec extends Specification {

expect:
applicationContext.containsBean(DefaultElasticsearchConfigurationProperties)
applicationContext.containsBean(RestHighLevelClient)
applicationContext.containsBean(ElasticsearchClient)
applicationContext.getBean(DefaultElasticsearchConfigurationProperties).httpHosts.size() == 2

}
Expand Down
Loading