更新时间:2024-01-23 GMT+08:00
分享

创建集群并提交作业

功能介绍

创建一个MRS集群并提交作业,并支持作业完成后删除集群,支持MRS 1.8.9及以上集群版本使用。使用接口前,您需要先获取下的资源信息。

  • 通过VPC创建或查询VPC、子网

  • 通过ECS创建或查询密钥对

  • 通过终端节点获取区域信息

  • 参考MRS服务支持的组件获取MRS版本及对应版本支持的组件信息

接口约束

调用方法

请参见如何调用API

URI

POST /v2/{project_id}/run-job-flow

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目编号。获取方法,请参见获取项目ID

请求参数

表2 请求Body参数

参数

是否必选

参数类型

描述

is_dec_project

Boolean

说明是否为专属云的资源,默认为false。

cluster_version

String

集群版本。例如:MRS 3.1.0。

cluster_name

String

集群名称,不允许相同。

只能由字母、数字、中划线和下划线组成,并且长度为1~64个字符。

cluster_type

String

集群类型,取值范围:

  • ANALYSIS:分析集群

  • STREAMING:流式集群

  • MIXED:混合集群

  • CUSTOM:自定义集群,仅MRS 3.x版本支持。

charge_info

ChargeInfo object

计费类型信息。

region

String

集群所在区域信息,请参见终端节点

vpc_name

String

子网所在VPC名称。 通过VPC管理控制台获取名称:

  1. 登录VPC管理控制台。

  2. 单击“虚拟私有云”,从左侧列表选择虚拟私有云。 在“虚拟私有云”页面的列表中即可获取VPC名称。

subnet_id

String

子网ID。通过VPC管理控制台获取子网ID:

  1. 登录VPC管理控制台。

  2. 单击“虚拟私有云”,从左侧列表选择虚拟私有云。

  3. 单击对应虚拟私有云所在行的“子网个数”查看子网。

  4. 单击对应子网名称,获取“网络ID”。 “subnet_id”和“subnet_name”必须至少填写一个,当这两个参数同时配置但是不匹配同一个子网时,集群会创建失败,请仔细填写参数。推荐使用“subnet_id”。

subnet_name

String

子网名称。 通过VPC管理控制台获取子网名称:

  1. 登录管理控制台。

  2. 单击“虚拟私有云”,从左侧列表选择虚拟私有云。

  3. 单击对应虚拟私有云所在行的“子网个数”查看子网,获取子网名称。 “subnet_id”和“subnet_name”必须至少填写一个,当这两个参数同时配置但是不匹配同一个子网时,集群会创建失败,请仔细填写参数。当仅填写“subnet_name”一个参数且VPC下存在同名子网时,创建集群时以VPC平台第一个名称的子网为准。推荐使用“subnet_id”。

components

String

组件名称列表,用逗号分隔。支持的组件请参见获取MRS集群信息页面的“MRS服务支持的组件”内容。

external_datasources

Array of ClusterDataConnectorMap objects

部署Hive和Ranger等组件时,可以关联数据连接,将元数据存储于关联的数据库

availability_zone

String

可用分区名称,不支持多AZ集群。 可用分区信息请参见终端节点

security_groups_id

String

集群安全组的ID。

  • 当该ID为空时MRS后台会自动创建安全组,自动创建的安全组名称以mrs_{cluster_name}开头。

  • 当该ID不为空时,表示使用固定安全组来创建集群,传入的ID必须是当前租户中包含的安全组ID,且该安全组中需要包含一条支持全部协议、全部端口、源地址为指定的管理面节点IP的入方向规则。

  • 支持多个安全组ID,以逗号分隔。

auto_create_default_security_group

Boolean

是否要创建MRS集群默认安全组,默认为false。 当指定该参数为true,则无论“security_groups_id”参数是否指定,都会为集群创建默认安全组。

safe_mode

String

MRS集群运行模式。

  • SIMPLE:普通集群,表示Kerberos认证关闭,用户可使用集群提供的所有功能。

  • KERBEROS:安全集群,表示Kerberos认证开启,普通用户无权限使用MRS集群的“文件管理”和“作业管理”功能,并且无法查看Hadoop、Spark的作业记录以及集群资源使用情况。如果需要使用集群更多功能,需要找Manager的管理员分配权限。

manager_admin_password

String

配置Manager管理员用户的密码。

  • 密码长度应在8~26个字符之间。

  • 至少包含四种字符组合,如大写字母,小写字母,数字,特殊字符(!@$%^-_=+[{}]:,./?),但不能包含空格。

  • 不能与用户名或者倒序用户名相同。

login_mode

String

节点登录方式。

  • PASSWORD:密码登录,选择此项时,node_root_password不能为空。

  • KEYPAIR:密钥对登录,选择此项时,node_keypair_name不能为空。

node_root_password

String

配置访问集群节点的root密码。 密码设置约束如下:

  • 字符串类型,可输入的字符串长度为8-26。

  • 至少包含四种字符组合,如大写字母,小写字母,数字,特殊字符(!@$%^-_=+[{}]:,./?),但不能包含空格。

  • 不能与用户名或者倒序用户名相同。

node_keypair_name

String

密钥对名称。用户可以使用密钥对方式登录集群节点。

enterprise_project_id

String

企业项目ID。 创建集群时,给集群绑定企业项目ID。 默认设置为0,表示为default企业项目。 获取方式请参见《企业管理API参考》的“查询企业项目列表”响应消息表“enterprise_project字段数据结构说明”的“id”。

eip_address

String

与MRS集群绑定的弹性公网IP,可实现使用弹性公网IP访问Manager的目的。该弹性公网IP必须已经创建且与集群在同一区域。

eip_id

String

当“eip_address”配置时,该参数必须配置,用于表示绑定的弹性公网IP的ID。可通过在VPC服务的“网络控制台 > 弹性公网IP和带宽 > 弹性公网IP”页面单击待绑定的弹性公网IP,在基本信息中获取“ID”。

mrs_ecs_default_agency

String

集群节点默认绑定的委托名称,固定为MRS_ECS_DEFAULT_AGENCY。 通过绑定委托,您可以将部分资源共享给ECS或BMS云服务来管理,例如通过配置ECS委托可自动获取AK/SK访问OBS。 MRS_ECS_DEFAULT_AGENCY委托拥有对象存储服务的OBS OperateAccess权限和在集群所在区域拥有CES FullAccess(对开启细粒度策略的用户)、CES Administrator和KMS Administrator权限。

template_id

String

