5
5
6
6
package org .opensearch .ml .bwc ;
7
7
8
+ import static org .opensearch .client .RestClientBuilder .DEFAULT_MAX_CONN_PER_ROUTE ;
9
+ import static org .opensearch .client .RestClientBuilder .DEFAULT_MAX_CONN_TOTAL ;
8
10
import static org .opensearch .commons .ConfigConstants .OPENSEARCH_SECURITY_SSL_HTTP_ENABLED ;
9
11
import static org .opensearch .commons .ConfigConstants .OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_FILEPATH ;
10
12
import static org .opensearch .commons .ConfigConstants .OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_KEYPASSWORD ;
36
38
import java .util .function .Consumer ;
37
39
import java .util .stream .Collectors ;
38
40
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 ;
51
58
import org .junit .After ;
52
59
import org .opensearch .client .Request ;
53
60
import org .opensearch .client .Response ;
@@ -173,7 +180,7 @@ protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOE
173
180
@ After
174
181
protected void wipeAllODFEIndices () throws IOException {
175
182
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 ());
177
184
try (
178
185
XContentParser parser = mediaType
179
186
.xContent ()
@@ -215,14 +222,21 @@ protected static void configureHttpsClient(RestClientBuilder builder, Settings s
215
222
String password = Optional
216
223
.ofNullable (System .getProperty ("password" ))
217
224
.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 () ));
220
227
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 );
226
240
} catch (Exception e ) {
227
241
throw new RuntimeException (e );
228
242
}
@@ -231,7 +245,8 @@ protected static void configureHttpsClient(RestClientBuilder builder, Settings s
231
245
final String socketTimeoutString = settings .get (CLIENT_SOCKET_TIMEOUT );
232
246
final TimeValue socketTimeout = TimeValue
233
247
.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 ()))));
235
250
if (settings .hasValue (CLIENT_PATH_PREFIX )) {
236
251
builder .setPathPrefix (settings .get (CLIENT_PATH_PREFIX ));
237
252
}
@@ -245,7 +260,7 @@ protected boolean preserveIndicesUponCompletion() {
245
260
return true ;
246
261
}
247
262
248
- protected Response ingestIrisData (String indexName ) throws IOException {
263
+ protected Response ingestIrisData (String indexName ) throws IOException , ParseException {
249
264
String irisDataIndexMapping = "" ;
250
265
TestHelper
251
266
.makeRequest (
0 commit comments