Help Center/ MapReduce Service/ API Reference/ API V1.1/ Auto Scaling APIs/ Configuring an Auto Scaling Rule
Updated on 2022-11-18 GMT+08:00

Configuring an Auto Scaling Rule

Function

This API is used to configure auto scaling rules.

The API used for cluster creation and job execution can also be used to create an auto scaling rule.

Constraints

None

Debugging

You can debug this API through automatic authentication in API Explorer. API Explorer can automatically generate sample SDK code and provide the sample SDK code debugging.

URI

  • Format

    POST /v1.1/{project_id}/autoscaling-policy/{cluster_id}

  • Parameter description
    Table 1 URI parameters

    Parameter

    Mandatory

    Type

    Description

    project_id

    Yes

    String

    Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

    cluster_id

    Yes

    String

    Cluster ID For details about how to obtain the cluster ID, see Obtaining the MRS Cluster Information.

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

node_group

Yes

String

Type of the node to which an auto scaling rule applies. Currently, only Task nodes support auto scaling rules, that is, the request value is task_node_default_group.

auto_scaling_policy

Yes

AutoScalingPolicy object

The auto scaling policy. Table 3 describes these parameters.

Table 3 AutoScalingPolicy object parameters

Parameter

Mandatory

Type

Description

auto_scaling_enable

Yes

Boolean

Whether to enable the auto scaling rule.

min_capacity

Yes

Integer

Minimum number of nodes left in the node group.

Value range: 0 to 500

max_capacity

Yes

Integer

Maximum number of nodes in the node group.

Value range: 0 to 500

resources_plans

No

List

Resource plan list. For details, see Table 4. If this parameter is left blank, the resource plan is disabled.

When auto scaling is enabled, either a resource plan or an auto scaling rule must be configured.

exec_scripts

No

List

List of custom scaling automation scripts. For details, see Table 5. If this parameter is left blank, a hook script is disabled.

rules

No

List

List of auto scaling rules. For details, see Table 6.

When auto scaling is enabled, either a resource plan or an auto scaling rule must be configured.

Table 4 resources_plan parameters

Parameter

Mandatory

Type

Description

period_type

Yes

String

Cycle type of a resource plan. Currently, only the following cycle type is supported:

daily

start_time

Yes

String

Start time of a resource plan. The value is in the format of hour:minute, indicating that the time ranges from 0:00 to 23:59.

end_time

Yes

String

End time of a resource plan. The value is in the same format as that of start_time. The interval between end_time and start_time must be greater than or equal to 30 minutes.

min_capacity

Yes

Integer

Minimum number of the preserved nodes in a node group in a resource plan.

Value range: 0 to 500

max_capacity

Yes

Integer

Maximum number of the preserved nodes in a node group in a resource plan.

Value range: 0 to 500

Table 5 exec_script parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Name of a custom automation script. It must be unique in a same cluster.

The value can contain only digits, letters, spaces, hyphens (-), and underscores (_) and must not start with a space.

The value can contain 1 to 64 characters.

uri

Yes

String

Path of a custom automation script. Set this parameter to an OBS bucket path or a local VM path.

  • OBS bucket path: Enter a script path manually. for example, s3a://XXX/scale.sh.
  • Local VM path: Enter a script path. The script path must start with a slash (/) and end with .sh.

parameters

No

String

Parameters of a custom automation script.

  • Multiple parameters are separated by space.
  • The following predefined system parameters can be transferred:
    • ${mrs_scale_node_num}: Number of the nodes to be added or removed
    • ${mrs_scale_type}: Scaling type. The value can be scale_out or scale_in.
    • ${mrs_scale_node_hostnames}: Host names of the nodes to be added or removed
    • ${mrs_scale_node_ips}: IP addresses of the nodes to be added or removed
    • ${mrs_scale_rule_name}: Name of the rule that triggers auto scaling
  • Other user-defined parameters are used in the same way as those of common shell scripts. Parameters are separated by space.

nodes

Yes

Array of strings

Type of a node where the custom automation script is executed. The node type can be Master, Core, or Task.

active_master

No

Boolean

Whether the custom automation script runs only on the active Master node.

The default value is false, indicating that the custom automation script can run on all Master nodes.

action_stage

Yes

String

Time when a script is executed.

The following four options are supported:

  • before_scale_out: before scale-out
  • before_scale_in: before scale-in
  • after_scale_out: after scale-out
  • after_scale_in: after scale-in

