Search in sources :

Example 1 with RemoteConnectionInfo

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

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

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

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

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

RemoteConnectionInfo (org.opensearch.client.cluster.RemoteConnectionInfo)5 RemoteInfoRequest (org.opensearch.client.cluster.RemoteInfoRequest)5 ClusterUpdateSettingsRequest (org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest)3 SearchRequest (org.opensearch.action.search.SearchRequest)2 RemoteInfoResponse (org.opensearch.client.cluster.RemoteInfoResponse)2 ClusterGetSettingsRequest (org.opensearch.action.admin.cluster.settings.ClusterGetSettingsRequest)1 ClusterGetSettingsResponse (org.opensearch.action.admin.cluster.settings.ClusterGetSettingsResponse)1 RestHighLevelClient (org.opensearch.client.RestHighLevelClient)1 SniffModeInfo (org.opensearch.client.cluster.SniffModeInfo)1 TimeValue (org.opensearch.common.unit.TimeValue)1