|
@@ -21,64 +21,12 @@ limitations under the License.
|
|
|
__all__ = ["select", "create", "get_hadoop_conf_dir", "get_hadoop_dir"]
|
|
|
|
|
|
import version
|
|
|
+import hdp_select
|
|
|
+
|
|
|
from resource_management.core import shell
|
|
|
-from resource_management.core.exceptions import Fail
|
|
|
-from resource_management.core.logger import Logger
|
|
|
-from resource_management.libraries.functions.default import default
|
|
|
-from resource_management.libraries.functions.get_hdp_version import get_hdp_version
|
|
|
from resource_management.libraries.script.script import Script
|
|
|
|
|
|
-# a mapping of Ambari server role to hdp-select component name for all
|
|
|
-# non-clients
|
|
|
-SERVER_ROLE_DIRECTORY_MAP = {
|
|
|
- 'ACCUMULO_MASTER' : 'accumulo-master',
|
|
|
- 'ACCUMULO_MONITOR' : 'accumulo-monitor',
|
|
|
- 'ACCUMULO_GC' : 'accumulo-gc',
|
|
|
- 'ACCUMULO_TRACER' : 'accumulo-tracer',
|
|
|
- 'ACCUMULO_TSERVER' : 'accumulo-tablet',
|
|
|
- 'ATLAS_SERVER' : 'atlas-server',
|
|
|
- 'FLUME_HANDLER' : 'flume-server',
|
|
|
- 'FALCON_SERVER' : 'falcon-server',
|
|
|
- 'NAMENODE' : 'hadoop-hdfs-namenode',
|
|
|
- 'DATANODE' : 'hadoop-hdfs-datanode',
|
|
|
- 'SECONDARY_NAMENODE' : 'hadoop-hdfs-secondarynamenode',
|
|
|
- 'NFS_GATEWAY' : 'hadoop-hdfs-nfs3',
|
|
|
- 'JOURNALNODE' : 'hadoop-hdfs-journalnode',
|
|
|
- 'HBASE_MASTER' : 'hbase-master',
|
|
|
- 'HBASE_REGIONSERVER' : 'hbase-regionserver',
|
|
|
- 'HIVE_METASTORE' : 'hive-metastore',
|
|
|
- 'HIVE_SERVER' : 'hive-server2',
|
|
|
- 'WEBHCAT_SERVER' : 'hive-webhcat',
|
|
|
- 'KAFKA_BROKER' : 'kafka-broker',
|
|
|
- 'KNOX_GATEWAY' : 'knox-server',
|
|
|
- 'OOZIE_SERVER' : 'oozie-server',
|
|
|
- 'RANGER_ADMIN' : 'ranger-admin',
|
|
|
- 'RANGER_USERSYNC' : 'ranger-usersync',
|
|
|
- 'SPARK_JOBHISTORYSERVER' : 'spark-historyserver',
|
|
|
- 'NIMBUS' : 'storm-nimbus',
|
|
|
- 'SUPERVISOR' : 'storm-supervisor',
|
|
|
- 'HISTORYSERVER' : 'hadoop-mapreduce-historyserver',
|
|
|
- 'APP_TIMELINE_SERVER' : 'hadoop-yarn-timelineserver',
|
|
|
- 'NODEMANAGER' : 'hadoop-yarn-nodemanager',
|
|
|
- 'RESOURCEMANAGER' : 'hadoop-yarn-resourcemanager',
|
|
|
- 'ZOOKEEPER_SERVER' : 'zookeeper-server'
|
|
|
-}
|
|
|
-
|
|
|
-# mapping of service check to hdp-select component
|
|
|
-SERVICE_CHECK_DIRECTORY_MAP = {
|
|
|
- "HDFS_SERVICE_CHECK" : "hadoop-client",
|
|
|
- "TEZ_SERVICE_CHECK" : "hadoop-client",
|
|
|
- "PIG_SERVICE_CHECK" : "hadoop-client"
|
|
|
-}
|
|
|
-
|
|
|
TEMPLATE = "conf-select {0} --package {1} --stack-version {2} --conf-version 0"
|
|
|
-HADOOP_DIR_TEMPLATE = "/usr/hdp/{0}/{1}/{2}"
|
|
|
-HADOOP_DIR_DEFAULTS = {
|
|
|
- "libexec": "/usr/lib/hadoop/libexec",
|
|
|
- "sbin": "/usr/lib/hadoop/sbin",
|
|
|
- "bin": "/usr/bin",
|
|
|
- "lib": "/usr/lib/hadoop/lib"
|
|
|
-}
|
|
|
|
|
|
def _valid(stack_name, package, ver):
|
|
|
if stack_name != "HDP":
|
|
@@ -89,21 +37,6 @@ def _valid(stack_name, package, ver):
|
|
|
|
|
|
return True
|
|
|
|
|
|
-def _get_upgrade_stack():
|
|
|
- """
|
|
|
- Gets the stack name and stack version if an upgrade is currently in progress.
|
|
|
- :return: the stack name and stack version as a tuple, or None if an
|
|
|
- upgrade is not in progress.
|
|
|
- """
|
|
|
- from resource_management.libraries.functions.default import default
|
|
|
- direction = default("/commandParams/upgrade_direction", None)
|
|
|
- stack_name = default("/hostLevelParams/stack_name", None)
|
|
|
- stack_version = default("/commandParams/version", None)
|
|
|
-
|
|
|
- if direction and stack_name and stack_version:
|
|
|
- return (stack_name, stack_version)
|
|
|
-
|
|
|
- return None
|
|
|
|
|
|
def create(stack_name, package, version):
|
|
|
"""
|
|
@@ -118,6 +51,7 @@ def create(stack_name, package, version):
|
|
|
|
|
|
shell.call(TEMPLATE.format("create-conf-dir", package, version), logoutput=False, quiet=True)
|
|
|
|
|
|
+
|
|
|
def select(stack_name, package, version, try_create=True):
|
|
|
"""
|
|
|
Selects a config version for the specified package. Currently only works if the version is
|
|
@@ -136,6 +70,7 @@ def select(stack_name, package, version, try_create=True):
|
|
|
|
|
|
shell.call(TEMPLATE.format("set-conf-dir", package, version), logoutput=False, quiet=False)
|
|
|
|
|
|
+
|
|
|
def get_hadoop_conf_dir(force_latest_on_upgrade=False):
|
|
|
"""
|
|
|
Gets the shared hadoop conf directory using:
|
|
@@ -157,7 +92,7 @@ def get_hadoop_conf_dir(force_latest_on_upgrade=False):
|
|
|
if Script.is_hdp_stack_greater_or_equal("2.2"):
|
|
|
hadoop_conf_dir = "/usr/hdp/current/hadoop-client/conf"
|
|
|
|
|
|
- stack_info = _get_upgrade_stack()
|
|
|
+ stack_info = hdp_select._get_upgrade_stack()
|
|
|
|
|
|
# if upgrading to >= HDP 2.3
|
|
|
if stack_info is not None and Script.is_hdp_stack_greater_or_equal("2.3"):
|
|
@@ -170,7 +105,7 @@ def get_hadoop_conf_dir(force_latest_on_upgrade=False):
|
|
|
# determine if hdp-select has been run and if not, then use the current
|
|
|
# hdp version until this component is upgraded
|
|
|
if not force_latest_on_upgrade:
|
|
|
- current_hdp_version = get_role_component_current_hdp_version()
|
|
|
+ current_hdp_version = hdp_select.get_role_component_current_hdp_version()
|
|
|
if current_hdp_version is not None and stack_version != current_hdp_version:
|
|
|
stack_version = current_hdp_version
|
|
|
|
|
@@ -179,65 +114,6 @@ def get_hadoop_conf_dir(force_latest_on_upgrade=False):
|
|
|
|
|
|
return hadoop_conf_dir
|
|
|
|
|
|
-def get_hadoop_dir(target):
|
|
|
- """
|
|
|
- Return the hadoop shared directory in the following override order
|
|
|
- 1. Use default for 2.1 and lower
|
|
|
- 2. If 2.2 and higher, use /usr/hdp/current/hadoop-client/{target}
|
|
|
- 3. If 2.2 and higher AND for an upgrade, use /usr/hdp/<version>/hadoop/{target}.
|
|
|
- However, if the upgrade has not yet invoked hdp-select, return the current
|
|
|
- version of the component.
|
|
|
- :target: the target directory
|
|
|
- """
|
|
|
-
|
|
|
- if not target in HADOOP_DIR_DEFAULTS:
|
|
|
- raise Fail("Target {0} not defined".format(target))
|
|
|
-
|
|
|
- hadoop_dir = HADOOP_DIR_DEFAULTS[target]
|
|
|
-
|
|
|
- if Script.is_hdp_stack_greater_or_equal("2.2"):
|
|
|
- hadoop_dir = HADOOP_DIR_TEMPLATE.format("current", "hadoop-client", target)
|
|
|
-
|
|
|
- stack_info = _get_upgrade_stack()
|
|
|
-
|
|
|
- if stack_info is not None:
|
|
|
- stack_version = stack_info[1]
|
|
|
-
|
|
|
- # determine if hdp-select has been run and if not, then use the current
|
|
|
- # hdp version until this component is upgraded
|
|
|
- current_hdp_version = get_role_component_current_hdp_version()
|
|
|
- if current_hdp_version is not None and stack_version != current_hdp_version:
|
|
|
- stack_version = current_hdp_version
|
|
|
-
|
|
|
- hadoop_dir = HADOOP_DIR_TEMPLATE.format(stack_version, "hadoop", target)
|
|
|
-
|
|
|
- return hadoop_dir
|
|
|
-
|
|
|
-
|
|
|
-def get_role_component_current_hdp_version():
|
|
|
- """
|
|
|
- Gets the current HDP version of the component that this role command is for.
|
|
|
- :return: the current HDP version of the specified component or None
|
|
|
- """
|
|
|
- hdp_select_component = None
|
|
|
- role = default("/role", "")
|
|
|
- role_command = default("/roleCommand", "")
|
|
|
-
|
|
|
- if role in SERVER_ROLE_DIRECTORY_MAP:
|
|
|
- hdp_select_component = SERVER_ROLE_DIRECTORY_MAP[role]
|
|
|
- elif role_command == "SERVICE_CHECK" and role in SERVICE_CHECK_DIRECTORY_MAP:
|
|
|
- hdp_select_component = SERVICE_CHECK_DIRECTORY_MAP[role]
|
|
|
-
|
|
|
- if hdp_select_component is None:
|
|
|
- return None
|
|
|
|
|
|
- current_hdp_version = get_hdp_version(hdp_select_component)
|
|
|
|
|
|
- if current_hdp_version is None:
|
|
|
- Logger.warning("Unable to determine hdp-select version for {0}".format(
|
|
|
- hdp_select_component))
|
|
|
- else:
|
|
|
- Logger.info("{0} is currently at version {1}".format(
|
|
|
- hdp_select_component, current_hdp_version))
|
|
|
|
|
|
- return current_hdp_version
|