You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2013/10/29 20:19:25 UTC

git commit: AMBARI-3523. Changes to support ambari agent to start and register on ubuntu (Arpit Gupta via mahadev)

Updated Branches:
  refs/heads/trunk 74d6a7f51 -> 99e0e02a0


AMBARI-3523. Changes to support ambari agent to start and register on ubuntu (Arpit Gupta via mahadev)


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

Branch: refs/heads/trunk
Commit: 99e0e02a0af1eb787f7c80e432c53f0d2d928a8c
Parents: 74d6a7f
Author: Mahadev Konar <ma...@apache.org>
Authored: Tue Oct 29 12:21:10 2013 -0700
Committer: Mahadev Konar <ma...@apache.org>
Committed: Tue Oct 29 12:21:10 2013 -0700

----------------------------------------------------------------------
 .../src/main/python/ambari_agent/HostInfo.py    | 24 ++++++++++++++------
 .../server/api/services/AmbariMetaInfo.java     | 13 +++++++----
 .../server/api/services/AmbariMetaInfoTest.java |  1 +
 3 files changed, 26 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/99e0e02a/ambari-agent/src/main/python/ambari_agent/HostInfo.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/HostInfo.py b/ambari-agent/src/main/python/ambari_agent/HostInfo.py
index e7e675f..696087c 100644
--- a/ambari-agent/src/main/python/ambari_agent/HostInfo.py
+++ b/ambari-agent/src/main/python/ambari_agent/HostInfo.py
@@ -47,7 +47,7 @@ class HostInfo:
 
   # List of live services checked for on the host, takes a map of plan strings
   DEFAULT_LIVE_SERVICES = [
-    {"redhat":"ntpd", "suse":"ntp"}
+    {"redhat":"ntpd", "suse":"ntp", "ubuntu":"ntp"}
   ]
 
   # Set of default users (need to be replaced with the configured user names)
@@ -102,8 +102,19 @@ class HostInfo:
   TIMEOUT_SECONDS = 60
   RESULT_UNAVAILABLE = "unable_to_determine"
 
-  IP_TBLS_IS_NOT_RUNNING = "iptables: Firewall is not running."
-
+  OS_NAME = platform.dist()[0].lower()
+  OS_UBUNTU = 'ubuntu'
+  # service cmd
+  SERVICE_CMD = "/sbin/service"
+  FIREWALL_SERVICE_NAME = "iptables"
+  FIREWALL_IS_NOT_RUNNING_MSG = "iptables: Firewall is not running."
+  # on ubuntu iptables service is called ufw
+  if OS_NAME == OS_UBUNTU:
+    SERVICE_CMD = "/usr/sbin/service"
+    FIREWALL_SERVICE_NAME = "ufw"
+    FIREWALL_IS_NOT_RUNNING_MSG = "ufw stop/waiting"
+
+  FIREWALL_STATUS_CMD = "%s %s status" % (SERVICE_CMD, FIREWALL_SERVICE_NAME)
   event = threading.Event()
   
   current_umask = -1
@@ -167,8 +178,7 @@ class HostInfo:
       svcCheckResult['status'] = "UNKNOWN"
       svcCheckResult['desc'] = ""
       try:
-        cmd = "/sbin/service " + serviceName + " status"
-        osStat = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE,
+        osStat = subprocess.Popen(shlex.split(self.FIREWALL_STATUS_CMD), stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
         out, err = osStat.communicate()
         if 0 != osStat.returncode:
@@ -277,9 +287,9 @@ class HostInfo:
   def checkIptables(self):
     iptablesIsRunning = False
     try:
-      iptables = subprocess.Popen(["/sbin/service", "iptables", "status"], stdout=subprocess.PIPE)
+      iptables = subprocess.Popen(self.FIREWALL_STATUS_CMD.split(), stdout=subprocess.PIPE)
       iptablesOut = iptables.communicate()[0]
-      if iptablesOut and len(iptablesOut) > 0 and not iptablesOut.strip() == self.IP_TBLS_IS_NOT_RUNNING:
+      if iptablesOut and len(iptablesOut) > 0 and not iptablesOut.strip() == self.FIREWALL_IS_NOT_RUNNING_MSG:
         iptablesIsRunning = True
     except:
       pass

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/99e0e02a/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 86266d3..f14afeb 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
@@ -50,6 +50,7 @@ import org.apache.ambari.server.state.stack.RepositoryXml.Os;
 import org.apache.ambari.server.state.stack.RepositoryXml.Repo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import java.util.Arrays;
 
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
@@ -72,6 +73,12 @@ public class AmbariMetaInfo {
   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";
+  // all the supported OS'es
+  private static final ArrayList<String> ALL_SUPPORTED_OS = new
+    ArrayList<String>(
+    Arrays.asList("centos5", "redhat5", "centos6", "redhat6", "oraclelinux5",
+      "oraclelinux6", "suse11", "sles11", "ubuntu12")
+  );
 
   public static final FilenameFilter FILENAME_FILTER = new FilenameFilter() {
     @Override
@@ -693,11 +700,7 @@ public class AmbariMetaInfo {
   }
 
   public boolean isOsSupported(String osType) {
-    return osType.equals("redhat5") || osType.equals("centos5") ||
-            osType.equals("oraclelinux5") ||
-            osType.equals("redhat6") || osType.equals("centos6") ||
-            osType.equals("oraclelinux6") ||
-            osType.equals("suse11") || osType.equals("sles11");
+    return ALL_SUPPORTED_OS.contains(osType);
   }
   
   private String generateRepoMetaKey(String stackName, String stackVersion,

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/99e0e02a/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 63a921d..5848c9f 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
@@ -435,6 +435,7 @@ public class AmbariMetaInfoTest {
     Assert.assertTrue(metaInfo.isOsSupported("oraclelinux6"));
     Assert.assertTrue(metaInfo.isOsSupported("suse11"));
     Assert.assertTrue(metaInfo.isOsSupported("sles11"));
+    Assert.assertTrue(metaInfo.isOsSupported("ubuntu12"));
     Assert.assertFalse(metaInfo.isOsSupported("windows"));
   }