Преглед на файлове

AMBARI-6749 - Flume service should be in STARTED state when no agents configured (jonathanhurley)

Jonathan Hurley преди 10 години
родител
ревизия
5a0b5810fe

+ 6 - 4
ambari-server/src/main/resources/stacks/HDP/2.0.6/services/FLUME/package/scripts/flume_handler.py

@@ -57,12 +57,13 @@ class FlumeHandler(Script):
     env.set_params(params)
 
     processes = flume_status()
+    expected_agents = find_expected_agent_names()
 
     json = {}
     json['processes'] = processes
     json['alerts'] = []
 
-    if len(processes) == 0 and len(find_expected_agent_names()) == 0:
+    if len(processes) == 0 and len(expected_agents) == 0:
       alert = {}
       alert['name'] = 'flume_agent'
       alert['label'] = 'Flume Agent process'
@@ -87,9 +88,10 @@ class FlumeHandler(Script):
 
     self.put_structured_out(json)
 
-    if 0 == len(processes):
-      raise ComponentIsNotRunning()
-    else:
+    # only throw an exception if there are agents defined and there is a 
+    # problem with the processes; if there are no agents defined, then 
+    # the service should report STARTED (green) instead of INSTALLED (red)
+    if len(expected_agents) > 0:
       for proc in processes:
         if not proc.has_key('status') or proc['status'] == 'NOT_RUNNING':
           raise ComponentIsNotRunning()

+ 22 - 0
ambari-server/src/test/python/stacks/2.0.6/FLUME/test_flume.py

@@ -124,6 +124,28 @@ class TestFlumeHandler(RMFTestCase):
     self.assertTrue(struct_out.has_key('alerts'))
 
     self.assertNoMoreResources()
+    
+  @patch("resource_management.libraries.script.Script.put_structured_out")
+  @patch("glob.glob")
+  @patch("sys.exit")
+  def test_status_no_agents(self, sys_exit_mock, glob_mock, structured_out_mock):
+    glob_mock.return_value = []
+
+    try:
+      self.executeScript("2.0.6/services/FLUME/package/scripts/flume_handler.py",
+       classname = "FlumeHandler",
+       command = "status",
+       config_file="default.json")
+    except:
+      self.fail("Exception not expected when no agents are defined")
+      
+    self.assertTrue(structured_out_mock.called)
+
+    # call_args[0] is a tuple, whose first element is the actual call argument
+    struct_out = structured_out_mock.call_args[0][0]
+    self.assertTrue(struct_out.has_key('processes'))
+    self.assertTrue(struct_out.has_key('alerts'))
+    self.assertNoMoreResources()    
 
   def assert_configure_default(self):