You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2014/04/03 23:05:56 UTC

git commit: AMBARI-5304. Finalize 2.1 stack definition for repo info file (ncole)

Repository: ambari
Updated Branches:
  refs/heads/trunk 99dbf3dbc -> bb4a19672


AMBARI-5304. Finalize 2.1 stack definition for repo info file (ncole)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/bb4a1967
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/bb4a1967
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/bb4a1967

Branch: refs/heads/trunk
Commit: bb4a19672e0e74a2126e3edf9f4d9ab9e480b433
Parents: 99dbf3d
Author: Nate Cole <nc...@hortonworks.com>
Authored: Wed Apr 2 10:37:26 2014 -0400
Committer: Nate Cole <nc...@hortonworks.com>
Committed: Thu Apr 3 17:05:49 2014 -0400

----------------------------------------------------------------------
 ambari-server/pom.xml                           |  3 +
 ambari-server/set-hdp-repo-url.sh               | 10 ++-
 .../server/state/stack/LatestRepoCallable.java  | 67 +++++++++++++++++++-
 .../resources/stacks/HDP/2.1/repos/repoinfo.xml |  1 +
 .../server/api/services/AmbariMetaInfoTest.java | 22 ++++++-
 .../resources/stacks/HDP/2.1.1/repos/hdp.json   |  2 +-
 6 files changed, 98 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/bb4a1967/ambari-server/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-server/pom.xml b/ambari-server/pom.xml
index 053cf57..f94256b 100644
--- a/ambari-server/pom.xml
+++ b/ambari-server/pom.xml
@@ -30,6 +30,7 @@
     <deb.dependency.list>openssl, postgresql (&gt;= 8.1), ${deb.python.ver}</deb.dependency.list>
     <custom.tests>false</custom.tests>
     <hdpUrlForCentos6>http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.1.1.0</hdpUrlForCentos6>
+    <hdpLatestUrl>http://public-repo-1.hortonworks.com/HDP/hdp_urlinfo.json</hdpLatestUrl>
     <common_functions.install.dir>/usr/lib/python2.6/site-packages/common_functions</common_functions.install.dir>
     <ambari-web-dir>${basedir}/../ambari-web/public</ambari-web-dir>
   </properties>
@@ -928,6 +929,7 @@
                       failonerror="true">
                       <arg value="${basedir}/set-hdp-repo-url.sh" />
                       <arg value="${hdpUrlForCentos6}" />
+                      <arg value="${hdpLatestUrl}" />
                     </exec>
                   </target>
                 </configuration>
@@ -944,6 +946,7 @@
                       failonerror="true">
                       <arg value="${basedir}/set-hdp-repo-url.sh" />
                       <arg value="${hdpUrlForCentos6}" />
+                      <arg value="${hdpLatestUrl}" />
                       <arg
                         value="${project.build.directory}/ambari-server-${project.version}-dist/ambari-server-${project.version}" />
                     </exec>

http://git-wip-us.apache.org/repos/asf/ambari/blob/bb4a1967/ambari-server/set-hdp-repo-url.sh
----------------------------------------------------------------------
diff --git a/ambari-server/set-hdp-repo-url.sh b/ambari-server/set-hdp-repo-url.sh
index e66d21e..3413137 100644
--- a/ambari-server/set-hdp-repo-url.sh
+++ b/ambari-server/set-hdp-repo-url.sh
@@ -28,19 +28,20 @@ then
 
   VERSION=2.1
   C6URL="$1"
+  LATEST_URL="$2"
   C5URL="${C6URL/centos6/centos5}"
   S11URL="${C6URL/centos6/suse11}"
   U12URL="${C6URL/centos6/ubuntu12}"
 
-  if [ "$#" != 2 ]
+  if [ "$#" != 3 ]
   then
     HDPREPO=target/classes/stacks/HDP/${VERSION}/repos
   else
-    HDPREPO=$2/var/lib/ambari-server/resources/stacks/HDP/${VERSION}/repos
+    HDPREPO=$3/var/lib/ambari-server/resources/stacks/HDP/${VERSION}/repos
   fi
 
   echo "Processing '${HDPREPO}/repoinfo.xml' and '${HDPLOCALREPO}/repoinfo.xml'"
