Search in sources :

Example 6 with RemoteInfo

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

the class ReindexSourceTargetValidationTests method testRemoteInfoSkipsValidation.

public void testRemoteInfoSkipsValidation() {
    // The index doesn't have to exist
    succeeds(new RemoteInfo(randomAsciiOfLength(5), "test", 9200, new BytesArray("test"), null, null, emptyMap(), RemoteInfo.DEFAULT_SOCKET_TIMEOUT, RemoteInfo.DEFAULT_CONNECT_TIMEOUT), "does_not_exist", "target");
    // And it doesn't matter if they are the same index. They are considered to be different because the remote one is, well, remote.
    succeeds(new RemoteInfo(randomAsciiOfLength(5), "test", 9200, new BytesArray("test"), null, null, emptyMap(), RemoteInfo.DEFAULT_SOCKET_TIMEOUT, RemoteInfo.DEFAULT_CONNECT_TIMEOUT), "target", "target");
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) RemoteInfo(org.elasticsearch.index.reindex.remote.RemoteInfo)

Example 7 with RemoteInfo

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

the class RestReindexActionTests method testBuildRemoteInfoFullyLoaded.

public void testBuildRemoteInfoFullyLoaded() throws IOException {
    Map<String, String> headers = new HashMap<>();
    headers.put("first", "a");
    headers.put("second", "b");
    headers.put("third", "");
    Map<String, Object> remote = new HashMap<>();
    remote.put("host", "https://example.com:9200");
    remote.put("username", "testuser");
    remote.put("password", "testpass");
    remote.put("headers", headers);
    remote.put("socket_timeout", "90s");
    remote.put("connect_timeout", "10s");
    Map<String, Object> query = new HashMap<>();
    query.put("a", "b");
    Map<String, Object> source = new HashMap<>();
    source.put("remote", remote);
    source.put("query", query);
    RemoteInfo remoteInfo = RestReindexAction.buildRemoteInfo(source);
    assertEquals("https", remoteInfo.getScheme());
    assertEquals("example.com", remoteInfo.getHost());
    assertEquals(9200, remoteInfo.getPort());
    assertEquals("{\n  \"a\" : \"b\"\n}", remoteInfo.getQuery().utf8ToString());
    assertEquals("testuser", remoteInfo.getUsername());
    assertEquals("testpass", remoteInfo.getPassword());
    assertEquals(headers, remoteInfo.getHeaders());
    assertEquals(timeValueSeconds(90), remoteInfo.getSocketTimeout());
    assertEquals(timeValueSeconds(10), remoteInfo.getConnectTimeout());
}
Also used : HashMap(java.util.HashMap) RemoteInfo(org.elasticsearch.index.reindex.remote.RemoteInfo)

Example 8 with RemoteInfo

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

the class RetryTests method testReindexFromRemote.

public void testReindexFromRemote() throws Exception {
    NodeInfo nodeInfo = client().admin().cluster().prepareNodesInfo().get().getNodes().get(0);
    TransportAddress address = nodeInfo.getHttp().getAddress().publishAddress();
    RemoteInfo remote = new RemoteInfo("http", address.getAddress(), address.getPort(), new BytesArray("{\"match_all\":{}}"), null, null, emptyMap(), RemoteInfo.DEFAULT_SOCKET_TIMEOUT, RemoteInfo.DEFAULT_CONNECT_TIMEOUT);
    ReindexRequestBuilder request = ReindexAction.INSTANCE.newRequestBuilder(client()).source("source").destination("dest").setRemoteInfo(remote);
    testCase(ReindexAction.NAME, request, matcher().created(DOC_COUNT));
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) TransportAddress(org.elasticsearch.common.transport.TransportAddress) RemoteInfo(org.elasticsearch.index.reindex.remote.RemoteInfo)

Example 9 with RemoteInfo

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

the class RoundTripTests method testReindexRequest.

