Skip to content

Commit 12c84e7

Browse files
committed
Fix breaking change from opensearch core
Signed-off-by: zane-neo <zaniu@amazon.com>
1 parent 75895af commit 12c84e7

File tree

1 file changed

+37
-22
lines changed

1 file changed

+37
-22
lines changed

plugin/src/test/java/org/opensearch/ml/bwc/MLCommonsBackwardsCompatibilityRestTestCase.java

+37-22
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package org.opensearch.ml.bwc;
77

8+
import static org.opensearch.client.RestClientBuilder.DEFAULT_MAX_CONN_PER_ROUTE;
9+
import static org.opensearch.client.RestClientBuilder.DEFAULT_MAX_CONN_TOTAL;
810
import static org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_ENABLED;
911
import static org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_FILEPATH;
1012
import static org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_KEYPASSWORD;
@@ -36,18 +38,23 @@
3638
import java.util.function.Consumer;
3739
import java.util.stream.Collectors;
3840

39-
import org.apache.http.Header;
40-
import org.apache.http.HttpEntity;
41-
import org.apache.http.HttpHeaders;
42-
import org.apache.http.HttpHost;
43-
import org.apache.http.auth.AuthScope;
44-
import org.apache.http.auth.UsernamePasswordCredentials;
45-
import org.apache.http.client.CredentialsProvider;
46-
import org.apache.http.conn.ssl.NoopHostnameVerifier;
47-
import org.apache.http.impl.client.BasicCredentialsProvider;
48-
import org.apache.http.message.BasicHeader;
49-
import org.apache.http.ssl.SSLContextBuilder;
50-
import org.apache.http.util.EntityUtils;
41+
import org.apache.hc.client5.http.auth.AuthScope;
42+
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
43+
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
44+
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager;
45+
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
46+
import org.apache.hc.client5.http.ssl.ClientTlsStrategyBuilder;
47+
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
48+
import org.apache.hc.core5.http.Header;
49+
import org.apache.hc.core5.http.HttpEntity;
50+
import org.apache.hc.core5.http.HttpHeaders;
51+
import org.apache.hc.core5.http.HttpHost;
52+
import org.apache.hc.core5.http.ParseException;
53+
import org.apache.hc.core5.http.io.entity.EntityUtils;
54+
import org.apache.hc.core5.http.message.BasicHeader;
55+
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
56+
import org.apache.hc.core5.ssl.SSLContextBuilder;
57+
import org.apache.hc.core5.util.Timeout;
5158
import org.junit.After;
5259
import org.opensearch.client.Request;
5360
import org.opensearch.client.Response;
@@ -173,7 +180,7 @@ protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOE
173180
@After
174181
protected void wipeAllODFEIndices() throws IOException {
175182
Response response = adminClient().performRequest(new Request("GET", "/_cat/indices?format=json&expand_wildcards=all"));
176-
MediaType mediaType = MediaType.fromMediaType(response.getEntity().getContentType().getValue());
183+
MediaType mediaType = MediaType.fromMediaType(response.getEntity().getContentType());
177184
try (
178185
XContentParser parser = mediaType
179186
.xContent()
@@ -215,14 +222,21 @@ protected static void configureHttpsClient(RestClientBuilder builder, Settings s
215222
String password = Optional
216223
.ofNullable(System.getProperty("password"))
217224
.orElseThrow(() -> new RuntimeException("password is missing"));
218-
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
219-
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
225+
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
226+
credentialsProvider.setCredentials(new AuthScope(null, -1), new UsernamePasswordCredentials(userName, password.toCharArray()));
220227
try {
221-
return httpClientBuilder
222-
.setDefaultCredentialsProvider(credentialsProvider)
223-
// disable the certificate since our testing cluster just uses the default security configuration
224-
.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
225-
.setSSLContext(SSLContextBuilder.create().loadTrustMaterial(null, (chains, authType) -> true).build());
228+
final TlsStrategy tlsStrategy = ClientTlsStrategyBuilder
229+
.create()
230+
.setHostnameVerifier(NoopHostnameVerifier.INSTANCE)
231+
.setSslContext(SSLContextBuilder.create().loadTrustMaterial(null, (chains, authType) -> true).build())
232+
.build();
233+
final PoolingAsyncClientConnectionManager connectionManager = PoolingAsyncClientConnectionManagerBuilder
234+
.create()
235+
.setMaxConnPerRoute(DEFAULT_MAX_CONN_PER_ROUTE)
236+
.setMaxConnTotal(DEFAULT_MAX_CONN_TOTAL)
237+
.setTlsStrategy(tlsStrategy)
238+
.build();
239+
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider).setConnectionManager(connectionManager);
226240
} catch (Exception e) {
227241
throw new RuntimeException(e);
228242
}
@@ -231,7 +245,8 @@ protected static void configureHttpsClient(RestClientBuilder builder, Settings s
231245
final String socketTimeoutString = settings.get(CLIENT_SOCKET_TIMEOUT);
232246
final TimeValue socketTimeout = TimeValue
233247
.parseTimeValue(socketTimeoutString == null ? "60s" : socketTimeoutString, CLIENT_SOCKET_TIMEOUT);
234-
builder.setRequestConfigCallback(conf -> conf.setSocketTimeout(Math.toIntExact(socketTimeout.getMillis())));
248+
builder
249+
.setRequestConfigCallback(conf -> conf.setResponseTimeout(Timeout.ofMilliseconds(Math.toIntExact(socketTimeout.getMillis()))));
235250
if (settings.hasValue(CLIENT_PATH_PREFIX)) {
236251
builder.setPathPrefix(settings.get(CLIENT_PATH_PREFIX));
237252
}
@@ -245,7 +260,7 @@ protected boolean preserveIndicesUponCompletion() {
245260
return true;
246261
}
247262

248-
protected Response ingestIrisData(String indexName) throws IOException {
263+
protected Response ingestIrisData(String indexName) throws IOException, ParseException {
249264
String irisDataIndexMapping = "";
250265
TestHelper
251266
.makeRequest(

0 commit comments

Comments
 (0)