Search in sources :

Example 1 with RemoteInfoResponse

use of org.opensearch.client.cluster.RemoteInfoResponse 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 2 with RemoteInfoResponse

use of org.opensearch.client.cluster.RemoteInfoResponse 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)

Example 3 with RemoteInfoResponse

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

the class OpenSearchRestHighLevelClientTestCase method setupRemoteClusterConfig.

protected static void setupRemoteClusterConfig(String remoteClusterName) throws Exception {
    // Configure local cluster as remote cluster:
    // TODO: replace with nodes info highlevel rest client code when it is available:
    final Request request = new Request("GET", "/_nodes");
    Map<?, ?> nodesResponse = (Map<?, ?>) toMap(client().performRequest(request)).get("nodes");
    // Select node info of first node (we don't know the node id):
    nodesResponse = (Map<?, ?>) nodesResponse.get(nodesResponse.keySet().iterator().next());
    String transportAddress = (String) nodesResponse.get("transport_address");
    ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
    updateSettingsRequest.transientSettings(singletonMap("cluster.remote." + remoteClusterName + ".seeds", transportAddress));
    ClusterUpdateSettingsResponse updateSettingsResponse = restHighLevelClient.cluster().putSettings(updateSettingsRequest, RequestOptions.DEFAULT);
    assertThat(updateSettingsResponse.isAcknowledged(), is(true));
    assertBusy(() -> {
        RemoteInfoResponse response = highLevelClient().cluster().remoteInfo(new RemoteInfoRequest(), RequestOptions.DEFAULT);
        assertThat(response, notNullValue());
        assertThat(response.getInfos().size(), greaterThan(0));
    });
}
Also used : PutPipelineRequest(org.opensearch.action.ingest.PutPipelineRequest) ListTasksRequest(org.opensearch.action.admin.cluster.node.tasks.list.ListTasksRequest) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) ClusterUpdateSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest) SearchRequest(org.opensearch.action.search.SearchRequest) RemoteInfoRequest(org.opensearch.client.cluster.RemoteInfoRequest) RemoteInfoResponse(org.opensearch.client.cluster.RemoteInfoResponse) ClusterUpdateSettingsResponse(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) ClusterUpdateSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest) RemoteInfoRequest(org.opensearch.client.cluster.RemoteInfoRequest)

Example 4 with RemoteInfoResponse

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

the class ClusterClientIT method testRemoteInfo.

public void testRemoteInfo() throws Exception {
    String clusterAlias = "local_cluster";
    setupRemoteClusterConfig(clusterAlias);
    ClusterGetSettingsRequest settingsRequest = new ClusterGetSettingsRequest();
    settingsRequest.includeDefaults(true);
    ClusterGetSettingsResponse settingsResponse = highLevelClient().cluster().getSettings(settingsRequest, RequestOptions.DEFAULT);
    List<String> seeds = SniffConnectionStrategy.REMOTE_CLUSTER_SEEDS.getConcreteSettingForNamespace(clusterAlias).get(settingsResponse.getTransientSettings());
    int connectionsPerCluster = SniffConnectionStrategy.REMOTE_CONNECTIONS_PER_CLUSTER.get(settingsResponse.getTransientSettings());
    TimeValue initialConnectionTimeout = RemoteClusterService.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING.get(settingsResponse.getTransientSettings());
    boolean skipUnavailable = RemoteClusterService.REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace(clusterAlias).get(settingsResponse.getTransientSettings());
    RemoteInfoRequest request = new RemoteInfoRequest();
    RemoteInfoResponse response = execute(request, highLevelClient().cluster()::remoteInfo, highLevelClient().cluster()::remoteInfoAsync);
    assertThat(response, notNullValue());
    assertThat(response.getInfos().size(), equalTo(1));
    RemoteConnectionInfo info = response.getInfos().get(0);
    assertThat(info.getClusterAlias(), equalTo(clusterAlias));
    assertThat(info.getInitialConnectionTimeoutString(), equalTo(initialConnectionTimeout.toString()));
    assertThat(info.isSkipUnavailable(), equalTo(skipUnavailable));
    assertThat(info.getModeInfo().modeName(), equalTo(SniffModeInfo.NAME));
    assertThat(info.getModeInfo().isConnected(), equalTo(true));
    SniffModeInfo sniffModeInfo = (SniffModeInfo) info.getModeInfo();
    assertThat(sniffModeInfo.getMaxConnectionsPerCluster(), equalTo(connectionsPerCluster));
    assertThat(sniffModeInfo.getNumNodesConnected(), equalTo(1));
    assertThat(sniffModeInfo.getSeedNodes(), equalTo(seeds));
}
Also used : ClusterGetSettingsResponse(org.opensearch.action.admin.cluster.settings.ClusterGetSettingsResponse) RemoteConnectionInfo(org.opensearch.client.cluster.RemoteConnectionInfo) SniffModeInfo(org.opensearch.client.cluster.SniffModeInfo) RemoteInfoResponse(org.opensearch.client.cluster.RemoteInfoResponse) ClusterGetSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterGetSettingsRequest) TimeValue(org.opensearch.common.unit.TimeValue) RemoteInfoRequest(org.opensearch.client.cluster.RemoteInfoRequest)

Aggregations

RemoteInfoRequest (org.opensearch.client.cluster.RemoteInfoRequest)4 RemoteInfoResponse (org.opensearch.client.cluster.RemoteInfoResponse)4 RestHighLevelClient (org.opensearch.client.RestHighLevelClient)2 RemoteConnectionInfo (org.opensearch.client.cluster.RemoteConnectionInfo)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 ListTasksRequest (org.opensearch.action.admin.cluster.node.tasks.list.ListTasksRequest)1 ClusterGetSettingsRequest (org.opensearch.action.admin.cluster.settings.ClusterGetSettingsRequest)1 ClusterGetSettingsResponse (org.opensearch.action.admin.cluster.settings.ClusterGetSettingsResponse)1 ClusterUpdateSettingsRequest (org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest)1 ClusterUpdateSettingsResponse (org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse)1 PutPipelineRequest (org.opensearch.action.ingest.PutPipelineRequest)1 SearchRequest (org.opensearch.action.search.SearchRequest)1 SniffModeInfo (org.opensearch.client.cluster.SniffModeInfo)1 CreateIndexRequest (org.opensearch.client.indices.CreateIndexRequest)1 TimeValue (org.opensearch.common.unit.TimeValue)1