Repository: ambari
Updated Branches:
  refs/heads/trunk 04fe46d74 -> 1cc4a20b3


AMBARI-15744. Webhcat Server failed to stop while stopping all the services. 
(stoader)


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

Branch: refs/heads/trunk
Commit: 1cc4a20b33157de8c547929321567911a13d8942
Parents: 04fe46d
Author: Toader, Sebastian <[email protected]>
Authored: Thu Apr 7 11:32:42 2016 +0200
Committer: Toader, Sebastian <[email protected]>
Committed: Thu Apr 7 11:33:31 2016 +0200

----------------------------------------------------------------------
 .../package/scripts/webhcat_service.py          | 14 +++--
 .../stacks/2.0.6/HIVE/test_webhcat_server.py    | 59 ++++++++++++++++++++
 2 files changed, 68 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1cc4a20b/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/webhcat_service.py
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/webhcat_service.py
 
b/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/webhcat_service.py
index 10e0990..487f078 100644
--- 
a/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/webhcat_service.py
+++ 
b/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/webhcat_service.py
@@ -55,14 +55,10 @@ def webhcat_service(action='start', upgrade_type=None):
       show_logs(params.hcat_log_dir, params.webhcat_user)
       raise
   elif action == 'stop':
-    daemon_cmd = format('{cmd} stop')
     try:
-      Execute(daemon_cmd,
-              user = params.webhcat_user,
-              environment = environ)
+      graceful_stop(cmd, environ)
     except:
       show_logs(params.hcat_log_dir, params.webhcat_user)
-      raise
 
     pid_expression = "`" + as_user(format("cat {webhcat_pid_file}"), 
user=params.webhcat_user) + "`"
     process_id_exists_command = format("ls {webhcat_pid_file} >/dev/null 2>&1 
&& ps -p {pid_expression} >/dev/null 2>&1")
@@ -85,3 +81,11 @@ def webhcat_service(action='start', upgrade_type=None):
     File(params.webhcat_pid_file,
          action="delete",
     )
+
+def graceful_stop(cmd, environ):
+  import params
+  daemon_cmd = format('{cmd} stop')
+
+  Execute(daemon_cmd,
+          user = params.webhcat_user,
+          environment = environ)

http://git-wip-us.apache.org/repos/asf/ambari/blob/1cc4a20b/ambari-server/src/test/python/stacks/2.0.6/HIVE/test_webhcat_server.py
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/python/stacks/2.0.6/HIVE/test_webhcat_server.py 
b/ambari-server/src/test/python/stacks/2.0.6/HIVE/test_webhcat_server.py
index 6fe49dc..86f185d 100644
--- a/ambari-server/src/test/python/stacks/2.0.6/HIVE/test_webhcat_server.py
+++ b/ambari-server/src/test/python/stacks/2.0.6/HIVE/test_webhcat_server.py
@@ -95,6 +95,36 @@ class TestWebHCatServer(RMFTestCase):
       self.assert_configure_secured()
       self.assertNoMoreResources()
 
+  @patch("webhcat_service.graceful_stop", new = 
MagicMock(side_effect=Exception))
+  def test_stop_graceful_stop_failed(self):
+    self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + 
"/scripts/webhcat_server.py",
+                       classname = "WebHCatServer",
+                       command = "stop",
+                       config_file="default.json",
+                       stack_version = self.STACK_VERSION,
+                       target = RMFTestCase.TARGET_COMMON_SERVICES
+                       )
+
+    self.assertResourceCalled('Execute', 'log_files=`find /var/log/webhcat 
-maxdepth 1 -type f` ; [ ! -z "$log_files" ] && tail -n 40 $log_files',
+                              logoutput = True,
+                              ignore_failures = True,
+                              user = 'hcat'
+                             )
+
+    self.assertResourceCalled('Execute', 'ambari-sudo.sh kill -9 
`ambari-sudo.sh su hcat -l -s /bin/bash -c \'[RMF_EXPORT_PLACEHOLDER]cat 
/var/run/webhcat/webhcat.pid\'`',
+                              not_if = "! (ls /var/run/webhcat/webhcat.pid 
>/dev/null 2>&1 && ps -p `ambari-sudo.sh su hcat -l -s /bin/bash -c 
'[RMF_EXPORT_PLACEHOLDER]cat /var/run/webhcat/webhcat.pid'` >/dev/null 2>&1) || 
( sleep 10 && ! (ls /var/run/webhcat/webhcat.pid >/dev/null 2>&1 && ps -p 
`ambari-sudo.sh su hcat -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]cat 
/var/run/webhcat/webhcat.pid'` >/dev/null 2>&1) )"
+                              )
+
+    self.assertResourceCalled('Execute', "! (ls /var/run/webhcat/webhcat.pid 
>/dev/null 2>&1 && ps -p `ambari-sudo.sh su hcat -l -s /bin/bash -c 
'[RMF_EXPORT_PLACEHOLDER]cat /var/run/webhcat/webhcat.pid'` >/dev/null 2>&1)",
+                              tries=20,
+                              try_sleep=3,
+                              )
+
+    self.assertResourceCalled('File', '/var/run/webhcat/webhcat.pid',
+                              action = ['delete'],
+                              )
+    self.assertNoMoreResources()
+
   def test_start_secured(self):
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + 
"/scripts/webhcat_server.py",
                        classname = "WebHCatServer",
