You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2013/12/13 22:16:27 UTC
[2/2] git commit: AMBARI-4056. Add to service scripts some method to
determine service state(started/stopped) (dlysnichenko)
AMBARI-4056. Add to service scripts some method to determine service state(started/stopped) (dlysnichenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/fd9cd27a
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/fd9cd27a
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/fd9cd27a
Branch: refs/heads/trunk
Commit: fd9cd27a1abfbd3e93ea6560fa5a907295c1b0a8
Parents: 5d9f9ed
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Fri Dec 13 23:11:37 2013 +0200
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Fri Dec 13 23:15:11 2013 +0200
----------------------------------------------------------------------
.../src/main/python/ambari_agent/ActionQueue.py | 11 +-
.../ambari_agent/CustomServiceOrchestrator.py | 82 +++++++++--
.../src/main/python/ambari_agent/LiveStatus.py | 22 +--
.../main/python/ambari_agent/PythonExecutor.py | 12 +-
.../resource_management/core/exceptions.py | 16 +++
.../libraries/functions/__init__.py | 1 +
.../libraries/functions/check_process_status.py | 36 +++++
.../libraries/script/__init__.py | 3 +-
.../libraries/script/script.py | 16 ++-
.../test/python/ambari_agent/TestActionQueue.py | 20 ++-
.../TestCustomServiceOrchestrator.py | 72 +++++++++-
.../test/python/ambari_agent/TestLiveStatus.py | 12 ++
.../python/ambari_agent/TestPythonExecutor.py | 1 -
.../org/apache/ambari/server/RoleCommand.java | 9 ++
.../ambari/server/agent/ExecutionCommand.java | 1 +
.../ambari/server/agent/HeartbeatMonitor.java | 135 ++++++++++++-------
.../ambari/server/agent/StatusCommand.java | 24 ++++
.../stacks/HDP/1.3._/hooks/before-START.py | 30 +++++
.../GANGLIA/package/scripts/ganglia_monitor.py | 17 +++
.../GANGLIA/package/scripts/ganglia_server.py | 7 +
.../GANGLIA/package/scripts/status_params.py | 25 ++++
.../SQOOP/package/scripts/sqoop_client.py | 3 +
.../GANGLIA/package/scripts/ganglia_monitor.py | 17 +++
.../GANGLIA/package/scripts/ganglia_server.py | 7 +
.../GANGLIA/package/scripts/status_params.py | 25 ++++
.../services/HBASE/package/scripts/__init__.py | 2 -
.../services/HBASE/package/scripts/functions.py | 2 -
.../services/HBASE/package/scripts/hbase.py | 2 -
.../HBASE/package/scripts/hbase_client.py | 7 +-
.../HBASE/package/scripts/hbase_master.py | 10 +-
.../HBASE/package/scripts/hbase_regionserver.py | 8 +-
.../HBASE/package/scripts/hbase_service.py | 6 +-
.../services/HBASE/package/scripts/params.py | 5 +-
.../HBASE/package/scripts/service_check.py | 2 -
.../HBASE/package/scripts/status_params.py | 25 ++++
.../services/HIVE/package/scripts/__init__.py | 2 -
.../2.0._/services/HIVE/package/scripts/hcat.py | 2 -
.../HIVE/package/scripts/hcat_client.py | 6 +-
.../HIVE/package/scripts/hcat_service_check.py | 2 -
.../2.0._/services/HIVE/package/scripts/hive.py | 2 -
.../HIVE/package/scripts/hive_client.py | 7 +-
.../HIVE/package/scripts/hive_metastore.py | 10 +-
.../HIVE/package/scripts/hive_server.py | 11 +-
.../HIVE/package/scripts/hive_service.py | 4 +-
.../services/HIVE/package/scripts/mysql.py | 58 --------
.../HIVE/package/scripts/mysql_server.py | 37 ++++-
.../HIVE/package/scripts/mysql_service.py | 20 +--
.../services/HIVE/package/scripts/params.py | 17 +--
.../HIVE/package/scripts/service_check.py | 2 -
.../HIVE/package/scripts/status_params.py | 30 +++++
.../NAGIOS/package/scripts/nagios_server.py | 8 +-
.../services/NAGIOS/package/scripts/params.py | 7 +-
.../NAGIOS/package/scripts/status_params.py | 26 ++++
.../OOZIE/package/scripts/oozie_client.py | 3 +
.../OOZIE/package/scripts/oozie_server.py | 7 +-
.../services/OOZIE/package/scripts/params.py | 5 +-
.../OOZIE/package/scripts/status_params.py | 26 ++++
.../services/PIG/package/scripts/pig_client.py | 3 +
.../services/SQOOP/package/scripts/__init__.py | 2 -
.../services/SQOOP/package/scripts/params.py | 2 -
.../SQOOP/package/scripts/service_check.py | 2 -
.../services/SQOOP/package/scripts/sqoop.py | 2 -
.../SQOOP/package/scripts/sqoop_client.py | 5 +-
.../services/WEBHCAT/package/scripts/params.py | 5 +-
.../WEBHCAT/package/scripts/status_params.py | 26 ++++
.../WEBHCAT/package/scripts/webhcat_server.py | 5 +
.../ZOOKEEPER/package/scripts/params.py | 7 +-
.../ZOOKEEPER/package/scripts/status_params.py | 26 ++++
.../package/scripts/zookeeper_client.py | 4 +
.../package/scripts/zookeeper_server.py | 5 +
70 files changed, 820 insertions(+), 239 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/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 53af10a..516d380 100644
--- a/ambari-agent/src/main/python/ambari_agent/ActionQueue.py
+++ b/ambari-agent/src/main/python/ambari_agent/ActionQueue.py
@@ -210,9 +210,18 @@ class ActionQueue(threading.Thread):
globalConfig = configurations['global']
else:
globalConfig = {}
+
+ command_format = self.determine_command_format_version(command)
+
livestatus = LiveStatus(cluster, service, component,
globalConfig, self.config)
- result = livestatus.build()
+ component_status = None
+ if command_format == self.COMMAND_FORMAT_V2:
+ # For custom services, responsibility to determine service status is
+ # delegated to python scripts
+ component_status = self.customServiceOrchestrator.requestComponentStatus(command)
+
+ result = livestatus.build(forsed_component_status= component_status)
logger.debug("Got live status for component " + component + \
" of service " + str(service) + \
" of cluster " + str(cluster))
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py b/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py
index 932f9ec..21032fa 100644
--- a/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py
+++ b/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py
@@ -28,6 +28,7 @@ from AgentException import AgentException
from PythonExecutor import PythonExecutor
from AmbariConfig import AmbariConfig
import hostname
+from LiveStatus import LiveStatus
logger = logging.getLogger()
@@ -39,6 +40,7 @@ class CustomServiceOrchestrator():
"""
SCRIPT_TYPE_PYTHON = "PYTHON"
+ COMMAND_NAME_STATUS = "STATUS"
CUSTOM_ACTION_COMMAND = 'ACTIONEXECUTE'
PRE_HOOK_PREFIX="before"
@@ -49,16 +51,43 @@ class CustomServiceOrchestrator():
self.tmp_dir = config.get('agent', 'prefix')
self.file_cache = FileCache(config)
self.python_executor = PythonExecutor(self.tmp_dir, config)
+ self.status_commands_stdout = os.path.join(self.tmp_dir,
+ 'status_command_stdout.txt')
+ self.status_commands_stderr = os.path.join(self.tmp_dir,
+ 'status_command_stderr.txt')
+ # Clean up old status command files if any
+ try:
+ os.unlink(self.status_commands_stdout)
+ os.unlink(self.status_commands_stderr)
+ except OSError:
+ pass # Ignore fail
- def runCommand(self, command, tmpoutfile, tmperrfile):
+ def runCommand(self, command, tmpoutfile, tmperrfile, forsed_command_name = None,
+ override_output_files = True):
+ """
+ forsed_command_name may be specified manually. In this case, value, defined at
+ command json, is ignored.
+ """
try:
- component_name = command['role']
+ try:
+ component_name = command['role']
+ except KeyError:
+ # For status commands and (maybe) custom actions component name
+ # is stored at another location
+ component_name = command['componentName']
script_type = command['commandParams']['script_type']
script = command['commandParams']['script']
- command_name = command['roleCommand']
timeout = int(command['commandParams']['command_timeout'])
- task_id = command['taskId']
+ task_id = "status"
+ try:
+ task_id = command['taskId']
+ command_name = command['roleCommand']
+ except KeyError:
+ pass # Status commands have no taskId
+
+ if forsed_command_name is not None: # If not supplied as an argument
+ command_name = forsed_command_name
if command_name == self.CUSTOM_ACTION_COMMAND:
base_dir = self.config.get('python', 'custom_actions_dir')
@@ -74,6 +103,7 @@ class CustomServiceOrchestrator():
script_path = self.resolve_script_path(base_dir, script, script_type)
script_tuple = (script_path, base_dir)
+
tmpstrucoutfile = os.path.join(self.tmp_dir,
"structured-out-{0}.json".format(task_id))
if script_type.upper() != self.SCRIPT_TYPE_PYTHON:
@@ -89,12 +119,16 @@ class CustomServiceOrchestrator():
py_file_list = [pre_hook_tuple, script_tuple, post_hook_tuple]
# filter None values
filtered_py_file_list = [i for i in py_file_list if i]
+
# Executing hooks and script
ret = None
for py_file, current_base_dir in filtered_py_file_list:
script_params = [command_name, json_path, current_base_dir]
ret = self.python_executor.run_file(py_file, script_params,
- tmpoutfile, tmperrfile, timeout, tmpstrucoutfile)
+ tmpoutfile, tmperrfile, timeout,
+ tmpstrucoutfile, override_output_files)
+ # Next run_file() invocations should always append to current output
+ override_output_files = False
if ret['exitcode'] != 0:
break
@@ -105,7 +139,7 @@ class CustomServiceOrchestrator():
exc_type, exc_obj, exc_tb = sys.exc_info()
message = "Catched an exception while executing "\
"custom service command: {0}: {1}".format(exc_type, exc_obj)
- logger.error(message)
+ logger.exception(message)
ret = {
'stdout' : message,
'stderr' : message,
@@ -115,6 +149,24 @@ class CustomServiceOrchestrator():
return ret
+ def requestComponentStatus(self, command):
+ """
+ Component status is determined by exit code, returned by runCommand().
+ Exit code 0 means that component is running and any other exit code means that
+ component is not running
+ """
+ override_output_files=True # by default, we override status command output
+ if logger.level == logging.DEBUG:
+ override_output_files = False
+ res = self.runCommand(command, self.status_commands_stdout,
+ self.status_commands_stderr, self.COMMAND_NAME_STATUS,
+ override_output_files=override_output_files)
+ if res['exitcode'] == 0:
+ return LiveStatus.LIVE_STATUS
+ else:
+ return LiveStatus.DEAD_STATUS
+
+
def resolve_script_path(self, base_dir, script, script_type):
"""
Incapsulates logic of script location determination.
@@ -151,10 +203,20 @@ class CustomServiceOrchestrator():
public_fqdn = hostname.public_hostname()
command['public_hostname'] = public_fqdn
# Now, dump the json file
- task_id = command['taskId']
- file_path = os.path.join(self.tmp_dir, "command-{0}.json".format(task_id))
- # Command json contains passwords, that's why we need proper permissions
- with os.fdopen(os.open(file_path, os.O_WRONLY | os.O_CREAT,0600), 'w') as f:
+ command_type = command['commandType']
+ from ActionQueue import ActionQueue # To avoid cyclic dependency
+ if command_type == ActionQueue.STATUS_COMMAND:
+ # These files are frequently created, thats why we don't
+ # store them all, but only the latest one
+ file_path = os.path.join(self.tmp_dir, "status_command.json")
+ else:
+ task_id = command['taskId']
+ file_path = os.path.join(self.tmp_dir, "command-{0}.json".format(task_id))
+ # Json may contain passwords, that's why we need proper permissions
+ if os.path.isfile(file_path):
+ os.unlink(file_path)
+ with os.fdopen(os.open(file_path, os.O_WRONLY | os.O_CREAT,
+ 0600), 'w') as f:
content = json.dumps(command, sort_keys = False, indent = 4)
f.write(content)
return file_path
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-agent/src/main/python/ambari_agent/LiveStatus.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/LiveStatus.py b/ambari-agent/src/main/python/ambari_agent/LiveStatus.py
index f43bc95..cfb11f7 100644
--- a/ambari-agent/src/main/python/ambari_agent/LiveStatus.py
+++ b/ambari-agent/src/main/python/ambari_agent/LiveStatus.py
@@ -141,21 +141,25 @@ class LiveStatus:
#TODO: Should also check belonging of server to cluster
return component['serviceName'] == self.service
- # Live status was stripped from heartbeat after revision e1718dd
- def build(self):
+ def build(self, forsed_component_status = None):
+ """
+ If forsed_component_status is explicitly defined, than StatusCheck methods are
+ not used. This feature has been added to support custom (ver 2.0) services.
+ """
global SERVICES, CLIENT_COMPONENTS, COMPONENTS, LIVE_STATUS, DEAD_STATUS
- statusCheck = StatusCheck(AmbariConfig.servicesToPidNames,
- AmbariConfig.pidPathesVars, self.globalConfig,
- AmbariConfig.servicesToLinuxUser)
+
livestatus = None
component = {"serviceName" : self.service, "componentName" : self.component}
if component in self.COMPONENTS + self.CLIENT_COMPONENTS :
- # CLIENT components can't have status STARTED
- if component in self.CLIENT_COMPONENTS:
- status = self.DEAD_STATUS
+ if forsed_component_status: # If already determined
+ status = forsed_component_status # Nothing to do
+ elif component in self.CLIENT_COMPONENTS:
+ status = self.DEAD_STATUS # CLIENT components can't have status STARTED
else:
+ statusCheck = StatusCheck(AmbariConfig.servicesToPidNames,
+ AmbariConfig.pidPathesVars, self.globalConfig,
+ AmbariConfig.servicesToLinuxUser)
serviceStatus = statusCheck.getStatus(self.component)
-
if serviceStatus is None:
logger.warn("There is no service to pid mapping for " + self.component)
status = self.LIVE_STATUS if serviceStatus else self.DEAD_STATUS
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-agent/src/main/python/ambari_agent/PythonExecutor.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/PythonExecutor.py b/ambari-agent/src/main/python/ambari_agent/PythonExecutor.py
index 915f2b9..ddfb6a8 100644
--- a/ambari-agent/src/main/python/ambari_agent/PythonExecutor.py
+++ b/ambari-agent/src/main/python/ambari_agent/PythonExecutor.py
@@ -48,16 +48,22 @@ class PythonExecutor:
pass
def run_file(self, script, script_params, tmpoutfile, tmperrfile, timeout,
- tmpstructedoutfile):
+ tmpstructedoutfile, override_output_files = True):
"""
Executes the specified python file in a separate subprocess.
Method returns only when the subprocess is finished.
Params arg is a list of script parameters
Timeout meaning: how many seconds should pass before script execution
is forcibly terminated
+ override_output_files option defines whether stdout/stderr files will be
+ recreated or appended
"""
- tmpout = open(tmpoutfile, 'w')
- tmperr = open(tmperrfile, 'w')
+ if override_output_files: # Recreate files
+ tmpout = open(tmpoutfile, 'w')
+ tmperr = open(tmperrfile, 'w')
+ else: # Append to files
+ tmpout = open(tmpoutfile, 'a')
+ tmperr = open(tmperrfile, 'a')
script_params += [tmpstructedoutfile]
pythonCommand = self.python_command(script, script_params)
logger.info("Running command " + pprint.pformat(pythonCommand))
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-agent/src/main/python/resource_management/core/exceptions.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/core/exceptions.py b/ambari-agent/src/main/python/resource_management/core/exceptions.py
index fa13a62..6a447d7 100644
--- a/ambari-agent/src/main/python/resource_management/core/exceptions.py
+++ b/ambari-agent/src/main/python/resource_management/core/exceptions.py
@@ -26,3 +26,19 @@ class Fail(Exception):
class InvalidArgument(Fail):
pass
+
+class ClientComponentHasNoStatus(Fail):
+ """
+ Thrown when status() method is called for a CLIENT component.
+ The only valid status for CLIENT component is installed,
+ that's why exception is thrown and later silently processed at script.py
+ """
+ pass
+
+class ComponentIsNotRunning(Fail):
+ """
+ Thrown when status() method is called for a component (only
+ in situations when component process is not running).
+ Later exception is silently processed at script.py
+ """
+ pass
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-agent/src/main/python/resource_management/libraries/functions/__init__.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/libraries/functions/__init__.py b/ambari-agent/src/main/python/resource_management/libraries/functions/__init__.py
index 8836c94..db3fc87 100644
--- a/ambari-agent/src/main/python/resource_management/libraries/functions/__init__.py
+++ b/ambari-agent/src/main/python/resource_management/libraries/functions/__init__.py
@@ -24,3 +24,4 @@ from resource_management.libraries.functions.default import *
from resource_management.libraries.functions.format import *
from resource_management.libraries.functions.get_kinit_path import *
from resource_management.libraries.functions.get_unique_id_and_date import *
+from resource_management.libraries.functions.check_process_status import *
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-agent/src/main/python/resource_management/libraries/functions/check_process_status.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/libraries/functions/check_process_status.py b/ambari-agent/src/main/python/resource_management/libraries/functions/check_process_status.py
new file mode 100644
index 0000000..6bb08ea
--- /dev/null
+++ b/ambari-agent/src/main/python/resource_management/libraries/functions/check_process_status.py
@@ -0,0 +1,36 @@
+from resource_management.core.exceptions import ComponentIsNotRunning
+__all__ = ["check_process_status"]
+
+import os, logging
+
+log = logging.getLogger('resource_management')
+
+def check_process_status(pid_file):
+ """
+ Function checks whether process is running.
+ Process is considered running, if pid file exists, and process with
+ a pid, mentioned in pid file is running
+ If process is not running, will throw ComponentIsNotRunning exception
+
+ @param pid_file: path to service pid file
+ """
+ if not pid_file or not os.path.isfile(pid_file):
+ raise ComponentIsNotRunning()
+ with open(pid_file, "r") as f:
+ try:
+ pid = int(f.read())
+ except:
+ log.debug("Pid file {0} does not exist".format(pid_file))
+ raise ComponentIsNotRunning()
+ try:
+ # Kill will not actually kill the process
+ # From the doc:
+ # If sig is 0, then no signal is sent, but error checking is still
+ # performed; this can be used to check for the existence of a
+ # process ID or process group ID.
+ os.kill(pid, 0)
+ except OSError:
+ log.debug("Process with pid {0} is not running. Stale pid file"
+ " at {1}".format(pid, pid_file))
+ raise ComponentIsNotRunning()
+ pass
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-agent/src/main/python/resource_management/libraries/script/__init__.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/libraries/script/__init__.py b/ambari-agent/src/main/python/resource_management/libraries/script/__init__.py
index 232e347..72d3aaf 100644
--- a/ambari-agent/src/main/python/resource_management/libraries/script/__init__.py
+++ b/ambari-agent/src/main/python/resource_management/libraries/script/__init__.py
@@ -21,4 +21,5 @@ Ambari Agent
"""
from resource_management.libraries.script.script import *
-from resource_management.libraries.script.hook import *
\ No newline at end of file
+from resource_management.libraries.script.hook import *
+from resource_management.libraries.script.config_dictionary import *
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-agent/src/main/python/resource_management/libraries/script/script.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/libraries/script/script.py b/ambari-agent/src/main/python/resource_management/libraries/script/script.py
index 2016a89..93d9aa2 100644
--- a/ambari-agent/src/main/python/resource_management/libraries/script/script.py
+++ b/ambari-agent/src/main/python/resource_management/libraries/script/script.py
@@ -25,7 +25,7 @@ import json
import logging
from resource_management.core.environment import Environment
-from resource_management.core.exceptions import Fail
+from resource_management.core.exceptions import Fail, ClientComponentHasNoStatus, ComponentIsNotRunning
from resource_management.core.resources.packaging import Package
from resource_management.libraries.script.config_dictionary import ConfigDictionary
from resource_management.libraries.script.repo_installer import RepoInstaller
@@ -35,8 +35,14 @@ class Script(object):
Executes a command for custom service. stdout and stderr are written to
tmpoutfile and to tmperrfile respectively.
Script instances share configuration as a class parameter and therefore
- even different Script instances can not be used from different threads at
- the same time
+ different Script instances can not be used from different threads at
+ the same time within a single python process
+
+ Accepted command line arguments mapping:
+ 1 command type (START/STOP/...)
+ 2 path to command json file
+ 3 path to service metadata dir (Directory "package" inside service directory)
+ 4 path to file with structured command output (file will be created)
"""
structuredOut = {}
@@ -87,6 +93,10 @@ class Script(object):
method = self.choose_method_to_execute(command_name)
with Environment(basedir) as env:
method(env)
+ except ClientComponentHasNoStatus or ComponentIsNotRunning:
+ # Support of component status checks.
+ # Non-zero exit code is interpreted as an INSTALLED status of a component
+ sys.exit(1)
except Fail:
logger.exception("Got exception while executing command {0}:".format(command_name))
sys.exit(1)
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/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 b30b293..b08e54e 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py
@@ -354,20 +354,36 @@ class TestActionQueue(TestCase):
@patch.object(ActionQueue, "status_update_callback")
+ @patch.object(ActionQueue, "determine_command_format_version")
@patch.object(StackVersionsFileHandler, "read_stack_version")
+ @patch.object(CustomServiceOrchestrator, "requestComponentStatus")
@patch.object(ActionQueue, "execute_command")
@patch.object(LiveStatus, "build")
def test_execute_status_command(self, build_mock, execute_command_mock,
- read_stack_version_mock,
+ requestComponentStatus_mock, read_stack_version_mock,
+ determine_command_format_version_mock,
status_update_callback):
actionQueue = ActionQueue(AmbariConfig().getConfig(), 'dummy_controller')
+
build_mock.return_value = "dummy report"
- # Try normal execution
+ # Check execution ov V1 status command
+ determine_command_format_version_mock.return_value = ActionQueue.COMMAND_FORMAT_V1
+ actionQueue.execute_status_command(self.status_command)
+ report = actionQueue.result()
+ expected = 'dummy report'
+ self.assertEqual(len(report['componentStatus']), 1)
+ self.assertEqual(report['componentStatus'][0], expected)
+ self.assertFalse(requestComponentStatus_mock.called)
+
+ # Check execution ov V2 status command
+ requestComponentStatus_mock.reset_mock()
+ determine_command_format_version_mock.return_value = ActionQueue.COMMAND_FORMAT_V2
actionQueue.execute_status_command(self.status_command)
report = actionQueue.result()
expected = 'dummy report'
self.assertEqual(len(report['componentStatus']), 1)
self.assertEqual(report['componentStatus'][0], expected)
+ self.assertTrue(requestComponentStatus_mock.called)
def test_determine_command_format_version(self):
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py b/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
index ec72ffe..3568f61 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
@@ -36,6 +36,7 @@ import StringIO
import sys
from AgentException import AgentException
from FileCache import FileCache
+from LiveStatus import LiveStatus
class TestCustomServiceOrchestrator(TestCase):
@@ -55,7 +56,9 @@ class TestCustomServiceOrchestrator(TestCase):
@patch("hostname.public_hostname")
- def test_dump_command_to_json(self, hostname_mock):
+ @patch("os.path.isfile")
+ @patch("os.unlink")
+ def test_dump_command_to_json(self, unlink_mock, isfile_mock, hostname_mock):
hostname_mock.return_value = "test.hst"
command = {
'commandType': 'EXECUTION_COMMAND',
@@ -72,13 +75,25 @@ class TestCustomServiceOrchestrator(TestCase):
tempdir = tempfile.gettempdir()
config.set('agent', 'prefix', tempdir)
orchestrator = CustomServiceOrchestrator(config)
- file = orchestrator.dump_command_to_json(command)
- self.assertTrue(os.path.exists(file))
- self.assertTrue(os.path.getsize(file) > 0)
- self.assertEqual(oct(os.stat(file).st_mode & 0777), '0600')
- os.unlink(file)
+ isfile_mock.return_value = True
+ # Test dumping EXECUTION_COMMAND
+ json_file = orchestrator.dump_command_to_json(command)
+ self.assertTrue(os.path.exists(json_file))
+ self.assertTrue(os.path.getsize(json_file) > 0)
+ self.assertEqual(oct(os.stat(json_file).st_mode & 0777), '0600')
+ self.assertTrue(json_file.endswith("command-3.json"))
+ os.unlink(json_file)
+ # Test dumping STATUS_COMMAND
+ command['commandType']='STATUS_COMMAND'
+ json_file = orchestrator.dump_command_to_json(command)
+ self.assertTrue(os.path.exists(json_file))
+ self.assertTrue(os.path.getsize(json_file) > 0)
+ self.assertEqual(oct(os.stat(json_file).st_mode & 0777), '0600')
+ self.assertTrue(json_file.endswith("status_command.json"))
+ os.unlink(json_file)
# Testing side effect of dump_command_to_json
self.assertEquals(command['public_hostname'], "test.hst")
+ self.assertTrue(unlink_mock.called)
@patch("os.path.exists")
@@ -143,6 +158,25 @@ class TestCustomServiceOrchestrator(TestCase):
self.assertEqual(run_file_mock.call_count, 3)
run_file_mock.reset_mock()
+
+ # Case when we force another command
+ run_file_mock.return_value = {
+ 'stdout' : 'sss',
+ 'stderr' : 'eee',
+ 'exitcode': 0,
+ }
+ ret = orchestrator.runCommand(command, "out.txt", "err.txt",
+ forsed_command_name=CustomServiceOrchestrator.COMMAND_NAME_STATUS)
+ ## Check that override_output_files was true only during first call
+ self.assertEquals(run_file_mock.call_args_list[0][0][6], True)
+ self.assertEquals(run_file_mock.call_args_list[1][0][6], False)
+ self.assertEquals(run_file_mock.call_args_list[2][0][6], False)
+ ## Check that forsed_command_name was taken into account
+ self.assertEqual(run_file_mock.call_args_list[0][0][1][0],
+ CustomServiceOrchestrator.COMMAND_NAME_STATUS)
+
+ run_file_mock.reset_mock()
+
# unknown script type case
command['commandParams']['script_type'] = "PUPPET"
ret = orchestrator.runCommand(command, "out.txt", "err.txt")
@@ -200,7 +234,31 @@ class TestCustomServiceOrchestrator(TestCase):
res3 = orchestrator.resolve_hook_script_path("/hooks_dir/", "prefix", "command",
"script_type")
self.assertEqual(res3, None)
- pass
+
+
+ @patch.object(CustomServiceOrchestrator, "runCommand")
+ def test_requestComponentStatus(self, runCommand_mock):
+ status_command = {
+ "serviceName" : 'HDFS',
+ "commandType" : "STATUS_COMMAND",
+ "clusterName" : "",
+ "componentName" : "DATANODE",
+ 'configurations':{}
+ }
+ orchestrator = CustomServiceOrchestrator(self.config)
+ # Test alive case
+ runCommand_mock.return_value = {
+ "exitcode" : 0
+ }
+ status = orchestrator.requestComponentStatus(status_command)
+ self.assertEqual(LiveStatus.LIVE_STATUS, status)
+
+ # Test dead case
+ runCommand_mock.return_value = {
+ "exitcode" : 1
+ }
+ status = orchestrator.requestComponentStatus(status_command)
+ self.assertEqual(LiveStatus.DEAD_STATUS, status)
def tearDown(self):
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py b/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py
index cfe45c3..a025f6e 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py
@@ -58,3 +58,15 @@ class TestLiveStatus(TestCase):
result = livestatus.build()
self.assertTrue(len(result) > 0, 'Livestatus should not be empty')
self.assertTrue(result.has_key('configurationTags'))
+ # Test build status with forsed_component_status
+ ## Alive
+ livestatus = LiveStatus('c1', 'HDFS', 'HDFS_CLIENT', { }, config)
+ result = livestatus.build(forsed_component_status = LiveStatus.LIVE_STATUS)
+ self.assertTrue(len(result) > 0, 'Livestatus should not be empty')
+ self.assertTrue(result['status'], LiveStatus.LIVE_STATUS)
+ ## Dead
+ livestatus = LiveStatus('c1', 'HDFS', 'HDFS_CLIENT', { }, config)
+ result = livestatus.build(forsed_component_status = LiveStatus.DEAD_STATUS)
+ self.assertTrue(len(result) > 0, 'Livestatus should not be empty')
+ self.assertTrue(result['status'], LiveStatus.DEAD_STATUS)
+
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py b/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
index 0711a38..8a73410 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
@@ -136,7 +136,6 @@ class TestPythonExecutor(TestCase):
self.assertTrue("python" in command[0])
self.assertEquals("script", command[1])
self.assertEquals("script_param1", command[2])
- pprint.pprint(command)
class Subprocess_mockup():
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/java/org/apache/ambari/server/RoleCommand.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/RoleCommand.java b/ambari-server/src/main/java/org/apache/ambari/server/RoleCommand.java
index 94013c2..4824ee9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/RoleCommand.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/RoleCommand.java
@@ -18,6 +18,15 @@
package org.apache.ambari.server;
public enum RoleCommand {
+
+ /*
+ * When adding/modifying enum members, please beware that except Java usages,
+ * RoleCommand string representations are used at role_command_order.json
+ * files
+ */
+
+
+public enum RoleCommand {
INSTALL,
UNINSTALL,
START,
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
index 0909020..8761b10 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
@@ -251,6 +251,7 @@ public class ExecutionCommand extends AgentCommand {
String DB_DRIVER_FILENAME = "db_driver_filename";
String REPO_INFO = "repo_info";
String DB_NAME = "db_name";
+ String GLOBAL = "global";
String SERVICE_CHECK = "SERVICE_CHECK"; // TODO: is it standart command? maybe add it to RoleCommand enum?
String COMMAND_TIMEOUT_DEFAULT = "600"; // TODO: Will be replaced by proper initialization in another jira
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
index 6f82676..ee6826a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
@@ -27,21 +27,14 @@ import com.google.inject.Injector;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.actionmanager.ActionManager;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
-import org.apache.ambari.server.state.Cluster;
-import org.apache.ambari.server.state.Clusters;
-import org.apache.ambari.server.state.Config;
-import org.apache.ambari.server.state.ConfigHelper;
-import org.apache.ambari.server.state.Host;
-import org.apache.ambari.server.state.HostState;
-import org.apache.ambari.server.state.Service;
-import org.apache.ambari.server.state.ServiceComponent;
-import org.apache.ambari.server.state.ServiceComponentHost;
-import org.apache.ambari.server.state.State;
+import org.apache.ambari.server.state.*;
import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
import org.apache.ambari.server.state.host.HostHeartbeatLostEvent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.*;
+
/**
* Monitors the node state and heartbeats.
*/
@@ -54,6 +47,7 @@ public class HeartbeatMonitor implements Runnable {
private volatile boolean shouldRun = true;
private Thread monitorThread = null;
private final ConfigHelper configHelper;
+ private final AmbariMetaInfo ambariMetaInfo;
public HeartbeatMonitor(Clusters clusters, ActionQueue aq, ActionManager am,
int threadWakeupInterval, Injector injector) {
@@ -62,6 +56,7 @@ public class HeartbeatMonitor implements Runnable {
this.actionManager = am;
this.threadWakeupInterval = threadWakeupInterval;
this.configHelper = injector.getInstance(ConfigHelper.class);
+ this.ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
}
public void shutdown() {
@@ -176,58 +171,98 @@ public class HeartbeatMonitor implements Runnable {
for (Cluster cl : clusters.getClustersForHost(hostname)) {
for (ServiceComponentHost sch : cl.getServiceComponentHosts(hostname)) {
- String serviceName = sch.getServiceName();
- Service service = cl.getService(sch.getServiceName());
- ServiceComponent sc = service.getServiceComponent(sch
- .getServiceComponentName());
- // Send status commands for any components
- if (LOG.isDebugEnabled()) {
- LOG.debug("Live status will include status of service " + serviceName + " of cluster " + cl.getClusterName());
- }
+ StatusCommand statusCmd = createStatusCommand(hostname, cl, sch);
+ cmds.add(statusCmd);
+ }
+ }
+ return cmds;
+ }
- Map<String, Map<String, String>> configurations = new TreeMap<String, Map<String, String>>();
- // get the cluster config for type 'global'
- // apply config group overrides
+ /**
+ * Generates status command and fills all apropriate fields.
+ * @throws AmbariException
+ */
+ private StatusCommand createStatusCommand(String hostname, Cluster cluster,
+ ServiceComponentHost sch) throws AmbariException {
+ String serviceName = sch.getServiceName();
+ String componentName = sch.getServiceComponentName();
+ Service service = cluster.getService(sch.getServiceName());
+ ServiceComponent sc = service.getServiceComponent(componentName);
+ StackId stackId = cluster.getDesiredStackVersion();
+ ServiceInfo serviceInfo = ambariMetaInfo.getServiceInfo(stackId.getStackName(),
+ stackId.getStackVersion(), serviceName);
+ ComponentInfo componentInfo = ambariMetaInfo.getComponent(
+ stackId.getStackName(), stackId.getStackVersion(),
+ serviceName, componentName);
- Config clusterConfig = cl.getDesiredConfigByType("global");
- if (clusterConfig != null) {
- // cluster config for 'global'
- Map<String, String> props = new HashMap<String, String>(clusterConfig.getProperties());
+ Map<String, Map<String, String>> configurations = new TreeMap<String, Map<String, String>>();
- // Apply global properties for this host from all config groups
- Map<String, Map<String, String>> allConfigTags = configHelper
- .getEffectiveDesiredTags(cl, hostname);
+ // get the cluster config for type 'global'
+ // apply config group overrides
- Map<String, Map<String, String>> configTags = new HashMap<String,
- Map<String, String>>();
+ Config clusterConfig = cluster.getDesiredConfigByType(GLOBAL);
+ if (clusterConfig != null) {
+ // cluster config for 'global'
+ Map<String, String> props = new HashMap<String, String>(clusterConfig.getProperties());
- for (Map.Entry<String, Map<String, String>> entry : allConfigTags.entrySet()) {
- if (entry.getKey().equals("global")) {
- configTags.put("global", entry.getValue());
- }
- }
+ // Apply global properties for this host from all config groups
+ Map<String, Map<String, String>> allConfigTags = configHelper
+ .getEffectiveDesiredTags(cluster, hostname);
- Map<String, Map<String, String>> properties = configHelper
- .getEffectiveConfigProperties(cl, configTags);
+ Map<String, Map<String, String>> configTags = new HashMap<String,
+ Map<String, String>>();
- if (!properties.isEmpty()) {
- for (Map<String, String> propertyMap : properties.values()) {
- props.putAll(propertyMap);
- }
- }
+ for (Map.Entry<String, Map<String, String>> entry : allConfigTags.entrySet()) {
+ if (entry.getKey().equals(GLOBAL)) {
+ configTags.put(GLOBAL, entry.getValue());
+ }
+ }
- configurations.put("global", props);
+ Map<String, Map<String, String>> properties = configHelper
+ .getEffectiveConfigProperties(cluster, configTags);
+
+ if (!properties.isEmpty()) {
+ for (Map<String, String> propertyMap : properties.values()) {
+ props.putAll(propertyMap);
}
+ }
- StatusCommand statusCmd = new StatusCommand();
- statusCmd.setClusterName(cl.getClusterName());
- statusCmd.setServiceName(serviceName);
- statusCmd.setComponentName(sch.getServiceComponentName());
- statusCmd.setConfigurations(configurations);
- cmds.add(statusCmd);
+ configurations.put(GLOBAL, props);
+ }
+
+ StatusCommand statusCmd = new StatusCommand();
+ statusCmd.setClusterName(cluster.getClusterName());
+ statusCmd.setServiceName(serviceName);
+ statusCmd.setComponentName(componentName);
+ statusCmd.setConfigurations(configurations);
+
+ // Fill command params
+ Map<String, String> commandParams = statusCmd.getCommandParams();
+ commandParams.put(SCHEMA_VERSION, serviceInfo.getSchemaVersion());
+
+ String commandTimeout = ExecutionCommand.KeyNames.COMMAND_TIMEOUT_DEFAULT;
+ CommandScriptDefinition script = componentInfo.getCommandScript();
+ if (serviceInfo.getSchemaVersion().equals(AmbariMetaInfo.SCHEMA_VERSION_2)) {
+ if (script != null) {
+ commandParams.put(SCRIPT, script.getScript());
+ commandParams.put(SCRIPT_TYPE, script.getScriptType().toString());
+ commandTimeout = String.valueOf(script.getTimeout());
+ } else {
+ String message = String.format("Component %s of service %s has not " +
+ "command script defined", componentName, serviceName);
+ throw new AmbariException(message);
}
}
- return cmds;
+ commandParams.put(COMMAND_TIMEOUT, commandTimeout);
+ commandParams.put(SERVICE_METADATA_FOLDER,
+ serviceInfo.getServiceMetadataFolder());
+ // Fill host level params
+ Map<String, String> hostLevelParams = statusCmd.getHostLevelParams();
+ hostLevelParams.put(STACK_NAME, stackId.getStackName());
+ hostLevelParams.put(STACK_VERSION, stackId.getStackVersion());
+
+ return statusCmd;
}
+
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/java/org/apache/ambari/server/agent/StatusCommand.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/StatusCommand.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/StatusCommand.java
index 54a3267..e7a46ff 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/StatusCommand.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/StatusCommand.java
@@ -17,6 +17,7 @@
*/
package org.apache.ambari.server.agent;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -35,6 +36,8 @@ public class StatusCommand extends AgentCommand {
private String serviceName;
private String componentName;
private Map<String, Map<String, String>> configurations;
+ private Map<String, String> commandParams = new HashMap<String, String>();
+ private Map<String, String> hostLevelParams = new HashMap<String, String>();
@JsonProperty("clusterName")
public String getClusterName() {
@@ -75,4 +78,25 @@ public class StatusCommand extends AgentCommand {
public void setConfigurations(Map<String, Map<String, String>> configurations) {
this.configurations = configurations;
}
+
+ @JsonProperty("hostLevelParams")
+ public Map<String, String> getHostLevelParams() {
+ return hostLevelParams;
+ }
+
+ @JsonProperty("hostLevelParams")
+ public void setHostLevelParams(Map<String, String> params) {
+ this.hostLevelParams = params;
+ }
+
+ @JsonProperty("commandParams")
+ public Map<String, String> getCommandParams() {
+ return commandParams;
+ }
+
+ @JsonProperty("commandParams")
+ public void setCommandParams(Map<String, String> commandParams) {
+ this.commandParams = commandParams;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/1.3._/hooks/before-START.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3._/hooks/before-START.py b/ambari-server/src/main/resources/stacks/HDP/1.3._/hooks/before-START.py
new file mode 100644
index 0000000..378b2d2
--- /dev/null
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3._/hooks/before-START.py
@@ -0,0 +1,30 @@
+##!/usr/bin/env python2.6
+"""
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+"""
+
+import sys
+from resource_management import *
+
+class BeforeStartHook(Hook):
+
+ def hook(self, env):
+ Execute(("touch", "/tmp/hook-test"))
+
+if __name__ == "__main__":
+ BeforeStartHook().execute()
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/1.3._/services/GANGLIA/package/scripts/ganglia_monitor.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3._/services/GANGLIA/package/scripts/ganglia_monitor.py b/ambari-server/src/main/resources/stacks/HDP/1.3._/services/GANGLIA/package/scripts/ganglia_monitor.py
index 5030329..3fa7f5e 100644
--- a/ambari-server/src/main/resources/stacks/HDP/1.3._/services/GANGLIA/package/scripts/ganglia_monitor.py
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3._/services/GANGLIA/package/scripts/ganglia_monitor.py
@@ -39,6 +39,23 @@ class GangliaMonitor(Script):
def stop(self, env):
ganglia_monitor_service.monitor("stop")
+
+ def status(self, env):
+ import status_params
+ pid_file_name = 'gmond.pid'
+ pid_file_count = 0
+ pid_dir = status_params.pid_dir
+ # Recursively check all existing gmond pid files
+ for cur_dir, subdirs, files in os.walk(pid_dir):
+ for file_name in files:
+ if file_name == pid_file_name:
+ pid_file = os.path.join(cur_dir, file_name)
+ check_process_status(pid_file)
+ pid_file_count += 1
+ if pid_file_count == 0: # If no any pid file is present
+ raise ComponentIsNotRunning()
+
+
def config(self, env):
import params
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/1.3._/services/GANGLIA/package/scripts/ganglia_server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3._/services/GANGLIA/package/scripts/ganglia_server.py b/ambari-server/src/main/resources/stacks/HDP/1.3._/services/GANGLIA/package/scripts/ganglia_server.py
index 02785d3..d8e3746 100644
--- a/ambari-server/src/main/resources/stacks/HDP/1.3._/services/GANGLIA/package/scripts/ganglia_server.py
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3._/services/GANGLIA/package/scripts/ganglia_server.py
@@ -45,6 +45,13 @@ class GangliaServer(Script):
env.set_params(params)
ganglia_server_service.server("stop")
+ def status(self, env):
+ import status_params
+ env.set_params(status_params)
+ pid_file = format("{pid_dir}/gmetad.pid")
+ # Recursively check all existing gmetad pid files
+ check_process_status(pid_file)
+
def config(self, env):
import params
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/1.3._/services/GANGLIA/package/scripts/status_params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3._/services/GANGLIA/package/scripts/status_params.py b/ambari-server/src/main/resources/stacks/HDP/1.3._/services/GANGLIA/package/scripts/status_params.py
new file mode 100644
index 0000000..3ccad2f
--- /dev/null
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3._/services/GANGLIA/package/scripts/status_params.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+"""
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+"""
+
+from resource_management import *
+
+config = Script.get_config()
+
+pid_dir = config['configurations']['global']['ganglia_runtime_dir']
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/1.3._/services/SQOOP/package/scripts/sqoop_client.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3._/services/SQOOP/package/scripts/sqoop_client.py b/ambari-server/src/main/resources/stacks/HDP/1.3._/services/SQOOP/package/scripts/sqoop_client.py
index c07de40..bd2863c 100644
--- a/ambari-server/src/main/resources/stacks/HDP/1.3._/services/SQOOP/package/scripts/sqoop_client.py
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3._/services/SQOOP/package/scripts/sqoop_client.py
@@ -33,5 +33,8 @@ class SqoopClient(Script):
env.set_params(params)
sqoop(type='client')
+ def status(self, env):
+ raise ClientComponentHasNoStatus()
+
if __name__ == "__main__":
SqoopClient().execute()
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/GANGLIA/package/scripts/ganglia_monitor.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/GANGLIA/package/scripts/ganglia_monitor.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/GANGLIA/package/scripts/ganglia_monitor.py
index 5030329..3fa7f5e 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/GANGLIA/package/scripts/ganglia_monitor.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/GANGLIA/package/scripts/ganglia_monitor.py
@@ -39,6 +39,23 @@ class GangliaMonitor(Script):
def stop(self, env):
ganglia_monitor_service.monitor("stop")
+
+ def status(self, env):
+ import status_params
+ pid_file_name = 'gmond.pid'
+ pid_file_count = 0
+ pid_dir = status_params.pid_dir
+ # Recursively check all existing gmond pid files
+ for cur_dir, subdirs, files in os.walk(pid_dir):
+ for file_name in files:
+ if file_name == pid_file_name:
+ pid_file = os.path.join(cur_dir, file_name)
+ check_process_status(pid_file)
+ pid_file_count += 1
+ if pid_file_count == 0: # If no any pid file is present
+ raise ComponentIsNotRunning()
+
+
def config(self, env):
import params
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/GANGLIA/package/scripts/ganglia_server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/GANGLIA/package/scripts/ganglia_server.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/GANGLIA/package/scripts/ganglia_server.py
index 02785d3..d8e3746 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/GANGLIA/package/scripts/ganglia_server.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/GANGLIA/package/scripts/ganglia_server.py
@@ -45,6 +45,13 @@ class GangliaServer(Script):
env.set_params(params)
ganglia_server_service.server("stop")
+ def status(self, env):
+ import status_params
+ env.set_params(status_params)
+ pid_file = format("{pid_dir}/gmetad.pid")
+ # Recursively check all existing gmetad pid files
+ check_process_status(pid_file)
+
def config(self, env):
import params
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/GANGLIA/package/scripts/status_params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/GANGLIA/package/scripts/status_params.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/GANGLIA/package/scripts/status_params.py
new file mode 100644
index 0000000..3ccad2f
--- /dev/null
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/GANGLIA/package/scripts/status_params.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+"""
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+"""
+
+from resource_management import *
+
+config = Script.get_config()
+
+pid_dir = config['configurations']['global']['ganglia_runtime_dir']
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/__init__.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/__init__.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/__init__.py
index 38e1a5e..5561e10 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/__init__.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/__init__.py
@@ -16,6 +16,4 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/functions.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/functions.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/functions.py
index d473638..80b49e6 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/functions.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/functions.py
@@ -16,8 +16,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
import os
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase.py
index 06b2c75..bd33463 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase.py
@@ -16,8 +16,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
from resource_management import *
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_client.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_client.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_client.py
index fa6da69..0f2a1bc 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_client.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_client.py
@@ -16,8 +16,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
import sys
@@ -36,7 +34,10 @@ class HbaseClient(Script):
env.set_params(params)
hbase(type='client')
-
+
+ def status(self, env):
+ raise ClientComponentHasNoStatus()
+
#for tests
def main():
command_type = 'install'
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_master.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_master.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_master.py
index 9370ec4..6036e73 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_master.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_master.py
@@ -16,8 +16,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
import sys
@@ -53,7 +51,13 @@ class HbaseMaster(Script):
hbase_service( 'master',
action = 'stop'
)
-
+
+ def status(self, env):
+ import status_params
+ env.set_params(status_params)
+ pid_file = format("{pid_dir}/hbase-hbase-master.pid")
+ check_process_status(pid_file)
+
def main():
command_type = sys.argv[1] if len(sys.argv)>1 else "install"
print "Running "+command_type
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_regionserver.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_regionserver.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_regionserver.py
index e380bc2..927ec4f 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_regionserver.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_regionserver.py
@@ -16,8 +16,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
import sys
@@ -53,6 +51,12 @@ class HbaseRegionServer(Script):
hbase_service( 'regionserver',
action = 'stop'
)
+
+ def status(self, env):
+ import status_params
+ env.set_params(status_params)
+ pid_file = format("{pid_dir}/hbase-hbase-regionserver.pid")
+ check_process_status(pid_file)
def decommission(self):
print "Decommission not yet implemented!"
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_service.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_service.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_service.py
index d49533f..7a1248b 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_service.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/hbase_service.py
@@ -16,15 +16,13 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
from resource_management import *
def hbase_service(
name,
- action = 'start'): # 'start' or 'stop'
+ action = 'start'): # 'start' or 'stop' or 'status'
import params
@@ -40,7 +38,7 @@ def hbase_service(
no_op_test = format("ls {pid_file} >/dev/null 2>&1 && ps `cat {pid_file}` >/dev/null 2>&1")
elif action == 'stop':
daemon_cmd = format("{cmd} stop {role} && rm -f {pid_file}")
-
+
if daemon_cmd is not None:
Execute ( daemon_cmd,
not_if = no_op_test,
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/params.py
index a8a0e6b..80400c6 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/params.py
@@ -16,12 +16,11 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
from resource_management import *
import functions
+import status_params
# server configurations
config = Script.get_config()
@@ -46,7 +45,7 @@ master_heapsize = config['configurations']['global']['hbase_master_heapsize']
regionserver_heapsize = config['configurations']['global']['hbase_regionserver_heapsize']
regionserver_xmn_size = functions.calc_xmn_from_xms(regionserver_heapsize, 0.2, 512)
-pid_dir = config['configurations']['global']['hbase_pid_dir']
+pid_dir = status_params.pid_dir
tmp_dir = config['configurations']['hbase-site']['hbase.tmp.dir']
client_jaas_config_file = default('hbase_client_jaas_config_file', format("{conf_dir}/hbase_client_jaas.conf"))
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/service_check.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/service_check.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/service_check.py
index 7de92fb..ff6d0ed 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/service_check.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/service_check.py
@@ -16,8 +16,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
from resource_management import *
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/status_params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/status_params.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/status_params.py
new file mode 100644
index 0000000..c9b20ef
--- /dev/null
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HBASE/package/scripts/status_params.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+"""
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+"""
+
+from resource_management import *
+
+config = Script.get_config()
+
+pid_dir = config['configurations']['global']['hbase_pid_dir']
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/__init__.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/__init__.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/__init__.py
index 38e1a5e..5561e10 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/__init__.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/__init__.py
@@ -16,6 +16,4 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hcat.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hcat.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hcat.py
index 827e963..2993d3a 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hcat.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hcat.py
@@ -16,8 +16,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
from resource_management import *
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hcat_client.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hcat_client.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hcat_client.py
index 1b3dd09..8b5921a 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hcat_client.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hcat_client.py
@@ -16,8 +16,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
import sys
@@ -37,5 +35,9 @@ class HCatClient(Script):
hcat()
+ def status(self, env):
+ raise ClientComponentHasNoStatus()
+
+
if __name__ == "__main__":
HCatClient().execute()
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hcat_service_check.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hcat_service_check.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hcat_service_check.py
index b9c8a6e..5112e99 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hcat_service_check.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hcat_service_check.py
@@ -16,8 +16,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
from resource_management import *
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive.py
index 36323dc..1963762 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive.py
@@ -16,8 +16,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
from resource_management import *
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_client.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_client.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_client.py
index 7a7fa5c..04e28ba 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_client.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_client.py
@@ -16,8 +16,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
import sys
from resource_management import *
@@ -28,11 +26,16 @@ class HiveClient(Script):
def install(self, env):
self.install_packages(env)
self.configure(env)
+
def configure(self, env):
import params
env.set_params(params)
hive(type='client')
+
+ def status(self, env):
+ raise ClientComponentHasNoStatus()
+
if __name__ == "__main__":
HiveClient().execute()
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_metastore.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_metastore.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_metastore.py
index 68dcf14..da7ed18 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_metastore.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_metastore.py
@@ -16,8 +16,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
import sys
@@ -27,6 +25,7 @@ from hive import hive
from hive_service import hive_service
class HiveMetastore(Script):
+
def install(self, env):
self.install_packages(env)
self.configure(env)
@@ -53,5 +52,12 @@ class HiveMetastore(Script):
action = 'stop'
)
+ def status(self, env):
+ import status_params
+ env.set_params(status_params)
+ pid_file = format("{hive_pid_dir}/{hive_metastore_pid}")
+ # Recursively check all existing gmetad pid files
+ check_process_status(pid_file)
+
if __name__ == "__main__":
HiveMetastore().execute()
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_server.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_server.py
index 4434e34..3dc7d3d 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_server.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_server.py
@@ -16,8 +16,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
import sys
@@ -27,6 +25,7 @@ from hive import hive
from hive_service import hive_service
class HiveServer(Script):
+
def install(self, env):
self.install_packages(env)
self.configure(env)
@@ -52,5 +51,13 @@ class HiveServer(Script):
action = 'stop'
)
+
+ def status(self, env):
+ import status_params
+ env.set_params(status_params)
+ pid_file = format("{hive_pid_dir}/{hive_pid}")
+ # Recursively check all existing gmetad pid files
+ check_process_status(pid_file)
+
if __name__ == "__main__":
HiveServer().execute()
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_service.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_service.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_service.py
index 0daab52..e8d4e5c 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_service.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/hive_service.py
@@ -16,8 +16,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
from resource_management import *
@@ -30,7 +28,7 @@ def hive_service(
import params
if name == 'metastore':
- pid_file = format("{hive_pid_dir}/hive.pid")
+ pid_file = format("{hive_pid_dir}/{hive_metastore_pid}")
cmd = format(
"env HADOOP_HOME={hadoop_home} JAVA_HOME={java64_home} {start_metastore_path} {hive_log_dir}/hive.out {hive_log_dir}/hive.log {pid_file} {hive_server_conf_dir}")
elif name == 'hiveserver2':
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/mysql.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/mysql.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/mysql.py
deleted file mode 100644
index 6b2ce33..0000000
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/mysql.py
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/usr/bin/env python
-"""
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-
-Ambari Agent
-
-"""
-
-from resource_management import *
-import sys
-from mysql_service import *
-
-def mysql():
- import params
-
- if System.get_instance().platform == "suse":
- Directory('/var/run/mysqld/',
- owner=params.mysql_user,
- group=params.mysql_group,
- recursive=True
- )
-
- Link('/var/run/mysqld/mysqld.pid',
- to='/var/lib/mysql/mysqld.pid')
-
- mysql_service(action='start')
-
- File(params.mysql_adduser_path,
- mode=0755,
- content=StaticFile('addMysqlUser.sh')
- )
-
- # Autoescaping
- cmd = ("bash", "-x", params.mysql_adduser_path, params.service_name,
- params.hive_metastore_user_name, params.hive_metastore_user_passwd, params.mysql_host[0])
-
- Execute(cmd,
- tries=3,
- try_sleep=5,
- path='/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin',
- logoutput=True
- )
-
- mysql_service(action='stop')
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/mysql_server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/mysql_server.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/mysql_server.py
index 674b4d6..5360f99 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/mysql_server.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/mysql_server.py
@@ -16,17 +16,20 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
import sys
from resource_management import *
-from mysql import mysql
from mysql_service import mysql_service
class MysqlServer(Script):
+
+ if System.get_instance().platform == "suse":
+ daemon_name = 'mysql'
+ else:
+ daemon_name = 'mysqld'
+
def install(self, env):
self.install_packages(env)
self.configure(env)
@@ -34,19 +37,41 @@ class MysqlServer(Script):
def configure(self, env):
import params
env.set_params(params)
- mysql()
+
+ mysql_service(daemon_name=self.daemon_name, action='start')
+
+ File(params.mysql_adduser_path,
+ mode=0755,
+ content=StaticFile('addMysqlUser.sh')
+ )
+
+ # Autoescaping
+ cmd = ("bash", "-x", params.mysql_adduser_path, self.daemon_name,
+ params.hive_metastore_user_name, params.hive_metastore_user_passwd, params.mysql_host[0])
+
+ Execute(cmd,
+ tries=3,
+ try_sleep=5,
+ path='/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin',
+ logoutput=True
+ )
+
+ mysql_service(daemon_name=self.daemon_name, action='stop')
def start(self, env):
import params
env.set_params(params)
- mysql_service(action = 'start')
+ mysql_service(daemon_name=self.daemon_name, action = 'start')
def stop(self, env):
import params
env.set_params(params)
- mysql_service(action = 'stop')
+ mysql_service(daemon_name=self.daemon_name, action = 'stop')
+
+ def status(self, env):
+ mysql_service(daemon_name=self.daemon_name, action = 'status')
if __name__ == "__main__":
MysqlServer().execute()
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/mysql_service.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/mysql_service.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/mysql_service.py
index f0b9ec7..4716343 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/mysql_service.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/mysql_service.py
@@ -16,25 +16,29 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
from resource_management import *
-def mysql_service(action='start'):
-
- import params
+def mysql_service(daemon_name=None, action='start'):
+ logoutput=True
if action == 'start':
- cmd = format('service {service_name} start')
+ cmd = format('service {daemon_name} start')
elif action == 'stop':
- cmd = format('service {service_name} stop')
+ cmd = format('service {daemon_name} stop')
+ elif action == 'status':
+ cmd = format('service {daemon_name} status')
+ logoutput = False
else:
cmd = None
if cmd is not None:
Execute(cmd,
path="/usr/local/bin/:/bin/:/sbin/",
- logoutput=True)
+ tries=1,
+ logoutput=logoutput)
+
+
+
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/params.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/params.py
index 2fbf776..38bb517 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/params.py
@@ -16,11 +16,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
from resource_management import *
+import status_params
# server configurations
config = Script.get_config()
@@ -64,8 +63,8 @@ hive_metastore_keytab_path = config['configurations']['hive-site']['hive.metast
hive_conf_dir = "/etc/hive/conf"
hive_dbroot = config['configurations']['global']['hive_dbroot']
hive_log_dir = config['configurations']['global']['hive_log_dir']
-hive_pid_dir = config['configurations']['global']['hive_pid_dir']
-hive_pid = 'hive-server.pid'
+hive_pid_dir = status_params.hive_pid_dir
+hive_pid = status_params.hive_pid
#hive-site
hive_database_name = config['configurations']['global']['hive_database_name']
@@ -77,7 +76,7 @@ hadoop_home = '/usr'
##Starting metastore
start_metastore_script = 'startMetastore.sh'
-
+hive_metastore_pid = status_params.hive_metastore_pid
java_share_dir = '/usr/share/java'
driver_curl_target = format("{java_share_dir}/{jdbc_jar_name}")
@@ -106,12 +105,6 @@ mysql_host = config['clusterHostInfo']['hive_mysql_host']
mysql_adduser_path = "/tmp/addMysqlUser.sh"
-if System.get_instance().platform == "suse":
- service_name = 'mysql'
-else:
- service_name = 'mysqld'
-
-
########## HCAT
hcat_conf_dir = '/etc/hcatalog/conf'
@@ -124,7 +117,7 @@ hcat_dbroot = hcat_lib
hcat_user = config['configurations']['global']['hcat_user']
webhcat_user = config['configurations']['global']['webhcat_user']
-hcat_pid_dir = config['configurations']['global']['hcat_pid_dir'] #hcat_pid_dir
+hcat_pid_dir = status_params.hcat_pid_dir
hcat_log_dir = config['configurations']['global']['hcat_log_dir'] #hcat_log_dir
hadoop_conf_dir = '/etc/hadoop/conf'
http://git-wip-us.apache.org/repos/asf/ambari/blob/fd9cd27a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/service_check.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/service_check.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/service_check.py
index c67896c..111e8a1 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/service_check.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/services/HIVE/package/scripts/service_check.py
@@ -16,8 +16,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-Ambari Agent
-
"""
from resource_management import *