【Azure Batch】在中国区批处理服务(Mooncake Batch Account)上实验自动池(Auto Pool)的创建/删除

简介: 【Azure Batch】在中国区批处理服务(Mooncake Batch Account)上实验自动池(Auto Pool)的创建/删除

问题描述

在Azure Batch的介绍文档中,提出了自动池的概念, 它可以在任务完成后,自动删除Pool资源,详细介绍:https://docs.azure.cn/zh-cn/batch/nodes-and-pools#autopools & https://learn.microsoft.com/zh-cn/rest/api/batchservice/job/add?tabs=HTTP#autopoolspecification

自动池是在提交作业时由 Batch 服务创建的池,而不是在创建将在池中运行的作业之前创建的。

Batch 服务将根据指定的特征管理自动池的生存期。

大多数情况下,这些池也设置为在其作业完成后自动删除。

 

虽然在自动池的文档中包含了示例,但是示例中的创建的Task需要一个 myprogram2.exe 应用,并且设置的 cloudServiceConfiguration 属性值已经不在可用。 所以,为了简化在中国区的Batch Account服务上实现自动池进行了本次实验。

 

问题解答

基于示例中,创建Task的 JSON 内容,需要做一下几点的修改:

1) POST 的请求 URL 从 Batch Account Overview 页面中 Account endpoint 复制。

account.region.batch.azure.com/jobs?api-version=2023-05-01.17.0


//变为

<your batch account>.<chinanorth3>.batch.chinacloudapi.cn/jobs?api-version=2023-05-01.17.0

2) Task中的commandLine内容修改为简单的CMD指令

"commandLine": "cmd /c  \"echo %date% %time% & set AZ_BATCH & timeout /t 90 > NUL & timeout /nobreak /t 10000 & echo 'what is your name?' & echo %date% %time%  \"",

3) Pool 的信息,指定 vm size 和 image

"pool": {
        "vmSize": "STANDARD_A1_V2",
         "virtualMachineConfiguration": {
            "imageReference": {
                "publisher": "microsoftwindowsserver",
                "offer": "windowsserver",
                "sku": "2019-datacenter-core-smalldisk",
                "version": "latest"
            },
            "nodeAgentSKUId": "batch.node.windows amd64",
            "licenseType": null,
            "nodePlacementConfiguration": {
                "policy": "Regional"
            }
        },

4)此处,获取Authorization的方式为从Azure门户上(F12 --> Network Trace )抓取Batch Task页面的Token

完成以上4步后,即可通过Postman或其他REST API工具发送POST请求。

 

完整的Task Body内容为:

{
  "id": "jobId-2",
  "priority": 100,
  "constraints": {
    "maxWallClockTime": "PT1H",
    "maxTaskRetryCount": -1
  },
  "jobManagerTask": {
    "id": "taskId",
    "commandLine": "cmd /c  \"echo %date% %time% & set AZ_BATCH & timeout /t 90 > NUL & timeout /nobreak /t 10000 & echo 'what is your name?' & echo %date% %time%  \"",
    "constraints": {
      "maxWallClockTime": "PT1H",
      "maxTaskRetryCount": 0,
      "retentionTime": "PT1H"
    },
    "requiredSlots": 2,
    "killJobOnCompletion": false,
    "userIdentity": {
      "autoUser": {
        "scope": "task",
        "elevationLevel": "admin"
      }
    },
    "runExclusive": true
  },
  "poolInfo": {
    "autoPoolSpecification": {
      "autoPoolIdPrefix": "mypool",
      "poolLifetimeOption": "job",
      "pool": {
        "vmSize": "STANDARD_A1_V2",
         "virtualMachineConfiguration": {
            "imageReference": {
                "publisher": "microsoftwindowsserver",
                "offer": "windowsserver",
                "sku": "2019-datacenter-core-smalldisk",
                "version": "latest"
            },
            "nodeAgentSKUId": "batch.node.windows amd64",
            "licenseType": null,
            "nodePlacementConfiguration": {
                "policy": "Regional"
            }
        },
        "resizeTimeout": "PT15M",
        "targetDedicatedNodes": 1,
        "targetLowPriorityNodes": 0,
        "taskSlotsPerNode": 1,
        "taskSchedulingPolicy": {
          "nodeFillType": "spread"
        },
        "enableAutoScale": false,
        "enableInterNodeCommunication": true,
        "metadata": [
          {
            "name": "myproperty",
            "value": "myvalue"
          }
        ],
        "targetNodeCommunicationMode": "default"
      }
    }
  }
}

请求的URL及Header:

POST  https://XXXXXXXXXXXXXX.chinanorth3.batch.chinacloudapi.cn/jobs?api-version=2023-05-01.17.0

 

Accept: */*

User-Agent: Thunder Client (https://www.thunderclient.com)

Content-Type: application/json; odata=minimalmetadata

Authorization: Bearer Token

 

示例Demo:

 

参考资料

自动池: https://docs.azure.cn/zh-cn/batch/nodes-and-pools#autopools

Job - Add : https://learn.microsoft.com/zh-cn/rest/api/batchservice/job/add?tabs=HTTP#autopoolspecification

目录
打赏
0
0
0
0
203
分享
相关文章
|
7月前
|
【Azure 存储服务】Azure Data Lake Storage (ADLS) Gen2 GRS Failover是否支持自动切换或者手动切换到灾备的终结点呢?
【Azure 存储服务】Azure Data Lake Storage (ADLS) Gen2 GRS Failover是否支持自动切换或者手动切换到灾备的终结点呢?
【Azure Cloud Service】创建Azure云服务时遇见分配VM资源错误: VM(s) with the following constraints cannot be allocated, because the condition is too restrictive
Allocation failed. VM(s) with the following constraints cannot be allocated, because the condition is too restrictive. Please remove some constraints and try again. Constraints applied are:\n - VM Size
【Azure 批处理 】Azure Batch门户中创建自定义作业模式失败解决办法
【Azure 批处理 】Azure Batch门户中创建自定义作业模式失败解决办法
|
7月前
【Azure Standard Logic App】Workflow积压非常严重的情况下, 执行实例居然不能自动缩放的原因?
【Azure Standard Logic App】Workflow积压非常严重的情况下, 执行实例居然不能自动缩放的原因?
PolarDB产品使用合集之集群配置主从1~16pcu,比如innodb_buffer_pool_size,另外线上innodb_buffer_pool_size配置里面是在变动的,该怎么配置
PolarDB是阿里云推出的一种云原生数据库服务,专为云设计,提供兼容MySQL、PostgreSQL的高性能、低成本、弹性可扩展的数据库解决方案,可以有效地管理和优化PolarDB实例,确保数据库服务的稳定、高效运行。以下是使用PolarDB产品的一些建议和最佳实践合集。
224 7
实时计算 Flink版产品使用合集之将sdkMode从rpc模式改为jdbc模式后,table.exec.mini-batch.enabled参数还生效吗
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
SAP WM高阶之Storage Type上架策略L下的Mixed Storage(1)
SAP WM高阶之Storage Type上架策略L下的Mixed Storage(1)
SAP WM高阶之Storage Type上架策略L下的Mixed Storage(1)
SAP WM高阶之Storage Type上架策略L下的Mixed Storage(2)
SAP WM高阶之Storage Type上架策略L下的Mixed Storage(2)
SAP WM高阶之Storage Type上架策略L下的Mixed Storage(2)
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等