def actionexecute(self, env): resolve_ambari_config() # Parse parameters from command json file. config = Script.get_config() host_name = socket.gethostname() version = default('/roleParams/version', None) # These 2 variables are optional service_package_folder = default('/roleParams/service_package_folder', None) hooks_folder = default('/roleParams/hooks_folder', None) tasks = json.loads(config['roleParams']['tasks']) if tasks: for t in tasks: task = ExecuteTask(t) Logger.info(str(task)) # If a (script, function) exists, it overwrites the command. if task.script and task.function and service_package_folder and hooks_folder: file_cache = FileCache(agent_config) command_paths = { "commandParams": { "service_package_folder": service_package_folder, "hooks_folder": hooks_folder } } server_url_prefix = default( '/hostLevelParams/jdk_location', "") base_dir = file_cache.get_service_base_dir( command_paths, server_url_prefix) script_path = os.path.join(base_dir, task.script) if not os.path.exists(script_path): message = "Script %s does not exist" % str(script_path) raise Fail(message) # Notice that the script_path is now the fully qualified path, and the # same command-#.json file is used. # Also, the python wrapper is used, since it sets up the correct environment variables command_params = [ "/usr/bin/ambari-python-wrap", script_path, task.function, self.command_data_file, self.basedir, self.stroutfile, self.logging_level, Script.get_tmp_dir() ] task.command = " ".join(command_params) # Replace redundant whitespace to make the unit tests easier to validate task.command = re.sub("\s+", " ", task.command).strip() if task.command: task.command = replace_variables(task.command, host_name, version) code, out = shell.call(task.command) Logger.info("Command: %s\nCode: %s, Out: %s" % (task.command, str(code), str(out))) if code != 0: raise Fail(out)
def actionexecute(self, env): resolve_ambari_config() # Parse parameters from command json file. config = Script.get_config() host_name = socket.gethostname() version = default('/roleParams/version', None) # These 2 variables are optional service_package_folder = default('/roleParams/service_package_folder', None) hooks_folder = default('/roleParams/hooks_folder', None) tasks = json.loads(config['roleParams']['tasks']) if tasks: for t in tasks: task = ExecuteTask(t) Logger.info(str(task)) # If a (script, function) exists, it overwrites the command. if task.script and task.function and service_package_folder and hooks_folder: file_cache = FileCache(agent_config) command_paths = {"commandParams": {"service_package_folder": service_package_folder, "hooks_folder": hooks_folder } } server_url_prefix = default('/hostLevelParams/jdk_location', "") base_dir = file_cache.get_service_base_dir(command_paths, server_url_prefix) script_path = os.path.join(base_dir, task.script) if not os.path.exists(script_path): message = "Script %s does not exist" % str(script_path) raise Fail(message) # Notice that the script_path is now the fully qualified path, and the # same command-#.json file is used. # Also, the python wrapper is used, since it sets up the correct environment variables command_params = ["/usr/bin/ambari-python-wrap", script_path, task.function, self.command_data_file, self.basedir, self.stroutfile, self.logging_level, Script.get_tmp_dir()] task.command = " ".join(command_params) # Replace redundant whitespace to make the unit tests easier to validate task.command = re.sub("\s+", " ", task.command).strip() if task.command: task.command = replace_variables(task.command, host_name, version) code, out = shell.call(task.command) Logger.info("Command: %s\nCode: %s, Out: %s" % (task.command, str(code), str(out))) if code != 0: raise Fail(out)
from resource_management.libraries.functions import format from resource_management.libraries.functions import conf_select from resource_management.libraries.functions import stack_select from resource_management.libraries.functions import format_jvm_option from resource_management.libraries.functions.is_empty import is_empty from resource_management.libraries.functions.version import format_stack_version from resource_management.libraries.functions.expect import expect from resource_management.libraries.functions import StackFeature from resource_management.libraries.functions.stack_features import check_stack_feature from resource_management.libraries.functions.stack_features import get_stack_feature_version from resource_management.libraries.functions.get_architecture import get_architecture from ambari_commons.constants import AMBARI_SUDO_BINARY from resource_management.libraries.functions.namenode_ha_utils import get_properties_for_all_nameservices, namenode_federation_enabled config = Script.get_config() tmp_dir = Script.get_tmp_dir() stack_root = Script.get_stack_root() architecture = get_architecture() dfs_type = default("/clusterLevelParams/dfs_type", "") artifact_dir = format("{tmp_dir}/AMBARI-artifacts/") jdk_name = default("/ambariLevelParams/jdk_name", None) java_home = config['ambariLevelParams']['java_home'] java_version = expect("/ambariLevelParams/java_version", int) jdk_location = config['ambariLevelParams']['jdk_location'] hadoop_custom_extensions_enabled = default( "/configurations/core-site/hadoop.custom-extensions.enabled", False)
import ambari_simplejson as json # simplejson is much faster comparing to Python 2.6 json module and has the same functions set. from resource_management.libraries.script import Script from resource_management.libraries.functions import default from resource_management.libraries.functions import format from resource_management.libraries.functions import conf_select from resource_management.libraries.functions import hdp_select from resource_management.libraries.functions import format_jvm_option from resource_management.libraries.functions.version import format_hdp_stack_version from resource_management.libraries.functions.version import compare_versions from ambari_commons.os_check import OSCheck config = Script.get_config() tmp_dir = Script.get_tmp_dir() artifact_dir = format("{tmp_dir}/AMBARI-artifacts/") jce_policy_zip = default("/hostLevelParams/jce_name", None) # None when jdk is already installed by user jce_location = config['hostLevelParams']['jdk_location'] jdk_name = default("/hostLevelParams/jdk_name", None) java_home = config['hostLevelParams']['java_home'] java_version = int(config['hostLevelParams']['java_version']) ambari_server_hostname = config['clusterHostInfo']['ambari_server_host'][0] stack_version_unformatted = str(config['hostLevelParams']['stack_version']) hdp_stack_version = format_hdp_stack_version(stack_version_unformatted) security_enabled = config['configurations']['cluster-env']['security_enabled'] hdfs_user = config['configurations']['hadoop-env']['hdfs_user']
def actionexecute(self, env): resolve_ambari_config() # Parse parameters from command json file. config = Script.get_config() host_name = socket.gethostname() version = default('/roleParams/version', None) # These 2 variables are optional service_package_folder = default( '/commandParams/service_package_folder', None) if service_package_folder is None: service_package_folder = default( '/serviceLevelParams/service_package_folder', None) hooks_folder = default('/commandParams/hooks_folder', None) tasks = json.loads(config['roleParams']['tasks']) if tasks: for t in tasks: task = ExecuteTask(t) Logger.info(str(task)) # If a (script, function) exists, it overwrites the command. if task.script and task.function: file_cache = FileCache(agent_config) if service_package_folder and hooks_folder: command_paths = { "commandParams": { "service_package_folder": service_package_folder, }, "clusterLevelParams": { "hooks_folder": hooks_folder }, "ambariLevelParams": { "jdk_location": default('/ambariLevelParams/jdk_location', "") } } base_dir = file_cache.get_service_base_dir( command_paths) else: base_dir = file_cache.get_custom_actions_base_dir({ "ambariLevelParams": { "jdk_location": default('/ambariLevelParams/jdk_location', "") } }) script_path = os.path.join(base_dir, task.script) if not os.path.exists(script_path): message = "Script %s does not exist" % str(script_path) raise Fail(message) # Notice that the script_path is now the fully qualified path, and the # same command-#.json file is used. # Also, the python wrapper is used, since it sets up the correct environment variables command_params = [ "/usr/bin/ambari-python-wrap", script_path, task.function, self.command_data_file, self.basedir, self.stroutfile, self.logging_level, Script.get_tmp_dir() ] task.command = "source /var/lib/ambari-agent/ambari-env.sh ; " + " ".join( command_params) # Replace redundant whitespace to make the unit tests easier to validate task.command = re.sub("\s+", " ", task.command).strip() if task.command: task.command = replace_variables(task.command, host_name, version) shell.checked_call(task.command, logoutput=True, quiet=True)