# App 上游

####创建上游

# 简介

创建上游

# Uri
POST /admin-api/applications/http/{app-id}/clusters
# 请求示例
# Shell
curl 'http://{admin-site}/admin-api/applications/http/1/clusters' \
	-H 'Content-Type: application/json;charset=UTF-8' \
  --data-raw '{
    "nodes":[
        {
            "netns":"",   // 网络
            "port":80,
            "weight":1,   // 转发权重
            "status":1,   // 1: 开启  2: 关闭
            "name":"",
            "use_proxy_host":false,   // 使用代理主机/请求主机作为上游地址。
            "ip":"127.0.0.1",   // 支持ip和domain
            "domain":null       // 支持ip和domain
        }
    ],
    "name":"openresty",     // 上游名字
    "ssl":false,            // 是否支持ssl协议
    "disable_ssl_verify":false,     // 是否检查上游的ssl证书, ssl为true时生效
    "checker":{
        "use_tcp":false,     // 使用 TCP 检查模式
        "http_req_uri":"/status",       // HTTP 请求 URI
        "http_req_host":"www.openresty.com",  HTTP 请求主机
        "user_agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0", // 用户代理
        "http_ver":"1.0",    // HTTP 版本
        "interval":3,        // 间隔
        "interval_unit":"sec",   // 间隔时间单位, 只支持 sec
        "timeout":1,
        "timeout_unit":"sec",   // 超时时间单位, 只支持 sec
        "fall":3,             // 不健康阈值
        "rise":2,             // 健康阈值
        "valid_statuses":[    // 有效状态
            200,
            302
        ],
        "concurrency":5,      // 最大并发数
        "report_interval":3,      // 上报间隔
        "report_interval_unit":"min"  // 上报间隔单位, 支持 sec, min, hour
    },
    "enable_checker":true    // 开启健康检查
}'
# 响应示例
Status: 200 OK
{
    "data":{
        "id":4
    },
    "status":0
}

# 修改上游信息

# 简介

修改上游信息

# Uri
POST /admin-api/applications/http/{app-id}/clusters/{cluster-id}
# 请求示例
# Shell
curl 'http://{admin-site}/admin-api/applications/http/1/clusters/4' \
  -X 'PUT' \
  -H 'Content-Type: application/json;charset=UTF-8' \
  --data-raw '{
    "ssl":false,
    "creator":1,
    "_created_unix":1615449424.7811,
    "_modified_unix":1615450307.0989,
    "nodes":[
        {
            "_modified_unix":1615450307.0989,
            "id":4,
            "_created_unix":1615449424.7811,
            "netns":"test",
            "status":1,
            "use_proxy_host":false,
            "name":"localhost.localdomain",
            "port":80,
            "ip":"127.0.0.1",
            "weight":1
        }
    ],
    "id":4,
    "disable_ssl_verify":false,
    "name":"openresty",
    "health":{
        "success":0,
        "fails":0,
        "total":0,
        "on":0,
        "off":0
    },
    "checker":{
        "fall":3,
        "http_req_host":"www.openresty.com",
        "http_ver":"1.0",
        "http_req_uri":"/status",
        "interval":3,
        "user_agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0",
        "interval_unit":"sec",
        "valid_statuses":[
            200,
            302
        ],
        "report_interval":3,
        "timeout":2,
        "report_interval_unit":"min",
        "use_tcp":false,
        "rise":2,
        "concurrency":5,
        "timeout_unit":"sec"
    },
    "enable_checker":true
}'
# 响应示例
Status: 200 OK
{
    "data":{
        "id":4
    },
    "status":0
}

# 获取上游列表

# 简介

获取上游列表

# Uri
GET /admin-api/applications/http/{app-id}/clusters
# Uri参数
  • page

    type: integer

    required: no

    description: 第几页 (default 1)

  • page_size

    type: integer

    required: no

    description: 每页大小 (default 20)

  • detail

    type: integer

    is_necessary: no

    description: 传任意值显示详细信息,不传显示简略信息

# 请求示例
# Shell
curl 'https://{admin-site}/admin-api/applications/http/3/clusters?page=2&page_size=2&detail=1'
# 响应示例
Status: 200 OK
{
    "data":{
        "meta":{
            "count":1
        },
        "data":[
            {
                "ssl":false,
                "creator":1,
                "_created_unix":1615449424.7811,
                "_modified_unix":1615450307.0989,
                "nodes":[
                    {
                        "_modified_unix":1615450307.0989,
                        "id":4,
                        "_created_unix":1615449424.7811,
                        "netns":"test",
                        "status":1,
                        "use_proxy_host":false,
                        "name":"localhost.localdomain",
                        "port":80,
                        "ip":"127.0.0.1",
                        "weight":1
                    }
                ],
                "id":4,
                "checker":{
                    "fall":3,
                    "http_req_host":"openresty.com",
                    "http_ver":"1.0",
                    "http_req_uri":"/status",
                    "interval":3,
                    "user_agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0",
                    "interval_unit":"sec",
                    "valid_statuses":[
                        200,
                        302
                    ],
                    "report_interval":3,
                    "timeout":1,
                    "report_interval_unit":"min",
                    "use_tcp":false,
                    "rise":2,
                    "concurrency":5
                },
                "disable_ssl_verify":false,
                "name":"openresty",
                "enable_checker":true
            }
        ]
    },
    "status":0
}

# 删除上游

# 简介

删除上游

# Uri
DELETE /admin-api/applications/http/{app-id}/clusters/{cluster-id}
# 请求示例
# Shell
curl 'http://{admin-site}/admin-api/applications/http/1/clusters/4' -X 'DELETE'

# 响应示例
Status: 200 OK
{
    "status":0
}