You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by fb...@apache.org on 2015/03/18 17:27:37 UTC
ambari git commit: AMBARI-10069 Lagging child processes block the
Agent execution queue
Repository: ambari
Updated Branches:
refs/heads/trunk 7d4fdd9be -> 21602caf6
AMBARI-10069 Lagging child processes block the Agent execution queue
Fixed Windows-specific process kill arguments. Refactored OS-specific routine dispatch. Updated unit tests.
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/21602caf
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/21602caf
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/21602caf
Branch: refs/heads/trunk
Commit: 21602caf64cfc88381de882b4ed566711342ab22
Parents: 7d4fdd9
Author: Florian Barca <fb...@hortonworks.com>
Authored: Wed Mar 18 09:27:26 2015 -0700
Committer: Florian Barca <fb...@hortonworks.com>
Committed: Wed Mar 18 09:27:26 2015 -0700
----------------------------------------------------------------------
.../test/python/ambari_agent/TestStatusCheck.py | 19 +++++--
.../src/main/python/ambari_commons/shell.py | 53 ++++++++++----------
.../HIVE/0.12.0.2.0/metainfo.xml | 2 +-
3 files changed, 43 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/21602caf/ambari-agent/src/test/python/ambari_agent/TestStatusCheck.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestStatusCheck.py b/ambari-agent/src/test/python/ambari_agent/TestStatusCheck.py
index a872e7f..32be4a8 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestStatusCheck.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestStatusCheck.py
@@ -21,11 +21,19 @@ import string
import random
import os
from unittest import TestCase
+from ambari_commons import OSCheck
from ambari_agent.StatusCheck import StatusCheck
-import AmbariConfig
import logging
-from mock.mock import patch, Mock
+from mock.mock import patch
+from mock.mock import MagicMock
+
+from only_for_platform import only_for_platform, get_platform, PLATFORM_LINUX, PLATFORM_WINDOWS
+
+if get_platform() != PLATFORM_WINDOWS:
+ os_distro_value = ('Suse','11','Final')
+else:
+ os_distro_value = ('win2012serverr2','6.3','WindowsServer')
USERNAME_LENGTH=10
USERNAME_CHARS=string.ascii_uppercase +string.ascii_lowercase + string.digits + '-_'
@@ -81,6 +89,7 @@ class TestStatusCheck(TestCase):
# Ensure that status checker return True for running process
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(StatusCheck, 'getIsLive')
def test_live(self, get_is_live_mock):
@@ -96,7 +105,8 @@ class TestStatusCheck(TestCase):
status = statusCheck.getStatus(COMPONENT_LIVE)
self.assertEqual(status, True)
-
+
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(logger, 'info')
def test_dont_relog_serToPidDict(self, logger_info_mock):
TestStatusCheck.timesLogged = 0
@@ -119,6 +129,7 @@ class TestStatusCheck(TestCase):
# Ensure that status checker return True for running process even if multiple
# pids for a service component exist
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(StatusCheck, 'getIsLive')
def test_live_if_multiple_pids(self, get_is_live_mock):
@@ -141,6 +152,7 @@ class TestStatusCheck(TestCase):
# Ensure that status checker prints error message if there is no linux user
# for service, which pid depends on user
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(StatusCheck, 'getIsLive')
@patch.object(logger, "error")
def test_no_user_mapping(self, error_mock, get_is_live_mock):
@@ -160,6 +172,7 @@ class TestStatusCheck(TestCase):
self.assertTrue(error_mock.called)
# Ensure that status checker return False for dead process
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(StatusCheck, 'getIsLive')
def test_dead(self, get_is_live_mock):
statusCheck = StatusCheck(self.serviceToPidDict, self.pidPathVars,
http://git-wip-us.apache.org/repos/asf/ambari/blob/21602caf/ambari-common/src/main/python/ambari_commons/shell.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/shell.py b/ambari-common/src/main/python/ambari_commons/shell.py
index 42b60f9..4531cf9 100644
--- a/ambari-common/src/main/python/ambari_commons/shell.py
+++ b/ambari-common/src/main/python/ambari_commons/shell.py
@@ -30,11 +30,8 @@ import traceback
import pprint
import platform
-if platform.system() != "Windows":
- try:
- import pwd
- except ImportError:
- import winpwd as pwd
+from ambari_commons import OSConst
+from ambari_commons.os_family_impl import OsFamilyImpl, OsFamilyFuncImpl
logger = logging.getLogger()
@@ -62,11 +59,19 @@ class _dict_to_object:
# windows specific code
-def _kill_process_with_children_windows(parent_pid):
- shellRunner().run(["taskkill", "/T", "/PID", "{0}".format(parent_pid)])
+@OsFamilyFuncImpl(os_family=OSConst.WINSRV_FAMILY)
+def kill_process_with_children(parent_pid):
+ shellRunnerWindows().run(["taskkill", "/F", "/T", "/PID", "{0}".format(parent_pid)])
+class shellRunner(object):
+ def run(self, script, user=None):
+ pass
-class shellRunnerWindows:
+ def runPowershell(self, file=None, script_block=None, args=[]):
+ raise NotImplementedError()
+
+@OsFamilyImpl(os_family=OSConst.WINSRV_FAMILY)
+class shellRunnerWindows(shellRunner):
# Run any command
def run(self, script, user=None):
logger.warn("user argument ignored on windows")
@@ -100,7 +105,8 @@ class shellRunnerWindows:
#linux specific code
-def _kill_process_with_children_linux(parent_pid):
+@OsFamilyFuncImpl(os_family=OsFamilyImpl.DEFAULT)
+def kill_process_with_children(parent_pid):
def kill_tree_function(pid, signal):
'''
Kills process tree starting from a given pid.
@@ -143,9 +149,12 @@ def _changeUid():
logger.warn("can not switch user for running command.")
-class shellRunnerLinux:
+@OsFamilyImpl(os_family=OsFamilyImpl.DEFAULT)
+class shellRunnerLinux(shellRunner):
# Run any command
def run(self, script, user=None):
+ import pwd
+
try:
if user != None:
user = pwd.getpwnam(user)[2]
@@ -154,8 +163,7 @@ class shellRunnerLinux:
threadLocal.uid = user
except Exception:
logger.warn("can not switch user for RUN_COMMAND.")
- code = 0
-
+
cmd = script
if isinstance(script, list):
@@ -170,20 +178,11 @@ class shellRunnerLinux:
return {'exitCode': code, 'output': out, 'error': err}
-def kill_process_with_children(parent_pid):
- if platform.system() == "Windows":
- _kill_process_with_children_windows(parent_pid)
- else:
- _kill_process_with_children_linux(parent_pid)
-
+@OsFamilyFuncImpl(os_family=OSConst.WINSRV_FAMILY)
def changeUid():
- if not platform.system() == "Windows":
- try:
- os.setuid(threadLocal.uid)
- except Exception:
- logger.warn("can not switch user for running command.")
+ #No Windows implementation
+ pass
-if platform.system() == "Windows":
- shellRunner = shellRunnerWindows
-else:
- shellRunner = shellRunnerLinux
\ No newline at end of file
+@OsFamilyFuncImpl(os_family=OsFamilyImpl.DEFAULT)
+def changeUid():
+ _changeUid()
http://git-wip-us.apache.org/repos/asf/ambari/blob/21602caf/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/metainfo.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/metainfo.xml b/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/metainfo.xml
index b227710..d6d63fa 100644
--- a/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/metainfo.xml
+++ b/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/metainfo.xml
@@ -279,7 +279,7 @@
<commandScript>
<script>scripts/service_check.py</script>
<scriptType>PYTHON</scriptType>
- <timeout>300</timeout>
+ <timeout>120</timeout>
</commandScript>
<requiredServices>