Search in sources :

Example 1 with EmptyTransportResponseHandler

use of org.opensearch.transport.EmptyTransportResponseHandler in project OpenSearch by opensearch-project.

the class ShardStateAction method sendShardAction.

private void sendShardAction(final String actionName, final ClusterState currentState, final TransportRequest request, final ActionListener<Void> listener) {
    ClusterStateObserver observer = new ClusterStateObserver(currentState, clusterService, null, logger, threadPool.getThreadContext());
    DiscoveryNode masterNode = currentState.nodes().getMasterNode();
    Predicate<ClusterState> changePredicate = MasterNodeChangePredicate.build(currentState);
    if (masterNode == null) {
        logger.warn("no master known for action [{}] for shard entry [{}]", actionName, request);
        waitForNewMasterAndRetry(actionName, observer, request, listener, changePredicate);
    } else {
        logger.debug("sending [{}] to [{}] for shard entry [{}]", actionName, masterNode.getId(), request);
        transportService.sendRequest(masterNode, actionName, request, new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {

            @Override
            public void handleResponse(TransportResponse.Empty response) {
                listener.onResponse(null);
            }

            @Override
            public void handleException(TransportException exp) {
                if (isMasterChannelException(exp)) {
                    waitForNewMasterAndRetry(actionName, observer, request, listener, changePredicate);
                } else {
                    logger.warn(new ParameterizedMessage("unexpected failure while sending request [{}]" + " to [{}] for shard entry [{}]", actionName, masterNode, request), exp);
                    listener.onFailure(exp instanceof RemoteTransportException ? (Exception) (exp.getCause() instanceof Exception ? exp.getCause() : new OpenSearchException(exp.getCause())) : exp);
                }
            }
        });
    }
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) RemoteTransportException(org.opensearch.transport.RemoteTransportException) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) TransportResponse(org.opensearch.transport.TransportResponse) RemoteTransportException(org.opensearch.transport.RemoteTransportException) ConnectTransportException(org.opensearch.transport.ConnectTransportException) TransportException(org.opensearch.transport.TransportException) OpenSearchException(org.opensearch.OpenSearchException) NotMasterException(org.opensearch.cluster.NotMasterException) NodeClosedException(org.opensearch.node.NodeClosedException) RemoteTransportException(org.opensearch.transport.RemoteTransportException) FailedToCommitClusterStateException(org.opensearch.cluster.coordination.FailedToCommitClusterStateException) ConnectTransportException(org.opensearch.transport.ConnectTransportException) TransportException(org.opensearch.transport.TransportException) IOException(java.io.IOException) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) OpenSearchException(org.opensearch.OpenSearchException) EmptyTransportResponseHandler(org.opensearch.transport.EmptyTransportResponseHandler)

Example 2 with EmptyTransportResponseHandler

use of org.opensearch.transport.EmptyTransportResponseHandler in project OpenSearch by opensearch-project.

the class TaskCancellationService method setBanOnNodes.

private void setBanOnNodes(String reason, boolean waitForCompletion, CancellableTask task, Collection<DiscoveryNode> childNodes, ActionListener<Void> listener) {
    if (childNodes.isEmpty()) {
        listener.onResponse(null);
        return;
    }
    final TaskId taskId = new TaskId(localNodeId(), task.getId());
    logger.trace("cancelling child tasks of [{}] on child nodes {}", taskId, childNodes);
    GroupedActionListener<Void> groupedListener = new GroupedActionListener<>(ActionListener.map(listener, r -> null), childNodes.size());
    final BanParentTaskRequest banRequest = BanParentTaskRequest.createSetBanParentTaskRequest(taskId, reason, waitForCompletion);
    for (DiscoveryNode node : childNodes) {
        transportService.sendRequest(node, BAN_PARENT_ACTION_NAME, banRequest, new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {

            @Override
            public void handleResponse(TransportResponse.Empty response) {
                logger.trace("sent ban for tasks with the parent [{}] to the node [{}]", taskId, node);
                groupedListener.onResponse(null);
            }

            @Override
            public void handleException(TransportException exp) {
                assert ExceptionsHelper.unwrapCause(exp) instanceof OpenSearchSecurityException == false;
                logger.warn("Cannot send ban for tasks with the parent [{}] to the node [{}]", taskId, node);
                groupedListener.onFailure(exp);
            }
        });
    }
}
Also used : StreamInput(org.opensearch.common.io.stream.StreamInput) TransportRequestHandler(org.opensearch.transport.TransportRequestHandler) EmptyTransportResponseHandler(org.opensearch.transport.EmptyTransportResponseHandler) TransportChannel(org.opensearch.transport.TransportChannel) TransportRequest(org.opensearch.transport.TransportRequest) ThreadPool(org.opensearch.threadpool.ThreadPool) Collection(java.util.Collection) ExceptionsHelper(org.opensearch.ExceptionsHelper) StreamOutput(org.opensearch.common.io.stream.StreamOutput) IOException(java.io.IOException) TransportResponse(org.opensearch.transport.TransportResponse) TransportService(org.opensearch.transport.TransportService) OpenSearchSecurityException(org.opensearch.OpenSearchSecurityException) GroupedActionListener(org.opensearch.action.support.GroupedActionListener) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) List(java.util.List) Logger(org.apache.logging.log4j.Logger) LegacyESVersion(org.opensearch.LegacyESVersion) StepListener(org.opensearch.action.StepListener) ActionListener(org.opensearch.action.ActionListener) ChannelActionListener(org.opensearch.action.support.ChannelActionListener) LogManager(org.apache.logging.log4j.LogManager) TransportException(org.opensearch.transport.TransportException) OpenSearchSecurityException(org.opensearch.OpenSearchSecurityException) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) TransportResponse(org.opensearch.transport.TransportResponse) TransportException(org.opensearch.transport.TransportException) GroupedActionListener(org.opensearch.action.support.GroupedActionListener) EmptyTransportResponseHandler(org.opensearch.transport.EmptyTransportResponseHandler)

