apex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vro...@apache.org
Subject [11/36] incubator-apex-core git commit: APEX-199 #resolve Added platform version check when launching app package
Date Sun, 25 Oct 2015 19:37:54 GMT
APEX-199 #resolve Added platform version check when launching app package


Project: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/commit/3e361866
Tree: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/tree/3e361866
Diff: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/diff/3e361866

Branch: refs/heads/feature-module
Commit: 3e3618668d672252a7b884fd80fb9da8c90378b9
Parents: 722fd67
Author: David Yan <david@datatorrent.com>
Authored: Thu Oct 15 18:50:27 2015 -0700
Committer: David Yan <david@datatorrent.com>
Committed: Thu Oct 15 18:50:27 2015 -0700

----------------------------------------------------------------------
 .../java/com/datatorrent/stram/cli/DTCli.java    | 18 ++++++++++++++++--
 .../com/datatorrent/stram/util/VersionInfo.java  | 19 +++++++++++++++++++
 .../datatorrent/stram/util/VersionInfoTest.java  | 12 ++++++++++++
 3 files changed, 47 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-apex-core/blob/3e361866/engine/src/main/java/com/datatorrent/stram/cli/DTCli.java
----------------------------------------------------------------------
diff --git a/engine/src/main/java/com/datatorrent/stram/cli/DTCli.java b/engine/src/main/java/com/datatorrent/stram/cli/DTCli.java
index e126f73..89f92f0 100644
--- a/engine/src/main/java/com/datatorrent/stram/cli/DTCli.java
+++ b/engine/src/main/java/com/datatorrent/stram/cli/DTCli.java
@@ -1888,7 +1888,10 @@ public class DTCli
 
           if (ap != null) {
             try {
-              checkCompatible(ap, cp);
+              if (!commandLineInfo.force) {
+                checkPlatformCompatible(ap);
+                checkConfigPackageCompatible(ap, cp);
+              }
               launchAppPackage(ap, cp, commandLineInfo, reader);
               return;
             } finally {
@@ -3426,7 +3429,7 @@ public class DTCli
 
   }
 
-  private void checkCompatible(AppPackage ap, ConfigPackage cp)
+  private void checkConfigPackageCompatible(AppPackage ap, ConfigPackage cp)
   {
     if (cp == null) {
       return;
@@ -3445,6 +3448,14 @@ public class DTCli
     }
   }
 
+  private void checkPlatformCompatible(AppPackage ap)
+  {
+    String apVersion = ap.getDtEngineVersion();
+    if (!VersionInfo.isCompatible(apVersion, VersionInfo.getVersion())) {
+      throw new CliException("This App Package is compiled with Apache Apex Core API version
" + apVersion + ", which is incompatible with this Apex Core version " + VersionInfo.getVersion());
+    }
+  }
+
   private void launchAppPackage(AppPackage ap, ConfigPackage cp, LaunchCommandLineInfo commandLineInfo,
ConsoleReader reader) throws Exception
   {
     new LaunchCommand().execute(getLaunchAppPackageArgs(ap, cp, commandLineInfo, reader),
reader);
@@ -3848,6 +3859,7 @@ public class DTCli
     final Option originalAppID = add(OptionBuilder.withArgName("application id").hasArg().withDescription("Specify
original application identifier for restart.").create("originalAppId"));
     final Option exactMatch = add(new Option("exactMatch", "Only consider applications with
exact app name"));
     final Option queue = add(OptionBuilder.withArgName("queue name").hasArg().withDescription("Specify
the queue to launch the application").create("queue"));
+    final Option force = add(new Option("force", "Force launch the application. Do not check
for compatibility"));
 
     private Option add(Option opt)
     {
@@ -3888,6 +3900,7 @@ public class DTCli
     result.args = line.getArgs();
     result.origAppId = line.getOptionValue(LAUNCH_OPTIONS.originalAppID.getOpt());
     result.exactMatch = line.hasOption("exactMatch");
+    result.force = line.hasOption("force");
     return result;
   }
 
@@ -3904,6 +3917,7 @@ public class DTCli
     String archives;
     String origAppId;
     boolean exactMatch;
+    boolean force;
     String[] args;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-apex-core/blob/3e361866/engine/src/main/java/com/datatorrent/stram/util/VersionInfo.java
----------------------------------------------------------------------
diff --git a/engine/src/main/java/com/datatorrent/stram/util/VersionInfo.java b/engine/src/main/java/com/datatorrent/stram/util/VersionInfo.java
index cd1bc3b..fc29b01 100644
--- a/engine/src/main/java/com/datatorrent/stram/util/VersionInfo.java
+++ b/engine/src/main/java/com/datatorrent/stram/util/VersionInfo.java
@@ -155,6 +155,25 @@ public class VersionInfo {
     }
   }
 
+  public static boolean isCompatible(String thisVersion, String requiredVersion)
+  {
+    String[] thisVersionComponent = normalizeVersion(thisVersion).split("\\.");
+    String[] requiredVersionComponent = normalizeVersion(requiredVersion).split("\\.");
+
+    // major version check
+    if (!thisVersionComponent[0].equals(requiredVersionComponent[0])) {
+      return false;
+    }
+
+    // minor version check
+    if (Integer.parseInt(thisVersionComponent[1]) < Integer.parseInt(requiredVersionComponent[1]))
{
+      return false;
+    }
+
+    // patch version doesn't matter
+    return true;
+  }
+
   private static String normalizeVersion(String ver)
   {
     for (int i = 0; i < ver.length(); i++) {

http://git-wip-us.apache.org/repos/asf/incubator-apex-core/blob/3e361866/engine/src/test/java/com/datatorrent/stram/util/VersionInfoTest.java
----------------------------------------------------------------------
diff --git a/engine/src/test/java/com/datatorrent/stram/util/VersionInfoTest.java b/engine/src/test/java/com/datatorrent/stram/util/VersionInfoTest.java
index a7a2a1a..60d11a9 100644
--- a/engine/src/test/java/com/datatorrent/stram/util/VersionInfoTest.java
+++ b/engine/src/test/java/com/datatorrent/stram/util/VersionInfoTest.java
@@ -42,4 +42,16 @@ public class VersionInfoTest
     Assert.assertTrue(c < 0);
   }
 
+  @Test
+  public void testCompatibleVersion()
+  {
+    Assert.assertFalse(VersionInfo.isCompatible("1.0", "1.1"));
+    Assert.assertTrue(VersionInfo.isCompatible("1.10", "1.2"));
+    Assert.assertTrue(VersionInfo.isCompatible("1.10.0", "1.10.34"));
+    Assert.assertTrue(VersionInfo.isCompatible("1.10.55", "1.10.3"));
+    Assert.assertTrue(VersionInfo.isCompatible("1.10.55", "1.10.55"));
+    Assert.assertFalse(VersionInfo.isCompatible("1.10.55", "2.10.55"));
+    Assert.assertFalse(VersionInfo.isCompatible("2.10.55", "1.10.55"));
+  }
+
 }


Mime
View raw message