fail_action

Yes

String

Whether to continue to execute subsequent scripts and create a cluster after the custom automation script fails to be executed.

  • continue: Continue to execute subsequent scripts.
  • errorout: Stop the action.
    NOTE:
    • You are advised to set this parameter to continue in the commissioning phase so that the cluster can continue to be installed and started no matter whether the custom automation script is executed successfully.
    • The scale-in operation cannot be undone. Therefore, fail_action must be set to continue for the scripts that are executed after scale-in.
Table 6 rules parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Name of an auto scaling rule.

A cluster name can contain only 1 to 64 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed.

Rule names must be unique in a node group.

description

No

String

Description about an auto scaling rule.

It contains a maximum of 1,024 characters.

adjustment_type

Yes

String

Auto scaling rule adjustment type. Possible values:

  • scale_out: cluster scale-out
  • scale_in: cluster scale-in

cool_down_minutes

Yes

Integer

Cluster cooling time after an auto scaling rule is triggered, when no auto scaling operation is performed. The unit is minute.

Value range: 0 to 10,080. One week is equal to 10,080 minutes.

scaling_adjustment

Yes

Integer

Number of nodes that can be adjusted once.

Value range: 1 to 100

trigger

Yes

Trigger object

Condition for triggering a rule. For details, see Table 7.

Table 7 trigger parameters

Parameter

Mandatory

Type

Description

metric_name

Yes

String

Metric name.

This triggering condition makes a judgment according to the value of the metric.

A metric name contains a maximum of 64 characters.

metric_value

Yes

String

Metric threshold to trigger a rule

The parameter value can be an integer or number with two decimal places only.

comparison_operator

No

String

Metric judgment logic operator. Possible values:

  • LT: less than
  • GT: greater than
  • LTOE: less than or equal to
  • GTOE: greater than or equal to

evaluation_periods

Yes

Integer

Number of consecutive five-minute periods, during which a metric threshold is reached

Value range: 1 to 288

Response Parameters

Table 8 Response parameter

Parameter

Type

Description

result

String

Operation result

  • succeeded: The operation is successful.

Example

  • Example request
    {
      "node_group":"task_node_default_group",
      "auto_scaling_policy": {
          "auto_scaling_enable": true,
          "min_capacity": "1",
          "max_capacity": "3",
          "resources_plans": [{
             "period_type": "daily",
             "start_time": "9:50",
             "end_time": "10:20",
             "min_capacity": "2",
             "max_capacity": "3"
             },{
             "period_type": "daily",
             "start_time": "10:20",
             "end_time": "12:30",
             "min_capacity": "0",
             "max_capacity": "2"
           }],
           "exec_scripts": [{
             "name": "before_scale_out",
             "uri": "s3a://XXX/zeppelin_install.sh",
             "parameters": "",
             "nodes": [
               "master",
               "core",
               "task"
             ],
             "active_master": "true",
             "action_stage": "before_scale_out",
             "fail_action": "continue"
             },{
             "name": "after_scale_out",
             "uri": "s3a://XXX/storm_rebalance.sh",
             "parameters": "",
             "nodes": [
               "master",
               "core",
               "task"
             ],
             "active_master": "true",
             "action_stage": "after_scale_out",
             "fail_action": "continue"
          }],
          "rules": [{
             "name": "default-expand-1",
             "adjustment_type": "scale_out",
             "cool_down_minutes": 5,
             "scaling_adjustment": 1,
             "trigger": {
                "metric_name": "YARNMemoryAvailablePercentage",
                "metric_value": "25",
                "comparison_operator": "LT",
                "evaluation_periods": 10
                }
              },
             {
              "name": "default-shrink-1",
              "adjustment_type": "scale_in",
              "cool_down_minutes": 5,
              "scaling_adjustment": 1,
              "trigger": {
                 "metric_name": "YARNMemoryAvailablePercentage",
                 "metric_value": "70",
                 "comparison_operator": "GT",
                 "evaluation_periods": 10
                  }
               }]
         }
    }

    A new auto scaling rule will overwrite the auto scaling rule saved in the original database. If you want to modify the original rule, query the original rule first, modify the rule, and submit a modification task. For details, see Querying Cluster Details.

  • Example response
    {       "result": "succeeded"  }

Status Codes

Table 9 describes the status code.

Table 9 Status code

Status Code

Description

200

The cluster has been created.

See Status Codes.

Error Codes

See Error Codes.