asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mb...@apache.org
Subject asterixdb git commit: ASTERIXDB-1687 - Configure Timeout On HTTP Connection
Date Thu, 13 Oct 2016 17:50:18 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master 71bd0b04c -> 791cc5d75


ASTERIXDB-1687 - Configure Timeout On HTTP Connection

Fixes ASTERIXDB-1687 - asterixhelper get_cluster_state can hang forever,
by configuring a timeout on connect and read for HTTP calls, in the
event the CC is in a bad state and cannot answer requests

Change-Id: Ice9606acaec8f27b56d1d8ed947cc1588074ff2f
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1276
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/791cc5d7
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/791cc5d7
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/791cc5d7

Branch: refs/heads/master
Commit: 791cc5d751200d9941efeaf8c5b81e3b79d82b35
Parents: 71bd0b0
Author: Michael Blow <mblow@apache.org>
Authored: Thu Oct 13 11:24:42 2016 -0400
Committer: Michael Blow <mblow@apache.org>
Committed: Thu Oct 13 10:49:51 2016 -0700

----------------------------------------------------------------------
 .../main/java/org/apache/asterix/clienthelper/Args.java   |  2 +-
 .../asterix/clienthelper/commands/RemoteCommand.java      |  8 ++++++++
 .../clienthelper/commands/WaitForClusterCommand.java      | 10 ++++++----
 3 files changed, 15 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/791cc5d7/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/Args.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/Args.java
b/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/Args.java
index e767f28..ceb873d 100644
--- a/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/Args.java
+++ b/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/Args.java
@@ -45,7 +45,7 @@ public class Args {
 
 
     @Option(name = "-timeout", metaVar = "<secs>", usage = "Timeout for wait commands
in seconds")
-    protected int timeoutSecs = -1;
+    protected int timeoutSecs = 0;
 
     @Option(name = "-quiet", aliases = "-q", usage = "Suppress all normal output")
     protected boolean quiet;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/791cc5d7/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/RemoteCommand.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/RemoteCommand.java
b/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/RemoteCommand.java
index 031a721..e7b6be3 100644
--- a/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/RemoteCommand.java
+++ b/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/RemoteCommand.java
@@ -23,10 +23,14 @@ import java.io.InputStream;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.asterix.clienthelper.Args;
 
 public abstract class RemoteCommand extends ClientCommand {
+
+    public static final int MAX_CONNECTION_TIMEOUT_SECS = 60;
+
     protected enum Method {
         GET,
         POST
@@ -64,6 +68,10 @@ public abstract class RemoteCommand extends ClientCommand {
     protected HttpURLConnection openConnection(String path, Method method) throws IOException
{
         URL url = new URL("http://" + hostPort + "/" + path);
         HttpURLConnection conn = (HttpURLConnection)url.openConnection();
+        final int timeoutMillis =
+                (int) TimeUnit.SECONDS.toMillis(Math.max(MAX_CONNECTION_TIMEOUT_SECS, args.getTimeoutSecs()));
+        conn.setConnectTimeout(timeoutMillis);
+        conn.setReadTimeout(timeoutMillis);
         conn.setRequestMethod(method.name());
         return conn;
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/791cc5d7/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/WaitForClusterCommand.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/WaitForClusterCommand.java
b/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/WaitForClusterCommand.java
index 390ce7b..b0b4c6f 100644
--- a/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/WaitForClusterCommand.java
+++ b/asterixdb/asterix-client-helper/src/main/java/org/apache/asterix/clienthelper/commands/WaitForClusterCommand.java
@@ -21,6 +21,7 @@ package org.apache.asterix.clienthelper.commands;
 import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.nio.charset.StandardCharsets;
+import java.util.concurrent.TimeUnit;
 
 import javax.servlet.http.HttpServletResponse;
 
@@ -38,17 +39,18 @@ public class WaitForClusterCommand extends RemoteCommand {
     @Override
     @SuppressWarnings("squid:S2142") // interrupted exception
     public int execute() throws IOException {
+        final int timeoutSecs = args.getTimeoutSecs();
         log("Waiting "
-                + (args.getTimeoutSecs() > 0 ? "up to " + args.getTimeoutSecs() + " seconds
" : "")
+                + (timeoutSecs > 0 ? "up to " + timeoutSecs + " seconds " : "")
                 + "for cluster " + hostPort + " to be available.");
 
         long startTime = System.currentTimeMillis();
+        long timeoutMillis = TimeUnit.SECONDS.toMillis(timeoutSecs);
         boolean first = true;
         String lastState = null;
         while (true) {
             if (!first) {
-                if (args.getTimeoutSecs() >= 0
-                        && (startTime + (args.getTimeoutSecs() * 1000) < System.currentTimeMillis()))
{
+                if (timeoutMillis > 0 && (startTime + timeoutMillis < System.currentTimeMillis()))
{
                     break;
                 }
                 try {
@@ -75,7 +77,7 @@ public class WaitForClusterCommand extends RemoteCommand {
                 // ignore exception, try again
             }
         }
-        log("Cluster " + hostPort + " was not available before timeout of " + args.getTimeoutSecs()
+        log("Cluster " + hostPort + " was not available before timeout of " + timeoutSecs
                 + " seconds was exhausted" + (lastState != null ? " (state: " + lastState
+ ")" : "")
                 + "; check logs for more information");
         return 1;


Mime
View raw message