Path: blob/develop/awscli/customizations/emr/applicationutils.py
1567 views
# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License"). You3# may not use this file except in compliance with the License. A copy of4# the License is located at5#6# http://aws.amazon.com/apache2.0/7#8# or in the "license" file accompanying this file. This file is9# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF10# ANY KIND, either express or implied. See the License for the specific11# language governing permissions and limitations under the License.1213from awscli.customizations.emr import constants14from awscli.customizations.emr import emrutils15from awscli.customizations.emr import exceptions161718def build_applications(region,19parsed_applications, ami_version=None):20app_list = []21step_list = []22ba_list = []2324for app_config in parsed_applications:25app_name = app_config['Name'].lower()2627if app_name == constants.HIVE:28hive_version = constants.LATEST29step_list.append(30_build_install_hive_step(region=region))31args = app_config.get('Args')32if args is not None:33hive_site_path = _find_matching_arg(34key=constants.HIVE_SITE_KEY, args_list=args)35if hive_site_path is not None:36step_list.append(37_build_install_hive_site_step(38region=region,39hive_site_path=hive_site_path))40elif app_name == constants.PIG:41pig_version = constants.LATEST42step_list.append(43_build_pig_install_step(44region=region))45elif app_name == constants.GANGLIA:46ba_list.append(47_build_ganglia_install_bootstrap_action(48region=region))49elif app_name == constants.HBASE:50ba_list.append(51_build_hbase_install_bootstrap_action(52region=region))53if ami_version >= '3.0':54step_list.append(55_build_hbase_install_step(56constants.HBASE_PATH_HADOOP2_INSTALL_JAR))57elif ami_version >= '2.1':58step_list.append(59_build_hbase_install_step(60constants.HBASE_PATH_HADOOP1_INSTALL_JAR))61else:62raise ValueError('aws: error: AMI version ' + ami_version +63'is not compatible with HBase.')64elif app_name == constants.IMPALA:65ba_list.append(66_build_impala_install_bootstrap_action(67region=region,68args=app_config.get('Args')))69else:70app_list.append(71_build_supported_product(72app_config['Name'], app_config.get('Args')))7374return app_list, ba_list, step_list757677def _build_supported_product(name, args):78if args is None:79args = []80config = {'Name': name.lower(), 'Args': args}81return config828384def _build_ganglia_install_bootstrap_action(region):85return emrutils.build_bootstrap_action(86name=constants.INSTALL_GANGLIA_NAME,87path=emrutils.build_s3_link(88relative_path=constants.GANGLIA_INSTALL_BA_PATH,89region=region))909192def _build_hbase_install_bootstrap_action(region):93return emrutils.build_bootstrap_action(94name=constants.INSTALL_HBASE_NAME,95path=emrutils.build_s3_link(96relative_path=constants.HBASE_INSTALL_BA_PATH,97region=region))9899100def _build_hbase_install_step(jar):101return emrutils.build_step(102jar=jar,103name=constants.START_HBASE_NAME,104action_on_failure=constants.TERMINATE_CLUSTER,105args=constants.HBASE_INSTALL_ARG)106107108def _build_impala_install_bootstrap_action(region, args=None):109args_list = [110constants.BASE_PATH_ARG,111emrutils.build_s3_link(region=region),112constants.IMPALA_VERSION,113constants.LATEST]114if args is not None:115args_list.append(constants.IMPALA_CONF)116args_list.append(','.join(args))117return emrutils.build_bootstrap_action(118name=constants.INSTALL_IMPALA_NAME,119path=emrutils.build_s3_link(120relative_path=constants.IMPALA_INSTALL_PATH,121region=region),122args=args_list)123124125def _build_install_hive_step(region,126action_on_failure=constants.TERMINATE_CLUSTER):127step_args = [128emrutils.build_s3_link(constants.HIVE_SCRIPT_PATH, region),129constants.INSTALL_HIVE_ARG,130constants.BASE_PATH_ARG,131emrutils.build_s3_link(constants.HIVE_BASE_PATH, region),132constants.HIVE_VERSIONS,133constants.LATEST]134step = emrutils.build_step(135name=constants.INSTALL_HIVE_NAME,136action_on_failure=action_on_failure,137jar=emrutils.build_s3_link(constants.SCRIPT_RUNNER_PATH, region),138args=step_args)139return step140141142def _build_install_hive_site_step(region, hive_site_path,143action_on_failure=constants.CANCEL_AND_WAIT):144step_args = [145emrutils.build_s3_link(constants.HIVE_SCRIPT_PATH, region),146constants.BASE_PATH_ARG,147emrutils.build_s3_link(constants.HIVE_BASE_PATH),148constants.INSTALL_HIVE_SITE_ARG,149hive_site_path,150constants.HIVE_VERSIONS,151constants.LATEST]152step = emrutils.build_step(153name=constants.INSTALL_HIVE_SITE_NAME,154action_on_failure=action_on_failure,155jar=emrutils.build_s3_link(constants.SCRIPT_RUNNER_PATH, region),156args=step_args)157return step158159160def _build_pig_install_step(region,161action_on_failure=constants.TERMINATE_CLUSTER):162step_args = [163emrutils.build_s3_link(constants.PIG_SCRIPT_PATH, region),164constants.INSTALL_PIG_ARG,165constants.BASE_PATH_ARG,166emrutils.build_s3_link(constants.PIG_BASE_PATH, region),167constants.PIG_VERSIONS,168constants.LATEST]169step = emrutils.build_step(170name=constants.INSTALL_PIG_NAME,171action_on_failure=action_on_failure,172jar=emrutils.build_s3_link(constants.SCRIPT_RUNNER_PATH, region),173args=step_args)174return step175176177def _find_matching_arg(key, args_list):178for arg in args_list:179if key in arg:180return arg181182return None183184185