public void testReindexRequest() throws IOException {
    ReindexRequest reindex = new ReindexRequest(new SearchRequest(), new IndexRequest());
    randomRequest(reindex);
    reindex.getDestination().version(randomFrom(Versions.MATCH_ANY, Versions.MATCH_DELETED, 12L, 1L, 123124L, 12L));
    reindex.getDestination().index("test");
    if (randomBoolean()) {
        int port = between(1, Integer.MAX_VALUE);
        BytesReference query = new BytesArray(randomAsciiOfLength(5));
        String username = randomBoolean() ? randomAsciiOfLength(5) : null;
        String password = username != null && randomBoolean() ? randomAsciiOfLength(5) : null;
        int headersCount = randomBoolean() ? 0 : between(1, 10);
        Map<String, String> headers = new HashMap<>(headersCount);
        while (headers.size() < headersCount) {
            headers.put(randomAsciiOfLength(5), randomAsciiOfLength(5));
        }
        TimeValue socketTimeout = parseTimeValue(randomPositiveTimeValue(), "socketTimeout");
        TimeValue connectTimeout = parseTimeValue(randomPositiveTimeValue(), "connectTimeout");
        reindex.setRemoteInfo(new RemoteInfo(randomAsciiOfLength(5), randomAsciiOfLength(5), port, query, username, password, headers, socketTimeout, connectTimeout));
    }
    ReindexRequest tripped = new ReindexRequest();
    roundTrip(reindex, tripped);
    assertRequestEquals(reindex, tripped);
    // Try slices with a version that doesn't support slices. That should fail.
    reindex.setSlices(between(2, 1000));
    Exception e = expectThrows(IllegalArgumentException.class, () -> roundTrip(Version.V_5_0_0_rc1, reindex, null));
    assertEquals("Attempting to send sliced reindex-style request to a node that doesn't support it. " + "Version is [5.0.0-rc1] but must be [5.1.1]", e.getMessage());
    // Try without slices with a version that doesn't support slices. That should work.
    tripped = new ReindexRequest();
    reindex.setSlices(1);
    roundTrip(Version.V_5_0_0_rc1, reindex, tripped);
    assertRequestEquals(Version.V_5_0_0_rc1, reindex, tripped);
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) SearchRequest(org.elasticsearch.action.search.SearchRequest) BytesArray(org.elasticsearch.common.bytes.BytesArray) HashMap(java.util.HashMap) RemoteInfo(org.elasticsearch.index.reindex.remote.RemoteInfo) TestUtil.randomSimpleString(org.apache.lucene.util.TestUtil.randomSimpleString) IndexRequest(org.elasticsearch.action.index.IndexRequest) TimeValue(org.elasticsearch.common.unit.TimeValue) TimeValue.parseTimeValue(org.elasticsearch.common.unit.TimeValue.parseTimeValue) IOException(java.io.IOException)

Example 10 with RemoteInfo

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

the class TransportReindexAction method buildRestClient.

/**
     * Build the {@link RestClient} used for reindexing from remote clusters.
     * @param remoteInfo connection information for the remote cluster
     * @param taskId the id of the current task. This is added to the thread name for easier tracking
     * @param threadCollector a list in which we collect all the threads created by the client
     */
