如何将新组添加到现有的应用程序组层次结构中

pxy2qtax  于 2021-06-21  发布在  Mesos
关注(0)|答案(2)|浏览(326)

在部署了一个新的马拉松应用程序组,其层次结构如下(注意,为了可读性,显示为yaml而不是json):

id: root_id
groups: 
- id: data_center_id
  groups:
  - id: category_id
    groups:
    - id: app_or_svc_type_id
      apps
      - id: app_id
        ....
      - id: app_id
        ....
      - id: app_id
        ....
    - id: app_or_svc_type_id
      apps
      - id: app_id
        ....
      - id: app_id
        ....
      - id: app_id
        ....

我现在想在类别级别添加一个额外的子组,所以现在看起来是这样的:

id: root_id
groups: 
- id: data_center_id
  groups:
  - id: category_id
    groups:
    - id: app_or_svc_type_id
      apps
      - id: app_id
        ....
      - id: app_id
        ....
      - id: app_id
        ....
    - id: app_or_svc_type_id
      apps
      - id: app_id
        ....
      - id: app_id
        ....
      - id: app_id
        ....
  # this is the new subgroup to add
  - id: category_id
    groups:
    - id: app_or_svc_type_id
      apps
      - id: app_id
        ....
      - id: app_id
        ....
      - id: app_id
        ....
    - id: app_or_svc_type_id
      apps
      - id: app_id
        ....
      - id: app_id
        ....
      - id: app_id
        ....

当我尝试通过使用marathonrestapi的put执行此操作时,现有的组将被销毁,新的子组将被创建。也许我在这里遗漏了一些东西,但是要添加新的微服务(例如,向现有的应用程序组层次结构添加新的微服务),这个功能是至关重要的。
感谢您的帮助

tcomlyy6

tcomlyy61#

我不太清楚你到底做了什么。告诉我们您的确切http请求可能会有所帮助。
您的问题可能是您的组和应用程序的ID不正确。有时,这会导致忽略组/应用程序而没有任何明显的错误:https://github.com/mesosphere/marathon/issues/1890
下面的http请求对我有效。
创建具有一个子组的初始组:

PUT /v2/groups/group HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 185
Content-Type: application/json
Host: localhost:8080
User-Agent: HTTPie/0.9.2

{
    "groups": [
        {
            "apps": [
                {
                    "cmd": "python -m SimpleHTTPServer $PORT",
                    "id": "/group/subgroup1/app"
                }
            ],
            "id": "/group/subgroup1"
        }
    ],
    "id": "/group"
}

HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, must-revalidate
Content-Type: application/json
Expires: 0
Pragma: no-cache
Server: Jetty(8.1.15.v20140411)
Transfer-Encoding: chunked
X-Marathon-Leader: http://localhost:8080

{
    "deploymentId": "6c59b425-49e2-4db8-8de0-a29020a34be7",
    "version": "2015-07-28T12:00:01.171Z"
}

使用包含其他子组的新定义更新组:

PUT /v2/groups/group HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 335
Content-Type: application/json
Host: localhost:8080
User-Agent: HTTPie/0.9.2

{
    "groups": [
        {
            "apps": [
                {
                    "cmd": "python -m SimpleHTTPServer $PORT",
                    "id": "/group/subgroup1/app"
                }
            ],
            "id": "/group/subgroup1"
        },
        {
            "apps": [
                {
                    "cmd": "python -m SimpleHTTPServer $PORT",
                    "id": "/group/subgroup2/app"
                }
            ],
            "id": "/group/subgroup2"
        }
    ],
    "id": "/group"
}

HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, must-revalidate
Content-Type: application/json
Expires: 0
Pragma: no-cache
Server: Jetty(8.1.15.v20140411)
Transfer-Encoding: chunked
X-Marathon-Leader: http://localhost:8080

{
    "deploymentId": "b72801f7-8a18-434e-bebb-81d55e698ef1",
    "version": "2015-07-28T12:03:17.109Z"
}

已存在的应用程序/组保持不变。
或者,您也可以使用 PUT 请求到 /v2/groups/group/subgroup2 只有那个小组的定义。

prdp8dxp

prdp8dxp2#

要添加子组,只需 PUT 或者 POST 在您的例子中,完全指定了其id的子组 /root_id/data_center_id/category_id .

相关问题