ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject git commit: AMBARI-5653. Upgradestack only handles specific OSs (ncole)
Date Fri, 02 May 2014 01:37:50 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk ef80c0a97 -> d0081327b


AMBARI-5653. Upgradestack only handles specific OSs (ncole)


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

Branch: refs/heads/trunk
Commit: d0081327b51b2e27c138a1562237f73a8d9c70f9
Parents: ef80c0a
Author: Nate Cole <ncole@hortonworks.com>
Authored: Thu May 1 21:21:24 2014 -0400
Committer: Nate Cole <ncole@hortonworks.com>
Committed: Thu May 1 21:21:24 2014 -0400

----------------------------------------------------------------------
 .../server/api/services/AmbariMetaInfo.java     | 13 ++++-
 .../server/state/stack/LatestRepoCallable.java  | 23 --------
 .../ambari/server/state/stack/OsFamily.java     | 57 ++++++++++++++++++++
 .../ambari/server/upgrade/StackUpgradeUtil.java | 48 +++++++++++++----
 .../server/upgrade/StackUpgradeUtilTest.java    | 24 ++++++++-
 5 files changed, 130 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d0081327/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
index 61e2954..1d2e5cc 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
@@ -111,7 +111,7 @@ public class AmbariMetaInfo {
   private final static Logger LOG = LoggerFactory.getLogger(AmbariMetaInfo.class);
   private static final String REPOSITORY_FILE_NAME = "repoinfo.xml";
   private static final String REPOSITORY_FOLDER_NAME = "repos";
-  private static final String REPOSITORY_XML_PROPERTY_BASEURL = "baseurl";
+  public static final String REPOSITORY_XML_PROPERTY_BASEURL = "baseurl";
   // all the supported OS'es
   private static final List<String> ALL_SUPPORTED_OS = Arrays.asList(
       "centos5", "redhat5", "centos6", "redhat6", "oraclelinux5",
@@ -895,7 +895,16 @@ public class AmbariMetaInfo {
     return ALL_SUPPORTED_OS.contains(osType);
   }
 
-  private String generateRepoMetaKey(String stackName, String stackVersion,
+  /**
+   * Returns a suitable key for use with stack url overrides.
+   * @param stackName the stack name
+   * @param stackVersion the stack version
+   * @param osType the os
+   * @param repoId the repo id
+   * @param field the field name
+   * @return the key for any repo value override
+   */
+  public String generateRepoMetaKey(String stackName, String stackVersion,
       String osType, String repoId, String field) {
 
     StringBuilder sb = new StringBuilder("repo:/");

http://git-wip-us.apache.org/repos/asf/ambari/blob/d0081327/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 fda9fc9..f8847d9 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
@@ -148,28 +148,5 @@ public class LatestRepoCallable implements Callable<Void> {
     
     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/d0081327/ambari-server/src/main/java/org/apache/ambari/server/state/stack/OsFamily.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/OsFamily.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/OsFamily.java
new file mode 100644
index 0000000..5c458a4
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/OsFamily.java
@@ -0,0 +1,57 @@
+/**
+ * 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.ambari.server.state.stack;
+
+public enum OsFamily {
+  REDHAT5("centos5", "redhat5", "oraclelinux5", "rhel5"),
+  REDHAT6("centos6", "redhat6", "oraclelinux6", "rhel6"),
+  SUSE11("suse11", "sles11"),
+  DEBIAN12("debian12", "ubuntu12");
+  
+  private String[] osTypes;
+  private OsFamily(String... oses) {
+    osTypes = oses;
+  }
+  
+  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];
+  }
+
+  /**
+   * Finds the family for the specific os
+   * @param os the os
+   * @return the family, or <code>null</code> if not defined
+   */
+  public static OsFamily find(String os) {
+    for (OsFamily f : values()) {
+      for (String t : f.osTypes) {
+        if (t.equals(os)) {
+          return f;
+        }
+      }
+    }
+    return null;
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/d0081327/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeUtil.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeUtil.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeUtil.java
index 5f96326..bdce8a7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeUtil.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeUtil.java
@@ -17,28 +17,27 @@
  */
 package org.apache.ambari.server.upgrade;
 
-import java.net.URI;
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Scanner;
-import java.util.Set;
 
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.orm.dao.ClusterDAO;
 import org.apache.ambari.server.orm.dao.ClusterStateDAO;
 import org.apache.ambari.server.orm.dao.HostComponentDesiredStateDAO;
 import org.apache.ambari.server.orm.dao.HostComponentStateDAO;
+import org.apache.ambari.server.orm.dao.MetainfoDAO;
 import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO;
 import org.apache.ambari.server.orm.dao.ServiceDesiredStateDAO;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
 import org.apache.ambari.server.orm.entities.ClusterStateEntity;
 import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
 import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
+import org.apache.ambari.server.orm.entities.MetainfoEntity;
 import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity;
 import org.apache.ambari.server.orm.entities.ServiceDesiredStateEntity;
 import org.apache.ambari.server.state.OperatingSystemInfo;
 import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.stack.OsFamily;
 
 import com.google.gson.Gson;
 import com.google.inject.Inject;
@@ -163,8 +162,6 @@ public class StackUpgradeUtil {
         !repoUrl.startsWith("http"))
       return;
     
-    String server = repoUrl;
-    
     String[] oses = new String[0]; 
     
     if (null != repoUrlOs) {
@@ -172,18 +169,51 @@ public class StackUpgradeUtil {
     }
     
     AmbariMetaInfo ami = injector.getInstance(AmbariMetaInfo.class);
+    MetainfoDAO metaDao = injector.getInstance(MetainfoDAO.class);
+    
+    String stackRepoId = stackName + "-" + stackVersion;
     
     if (0 == oses.length) {
       // do them all
       for (OperatingSystemInfo osi : ami.getOperatingSystems(stackName, stackVersion)) {
         ami.updateRepoBaseURL(stackName, stackVersion, osi.getOsType(),
-            stackName + "-" + stackVersion, server);
+            stackRepoId, repoUrl);
       }
       
     } else {
       for (String os : oses) {
-        ami.updateRepoBaseURL(stackName, stackVersion, os,
-            stackName + "-" + stackVersion, server);
+        
+        OsFamily family = OsFamily.find(os);
+        if (null != family) {
+          String key = ami.generateRepoMetaKey(stackName, stackVersion, os,
+              stackName + "-" + stackVersion, AmbariMetaInfo.REPOSITORY_XML_PROPERTY_BASEURL);
+
+          String familyKey = ami.generateRepoMetaKey(stackName, stackVersion,
+              family.name().toLowerCase(), stackRepoId, AmbariMetaInfo.REPOSITORY_XML_PROPERTY_BASEURL);
+          
+          // need to use (for example) redhat6 if the os is centos6
+          MetainfoEntity entity = metaDao.findByKey(key);
+          if (null == entity) {
+            entity = new MetainfoEntity();
+            entity.setMetainfoName(key);
+            entity.setMetainfoValue(repoUrl);
+            metaDao.merge(entity);
+          } else {
+            entity.setMetainfoValue(repoUrl);
+            metaDao.merge(entity);
+          }
+          
+          entity = metaDao.findByKey(familyKey);
+          if (null == entity) {
+            entity = new MetainfoEntity();
+            entity.setMetainfoName(familyKey);
+            entity.setMetainfoValue(repoUrl);
+            metaDao.merge(entity);
+          } else {
+            entity.setMetainfoValue(repoUrl);
+            metaDao.merge(entity);
+          }
+        }        
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/d0081327/ambari-server/src/test/java/org/apache/ambari/server/upgrade/StackUpgradeUtilTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/StackUpgradeUtilTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/StackUpgradeUtilTest.java
index 5cda29c..64de35d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/StackUpgradeUtilTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/StackUpgradeUtilTest.java
@@ -98,7 +98,8 @@ public class StackUpgradeUtilTest {
 
     entities = dao.findAll();
     for (MetainfoEntity entity : entities) {
-      Assert.assertTrue(entity.getMetainfoName().startsWith("repo:/HDP/1.3.0/centos6"));
+      Assert.assertTrue(entity.getMetainfoName().startsWith("repo:/HDP/1.3.0/centos6") ||
+          entity.getMetainfoName().startsWith("repo:/HDP/1.3.0/redhat6"));
       Assert.assertEquals(localRepoUrl, entity.getMetainfoValue());
     }
 
@@ -112,10 +113,31 @@ public class StackUpgradeUtilTest {
     entities = dao.findAll();
     for (MetainfoEntity entity : entities) {
       Assert.assertTrue(entity.getMetainfoName().startsWith("repo:/HDP/1.3.0/centos6") ||
+          entity.getMetainfoName().startsWith("repo:/HDP/1.3.0/redhat6") ||
+          entity.getMetainfoName().startsWith("repo:/HDP/1.3.0/redhat5") ||
           entity.getMetainfoName().startsWith("repo:/HDP/1.3.0/centos5"));
       Assert.assertEquals(localRepoUrl, entity.getMetainfoValue());
     }
     
+    // verify that a change to centos6 also changes redhat6
+    localRepoUrl = "http://newfoo.bar";
+    stackUpgradeUtil.updateLocalRepo(stackName, stackVersion, localRepoUrl, "centos6");
+    entities = dao.findAll();
+    boolean foundCentos6 = false;
+    boolean foundRedhat6 = false;
+    for (MetainfoEntity entity : entities) {
+      if (-1 != entity.getMetainfoName().indexOf("centos6")) {
+        foundCentos6 = true;
+        Assert.assertEquals(localRepoUrl, entity.getMetainfoValue());
+      } else if (-1 != entity.getMetainfoName().indexOf("redhat6")) {
+        foundRedhat6 = true;
+        Assert.assertEquals(localRepoUrl, entity.getMetainfoValue());
+      } else {
+        Assert.assertFalse(localRepoUrl.equals(entity.getMetainfoValue()));
+      }
+    }
+    Assert.assertTrue(foundCentos6);
+    Assert.assertTrue(foundRedhat6);
     
   }
   


Mime
View raw message