You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@samza.apache.org by at...@apache.org on 2019/02/05 00:14:49 UTC

[samza] branch master updated: SAMZA-2096: Support getVersion in Sql Shell

This is an automated email from the ASF dual-hosted git repository.

atoomula pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/samza.git


The following commit(s) were added to refs/heads/master by this push:
     new edef5a2  SAMZA-2096: Support getVersion in Sql Shell
edef5a2 is described below

commit edef5a2038b1c377f495fe4e4f4b6a1257bb18e5
Author: Weiqing Yang <ya...@gmail.com>
AuthorDate: Mon Feb 4 16:14:37 2019 -0800

    SAMZA-2096: Support getVersion in Sql Shell
    
    ## What changes were proposed in this pull request?
    1. Print version information when Shell is just initialized.
    2. Support "VERSION" command.
    
    ## How was this patch tested?
    Test in Shell.
    
    Author: Weiqing Yang <ya...@gmail.com>
    
    Reviewers: shenodaguirguis,atoomula
    
    Closes #904 from weiqingy/shellVersion
---
 build.gradle                                       |  6 ++++
 .../samza/sql/client/cli/CliCommandType.java       |  1 +
 .../apache/samza/sql/client/cli/CliConstants.java  |  5 +---
 .../org/apache/samza/sql/client/cli/CliShell.java  | 18 +++++++++++
 .../samza/sql/client/impl/SamzaExecutor.java       |  5 ++++
 .../samza/sql/client/interfaces/SqlExecutor.java   | 35 +++++++++++++---------
 .../samza/sql/client/interfaces/SqlFunction.java   |  8 ++---
 7 files changed, 56 insertions(+), 22 deletions(-)

