创建或更新期望节点 API

编辑

创建或更新期望节点 API

编辑

此功能旨在供 Elasticsearch ServiceElastic 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 进程可以使用的处理器数量至少在下限范围内,最高可达上限范围。这在使用 cgroup 的 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"
        }
    ]
}