This is an automated email from the ASF dual-hosted git repository.

jluniya pushed a commit to branch branch-feature-AMBARI-14714
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/branch-feature-AMBARI-14714 by 
this push:
     new 8bcb392  AMBARI-23136: Continued: update execution_command to add two 
new apis (#891)
8bcb392 is described below

commit 8bcb39210033a25b0b8bb18e33d083d899899f80
Author: sduan <sd...@hortonworks.com>
AuthorDate: Thu Apr 5 23:50:17 2018 -0700

    AMBARI-23136: Continued: update execution_command to add two new apis (#891)
    
    * AMBARI-23136: Continued: update execution_command to add two new apis
    
    * AMBARI-23136: Continued: update execution_command to add two new apis
---
 .../execution_command/execution_command.py         | 41 ++++++++++++++++++++--
 .../libraries/execution_command/module_configs.py  | 34 ++++++++++++++----
 .../src/test/python/TestExecutionCommand.py        | 24 +++++++++++--
 ambari-common/src/test/python/command.json         | 10 ++++--
 4 files changed, 96 insertions(+), 13 deletions(-)

diff --git 
a/ambari-common/src/main/python/resource_management/libraries/execution_command/execution_command.py
 
b/ambari-common/src/main/python/resource_management/libraries/execution_command/execution_command.py
index f1bef79..f6b52d7 100644
--- 
a/ambari-common/src/main/python/resource_management/libraries/execution_command/execution_command.py
+++ 
b/ambari-common/src/main/python/resource_management/libraries/execution_command/execution_command.py
@@ -36,7 +36,7 @@ class ExecutionCommand(object):
     :param command: json string or a python dict object
     """
     self._execution_command = command
-    self._module_configs = 
module_configs.ModuleConfigs(self.__get_value("configurations"))
+    self._module_configs = 
module_configs.ModuleConfigs(self.__get_value("configurations"), 
self.__get_value("configurationAttributes"))
 
   def __get_value(self, key, default_value=None):
     """
@@ -54,6 +54,15 @@ class ExecutionCommand(object):
     except:
       return default_value
 
+  def get_value(self, query_string, default_value=None):
+    """
+    Query config attribute from execution_command directly
+    :param query_string: full query key string
+    :param default_value: if key does not exist, return default value
+    :return: config attribute
+    """
+    return self.__get_value(query_string, default_value)
+
   """
   Global variables section
   """
@@ -80,6 +89,12 @@ class ExecutionCommand(object):
   def get_cluster_name(self):
     return self.__get_value("clusterName")
 
+  def get_repository_file(self):
+    return self.__get_value("repositoryFile")
+
+  def get_local_components(self):
+    return self.__get_value("localComponents", [])
+
   """
   Ambari variables section
   """
@@ -231,10 +246,32 @@ class ExecutionCommand(object):
   def need_refresh_topology(self):
     return self.__get_value('commandParams/refresh_topology', False)
 
+  def check_only_update_files(self):
+    return self.__get_value('commandParams/update_files_only', False)
+
 
   """
   Role related variables section
   """
 
   def is_upgrade_suspended(self):
-    return self.__get_value('roleParams/upgrade_suspended', False)
\ No newline at end of file
+    return self.__get_value('roleParams/upgrade_suspended', False)
+
+  """
+  Cluster Host Info
+  """
+
+  def get_component_hosts(self, component_name):
+    key = "clusterHostInfo/" + component_name + "_hosts"
+    if component_name == "oozie_server":
+      key = "clusterHostInfo/" + component_name
+    return self.__get_value(key, [])
+
+  def get_all_hosts(self):
+    return self.__get_value('clusterHostInfo/all_hosts', [])
+
+  def get_all_racks(self):
+    return self.__get_value('clusterHostInfo/all_racks', [])
+
+  def get_all_ipv4_ips(self):
+    return self.__get_value('clusterHostInfo/all_ipv4_ips', [])
\ No newline at end of file
diff --git 
a/ambari-common/src/main/python/resource_management/libraries/execution_command/module_configs.py
 
b/ambari-common/src/main/python/resource_management/libraries/execution_command/module_configs.py
index 967449f..d315b50 100644
--- 
a/ambari-common/src/main/python/resource_management/libraries/execution_command/module_configs.py
+++ 
b/ambari-common/src/main/python/resource_management/libraries/execution_command/module_configs.py
@@ -23,18 +23,40 @@ __all__ = ["ModuleConfigs"]
 
 class ModuleConfigs(object):
   """
-  This class maps to "/configurations" block in command.json which includes 
configuration information of a service
+  This class maps to "/configurations" and "/configurationAttributes in 
command.json which includes configuration information of a service
   """
 
-  def __init__(self, config):
-    self.__module_configs = config
+  def __init__(self, configs, configAttributes):
+    self.__module_configs = configs
+    self.__module_config_attributes = configAttributes
 
-  def get_properties(self, module_name, config_type, property_names):
-    return map(lambda property_name: self.get_property_value(module_name, 
config_type, property_name), property_names)
+  def get_all_attributes(self, module_name, config_type):
+    try:
+      return self.__module_config_attributes[config_type]
+    except:
+      return {}
+
+  def get_all_properties(self, module_name, config_type):
+    try:
+      return self.__module_configs[config_type]
+    except:
+      return {}
+
+  def get_properties(self, module_name, config_type, property_names, 
default=None):
+    properties = {}
+    try:
+      for property_name in property_names:
+        properties[property_name] = self.get_property_value(module_name, 
config_type, property_name, default)
+    except:
+      return {}
+    return properties
 
   def get_property_value(self, module_name, config_type, property_name, 
default=None):
     try:
-      return self.__module_configs[config_type][property_name]
+      if property_name:
+        return self.__module_configs[config_type][property_name]
+      else:
+        return self.__module_configs[config_type]
     except:
       return default
 
diff --git a/ambari-common/src/test/python/TestExecutionCommand.py 
b/ambari-common/src/test/python/TestExecutionCommand.py
index 79da47f..824e2f0 100644
--- a/ambari-common/src/test/python/TestExecutionCommand.py
+++ b/ambari-common/src/test/python/TestExecutionCommand.py
@@ -40,6 +40,14 @@ class TestExecutionCommand(TestCase):
     module_name = self.__execution_command.get_module_name()
     self.assertEquals(module_name, "ZOOKEEPER")
 
+  def test_get_oozie_server_hosts(self):
+    oozie_server = self.__execution_command.get_component_hosts('oozie_server')
+    self.assertEqual(oozie_server, 'host2')
+
+  def test_get_ganglia_server_hosts(self):
+    ganglia_server_hosts = 
self.__execution_command.get_component_hosts('ganglia_server')
+    self.assertEqual(ganglia_server_hosts, 'host1')
+
   def test_get_module_configs(self):
     module_configs = self.__execution_command.get_module_configs()
     self.assertNotEquals(module_configs, None)
@@ -49,12 +57,22 @@ class TestExecutionCommand(TestCase):
     self.assertEquals(zookeeper_client_port_fake, None)
     zookeeper_client_port_default_value = 
module_configs.get_property_value("zookeeper", "zoo.cfg", "clientPort1", 1111)
     self.assertEquals(int(zookeeper_client_port_default_value), 1111)
-    zookeeper_empty_value = module_configs.get_property_value("zookeeper", 
"zoo_fake", "", {})
+    zookeeper_empty_value = module_configs.get_all_properties("zookeeper", 
"zoo_fake")
     self.assertEquals(zookeeper_empty_value, {})
     zookeeper_log_max_backup_size = 
module_configs.get_property_value('zookeeper', 'zookeeper-log4j',
                                                                       
'zookeeper_log_max_backup_size', 10)
     self.assertEquals(zookeeper_log_max_backup_size, 10)
+    properties = module_configs.get_properties("zookeeper", "zoo.cfg", 
['clientPort', 'dataDir', 'fake'])
+    self.assertEqual(int(properties.get('clientPort')), 2181)
+    self.assertEqual(properties.get('fake'), None)
 
   def test_get_stack_name(self):
-    stack_name = self.__execution_command.get_stack_name()
-    self.assertEquals(stack_name, "HDPCORE")
\ No newline at end of file
+    stack_name = self.__execution_command.get_mpack_name()
+    self.assertEquals(stack_name, "HDPCORE")
+
+  def test_access_to_module_configs(self):
+    module_configs = self.__execution_command.get_module_configs()
+    is_zoo_cfg_there = module_configs.get_property_value("zookeeper", 
"zoo.cfg", "") is not None
+    self.assertTrue(is_zoo_cfg_there)
+    zoo_cfg = module_configs.get_property_value("zookeeper", "zoo.cfg", "")
+    self.assertTrue(isinstance(zoo_cfg, dict))
\ No newline at end of file
diff --git a/ambari-common/src/test/python/command.json 
b/ambari-common/src/test/python/command.json
index 220a85c..b54f3df 100644
--- a/ambari-common/src/test/python/command.json
+++ b/ambari-common/src/test/python/command.json
@@ -83,11 +83,17 @@
       "zk_user": "zookeeper"
     }
   },
-  "hostLevelParams": {
+  "clusterLevelParams": {
     "stack_name": "HDPCORE",
     "group_list": "[\"hdfs\",\"users\"]",
-    "host_sys_prepped": "false",
     "jdk_name": "jdk-8u112-linux-x64.tar.gz",
     "stack_version": "1.0.0-b141"
+  },
+  "ambariLevelParams": {
+    "host_sys_prepped": "false"
+  },
+  "clusterHostInfo": {
+    "ganglia_server_hosts": "host1",
+    "oozie_server": "host2"
   }
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
jlun...@apache.org.

Reply via email to