Skip to content
This repository has been archived by the owner on Dec 15, 2024. It is now read-only.

api usage

bobliu edited this page Jun 9, 2017 · 6 revisions

#1 GET - http://localhost:8589/v1/groups/{groupid}/engines

获取集群中某个 Group 下所有 Docker 节点的信息和状态。

Engines: 为数组结构,包含 Group 下所有已在 Humpback 站点分组中注册的 Docker 服务节点
ID: 节点唯一标识,可在 Docker 节点本地使用 docker info | grep ID 查看
Name: 节点宿主机名称,由节点自动获取注册
IP: 节点宿主机IP地址,由节点自动获取注册 APIAddr: 节点运行的 Humpback-Agent 容器服务 API 地址
Cpus: 节点 CPU 核数
Memory: 节点物理内存大小,单位:MB
Labels: 节点 Docker Daemon 部分标识,可在 Docker 启动时或在配置中添加 --label=xxx 来设置
StateText: 节点状态描述,状态分为如下几种:

  • Pending 节点正在加入集群状态
  • Unhealthy 节点保留状态,后期扩展
  • Healthy 节点在集群中,正常状态
  • Disconnected 节点离线状态
/*Response*/
HTTP 200 OK
{
  "Code": 0,
  "Error": "request successed",
  "Contnet": "group engines response",
  "ResponseID": "b4116080-b954-4105-939e-86395399c40d",
  "Data": {
    "GroupId": "4d8c8b31-eba2-4882-bd61-6579d051a518",
    "Engines": [
      {
        "ID": "6PBX:LVJJ:L3QG:DHWD:BWOU:XHDN:CRGB:CNVW:LKKB:S3JI:EDVQ:YSZL",
        "Name": "BOBLIU1.DOCKER",
        "IP": "192.168.2.80",
        "APIAddr": "192.168.2.80:8500",
        "Cpus": 4,
        "Memory": 990,
        "Labels": {
          "kernelversion": "3.10.5-12.1.x86_64",
          "location": "wh7",
          "operatingsystem": "<unknown>",
          "os": "centos6",
          "storagedirver": "aufs"
        },
        "StateText": "Healthy"
      },
      {
        "ID": "PHTU:CCAI:XFGP:G6BZ:WOPE:74HH:P6QK:I3GF:UQCL:SCWY:WP6U:67FN",
        "Name": "BOBLIU2.DOCKER",
        "IP": "192.168.2.81",
        "APIAddr": "192.168.2.81:8500",
        "Cpus": 4,
        "Memory": 990,
        "Labels": {
          "kernelversion": "3.10.5-12.1.x86_64",
          "location": "wh7",
          "operatingsystem": "<unknown>",
          "os": "centos6",
          "storagedirver": "aufs"
        },
        "StateText": "Healthy"
      }
    ]
  }
}

#2 GET - http://localhost:8589/v1/groups/engines/192.168.2.81

根据一个 Docker 节点 IP 来获取集群中节点的信息和状态。
这个响应体中没有 GroupID 属性,意味着没有在 Humpback 站点分组中注册的节点只要加入集群,都可以被查询到。

/*Response*/
HTTP 200 OK
{
  "Code": 0,
  "Error": "request successed",
  "Contnet": "engine response",
  "ResponseID": "4f1f09f0-d095-43f0-ab0e-cdb25bacb332",
  "Data": {
    "Engine": {
      "ID": "PHTU:CCAI:XFGP:G6BZ:WOPE:74HH:P6QK:I3GF:UQCL:SCWY:WP6U:67FN",
      "Name": "BOBLIU2.DOCKER",
      "IP": "192.168.2.81",
      "APIAddr": "192.168.2.81:8500",
      "Cpus": 4,
      "Memory": 990,
      "Labels": {
        "kernelversion": "3.10.5-12.1.x86_64",
        "location": "wh7",
        "operatingsystem": "<unknown>",
        "os": "centos6",
        "storagedirver": "aufs"
      },
      "StateText": "Healthy"
    }
  }
}

#3 GET - http://localhost:8589/v1/groups/{groupid}/collections

获取集群中某个 Group 下所有被调度的容器信息,获取的数据中只包含通过集群模式创建的容器信息。

