Browse Source

MAPREDUCE-2587. Generate yarn version for UI. (Thomas Graves via llu)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/MR-279@1136110 13f79535-47bb-0310-9956-ffa450edef68
Luke Lu 14 years ago
parent
commit
36632b0705

+ 2 - 0
mapreduce/CHANGES.txt

@@ -5,6 +5,8 @@ Trunk (unreleased changes)
 
 
     MAPREDUCE-279
     MAPREDUCE-279
 
 
+    MAPREDUCE-2587. Generate yarn version for UI. (Thomas Graves via llu)
+
     Fix stopContainer for setsid challenged platforms. (llu)
     Fix stopContainer for setsid challenged platforms. (llu)
 
 
     Fix concurrent modification exception in the Capacity Scheduler (mahadev)
     Fix concurrent modification exception in the Capacity Scheduler (mahadev)

+ 12 - 1
mapreduce/assembly/all.xml

@@ -1,7 +1,7 @@
 <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
 <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
   xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
-  <id>bin</id>
+  <id>all</id>
   <formats>
   <formats>
     <format>tar.gz</format>
     <format>tar.gz</format>
   </formats>
   </formats>
@@ -44,6 +44,9 @@
       <excludes>
       <excludes>
         <exclude>**/*.jar</exclude>
         <exclude>**/*.jar</exclude>
         <exclude>**/target/**</exclude>
         <exclude>**/target/**</exclude>
+        <!-- scripts to include later for setting fileMode -->
+        <exclude>**/bin/*</exclude>
+        <exclude>**/scripts/*</exclude>
         <!-- images that we don't need (and cause problems for our tools) -->
         <!-- images that we don't need (and cause problems for our tools) -->
         <exclude>**/dt-*/images/**</exclude>
         <exclude>**/dt-*/images/**</exclude>
         <!-- until the code that does this is fixed -->
         <!-- until the code that does this is fixed -->
@@ -63,6 +66,14 @@
         <include>src/**</include>
         <include>src/**</include>
       </includes>
       </includes>
     </fileSet>
     </fileSet>
+    <fileSet>
+      <outputDirectory>sources</outputDirectory>
+      <includes>
+        <include>**/bin/*</include>
+        <include>**/scripts/*</include>
+      </includes>
+      <fileMode>0755</fileMode>
+    </fileSet>
   </fileSets>
   </fileSets>
   <moduleSets>
   <moduleSets>
     <moduleSet>
     <moduleSet>

+ 15 - 0
mapreduce/yarn/yarn-common/pom.xml

@@ -73,6 +73,20 @@
               <goal>exec</goal>
               <goal>exec</goal>
             </goals>
             </goals>
           </execution>
           </execution>
+          <execution>
+            <id>generate-version</id>
+            <phase>generate-sources</phase>
+            <configuration>
+              <executable>scripts/saveVersion.sh</executable>
+              <arguments>
+                <argument>${yarn.version}</argument>
+                <argument>${project.build.directory}</argument>
+              </arguments>
+            </configuration>
+            <goals>
+              <goal>exec</goal>
+            </goals>
+          </execution>
         </executions>
         </executions>
       </plugin>
       </plugin>
 
 
@@ -89,6 +103,7 @@
             <configuration>
             <configuration>
               <sources>
               <sources>
                 <source>target/generated-sources/proto</source>
                 <source>target/generated-sources/proto</source>
+                <source>target/generated-sources/version</source>
               </sources>
               </sources>
             </configuration>
             </configuration>
           </execution>
           </execution>

+ 62 - 0
mapreduce/yarn/yarn-common/scripts/saveVersion.sh

@@ -0,0 +1,62 @@
+#!/bin/sh
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+# This file is used to generate the package-info.java class that
+# records the version, revision, branch, user, timestamp, and url
+unset LANG
+unset LC_CTYPE
+unset LC_TIME
+version=$1
+build_dir=$2
+user=`whoami`
+date=`date`
+dir=`pwd`
+cwd=`dirname $dir`
+if git rev-parse HEAD 2>/dev/null > /dev/null ; then
+  revision=`git log -1 --pretty=format:"%H" ../`
+  hostname=`hostname`
+  branch=`git branch | sed -n -e 's/^* //p'`
+  url="git://${hostname}${cwd}"
+elif [ -d .svn ]; then
+  revision=`svn info ../ | sed -n -e 's/Last Changed Rev: \(.*\)/\1/p'`
+  url=`svn info ../ | sed -n -e 's/URL: \(.*\)/\1/p'`
+  # Get canonical branch (branches/X, tags/X, or trunk)
+  branch=`echo $url | sed -n -e 's,.*\(branches/.*\)$,\1,p' \
+                             -e 's,.*\(tags/.*\)$,\1,p' \
+                             -e 's,.*trunk$,trunk,p'`
+else
+  revision="Unknown"
+  branch="Unknown"
+  url="file://$cwd"
+fi
+srcChecksum=`find ../ -name '*.java' | grep -v generated-sources | LC_ALL=C sort | xargs md5sum | md5sum | cut -d ' ' -f 1`
+
+mkdir -p $build_dir/generated-sources/version/org/apache/hadoop/yarn/
+cat << EOF | \
+  sed -e "s/VERSION/$version/" -e "s/USER/$user/" -e "s/DATE/$date/" \
+      -e "s|URL|$url|" -e "s/REV/$revision/" \
+      -e "s|BRANCH|$branch|" -e "s/SRCCHECKSUM/$srcChecksum/" \
+      > $build_dir/generated-sources/version/org/apache/hadoop/yarn/package-info.java
+/*
+ * Generated by saveVersion.sh
+ */
+@YarnVersionAnnotation(version="VERSION", revision="REV", branch="BRANCH",
+                         user="USER", date="DATE", url="URL",
+                         srcChecksum="SRCCHECKSUM")
+package org.apache.hadoop.yarn;
+EOF

