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 2017/01/18 15:49:05 UTC

ambari git commit: AMBARI-19585. Client config tags may not be saved by agent (Attila Doroszlai via magyari_sandor)

Repository: ambari
Updated Branches:
  refs/heads/trunk d7f1e8c00 -> 753a5b036


AMBARI-19585. Client config tags may not be saved by agent (Attila Doroszlai via magyari_sandor)


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

Branch: refs/heads/trunk
Commit: 753a5b0362c53b1d8677ff5cf0806ac1058baf4b
Parents: d7f1e8c
Author: Attila Doroszlai <ad...@hortonworks.com>
Authored: Wed Jan 18 16:42:44 2017 +0100
Committer: Sandor Magyari <sm...@hortonworks.com>
Committed: Wed Jan 18 16:42:44 2017 +0100

----------------------------------------------------------------------
 .../src/main/python/ambari_agent/Controller.py  | 20 +++++++--
 .../test/python/ambari_agent/TestActionQueue.py | 43 ++++++++++++++++++++
 .../test/python/ambari_agent/TestController.py  | 20 +++++----
 3 files changed, 72 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/753a5b03/ambari-agent/src/main/python/ambari_agent/Controller.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/Controller.py b/ambari-agent/src/main/python/ambari_agent/Controller.py
index d00ffae..6370715 100644
--- a/ambari-agent/src/main/python/ambari_agent/Controller.py
+++ b/ambari-agent/src/main/python/ambari_agent/Controller.py
@@ -246,6 +246,8 @@ class Controller(threading.Thread):
     else:
       """Only add to the queue if not empty list """
       logger.info("Adding %s commands. Heartbeat id = %s", len(commands), self.responseId)
+      if 'clusterName' in commands[0].keys():
+        self.updateComponents(commands[0]['clusterName'])
       self.actionQueue.put(commands)
 
   def addToStatusQueue(self, commands):
@@ -253,7 +255,7 @@ class Controller(threading.Thread):
       logger.debug("No status commands received from %s", self.serverHostname)
     else:
       logger.info("Adding %s status commands. Heartbeat id = %s", len(commands), self.responseId)
-      if not LiveStatus.SERVICES:
+      if 'clusterName' in commands[0].keys():
         self.updateComponents(commands[0]['clusterName'])
       self.recovery_manager.process_status_commands(commands)
       self.actionQueue.put_status(commands)
@@ -568,19 +570,29 @@ class Controller(threading.Thread):
 
 
   def updateComponents(self, cluster_name):
+    if LiveStatus.SERVICES:
+      return
+
     logger.debug("Updating components map of cluster " + cluster_name)
 
     # May throw IOError on server connection error
     response = self.sendRequest(self.componentsUrl + cluster_name, None)
     logger.debug("Response from %s was %s", self.serverHostname, str(response))
 
+    services, client_components, server_components = [], [], []
     for service, components in response['components'].items():
-      LiveStatus.SERVICES.append(service)
+      services.append(service)
       for component, category in components.items():
+        service_component = {"serviceName": service, "componentName": component}
         if category == 'CLIENT':
-          LiveStatus.CLIENT_COMPONENTS.append({"serviceName": service, "componentName": component})
+          client_components.append(service_component)
         else:
-          LiveStatus.COMPONENTS.append({"serviceName": service, "componentName": component})
+          server_components.append(service_component)
+
+    LiveStatus.SERVICES = services
+    LiveStatus.CLIENT_COMPONENTS = client_components
+    LiveStatus.COMPONENTS = server_components
+
     logger.debug("Components map updated")
     logger.debug("LiveStatus.SERVICES" + str(LiveStatus.SERVICES))
     logger.debug("LiveStatus.CLIENT_COMPONENTS" + str(LiveStatus.CLIENT_COMPONENTS))

