Search in sources :

Example 1 with RemoteInfoRequest

use of org.opensearch.client.cluster.RemoteInfoRequest in project OpenSearch by opensearch-project.

the class RemoteClustersIT method testProxyModeConnectionWorks.

public void testProxyModeConnectionWorks() throws IOException {
    String cluster2RemoteClusterSeed = "opensearch-2:9300";
    logger.info("Configuring remote cluster [{}]", cluster2RemoteClusterSeed);
    ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest().persistentSettings(Settings.builder().put("cluster.remote.cluster2.mode", "proxy").put("cluster.remote.cluster2.proxy_address", cluster2RemoteClusterSeed).build());
    assertTrue(cluster1Client().cluster().putSettings(request, RequestOptions.DEFAULT).isAcknowledged());
    RemoteConnectionInfo rci = cluster1Client().cluster().remoteInfo(new RemoteInfoRequest(), RequestOptions.DEFAULT).getInfos().get(0);
    logger.info("Connection info: {}", rci);
    assertTrue(rci.isConnected());
    assertEquals(2L, cluster1Client().search(new SearchRequest("cluster2:test2"), RequestOptions.DEFAULT).getHits().getTotalHits().value);
}
Also used : SearchRequest(org.opensearch.action.search.SearchRequest) RemoteConnectionInfo(org.opensearch.client.cluster.RemoteConnectionInfo) ClusterUpdateSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest) RemoteInfoRequest(org.opensearch.client.cluster.RemoteInfoRequest)

Example 2 with RemoteInfoRequest

use of org.opensearch.client.cluster.RemoteInfoRequest in project OpenSearch by opensearch-project.

the class RemoteClustersIT method testSniffModeConnectionFails.

public void testSniffModeConnectionFails() throws IOException {
    String cluster2RemoteClusterSeed = "opensearch-2:9300";
    logger.info("Configuring remote cluster [{}]", cluster2RemoteClusterSeed);
    ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest().persistentSettings(Settings.builder().put("cluster.remote.cluster2alt.mode", "sniff").put("cluster.remote.cluster2alt.seeds", cluster2RemoteClusterSeed).build());
    assertTrue(cluster1Client().cluster().putSettings(request, RequestOptions.DEFAULT).isAcknowledged());
    RemoteConnectionInfo rci = cluster1Client().cluster().remoteInfo(new RemoteInfoRequest(), RequestOptions.DEFAULT).getInfos().get(0);
    logger.info("Connection info: {}", rci);
    assertFalse(rci.isConnected());
}
Also used : RemoteConnectionInfo(org.opensearch.client.cluster.RemoteConnectionInfo) ClusterUpdateSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest) RemoteInfoRequest(org.opensearch.client.cluster.RemoteInfoRequest)

Example 3 with RemoteInfoRequest

use of org.opensearch.client.cluster.RemoteInfoRequest in project OpenSearch by opensearch-project.

the class RemoteClustersIT method testHAProxyModeConnectionWorks.

public void testHAProxyModeConnectionWorks() throws IOException {
    String proxyAddress = "haproxy:9600";
    logger.info("Configuring remote cluster [{}]", proxyAddress);
    ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest().persistentSettings(Settings.builder().put("cluster.remote.haproxynosn.mode", "proxy").put("cluster.remote.haproxynosn.proxy_address", proxyAddress).build());
    assertTrue(cluster1Client().cluster().putSettings(request, RequestOptions.DEFAULT).isAcknowledged());
    RemoteConnectionInfo rci = cluster1Client().cluster().remoteInfo(new RemoteInfoRequest(), RequestOptions.DEFAULT).getInfos().get(0);
    logger.info("Connection info: {}", rci);
    assertTrue(rci.isConnected());
    assertEquals(2L, cluster1Client().search(new SearchRequest("haproxynosn:test2"), RequestOptions.DEFAULT).getHits().getTotalHits().value);
}
Also used : SearchRequest(org.opensearch.action.search.SearchRequest) RemoteConnectionInfo(org.opensearch.client.cluster.RemoteConnectionInfo) ClusterUpdateSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest) RemoteInfoRequest(org.opensearch.client.cluster.RemoteInfoRequest)

Example 4 with RemoteInfoRequest

