remote = new RemoteClusterConnection(settings, clusterAlias, seedList, transportService, numRemoteConnections, getNodePredicate(settings), proxyAddress); remoteClusters.put(clusterAlias, remote); remote.updateSeedNodes(proxyAddress, seedList, ActionListener.wrap( response -> { if (countDown.countDown()) { connectionListener.onFailure(exception); if (finalRemote.isClosed() == false) { logger.warn("failed to update seed list for cluster: " + entry.getKey(), exception);
/** * Fetches all shards for the search request from this remote connection. This is used to later run the search on the remote end. */ public void fetchSearchShards(ClusterSearchShardsRequest searchRequest, ActionListener<ClusterSearchShardsResponse> listener) { final ActionListener<ClusterSearchShardsResponse> searchShardsListener; final Consumer<Exception> onConnectFailure; if (skipUnavailable) { onConnectFailure = (exception) -> listener.onResponse(ClusterSearchShardsResponse.EMPTY); searchShardsListener = ActionListener.wrap(listener::onResponse, (e) -> listener.onResponse(ClusterSearchShardsResponse.EMPTY)); } else { onConnectFailure = listener::onFailure; searchShardsListener = listener; } // in case we have no connected nodes we try to connect and if we fail we either notify the listener or not depending on // the skip_unavailable setting ensureConnected(ActionListener.wrap((x) -> fetchShardsInternal(searchRequest, searchShardsListener), onConnectFailure)); }
.indicesOptions(indicesOptions).local(true).preference(preference) .routing(routing); remoteClusterConnection.fetchSearchShards(searchShardsRequest, new ActionListener<ClusterSearchShardsResponse>() { @Override
public Transport.Connection getConnection(String cluster) { return getRemoteClusterConnection(cluster).getConnection(); }
request.nodes(true); request.local(true); // run this on the node that gets the request it's as good as any other final DiscoveryNode node = getAnyConnectedNode(); Transport.Connection connection = connectionManager.getConnection(node); transportService.sendRequest(connection, ClusterStateAction.NAME, request, TransportRequestOptions.EMPTY, ensureConnected(ActionListener.wrap((x) -> runnable.run(), listener::onFailure)); } catch (Exception ex) { listener.onFailure(ex);
/** * Ensures that the given cluster alias is connected. If the cluster is connected this operation * will invoke the listener immediately. */ void ensureConnected(String clusterAlias, ActionListener<Void> listener) { getRemoteClusterConnection(clusterAlias).ensureConnected(listener); }
public void getRemoteConnectionInfos(ActionListener<Collection<RemoteConnectionInfo>> listener) { final Map<String, RemoteClusterConnection> remoteClusters = this.remoteClusters; if (remoteClusters.isEmpty()) { listener.onResponse(Collections.emptyList()); } else { final GroupedActionListener<RemoteConnectionInfo> actionListener = new GroupedActionListener<>(listener, remoteClusters.size(), Collections.emptyList()); for (RemoteClusterConnection connection : remoteClusters.values()) { connection.getConnectionInfo(actionListener); } } }
boolean isRemoteNodeConnected(final String remoteCluster, final DiscoveryNode node) { return remoteClusters.get(remoteCluster).isNodeConnected(node); }
/** * Fetches all shards for the search request from this remote connection. This is used to later run the search on the remote end. */ public void fetchSearchShards(ClusterSearchShardsRequest searchRequest, ActionListener<ClusterSearchShardsResponse> listener) { final ActionListener<ClusterSearchShardsResponse> searchShardsListener; final Consumer<Exception> onConnectFailure; if (skipUnavailable) { onConnectFailure = (exception) -> listener.onResponse(ClusterSearchShardsResponse.EMPTY); searchShardsListener = ActionListener.wrap(listener::onResponse, (e) -> listener.onResponse(ClusterSearchShardsResponse.EMPTY)); } else { onConnectFailure = listener::onFailure; searchShardsListener = listener; } // in case we have no connected nodes we try to connect and if we fail we either notify the listener or not depending on // the skip_unavailable setting ensureConnected(ActionListener.wrap((x) -> fetchShardsInternal(searchRequest, searchShardsListener), onConnectFailure)); }
for (final String cluster : clusters) { RemoteClusterConnection connection = remoteClusters.get(cluster); connection.collectNodes(new ActionListener<Function<String, DiscoveryNode>>() { @Override public void onResponse(Function<String, DiscoveryNode> nodeLookup) {
/** * Returns a connection to the given node on the given remote cluster * @throws IllegalArgumentException if the remote cluster is unknown */ public Transport.Connection getConnection(DiscoveryNode node, String cluster) { return getRemoteClusterConnection(cluster).getConnection(node); }
request.nodes(true); request.local(true); // run this on the node that gets the request it's as good as any other final DiscoveryNode node = getAnyConnectedNode(); Transport.Connection connection = connectionManager.getConnection(node); transportService.sendRequest(connection, ClusterStateAction.NAME, request, TransportRequestOptions.EMPTY, ensureConnected(ActionListener.wrap((x) -> runnable.run(), listener::onFailure)); } catch (Exception ex) { listener.onFailure(ex);
/** * Ensures that the given cluster alias is connected. If the cluster is connected this operation * will invoke the listener immediately. */ public void ensureConnected(String clusterAlias, ActionListener<Void> listener) { RemoteClusterConnection remoteClusterConnection = remoteClusters.get(clusterAlias); if (remoteClusterConnection == null) { throw new IllegalArgumentException("no such remote cluster: " + clusterAlias); } remoteClusterConnection.ensureConnected(listener); }
public void getRemoteConnectionInfos(ActionListener<Collection<RemoteConnectionInfo>> listener) { final Map<String, RemoteClusterConnection> remoteClusters = this.remoteClusters; if (remoteClusters.isEmpty()) { listener.onResponse(Collections.emptyList()); } else { final GroupedActionListener<RemoteConnectionInfo> actionListener = new GroupedActionListener<>(listener, remoteClusters.size(), Collections.emptyList()); for (RemoteClusterConnection connection : remoteClusters.values()) { connection.getConnectionInfo(actionListener); } } }
boolean isRemoteNodeConnected(final String remoteCluster, final DiscoveryNode node) { return remoteClusters.get(remoteCluster).isNodeConnected(node); }
for (final String cluster : clusters) { RemoteClusterConnection connection = remoteClusters.get(cluster); connection.collectNodes(new ActionListener<Function<String, DiscoveryNode>>() { @Override public void onResponse(Function<String, DiscoveryNode> nodeLookup) {
remote = new RemoteClusterConnection(settings, entry.getKey(), entry.getValue(), transportService, numRemoteConnections, getNodePredicate(settings)); remoteClusters.put(entry.getKey(), remote); remote.updateSeedNodes(entry.getValue(), ActionListener.wrap( response -> { if (countDown.countDown()) { connectionListener.onFailure(exception); if (finalRemote.isClosed() == false) { logger.warn("failed to update seed list for cluster: " + entry.getKey(), exception);
/** * Fetches all shards for the search request from this remote connection. This is used to later run the search on the remote end. */ public void fetchSearchShards(ClusterSearchShardsRequest searchRequest, ActionListener<ClusterSearchShardsResponse> listener) { if (connectedNodes.size() == 0) { // just in case if we are not connected for some reason we try to connect and if we fail we have to notify the listener // this will cause some back pressure on the search end and eventually will cause rejections but that's fine // we can't proceed with a search on a cluster level. // in the future we might want to just skip the remote nodes in such a case but that can already be implemented on the caller // end since they provide the listener. ensureConnected(ActionListener.wrap((x) -> fetchShardsInternal(searchRequest, listener), listener::onFailure)); } else { fetchShardsInternal(searchRequest, listener); } }
public Transport.Connection getConnection(String cluster) { RemoteClusterConnection connection = remoteClusters.get(cluster); if (connection == null) { throw new IllegalArgumentException("no such remote cluster: " + cluster); } return connection.getConnection(); }
/** * Ensures that the given cluster alias is connected. If the cluster is connected this operation * will invoke the listener immediately. */ public void ensureConnected(String clusterAlias, ActionListener<Void> listener) { RemoteClusterConnection remoteClusterConnection = remoteClusters.get(clusterAlias); if (remoteClusterConnection == null) { throw new IllegalArgumentException("no such remote cluster: " + clusterAlias); } remoteClusterConnection.ensureConnected(listener); }