diff --git a/build.gradle b/build.gradle
index 3e8d08a..53b01dc 100644
--- a/build.gradle
+++ b/build.gradle
@@ -346,6 +346,12 @@ project(":samza-sql_$scalaVersion") {
 project(":samza-sql-shell_$scalaVersion") {
   apply plugin: 'java'
 
+  jar {
+    manifest {
+      attributes("Implementation-Version": "$version")
+    }
+  }
+
   dependencies {
     compile project(":samza-sql_$scalaVersion")
     compile project(":samza-tools_$scalaVersion")
diff --git a/samza-sql-shell/src/main/java/org/apache/samza/sql/client/cli/CliCommandType.java b/samza-sql-shell/src/main/java/org/apache/samza/sql/client/cli/CliCommandType.java
index 0cd170e..f153cef 100755
--- a/samza-sql-shell/src/main/java/org/apache/samza/sql/client/cli/CliCommandType.java
+++ b/samza-sql-shell/src/main/java/org/apache/samza/sql/client/cli/CliCommandType.java
@@ -42,6 +42,7 @@ enum CliCommandType {
   CLEAR("CLEAR", "\tClears the screen.", "CLEAR"),
   EXIT("EXIT", "\tExits the shell.", "Exit"),
   QUIT("QUIT", "\tQuits the shell.", "QUIT"),
+  VERSION("VERSION", "\tShows version information", "VERSION"),
 
   INVALID_COMMAND("INVALID_COMMAND", "INVALID_COMMAND", "INVALID_COMMAND");
 
diff --git a/samza-sql-shell/src/main/java/org/apache/samza/sql/client/cli/CliConstants.java b/samza-sql-shell/src/main/java/org/apache/samza/sql/client/cli/CliConstants.java
index e417099..b20e614 100755
--- a/samza-sql-shell/src/main/java/org/apache/samza/sql/client/cli/CliConstants.java
+++ b/samza-sql-shell/src/main/java/org/apache/samza/sql/client/cli/CliConstants.java
@@ -34,9 +34,6 @@ class CliConstants {
   public static final String CONFIG_EXECUTOR = "shell.executor";
   public static final String DEFAULT_EXECUTOR_CLASS = "org.apache.samza.sql.client.impl.SamzaExecutor";
 
-  public static final String VERSION = "0.0.1";
-
-
   public static final String WELCOME_MESSAGE;
   static {
         WELCOME_MESSAGE =
@@ -51,7 +48,7 @@ class CliConstants {
 "   \\  \\:\\/:/        /  /:/        /  /:/     \\  \\:\\           /  /:/ \n"+
 "    \\  \\::/        /__/:/        /__/:/       \\  \\:\\         /__/:/ \n"+
 "     \\__\\/         \\__\\/         \\__\\/         \\__\\/         \\__\\/  \n\n"+
-"Welcome to Samza SQL shell (V" + VERSION + "). Enter HELP for all commands.\n\n";
+"Welcome to Samza SQL shell. Enter HELP for all commands.\n";
   }
 
   public static final char SPACE = '\u0020';
diff --git a/samza-sql-shell/src/main/java/org/apache/samza/sql/client/cli/CliShell.java b/samza-sql-shell/src/main/java/org/apache/samza/sql/client/cli/CliShell.java
index 8bdbf7d..98c6e1d 100755
--- a/samza-sql-shell/src/main/java/org/apache/samza/sql/client/cli/CliShell.java
+++ b/samza-sql-shell/src/main/java/org/apache/samza/sql/client/cli/CliShell.java
@@ -119,9 +119,11 @@ class CliShell {
     // screen and we need it to show streaming results. Clear the screen instead.
     clearScreen();
     writer.write(CliConstants.WELCOME_MESSAGE);
+    printVersion();
     if(!CliUtil.isNullOrEmpty(message)) {
       writer.println(message);
     }
+    writer.println();
 
     try {
       // Check if jna.jar exists in class path
@@ -205,6 +207,10 @@ class CliShell {
               commandStop(command);
               break;
 
+            case VERSION:
+              commandVersion(command);
+              break;
+
             case INVALID_COMMAND:
               printHelpMessage();
               break;
@@ -242,6 +248,18 @@ class CliShell {
     }
   }
 
+  private void commandVersion(CliCommand command) {
+    printVersion();
+  }
+
+  private void printVersion() {
+    String version = String.format("Shell version %s, Executor is %s, version %s",
+            this.getClass().getPackage().getImplementationVersion(),
+            executor.getClass().getName(),
+            executor.getVersion());
+    writer.println(version);
+  }
+
   private void commandClear() {
     clearScreen();
   }
diff --git a/samza-sql-shell/src/main/java/org/apache/samza/sql/client/impl/SamzaExecutor.java b/samza-sql-shell/src/main/java/org/apache/samza/sql/client/impl/SamzaExecutor.java
index 73f80e8..0434815 100755
--- a/samza-sql-shell/src/main/java/org/apache/samza/sql/client/impl/SamzaExecutor.java
+++ b/samza-sql-shell/src/main/java/org/apache/samza/sql/client/impl/SamzaExecutor.java
@@ -298,6 +298,11 @@ public class SamzaExecutor implements SqlExecutor {
     return udfs;
   }
 
+  @Override
+  public String getVersion() {
+    return this.getClass().getPackage().getImplementationVersion();
+  }
+
   static void saveOutputMessage(OutgoingMessageEnvelope messageEnvelope) {
     outputData.add(messageEnvelope);
   }
diff --git a/samza-sql-shell/src/main/java/org/apache/samza/sql/client/interfaces/SqlExecutor.java b/samza-sql-shell/src/main/java/org/apache/samza/sql/client/interfaces/SqlExecutor.java
index 37c1cca..fb7d109 100644
--- a/samza-sql-shell/src/main/java/org/apache/samza/sql/client/interfaces/SqlExecutor.java
+++ b/samza-sql-shell/src/main/java/org/apache/samza/sql/client/interfaces/SqlExecutor.java
@@ -56,7 +56,7 @@ public interface SqlExecutor {
    * @param context The ExecutionContext at the time of the call.
    * @throws ExecutorException if the Executor encounters an error.
    */
-  public void start(ExecutionContext context) throws ExecutorException;
+  void start(ExecutionContext context) throws ExecutorException;
 
   /**
    * Indicates no further calls will be made thus it's safe for the executor to clean up.
@@ -64,20 +64,20 @@ public interface SqlExecutor {
    * @param context The ExecutionContext at the time of the call.
    * @throws ExecutorException if the Executor encounters an error.
    */
-  public void stop(ExecutionContext context) throws ExecutorException;
+  void stop(ExecutionContext context) throws ExecutorException;
 
   /**
    *
    * @return An EnvironmentVariableHandler that handles executor specific environment variables
    */
-  public EnvironmentVariableHandler getEnvironmentVariableHandler();
+  EnvironmentVariableHandler getEnvironmentVariableHandler();
 
   /**
    * @param context The ExecutionContext at the time of the call.
    * @return A list of table names. Could be empty.
    * @throws ExecutorException if the Executor encounters an error.
    */
-  public List<String> listTables(ExecutionContext context) throws ExecutorException;
+  List<String> listTables(ExecutionContext context) throws ExecutorException;
 
   /**
    * @param context   The ExecutionContext at the time of the call.
@@ -85,7 +85,7 @@ public interface SqlExecutor {
    * @return Schema of the table.
    * @throws ExecutorException if the Executor encounters an error.
    */
-  public SqlSchema getTableSchema(ExecutionContext context, String tableName) throws ExecutorException;
+  SqlSchema getTableSchema(ExecutionContext context, String tableName) throws ExecutorException;
 
   /**
    * @param context   The ExecutionContext at the time of the call.
@@ -93,14 +93,14 @@ public interface SqlExecutor {
    * @return The query result.
    * @throws ExecutorException if the Executor encounters an error.
    */
-  public QueryResult executeQuery(ExecutionContext context, String statement) throws ExecutorException;
+  QueryResult executeQuery(ExecutionContext context, String statement) throws ExecutorException;
 
 
   /**
    * @return how many rows available for reading.
    * @throws ExecutorException if the Executor encounters an error.
    */
-  public int getRowCount() throws ExecutorException;
+  int getRowCount() throws ExecutorException;
 
   /**
    * Row starts at 0. Executor shall keep the data retrieved.
@@ -112,7 +112,7 @@ public interface SqlExecutor {
    * @return A list of row data represented by a String array.
    * @throws ExecutorException if the Executor encounters an error.
    */
-  public List<String[]> retrieveQueryResult(ExecutionContext context, int startRow, int endRow) throws ExecutorException;
+  List<String[]> retrieveQueryResult(ExecutionContext context, int startRow, int endRow) throws ExecutorException;
 
 
   /**
@@ -125,7 +125,7 @@ public interface SqlExecutor {
    * @return available data between startRow and endRow (both are inclusive)
    * @throws ExecutorException if the Executor encounters an error.
    */
-  public List<String[]> consumeQueryResult(ExecutionContext context, int startRow, int endRow) throws ExecutorException;
+  List<String[]> consumeQueryResult(ExecutionContext context, int startRow, int endRow) throws ExecutorException;
 
   /**
    * Executes all the NON-QUERY statements in the sqlFile.
@@ -136,7 +136,7 @@ public interface SqlExecutor {
    * @return Execution result.
    * @throws ExecutorException if the Executor encounters an error.
    */
-  public NonQueryResult executeNonQuery(ExecutionContext context, File file) throws ExecutorException;
+  NonQueryResult executeNonQuery(ExecutionContext context, File file) throws ExecutorException;
 
   /**
    * @param context    The ExecutionContext at the time of the call.
@@ -144,14 +144,14 @@ public interface SqlExecutor {
    * @return Execution result.
    * @throws ExecutorException if the Executor encounters an error.
    */
-  public NonQueryResult executeNonQuery(ExecutionContext context, List<String> statements) throws ExecutorException;
+  NonQueryResult executeNonQuery(ExecutionContext context, List<String> statements) throws ExecutorException;
 
   /**
    * @param context The ExecutionContext at the time of the call.
    * @param exeId   Execution ID.
    * @throws ExecutorException if the Executor encounters an error.
    */
-  public void stopExecution(ExecutionContext context, int exeId) throws ExecutorException;
+  void stopExecution(ExecutionContext context, int exeId) throws ExecutorException;
 
 
   /**
@@ -161,14 +161,14 @@ public interface SqlExecutor {
    * @param exeId   Execution ID.
    * @throws ExecutorException if the Executor encounters an error.
    */
-  public void removeExecution(ExecutionContext context, int exeId) throws ExecutorException;
+  void removeExecution(ExecutionContext context, int exeId) throws ExecutorException;
 
   /**
    * @param execId Execution ID.
    * @return ExecutionStatus.
    * @throws ExecutorException if the Executor encounters an error.
    */
-  public ExecutionStatus queryExecutionStatus(int execId) throws ExecutorException;
+  ExecutionStatus queryExecutionStatus(int execId) throws ExecutorException;
 
   /**
    * @param context The ExecutionContext at the time of the call.
@@ -176,4 +176,11 @@ public interface SqlExecutor {
    * @throws ExecutorException if the Executor encounters an error.
    */
   List<SqlFunction> listFunctions(ExecutionContext context) throws ExecutorException;
+
+  /**
+   * Gets the version of this executor.
+   * @return A String representing the version of the executor. This function does NOT throw an
+   * ExecutorException as the caller has nothing to do to "recover" if the function fails.
+   */
+  String getVersion();
 }
diff --git a/samza-sql-shell/src/main/java/org/apache/samza/sql/client/interfaces/SqlFunction.java b/samza-sql-shell/src/main/java/org/apache/samza/sql/client/interfaces/SqlFunction.java
index 3ac602c..5d28ce6 100644
--- a/samza-sql-shell/src/main/java/org/apache/samza/sql/client/interfaces/SqlFunction.java
+++ b/samza-sql-shell/src/main/java/org/apache/samza/sql/client/interfaces/SqlFunction.java
@@ -29,25 +29,25 @@ public interface SqlFunction {
    * Gets the name of the function.
    * @return name of the function
    */
-  public String getName();
+  String getName();
 
   /**
    * Gets the description of the function.
    * @return description of the function.
    */
-  public String getDescription();
+  String getDescription();
 
   /**
    * Gets the argument types of the function as a List.
    * @return A list containing the type names of the arguments.
    */
-  public List<String> getArgumentTypes();
+  List<String> getArgumentTypes();
 
   /**
    * Gets the return type of the function.
    * @return return type name
    */
-  public String getReturnType();
+  String getReturnType();
 
   /**
    * Don't forget to implement toString()