+ 74 - 0
mapreduce/yarn/yarn-common/src/main/java/org/apache/hadoop/yarn/YarnVersionAnnotation.java

@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.yarn;
+
+import java.lang.annotation.*;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * A package attribute that captures the version of Yarn that was compiled.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.PACKAGE)
+@InterfaceAudience.LimitedPrivate({"MapReduce", "yarn"})
+@InterfaceStability.Unstable
+public @interface YarnVersionAnnotation {
+ 
+  /**
+   * Get the Yarn version
+   * @return the version string "0.6.3-dev"
+   */
+  String version();
+  
+  /**
+   * Get the username that compiled Yarn.
+   */
+  String user();
+  
+  /**
+   * Get the date when Yarn was compiled.
+   * @return the date in unix 'date' format
+   */
+  String date();
+    
+  /**
+   * Get the url for the subversion repository.
+   */
+  String url();
+  
+  /**
+   * Get the subversion revision.
+   * @return the revision number as a string (eg. "451451")
+   */
+  String revision();
+
+  /**
+   * Get the branch from which this was compiled.
+   * @return The branch name, e.g. "trunk" or "branches/branch-0.20"
+   */
+  String branch();
+
+  /**
+   * Get a checksum of the source files from which
+   * Yarn was compiled.
+   * @return a string that uniquely identifies the source
+   **/
+  String srcChecksum();    
+}

+ 125 - 0
mapreduce/yarn/yarn-common/src/main/java/org/apache/hadoop/yarn/util/YarnVersionInfo.java

@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.yarn.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.yarn.YarnVersionAnnotation;
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * This class finds the package info for Yarn and the YarnVersionAnnotation
+ * information.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Unstable
+public class YarnVersionInfo {
+  private static final Log LOG = LogFactory.getLog(YarnVersionInfo.class);
+
+  private static Package myPackage;
+  private static YarnVersionAnnotation version;
+  
+  static {
+    myPackage = YarnVersionAnnotation.class.getPackage();
+    version = myPackage.getAnnotation(YarnVersionAnnotation.class);
+  }
+
+  /**
+   * Get the meta-data for the Yarn package.
+   * @return
+   */
+  static Package getPackage() {
+    return myPackage;
+  }
+  
+  /**
+   * Get the Yarn version.
+   * @return the Yarn version string, eg. "0.6.3-dev"
+   */
+  public static String getVersion() {
+    return version != null ? version.version() : "Unknown";
+  }
+  
+  /**
+   * Get the subversion revision number for the root directory
+   * @return the revision number, eg. "451451"
+   */
+  public static String getRevision() {
+    return version != null ? version.revision() : "Unknown";
+  }
+
+  /**
+   * Get the branch on which this originated.
+   * @return The branch name, e.g. "trunk" or "branches/branch-0.20"
+   */
+  public static String getBranch() {
+    return version != null ? version.branch() : "Unknown";
+  }
+
+  /**
+   * The date that Yarn was compiled.
+   * @return the compilation date in unix date format
+   */
+  public static String getDate() {
+    return version != null ? version.date() : "Unknown";
+  }
+  
+  /**
+   * The user that compiled Yarn.
+   * @return the username of the user
+   */
+  public static String getUser() {
+    return version != null ? version.user() : "Unknown";
+  }
+  
+  /**
+   * Get the subversion URL for the root Yarn directory.
+   */
+  public static String getUrl() {
+    return version != null ? version.url() : "Unknown";
+  }
+
+  /**
+   * Get the checksum of the source files from which Yarn was
+   * built.
+   **/
+  public static String getSrcChecksum() {
+    return version != null ? version.srcChecksum() : "Unknown";
+  }
+
+  /**
+   * Returns the buildVersion which includes version, 
+   * revision, user and date. 
+   */
+  public static String getBuildVersion(){
+    return YarnVersionInfo.getVersion() + 
+    " from " + YarnVersionInfo.getRevision() +
+    " by " + YarnVersionInfo.getUser() + 
+    " source checksum " + YarnVersionInfo.getSrcChecksum();
+  }
+  
+  public static void main(String[] args) {
+    LOG.debug("version: "+ version);
+    System.out.println("Yarn " + getVersion());
+    System.out.println("Subversion " + getUrl() + " -r " + getRevision());
+    System.out.println("Compiled by " + getUser() + " on " + getDate());
+    System.out.println("From source with checksum " + getSrcChecksum());
+  }
+}