static RestClient buildRestClient(RemoteInfo remoteInfo, long taskId, List<Thread> threadCollector) {
    Header[] clientHeaders = new Header[remoteInfo.getHeaders().size()];
    int i = 0;
    for (Map.Entry<String, String> header : remoteInfo.getHeaders().entrySet()) {
        clientHeaders[i] = new BasicHeader(header.getKey(), header.getValue());
    }
    return RestClient.builder(new HttpHost(remoteInfo.getHost(), remoteInfo.getPort(), remoteInfo.getScheme())).setDefaultHeaders(clientHeaders).setRequestConfigCallback(c -> {
        c.setConnectTimeout(Math.toIntExact(remoteInfo.getConnectTimeout().millis()));
        c.setSocketTimeout(Math.toIntExact(remoteInfo.getSocketTimeout().millis()));
        return c;
    }).setHttpClientConfigCallback(c -> {
        if (remoteInfo.getUsername() != null) {
            UsernamePasswordCredentials creds = new UsernamePasswordCredentials(remoteInfo.getUsername(), remoteInfo.getPassword());
            CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(AuthScope.ANY, creds);
            c.setDefaultCredentialsProvider(credentialsProvider);
        }
        AtomicInteger threads = new AtomicInteger();
        c.setThreadFactory(r -> {
            String name = "es-client-" + taskId + "-" + threads.getAndIncrement();
            Thread t = new Thread(r, name);
            threadCollector.add(t);
            return t;
        });
        c.setDefaultIOReactorConfig(IOReactorConfig.custom().setIoThreadCount(1).build());
        return c;
    }).build();
}
Also used : Versions(org.elasticsearch.common.lucene.uid.Versions) RemoteScrollableHitSource(org.elasticsearch.index.reindex.remote.RemoteScrollableHitSource) IOReactorConfig(org.apache.http.impl.nio.reactor.IOReactorConfig) Property(org.elasticsearch.common.settings.Setting.Property) BiFunction(java.util.function.BiFunction) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Header(org.apache.http.Header) VersionType(org.elasticsearch.index.VersionType) AutoCreateIndex(org.elasticsearch.action.support.AutoCreateIndex) RemoteInfo(org.elasticsearch.index.reindex.remote.RemoteInfo) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) IndexRequest(org.elasticsearch.action.index.IndexRequest) ClusterState(org.elasticsearch.cluster.ClusterState) Operations(org.apache.lucene.util.automaton.Operations) Settings(org.elasticsearch.common.settings.Settings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ParentBulkByScrollTask(org.elasticsearch.action.bulk.byscroll.ParentBulkByScrollTask) ThreadPool(org.elasticsearch.threadpool.ThreadPool) Failure(org.elasticsearch.action.bulk.BulkItemResponse.Failure) Automata(org.apache.lucene.util.automaton.Automata) AbstractAsyncBulkByScrollAction(org.elasticsearch.action.bulk.byscroll.AbstractAsyncBulkByScrollAction) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) WorkingBulkByScrollTask(org.elasticsearch.action.bulk.byscroll.WorkingBulkByScrollTask) BulkByScrollResponse(org.elasticsearch.action.bulk.byscroll.BulkByScrollResponse) ActionFilters(org.elasticsearch.action.support.ActionFilters) Setting(org.elasticsearch.common.settings.Setting) Collections.synchronizedList(java.util.Collections.synchronizedList) Automaton(org.apache.lucene.util.automaton.Automaton) Collections.emptyList(java.util.Collections.emptyList) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException) CredentialsProvider(org.apache.http.client.CredentialsProvider) Task(org.elasticsearch.tasks.Task) RestClient(org.elasticsearch.client.RestClient) XContentType(org.elasticsearch.common.xcontent.XContentType) ClusterService(org.elasticsearch.cluster.service.ClusterService) SearchRequest(org.elasticsearch.action.search.SearchRequest) INTERNAL(org.elasticsearch.index.VersionType.INTERNAL) Function(java.util.function.Function) BackoffPolicy(org.elasticsearch.action.bulk.BackoffPolicy) Strings(org.elasticsearch.common.Strings) Inject(org.elasticsearch.common.inject.Inject) ArrayList(java.util.ArrayList) ScrollableHitSource(org.elasticsearch.action.bulk.byscroll.ScrollableHitSource) HandledTransportAction(org.elasticsearch.action.support.HandledTransportAction) ParentTaskAssigningClient(org.elasticsearch.client.ParentTaskAssigningClient) Objects.requireNonNull(java.util.Objects.requireNonNull) Regex(org.elasticsearch.common.regex.Regex) TransportService(org.elasticsearch.transport.TransportService) CharacterRunAutomaton(org.apache.lucene.util.automaton.CharacterRunAutomaton) Script(org.elasticsearch.script.Script) BulkByScrollParallelizationHelper(org.elasticsearch.action.bulk.byscroll.BulkByScrollParallelizationHelper) Client(org.elasticsearch.client.Client) IOException(java.io.IOException) MinimizationOperations(org.apache.lucene.util.automaton.MinimizationOperations) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) XContentParser(org.elasticsearch.common.xcontent.XContentParser) VersionFieldMapper(org.elasticsearch.index.mapper.VersionFieldMapper) AuthScope(org.apache.http.auth.AuthScope) SearchFailure(org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure) BasicHeader(org.apache.http.message.BasicHeader) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) HttpHost(org.apache.http.HttpHost) ScriptService(org.elasticsearch.script.ScriptService) ActionListener(org.elasticsearch.action.ActionListener) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpHost(org.apache.http.HttpHost) Map(java.util.Map) BasicHeader(org.apache.http.message.BasicHeader)

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