-  echo "$2"
+  echo "$3"
 
   echo "Setting centos5 stack url to '$C5URL'"
   sed "s;REPLACE_WITH_CENTOS5_URL;$C5URL;" ${HDPREPO}/repoinfo.xml >  ${HDPREPO}/repoinfo.xml.tmp; mv ${HDPREPO}/repoinfo.xml.tmp ${HDPREPO}/repoinfo.xml
@@ -53,4 +54,7 @@ then
 
   echo "Setting ubuntu12 stack url to '$U12URL'"
   sed  "s;REPLACE_WITH_UBUNTU12_URL;$U12URL;" ${HDPREPO}/repoinfo.xml >  ${HDPREPO}/repoinfo.xml.tmp; mv ${HDPREPO}/repoinfo.xml.tmp ${HDPREPO}/repoinfo.xml
+
+  echo "Replacing latest lookup url to '$LATEST_URL'"
+  sed "s;\(<latest>\)\([^>]*\)\(<\/latest>\);\1$LATEST_URL\3;" ${HDPREPO}/repoinfo.xml > ${HDPREPO}/repoinfo.xml.tmp; mv ${HDPREPO}/repoinfo.xml.tmp ${HDPREPO}/repoinfo.xml
 fi

http://git-wip-us.apache.org/repos/asf/ambari/blob/bb4a1967/ambari-server/src/main/java/org/apache/ambari/server/state/stack/LatestRepoCallable.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/LatestRepoCallable.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/LatestRepoCallable.java
index d1b5fdb..fda9fc9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/LatestRepoCallable.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/LatestRepoCallable.java
@@ -21,12 +21,14 @@ import java.io.File;
 import java.io.FileReader;
 import java.io.InputStreamReader;
 import java.lang.reflect.Type;
+import java.net.URI;
 import java.util.Map;
 import java.util.concurrent.Callable;
 
 import org.apache.ambari.server.controller.internal.URLStreamProvider;
 import org.apache.ambari.server.state.RepositoryInfo;
 import org.apache.ambari.server.state.StackInfo;
+import org.apache.http.client.utils.URIBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -98,8 +100,23 @@ public class LatestRepoCallable implements Callable<Void> {
             
             @SuppressWarnings("unchecked")
             Map<String, String> osMap = (Map<String, String>) valueMap.get("latest");
-            if (osMap.containsKey(ri.getOsType())) {
-              ri.setLatestBaseUrl(osMap.get(ri.getOsType()));
+            
+            String baseUrl = resolveOsUrl(ri.getOsType(), osMap);
+            if (null != baseUrl) {
+              // !!! in the case where <name>.repo is defined with the base url, strip that off.
+              // Agents do the reverse action (take the base url, and append <name>.repo)
+              String repoFileName = stack.getName().toLowerCase() + ".repo";
+              int idx = baseUrl.toLowerCase().indexOf(repoFileName); 
+              
+              if (-1 != idx && baseUrl.toLowerCase().endsWith(repoFileName)) {
+                baseUrl = baseUrl.substring(0, idx);
+              }
+              
+              if ('/' == baseUrl.charAt(baseUrl.length()-1)) {
+                baseUrl = baseUrl.substring(0, baseUrl.length()-1);
+              }
+              
+              ri.setLatestBaseUrl(baseUrl);
             }
           }
         }
@@ -108,5 +125,51 @@ public class LatestRepoCallable implements Callable<Void> {
     
     return null;
   }
+  
+  /**
+   * Resolves a base url given that certain OS types can be used interchangeably.
+   * @param os the target os to find
+   * @param osMap the map of os-to-baseurl 
+   * @return the url for an os.
+   */
+  private String resolveOsUrl(String os, Map<String, String> osMap) {
+    
+    // !!! look for the OS directly
+    if (osMap.containsKey(os))
+      return osMap.get(os);
+    
+    // !!! os not found, find and return the first compatible one
+    String[] possibleTypes = OsFamily.findTypes(os);
+    
+    for (String type : possibleTypes) {
+      if (osMap.containsKey(type))
+        return osMap.get(type);
+    }
+    
+    return null;
+  }
 
