|
@@ -37,6 +37,7 @@ from resource_management.core.exceptions import Fail, ClientComponentHasNoStatus
|
|
from resource_management.core.resources.packaging import Package
|
|
from resource_management.core.resources.packaging import Package
|
|
from resource_management.libraries.functions.version_select_util import get_component_version
|
|
from resource_management.libraries.functions.version_select_util import get_component_version
|
|
from resource_management.libraries.functions.version import compare_versions
|
|
from resource_management.libraries.functions.version import compare_versions
|
|
|
|
+from resource_management.libraries.functions.version import format_hdp_stack_version
|
|
from resource_management.libraries.script.config_dictionary import ConfigDictionary, UnknownConfiguration
|
|
from resource_management.libraries.script.config_dictionary import ConfigDictionary, UnknownConfiguration
|
|
|
|
|
|
if OSCheck.is_windows_family():
|
|
if OSCheck.is_windows_family():
|
|
@@ -115,23 +116,45 @@ class Script(object):
|
|
except IOError, err:
|
|
except IOError, err:
|
|
Script.structuredOut.update({"errMsg" : "Unable to write to " + self.stroutfile})
|
|
Script.structuredOut.update({"errMsg" : "Unable to write to " + self.stroutfile})
|
|
|
|
|
|
- def save_component_version_to_structured_out(self, stack_name):
|
|
|
|
|
|
+ def save_component_version_to_structured_out(self):
|
|
"""
|
|
"""
|
|
:param stack_name: One of HDP, HDPWIN, PHD, BIGTOP.
|
|
:param stack_name: One of HDP, HDPWIN, PHD, BIGTOP.
|
|
:return: Append the version number to the structured out.
|
|
:return: Append the version number to the structured out.
|
|
"""
|
|
"""
|
|
- import params
|
|
|
|
- component_version = None
|
|
|
|
-
|
|
|
|
|
|
+ from resource_management.libraries.functions.default import default
|
|
|
|
+ stack_name = default("/hostLevelParams/stack_name", None)
|
|
stack_to_component = self.get_stack_to_component()
|
|
stack_to_component = self.get_stack_to_component()
|
|
- if stack_to_component:
|
|
|
|
- if stack_name == "HDP" and params.hdp_stack_version != "" and compare_versions(params.hdp_stack_version, '2.2') >= 0:
|
|
|
|
- component_name = stack_to_component[stack_name] if stack_name in stack_to_component else None
|
|
|
|
- component_version = get_component_version(stack_name, component_name)
|
|
|
|
|
|
+ if stack_to_component and stack_name:
|
|
|
|
+ component_name = stack_to_component[stack_name] if stack_name in stack_to_component else None
|
|
|
|
+ component_version = get_component_version(stack_name, component_name)
|
|
|
|
|
|
if component_version:
|
|
if component_version:
|
|
self.put_structured_out({"version": component_version})
|
|
self.put_structured_out({"version": component_version})
|
|
|
|
|
|
|
|
+ def should_expose_component_version(self, command_name):
|
|
|
|
+ """
|
|
|
|
+ Analyzes config and given command to determine if stack version should be written
|
|
|
|
+ to structured out. Currently only HDP stack versions >= 2.2 are supported.
|
|
|
|
+ :param command_name: command name
|
|
|
|
+ :return: True or False
|
|
|
|
+ """
|
|
|
|
+ from resource_management.libraries.functions.default import default
|
|
|
|
+ stack_version_unformatted = str(default("/hostLevelParams/stack_version", ""))
|
|
|
|
+ hdp_stack_version = format_hdp_stack_version(stack_version_unformatted)
|
|
|
|
+ if hdp_stack_version != "" and compare_versions(hdp_stack_version, '2.2') >= 0:
|
|
|
|
+ if command_name.lower() == "status":
|
|
|
|
+ request_version = default("/commandParams/request_version", None)
|
|
|
|
+ if request_version is not None:
|
|
|
|
+ return True
|
|
|
|
+ else:
|
|
|
|
+ if "version" in Script.structuredOut:
|
|
|
|
+ del Script.structuredOut["version"]
|
|
|
|
+ Script.structuredOut.update({})
|
|
|
|
+ else:
|
|
|
|
+ # Populate version only on base commands
|
|
|
|
+ return command_name.lower() == "start" or command_name.lower() == "install" or command_name.lower() == "restart"
|
|
|
|
+ return False
|
|
|
|
+
|
|
def execute(self):
|
|
def execute(self):
|
|
"""
|
|
"""
|
|
Sets up logging;
|
|
Sets up logging;
|
|
@@ -183,16 +206,6 @@ class Script(object):
|
|
with Environment(self.basedir, tmp_dir=Script.tmp_dir) as env:
|
|
with Environment(self.basedir, tmp_dir=Script.tmp_dir) as env:
|
|
env.config.download_path = Script.tmp_dir
|
|
env.config.download_path = Script.tmp_dir
|
|
method(env)
|
|
method(env)
|
|
-
|
|
|
|
- # For start actions, try to advertise the component's version
|
|
|
|
- if command_name.lower() == "start" or command_name.lower() == "install":
|
|
|
|
- try:
|
|
|
|
- import params
|
|
|
|
- # This is to support older stacks
|
|
|
|
- if hasattr(params, "stack_name"):
|
|
|
|
- self.save_component_version_to_structured_out(params.stack_name)
|
|
|
|
- except ImportError:
|
|
|
|
- logger.error("Executing command %s could not import params" % str(command_name))
|
|
|
|
except ClientComponentHasNoStatus or ComponentIsNotRunning:
|
|
except ClientComponentHasNoStatus or ComponentIsNotRunning:
|
|
# Support of component status checks.
|
|
# Support of component status checks.
|
|
# Non-zero exit code is interpreted as an INSTALLED status of a component
|
|
# Non-zero exit code is interpreted as an INSTALLED status of a component
|
|
@@ -200,7 +213,9 @@ class Script(object):
|
|
except Fail:
|
|
except Fail:
|
|
logger.exception("Error while executing command '{0}':".format(command_name))
|
|
logger.exception("Error while executing command '{0}':".format(command_name))
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
-
|
|
|
|
|
|
+ finally:
|
|
|
|
+ if self.should_expose_component_version(command_name):
|
|
|
|
+ self.save_component_version_to_structured_out()
|
|
|
|
|
|
def choose_method_to_execute(self, command_name):
|
|
def choose_method_to_execute(self, command_name):
|
|
"""
|
|
"""
|
|
@@ -350,13 +365,8 @@ class Script(object):
|
|
if rolling_restart:
|
|
if rolling_restart:
|
|
self.post_rolling_restart(env)
|
|
self.post_rolling_restart(env)
|
|
|
|
|
|
- try:
|
|
|
|
- import params
|
|
|
|
- if hasattr(params, "stack_name"):
|
|
|
|
- self.save_component_version_to_structured_out(params.stack_name)
|
|
|
|
- except ImportError:
|
|
|
|
- logger.error("Restart command could not import params")
|
|
|
|
-
|
|
|
|
|
|
+ if self.should_expose_component_version("restart"):
|
|
|
|
+ self.save_component_version_to_structured_out()
|
|
|
|
|
|
def post_rolling_restart(self, env):
|
|
def post_rolling_restart(self, env):
|
|
"""
|
|
"""
|