+ 55 - 0
mapreduce/yarn/yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestYarnVersionInfo.java

@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.yarn.util;
+
+import junit.framework.TestCase;
+import java.io.IOException;
+
+import org.apache.hadoop.yarn.util.YarnVersionInfo;
+import org.junit.Test;
+
+/**
+ * A JUnit test to test {@link YarnVersionInfo}
+ */
+public class TestYarnVersionInfo extends TestCase {
+  
+  /**
+   * Test the yarn version info routines.
+   * @throws IOException
+   */
+  @Test
+  public void testVersionInfoGenerated() throws IOException {
+
+    // can't easily know what the correct values are going to be so just
+    // make sure they aren't Unknown
+    assertTrue("getVersion returned Unknown", !YarnVersionInfo.getVersion().equals("Unknown"));
+    assertTrue("getUser returned Unknown", !YarnVersionInfo.getUser().equals("Unknown"));
+    assertTrue("getUrl returned Unknown", !YarnVersionInfo.getUrl().equals("Unknown"));
+    assertTrue("getSrcChecksum returned Unknown", !YarnVersionInfo.getSrcChecksum().equals("Unknown"));
+
+    // these could be Unknown if the VersionInfo generated from code not in svn or git
+    // so just check that they return something
+    assertNotNull("getRevision returned null", YarnVersionInfo.getRevision());
+    assertNotNull("getBranch returned null", YarnVersionInfo.getBranch());
+
+    assertTrue("getBuildVersion check doesn't contain: source checksum",
+               YarnVersionInfo.getBuildVersion().contains("source checksum"));
+
+  }
+}

+ 2 - 1
mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RmController.java

@@ -23,6 +23,7 @@ import static org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebApp.QUEU
 import static org.apache.hadoop.yarn.util.StringHelper.join;
 import static org.apache.hadoop.yarn.util.StringHelper.join;
 
 
 import org.apache.hadoop.util.VersionInfo;
 import org.apache.hadoop.util.VersionInfo;
+import org.apache.hadoop.yarn.util.YarnVersionInfo;
 import org.apache.hadoop.yarn.api.records.Application;
 import org.apache.hadoop.yarn.api.records.Application;
 import org.apache.hadoop.yarn.api.records.ApplicationId;
 import org.apache.hadoop.yarn.api.records.ApplicationId;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
@@ -54,7 +55,7 @@ public class RmController extends Controller {
       _("Cluster ID:", ts).
       _("Cluster ID:", ts).
       _("ResourceManager state:", rm.getServiceState()).
       _("ResourceManager state:", rm.getServiceState()).
       _("ResourceManager started on:", Times.format(ts)).
       _("ResourceManager started on:", Times.format(ts)).
-      _("ResourceManager version:", "1.0-SNAPSHOT").
+      _("ResourceManager version:", YarnVersionInfo.getBuildVersion()).
       _("Hadoop version:", VersionInfo.getBuildVersion());
       _("Hadoop version:", VersionInfo.getBuildVersion());
     render(InfoPage.class);
     render(InfoPage.class);
   }
   }