scenario:
  id: 15b3c1e3-f620-4278-92c9-272f132a1155
  context:
    auth:
      type: digest
    base_path: /v1beta2
    host: null
  description: ng_cluster_recycle_bin_restore_alicloud
  name: ng_cluster_recycle_bin_restore_alicloud
steps:
  - operation_id: TidbService_CreateTidb
    request_type: http
    request: |-
      {
        "method": "POST",
        "path": "/tidbs",
        "headers": {},
        "query_params": {},
        "body": {
          "displayName": "ng-recycle-bin-restore-cluster",
          "regionId": "{regionId}",
          "minRcu": "5000",
          "maxRcu": "6000",
          "servicePlan": "Premium",
          "cloudProvider": "{cloud_provider}"
        },
        "body_params": {
          "regionId": "region_id",
          "cloud_provider": "cloud_provider"
        },
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    save: |-
      {
        "placeholder": [
          {
            "key": "cluster_1",
            "eval": "body.tidbId"
          }
        ]
      }
    description: ""
    max_retries: 0
    delay_after: 0
    name: ""
    continue_on_unexpected: false
    stage: ""
    meta: "{}"
    generation_id: ""
    order: 0
  - operation_id: PrivateEndpointConnectionService_GetPrivateLinkService
    request_type: http
    request: |-
      {
        "method": "GET",
        "path": "/tidbs/{tidbId}/privateLinkService",
        "headers": {},
        "query_params": {},
        "body": {},
        "path_params": {
          "tidbId": "cluster_1"
        },
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == 'ACTIVE'"
      }
    save: |-
      {
        "placeholder": [
          {
            "key": "private_link_service_1",
            "eval": "body.serviceName"
          }
        ]
      }
    description: ''
    max_retries: 120
    delay_after: 30
    name: ''
    continue_on_unexpected: false
    stage: ''
    meta: '{}'
    generation_id: ''
    order: 0.5
  - operation_id: TidbService_GetTidb
    request_type: http
    request: |-
      {
        "method": "GET",
        "path": "/tidbs/{tidbId}",
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_1"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == 'ACTIVE'"
      }
    save: null
    description: ""
    max_retries: 120
    delay_after: 30
    name: ""
    continue_on_unexpected: false
    stage: ""
    meta: "{}"
    generation_id: ""
    order: 1
  - operation_id: TidbService_ResetRootPassword
    request_type: http
    request: |-
      {
        "method": "POST",
        "path": "/tidbs/{tidbId}:resetRootPassword",
        "headers": {},
        "query_params": {},
        "body": {
          "rootPassword": "pi31415926"
        },
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_1"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    save: null
    description: ''
    max_retries: 5
    delay_after: 60
    name: ''
    continue_on_unexpected: false
    stage: ''
    meta: '{}'
    generation_id: ''
    order: 1.5
  - operation_id: PublicConnectionSettingService_UpdatePublicConnectionSetting
    request_type: http
    request: |-
      {
        "method": "PATCH",
        "path": "/tidbs/{tidbId}/publicConnectionSetting",
        "headers": {},
        "query_params": {},
        "body": {
          "enabled": true,
          "ipAccessList": [
            {
              "cidrNotation": "0.0.0.0/0",
              "description": "Allow all IPs"
            }
          ]
        },
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_1"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    save: null
    description: ""
    max_retries: 0
    delay_after: 0
    name: ""
    continue_on_unexpected: false
    stage: ""
    meta: "{}"
    generation_id: ""
    order: 2
  - operation_id: ClusterService_GetCluster
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 3
    case_type: supplimental_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "GET",
        "path": "/tidbs/{tidbId}",
        "path_params": {
          "tidbId": "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: 40
    delay_after: 10
    step_type: defined
    name: force_wait_dns
    save: null
    continue_on_unexpected: true
    stage: prepare
    meta: "{}"
  - operation_id: TidbService_GetTidb
    request_type: http
    request: |-
      {
        "method": "GET",
        "path": "/tidbs/{tidbId}",
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_1"
        }
      }
    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 != \"\""
      }
    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"}
        ]
      }
    description: ""
    max_retries: 120
    delay_after: 30
    name: ""
    continue_on_unexpected: false
    stage: ""
    meta: "{}"
    generation_id: ""
    order: 3.5
  - operation_id: Mysqlsh_connection
    case_type: typical_positive
    request_type: cmd_mysqlsh
    request: |-
      {
        "name": "mysqlsh",
        "args": [
          "--sql",
          "mysql://root:pi31415926@{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: 4
  - operation_id: Mysqlsh_connection
    case_type: typical_positive
    request_type: cmd_mysqlsh
    request: |-
      {
        "name": "mysqlsh",
        "args": [
          "--sql",
          "mysql://root:pi31415926@{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: 5
  - operation_id: TidbService_ListTidbBackups
    request_type: http
    request: |-
      {
        "method": "GET",
        "path": "/tidbs/{tidbId}/backups",
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_1"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.backups[0].id != ''"
      }
    save: null
    description: ""
    max_retries: 70
    delay_after: 60
    name: ""
    continue_on_unexpected: false
    stage: ""
    meta: "{}"
    generation_id: ""
    order: 6
  - operation_id: TidbService_DeleteTidb
    request_type: http
    request: |-
      {
        "method": "DELETE",
        "path": "/tidbs/{tidbId}",
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_1"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    save: null
    description: ''
    max_retries: 0
    delay_after: 0
    name: ''
    continue_on_unexpected: false
    stage: ''
    meta: '{}'
    generation_id: ''
    order: 7
  - operation_id: BackupService_ListDeletedTidbs
    request_type: http
    request: |-
      {
        "method": "GET",
        "path": "/backups:listDeletedTidbs?orgId={orgId}&tidbIds[]={tidbId}",
        "path_params": {
          "tidbId": "cluster_1",
          "orgId": "org_id"
        },
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.totalSize > 0"
      }
    save: null
    description: ''
    max_retries: 120
    delay_after: 30
    name: ''
    continue_on_unexpected: false
    stage: ''
    meta: '{}'
    generation_id: ''
    order: 8
  - operation_id: BackupService_ListBackups
    request_type: http
    request: |-
      {
        "method": "GET",
        "path": "/backups?orgId={orgId}&tidbIds[]={tidbId}",
        "path_params": {
          "tidbId": "cluster_1",
          "orgId": "org_id"
        },
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.totalSize > 0"
      }
    save: |-
      {
        "placeholder": [
          {
            "key": "backup_1",
            "eval": "body.backups[0].id"
          }
        ]
      }
    description: ''
    max_retries: 120
    delay_after: 30
    name: ''
    continue_on_unexpected: false
    stage: ''
    meta: '{}'
    generation_id: ''
    order: 9
  - operation_id: TidbService_RestoreTidb
    request_type: http
    request: |-
      {
        "method": "POST",
        "path": "/tidbs:restore",
        "headers": {},
        "query_params": {},
        "body": {
          "tidb": {
            "displayName": "ng-alicloud-recycle-restore-cluster",
            "regionId": "{regionId}",
            "minRcu": "5000",
            "maxRcu": "5500",
            "servicePlan": "Premium"
          },
          "sourceTidbId": "{tidbId}",
          "restoreMode": "SNAPSHOT",
          "backupId": "{backupId}"
        },
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "body_params": {
          "regionId": "region_id",
          "tidbId": "cluster_1",
          "backupId": "backup_1"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    save: |-
      {
        "placeholder": [
          {
            "key": "cluster_2",
            "eval": "body.tidb.tidbId"
          }
        ]
      }
    description: ""
    max_retries: 0
    delay_after: 0
    name: ""
    continue_on_unexpected: false
    stage: ""
    meta: "{}"
    generation_id: ""
    order: 10
  - operation_id: TidbService_RestoreStatus
    request_type: http
    request: |-
      {
        "method": "GET",
        "path": "/tidbs/{tidbId}:restoreStatus",
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_2"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == 'SUCCEEDED'"
      }
    save: null
    description: ""
    max_retries: 120
    delay_after: 30
    name: ""
    continue_on_unexpected: false
    stage: ""
    meta: "{}"
    generation_id: ""
    order: 11
  - operation_id: TidbService_GetTidb
    request_type: http
    request: |-
      {
        "method": "GET",
        "path": "/tidbs/{tidbId}",
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_2"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == 'ACTIVE' && body.minRcu == '5000' && body.maxRcu == '5500'"
      }
    save: null
    description: ""
    max_retries: 120
    delay_after: 30
    name: ""
    continue_on_unexpected: false
    stage: ""
    meta: "{}"
    generation_id: ""
    order: 12
  - operation_id: PublicConnectionSettingService_UpdatePublicConnectionSetting
    request_type: http
    request: |-
      {
        "method": "PATCH",
        "path": "/tidbs/{tidbId}/publicConnectionSetting",
        "headers": {},
        "query_params": {},
        "body": {
          "enabled": true,
          "ipAccessList": [
            {
              "cidrNotation": "0.0.0.0/0",
              "description": "Allow all IPs"
            }
          ]
        },
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_2"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    save: null
    description: ""
    max_retries: 0
    delay_after: 0
    name: ""
    continue_on_unexpected: false
    stage: ""
    meta: "{}"
    generation_id: ""
    order: 13
  - operation_id: ClusterService_GetCluster
    generation_id: 09198df8-3eef-4d82-a5a4-31eb9b0db7de
    order: 14
    case_type: supplimental_positive
    request_type: http
    request: |-
      {
        "auth": {
          "auth_type": "digest",
          "content": {"private_key": "placeholder","public_key": "placeholder"}
        },
        "method": "GET",
        "path": "/tidbs/{tidbId}",
        "path_params": {
          "tidbId": "cluster_2"
        },
        "query_params": {},
        "headers": {},
        "body": {}
      }
    expect: |-
      {
        "status_code": 200,
        "cel": "body.state == \"ABC\""
      }
    description: Poll the cluster state until it becomes ACTIVE.
    max_retries: 40
    delay_after: 10
    step_type: defined
    name: force_wait_dns
    save: null
    continue_on_unexpected: true
    stage: prepare
    meta: "{}"
  - operation_id: TidbService_GetTidb
    request_type: http
    request: |-
      {
        "method": "GET",
        "path": "/tidbs/{tidbId}",
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_2"
        }
      }
    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 != \"\""
      }
    save: |-
      {
        "placeholder": [
          {"key": "public_endpoint_2", "eval": "body.endpoints.filter(e, e.connectionType == 'PUBLIC')[0].host"},
          {"key": "port_2", "eval": "body.endpoints.filter(e, e.connectionType == 'PUBLIC')[0].port"}
        ]
      }
    description: ""
    max_retries: 120
    delay_after: 30
    name: ""
    continue_on_unexpected: false
    stage: ""
    meta: "{}"
    generation_id: ""
    order: 15
  - operation_id: Mysqlsh_connection
    case_type: typical_positive
    request_type: cmd_mysqlsh
    request: |-
      {
        "name": "mysqlsh",
        "args": [
          "--sql",
          "mysql://root:pi31415926@{public_endpoint}:{port}/test",
          "--result-format=json",
          "-e",
          "SELECT value FROM tt WHERE name = 'test1';",
          "--quiet-start=2"
        ],
        "args_params": {
          "public_endpoint": "public_endpoint_2",
          "port": "port_2"
        }
      }
    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: 16
  - operation_id: TidbService_DeleteTidbBackup
    request_type: http
    request: |-
      {
        "method": "DELETE",
        "path": "/backups/{backupId}",
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_1",
          "backupId": "backup_1"
        }
      }
    expect: |-
      {
        "status_code": 400,
        "cel": ""
      }
    save: null
    description: ""
    max_retries: 0
    delay_after: 0
    name: ""
    continue_on_unexpected: false
    stage: ""
    meta: "{}"
    generation_id: ""
    order: 17
  - operation_id: TidbService_DeleteRestoreTidb
    request_type: http
    request: |-
      {
        "method": "DELETE",
        "path": "/tidbs/{tidbId}",
        "headers": {},
        "query_params": {},
        "body": {},
        "auth": {
          "auth_type": "digest",
          "content": {
            "private_key": "placeholder",
            "public_key": "placeholder"
          }
        },
        "path_params": {
          "tidbId": "cluster_2"
        }
      }
    expect: |-
      {
        "status_code": 200,
        "cel": ""
      }
    save: null
    description: ""
    max_retries: 0
    delay_after: 0
    name: ""
    continue_on_unexpected: false
    stage: ""
    meta: "{}"
    generation_id: ""
    order: 18