当集群类型为CUSTOM时,用于指定节点部署所使用的模板。

  • mgmt_control_combined_v2:管控合设模板,管理角色和控制角色共同部署在Master节点中,数据实例合设在同一节点组。该部署方式适用于100个以下的节点,可以减少成本。

  • mgmt_control_separated_v2:管控分设模板,管理角色和控制角色分别部署在不同的Master节点中,数据实例合设在同一节点组。该部署方式适用于100-500个节点,在高并发负载情况下表现更好。

  • mgmt_control_data_separated_v2:数据分设模板,管理角色和控制角色分别部署在不同的Master节点中,数据实例分设在不同节点组。该部署方式适用于500个以上的节点,可以将各组件进一步分开部署,适用于更大的集群规模。

tags

Array of Tag objects

集群的标签信息。

同一个集群最多能使用10个tag,tag的名称(key)不能重复。

log_collection

Integer

集群创建失败时,是否收集失败日志。 默认设置为1,此时将创建OBS桶仅用于MRS集群创建失败时的日志收集。 枚举值:

  • 0:不收集

  • 1:收集

node_groups

Array of NodeGroupV2 objects

组成集群的节点组信息。

bootstrap_scripts

Array of BootstrapScript objects

配置引导操作脚本信息。

log_uri

String

集群日志转储至OBS的具体路径。 开启日志转储功能后,日志上传需要对应OBS路径的读写权限, 请配置MRS_ECS_DEFULT_AGENCY默认委托或具有对应OBS路径读写权限的自定义委托。 具体请参见配置存算分离集群(委托方式)。 该参数只适用于支持“集群日志转储OBS”特性的集群版本。

component_configs

Array of ComponentConfig objects

集群组件自定义配置。 该参数只适用于支持“自定义组件配置创建集群”特性的集群版本。

delete_when_no_steps

Boolean

作业完成后是否自动删除集群,默认为false。

steps

Array of StepConfig objects

作业列表。

表3 ClusterDataConnectorMap

参数

是否必选

参数类型

描述

map_id

Integer

数据连接关联ID值

connector_id

String

数据连接ID值

component_name

String

组件名

role_type

String

组件角色类型。

  • hive_metastore:Hive Metastore角色

  • hive_data:Hive角色

  • hbase_data:Hbase角色

  • ranger_data:Ranger角色

source_type

String

数据连接类型。

  • LOCAL_DB:本地元数据

  • RDS_POSTGRES:RDS服务PostgreSQL数据库

  • RDS_MYSQL:RDS服务MySQL数据库

  • gaussdb-mysql:云数据库GaussDB(for MySQL)

cluster_id

String

关联集群id

status

Integer

数据连接状态。

  • 0:代表正常状态

  • 1:代表使用中

表4 Tag

参数

是否必选

参数类型

描述

key

String

键。

  • 最大长度36个unicode字符,不能为空字符串。

  • 标签的key值不能包含非打印字符ASCII(0-31),“=”,“*”,“<”,“>”,“\”,“,”,“|”,“/”,且首尾字符不能为空格。

  • 同一资源的key值不能重复。

value

String

值。

  • 最大长度43个unicode字符,可以为空字符串。

  • 标签的value值不能包含非打印字符ASCII(0-31),“=”,“*”,“<”,“>”,“\”,“,”,“|”,“/”,且首尾字符不能为空格。

表5 NodeGroupV2

参数

是否必选

参数类型

描述

group_name

String

节点组名称,最大长度64,支持大小写英文、数字以及“_”。节点组配置原则如下:

  • master_node_default_group:Master节点组,所有集群类型均需包含该节点组。

  • core_node_analysis_group:分析Core节点组,分析集群、混合集群均需包含该节点组。

  • core_node_streaming_group:流式Core节点组,流式集群和混合集群均需包含该节点组。

  • task_node_analysis_group:分析Task节点组,分析集群和混合集群可根据需要选择该节点组。

  • task_node_streaming_group:流式Task节点组,流式集群、混合集群可根据需要选择该节点组。

  • node_group{x}:自定义集群节点组,可根据需要添加多个,最多支持添加9个该节点组。

node_num

Integer

节点数量,取值范围0~500,Core与Task节点总数最大为500个。

node_size

String

节点的实例规格。 例如:c3.4xlarge.2.linux.bigdata。实例规格详细说明请参见MRS所使用的弹性云服务器规格MRS所使用的裸金属服务器规格。 该参数建议从MRS控制台的集群创建页面获取对应区域对应版本所支持的规格。

root_volume

Volume object

节点系统盘信息,部分虚拟机或BMS自带系统盘的情况该参数可选,其他情况该参数必选。

data_volume

Volume object

节点数据盘信息,当data_volume_count不为0时,该参数必选。

data_volume_count

Integer

节点数据磁盘存储数目,取值范围:0~10。

charge_info

ChargeInfo object

节点组的计费类型,Master和Core节点组是和集群的计费类型一致,Task节点组可以和集群的计费类型不同。

auto_scaling_policy

AutoScalingPolicy object

弹性伸缩规则信息。

assigned_roles

Array of strings

当集群类型为CUSTOM时,该参数必选。可以指定节点组中部署的角色,该参数是一个字符串数组,每个字符串表示一个角色表达式。 角色表达式定义:

  • 当该角色在节点组所有节点部署时: {role name},如“DataNode”。

  • 当该角色在节点组指定下标节点部署时:{role name}:{index1},{index2}…,{indexN},如“NameNode:1,2”,下标从1开始计数。

  • 部分角色支持多实例部署(即在一个节点部署多个同角色的实例):{role name}[{instance count}],如“EsNode[9]” 可选的角色请参考MRS支持的角色与组件对应表

表6 Volume

参数

是否必选

参数类型

描述

type

String

磁盘类型。 磁盘类型枚举值:

  • SATA:普通IO磁盘类型。

  • SAS:高IO磁盘类型。

  • SSD:超高IO磁盘类型。

  • GPSSD:通用型SSD磁盘类型

size

Integer

数据盘大小,容量单位为GB,输入大小范围为[10,32768]。

表7 ChargeInfo

参数

是否必选

参数类型

描述

charge_mode

String

计费模式。取值范围:

  • prePaid:预付费,即包年/包月。(创建集群接口现已支持预付费,创建集群并提交作业接口暂不支持预付费。)

  • postPaid:后付费,即按需计费。

period_type

String

周期类型。取值范围:

  • month:包月。

  • year: 包年。

  • day:按需计费

period_num

Integer

周期数,“charge_mode”为“prePaid”时生效,且为必选值,指定订购的时间。取值范围:

  • 当“period_type”为“month”时,取值为1~9。

  • 当“period_type”为“year”时,取值为1~3。

is_auto_pay

Boolean