关于 Metas属性,每次通过集群模式创建容器,系统会根据实例数创建一批容器并分散调度到不同的 Docker 节点上,该批次容器都统一由一个MetaData 结构来描述,并生成一个唯一的 MetaID,以后涉及到该 Meta 的操作都会处理这些容器。

Metas: 一个数组结构,Group 中会创建多批次容器,因此一个 Group 会存在多个 MetaData
MetaId: MetaData 的唯一编号,代表某次创建的容器集合
Instances: 容器实例数,正常情况下与 Containers 数量保持一致
WebHooks: Hook API 回调路径
Config: 初次创建 MetaData 时的配置信息,以后设计容器调度、迁移或修改实例数,系统都会以该 Config 信息来构造容器
Containers: 包含MetaData中所有容器实例信息和隶属节点情况,通过 IPHostName 可以查到具体分配到了某个节点上

关于容器名称规则是按组编号前8位+Meta.ConfigName+索引方式组合,避免容器名称冲突。

/*Response*/
HTTP 200 OK 
{
  "Code": 0,
  "Error": "request successed",
  "Contnet": "group containers response",
  "ResponseID": "017a3149-16d9-421c-8528-9d2379ec6556",
  "Data": {
    "GroupId": "4d8c8b31-eba2-4882-bd61-6579d051a518",
    "Metas": [
      {
        "MetaId": "b2778cd3-9a8a-4ffe-9fd1-e5f14fd176c1",
        "Instances": 2,
        "WebHooks": [
          {
            "Url": "http://127.0.0.1:8871/api/hook/redis",
            "SecretToken": ""
          }
        ],
        "Config": {
          "Id": "",
          "Image": "redis:3.2.9",
          "Command": "",
          "Name": "redis",
          "Ports": [
            {
              "PrivatePort": 6379,
              "PublicPort": 0,
              "Type": "tcp",
              "Ip": ""
            }
          ],
          "Volumes": null,
          "Dns": null,
          "Env": [
            "env=dev"
          ],
          "HostName": "testhostname",
          "NetworkMode": "bridge",
          "RestartPolicy": "always",
          "RestartRetryCount": 2,
          "Extrahosts": [
            "hostname:IP"
          ],
          "Links": null,
          "Ulimits": null
        },
        "Containers": [
          {
            "IP": "192.168.2.82",
            "HostName": "BOBLIU3.DOCKER",
            "Container": {
              "Id": "0c95c527ca1d5378ced1e9c8c6479d2cb1fa224d164b736444ee8d36e5890de0",
              "Image": "redis:3.2.9",
              "Command": "",
              "Name": "CLUSTER-4d8c8b31-redis-1",
              "Ports": [
                {
                  "PrivatePort": 6379,
                  "PublicPort": 32684,
                  "Type": "tcp",
                  "Ip": "0.0.0.0"
                }
              ],
              "Volumes": [],
              "Dns": null,
              "Env": [
                "env=dev",
                "HUMPBACK_CLUSTER_GROUPID=4d8c8b31-eba2-4882-bd61-6579d051a518",
                "HUMPBACK_CLUSTER_METAID=b2778cd3-9a8a-4ffe-9fd1-e5f14fd176c1",
                "HUMPBACK_CLUSTER_CONTAINER_INDEX=1",
                "HUMPBACK_CLUSTER_CONTAINER_ORIGINALNAME=CLUSTER-4d8c8b31-redis-1",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
              ],
              "HostName": "testhostname",
              "NetworkMode": "bridge",
              "Status": {
                "Status": "",
                "Running": true,
                "Paused": false,
                "Restarting": false,
                "OOMKilled": false,
                "Dead": false,
                "Pid": 8921,
                "ExitCode": 0,
                "Error": "",
                "StartedAt": "2017-04-10T14:38:02.179547213Z",
                "FinishedAt": "0001-01-01T00:00:00Z"
              },
              "RestartPolicy": "always",
              "RestartRetryCount": 2,
              "Extrahosts": [
                "hostname:IP"
              ],
              "Links": null,
              "Ulimits": null
            }
          },
          {
            "IP": "192.168.2.80",
            "HostName": "BOBLIU1.DOCKER",
            "Container": {
              "Id": "f493995421ffd924d18a697070c4aa8bfe148e1a0ebe9ed7665110be3f7a53b3",
              "Image": "redis:3.2.9",
              "Command": "",
              "Name": "CLUSTER-4d8c8b31-redis-2",
              "Ports": [
                {
                  "PrivatePort": 5000,
                  "PublicPort": 32679,
                  "Type": "tcp",
                  "Ip": "0.0.0.0"
                }
              ],
              "Volumes": [],
              "Dns": null,
              "Env": [
                "env=dev",
                "HUMPBACK_CLUSTER_GROUPID=4d8c8b31-eba2-4882-bd61-6579d051a518",
                "HUMPBACK_CLUSTER_METAID=b2778cd3-9a8a-4ffe-9fd1-e5f14fd176c1",
                "HUMPBACK_CLUSTER_CONTAINER_INDEX=2",
                "HUMPBACK_CLUSTER_CONTAINER_ORIGINALNAME=CLUSTER-4d8c8b31-redis-2",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
              ],
              "HostName": "testhostname",
              "NetworkMode": "bridge",
              "Status": {
                "Status": "",
                "Running": true,
                "Paused": false,
                "Restarting": false,
                "OOMKilled": false,
                "Dead": false,
                "Pid": 8677,
                "ExitCode": 0,
                "Error": "",
                "StartedAt": "2017-04-10T14:38:02.534519018Z",
                "FinishedAt": "0001-01-01T00:00:00Z"
              },
              "RestartPolicy": "always",
              "RestartRetryCount": 2,
              "Extrahosts": [
                "hostname:IP"
              ],
              "Links": null,
              "Ulimits": null
            }
          }
        ]
      }
    ]
  }
}