use of org.opensearch.client.cluster.RemoteInfoRequest in project OpenSearch by opensearch-project.

the class ClusterClientDocumentationIT method testRemoteInfoAsync.

public void testRemoteInfoAsync() throws Exception {
    setupRemoteClusterConfig("local_cluster");
    RestHighLevelClient client = highLevelClient();
    // tag::remote-info-request
    RemoteInfoRequest request = new RemoteInfoRequest();
    // end::remote-info-request
    // tag::remote-info-execute-listener
    ActionListener<RemoteInfoResponse> listener = new ActionListener<RemoteInfoResponse>() {

        @Override
        public void onResponse(RemoteInfoResponse response) {
        // <1>
        }

        @Override
        public void onFailure(Exception e) {
        // <2>
        }
    };
    // end::remote-info-execute-listener
    // Replace the empty listener by a blocking listener in test
    final CountDownLatch latch = new CountDownLatch(1);
    listener = new LatchedActionListener<>(listener, latch);
    // tag::health-execute-async
    // <1>
    client.cluster().remoteInfoAsync(request, RequestOptions.DEFAULT, listener);
    // end::health-execute-async
    assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
Also used : LatchedActionListener(org.opensearch.action.LatchedActionListener) ActionListener(org.opensearch.action.ActionListener) RemoteInfoResponse(org.opensearch.client.cluster.RemoteInfoResponse) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) CountDownLatch(java.util.concurrent.CountDownLatch) RemoteInfoRequest(org.opensearch.client.cluster.RemoteInfoRequest) IOException(java.io.IOException)

Example 5 with RemoteInfoRequest

use of org.opensearch.client.cluster.RemoteInfoRequest in project OpenSearch by opensearch-project.

the class ClusterClientDocumentationIT method testRemoteInfo.

public void testRemoteInfo() throws Exception {
    setupRemoteClusterConfig("local_cluster");
    RestHighLevelClient client = highLevelClient();
    // tag::remote-info-request
    RemoteInfoRequest request = new RemoteInfoRequest();
    // end::remote-info-request
    // tag::remote-info-execute
    // <1>
    RemoteInfoResponse response = client.cluster().remoteInfo(request, RequestOptions.DEFAULT);
    // end::remote-info-execute
    // tag::remote-info-response
    List<RemoteConnectionInfo> infos = response.getInfos();
    // end::remote-info-response
    assertThat(infos.size(), greaterThan(0));
}
Also used : RemoteConnectionInfo(org.opensearch.client.cluster.RemoteConnectionInfo) RemoteInfoResponse(org.opensearch.client.cluster.RemoteInfoResponse) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) RemoteInfoRequest(org.opensearch.client.cluster.RemoteInfoRequest)

Aggregations

RemoteInfoRequest (org.opensearch.client.cluster.RemoteInfoRequest)8 ClusterUpdateSettingsRequest (org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest)5 RemoteConnectionInfo (org.opensearch.client.cluster.RemoteConnectionInfo)5 RemoteInfoResponse (org.opensearch.client.cluster.RemoteInfoResponse)4 SearchRequest (org.opensearch.action.search.SearchRequest)3 ClusterGetSettingsRequest (org.opensearch.action.admin.cluster.settings.ClusterGetSettingsRequest)2 RestHighLevelClient (org.opensearch.client.RestHighLevelClient)2 IOException (java.io.IOException)1 Collections.singletonMap (java.util.Collections.singletonMap)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ActionListener (org.opensearch.action.ActionListener)1 LatchedActionListener (org.opensearch.action.LatchedActionListener)1 ClusterHealthRequest (org.opensearch.action.admin.cluster.health.ClusterHealthRequest)1 ListTasksRequest (org.opensearch.action.admin.cluster.node.tasks.list.ListTasksRequest)1 ClusterGetSettingsResponse (org.opensearch.action.admin.cluster.settings.ClusterGetSettingsResponse)1 ClusterUpdateSettingsResponse (org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse)1 PutPipelineRequest (org.opensearch.action.ingest.PutPipelineRequest)1 AcknowledgedRequest (org.opensearch.action.support.master.AcknowledgedRequest)1 SniffModeInfo (org.opensearch.client.cluster.SniffModeInfo)1