apex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From david...@apache.org
Subject incubator-apex-core git commit: Make the version retrieval reusable.
Date Thu, 10 Mar 2016 02:30:10 GMT
Repository: incubator-apex-core
Updated Branches:
  refs/heads/master 30bb9e022 -> 18fc36e33


Make the version retrieval reusable.


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/18fc36e3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/tree/18fc36e3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/diff/18fc36e3

Branch: refs/heads/master
Commit: 18fc36e33b354e9e7a02f6a60c1b158bdf0c9e49
Parents: 30bb9e0
Author: Thomas Weise <thomas@datatorrent.com>
Authored: Wed Mar 9 16:05:12 2016 -0800
Committer: Thomas Weise <thomas@datatorrent.com>
Committed: Wed Mar 9 16:05:12 2016 -0800

----------------------------------------------------------------------
 .../datatorrent/stram/StreamingAppMaster.java   |  2 +-
 .../java/com/datatorrent/stram/cli/DTCli.java   | 26 +++++----
 .../com/datatorrent/stram/util/VersionInfo.java | 58 +++++++++++---------
 .../com/datatorrent/stram/webapp/AppInfo.java   |  2 +-
 .../datatorrent/stram/util/VersionInfoTest.java | 11 ++++
 5 files changed, 60 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-apex-core/blob/18fc36e3/engine/src/main/java/com/datatorrent/stram/StreamingAppMaster.java
----------------------------------------------------------------------
diff --git a/engine/src/main/java/com/datatorrent/stram/StreamingAppMaster.java b/engine/src/main/java/com/datatorrent/stram/StreamingAppMaster.java
index 3b0a49b..e060acf 100644
--- a/engine/src/main/java/com/datatorrent/stram/StreamingAppMaster.java
+++ b/engine/src/main/java/com/datatorrent/stram/StreamingAppMaster.java
@@ -58,7 +58,7 @@ public class StreamingAppMaster extends StramUtils.YarnContainerMain
     StdOutErrLog.tieSystemOutAndErrToLog();
     LOG.info("Master starting with classpath: {}", System.getProperty("java.class.path"));
 
-    LOG.info("version: {}", VersionInfo.getBuildVersion());
+    LOG.info("version: {}", VersionInfo.APEX_VERSION.getBuildVersion());
     StringWriter sw = new StringWriter();
     for (Map.Entry<String, String> e : System.getenv().entrySet()) {
       sw.append("\n").append(e.getKey()).append("=").append(e.getValue());

http://git-wip-us.apache.org/repos/asf/incubator-apex-core/blob/18fc36e3/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 e80b80d..9e0a1fc 100644
--- a/engine/src/main/java/com/datatorrent/stram/cli/DTCli.java
+++ b/engine/src/main/java/com/datatorrent/stram/cli/DTCli.java
@@ -1486,7 +1486,8 @@ public class DTCli
 
   private void printWelcomeMessage()
   {
-    System.out.println("DT CLI " + VersionInfo.getVersion() + " " + VersionInfo.getDate()
+ " " + VersionInfo.getRevision());
+    VersionInfo v = VersionInfo.APEX_VERSION;
+    System.out.println("DT CLI " + v.getVersion() + " " + v.getDate() + " " + v.getRevision());
   }
 
   private void printHelp(String command, CommandSpec commandSpec, PrintStream os)
@@ -1905,7 +1906,7 @@ public class DTCli
           submitApp = getStramAppLauncher(fileName, config, commandLineInfo.ignorePom);
         }
         submitApp.loadDependencies();
-        
+
         if (commandLineInfo.origAppId != null) {
           // ensure app is not running
           ApplicationReport ar = null;
@@ -1936,7 +1937,7 @@ public class DTCli
             }
           }
         }
-        
+
         if (appFactory == null && matchString != null) {
           // attempt to interpret argument as property file - do we still need it?
           try {
@@ -1952,7 +1953,7 @@ public class DTCli
             // ignore
           }
         }
-        
+
         if (appFactory == null) {
           List<AppFactory> matchingAppFactories = getMatchingAppFactories(submitApp,
matchString, commandLineInfo.exactMatch);
           if (matchingAppFactories == null || matchingAppFactories.isEmpty()) {
@@ -1988,7 +1989,7 @@ public class DTCli
             if (!consolePresent) {
               throw new CliException("More than one application in jar file match '" + matchString
+ "'");
             } else {
-              
+
               boolean useHistory = reader.isHistoryEnabled();
               reader.setHistoryEnabled(false);
               History previousHistory = reader.getHistory();
@@ -2021,9 +2022,9 @@ public class DTCli
               }
             }
           }
