|
37 | 37 | import org.elasticsearch.action.ActionRequestValidationException;
|
38 | 38 | import org.elasticsearch.action.bulk.BackoffPolicy;
|
39 | 39 | import org.elasticsearch.action.bulk.BulkItemResponse.Failure;
|
| 40 | +import org.elasticsearch.client.RestClientBuilder; |
40 | 41 | import org.elasticsearch.common.bytes.BytesReference;
|
41 | 42 | import org.elasticsearch.common.xcontent.DeprecationHandler;
|
42 | 43 | import org.elasticsearch.index.reindex.ScrollableHitSource.SearchFailure;
|
@@ -206,34 +207,39 @@ static RestClient buildRestClient(RemoteInfo remoteInfo, long taskId, List<Threa
|
206 | 207 | for (Map.Entry<String, String> header : remoteInfo.getHeaders().entrySet()) {
|
207 | 208 | clientHeaders[i++] = new BasicHeader(header.getKey(), header.getValue());
|
208 | 209 | }
|
209 |
| - return RestClient.builder(new HttpHost(remoteInfo.getHost(), remoteInfo.getPort(), remoteInfo.getScheme())) |
210 |
| - .setDefaultHeaders(clientHeaders) |
211 |
| - .setRequestConfigCallback(c -> { |
212 |
| - c.setConnectTimeout(Math.toIntExact(remoteInfo.getConnectTimeout().millis())); |
213 |
| - c.setSocketTimeout(Math.toIntExact(remoteInfo.getSocketTimeout().millis())); |
214 |
| - return c; |
215 |
| - }) |
216 |
| - .setHttpClientConfigCallback(c -> { |
217 |
| - // Enable basic auth if it is configured |
218 |
| - if (remoteInfo.getUsername() != null) { |
219 |
| - UsernamePasswordCredentials creds = new UsernamePasswordCredentials(remoteInfo.getUsername(), |
220 |
| - remoteInfo.getPassword()); |
221 |
| - CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); |
222 |
| - credentialsProvider.setCredentials(AuthScope.ANY, creds); |
223 |
| - c.setDefaultCredentialsProvider(credentialsProvider); |
224 |
| - } |
225 |
| - // Stick the task id in the thread name so we can track down tasks from stack traces |
226 |
| - AtomicInteger threads = new AtomicInteger(); |
227 |
| - c.setThreadFactory(r -> { |
228 |
| - String name = "es-client-" + taskId + "-" + threads.getAndIncrement(); |
229 |
| - Thread t = new Thread(r, name); |
230 |
| - threadCollector.add(t); |
231 |
| - return t; |
232 |
| - }); |
233 |
| - // Limit ourselves to one reactor thread because for now the search process is single threaded. |
234 |
| - c.setDefaultIOReactorConfig(IOReactorConfig.custom().setIoThreadCount(1).build()); |
235 |
| - return c; |
236 |
| - }).build(); |
| 210 | + final RestClientBuilder builder = |
| 211 | + RestClient.builder(new HttpHost(remoteInfo.getHost(), remoteInfo.getPort(), remoteInfo.getScheme())) |
| 212 | + .setDefaultHeaders(clientHeaders) |
| 213 | + .setRequestConfigCallback(c -> { |
| 214 | + c.setConnectTimeout(Math.toIntExact(remoteInfo.getConnectTimeout().millis())); |
| 215 | + c.setSocketTimeout(Math.toIntExact(remoteInfo.getSocketTimeout().millis())); |
| 216 | + return c; |
| 217 | + }) |
| 218 | + .setHttpClientConfigCallback(c -> { |
| 219 | + // Enable basic auth if it is configured |
| 220 | + if (remoteInfo.getUsername() != null) { |
| 221 | + UsernamePasswordCredentials creds = new UsernamePasswordCredentials(remoteInfo.getUsername(), |
| 222 | + remoteInfo.getPassword()); |
| 223 | + CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); |
| 224 | + credentialsProvider.setCredentials(AuthScope.ANY, creds); |
| 225 | + c.setDefaultCredentialsProvider(credentialsProvider); |
| 226 | + } |
| 227 | + // Stick the task id in the thread name so we can track down tasks from stack traces |
| 228 | + AtomicInteger threads = new AtomicInteger(); |
| 229 | + c.setThreadFactory(r -> { |
| 230 | + String name = "es-client-" + taskId + "-" + threads.getAndIncrement(); |
| 231 | + Thread t = new Thread(r, name); |
| 232 | + threadCollector.add(t); |
| 233 | + return t; |
| 234 | + }); |
| 235 | + // Limit ourselves to one reactor thread because for now the search process is single threaded. |
| 236 | + c.setDefaultIOReactorConfig(IOReactorConfig.custom().setIoThreadCount(1).build()); |
| 237 | + return c; |
| 238 | + }); |
| 239 | + if (Strings.hasLength(remoteInfo.getPathPrefix()) && "/".equals(remoteInfo.getPathPrefix()) == false) { |
| 240 | + builder.setPathPrefix(remoteInfo.getPathPrefix()); |
| 241 | + } |
| 242 | + return builder.build(); |
237 | 243 | }
|
238 | 244 |
|
239 | 245 | /**
|
|
0 commit comments