Skip to content

Commit

Permalink
Nicer failure message when node should not connect to another in node…
Browse files Browse the repository at this point in the history
…s API

There are cases where nodes should not connect to another node. For example, client nodes do not connect to other client nodes. When executing a nodes level API, we should have a nicer failure indicating that, and not log it by default, as its not a real failure
  • Loading branch information
kimchy committed Mar 6, 2014
1 parent f1248e5 commit 1ba84d2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ public void run() {
} else {
if (node == null) {
onFailure(idx, nodeId, new NoSuchNodeException(nodeId));
} else if (!clusterService.localNode().shouldConnectTo(node)) {
onFailure(idx, nodeId, new NodeShouldNotConnectException(clusterService.localNode(), node));
} else {
NodeRequest nodeRequest = newNodeRequest(nodeId, request);
transportService.sendRequest(node, transportNodeAction, nodeRequest, transportRequestOptions, new BaseTransportResponseHandler<NodeResponse>() {
Expand Down Expand Up @@ -202,7 +204,7 @@ private void onOperation(int idx, NodeResponse nodeResponse) {
}

private void onFailure(int idx, String nodeId, Throwable t) {
if (logger.isDebugEnabled()) {
if (logger.isDebugEnabled() && !(t instanceof NodeShouldNotConnectException)) {
logger.debug("failed to execute on node [{}]", t, nodeId);
}
if (accumulateExceptions()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.transport;

import org.elasticsearch.cluster.node.DiscoveryNode;

/**
*/
public class NodeShouldNotConnectException extends NodeNotConnectedException {

public NodeShouldNotConnectException(DiscoveryNode fromNode, DiscoveryNode node) {
super(node, "node should not connect from [" + fromNode + "]");
}
}

0 comments on commit 1ba84d2

Please sign in to comment.