sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject git commit: SQOOP-723: Add possibility to have synchronous submissions in Sqoop 2
Date Sat, 13 Apr 2013 19:45:20 GMT
Updated Branches:
  refs/heads/sqoop2 135f00cf1 -> 6ceb22497


SQOOP-723: Add possibility to have synchronous submissions in Sqoop 2

(Abraham Elmahrek via Jarek Jarcec Cecho)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/6ceb2249
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/6ceb2249
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/6ceb2249

Branch: refs/heads/sqoop2
Commit: 6ceb22497c0161880a37a7bee51f1de6093e6dcc
Parents: 135f00c
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Sat Apr 13 12:44:50 2013 -0700
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Sat Apr 13 12:44:50 2013 -0700

----------------------------------------------------------------------
 .../org/apache/sqoop/client/core/Constants.java    |    6 +++
 .../client/shell/SubmissionStartFunction.java      |   32 +++++++++++++++
 .../src/main/resources/client-resource.properties  |    4 +-
 3 files changed, 41 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/6ceb2249/client/src/main/java/org/apache/sqoop/client/core/Constants.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/core/Constants.java b/client/src/main/java/org/apache/sqoop/client/core/Constants.java
index 027173c..c6c6d8e 100644
--- a/client/src/main/java/org/apache/sqoop/client/core/Constants.java
+++ b/client/src/main/java/org/apache/sqoop/client/core/Constants.java
@@ -43,6 +43,8 @@ public class Constants {
   public static final String OPT_SERVER = "server";
   public static final String OPT_CLIENT = "client";
   public static final String OPT_PROTOCOL = "protocol";
+  public static final String OPT_SYNCHRONOUS = "synchronous";
+  public static final String OPT_POLL_TIMEOUT = "poll-timeout";
 
   public static final char OPT_XID_CHAR = 'x';
   public static final char OPT_ALL_CHAR = 'a';
@@ -295,6 +297,10 @@ public class Constants {
 
   public static final String RES_SUBMISSION_USAGE =
       "submission.usage";
+  public static final String RES_PROMPT_SYNCHRONOUS =
+      "submission.prompt_synchronous";
+  public static final String RES_PROMPT_POLL_TIMEOUT =
+      "submission.prompt_poll_timeout";
 
   public static final String RES_UPDATE_USAGE =
       "update.usage";

http://git-wip-us.apache.org/repos/asf/sqoop/blob/6ceb2249/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStartFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStartFunction.java
b/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStartFunction.java
index cefe0a2..f68ac11 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStartFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/SubmissionStartFunction.java
@@ -19,6 +19,7 @@ package org.apache.sqoop.client.shell;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.OptionBuilder;
+import org.apache.log4j.Logger;
 import org.apache.sqoop.client.core.Constants;
 import org.apache.sqoop.client.utils.SubmissionDisplayer;
 import org.apache.sqoop.model.MSubmission;
@@ -29,6 +30,9 @@ import static org.apache.sqoop.client.shell.ShellEnvironment.*;
  *
  */
 public class SubmissionStartFunction extends SqoopFunction {
+  public static final Logger LOG = Logger.getLogger(SubmissionStartFunction.class);
+  public static final long POLL_TIMEOUT = 10000;
+
   @SuppressWarnings("static-access")
   public SubmissionStartFunction() {
     this.addOption(OptionBuilder
@@ -36,6 +40,15 @@ public class SubmissionStartFunction extends SqoopFunction {
       .withLongOpt(Constants.OPT_JID)
       .hasArg()
       .create(Constants.OPT_JID_CHAR));
+    this.addOption(OptionBuilder
+      .withDescription(resourceString(Constants.RES_PROMPT_SYNCHRONOUS))
+      .withLongOpt(Constants.OPT_SYNCHRONOUS)
+      .create());
+    this.addOption(OptionBuilder
+      .withDescription(resourceString(Constants.RES_PROMPT_POLL_TIMEOUT))
+      .withLongOpt(Constants.OPT_POLL_TIMEOUT)
+      .hasArg()
+      .create());
   }
 
   public Object executeFunction(CommandLine line) {
@@ -46,6 +59,25 @@ public class SubmissionStartFunction extends SqoopFunction {
 
     MSubmission submission = client.startSubmission(getLong(line, Constants.OPT_JID));
     SubmissionDisplayer.display(submission);
+
+    // Poll until finished
+    if (line.hasOption(Constants.OPT_SYNCHRONOUS)) {
+      long pollTimeout = POLL_TIMEOUT;
+      if (line.hasOption(Constants.OPT_POLL_TIMEOUT)) {
+        pollTimeout = Long.getLong(line.getOptionValue(Constants.OPT_POLL_TIMEOUT)).longValue();
+      }
+      while (submission.getStatus().isRunning()) {
+        submission = client.getSubmissionStatus(getLong(line, Constants.OPT_JID));
+        SubmissionDisplayer.display(submission);
+
+        // Wait some time
+        try {
+          Thread.sleep(pollTimeout);
+        } catch (InterruptedException e) {
+          LOG.error("Could not sleep");
+        }
+      }
+    }
     return null;
   }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/6ceb2249/client/src/main/resources/client-resource.properties
----------------------------------------------------------------------
diff --git a/client/src/main/resources/client-resource.properties b/client/src/main/resources/client-resource.properties
index 374ed4e..c7a4cb3 100644
--- a/client/src/main/resources/client-resource.properties
+++ b/client/src/main/resources/client-resource.properties
@@ -164,6 +164,8 @@ sqoop.prompt_shell_loadrc = Loading resource file {0}
 sqoop.prompt_shell_loadedrc = Resource file loaded.
 
 submission.usage = Usage: submission {0}
+submission.prompt_synchronous = Wait for submission to finish
+submission.prompt_poll_timeout = How often the client should communicate with the server
in milliseconds (Default: 10000)
 
 # Various Table headers
 table.header.id = Id
@@ -190,4 +192,4 @@ formdisplayer.possible_values = Possible values
 formdisplayer.unsupported_datatype = Unsupported data type
 formdisplayer.input_sensitive = This input is sensitive
 
-formdisplayer.warning_message = There were warnings while create or update, but saved successfully.
\ No newline at end of file
+formdisplayer.warning_message = There were warnings while create or update, but saved successfully.


Mime
View raw message