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/22 02:28:19 UTC

[samza] branch master updated: SAMZA-2111: Refactoring ApplicationRunnerMain code

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 d5d0956  SAMZA-2111: Refactoring ApplicationRunnerMain code
d5d0956 is described below

commit d5d0956b5ea861cf59e5733bc2851995495a1879
Author: Aditya Toomula <at...@linkedin.com>
AuthorDate: Thu Feb 21 18:28:09 2019 -0800

    SAMZA-2111: Refactoring ApplicationRunnerMain code
    
    Adding invokeApplicationRunner public static API in preparation for fast sql where this API will be called directly within the same process.
    
    Author: Aditya Toomula <at...@linkedin.com>
    
    Reviewers: prateekm
    
    Closes #927 from atoomula/runner and squashes the following commits:
    
    47c33884 [Aditya Toomula] Refactoring ApplicationRunnerMain code in preparation for fast samza sql.
    c7c525a9 [Aditya Toomula] Refactoring ApplicationRunnerMain code in preparation for fast samza sql.
    4b5fb24d [Aditya Toomula] Refactoring ApplicationRunnerMain code in preparation for fast samza sql.
    39a8626c [Aditya Toomula] Refactoring ApplicationRunnerMain code in preparation for fast samza sql.
---
 .../samza/runtime/ApplicationRunnerMain.java       | 22 +----------
 ...nRunnerMain.java => ApplicationRunnerUtil.java} | 43 ++++++++--------------
 2 files changed, 18 insertions(+), 47 deletions(-)

diff --git a/samza-core/src/main/java/org/apache/samza/runtime/ApplicationRunnerMain.java b/samza-core/src/main/java/org/apache/samza/runtime/ApplicationRunnerMain.java
index fccde1c..2ca2945 100644
--- a/samza-core/src/main/java/org/apache/samza/runtime/ApplicationRunnerMain.java
+++ b/samza-core/src/main/java/org/apache/samza/runtime/ApplicationRunnerMain.java
@@ -21,10 +21,9 @@ package org.apache.samza.runtime;
 
 import joptsimple.OptionSet;
 import joptsimple.OptionSpec;
-import org.apache.samza.application.ApplicationUtil;
 import org.apache.samza.config.Config;
 import org.apache.samza.util.CommandLine;
-import org.apache.samza.util.Util;
+
 
 /**
  * This class contains the main() method used by run-app.sh.
@@ -50,24 +49,7 @@ public class ApplicationRunnerMain {
     ApplicationRunnerCommandLine cmdLine = new ApplicationRunnerCommandLine();
     OptionSet options = cmdLine.parser().parse(args);
     Config orgConfig = cmdLine.loadConfig(options);
-    Config config = Util.rewriteConfig(orgConfig);
     ApplicationRunnerOperation op = cmdLine.getOperation(options);
-
-    ApplicationRunner appRunner =
-        ApplicationRunners.getApplicationRunner(ApplicationUtil.fromConfig(config), config);
-
-    switch (op) {
-      case RUN:
-        appRunner.run(null);
-        break;
-      case KILL:
-        appRunner.kill();
-        break;
-      case STATUS:
-        System.out.println(appRunner.status());
-        break;
-      default:
-        throw new IllegalArgumentException("Unrecognized operation: " + op);
-    }
+    ApplicationRunnerUtil.invoke(orgConfig, op);
   }
 }
diff --git a/samza-core/src/main/java/org/apache/samza/runtime/ApplicationRunnerMain.java b/samza-core/src/main/java/org/apache/samza/runtime/ApplicationRunnerUtil.java
similarity index 54%
copy from samza-core/src/main/java/org/apache/samza/runtime/ApplicationRunnerMain.java
copy to samza-core/src/main/java/org/apache/samza/runtime/ApplicationRunnerUtil.java
index fccde1c..28dfeb1 100644
--- a/samza-core/src/main/java/org/apache/samza/runtime/ApplicationRunnerMain.java
+++ b/samza-core/src/main/java/org/apache/samza/runtime/ApplicationRunnerUtil.java
@@ -19,39 +19,27 @@
 
 package org.apache.samza.runtime;
 
-import joptsimple.OptionSet;
-import joptsimple.OptionSpec;
 import org.apache.samza.application.ApplicationUtil;
 import org.apache.samza.config.Config;
-import org.apache.samza.util.CommandLine;
 import org.apache.samza.util.Util;
 
+
 /**
- * This class contains the main() method used by run-app.sh.
- * It creates the {@link ApplicationRunner} based on the config, and then run the application.
+ * Util class to create {@link ApplicationRunner} from the configuration and run the application
  */
-public class ApplicationRunnerMain {
-
-  public static class ApplicationRunnerCommandLine extends CommandLine {
-    public OptionSpec operationOpt =
-        parser().accepts("operation", "The operation to perform; run, status, kill.")
-            .withRequiredArg()
-            .ofType(String.class)
-            .describedAs("operation=run")
-            .defaultsTo("run");
-
-    public ApplicationRunnerOperation getOperation(OptionSet options) {
-      String rawOp = options.valueOf(operationOpt).toString();
-      return ApplicationRunnerOperation.fromString(rawOp);
-    }
-  }
-
-  public static void main(String[] args) throws Exception {
-    ApplicationRunnerCommandLine cmdLine = new ApplicationRunnerCommandLine();
-    OptionSet options = cmdLine.parser().parse(args);
-    Config orgConfig = cmdLine.loadConfig(options);
-    Config config = Util.rewriteConfig(orgConfig);
-    ApplicationRunnerOperation op = cmdLine.getOperation(options);
+public class ApplicationRunnerUtil {
+
+  /**
+   * This method rewrites the passed in config, creates the {@link ApplicationRunner} from the rewritten config and
+   * invokes the appropriate operation on the runner based on the specified {@link ApplicationRunnerOperation}.
+   * It returns the runner so that the caller could get the status of application on STATUS op.
+   *
+   * @param originalConfig the original configuration of the application
+   * @param op the {@link ApplicationRunnerOperation} that needs to be performed on the Application.
+   * @return the {@link ApplicationRunner} object.
+   */
+  public static ApplicationRunner invoke(Config originalConfig, ApplicationRunnerOperation op) {
+    Config config = Util.rewriteConfig(originalConfig);
 
     ApplicationRunner appRunner =
         ApplicationRunners.getApplicationRunner(ApplicationUtil.fromConfig(config), config);
@@ -69,5 +57,6 @@ public class ApplicationRunnerMain {
       default:
         throw new IllegalArgumentException("Unrecognized operation: " + op);
     }
+    return appRunner;
   }
 }