scenario:
  id: abcf522f5754a26096985d8962f63abc
  context:
    auth:
      type: digest
    base_path: /v1beta1
    host: null
  description: "Auto-generated scenario for scale up tidb and tikv Standard"
  name: scale_up_tidb_tikv_standard
steps:
  - case_id: c37f522f5754a26096985d8962f63afe
    operation_id: ClusterService_CreateCluster
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "POST",
        "path": "/clusters",
        "path_params": {},
        "query_params": {},
        "headers": {},
        "body": {
          "displayName": "sce-scaleup",
          "labels": {
            "tidb.cloud/project": "{projectId}"
          },
          "port": 4000,
          "regionId": "{regionId}",
          "rootPassword": "31415926",
          "tidbNodeSetting": {
            "nodeSpecKey": "4C16G-V2",
            "tidbNodeGroups": [
              {
                "nodeCount": 1
              }
            ]
          },
          "tikvNodeSetting": {
            "nodeCount": 3,
            "nodeSpecKey": "4C16G-V2",
            "storageSizeGi": 200,
            "storageType": "Standard"
          }
        },
        "body_params": {
          "regionId": "region_id",
          "projectId": "project_id"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == \"CREATING\""
      }
    description: Create a 1 TiDB 3 TiKV dedicated cluster to prepare for scaling TiDB nodes.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: create_cluster
    save: |-
      {
        "placeholder": [
          { "key": "cluster_1", "eval": "body.clusterId" }
        ]
      }
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 1
  - case_id: c37f522f5754a26096985d8962f63aab
    operation_id: ClusterService_GetCluster
    case_type: supplimental_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "GET",
        "path": "/clusters/{clusterId}",
        "path_params": {
          "clusterId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == \"ACTIVE\" && body.tikvNodeSetting.nodeSpecKey == '4C16G-V2' && body.tikvNodeSetting.storageType == \"Standard\""
      }
    description: Poll the cluster state until it becomes ACTIVE to proceed with the update operation.
    max_retries: 60
    delay_after: 60
    step_type: defined
    name: wait_for_cluster_active
    save: |-
      {
        "placeholder": [
          { "key": "tidbnodegroup_1", "eval": "body.tidbNodeSetting.tidbNodeGroups[0].tidbNodeGroupId" }
        ]
      }
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 2
  - case_id: wait_for_tidb_nodegroup_active
    operation_id: TidbNodeGroupService_GetTidbNodeGroup
    case_type: http
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "GET",
        "path": "/clusters/{clusterId}/tidbNodeGroups/{tidbNodeGroupId}",
        "path_params": {
          "clusterId": "cluster_1",
          "tidbNodeGroupId": "tidbnodegroup_1"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == \"ACTIVE\" && size(body.endpoints.filter(e, e.connectionType == 'PUBLIC')) > 0 && body.endpoints.filter(e, e.connectionType == 'PUBLIC')[0].host != \"\""
      }
    description: Poll the TiDB Node Group until it becomes ACTIVE.
    max_retries: 120
    delay_after: 30
    step_type: generated
    name: wait_for_tidb_node_group_active
    save: |-
      {
        "placeholder": [
          {"key": "public_endpoint", "eval": "body.endpoints.filter(e, e.connectionType == 'PUBLIC')[0].host"},
          {"key": "port", "eval": "body.endpoints.filter(e, e.connectionType == 'PUBLIC')[0].port"}
        ]
      }
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 2.1
  - case_id: set_public_endpoint
    operation_id: TidbNodeGroupService_UpdatePublicEndpointSetting
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "PATCH",
        "path": "/clusters/{clusterId}/tidbNodeGroups/{tidbNodeGroupId}/publicEndpointSetting",
        "path_params": {
          "clusterId": "cluster_1",
          "tidbNodeGroupId": "tidbnodegroup_1"
        },
        "query_params": {},
        "headers": {},
        "body": {
          "enabled": true,
          "ipAccessList": [
            {
              "cidrNotation": "0.0.0.0/0",
              "description": "all"
            }
          ]
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.enabled == true"
      }
    description: Update the cluster to set the public endpoint.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: set_public_endpoint
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 2.2
  - case_id: force_wait_dns
    operation_id: ClusterService_GetCluster
    case_type: supplimental_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "GET",
        "path": "/clusters/{clusterId}",
        "path_params": {
          "clusterId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == \"ABC\""
      }
    description: Poll the cluster state until it becomes ACTIVE.
    max_retries: 30
    delay_after: 10
    step_type: defined
    name: force_wait_dns
    save: null
    continue_on_unexpected: true
    stage: prepare
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 2.3
  - case_id: connect_to_db_to_add_table
    operation_id: Mysqlsh_connection
    case_type: typical_positive
    request_type: cmd_mysqlsh
    request: |-
      {
        "name": "mysqlsh",
        "args": [
          "--sql",
          "mysql://root:31415926@{public_endpoint}:{port}/test",
          "--result-format=json",
          "-e",
          "CREATE TABLE IF NOT EXISTS tt (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), value INT); INSERT INTO tt (name, value) VALUES ('test1', 100), ('test2', 200);",
          "--quiet-start=2"
        ],
        "args_params": {
          "public_endpoint": "public_endpoint",
          "port": "port"
        }
      }
    expect: |-
      {
        "exit_code": 0,
        "cel": ""
      }
    description: Check the connection status of the cluster.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: check_password
    continue_on_unexpected: false
    save: null
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 2.4
  - case_id: connect_to_db_to_check_data
    operation_id: Mysqlsh_connection
    case_type: typical_positive
    request_type: cmd_mysqlsh
    request: |-
      {
        "name": "mysqlsh",
        "args": [
          "--sql",
          "mysql://root:31415926@{public_endpoint}:{port}/test",
          "--result-format=json",
          "-e",
          "SELECT value FROM tt WHERE name = 'test1';",
          "--quiet-start=2"
        ],
        "args_params": {
          "public_endpoint": "public_endpoint",
          "port": "port"
        }
      }
    expect: |-
      {
        "exit_code": 0,
        "cel": "output.value == 100"
      }
    description: Check the connection status of the cluster.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: check_password
    continue_on_unexpected: false
    save: null
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 2.5
  - case_id: ClusterService_UpdateCluster_scale_up_tikv_tidb
    operation_id: ClusterService_UpdateCluster
    case_type: user_defined
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "PATCH",
        "path": "/clusters/{clusterId}",
        "path_params": {
          "clusterId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {
          "tidbNodeSetting": {
            "nodeSpecKey": "8C32G-V2"
          },
          "tikvNodeSetting": {
            "nodeSpecKey": "8C32G-V2"
          }
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == 'MODIFYING'"
      }
    description: Scale up TiDB andTiKV spec from 4C16G-V2 to 8C32G-V2.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: Scale up TiDB and TiKV Nodes
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 3
  - case_id: wait_for_cluster_active
    operation_id: ClusterService_GetCluster
    case_type: supplimental_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "GET",
        "path": "/clusters/{clusterId}",
        "path_params": {
          "clusterId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == \"ACTIVE\" && body.tikvNodeSetting.nodeSpecKey == '8C32G-V2'"
      }
    description: Poll the cluster state until it becomes ACTIVE to proceed with the update operation.
    max_retries: 30
    delay_after: 60
    step_type: defined
    name: wait_for_cluster_active
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 4
  - case_id: connect_to_db_to_check_data
    operation_id: Mysqlsh_connection
    case_type: typical_positive
    request_type: cmd_mysqlsh
    request: |-
      {
        "name": "mysqlsh",
        "args": [
          "--sql",
          "mysql://root:31415926@{public_endpoint}:{port}/test",
          "--result-format=json",
          "-e",
          "SELECT value FROM tt WHERE name = 'test2';",
          "--quiet-start=2"
        ],
        "args_params": {
          "public_endpoint": "public_endpoint",
          "port": "port"
        }
      }
    expect: |-
      {
        "exit_code": 0,
        "cel": "output.value == 200"
      }
    description: Check the connection status of the cluster.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: check_password
    continue_on_unexpected: false
    save: null
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 4.5
  - case_id: ClusterService_UpdateCluster_scale_down_tikv_tidb
    operation_id: ClusterService_UpdateCluster
    case_type: user_defined
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "PATCH",
        "path": "/clusters/{clusterId}",
        "path_params": {
          "clusterId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {
          "tidbNodeSetting": {
            "nodeSpecKey": "4C16G-V2"
          },
          "tikvNodeSetting": {
            "nodeSpecKey": "4C16G-V2"
          }
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    description: Scale down TiKV spec from 8C32G-V2 to 4C16G-V2.
    max_retries: 0
    delay_after: 0
    step_type: defined
    name: Scale down TiKV Nodes
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: '{}'
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 5
  - case_id: cleanup_cluster_1
    operation_id: ClusterService_DeleteCluster
    case_type: typical_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "DELETE",
        "path": "/clusters/{clusterId}",
        "path_params": {
          "clusterId": "cluster_1"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    description: Cleanup step for TiDB Cloud cluster with no parent dependency.
    max_retries: 0
    delay_after: 0
    step_type: generated
    name: Delete TiDB Cloud Cluster
    save: null
    continue_on_unexpected: false
    stage: execute
    meta: "{}"
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 6
