AMBARI-18444. On restarting service using APIs in Ambari, Ambari still says 
that service needs to be restarted on the UI (aonishuk)


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

Branch: refs/heads/branch-2.5
Commit: feb0dda30e6178d1c5cd7ed6bdd12d550f4312fa
Parents: 5d2325b
Author: Andrew Onishuk <aonis...@hortonworks.com>
Authored: Thu Sep 22 15:38:49 2016 +0300
Committer: Andrew Onishuk <aonis...@hortonworks.com>
Committed: Thu Sep 22 15:38:49 2016 +0300

----------------------------------------------------------------------
 .../src/main/python/ambari_agent/ActionQueue.py |  3 +-
 .../test/python/ambari_agent/TestActionQueue.py | 58 ++++++++++++++++++++
 2 files changed, 60 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/feb0dda3/ambari-agent/src/main/python/ambari_agent/ActionQueue.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/ActionQueue.py 
b/ambari-agent/src/main/python/ambari_agent/ActionQueue.py
index 064e4f0..f104939 100644
--- a/ambari-agent/src/main/python/ambari_agent/ActionQueue.py
+++ b/ambari-agent/src/main/python/ambari_agent/ActionQueue.py
@@ -65,6 +65,7 @@ class ActionQueue(threading.Thread):
   ROLE_COMMAND_STOP = 'STOP'
   ROLE_COMMAND_CUSTOM_COMMAND = 'CUSTOM_COMMAND'
   CUSTOM_COMMAND_RESTART = 'RESTART'
+  CUSTOM_COMMAND_START = ROLE_COMMAND_START
 
   IN_PROGRESS_STATUS = 'IN_PROGRESS'
   COMPLETED_STATUS = 'COMPLETED'
@@ -417,7 +418,7 @@ class ActionQueue(threading.Thread):
              (command['roleCommand'] == self.ROLE_COMMAND_INSTALL and 
component in LiveStatus.CLIENT_COMPONENTS) or
                (command['roleCommand'] == self.ROLE_COMMAND_CUSTOM_COMMAND and
                   'custom_command' in command['hostLevelParams'] and
-                      command['hostLevelParams']['custom_command'] == 
self.CUSTOM_COMMAND_RESTART)):
+                      command['hostLevelParams']['custom_command'] in 
(self.CUSTOM_COMMAND_RESTART, self.CUSTOM_COMMAND_START))):
         configHandler.write_actual_component(command['role'],
                                              command['configurationTags'])
         if 'clientsToUpdateConfigs' in command['hostLevelParams'] and 
command['hostLevelParams']['clientsToUpdateConfigs']:

http://git-wip-us.apache.org/repos/asf/ambari/blob/feb0dda3/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 1805c9a..7d04d42 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py
@@ -200,6 +200,19 @@ class TestActionQueue(TestCase):
     'hostLevelParams':{'custom_command': 'RESTART'}
   }
 
+  datanode_start_custom_command = {
+    'commandType': 'EXECUTION_COMMAND',
+    'role': u'DATANODE',
+    'roleCommand': u'CUSTOM_COMMAND',
+    'commandId': '1-1',
+    'taskId': 9,
+    'clusterName': u'cc',
+    'serviceName': u'HDFS',
+    'configurations':{'global' : {}},
+    'configurationTags':{'global' : { 'tag': 'v123' }},
+    'hostLevelParams':{'custom_command': 'START'}
+  }
+
   status_command_for_alerts = {
     "serviceName" : 'FLUME',
     "commandType" : "STATUS_COMMAND",
@@ -776,6 +789,51 @@ class TestActionQueue(TestCase):
     self.assertFalse(write_client_components_mock.called)
 
   @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = 
os_distro_value))
+  @patch.object(ActualConfigHandler, "write_client_components")
+  @patch.object(ActualConfigHandler, "write_actual_component")
+  @patch.object(CustomServiceOrchestrator, "runCommand")
+  @patch("CommandStatusDict.CommandStatusDict")
+  @patch.object(ActionQueue, "status_update_callback")
+  def test_store_configuration_tags_on_custom_start_command(self, 
status_update_callback_mock,
+                                    command_status_dict_mock,
+                                    cso_runCommand_mock, 
write_actual_component_mock, write_client_components_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
+
+    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(self.datanode_start_custom_command)
+    report = actionQueue.result()
+    expected = {'status': 'COMPLETED',
+                'configurationTags': {'global': {'tag': 'v123'}},
+                'stderr': 'stderr',
+                'stdout': 'out\n\nCommand completed successfully!\n',
+                'clusterName': u'cc',
+                'structuredOut': '""',
+                'roleCommand': u'CUSTOM_COMMAND',
+                'serviceName': u'HDFS',
+                'role': u'DATANODE',
+                'actionId': '1-1',
+                'taskId': 9,
+                'customCommand': 'START',
+                'exitCode': 0}
+    self.assertEqual(len(report['reports']), 1)
+    self.assertEqual(expected, report['reports'][0])
+
+    # Configuration tags should be updated on custom start 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(CustomServiceOrchestrator, "requestComponentStatus")
   @patch.object(CustomServiceOrchestrator, "requestComponentSecurityState")

Reply via email to