+  private enum OsFamily {
+    REDHAT5("centos5", "redhat5", "oraclelinux5"),
+    REDHAT6("centos6", "redhat6", "oraclelinux6"),
+    SUSE11("suse11", "sles11"),
+    UBUNTU12("ubuntu12");
+    
+    private String[] osTypes;
+    private OsFamily(String... oses) {
+      osTypes = oses;
+    }
+    
+    private static String[] findTypes(String os) {
+      for (OsFamily f : values()) {
+        for (String t : f.osTypes) {
+          if (t.equals(os)) {
+            return f.osTypes;
+          }
+        }
+      }
+      return new String[0];
+    }
+  }
+  
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/bb4a1967/ambari-server/src/main/resources/stacks/HDP/2.1/repos/repoinfo.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.1/repos/repoinfo.xml b/ambari-server/src/main/resources/stacks/HDP/2.1/repos/repoinfo.xml
index 0f5f61a..afb210f 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.1/repos/repoinfo.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.1/repos/repoinfo.xml
@@ -16,6 +16,7 @@
    limitations under the License.
 -->
 <reposinfo>
+  <latest>http://s3.amazonaws.com/dev.hortonworks.com/HDP/hdp_urlinfo.json</latest>
   <os type="centos6">
     <repo>
       <baseurl>REPLACE_WITH_CENTOS6_URL</baseurl>

http://git-wip-us.apache.org/repos/asf/ambari/blob/bb4a1967/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
index 60936a1..9ff575d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
@@ -1291,9 +1291,29 @@ public class AmbariMetaInfoTest {
   public void testLatestRepo() throws Exception {
     
     for (RepositoryInfo ri : metaInfo.getRepositories("HDP", "2.1.1", "centos6")) {
-      Assert.assertEquals("http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos6/2.x/BUILDS/2.1.1.0-118",
+      Assert.assertEquals(
+          "Expected the base url to be set properly",
+          "http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos6/2.x/BUILDS/2.1.1.0-118",
           ri.getLatestBaseUrl());
+      Assert.assertEquals(
+          "Expected the default URL to be the same as in the xml file",
+          "http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.0.6.0",
+          ri.getDefaultBaseUrl());
     }
+    
+    for (RepositoryInfo ri : metaInfo.getRepositories("HDP", "2.1.1", "suse11")) {
+      Assert.assertEquals(
+          "Expected hdp.json to be stripped from the url",
+          "http://s3.amazonaws.com/dev.hortonworks.com/HDP/suse11/2.x/BUILDS/2.1.1.0-118",
+          ri.getLatestBaseUrl());
+    }
+
+    for (RepositoryInfo ri : metaInfo.getRepositories("HDP", "2.1.1", "sles11")) {
+      Assert.assertEquals("http://s3.amazonaws.com/dev.hortonworks.com/HDP/suse11/2.x/BUILDS/2.1.1.0-118",
+          ri.getLatestBaseUrl());
+    }
+    
+    
   }
 
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/bb4a1967/ambari-server/src/test/resources/stacks/HDP/2.1.1/repos/hdp.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/resources/stacks/HDP/2.1.1/repos/hdp.json b/ambari-server/src/test/resources/stacks/HDP/2.1.1/repos/hdp.json
index 8c47ae6..fc51627 100644
--- a/ambari-server/src/test/resources/stacks/HDP/2.1.1/repos/hdp.json
+++ b/ambari-server/src/test/resources/stacks/HDP/2.1.1/repos/hdp.json
@@ -4,7 +4,7 @@
       "centos6": "http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos6/2.x/BUILDS/2.1.1.0-118",
       "redhat6": "http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos6/2.x/BUILDS/2.1.1.0-118",
       "oraclelinux6": "http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos6/2.x/BUILDS/2.1.1.0-118",
-      "suse11": "http://s3.amazonaws.com/dev.hortonworks.com/HDP/suse11/2.x/BUILDS/2.1.1.0-118"
+      "suse11": "http://s3.amazonaws.com/dev.hortonworks.com/HDP/suse11/2.x/BUILDS/2.1.1.0-118/hdp.repo"
     }
   }
 }