是否自动支付,包周期模式下使用,下单订购后,是否自动从客户的账户中支付,而不需要客户手动去进行支付,默认为手动支付。取值范围:

  • true:自动支付,会自动选择折扣和优惠券进行优惠,然后自动从客户账户中支付,自动支付失败后会生成订单成功、但订单状态为“待支付”,等待客户手动支付。

  • false:手动支付,需要客户手动去支付,客户可以选择折扣和优惠券。

表8 AutoScalingPolicy

参数

是否必选

参数类型

描述

auto_scaling_enable

Boolean

当前自动伸缩规则是否开启。

min_capacity

Integer

指定该节点组的最小保留节点数。 取值范围:[0~500]

max_capacity

Integer

指定该节点组的最大节点数。 取值范围:[0~500]

resources_plans

Array of ResourcesPlan objects

资源计划列表。若该参数为空表示不启用资源计划。

当启用弹性伸缩时,资源计划与自动伸缩规则需至少配置其中一种。

rules

Array of Rule objects

自动伸缩的规则列表。当启用弹性伸缩时,资源计划与自动伸缩规则需至少配置其中一种。

exec_scripts

Array of ScaleScript objects

弹性伸缩自定义自动化脚本列表。若该参数为空表示不启用自动化脚本。在V2弹性伸缩策略创建和更新接口中暂时不支持该字段。

表9 ResourcesPlan

参数

是否必选

参数类型

描述

period_type

String

资源计划的周期类型,当前只允许以下类型:

daily

start_time

String

资源计划的起始时间,格式为“hour:minute”,表示时间在0:00-23:59之间。

end_time

String

资源计划的结束时间,格式与“start_time”相同,不早于start_time表示的时间,且与start_time间隔不小于30min。

min_capacity

Integer

资源计划内该节点组的最小保留节点数。 取值范围:[0~500]

max_capacity

Integer

资源计划内该节点组的最大保留节点数。 取值范围:[0~500]

effective_days

Array of strings

资源计划的生效日期,为空时代表每日,另外也可为以下返回值:

MONDAY(周一)、TUESDAY(周二)、WEDNESDAY(周三)、THURSDAY(周四)、FRIDAY(周五)、SATURDAY(周六)、SUNDAY(周日)

表10 Rule

参数

是否必选

参数类型

描述

name

String

弹性伸缩规则的名称。 只能由字母、数字、中划线和下划线组成,并且长度为1~64个字符。 在一个节点组范围内,不允许重名。

description

String

弹性伸缩规则的说明。 最大长度为1024字符。

adjustment_type

String

弹性伸缩规则的调整类型,只允许以下类型: 枚举值:

  • scale_out:扩容

  • scale_in:缩容

cool_down_minutes

Integer

触发弹性伸缩规则后,该集群处于冷却状态(不再执行弹性伸缩操作)的时长,单位为分钟。 取值范围[0~10080],10080为一周的分钟数。

scaling_adjustment

Integer

单次调整集群节点的个数。 取值范围[1~100]

trigger

Trigger object

描述该规则触发条件。

表11 Trigger

参数

是否必选

参数类型

描述

metric_name

String

指标名称。 该触发条件会依据该名称对应指标的值来进行判断。 最大长度为64个字符。

metric_value

String

指标阈值。

触发该条件的指标阈值,只允许输入整数或者带两位小数的数。

comparison_operator

String

指标判断逻辑运算符,包括:

  • LT:小于

  • GT:大于

  • LTOE:小于等于

  • GTOE:大于等于

evaluation_periods

Integer

判断连续满足指标阈值的周期数(一个周期为5分钟)。 取值范围[1~288]

表12 ScaleScript

参数

是否必选

参数类型

描述

name

String

弹性伸缩自定义自动化脚本的名称,同一个集群的自定义自动化脚本名称不允许相同。 只能由数字、英文字符、空格、中划线和下划线组成,且不能以空格开头。 可输入的字符串长度为1~64个字符。

uri

String

自定义自动化脚本的路径。设置为OBS桶的路径或虚拟机本地的路径。

  • OBS桶的路径:直接手动输入脚本路径。示例:obs://XXX/scale.sh

  • 虚拟机本地的路径:用户需要输入正确的脚本路径。脚本所在的路径必须以‘/’开头,以.sh结尾。

parameters

String

自定义自动化脚本参数。 多个参数间用空格隔开。 可以传入以下系统预定义参数:

  • ${mrs_scale_node_num}:扩缩容节点数

  • ${mrs_scale_type}:扩缩容类型,扩容为scale_out,缩容为scale_in

  • ${mrs_scale_node_hostnames}:扩缩容的节点主机名称

  • ${mrs_scale_node_ips}:扩缩容的节点IP

  • ${mrs_scale_rule_name}:触发扩缩容的规则名

其他用户自定义参数使用方式与普通shell脚本相同,多个参数中间用空格隔开。

nodes

Array of strings

自定义自动化脚本所执行的节点组名称。

active_master

Boolean

自定义自动化脚本是否只运行在主Master节点上。 缺省值为false,表示自定义自动化脚本可运行在所有Master节点上。

fail_action

String

自定义自动化脚本执行失败后,是否继续执行后续脚本和创建集群。 说明:

  • 建议您在调试阶段设置为“continue”,无论此自定义自动化脚本是否执行成功,则集群都能继续安装和启动。

  • 由于缩容成功无法回滚,因此缩容后执行的脚本“fail_action”必须设置为“continue”。 枚举值:

  • continue:继续执行后续脚本。

  • errorout:终止操作。

action_stage

String

脚本执行时机。 枚举值:

  • before_scale_out:扩容前

  • before_scale_in:缩容前

  • after_scale_out:扩容后

  • after_scale_in:缩容后

表13 BootstrapScript

参数

是否必选

参数类型

描述

name

String

引导操作脚本的名称,同一个集群的引导操作脚本名称不允许相同。 只能由数字、英文字符、空格、中划线和下划线组成,且不能以空格开头。 可输入的字符串长度为1~64个字符。

uri

String

引导操作脚本的路径。设置为OBS桶的路径或虚拟机本地的路径。 OBS桶的路径:直接手动输入脚本路径。例如输入MRS提供的公共样例脚本路径。示例:obs://bootstrap/presto/presto-install.sh,其中安装dualroles时,presto-install.sh脚本参数为dualroles, 安装worker时,presto-install.sh脚本参数为worker。根据Presto使用习惯,建议您在Active Master节点上安装dualroles,在Core节点上安装worker。 虚拟机本地的路径:用户需要输入正确的脚本路径。脚本所在的路径必须以‘/’开头,以.sh结尾。

parameters

String

引导操作脚本参数。

nodes

Array of strings

引导操作脚本所执行的节点组名称。

active_master

Boolean

引导操作脚本是否只运行在主Master节点上。 缺省值为false,表示引导操作脚本可运行在所有Master节点上。

