创建或更新期望节点 API

编辑

创建或更新期望节点 API

编辑

此功能旨在由 Elasticsearch 服务Elastic Cloud EnterpriseElastic Cloud on Kubernetes 间接使用。不支持直接使用。

创建或更新期望节点。

请求

编辑
resp = client.perform_request(
    "PUT",
    "/_internal/desired_nodes/<history_id>/<version>",
    headers={"Content-Type": "application/json"},
    body={
        "nodes": [
            {
                "settings": {
                    "node.name": "instance-000187",
                    "node.external_id": "instance-000187",
                    "node.roles": [
                        "data_hot",
                        "master"
                    ],
                    "node.attr.data": "hot",
                    "node.attr.logical_availability_zone": "zone-0"
                },
                "processors": 8,
                "memory": "58gb",
                "storage": "2tb"
            }
        ]
    },
)
print(resp)
const response = await client.transport.request({
  method: "PUT",
  path: "/_internal/desired_nodes/<history_id>/<version>",
  body: {
    nodes: [
      {
        settings: {
          "node.name": "instance-000187",
          "node.external_id": "instance-000187",
          "node.roles": ["data_hot", "master"],
          "node.attr.data": "hot",
          "node.attr.logical_availability_zone": "zone-0",
        },
        processors: 8,
        memory: "58gb",
        storage: "2tb",
      },
    ],
  },
});
console.log(response);
PUT /_internal/desired_nodes/<history_id>/<version>
{
    "nodes" : [
        {
            "settings" : {
                 "node.name" : "instance-000187",
                 "node.external_id": "instance-000187",
                 "node.roles" : ["data_hot", "master"],
                 "node.attr.data" : "hot",
                 "node.attr.logical_availability_zone" : "zone-0"
            },
            "processors" : 8.0,
            "memory" : "58gb",
            "storage" : "2tb"
        }
    ]
}

查询参数

编辑
master_timeout
(可选,时间单位) 等待主节点的时间段。如果在超时过期之前主节点不可用,则请求失败并返回错误。默认为 30s。也可以设置为 -1 表示请求不应超时。
dry_run
(可选,布尔值) 如果为 true,则请求模拟更新并返回带有 dry_run 字段设置为 true 的响应。

描述

编辑

此 API 创建或更新期望节点。外部编排器可以使用此 API 来让 Elasticsearch 了解集群拓扑结构,包括添加或删除节点等未来更改。利用此信息,系统能够做出更好的决策。

可以通过添加 ?dry_run 查询参数来以“试运行”模式运行更新。这将验证请求结果,但不会实际执行更新。

示例

编辑

在此示例中,创建了具有历史记录 Ywkh3INLQcuPT49f6kcppA 的期望节点的新版本。此 API 仅接受单调递增的版本。

resp = client.perform_request(
    "PUT",
    "/_internal/desired_nodes/Ywkh3INLQcuPT49f6kcppA/100",
    headers={"Content-Type": "application/json"},
    body={
        "nodes": [
            {
                "settings": {
                    "node.name": "instance-000187",
                    "node.external_id": "instance-000187",
                    "node.roles": [
                        "data_hot",
                        "master"
                    ],
                    "node.attr.data": "hot",
                    "node.attr.logical_availability_zone": "zone-0"
                },
                "processors": 8,
                "memory": "58gb",
                "storage": "2tb"
            }
        ]
    },
)
print(resp)
const response = await client.transport.request({
  method: "PUT",
  path: "/_internal/desired_nodes/Ywkh3INLQcuPT49f6kcppA/100",
  body: {
    nodes: [
      {
        settings: {
          "node.name": "instance-000187",
          "node.external_id": "instance-000187",
          "node.roles": ["data_hot", "master"],
          "node.attr.data": "hot",
          "node.attr.logical_availability_zone": "zone-0",
        },
        processors: 8,
        memory: "58gb",
        storage: "2tb",
      },
    ],
  },
});
console.log(response);
PUT /_internal/desired_nodes/Ywkh3INLQcuPT49f6kcppA/100
{
    "nodes" : [
        {
            "settings" : {
                 "node.name" : "instance-000187",
                 "node.external_id": "instance-000187",
                 "node.roles" : ["data_hot", "master"],
                 "node.attr.data" : "hot",
                 "node.attr.logical_availability_zone" : "zone-0"
            },
            "processors" : 8.0,
            "memory" : "58gb",
            "storage" : "2tb"
        }
    ]
}

API 返回以下结果

{
  "replaced_existing_history_id": false,
  "dry_run": false
}

此外,还可以指定处理器范围。这在 Elasticsearch 节点可以部署在主机上的环境中非常有用,在这些环境中,Elasticsearch 进程可以使用处理器的数量至少保证在较低范围内,最多在较高范围内。这是在使用 cgroups 的 Linux 部署中常见的场景。

resp = client.perform_request(
    "PUT",
    "/_internal/desired_nodes/Ywkh3INLQcuPT49f6kcppA/101",
    headers={"Content-Type": "application/json"},
    body={
        "nodes": [
            {
                "settings": {
                    "node.name": "instance-000187",
                    "node.external_id": "instance-000187",
                    "node.roles": [
                        "data_hot",
                        "master"
                    ],
                    "node.attr.data": "hot",
                    "node.attr.logical_availability_zone": "zone-0"
                },
                "processors_range": {
                    "min": 8,
                    "max": 10
                },
                "memory": "58gb",
                "storage": "2tb"
            }
        ]
    },
)
print(resp)
const response = await client.transport.request({
  method: "PUT",
  path: "/_internal/desired_nodes/Ywkh3INLQcuPT49f6kcppA/101",
  body: {
    nodes: [
      {
        settings: {
          "node.name": "instance-000187",
          "node.external_id": "instance-000187",
          "node.roles": ["data_hot", "master"],
          "node.attr.data": "hot",
          "node.attr.logical_availability_zone": "zone-0",
        },
        processors_range: {
          min: 8,
          max: 10,
        },
        memory: "58gb",
        storage: "2tb",
      },
    ],
  },
});
console.log(response);
PUT /_internal/desired_nodes/Ywkh3INLQcuPT49f6kcppA/101
{
    "nodes" : [
        {
            "settings" : {
                 "node.name" : "instance-000187",
                 "node.external_id": "instance-000187",
                 "node.roles" : ["data_hot", "master"],
                 "node.attr.data" : "hot",
                 "node.attr.logical_availability_zone" : "zone-0"
            },
            "processors_range" : {"min": 8.0, "max": 10.0},
            "memory" : "58gb",
            "storage" : "2tb"
        }
    ]
}