http://git-wip-us.apache.org/repos/asf/ambari/blob/753a5b03/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py b/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py
index d4f5436..9fefefb 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py
@@ -930,6 +930,49 @@ class TestActionQueue(TestCase):
     self.assertTrue(write_actual_component_mock.called)
 
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
+  @patch.object(ActualConfigHandler, "write_actual_component")
+  @patch.object(CustomServiceOrchestrator, "runCommand")
+  @patch("CommandStatusDict.CommandStatusDict")
+  @patch.object(ActionQueue, "status_update_callback")
+  def test_store_config_tags_on_install_client_command(self, status_update_callback_mock,
+      command_status_dict_mock,
+      cso_runCommand_mock, write_actual_component_mock):
+
+    custom_service_orchestrator_execution_result_dict = {
+      'stdout': 'out',
+      'stderr': 'stderr',
+      'structuredOut' : '',
+      'exitcode' : 0
+    }
+    cso_runCommand_mock.return_value = custom_service_orchestrator_execution_result_dict
+
+    tez_client_install_command = {
+      'commandType': 'EXECUTION_COMMAND',
+      'role': u'TEZ_CLIENT',
+      'roleCommand': u'INSTALL',
+      'commandId': '1-1',
+      'taskId': 9,
+      'clusterName': u'cc',
+      'serviceName': u'TEZ',
+      'configurations': {'global' : {}},
+      'configurationTags': {'global' : { 'tag': 'v123' }},
+      'hostLevelParams': {}
+    }
+    LiveStatus.CLIENT_COMPONENTS = ({'serviceName': 'TEZ', 'componentName': 'TEZ_CLIENT'}, )
+
+    config = AmbariConfig()
+    tempdir = tempfile.gettempdir()
+    config.set('agent', 'prefix', tempdir)
+    config.set('agent', 'cache_dir', "/var/lib/ambari-agent/cache")
+    config.set('agent', 'tolerate_download_failures', "true")
+    dummy_controller = MagicMock()
+    actionQueue = ActionQueue(config, dummy_controller)
+    actionQueue.execute_command(tez_client_install_command)
+
+    # Configuration tags should be updated on install client command
+    self.assertTrue(write_actual_component_mock.called)
+
+  @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
   @patch.object(ActionQueue, "status_update_callback")
   @patch.object(ActionQueue, "execute_command")
   @patch.object(LiveStatus, "build")

http://git-wip-us.apache.org/repos/asf/ambari/blob/753a5b03/ambari-agent/src/test/python/ambari_agent/TestController.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestController.py b/ambari-agent/src/test/python/ambari_agent/TestController.py
index b47af03..663e215 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestController.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestController.py
@@ -148,13 +148,19 @@ class TestController(unittest.TestCase):
 
   @patch("pprint.pformat")
   def test_addToQueue(self, pformatMock):
-
     actionQueue = MagicMock()
+    updateComponents = Mock()
     self.controller.actionQueue = actionQueue
+    self.controller.updateComponents = updateComponents
+
     self.controller.addToQueue(None)
     self.assertFalse(actionQueue.put.called)
-    self.controller.addToQueue("cmd")
+    self.assertFalse(updateComponents.called)
+
+    commands = ambari_simplejson.loads('[{"clusterName":"dummy_cluster"}]')
+    self.controller.addToQueue(commands)
     self.assertTrue(actionQueue.put.called)
+    self.assertTrue(updateComponents.called)
 
 
   @patch("pprint.pformat")
@@ -169,19 +175,19 @@ class TestController(unittest.TestCase):
     process_status_commands = MagicMock(name="process_status_commands")
     self.controller.recovery_manager.process_status_commands = process_status_commands
 
-    updateComponents = Mock()
-    self.controller.updateComponents = updateComponents
+    sendRequest = MagicMock(return_value={'components':{}})
+    self.controller.sendRequest = sendRequest
     self.controller.addToStatusQueue(None)
     self.assertFalse(actionQueue.put_status.called)
-    self.assertFalse(updateComponents.called)
+    self.assertFalse(sendRequest.called)
     self.controller.addToStatusQueue(commands)
     self.assertTrue(actionQueue.put_status.called)
-    self.assertFalse(updateComponents.called)
+    self.assertFalse(sendRequest.called)
     LiveStatus_mock.SERVICES = []
     LiveStatus_mock.CLIENT_COMPONENTS = []
     LiveStatus_mock.COMPONENTS = []
     self.controller.addToStatusQueue(commands)
-    self.assertTrue(updateComponents.called)
+    self.assertTrue(sendRequest.called)
     self.assertTrue(actionQueue.put_status.called)
     self.assertTrue(process_status_commands.called)