#4 GET - http://localhost:8589/v1/groups/collections/{metaid}

获取集群中单个 MetaData 信息,在加载某个MetaData 详细页时可调用该接口

/*response*/
HTTP 200 OK
{
  "Code": 0,
  "Error": "request successed",
  "Contnet": "group containers response",
  "ResponseID": "2c43219e-d8b6-452f-b32c-96314bcbf09a",
  "Data": {
    "Meta": {
      "MetaId": "b2778cd3-9a8a-4ffe-9fd1-e5f14fd176c1",
      "Instances": 2,
      "WebHooks": [
        {
          "Url": "http://127.0.0.1:8871/api/hook/redis",
          "SecretToken": ""
        }
      ],
      "Config": {
        "Id": "",
        "Image": "redis:3.2.9",
        "Command": "",
        "Name": "redis",
        "Ports": [
          {
            "PrivatePort": 6379,
            "PublicPort": 0,
            "Type": "tcp",
            "Ip": ""
          }
        ],
        "Volumes": null,
        "Dns": null,
        "Env": [
          "env=dev"
        ],
        "HostName": "testhostname",
        "NetworkMode": "bridge",
        "RestartPolicy": "always",
        "RestartRetryCount": 2,
        "Extrahosts": [
          "hostname:IP"
        ],
        "Links": null,
        "Ulimits": null
      },
      "Containers": [
        {
          "IP": "192.168.2.82",
          "HostName": "BOBLIU3.DOCKER",
          "Container": {
            "Id": "0c95c527ca1d5378ced1e9c8c6479d2cb1fa224d164b736444ee8d36e5890de0",
            "Image": "redis:3.2.9",
            "Command": "",
            "Name": "CLUSTER-4d8c8b31-redis-1",
            "Ports": [
              {
                "PrivatePort": 6379,
                "PublicPort": 32684,
                "Type": "tcp",
                "Ip": "0.0.0.0"
              }
            ],
            "Volumes": [],
            "Dns": null,
            "Env": [
              "env=dev",
              "HUMPBACK_CLUSTER_GROUPID=4d8c8b31-eba2-4882-bd61-6579d051a518",
              "HUMPBACK_CLUSTER_METAID=b2778cd3-9a8a-4ffe-9fd1-e5f14fd176c1",
              "HUMPBACK_CLUSTER_CONTAINER_INDEX=1",
              "HUMPBACK_CLUSTER_CONTAINER_ORIGINALNAME=CLUSTER-4d8c8b31-redis-1",
              "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "HostName": "testhostname",
            "NetworkMode": "bridge",
            "Status": {
              "Status": "",
              "Running": true,
              "Paused": false,
              "Restarting": false,
              "OOMKilled": false,
              "Dead": false,
              "Pid": 8921,
              "ExitCode": 0,
              "Error": "",
              "StartedAt": "2017-04-10T14:38:02.179547213Z",
              "FinishedAt": "0001-01-01T00:00:00Z"
            },
            "RestartPolicy": "always",
            "RestartRetryCount": 2,
            "Extrahosts": [
              "hostname:IP"
            ],
            "Links": null,
            "Ulimits": null
          }
        },
        {
          "IP": "192.168.2.80",
          "HostName": "BOBLIU1.DOCKER",
          "Container": {
            "Id": "f493995421ffd924d18a697070c4aa8bfe148e1a0ebe9ed7665110be3f7a53b3",
            "Image": "redis:3.2.9",
            "Command": "",
            "Name": "CLUSTER-4d8c8b31-redis-2",
            "Ports": [
              {
                "PrivatePort": 5000,
                "PublicPort": 32679,
                "Type": "tcp",
                "Ip": "0.0.0.0"
              }
            ],
            "Volumes": [],
            "Dns": null,
            "Env": [
              "env=dev",
              "HUMPBACK_CLUSTER_GROUPID=4d8c8b31-eba2-4882-bd61-6579d051a518",
              "HUMPBACK_CLUSTER_METAID=b2778cd3-9a8a-4ffe-9fd1-e5f14fd176c1",
              "HUMPBACK_CLUSTER_CONTAINER_INDEX=2",
              "HUMPBACK_CLUSTER_CONTAINER_ORIGINALNAME=CLUSTER-4d8c8b31-redis-2",
              "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "HostName": "testhostname",
            "NetworkMode": "bridge",
            "Status": {
              "Status": "",
              "Running": true,
              "Paused": false,
              "Restarting": false,
              "OOMKilled": false,
              "Dead": false,
              "Pid": 8677,
              "ExitCode": 0,
              "Error": "",
              "StartedAt": "2017-04-10T14:38:02.534519018Z",
              "FinishedAt": "0001-01-01T00:00:00Z"
            },
            "RestartPolicy": "always",
            "RestartRetryCount": 2,
            "Extrahosts": [
              "hostname:IP"
            ],
            "Links": null,
            "Ulimits": null
          }
        }
      ]
    }
  }
}

#5 GET - http://localhost:8589/v1/groups/collections/{metaid}/base

获取集群中单个 MetaData 的基础配置信息,不包括容器信息和分配的节点信息

/*response*/
HTTP 200 OK
{
  "Code": 0,
  "Error": "request successed",
  "Contnet": "group containers meta response",
  "ResponseID": "bfa76604-1a69-4fa3-8afa-b236f6c9b777",
  "Data": {
    "MetaBase": {
      "GroupId": "4d8c8b31-eba2-4882-bd61-6579d051a518",
      "MetaId": "b2778cd3-9a8a-4ffe-9fd1-e5f14fd176c1",
      "Instances": 2,
      "WebHooks": [
        {
          "Url": "http://127.0.0.1:8871/api/hook/redis",
          "SecretToken": ""
        }
      ],
      "ImageTag": "3.2.9",
      "Id": "",
      "Image": "redis:3.2.9",
      "Command": "",
      "Name": "redis",
      "Ports": [
        {
          "PrivatePort": 6379,
          "PublicPort": 0,
          "Type": "tcp",
          "Ip": ""
        }
      ],
      "Volumes": null,
      "Dns": null,
      "Env": [
        "env=dev"
      ],
      "HostName": "testhostname",
      "NetworkMode": "bridge",
      "RestartPolicy": "always",
      "RestartRetryCount": 2,
      "Extrahosts": [
        "hostname:IP"
      ],
      "Links": null,
      "Ulimits": null
    }
  }
}

#6 POST - http://localhost:8589/v1/groups/collections

为集群中某个 Group 创建容器并产生一个新的 MetaData, 创建成功后, MetaData 中的所有容器由集群实施调度管理。 但该接口不一定会根据 Instances 数量创建出所有容器,比如当出现宿主机端口被占用等情况时, 就只返回创建成功的部分容器信息,剩下失败的容器由集群定期恢复构建。

GroupId: 创建的目标分组编号
Instances: 容器实例数
WebHooks: Hook API 回调路径
Config: 创建容器的基本配置信息

/*request*/
{
  "GroupId": "4d8c8b31-eba2-4882-bd61-6579d051a518",
  "Instances": 2,
  "WebHooks": [
    "Url": "http://127.0.0.1:8871/api/hook/redis",
    "SecretToken": ""
  ],
  "Config": {
    "Name": "redis",
    "Command": "",
    "Image": "redis:3.2.9",
    "Ports": [
      {
        "PrivatePort": 6379,
        "PublicPort": 0,
        "Type": "tcp"
      }
    ],
    "Env": [
      "env=dev"
    ],
    "HostName": "testhostname",
    "NetworkMode": "bridge",
    "RestartPolicy": "always",
    "RestartRetryCount": 2,
    "Extrahosts": [
      "hostname:IP"
    ],
    "CPUShares": 0,
    "Memory": 0
  }
}

在创建完成后的响应体中,包括了新构建 MetaData 的编号:MetaID,凡以后涉及对该批容器的操作接口调用,都需要提供这个编号。

GroupId: 创建容器的组编号
MetaId: MetaData 编号
Created: 创建返回描述串,若全部成功: "created all", 部分成功: "created partial"
Containers: 所有容器实例信息和隶属节点情况,通过 IPHostName 可以查到具体分配到了某个节点上

/*response*/
HTTP 200 OK
{
  "Code": 0,
  "Error": "request successed",
  "Contnet": "create containers response",
  "ResponseID": "5f7ddbf0-b244-4855-9f68-a39b55fa9355",
  "Data": {
    "GroupId": "4d8c8b31-eba2-4882-bd61-6579d051a518",
    "MetaId": "0b330699-7bc6-4016-a282-9cb704b32440",
    "Created": "created all",
    "Containers": [
      {
        "IP": "192.168.2.80",
        "HostName": "BOBLIU1.DOCKER",
        "Id": "718acae02aa25405f30d2419fef972263c1d7b55e329665c0ab5dc8ba5ccd81e",
        "Image": "redis:3.2.9",
        "Command": "",
        "Name": "CLUSTER-4d8c8b31-redis-1",
        "Ports": [
          {
            "PrivatePort": 6379,
            "PublicPort": 32067,
            "Type": "tcp",
            "Ip": "0.0.0.0"
          }
        ],
        "Volumes": [],
        "Dns": null,
        "Env": [
          "env=dev",
          "HUMPBACK_CLUSTER_GROUPID=4d8c8b31-eba2-4882-bd61-6579d051a518",
          "HUMPBACK_CLUSTER_METAID=0b330699-7bc6-4016-a282-9cb704b32440",
          "HUMPBACK_CLUSTER_CONTAINER_INDEX=1",
          "HUMPBACK_CLUSTER_CONTAINER_ORIGINALNAME=CLUSTER-4d8c8b31-redis-1",
          "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
        ],
        "NetworkMode": "bridge",
        "Status": {
          "Status": "running",
          "Running": true,
          "Paused": false,
          "Restarting": false,
          "OOMKilled": false,
          "Dead": false,
          "Pid": 4386,
          "ExitCode": 0,
          "Error": "",
          "StartedAt": "2017-05-03T05:03:11.292436467Z",
          "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "RestartPolicy": "always",
        "RestartRetryCount": 2,
        "Extrahosts": [
          "hostname:IP"
        ],
        "Links": null,
        "Ulimits": null
      },
      {
        "IP": "192.168.2.81",
        "HostName": "BOBLIU2.DOCKER",
        "Id": "21adaa829620a13573b4a0526f95a177af528d7f1b5cd016a774e3e9e5d82d44",
        "Image": "redis:3.2.9",
        "Command": "",
        "Name": "CLUSTER-4d8c8b31-redis-2",
        "Ports": [
          {
            "PrivatePort": 6379,
            "PublicPort": 32189,
            "Type": "tcp",
            "Ip": "0.0.0.0"
          }
        ],
        "Volumes": [],
        "Dns": null,
        "Env": [
          "env=dev",
          "HUMPBACK_CLUSTER_GROUPID=4d8c8b31-eba2-4882-bd61-6579d051a518",
          "HUMPBACK_CLUSTER_METAID=0b330699-7bc6-4016-a282-9cb704b32440",
          "HUMPBACK_CLUSTER_CONTAINER_INDEX=2",
          "HUMPBACK_CLUSTER_CONTAINER_ORIGINALNAME=CLUSTER-4d8c8b31-redis-2",
          "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
        ],
        "NetworkMode": "bridge",
        "Status": {
          "Status": "running",
          "Running": true,
          "Paused": false,
          "Restarting": false,
          "OOMKilled": false,
          "Dead": false,
          "Pid": 3628,
          "ExitCode": 0,
          "Error": "",
          "StartedAt": "2017-05-03T05:03:11.988971582Z",
          "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "RestartPolicy": "always",
        "RestartRetryCount": 2,
        "Extrahosts": [
          "hostname:IP"
        ],
        "Links": null,
        "Ulimits": null
      }
    ]
  }
}

当该组中所有 Docker 节点都不在线时(也可能 Humpback-Agent关闭离线),会导致系统返回一个 ErrClusterNoEngineAvailable 错误,这表明当前创建容器时集群中无可用节点可分配,导致创建失败。

/*response*/
HTTP 500 ERROR
{
  "Code": -1002,
  "Error": "request failure error",
  "Contnet": "cluster no docker-engine available",
  "ResponseID": "559cdbe8-d0c6-4377-846a-3d3e90ffb1e2",
  "Data": null
}

若在创建时请求体中的 Config.Name 属性已在该组中的其它 MetaData 中存在相同,此时会导致系统返回一个冲突 ErrClusterCreateContainerNameConflict 错误, 表明创建冲突失败;但是不同组中可以出现相同名称。

/*response*/
HTTP 500 ERROR
{
  "Code": -1002,
  "Error": "request failure error",
  "Contnet": "cluster create containers name conflict, this cluster already exists",
  "ResponseID": "9600a9fd-7299-405a-ad75-5ee897df54f5",
  "Data": null
}  

#7 PUT - http://localhost:8589/v1/groups/collections

修改某组中一个 MetaData 的值,对实例数或 WebHook 进行调整。
实例数增加,系统会按实例差值创建新容器并调度到相对容器数最少的节点上,尽量保持分散。
实例数减少,系统会选择容器相对较多的节点,回收多余的容器。
实例数不变,不作任何处理,只覆盖修改 WebHooks 信息。
注:实例数不能修改为0,必须至少保持一个实例在集群中。

MetaId: 修改的 MetaData 编号
Instances: 新调整的容器实例数
WebHooks: Hook API 回调路径

/*request*/
{
  "MetaId":"0b330699-7bc6-4016-a282-9cb704b32440",
  "Instances":1, #改为1个实例
  "WebHooks":[   #WebHook被置空后,不能接收该 `MetaData` 的报警事件信息
  ]
}

在修改后的响应体中,Containers 数组的数量会根据新实例数变化,正常情况下一般保持一致。

GroupId: 创建容器的组编号
MetaId: MetaData 编号
Created: 创建返回描述串,若全部成功: "created all", 部分成功: "created partial"
Containers: 所有容器实例信息和隶属节点情况,通过 IPHostName 可以查到具体分配到了某个节点上

/*response*/
HTTP 200 OK
{
  "Code": 0,
  "Error": "request successed",
  "Contnet": "update containers response",
  "ResponseID": "a26113c5-9834-48bc-ad93-54e1bfffd3b8",
  "Data": {
    "MetaId": "0b330699-7bc6-4016-a282-9cb704b32440",
    "Updated": "updated all",
    "Containers": [
      {
        "IP": "192.168.2.80",
        "HostName": "BOBLIU1.DOCKER",
        "Id": "718acae02aa25405f30d2419fef972263c1d7b55e329665c0ab5dc8ba5ccd81e",
        "Image": "redis:3.2.9",
        "Command": "",
        "Name": "CLUSTER-4d8c8b31-redis-1",
        "Ports": [
          {
            "PrivatePort": 6379,
            "PublicPort": 32067,
            "Type": "tcp",
            "Ip": "0.0.0.0"
          }
        ],
        "Volumes": [],
        "Dns": null,
        "Env": [
          "env=dev",
          "HUMPBACK_CLUSTER_GROUPID=4d8c8b31-eba2-4882-bd61-6579d051a518",
          "HUMPBACK_CLUSTER_METAID=0b330699-7bc6-4016-a282-9cb704b32440",
          "HUMPBACK_CLUSTER_CONTAINER_INDEX=1",
          "HUMPBACK_CLUSTER_CONTAINER_ORIGINALNAME=CLUSTER-4d8c8b31-redis-1",
          "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
        ],
        "NetworkMode": "bridge",
        "Status": {
          "Status": "running",
          "Running": true,
          "Paused": false,
          "Restarting": false,
          "OOMKilled": false,
          "Dead": false,
          "Pid": 4386,
          "ExitCode": 0,
          "Error": "",
          "StartedAt": "2017-05-03T05:03:11.292436467Z",
          "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "RestartPolicy": "always",
        "RestartRetryCount": 2,
        "Extrahosts": [
          "hostname:IP"
        ],
        "Links": null,
        "Ulimits": null
      }
    ]
  }
}

#8 PUT - http://localhost:8589/v1/groups/collections/upgrade

对一个 MetaData 中所有容器的镜像版本升级,也可通过该接口回滚镜像版本。
若在升级过程中出现部分容器升级失败,则系统会将所有容器镜像版本全部回滚,包括已升级成功的容器。

MetaId: 修改的 MetaData 编号
ImageTag: 升级镜像版本号

/*request*/
{
  "MetaId": "0b330699-7bc6-4016-a282-9cb704b32440",
  "ImageTag": "3.3"
}

升级成功后,所有容器编号都发生了变化,这表明容器已经全部删除重建了,同时所有容器的镜像版本已经与 ImageTag 保持一致。

/*response*/
HTTP 200 OK
{
  "Code": 0,
  "Error": "request successed",
  "Contnet": "upgrade containers response",
  "ResponseID": "ff58a5b5-c17e-4ecb-8438-869510faea5d",
  "Data": {
    "MetaId": "0b330699-7bc6-4016-a282-9cb704b32440",
    "Upgrade": "upgrade containers",
    "Containers": [
      {
        "IP": "192.168.2.80",
        "HostName": "BOBLIU1.DOCKER",
        "Id": "8a04a8fac246e612ff274b2045320608ec4f05b2e316802912b77c07bcbe6320",
        "Image": "redis:3.3",
        "Command": "",
        "Name": "CLUSTER-4d8c8b31-redis-1",
        "Ports": [
          {
            "PrivatePort": 6379,
            "PublicPort": 30187,
            "Type": "tcp",
            "Ip": "0.0.0.0"
          }
        ],
        "Volumes": [],
        "Dns": null,
        "Env": [
          "env=dev",
          "HUMPBACK_CLUSTER_GROUPID=4d8c8b31-eba2-4882-bd61-6579d051a518",
          "HUMPBACK_CLUSTER_METAID=0b330699-7bc6-4016-a282-9cb704b32440",
          "HUMPBACK_CLUSTER_CONTAINER_INDEX=1",
          "HUMPBACK_CLUSTER_CONTAINER_ORIGINALNAME=CLUSTER-4d8c8b31-redis-1",
          "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
        ],
        "NetworkMode": "bridge",
        "Status": {
          "Status": "running",
          "Running": true,
          "Paused": false,
          "Restarting": false,
          "OOMKilled": false,
          "Dead": false,
          "Pid": 33728,
          "ExitCode": 0,
          "Error": "",
          "StartedAt": "2017-06-09T07:39:15.617308308Z",
          "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "RestartPolicy": "always",
        "RestartRetryCount": 2,
        "Extrahosts": [
          "hostname:IP"
        ],
        "Links": null,
        "Ulimits": null
      },
      {
        "IP": "192.168.2.81",
        "HostName": "BOBLIU2.DOCKER",
        "Id": "a15a16a4a7fc9633c6d5b98da962045c4745ecbaca98162d7db40b80e6d45b25",
        "Image": "redis:3.3",
        "Command": "",
        "Name": "CLUSTER-4d8c8b31-redis-2",
        "Ports": [
          {
            "PrivatePort": 6379,
            "PublicPort": 31008,
            "Type": "tcp",
            "Ip": "0.0.0.0"
          }
        ],
        "Volumes": [],
        "Dns": null,
        "Env": [
          "env=dev",
          "HUMPBACK_CLUSTER_GROUPID=4d8c8b31-eba2-4882-bd61-6579d051a518",
          "HUMPBACK_CLUSTER_METAID=0b330699-7bc6-4016-a282-9cb704b32440",
          "HUMPBACK_CLUSTER_CONTAINER_INDEX=2",
          "HUMPBACK_CLUSTER_CONTAINER_ORIGINALNAME=CLUSTER-4d8c8b31-redis-2",
          "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
        ],
        "NetworkMode": "bridge",
        "Status": {
          "Status": "running",
          "Running": true,
          "Paused": false,
          "Restarting": false,
          "OOMKilled": false,
          "Dead": false,
          "Pid": 49961,
          "ExitCode": 0,
          "Error": "",
          "StartedAt": "2017-06-09T07:39:16.412607883Z",
          "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "RestartPolicy": "always",
        "RestartRetryCount": 2,
        "Extrahosts": [
          "hostname:IP"
        ],
        "Links": null,
        "Ulimits": null
      }
    ]
  }
}

#9 PUT - http://localhost:8589/v1/groups/collections/action

对一个 MetaData 中的所有容器进行操作。

/*request*/
{
  "MetaId":"0b330699-7bc6-4016-a282-9cb704b32440",
  "Action":"stop"
}

支持的 Action 命令如下:

  • start: 启动容器
  • stop: 停止容器
  • restart: 重启容器

响应体中会分别反应出该 MetaData 所有容器接受命令的处理结果并以 Result 属性区分,若有容器停止失败,会在 Result 中显示详细异常信息。

/*response*/
HTTP 200 OK
{
  "Code": 0,
  "Error": "request successed",
  "Contnet": "operate containers response",
  "ResponseID": "45513aed-46ad-49a0-8940-65a3ef54b436",
  "Data": {
    "MetaId": "0b330699-7bc6-4016-a282-9cb704b32440",
    "Action": "stop",
    "Containers": [
      {
        "IP": "192.168.2.81",
        "HostName": "BOBLIU2.DOCKER",
        "ContainerId": "8a04a8fac246e612ff274b2045320608ec4f05b2e316802912b77c07bcbe6320",
        "Result": "stop successed."
      },
      {
        "IP": "192.168.2.81",
        "HostName": "BOBLIU2.DOCKER",
        "ContainerId": "a15a16a4a7fc9633c6d5b98da962045c4745ecbaca98162d7db40b80e6d45b25",
        "Result": "stop successed."
      }
    ]
  }
}

#10 DELETE - http://localhost:8589/v1/groups/collections/{metaid}

从集群中删除一个 MetaData 信息,一但从集群删除,这个 MetaData 中的所有容器不可恢复。

/*response*/
HTTP 200 OK
{
  "Code": 0,
  "Error": "request successed",
  "Contnet": "remove containers response",
  "ResponseID": "ce46e339-230e-45a3-946f-6b85164fc7a1",
  "Data": {
    "MetaId": "0b330699-7bc6-4016-a282-9cb704b32440",
    "Containers": [
      {
        "IP": "192.168.2.81",
        "HostName": "BOBLIU2.DOCKER",
        "ContainerId": "8a04a8fac246e612ff274b2045320608ec4f05b2e316802912b77c07bcbe6320",
        "Result": "remove successed."
      },
      {
        "IP": "192.168.2.81",
        "HostName": "BOBLIU2.DOCKER",
        "ContainerId": "a15a16a4a7fc9633c6d5b98da962045c4745ecbaca98162d7db40b80e6d45b25",
        "Result": "remove successed."
      }
    ]
  }
}
Clone this wiki locally