fail_action

String

引导操作脚本执行失败后,是否继续执行后续脚本和创建集群。 缺省值为errorout,表示终止操作。 说明: 建议您在调试阶段设置为“继续”,无论此引导操作是否执行成功,则集群都能继续安装和启动。 枚举值:

  • continue:继续执行后续脚本。

  • errorout:终止操作。

before_component_start

Boolean

引导操作脚本执行的时间。目前支持“组件启动前”和“组件启动后”两种类型。 缺省值为false,表示引导操作脚本在组件启动后执行。

start_time

Long

单个引导操作脚本的执行时间。

state

String

单个引导操作脚本的运行状态。

  • PENDING

  • IN_PROGRESS

  • SUCCESS

  • FAILURE

action_stages

Array of strings

选择引导操作脚本执行的时间。

  • BEFORE_COMPONENT_FIRST_START: 组件首次启动前

  • AFTER_COMPONENT_FIRST_START: 组件首次启动后

  • BEFORE_SCALE_IN: 缩容前

  • AFTER_SCALE_IN: 缩容后

  • BEFORE_SCALE_OUT: 扩容前

  • AFTER_SCALE_OUT: 扩容后

表14 ComponentConfig

参数

是否必选

参数类型

描述

component_name

String

组件名称

configs

Array of Config objects

组件配置项列表

表15 Config

参数

是否必选

参数类型

描述

key

String

配置名,仅支持MRS组件配置页面上所展示的配置名。

value

String

配置值

config_file_name

String

配置文件名,仅支持MRS组件配置页面上所展示的文件名。

表16 StepConfig

参数

是否必选

参数类型

描述

job_execution

JobExecution object

作业参数

表17 JobExecution

参数

是否必选

参数类型

描述

job_type

String

作业类型:

  • MapReduce

  • SparkSubmit

  • SparkPython:该类型作业将转换为SparkSubmit类型提交,MRS控制台界面的作业类型展示为SparkSubmit,通过接口查询作业列表信息时作业类型请选择SparkSubmit。

  • HiveScript

  • HiveSql

  • DistCp,导入、导出数据。

  • SparkScript

  • SparkSql

  • Flink

job_name

String

作业名称,只能由字母、数字、中划线和下划线组成,并且长度为1~64个字符。 说明: 不同作业的名称允许相同,但不建议设置相同。

arguments

Array of strings

程序执行的关键参数,该参数由用户程序内的函数指定,MRS只负责参数的传入。 最多为150000字符,不能包含;|&>'<$!"\特殊字符,可为空。 说明:

  • 若输入带有敏感信息(如登录密码)的参数可能在作业详情展示和日志打印中存在暴露的风险,请谨慎操作。

  • 提交HiveScript或HiveSql类型的作业时如需以“obs://”开头格式访问存储在OBS上的文件,请在Hive服务配置页面搜索参数“core.site.customized.configs”,新增OBS的endpoint配置项,参数为“fs.obs.endpoint”,值请输入OBS对应的endpoint,具体请参考终端节点

properties

Map<String,String>

程序系统参数。 最多为2048字符,不能包含><|'`&!\特殊字符,可为空。

响应参数

状态码: 200

表18 响应Body参数

参数

参数类型

描述

cluster_id

String

集群创建成功后系统返回的集群ID值。

请求示例

创建一个版本号为MRS 3.1.0的自定义管控合设集群,并提交一个作业类型为HiveScript的作业。

POST /v2/{project_id}/run-job-flow

{
  "cluster_version" : "MRS 3.1.0",
  "cluster_name" : "mrs_heshe_dm",
  "cluster_type" : "CUSTOM",
  "charge_info" : {
    "charge_mode" : "postPaid"
  },
  "region" : "",
  "availability_zone" : "",
  "vpc_name" : "vpc-37cd",
  "subnet_id" : "1f8c5ca6-1f66-4096-bb00-baf175954f6e",
  "subnet_name" : "subnet",
  "components" : "Hadoop,Spark2x,HBase,Hive,Hue,Loader,Kafka,Storm,Flume,Flink,Oozie,Ranger,Tez",
  "safe_mode" : "KERBEROS",
  "manager_admin_password" : "your password",
  "login_mode" : "PASSWORD",
  "node_root_password" : "your password",
  "mrs_ecs_default_agency" : "MRS_ECS_DEFAULT_AGENCY",
  "template_id" : "mgmt_control_combined_v2",
  "log_collection" : 1,
  "tags" : [ {
    "key" : "tag1",
    "value" : "111"
  }, {
    "key" : "tag2",
    "value" : "222"
  } ],
  "node_groups" : [ {
    "group_name" : "master_node_default_group",
    "node_num" : 3,
    "node_size" : "Sit3.4xlarge.4.linux.bigdata",
    "root_volume" : {
      "type" : "SAS",
      "size" : 480
    },
    "data_volume" : {
      "type" : "SAS",
      "size" : 600
    },
    "data_volume_count" : 1,
    "assigned_roles" : [ "OMSServer:1,2", "SlapdServer:1,2", "KerberosServer:1,2", "KerberosAdmin:1,2", "quorumpeer:1,2,3", "NameNode:2,3", "Zkfc:2,3", "JournalNode:1,2,3", "ResourceManager:2,3", "JobHistoryServer:2,3", "DBServer:1,3", "Hue:1,3", "LoaderServer:1,3", "MetaStore:1,2,3", "WebHCat:1,2,3", "HiveServer:1,2,3", "HMaster:2,3", "MonitorServer:1,2", "Nimbus:1,2", "UI:1,2", "JDBCServer2x:1,2,3", "JobHistory2x:2,3", "SparkResource2x:1,2,3", "oozie:2,3", "LoadBalancer:2,3", "TezUI:1,3", "TimelineServer:3", "RangerAdmin:1,2", "UserSync:2", "TagSync:2", "KerberosClient", "SlapdClient", "meta", "HSConsole:2,3", "FlinkResource:1,2,3", "DataNode:1,2,3", "NodeManager:1,2,3", "IndexServer2x:1,2", "ThriftServer:1,2,3", "RegionServer:1,2,3", "ThriftServer1:1,2,3", "RESTServer:1,2,3", "Broker:1,2,3", "Supervisor:1,2,3", "Logviewer:1,2,3", "Flume:1,2,3", "HSBroker:1,2,3" ]
  }, {
    "group_name" : "node_group_1",
    "node_num" : 3,
    "node_size" : "Sit3.4xlarge.4.linux.bigdata",
    "root_volume" : {
      "type" : "SAS",
      "size" : 480
    },
    "data_volume" : {
      "type" : "SAS",
      "size" : 600
    },
    "data_volume_count" : 1,
    "assigned_roles" : [ "DataNode", "NodeManager", "RegionServer", "Flume:1", "Broker", "Supervisor", "Logviewer", "HBaseIndexer", "KerberosClient", "SlapdClient", "meta", "HSBroker:1,2", "ThriftServer", "ThriftServer1", "RESTServer", "FlinkResource" ]
  }, {
    "group_name" : "node_group_2",
    "node_num" : 1,
    "node_size" : "Sit3.4xlarge.4.linux.bigdata",
    "root_volume" : {
      "type" : "SAS",
      "size" : 480
    },
    "data_volume" : {
      "type" : "SAS",
      "size" : 600
    },
    "data_volume_count" : 1,
    "assigned_roles" : [ "NodeManager", "KerberosClient", "SlapdClient", "meta", "FlinkResource" ]
  } ],
  "log_uri" : "obs://bucketTest/logs",
  "delete_when_no_steps" : true,
  "steps" : [ {
    "job_execution" : {
      "job_name" : "import_file",
      "job_type" : "DistCp",
      "arguments" : [ "obs://test/test.sql", "/user/hive/input" ]
    }
  }, {
    "job_execution" : {
      "job_name" : "hive_test",
      "job_type" : "HiveScript",
      "arguments" : [ "obs://test/hive/sql/HiveScript.sql" ]
    }
  } ]
}

