Skip to content

Commit

Permalink
🔧 adding configuration parameters to elastic search clients
Browse files Browse the repository at this point in the history
Signed-off-by: dseurotech <davide.salvador@eurotech.com>
  • Loading branch information
dseurotech authored and Coduz committed Jul 2, 2024
1 parent ad9977b commit 5eaf3bb
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,26 @@
# Contributors:
# Eurotech - initial API and implementation
###############################################################################

#
# Provider
datastore.elasticsearch.provider=org.eclipse.kapua.service.elasticsearch.client.rest.RestElasticsearchClientProvider
datastore.elasticsearch.module=datastore-elasticsearch-client

#
# Connection
datastore.elasticsearch.cluster=kapua-datastore
datastore.elasticsearch.nodes=127.0.0.1:9200
datastore.elasticsearch.username=
datastore.elasticsearch.password=

datastore.elasticsearch.client.reconnection_wait_between_exec=15000

datastore.elasticsearch.numberOfIOThreads=1
#
# Requests
datastore.elasticsearch.request.query.timeout=15000
datastore.elasticsearch.request.scroll.timeout=60000
datastore.elasticsearch.request.retry.max=3
datastore.elasticsearch.request.retry.wait=2500

datastore.elasticsearch.request.connection.timeout.millis=5000
datastore.elasticsearch.request.socket.timeout.millis=3000
#
# SSL
datastore.elasticsearch.ssl.enabled=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
* The {@link ElasticsearchClientConfiguration} used to configure an instance of a {@link ElasticsearchClient}
Expand All @@ -31,6 +32,7 @@ public class ElasticsearchClientConfiguration {
private List<ElasticsearchNode> nodes;
private String username;
private String password;
private Integer numberOfIOThreads;

private ElasticsearchClientReconnectConfiguration reconnectConfiguration;
private ElasticsearchClientRequestConfiguration requestConfiguration;
Expand All @@ -49,7 +51,8 @@ public String getModuleName() {
/**
* Sets the module name which is managing the {@link ElasticsearchClient} instance.
*
* @param moduleName The module name which is managing the {@link ElasticsearchClient} instance.
* @param moduleName
* The module name which is managing the {@link ElasticsearchClient} instance.
* @since 1.3.0
*/
public void setModuleName(String moduleName) {
Expand Down Expand Up @@ -90,7 +93,8 @@ public String getClusterName() {
/**
* Sets the Elasticsearch cluster name to use.
*
* @param clusterName The Elasticsearch cluster name to use.
* @param clusterName
* The Elasticsearch cluster name to use.
* @return This {@link ElasticsearchClientConfiguration} to chain method invocation.
* @since 1.3.0
*/
Expand All @@ -113,7 +117,6 @@ public List<ElasticsearchNode> getNodes() {
return nodes;
}


/**
* Adds a new {@link ElasticsearchNode} to the {@link List} {@link ElasticsearchNode}s already configured.
* <p>
Expand All @@ -122,8 +125,10 @@ public List<ElasticsearchNode> getNodes() {
* getNodes().add(new ElasticsearchNode(address, port));
* </pre>
*
* @param address The host of the Elasticsearch node
* @param port The port of the Elasticsearch node
* @param address
* The host of the Elasticsearch node
* @param port
* The port of the Elasticsearch node
* @return This {@link ElasticsearchClientConfiguration} to chain method invocation.
* @since 1.3.0
*/
Expand All @@ -135,7 +140,8 @@ public ElasticsearchClientConfiguration addNode(String address, int port) {
/**
* Sets the {@link List} of {@link ElasticsearchNode}s.
*
* @param nodes The {@link List} of {@link ElasticsearchNode}s.
* @param nodes
* The {@link List} of {@link ElasticsearchNode}s.
* @return This {@link ElasticsearchClientConfiguration} to chain method invocation.
* @since 1.3.0
*/
Expand All @@ -159,7 +165,8 @@ public String getUsername() {
* <p>
* Optional.
*
* @param username The username used to authenticate into Elasticsearch.
* @param username
* The username used to authenticate into Elasticsearch.
* @return This {@link ElasticsearchClientConfiguration} to chain method invocation.
* @since 1.3.0
*/
Expand All @@ -183,7 +190,8 @@ public String getPassword() {
* <p>
* Optional.
*
* @param password The password used to authenticate into Elasticsearch.
* @param password
* The password used to authenticate into Elasticsearch.
* @return This {@link ElasticsearchClientConfiguration} to chain method invocation.
* @since 1.3.0
*/
Expand All @@ -209,7 +217,8 @@ public ElasticsearchClientReconnectConfiguration getReconnectConfiguration() {
/**
* Sets the {@link ElasticsearchClientReconnectConfiguration}.
*
* @param reconnectConfiguration The {@link ElasticsearchClientReconnectConfiguration}.
* @param reconnectConfiguration
* The {@link ElasticsearchClientReconnectConfiguration}.
* @return This {@link ElasticsearchClientConfiguration} to chain method invocation.
* @since 1.3.0
*/
Expand All @@ -235,7 +244,8 @@ public ElasticsearchClientRequestConfiguration getRequestConfiguration() {
/**
* Sets the {@link ElasticsearchClientReconnectConfiguration}.
*
* @param requestConfiguration the {@link ElasticsearchClientReconnectConfiguration}.
* @param requestConfiguration
* the {@link ElasticsearchClientReconnectConfiguration}.
* @return This {@link ElasticsearchClientConfiguration} to chain method invocation.
* @since 1.3.0
*/
Expand All @@ -261,12 +271,24 @@ public ElasticsearchClientSslConfiguration getSslConfiguration() {
/**
* Sets the {@link ElasticsearchClientSslConfiguration}
*
* @param sslConfiguration The {@link ElasticsearchClientSslConfiguration}
* @param sslConfiguration
* The {@link ElasticsearchClientSslConfiguration}
* @return This {@link ElasticsearchClientConfiguration} to chain method invocation.
* @since 1.3.0
*/
public ElasticsearchClientConfiguration setSslConfiguration(ElasticsearchClientSslConfiguration sslConfiguration) {
this.sslConfiguration = sslConfiguration;
return this;
}

public int getNumberOfIOThreads() {
return Optional.ofNullable(numberOfIOThreads)
.filter(i -> i > 0)
.orElseGet(() -> Runtime.getRuntime().availableProcessors());
}

public ElasticsearchClientConfiguration setNumberOfIOThreads(Integer numberOfIOThreads) {
this.numberOfIOThreads = numberOfIOThreads;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
/**
* The {@link ElasticsearchClientRequestConfiguration} definition.
* <p>
* It contains values for configuring request properties.
* It contains default values to ease the usage of the class.
* It contains values for configuring request properties. It contains default values to ease the usage of the class.
*/
public class ElasticsearchClientRequestConfiguration {

Expand All @@ -27,6 +26,8 @@ public class ElasticsearchClientRequestConfiguration {

private int queryTimeout = 15000;
private int scrollTimeout = 60000;
private int connectionTimeoutMillis = 5000;
private int socketTimeoutMillis = 3000;

/**
* Gets the number of maximum attempts to retry a {@link Request}.
Expand All @@ -43,7 +44,8 @@ public int getRequestRetryAttemptMax() {
/**
* Sets the number of maximum attempts to retry a {@link Request}.
*
* @param requestRetryAttemptMax The number of maximum attempts to retry a {@link Request}.
* @param requestRetryAttemptMax
* The number of maximum attempts to retry a {@link Request}.
* @return This {@link ElasticsearchClientRequestConfiguration} to chain method invocation.
* @since 1.3.0
*/
Expand All @@ -67,7 +69,8 @@ public int getRequestRetryAttemptWait() {
/**
* Sets the wait time between {@link Request} retries.
*
* @param requestRetryAttemptWait The wait time between {@link Request} retries.
* @param requestRetryAttemptWait
* The wait time between {@link Request} retries.
* @return This {@link ElasticsearchClientRequestConfiguration} to chain method invocation.
* @since 1.3.0
*/
Expand All @@ -91,7 +94,8 @@ public int getQueryTimeout() {
/**
* Sets the query {@link Request} timeout.
*
* @param queryTimeout The query {@link Request} timeout.
* @param queryTimeout
* The query {@link Request} timeout.
* @return This {@link ElasticsearchClientRequestConfiguration} to chain method invocation.
* @since 1.3.0
*/
Expand All @@ -115,12 +119,63 @@ public int getScrollTimeout() {
/**
* Sets the scroll {@link Request} timeout.
*
* @param scrollTimeout The scroll {@link Request} timeout.
* @param scrollTimeout
* The scroll {@link Request} timeout.
* @return This {@link ElasticsearchClientRequestConfiguration} to chain method invocation.
* @since 1.3.0
*/
public ElasticsearchClientRequestConfiguration setScrollTimeout(int scrollTimeout) {
this.scrollTimeout = scrollTimeout;
return this;
}

/**
* Gets the {@link Request} connection timeout. https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/7.17/_timeouts.html
* <p>
* Default value: 5000 ms
*
* @return The query {@link Request} connection timeout.
* @since 2.1.0
*/
public int getConnectionTimeoutMillis() {
return connectionTimeoutMillis;
}

/**
* Gets the {@link Request} socket timeout. https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/7.17/_timeouts.html
* <p>
* Default value: 3000 ms
*
* @return The query {@link Request} connection timeout.
* @since 2.1.0
*/
public int getSocketTimeoutMillis() {
return socketTimeoutMillis;
}

/**
* Sets the scroll {@link Request} connection timeout. https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/7.17/_timeouts.html.
*
* @param connectionTimeoutMillis
* The scroll {@link Request} connection timeout.
* @return This {@link ElasticsearchClientRequestConfiguration} to chain method invocation.
* @since 2.1.0
*/
public ElasticsearchClientRequestConfiguration setConnectionTimeoutMillis(int connectionTimeoutMillis) {
this.connectionTimeoutMillis = connectionTimeoutMillis;
return this;
}

/**
* Sets the scroll {@link Request} socket timeout. https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/7.17/_timeouts.html.
*
* @param socketTimeoutMillis
* The scroll {@link Request} socket timeout.
* @return This {@link ElasticsearchClientRequestConfiguration} to chain method invocation.
* @since 2.1.0
*/
public ElasticsearchClientRequestConfiguration setSocketTimeoutMillis(int socketTimeoutMillis) {
this.socketTimeoutMillis = socketTimeoutMillis;
return this;
}
}
Loading

0 comments on commit 5eaf3bb

Please sign in to comment.