@@ -139,6 +169,35 @@ class TestWebHCatServer(RMFTestCase):
     )
     self.assertNoMoreResources()
 
+  @patch("webhcat_service.graceful_stop", new = 
MagicMock(side_effect=Exception))
+  def test_stop_secured_graceful_stop_failed(self):
+    self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + 
"/scripts/webhcat_server.py",
+                       classname = "WebHCatServer",
+                       command = "stop",
+                       config_file="secured.json",
+                       stack_version = self.STACK_VERSION,
+                       target = RMFTestCase.TARGET_COMMON_SERVICES
+                       )
+
+    self.assertResourceCalled('Execute', 'log_files=`find /var/log/webhcat 
-maxdepth 1 -type f` ; [ ! -z "$log_files" ] && tail -n 40 $log_files',
+                              logoutput = True,
+                              ignore_failures = True,
+                              user = 'hcat'
+                              )
+    
+    self.assertResourceCalled('Execute', 'ambari-sudo.sh kill -9 
`ambari-sudo.sh su hcat -l -s /bin/bash -c \'[RMF_EXPORT_PLACEHOLDER]cat 
/var/run/webhcat/webhcat.pid\'`',
+                              not_if = "! (ls /var/run/webhcat/webhcat.pid 
>/dev/null 2>&1 && ps -p `ambari-sudo.sh su hcat -l -s /bin/bash -c 
'[RMF_EXPORT_PLACEHOLDER]cat /var/run/webhcat/webhcat.pid'` >/dev/null 2>&1) || 
( sleep 10 && ! (ls /var/run/webhcat/webhcat.pid >/dev/null 2>&1 && ps -p 
`ambari-sudo.sh su hcat -l -s /bin/bash -c '[RMF_EXPORT_PLACEHOLDER]cat 
/var/run/webhcat/webhcat.pid'` >/dev/null 2>&1) )"
+                              )
+
+    self.assertResourceCalled('Execute', "! (ls /var/run/webhcat/webhcat.pid 
>/dev/null 2>&1 && ps -p `ambari-sudo.sh su hcat -l -s /bin/bash -c 
'[RMF_EXPORT_PLACEHOLDER]cat /var/run/webhcat/webhcat.pid'` >/dev/null 2>&1)",
+                              tries=20,
+                              try_sleep=3,
+                              )
+    self.assertResourceCalled('File', '/var/run/webhcat/webhcat.pid',
+                              action = ['delete'],
+                              )
+    self.assertNoMoreResources()
+
   def assert_configure_default(self):
     self.assertResourceCalled('Directory', '/var/run/webhcat',
                               owner = 'hcat',

Reply via email to