コード例 #1
0
  public Response execute(Request request) {
    Response response = null;

    boolean newNode;
    do {
      SimpleRequest routedRequest =
          new SimpleRequest(
              request.method(), null, request.path(), request.params(), request.body());

      newNode = false;
      try {
        response = currentTransport.execute(routedRequest);
        ByteSequence body = routedRequest.body();
        if (body != null) {
          stats.bytesSent += body.length();
        }
      } catch (Exception ex) {
        // configuration error - including SSL/PKI - bail out
        if (ex instanceof EsHadoopIllegalStateException) {
          throw (EsHadoopException) ex;
        }
        // issues with the SSL handshake, bail out instead of retry, for security reasons
        if (ex instanceof javax.net.ssl.SSLException) {
          throw new EsHadoopTransportException(ex);
        }
        // check for fatal, non-recoverable network exceptions

        if (ex instanceof BindException
            || ex instanceof NoRouteToHostException
            || ex instanceof UnknownHostException) {
          throw new EsHadoopTransportException(ex);
        }

        if (log.isTraceEnabled()) {
          log.trace(
              String.format(
                  "Caught exception while performing request [%s][%s] - falling back to the next node in line...",
                  currentNode, request.path()),
              ex);
        }

        String failed = currentNode;

        failedNodes.put(failed, ex);

        newNode = selectNextNode();

        log.error(
            String.format(
                "Node [%s] failed (%s); "
                    + (newNode
                        ? "selected next node [" + currentNode + "]"
                        : "no other nodes left - aborting..."),
                failed,
                ex.getMessage()));

        if (!newNode) {
          throw new EsHadoopNoNodesLeftException(failedNodes);
        }
      }
    } while (newNode);

    return response;
  }
コード例 #2
0
 @Override
 public byte[] getRequestBody(SimpleRequest request) {
   return request.getBody();
 }
コード例 #3
0
 @Override
 public String getRequestUri(SimpleRequest request) {
   return request.getUri();
 }
コード例 #4
0
 @Override
 public List<HeaderPair> getRequestHeaders(SimpleRequest request) {
   return request.getHeaders();
 }
コード例 #5
0
 @Override
 public String getRequestMethod(SimpleRequest request) {
   return request.getMethod();
 }