-          
+
         }
-        
+
         if (appFactory != null) {
           if (!commandLineInfo.localMode) {
 
@@ -2047,7 +2048,7 @@ public class DTCli
                   {
                     // no-op
                   }
-                  
+
                 });
                 System.setOut(dummyStream);
               }
@@ -2065,7 +2066,7 @@ public class DTCli
         } else {
           System.err.println("No application specified.");
         }
-        
+
       } finally {
         IOUtils.closeQuietly(cp);
       }
@@ -3017,7 +3018,7 @@ public class DTCli
 
             // add default value
             operatorDiscoverer.addDefaultValue(clazz, oper);
-            
+
             // add class hierarchy info to portClassHier and fetch port types with schema
classes
             operatorDiscoverer.buildAdditionalPortInfo(oper, portClassHier, portTypesWithSchemaClasses);
 
@@ -3460,8 +3461,9 @@ public class DTCli
   private void checkPlatformCompatible(AppPackage ap)
   {
     String apVersion = ap.getDtEngineVersion();
-    if (!VersionInfo.isCompatible(VersionInfo.getVersion(), apVersion)) {
-      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());
+    VersionInfo actualVersion = VersionInfo.APEX_VERSION;
+    if (!VersionInfo.isCompatible(actualVersion.getVersion(), apVersion)) {
+      throw new CliException("This App Package is compiled with Apache Apex Core API version
" + apVersion + ", which is incompatible with this Apex Core version " + actualVersion.getVersion());
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-apex-core/blob/18fc36e3/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 ce083b5..cd20caa 100644
--- a/engine/src/main/java/com/datatorrent/stram/util/VersionInfo.java
+++ b/engine/src/main/java/com/datatorrent/stram/util/VersionInfo.java
@@ -37,43 +37,44 @@ import org.apache.hadoop.classification.InterfaceStability;
  */
 @InterfaceAudience.Private
 @InterfaceStability.Unstable
-public class VersionInfo {
-
-  private static String version = "Unknown";
-  private static String user = "Unknown";
-  private static String date = "Unknown";
-  private static String revision = "Unknown";
-
-  static {
+public class VersionInfo
+{
+  private String version = "Unknown";
+  private String user = "Unknown";
+  private String date = "Unknown";
+  private String revision = "Unknown";
+
+  public VersionInfo(Class<?> classInJar, String groupId, String artifactId, String
gitPropertiesResource)
+  {
     try {
-      URL res = VersionInfo.class.getResource(VersionInfo.class.getSimpleName() + ".class");
+      URL res = classInJar.getResource(classInJar.getSimpleName() + ".class");
       URLConnection conn = res.openConnection();
       if (conn instanceof JarURLConnection) {
         Manifest mf = ((JarURLConnection) conn).getManifest();
         Attributes mainAttribs = mf.getMainAttributes();
         String builtBy = mainAttribs.getValue("Built-By");
         if(builtBy != null) {
-          VersionInfo.user = builtBy;
+          this.user = builtBy;
         }
       }
 
-      Enumeration<URL> resources = VersionInfo.class.getClassLoader().getResources("META-INF/maven/org.apache.apex/apex-engine/pom.properties");
+      Enumeration<URL> resources = classInJar.getClassLoader().getResources("META-INF/maven/"
+ groupId + "/" + artifactId + "/pom.properties");
       while (resources.hasMoreElements()) {
         Properties pomInfo = new Properties();
         pomInfo.load(resources.nextElement().openStream());
         String v = pomInfo.getProperty("version", "unknown");
-        VersionInfo.version = v;
+        this.version = v;
       }
 
-      resources = VersionInfo.class.getClassLoader().getResources("dt-git.properties");
+      resources = VersionInfo.class.getClassLoader().getResources(gitPropertiesResource);
       while (resources.hasMoreElements()) {
         Properties gitInfo = new Properties();
         gitInfo.load(resources.nextElement().openStream());
         String commitAbbrev = gitInfo.getProperty("git.commit.id.abbrev", "unknown");
         String branch = gitInfo.getProperty("git.branch", "unknown");
-        VersionInfo.revision = "rev: " + commitAbbrev + " branch: " + branch;
-        VersionInfo.date = gitInfo.getProperty("git.build.time", VersionInfo.date);
-        VersionInfo.user = gitInfo.getProperty("git.build.user.name", VersionInfo.user);
+        this.revision = "rev: " + commitAbbrev + " branch: " + branch;
+        this.date = gitInfo.getProperty("git.build.time", this.date);
+        this.user = gitInfo.getProperty("git.build.user.name", this.user);
         break;
       }
 
@@ -88,7 +89,7 @@ public class VersionInfo {
    *
    * @return the version string, e.g. "0.1.1-SNAPSHOT"
    */
-  public static String getVersion() {
+  public String getVersion() {
     return version;
   }
 
@@ -97,7 +98,7 @@ public class VersionInfo {
    *
    * @return the compilation date
    */
-  public static String getDate() {
+  public String getDate() {
     return date;
   }
 
@@ -106,7 +107,7 @@ public class VersionInfo {
    *
    * @return the username of the user
    */
-  public static String getUser() {
+  public String getUser() {
     return user;
   }
 
@@ -114,17 +115,24 @@ public class VersionInfo {
    * Get the SCM revision number
    * @return the revision number, eg. "451451"
    */
-  public static String getRevision() {
+  public String getRevision() {
     return revision;
   }
 
   /**
    * Returns the buildVersion which includes version, revision, user and date.
    */
-  public static String getBuildVersion() {
-    return VersionInfo.getVersion() + " from " + VersionInfo.getRevision() + " by " + VersionInfo.getUser()
+ " on " + VersionInfo.getDate();
+  public String getBuildVersion() {
+    return getVersion() + " from " + getRevision() + " by " + getUser() + " on " + getDate();
   }
 
+  private static String groupId = "org.apache.apex";
+  private static String artifactId = "apex-engine";
+  private static Class<?> classInJar = VersionInfo.class;
+  private static String gitPropertiesResource = "dt-git.properties";
+  public static final VersionInfo APEX_VERSION = new VersionInfo(classInJar, groupId, artifactId,
gitPropertiesResource);
+
+
   /**
    * Compares two version strings.
    *
@@ -187,9 +195,9 @@ public class VersionInfo {
 
   @SuppressWarnings("UseOfSystemOutOrSystemErr")
   public static void main(String[] args) {
-    System.out.println("Malhar " + getVersion());
-    System.out.println("Revision " + getRevision());
-    System.out.println("Compiled by " + getUser() + " on " + getDate());
+    System.out.println("Apex " + APEX_VERSION.getVersion());
+    System.out.println("Revision " + APEX_VERSION.getRevision());
+    System.out.println("Compiled by " + APEX_VERSION.getUser() + " on " + APEX_VERSION.getDate());
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-apex-core/blob/18fc36e3/engine/src/main/java/com/datatorrent/stram/webapp/AppInfo.java
----------------------------------------------------------------------
diff --git a/engine/src/main/java/com/datatorrent/stram/webapp/AppInfo.java b/engine/src/main/java/com/datatorrent/stram/webapp/AppInfo.java
index 109a401..745b347 100644
--- a/engine/src/main/java/com/datatorrent/stram/webapp/AppInfo.java
+++ b/engine/src/main/java/com/datatorrent/stram/webapp/AppInfo.java
@@ -214,7 +214,7 @@ public class AppInfo {
     this.appMasterTrackingUrl = context.getAppMasterTrackingUrl();
     this.stats = context.getStats();
     this.gatewayAddress = context.getGatewayAddress();
-    this.version = VersionInfo.getBuildVersion();
+    this.version = VersionInfo.APEX_VERSION.getBuildVersion();
     this.attributes = new TreeMap<>();
     for (Map.Entry<Attribute<Object>, Object> entry : AttributeMap.AttributeInitializer.getAllAttributes(context,
DAGContext.class).entrySet()) {
       this.attributes.put(entry.getKey().getSimpleName(), entry.getKey().codec.toString(entry.getValue()));

http://git-wip-us.apache.org/repos/asf/incubator-apex-core/blob/18fc36e3/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 60d11a9..6e5b64f 100644
--- a/engine/src/test/java/com/datatorrent/stram/util/VersionInfoTest.java
+++ b/engine/src/test/java/com/datatorrent/stram/util/VersionInfoTest.java
@@ -21,6 +21,8 @@ package com.datatorrent.stram.util;
 import org.junit.Assert;
 import org.junit.Test;
 
+import com.datatorrent.api.Operator;
+
 /**
  *
  */
@@ -54,4 +56,13 @@ public class VersionInfoTest
     Assert.assertFalse(VersionInfo.isCompatible("2.10.55", "1.10.55"));
   }
 
+  @Test
+  public void testMavenProperties()
+  {
+    VersionInfo v = new VersionInfo(Operator.class, "org.apache.apex", "apex-api", "git-properties-unavailable");
+    if (!v.getVersion().matches("[0-9]+.[0-9]+.[0-9]+.*")) {
+      Assert.fail("Version number pattern does not match: " + v.getVersion());
+    }
+  }
+
 }


Mime
View raw message