响应示例

状态码: 200

正常响应示例。

{
  "cluster_id" : "da1592c2-bb7e-468d-9ac9-83246e95447a"
}

SDK代码示例

SDK代码示例如下。

创建一个版本号为MRS 3.1.0的自定义管控合设集群,并提交一个作业类型为HiveScript的作业。

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.mrs.v2.region.MrsRegion;
import com.huaweicloud.sdk.mrs.v2.*;
import com.huaweicloud.sdk.mrs.v2.model.*;

import java.util.List;
import java.util.ArrayList;

public class RunJobFlowSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        MrsClient client = MrsClient.newBuilder()
                .withCredential(auth)
                .withRegion(MrsRegion.valueOf("<YOUR REGION>"))
                .build();
        RunJobFlowRequest request = new RunJobFlowRequest();
        RunJobFlowCommand body = new RunJobFlowCommand();
        List<String> listJobExecutionArguments = new ArrayList<>();
        listJobExecutionArguments.add("obs://test/hive/sql/HiveScript.sql");
        JobExecution jobExecutionSteps = new JobExecution();
        jobExecutionSteps.withJobType("HiveScript")
            .withJobName("hive_test")
            .withArguments(listJobExecutionArguments);
        List<String> listJobExecutionArguments1 = new ArrayList<>();
        listJobExecutionArguments1.add("obs://test/test.sql");
        listJobExecutionArguments1.add("/user/hive/input");
        JobExecution jobExecutionSteps1 = new JobExecution();
        jobExecutionSteps1.withJobType("DistCp")
            .withJobName("import_file")
            .withArguments(listJobExecutionArguments1);
        List<StepConfig> listbodySteps = new ArrayList<>();
        listbodySteps.add(
            new StepConfig()
                .withJobExecution(jobExecutionSteps1)
        );
        listbodySteps.add(
            new StepConfig()
                .withJobExecution(jobExecutionSteps)
        );
        List<String> listNodeGroupsAssignedRoles = new ArrayList<>();
        listNodeGroupsAssignedRoles.add("NodeManager");
        listNodeGroupsAssignedRoles.add("KerberosClient");
        listNodeGroupsAssignedRoles.add("SlapdClient");
        listNodeGroupsAssignedRoles.add("meta");
        listNodeGroupsAssignedRoles.add("FlinkResource");
        Volume dataVolumeNodeGroups = new Volume();
        dataVolumeNodeGroups.withType("SAS")
            .withSize(600);
        Volume rootVolumeNodeGroups = new Volume();
        rootVolumeNodeGroups.withType("SAS")
            .withSize(480);
        List<String> listNodeGroupsAssignedRoles1 = new ArrayList<>();
        listNodeGroupsAssignedRoles1.add("DataNode");
        listNodeGroupsAssignedRoles1.add("NodeManager");
        listNodeGroupsAssignedRoles1.add("RegionServer");
        listNodeGroupsAssignedRoles1.add("Flume:1");
        listNodeGroupsAssignedRoles1.add("Broker");
        listNodeGroupsAssignedRoles1.add("Supervisor");
        listNodeGroupsAssignedRoles1.add("Logviewer");
        listNodeGroupsAssignedRoles1.add("HBaseIndexer");
        listNodeGroupsAssignedRoles1.add("KerberosClient");
        listNodeGroupsAssignedRoles1.add("SlapdClient");
        listNodeGroupsAssignedRoles1.add("meta");
        listNodeGroupsAssignedRoles1.add("HSBroker:1,2");
        listNodeGroupsAssignedRoles1.add("ThriftServer");
        listNodeGroupsAssignedRoles1.add("ThriftServer1");
        listNodeGroupsAssignedRoles1.add("RESTServer");
        listNodeGroupsAssignedRoles1.add("FlinkResource");
        Volume dataVolumeNodeGroups1 = new Volume();
        dataVolumeNodeGroups1.withType("SAS")
            .withSize(600);
        Volume rootVolumeNodeGroups1 = new Volume();
        rootVolumeNodeGroups1.withType("SAS")
            .withSize(480);
        List<String> listNodeGroupsAssignedRoles2 = new ArrayList<>();
        listNodeGroupsAssignedRoles2.add("OMSServer:1,2");
        listNodeGroupsAssignedRoles2.add("SlapdServer:1,2");
        listNodeGroupsAssignedRoles2.add("KerberosServer:1,2");
        listNodeGroupsAssignedRoles2.add("KerberosAdmin:1,2");
        listNodeGroupsAssignedRoles2.add("quorumpeer:1,2,3");
        listNodeGroupsAssignedRoles2.add("NameNode:2,3");
        listNodeGroupsAssignedRoles2.add("Zkfc:2,3");
        listNodeGroupsAssignedRoles2.add("JournalNode:1,2,3");
        listNodeGroupsAssignedRoles2.add("ResourceManager:2,3");
        listNodeGroupsAssignedRoles2.add("JobHistoryServer:2,3");
        listNodeGroupsAssignedRoles2.add("DBServer:1,3");
        listNodeGroupsAssignedRoles2.add("Hue:1,3");
        listNodeGroupsAssignedRoles2.add("LoaderServer:1,3");
        listNodeGroupsAssignedRoles2.add("MetaStore:1,2,3");
        listNodeGroupsAssignedRoles2.add("WebHCat:1,2,3");
        listNodeGroupsAssignedRoles2.add("HiveServer:1,2,3");
        listNodeGroupsAssignedRoles2.add("HMaster:2,3");
        listNodeGroupsAssignedRoles2.add("MonitorServer:1,2");
        listNodeGroupsAssignedRoles2.add("Nimbus:1,2");
        listNodeGroupsAssignedRoles2.add("UI:1,2");
        listNodeGroupsAssignedRoles2.add("JDBCServer2x:1,2,3");
        listNodeGroupsAssignedRoles2.add("JobHistory2x:2,3");
        listNodeGroupsAssignedRoles2.add("SparkResource2x:1,2,3");
        listNodeGroupsAssignedRoles2.add("oozie:2,3");
        listNodeGroupsAssignedRoles2.add("LoadBalancer:2,3");
        listNodeGroupsAssignedRoles2.add("TezUI:1,3");
        listNodeGroupsAssignedRoles2.add("TimelineServer:3");
        listNodeGroupsAssignedRoles2.add("RangerAdmin:1,2");
        listNodeGroupsAssignedRoles2.add("UserSync:2");
        listNodeGroupsAssignedRoles2.add("TagSync:2");
        listNodeGroupsAssignedRoles2.add("KerberosClient");
        listNodeGroupsAssignedRoles2.add("SlapdClient");
        listNodeGroupsAssignedRoles2.add("meta");
        listNodeGroupsAssignedRoles2.add("HSConsole:2,3");
        listNodeGroupsAssignedRoles2.add("FlinkResource:1,2,3");
        listNodeGroupsAssignedRoles2.add("DataNode:1,2,3");
        listNodeGroupsAssignedRoles2.add("NodeManager:1,2,3");
        listNodeGroupsAssignedRoles2.add("IndexServer2x:1,2");
        listNodeGroupsAssignedRoles2.add("ThriftServer:1,2,3");
        listNodeGroupsAssignedRoles2.add("RegionServer:1,2,3");
        listNodeGroupsAssignedRoles2.add("ThriftServer1:1,2,3");
        listNodeGroupsAssignedRoles2.add("RESTServer:1,2,3");
        listNodeGroupsAssignedRoles2.add("Broker:1,2,3");
        listNodeGroupsAssignedRoles2.add("Supervisor:1,2,3");
        listNodeGroupsAssignedRoles2.add("Logviewer:1,2,3");
        listNodeGroupsAssignedRoles2.add("Flume:1,2,3");
        listNodeGroupsAssignedRoles2.add("HSBroker:1,2,3");
        Volume dataVolumeNodeGroups2 = new Volume();
        dataVolumeNodeGroups2.withType("SAS")
            .withSize(600);
        Volume rootVolumeNodeGroups2 = new Volume();
        rootVolumeNodeGroups2.withType("SAS")
            .withSize(480);
        List<NodeGroupV2> listbodyNodeGroups = new ArrayList<>();
        listbodyNodeGroups.add(
            new NodeGroupV2()
                .withGroupName("master_node_default_group")
                .withNodeNum(3)
                .withNodeSize("Sit3.4xlarge.4.linux.bigdata")
                .withRootVolume(rootVolumeNodeGroups2)
                .withDataVolume(dataVolumeNodeGroups2)
                .withDataVolumeCount(1)
                .withAssignedRoles(listNodeGroupsAssignedRoles2)
        );
        listbodyNodeGroups.add(
            new NodeGroupV2()
                .withGroupName("node_group_1")
                .withNodeNum(3)
                .withNodeSize("Sit3.4xlarge.4.linux.bigdata")
                .withRootVolume(rootVolumeNodeGroups1)
                .withDataVolume(dataVolumeNodeGroups1)
                .withDataVolumeCount(1)
                .withAssignedRoles(listNodeGroupsAssignedRoles1)
        );
        listbodyNodeGroups.add(
            new NodeGroupV2()
                .withGroupName("node_group_2")
                .withNodeNum(1)
                .withNodeSize("Sit3.4xlarge.4.linux.bigdata")
                .withRootVolume(rootVolumeNodeGroups)
                .withDataVolume(dataVolumeNodeGroups)
                .withDataVolumeCount(1)
                .withAssignedRoles(listNodeGroupsAssignedRoles)
        );
        List<Tag> listbodyTags = new ArrayList<>();
        listbodyTags.add(
            new Tag()
                .withKey("tag1")
                .withValue("111")
        );
        listbodyTags.add(
            new Tag()
                .withKey("tag2")
                .withValue("222")
        );
        ChargeInfo chargeInfobody = new ChargeInfo();
        chargeInfobody.withChargeMode("postPaid");
        body.withSteps(listbodySteps);
        body.withDeleteWhenNoSteps(true);
        body.withLogUri("obs://bucketTest/logs");
        body.withNodeGroups(listbodyNodeGroups);
        body.withLogCollection(RunJobFlowCommand.LogCollectionEnum.NUMBER_1);
        body.withTags(listbodyTags);
        body.withTemplateId("mgmt_control_combined_v2");
        body.withMrsEcsDefaultAgency("MRS_ECS_DEFAULT_AGENCY");
        body.withNodeRootPassword("your password");
        body.withLoginMode("PASSWORD");
        body.withManagerAdminPassword("your password");
        body.withSafeMode("KERBEROS");
        body.withAvailabilityZone("");
        body.withComponents("Hadoop,Spark2x,HBase,Hive,Hue,Loader,Kafka,Storm,Flume,Flink,Oozie,Ranger,Tez");
        body.withSubnetName("subnet");
        body.withSubnetId("1f8c5ca6-1f66-4096-bb00-baf175954f6e");
        body.withVpcName("vpc-37cd");
        body.withRegion("");
        body.withChargeInfo(chargeInfobody);
        body.withClusterType("CUSTOM");
        body.withClusterName("mrs_heshe_dm");
        body.withClusterVersion("MRS 3.1.0");
        request.withBody(body);
        try {
            RunJobFlowResponse response = client.runJobFlow(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

创建一个版本号为MRS 3.1.0的自定义管控合设集群,并提交一个作业类型为HiveScript的作业。

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkmrs.v2.region.mrs_region import MrsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkmrs.v2 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.getenv("CLOUD_SDK_AK")
    sk = os.getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

    client = MrsClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(MrsRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = RunJobFlowRequest()
        listArgumentsJobExecution = [
            "obs://test/hive/sql/HiveScript.sql"
        ]
        jobExecutionSteps = JobExecution(
            job_type="HiveScript",
            job_name="hive_test",
            arguments=listArgumentsJobExecution
        )
        listArgumentsJobExecution1 = [
            "obs://test/test.sql",
            "/user/hive/input"
        ]
        jobExecutionSteps1 = JobExecution(
            job_type="DistCp",
            job_name="import_file",
            arguments=listArgumentsJobExecution1
        )
        listStepsbody = [
            StepConfig(
                job_execution=jobExecutionSteps1
            ),
            StepConfig(
                job_execution=jobExecutionSteps
            )
        ]
        listAssignedRolesNodeGroups = [
            "NodeManager",
            "KerberosClient",
            "SlapdClient",
            "meta",
            "FlinkResource"
        ]
        dataVolumeNodeGroups = Volume(
            type="SAS",
            size=600
        )
        rootVolumeNodeGroups = Volume(
            type="SAS",
            size=480
        )
        listAssignedRolesNodeGroups1 = [
            "DataNode",
            "NodeManager",
            "RegionServer",
            "Flume:1",
            "Broker",
            "Supervisor",
            "Logviewer",
            "HBaseIndexer",
            "KerberosClient",
            "SlapdClient",
            "meta",
            "HSBroker:1,2",
            "ThriftServer",
            "ThriftServer1",
            "RESTServer",
            "FlinkResource"
        ]
        dataVolumeNodeGroups1 = Volume(
            type="SAS",
            size=600
        )
        rootVolumeNodeGroups1 = Volume(
            type="SAS",
            size=480
        )
        listAssignedRolesNodeGroups2 = [
            "OMSServer:1,2",
            "SlapdServer:1,2",
            "KerberosServer:1,2",
            "KerberosAdmin:1,2",
            "quorumpeer:1,2,3",
            "NameNode:2,3",
            "Zkfc:2,3",
            "JournalNode:1,2,3",
            "ResourceManager:2,3",
            "JobHistoryServer:2,3",
            "DBServer:1,3",
            "Hue:1,3",
            "LoaderServer:1,3",
            "MetaStore:1,2,3",
            "WebHCat:1,2,3",
            "HiveServer:1,2,3",
            "HMaster:2,3",
            "MonitorServer:1,2",
            "Nimbus:1,2",
            "UI:1,2",
            "JDBCServer2x:1,2,3",
            "JobHistory2x:2,3",
            "SparkResource2x:1,2,3",
            "oozie:2,3",
            "LoadBalancer:2,3",
            "TezUI:1,3",
            "TimelineServer:3",
            "RangerAdmin:1,2",
            "UserSync:2",
            "TagSync:2",
            "KerberosClient",
            "SlapdClient",
            "meta",
            "HSConsole:2,3",
            "FlinkResource:1,2,3",
            "DataNode:1,2,3",
            "NodeManager:1,2,3",
            "IndexServer2x:1,2",
            "ThriftServer:1,2,3",
            "RegionServer:1,2,3",
            "ThriftServer1:1,2,3",
            "RESTServer:1,2,3",
            "Broker:1,2,3",
            "Supervisor:1,2,3",
            "Logviewer:1,2,3",
            "Flume:1,2,3",
            "HSBroker:1,2,3"
        ]
        dataVolumeNodeGroups2 = Volume(
            type="SAS",
            size=600
        )
        rootVolumeNodeGroups2 = Volume(
            type="SAS",
            size=480
        )
        listNodeGroupsbody = [
            NodeGroupV2(
                group_name="master_node_default_group",
                node_num=3,
                node_size="Sit3.4xlarge.4.linux.bigdata",
                root_volume=rootVolumeNodeGroups2,
                data_volume=dataVolumeNodeGroups2,
                data_volume_count=1,
                assigned_roles=listAssignedRolesNodeGroups2
            ),
            NodeGroupV2(
                group_name="node_group_1",
                node_num=3,
                node_size="Sit3.4xlarge.4.linux.bigdata",
                root_volume=rootVolumeNodeGroups1,
                data_volume=dataVolumeNodeGroups1,
                data_volume_count=1,
                assigned_roles=listAssignedRolesNodeGroups1
            ),
            NodeGroupV2(
                group_name="node_group_2",
                node_num=1,
                node_size="Sit3.4xlarge.4.linux.bigdata",
                root_volume=rootVolumeNodeGroups,
                data_volume=dataVolumeNodeGroups,
                data_volume_count=1,
                assigned_roles=listAssignedRolesNodeGroups
            )
        ]
        listTagsbody = [
            Tag(
                key="tag1",
                value="111"
            ),
            Tag(
                key="tag2",
                value="222"
            )
        ]
        chargeInfobody = ChargeInfo(
            charge_mode="postPaid"
        )
        request.body = RunJobFlowCommand(
            steps=listStepsbody,
            delete_when_no_steps=True,
            log_uri="obs://bucketTest/logs",
            node_groups=listNodeGroupsbody,
            log_collection=1,
            tags=listTagsbody,
            template_id="mgmt_control_combined_v2",
            mrs_ecs_default_agency="MRS_ECS_DEFAULT_AGENCY",
            node_root_password="your password",
            login_mode="PASSWORD",
            manager_admin_password="your password",
            safe_mode="KERBEROS",
            availability_zone="",
            components="Hadoop,Spark2x,HBase,Hive,Hue,Loader,Kafka,Storm,Flume,Flink,Oozie,Ranger,Tez",
            subnet_name="subnet",
            subnet_id="1f8c5ca6-1f66-4096-bb00-baf175954f6e",
            vpc_name="vpc-37cd",
            region="",
            charge_info=chargeInfobody,
            cluster_type="CUSTOM",
            cluster_name="mrs_heshe_dm",
            cluster_version="MRS 3.1.0"
        )
        response = client.run_job_flow(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

创建一个版本号为MRS 3.1.0的自定义管控合设集群,并提交一个作业类型为HiveScript的作业。

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    mrs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v2/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := mrs.NewMrsClient(
        mrs.MrsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.RunJobFlowRequest{}
	var listArgumentsJobExecution = []string{
        "obs://test/hive/sql/HiveScript.sql",
    }
	jobExecutionSteps := &model.JobExecution{
		JobType: "HiveScript",
		JobName: "hive_test",
		Arguments: &listArgumentsJobExecution,
	}
	var listArgumentsJobExecution1 = []string{
        "obs://test/test.sql",
	    "/user/hive/input",
    }
	jobExecutionSteps1 := &model.JobExecution{
		JobType: "DistCp",
		JobName: "import_file",
		Arguments: &listArgumentsJobExecution1,
	}
	var listStepsbody = []model.StepConfig{
        {
            JobExecution: jobExecutionSteps1,
        },
        {
            JobExecution: jobExecutionSteps,
        },
    }
	var listAssignedRolesNodeGroups = []string{
        "NodeManager",
	    "KerberosClient",
	    "SlapdClient",
	    "meta",
	    "FlinkResource",
    }
	dataVolumeNodeGroups := &model.Volume{
		Type: "SAS",
		Size: int32(600),
	}
	rootVolumeNodeGroups := &model.Volume{
		Type: "SAS",
		Size: int32(480),
	}
	var listAssignedRolesNodeGroups1 = []string{
        "DataNode",
	    "NodeManager",
	    "RegionServer",
	    "Flume:1",
	    "Broker",
	    "Supervisor",
	    "Logviewer",
	    "HBaseIndexer",
	    "KerberosClient",
	    "SlapdClient",
	    "meta",
	    "HSBroker:1,2",
	    "ThriftServer",
	    "ThriftServer1",
	    "RESTServer",
	    "FlinkResource",
    }
	dataVolumeNodeGroups1 := &model.Volume{
		Type: "SAS",
		Size: int32(600),
	}
	rootVolumeNodeGroups1 := &model.Volume{
		Type: "SAS",
		Size: int32(480),
	}
	var listAssignedRolesNodeGroups2 = []string{
        "OMSServer:1,2",
	    "SlapdServer:1,2",
	    "KerberosServer:1,2",
	    "KerberosAdmin:1,2",
	    "quorumpeer:1,2,3",
	    "NameNode:2,3",
	    "Zkfc:2,3",
	    "JournalNode:1,2,3",
	    "ResourceManager:2,3",
	    "JobHistoryServer:2,3",
	    "DBServer:1,3",
	    "Hue:1,3",
	    "LoaderServer:1,3",
	    "MetaStore:1,2,3",
	    "WebHCat:1,2,3",
	    "HiveServer:1,2,3",
	    "HMaster:2,3",
	    "MonitorServer:1,2",
	    "Nimbus:1,2",
	    "UI:1,2",
	    "JDBCServer2x:1,2,3",
	    "JobHistory2x:2,3",
	    "SparkResource2x:1,2,3",
	    "oozie:2,3",
	    "LoadBalancer:2,3",
	    "TezUI:1,3",
	    "TimelineServer:3",
	    "RangerAdmin:1,2",
	    "UserSync:2",
	    "TagSync:2",
	    "KerberosClient",
	    "SlapdClient",
	    "meta",
	    "HSConsole:2,3",
	    "FlinkResource:1,2,3",
	    "DataNode:1,2,3",
	    "NodeManager:1,2,3",
	    "IndexServer2x:1,2",
	    "ThriftServer:1,2,3",
	    "RegionServer:1,2,3",
	    "ThriftServer1:1,2,3",
	    "RESTServer:1,2,3",
	    "Broker:1,2,3",
	    "Supervisor:1,2,3",
	    "Logviewer:1,2,3",
	    "Flume:1,2,3",
	    "HSBroker:1,2,3",
    }
	dataVolumeNodeGroups2 := &model.Volume{
		Type: "SAS",
		Size: int32(600),
	}
	rootVolumeNodeGroups2 := &model.Volume{
		Type: "SAS",
		Size: int32(480),
	}
	dataVolumeCountNodeGroups:= int32(1)
	dataVolumeCountNodeGroups1:= int32(1)
	dataVolumeCountNodeGroups2:= int32(1)
	var listNodeGroupsbody = []model.NodeGroupV2{
        {
            GroupName: "master_node_default_group",
            NodeNum: int32(3),
            NodeSize: "Sit3.4xlarge.4.linux.bigdata",
            RootVolume: rootVolumeNodeGroups2,
            DataVolume: dataVolumeNodeGroups2,
            DataVolumeCount: &dataVolumeCountNodeGroups,
            AssignedRoles: &listAssignedRolesNodeGroups2,
        },
        {
            GroupName: "node_group_1",
            NodeNum: int32(3),
            NodeSize: "Sit3.4xlarge.4.linux.bigdata",
            RootVolume: rootVolumeNodeGroups1,
            DataVolume: dataVolumeNodeGroups1,
            DataVolumeCount: &dataVolumeCountNodeGroups1,
            AssignedRoles: &listAssignedRolesNodeGroups1,
        },
        {
            GroupName: "node_group_2",
            NodeNum: int32(1),
            NodeSize: "Sit3.4xlarge.4.linux.bigdata",
            RootVolume: rootVolumeNodeGroups,
            DataVolume: dataVolumeNodeGroups,
            DataVolumeCount: &dataVolumeCountNodeGroups2,
            AssignedRoles: &listAssignedRolesNodeGroups,
        },
    }
	var listTagsbody = []model.Tag{
        {
            Key: "tag1",
            Value: "111",
        },
        {
            Key: "tag2",
            Value: "222",
        },
    }
	chargeInfobody := &model.ChargeInfo{
		ChargeMode: "postPaid",
	}
	deleteWhenNoStepsRunJobFlowCommand:= true
	logUriRunJobFlowCommand:= "obs://bucketTest/logs"
	logCollectionRunJobFlowCommand:= model.GetRunJobFlowCommandLogCollectionEnum().E_1
	templateIdRunJobFlowCommand:= "mgmt_control_combined_v2"
	mrsEcsDefaultAgencyRunJobFlowCommand:= "MRS_ECS_DEFAULT_AGENCY"
	nodeRootPasswordRunJobFlowCommand:= "your password"
	subnetIdRunJobFlowCommand:= "1f8c5ca6-1f66-4096-bb00-baf175954f6e"
	request.Body = &model.RunJobFlowCommand{
		Steps: listStepsbody,
		DeleteWhenNoSteps: &deleteWhenNoStepsRunJobFlowCommand,
		LogUri: &logUriRunJobFlowCommand,
		NodeGroups: listNodeGroupsbody,
		LogCollection: &logCollectionRunJobFlowCommand,
		Tags: &listTagsbody,
		TemplateId: &templateIdRunJobFlowCommand,
		MrsEcsDefaultAgency: &mrsEcsDefaultAgencyRunJobFlowCommand,
		NodeRootPassword: &nodeRootPasswordRunJobFlowCommand,
		LoginMode: "PASSWORD",
		ManagerAdminPassword: "your password",
		SafeMode: "KERBEROS",
		AvailabilityZone: "",
		Components: "Hadoop,Spark2x,HBase,Hive,Hue,Loader,Kafka,Storm,Flume,Flink,Oozie,Ranger,Tez",
		SubnetName: "subnet",
		SubnetId: &subnetIdRunJobFlowCommand,
		VpcName: "vpc-37cd",
		Region: "",
		ChargeInfo: chargeInfobody,
		ClusterType: "CUSTOM",
		ClusterName: "mrs_heshe_dm",
		ClusterVersion: "MRS 3.1.0",
	}
	response, err := client.RunJobFlow(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

正常响应示例。

错误码

请参见错误码

分享:

    相关文档

    相关产品