Example 3 with EmptyTransportResponseHandler

use of org.opensearch.transport.EmptyTransportResponseHandler in project OpenSearch by opensearch-project.

the class VerifyNodeRepositoryAction method verify.

public void verify(String repository, String verificationToken, final ActionListener<List<DiscoveryNode>> listener) {
    final DiscoveryNodes discoNodes = clusterService.state().nodes();
    final DiscoveryNode localNode = discoNodes.getLocalNode();
    final ObjectContainer<DiscoveryNode> masterAndDataNodes = discoNodes.getMasterAndDataNodes().values();
    final List<DiscoveryNode> nodes = new ArrayList<>();
    for (ObjectCursor<DiscoveryNode> cursor : masterAndDataNodes) {
        DiscoveryNode node = cursor.value;
        if (RepositoriesService.isDedicatedVotingOnlyNode(node.getRoles()) == false) {
            nodes.add(node);
        }
    }
    final CopyOnWriteArrayList<VerificationFailure> errors = new CopyOnWriteArrayList<>();
    final AtomicInteger counter = new AtomicInteger(nodes.size());
    for (final DiscoveryNode node : nodes) {
        if (node.equals(localNode)) {
            try {
                doVerify(repository, verificationToken, localNode);
            } catch (Exception e) {
                logger.warn(() -> new ParameterizedMessage("[{}] failed to verify repository", repository), e);
                errors.add(new VerificationFailure(node.getId(), e));
            }
            if (counter.decrementAndGet() == 0) {
                finishVerification(repository, listener, nodes, errors);
            }
        } else {
            transportService.sendRequest(node, ACTION_NAME, new VerifyNodeRepositoryRequest(repository, verificationToken), new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {

                @Override
                public void handleResponse(TransportResponse.Empty response) {
                    if (counter.decrementAndGet() == 0) {
                        finishVerification(repository, listener, nodes, errors);
                    }
                }

                @Override
                public void handleException(TransportException exp) {
                    errors.add(new VerificationFailure(node.getId(), exp));
                    if (counter.decrementAndGet() == 0) {
                        finishVerification(repository, listener, nodes, errors);
                    }
                }
            });
        }
    }
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TransportResponse(org.opensearch.transport.TransportResponse) TransportException(org.opensearch.transport.TransportException) IOException(java.io.IOException) TransportException(org.opensearch.transport.TransportException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) EmptyTransportResponseHandler(org.opensearch.transport.EmptyTransportResponseHandler) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 4 with EmptyTransportResponseHandler

use of org.opensearch.transport.EmptyTransportResponseHandler in project OpenSearch by opensearch-project.

the class TaskCancellationService method removeBanOnNodes.

private void removeBanOnNodes(CancellableTask task, Collection<DiscoveryNode> childNodes) {
    final BanParentTaskRequest request = BanParentTaskRequest.createRemoveBanParentTaskRequest(new TaskId(localNodeId(), task.getId()));
    for (DiscoveryNode node : childNodes) {
        logger.trace("Sending remove ban for tasks with the parent [{}] to the node [{}]", request.parentTaskId, node);
        transportService.sendRequest(node, BAN_PARENT_ACTION_NAME, request, new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {

            @Override
            public void handleException(TransportException exp) {
                assert ExceptionsHelper.unwrapCause(exp) instanceof OpenSearchSecurityException == false;
                logger.info("failed to remove the parent ban for task {} on node {}", request.parentTaskId, node);
            }
        });
    }
}
Also used : OpenSearchSecurityException(org.opensearch.OpenSearchSecurityException) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) EmptyTransportResponseHandler(org.opensearch.transport.EmptyTransportResponseHandler) TransportException(org.opensearch.transport.TransportException)

Aggregations

DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)4 EmptyTransportResponseHandler (org.opensearch.transport.EmptyTransportResponseHandler)4 TransportException (org.opensearch.transport.TransportException)4 IOException (java.io.IOException)3 TransportResponse (org.opensearch.transport.TransportResponse)3 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)2 OpenSearchSecurityException (org.opensearch.OpenSearchSecurityException)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 ExceptionsHelper (org.opensearch.ExceptionsHelper)1 LegacyESVersion (org.opensearch.LegacyESVersion)1 OpenSearchException (org.opensearch.OpenSearchException)1 ActionListener (org.opensearch.action.ActionListener)1 StepListener (org.opensearch.action.StepListener)1 ChannelActionListener (org.opensearch.action.support.ChannelActionListener)1