Search in sources :

Example 1 with RemoteInfo

use of org.elasticsearch.index.reindex.remote.RemoteInfo in project elasticsearch by elastic.

the class RestReindexAction method buildRemoteInfo.

static RemoteInfo buildRemoteInfo(Map<String, Object> source) throws IOException {
    @SuppressWarnings("unchecked") Map<String, Object> remote = (Map<String, Object>) source.remove("remote");
    if (remote == null) {
        return null;
    }
    String username = extractString(remote, "username");
    String password = extractString(remote, "password");
    String hostInRequest = requireNonNull(extractString(remote, "host"), "[host] must be specified to reindex from a remote cluster");
    Matcher hostMatcher = HOST_PATTERN.matcher(hostInRequest);
    if (false == hostMatcher.matches()) {
        throw new IllegalArgumentException("[host] must be of the form [scheme]://[host]:[port] but was [" + hostInRequest + "]");
    }
    String scheme = hostMatcher.group("scheme");
    String host = hostMatcher.group("host");
    int port = Integer.parseInt(hostMatcher.group("port"));
    Map<String, String> headers = extractStringStringMap(remote, "headers");
    TimeValue socketTimeout = extractTimeValue(remote, "socket_timeout", RemoteInfo.DEFAULT_SOCKET_TIMEOUT);
    TimeValue connectTimeout = extractTimeValue(remote, "connect_timeout", RemoteInfo.DEFAULT_CONNECT_TIMEOUT);
    if (false == remote.isEmpty()) {
        throw new IllegalArgumentException("Unsupported fields in [remote]: [" + Strings.collectionToCommaDelimitedString(remote.keySet()) + "]");
    }
    return new RemoteInfo(scheme, host, port, queryForRemote(source), username, password, headers, socketTimeout, connectTimeout);
}
Also used : Matcher(java.util.regex.Matcher) RemoteInfo(org.elasticsearch.index.reindex.remote.RemoteInfo) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap) TimeValue(org.elasticsearch.common.unit.TimeValue) TimeValue.parseTimeValue(org.elasticsearch.common.unit.TimeValue.parseTimeValue)

Example 2 with RemoteInfo

use of org.elasticsearch.index.reindex.remote.RemoteInfo in project elasticsearch by elastic.

the class ReindexFromRemoteBuildRestClientTests method testBuildRestClient.

public void testBuildRestClient() throws Exception {
    RemoteInfo remoteInfo = new RemoteInfo("https", "localhost", 9200, new BytesArray("ignored"), null, null, emptyMap(), RemoteInfo.DEFAULT_SOCKET_TIMEOUT, RemoteInfo.DEFAULT_CONNECT_TIMEOUT);
    long taskId = randomLong();
    List<Thread> threads = synchronizedList(new ArrayList<>());
    RestClient client = TransportReindexAction.buildRestClient(remoteInfo, taskId, threads);
    try {
        assertBusy(() -> assertThat(threads, hasSize(2)));
        int i = 0;
        for (Thread thread : threads) {
            assertEquals("es-client-" + taskId + "-" + i, thread.getName());
            i++;
        }
    } finally {
        client.close();
    }
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) RestClient(org.elasticsearch.client.RestClient) RemoteInfo(org.elasticsearch.index.reindex.remote.RemoteInfo)

Example 3 with RemoteInfo

use of org.elasticsearch.index.reindex.remote.RemoteInfo in project elasticsearch by elastic.

the class ReindexFromRemoteWhitelistTests method testWhitelistedByPrefix.

public void testWhitelistedByPrefix() {
    checkRemoteWhitelist(buildRemoteWhitelist(singletonList("*.example.com:9200")), new RemoteInfo(randomAsciiOfLength(5), "es.example.com", 9200, new BytesArray("test"), null, null, emptyMap(), RemoteInfo.DEFAULT_SOCKET_TIMEOUT, RemoteInfo.DEFAULT_CONNECT_TIMEOUT));
    checkRemoteWhitelist(buildRemoteWhitelist(singletonList("*.example.com:9200")), newRemoteInfo("6e134134a1.us-east-1.aws.example.com", 9200));
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) RemoteInfo(org.elasticsearch.index.reindex.remote.RemoteInfo)

Example 4 with RemoteInfo

use of org.elasticsearch.index.reindex.remote.RemoteInfo in project elasticsearch by elastic.

the class RestReindexActionTests method testBuildRemoteInfoWithAllHostParts.

public void testBuildRemoteInfoWithAllHostParts() throws IOException {
    RemoteInfo info = buildRemoteInfoHostTestCase("http://example.com:9200");
    assertEquals("http", info.getScheme());
    assertEquals("example.com", info.getHost());
    assertEquals(9200, info.getPort());
    // Didn't set the timeout so we should get the default
    assertEquals(RemoteInfo.DEFAULT_SOCKET_TIMEOUT, info.getSocketTimeout());
    // Didn't set the timeout so we should get the default
    assertEquals(RemoteInfo.DEFAULT_CONNECT_TIMEOUT, info.getConnectTimeout());
    info = buildRemoteInfoHostTestCase("https://other.example.com:9201");
    assertEquals("https", info.getScheme());
    assertEquals("other.example.com", info.getHost());
    assertEquals(9201, info.getPort());
    assertEquals(RemoteInfo.DEFAULT_SOCKET_TIMEOUT, info.getSocketTimeout());
    assertEquals(RemoteInfo.DEFAULT_CONNECT_TIMEOUT, info.getConnectTimeout());
}
Also used : RemoteInfo(org.elasticsearch.index.reindex.remote.RemoteInfo)

Example 5 with RemoteInfo

use of org.elasticsearch.index.reindex.remote.RemoteInfo in project elasticsearch by elastic.

the class ReindexRequestTests method testReindexFromRemoteDoesNotSupportWorkers.

public void testReindexFromRemoteDoesNotSupportWorkers() {
    ReindexRequest reindex = newRequest();
    reindex.setRemoteInfo(new RemoteInfo(randomAsciiOfLength(5), randomAsciiOfLength(5), between(1, Integer.MAX_VALUE), new BytesArray("real_query"), null, null, emptyMap(), RemoteInfo.DEFAULT_SOCKET_TIMEOUT, RemoteInfo.DEFAULT_CONNECT_TIMEOUT));
    reindex.setSlices(between(2, Integer.MAX_VALUE));
    ActionRequestValidationException e = reindex.validate();
    assertEquals("Validation Failed: 1: reindex from remote sources doesn't support workers > 1 but was [" + reindex.getSlices() + "];", e.getMessage());
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException) RemoteInfo(org.elasticsearch.index.reindex.remote.RemoteInfo)

Aggregations

RemoteInfo (org.elasticsearch.index.reindex.remote.RemoteInfo)11 BytesArray (org.elasticsearch.common.bytes.BytesArray)7 ActionRequestValidationException (org.elasticsearch.action.ActionRequestValidationException)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IndexRequest (org.elasticsearch.action.index.IndexRequest)2 SearchRequest (org.elasticsearch.action.search.SearchRequest)2 UncheckedIOException (java.io.UncheckedIOException)1 ArrayList (java.util.ArrayList)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.synchronizedList (java.util.Collections.synchronizedList)1 List (java.util.List)1 Objects (java.util.Objects)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 Matcher (java.util.regex.Matcher)1