使用 Batch 应用程序包将应用程序部署到计算节点Deploy applications to compute nodes with Batch application packages

使用 Azure Batch 的应用程序包功能可以轻松管理任务应用程序并将其部署到池中的计算节点。The application packages feature of Azure Batch provides easy management of task applications and their deployment to the compute nodes in your pool. 使用应用程序包可以上传和管理任务运行的多个应用程序版本,包括其支持文件。With application packages, you can upload and manage multiple versions of the applications your tasks run, including their supporting files. 然后,可以将一个或多个此类应用程序自动部署到池中的计算节点。You can then automatically deploy one or more of these applications to the compute nodes in your pool.

本文介绍如何使用 Azure 门户上传和管理应用程序包。In this article, you learn how to upload and manage application packages in the Azure portal. 然后,介绍如何使用 Batch .NET 库将包安装到池的计算节点。You then learn how to install them on a pool's compute nodes with the Batch .NET library.

备注

在 2017 年 7 月 5 日以后创建的所有 Batch 池都支持应用程序包。Application packages are supported on all Batch pools created after 5 July 2017. 在 2016 年 3 月 10 日和 2017 年 7 月 5 日期间创建的 Batch 池也支持应用程序包,但前提是该池是使用云服务配置创建的。They are supported on Batch pools created between 10 March 2016 and 5 July 2017 only if the pool was created using a Cloud Service configuration. 在 2016 年 3 月 10 日以前创建的 Batch 池不支持应用程序包。Batch pools created prior to 10 March 2016 do not support application packages.

用于创建和管理应用程序包的 API 属于 Batch Management .NET 库。The APIs for creating and managing application packages are part of the Batch Management .NET library. 用于在计算节点上安装应用程序包的 API 属于 Batch .NET 库。The APIs for installing application packages on a compute node are part of the Batch .NET library. 其他语言的可用 Batch API 中提供了对应的功能。Comparable features are in the available Batch APIs for other languages.

此处所述的应用程序包功能替换了旧版服务中的“批处理应用”功能。The application packages feature described here supersedes the Batch Apps feature available in previous versions of the service.

应用程序包要求Application package requirements

要使用应用程序包,需要将 Azure 存储帐户链接到批处理帐户。To use application packages, you need to link an Azure Storage account to your Batch account.

关于应用程序和应用程序包About applications and application packages

在 Azure Batch 中,应用程序是指一组已创建版本的二进制文件,这些文件可自动下载到池中的计算节点。Within Azure Batch, an application refers to a set of versioned binaries that can be automatically downloaded to the compute nodes in your pool. 应用程序包指的是这些二进制文件中的一组特定组合,其代表应用程序的特定版本。An application package refers to a specific set of those binaries and represents a given version of the application.

应用程序和应用程序包的概要关系图High-level diagram of applications and application packages

应用程序Applications

Batch 中的应用程序包含一个或多个应用程序包,指定应用程序的配置选项。An application in Batch contains one or more application packages and specifies configuration options for the application. 例如,应用程序可以指定要安装在计算节点上的默认应用程序包版本,以及应用程序的包是否可以更新或删除。For example, an application can specify the default application package version to install on compute nodes and whether its packages can be updated or deleted.

应用程序包Application packages

应用程序包为 .zip 文件,其中包含应用程序二进制文件和应用程序运行任务所需的支持文件。An application package is a .zip file that contains the application binaries and supporting files that are required for your tasks to run the application. 每个应用程序包都代表特定版本的应用程序。Each application package represents a specific version of the application.

可以在池和任务级别指定应用程序包。You can specify application packages at the pool and task levels. 创建池或任务时,可以指定其中的一个或多个包,以及(可选)指定版本。You can specify one or more of these packages and (optionally) a version when you create a pool or task.

  • 池应用程序包部署到池中的每个节点。Pool application packages are deployed to every node in the pool. 当节点加入池以及重新启动或重置映像时,就会部署应用程序。Applications are deployed when a node joins a pool, and when it is rebooted or reimaged.

    当池中的所有节点执行作业的任务时,便适合使用池应用程序包。Pool application packages are appropriate when all nodes in a pool execute a job's tasks. 可以在创建池时指定一个或多个应用程序包,并且可以添加或更新现有池的包。You can specify one or more application packages when you create a pool, and you can add or update an existing pool's packages. 如果更新现有池的应用程序包,必须重新启动它的节点才能安装新包。If you update an existing pool's application packages, you must restart its nodes to install the new package.

  • 在运行任务的命令行之前,任务应用程序包只部署到计划要运行任务的计算节点。Task application packages are deployed only to a compute node scheduled to run a task, just before running the task's command line. 如果节点上已有指定的应用程序包和版本,则不会重新部署,而是使用现有包。If the specified application package and version is already on the node, it is not redeployed and the existing package is used.

    在共享池的环境中,任务应用程序包装很有用:不同的操作在一个池上运行,而某项作业完成时并不删除该池。Task application packages are useful in shared-pool environments, where different jobs are run on one pool, and the pool is not deleted when a job is completed. 如果作业中的任务少于池中的节点,任务应用程序包可以减少数据传输,因为应用程序只部署到运行任务的节点。If your job has fewer tasks than nodes in the pool, task application packages can minimize data transfer since your application is deployed only to the nodes that run tasks.

    其他可受益于任务应用程序包的方案为,运行大型应用程序但只执行少数任务的作业。Other scenarios that can benefit from task application packages are jobs that run a large application, but for only a few tasks. 例如,预处理或合并应用程序非常庞大的预处理阶段或合并任务可能受益于使用任务应用程序包。For example, a pre-processing stage or a merge task, where the pre-processing or merge application is heavyweight, may benefit from using task application packages.

重要

批处理帐户中的应用程序和应用程序包数目,以及应用程序包的大小上限有其限制。There are restrictions on the number of applications and application packages within a Batch account and on the maximum application package size. 有关这些限制的详细信息,请参阅 Azure Batch 服务的配额和限制See Quotas and limits for the Azure Batch service for details about these limits.

应用程序包的优点Benefits of application packages

应用程序包可以简化 Batch 解决方案中的代码,也能降低管理任务运行的应用程序所需的开销。Application packages can simplify the code in your Batch solution and lower the overhead required to manage the applications that your tasks run.

有了应用程序包,池的启动任务不需要指定在节点上安装一长串的单个资源文件。With application packages, your pool's start task doesn't have to specify a long list of individual resource files to install on the nodes. 不需要在 Azure 存储中或在节点上手动管理应用程序的多个版本。You don't have to manually manage multiple versions of your application files in Azure Storage, or on your nodes. 而且,也不必费心生成 SAS URL 来提供这些文件在存储帐户中的访问权限。And, you don't need to worry about generating SAS URLs to provide access to the files in your Storage account. Batch 在后台与 Azure 存储协作来存储应用程序包,并将其部署到计算节点。Batch works in the background with Azure Storage to store application packages and deploy them to compute nodes.

备注

启动任务的总大小必须小于或等于 32768 个字符,其中包括资源文件和环境变量。The total size of a start task must be less than or equal to 32768 characters, including resource files and environment variables. 如果启动任务超出此限制,备选方案就是使用应用程序包。If your start task exceeds this limit, then using application packages is another option. 还可以创建一个包含资源文件的压缩存档,将此存档作为 blob 上传到 Azure 存储,再从启动任务的命令行中解压缩该存档。You can also create a zipped archive containing your resource files, upload it as a blob to Azure Storage, and then unzip it from the command line of your start task.

上传和管理应用程序Upload and manage applications

可以使用 Azure 门户或 Batch 管理 API 来管理 Batch 帐户中的应用程序包。You can use the Azure portal or the Batch Management APIs to manage the application packages in your Batch account. 在后面几个部分中,将先介绍如何链接存储帐户,再介绍如何使用门户来添加应用程序和包以及管理它们。In the next few sections, we first show how to link a Storage account, then discuss adding applications and packages and managing them with the portal.

要使用应用程序包,必须先将 Azure 存储帐户链接到 Batch 帐户。To use application packages, you must first link an Azure Storage account to your Batch account. 如果尚未配置存储帐户,第一次单击 Batch 帐户中的“应用程序”时,Azure 门户会显示警告。If you have not yet configured a Storage account, the Azure portal displays a warning the first time you click Applications in your Batch account.

Azure 门户中显示的“未配置存储帐户”警告'No storage account configured' warning in Azure portal

Batch 服务使用关联的存储帐户存储应用程序包。The Batch service uses the associated Storage account to store your application packages. 链接两个帐户后,Batch 便能将存储在链接之存储帐户中的包自动部署到计算节点。After you've linked the two accounts, Batch can automatically deploy the packages stored in the linked Storage account to your compute nodes. 若要将存储帐户链接到 Batch 帐户,请单击“警告”窗口中的“存储帐户”,然后再次单击“存储帐户”。 To link a Storage account to your Batch account, click Storage account on the Warning window, and then click Storage Account again.

在 Azure 门户中选择存储帐户边栏选项卡Choose storage account blade in Azure portal

建议专门创建一个存储帐户用作批处理帐户,并在此处选择该帐户。We recommend that you create a Storage account specifically for use with your Batch account, and select it here. 创建存储帐户后,可以使用“存储帐户”窗口将其链接到 Batch 帐户。After you've created a Storage account, you can then link it to your Batch account by using the Storage Account window.

重要

  • 目前无法将应用程序包用于配置有防火墙规则的 Azure 存储帐户。Currently you can't use application packages with an Azure Storage account that is configured with firewall rules.
  • “分层命名空间”设置为“已启用”的 Azure 存储帐户不能用于应用程序包 。An Azure Storage account with Hierarchical namespace set to Enabled can't be used for application packages.

Batch 服务使用 Azure 存储将应用程序包存储为块 blob。The Batch service uses Azure Storage to store your application packages as block blobs. 块 blob 数据正常收费,且每个包的大小不能超过最大块 blob 大小。You are charged as normal for the block blob data, and the size of each package can't exceed the maximum block blob size. 有关详细信息,请参阅存储帐户的 Azure 存储可伸缩性和性能目标For more information, see Azure Storage scalability and performance targets for storage accounts. 请务必考虑应用程序包的大小和数目,并定期删除过时的包以降低成本。Be sure to consider the size and number of your application packages, and periodically remove deprecated packages to minimize costs.

查看当前应用程序View current applications

若要查看 Batch 帐户中的应用程序,请在查看“Batch 帐户”时,单击左侧菜单中的“应用程序”菜单项。To view the applications in your Batch account, click the Applications menu item in the left menu while viewing your Batch account.

应用程序磁贴Applications tile

选择此菜单选项打开“应用程序”窗口:Selecting this menu option opens the Applications window:

列出应用程序List applications

此窗口显示帐户中每个应用程序的 ID,以及以下属性:This window displays the ID of each application in your account and the following properties:

  • :与此应用程序关联的版本号。Packages: The number of versions associated with this application.
  • 默认版本:如果你在为池指定应用程序时未指明版本,系统安装的是此应用程序版本。Default version: The application version installed if you do not indicate a version when you specify the application for a pool. 此设置是可选的。This setting is optional.
  • 允许更新:用于指定是否允许更新、删除和添加包的值。Allow updates: The value that specifies whether package updates, deletions, and additions are allowed. 如果此值设置为“否”,将禁用对应用程序包执行更新和删除操作。If this is set to No, package updates and deletions are disabled for the application. 只能添加新的应用程序包版本。Only new application package versions can be added. 默认值为“是”。The default is Yes.

若要查看计算节点上的应用程序包的文件结构,请在门户中导航到 Batch 帐户。If you'd like to see the file structure of the application package on your compute node, navigate to your Batch account in the portal. 从 Batch 帐户导航到“池”。From your Batch account, navigate to Pools. 选择包含所需计算节点的池。Select the pool that contains the compute node(s) you're interested in.

池中的节点Nodes in pool

选择池后,导航到安装了应用程序包的计算节点。Once you've selected your pool, navigate to the compute node that the application package is installed on. 其中,可在“应用程序”文件夹中查看应用程序包详细信息。From there, the details of the application package are located in the applications folder. 计算节点上的其他文件夹包含启动任务、输出文件、错误输出等其他文件。Additional folders on the compute node contain other files, such as start tasks, output files, error output, etc.

节点上的文件Files on node

查看应用程序详细信息View application details

若要查看某个应用程序的详细信息,请在“应用程序”窗口中选择该应用程序。To see the details for an application, select the application in the Applications window.

应用程序详细信息Application details

在应用程序详细信息中,可以配置应用程序的以下设置。In the application details, you can configure the following settings for your application.

  • 允许更新:指定能否更新或删除应用程序包。Allow updates: Specify whether its application packages can be updated or deleted. 请参阅下文中的“更新或删除应用程序包”。See "Update or Delete an application package" later in this article.
  • 默认版本:指定要部署到计算节点的默认应用程序包。Default version: Specify a default application package to deploy to compute nodes.
  • 显示名称:指定在 Batch 解决方案显示应用程序相关信息时(例如,在通过 Batch 提供给客户的服务 UI 中),解决方案可使用的易记名称。Display name: Specify a friendly name that your Batch solution can use when it displays information about the application, for example, in the UI of a service that you provide to your customers through Batch.

添加新的应用程序Add a new application

若要创建新应用程序,请添加应用程序包并指定新的唯一应用程序 ID。To create a new application, add an application package and specify a new, unique application ID. 使用新应用程序 ID 添加的第一个应用程序包也会创建新的应用程序。The first application package that you add with the new application ID also creates the new application.

单击“应用程序” > “添加”。Click Applications > Add.

Azure 门户中的新建应用程序边栏选项卡New application blade in Azure portal

“新建应用程序”窗口提供以下字段,用于指定新应用程序和应用程序包的设置。The New application window provides the following fields to specify the settings of your new application and application package.

应用程序 IDApplication ID

此字段指定新应用程序的 ID,需符合标准 Azure Batch ID 验证规则。This field specifies the ID of your new application, which is subject to the standard Azure Batch ID validation rules. 提供应用程序 ID 的规则如下所示:The rules for providing an application ID are as follows:

  • 在 Windows 节点上,ID 可以包含字母数字字符、连字符和下划线的任意组合。On Windows nodes, the ID can contain any combination of alphanumeric characters, hyphens, and underscores. 在 Linux 节点上,仅允许使用字母数字字符和下划线。On Linux nodes, only alphanumeric characters and underscores are permitted.
  • 不能超过 64 个字符。Cannot contain more than 64 characters.
  • 在 Batch 帐户内必须唯一。Must be unique within the Batch account.
  • 保留大小写和不区分大小写。Is case-preserving and case-insensitive.

版本Version

此字段指定要上传的应用程序包版本。This field specifies the version of the application package you are uploading. 版本字符串需符合以下验证规则:Version strings are subject to the following validation rules:

  • 在 Windows 节点上,此版本字符串可以包含字母数字字符、连字符、下划线和句点的任意组合。On Windows nodes, the version string can contain any combination of alphanumeric characters, hyphens, underscores, and periods. 在 Linux 节点上,此版本字符串只能包含字母数字字符和下划线。On Linux nodes, the version string can contain only alphanumeric characters and underscores.
  • 不能超过 64 个字符。Cannot contain more than 64 characters.
  • 在应用程序内必须唯一。Must be unique within the application.
  • 保留大小写和不区分大小写。Are case-preserving and case-insensitive.

应用程序包Application package

指定包含应用程序二进制文件和执行应用程序所需的任何支持文件的 .zip 文件。This field specifies the .zip file that contains the application binaries and supporting files that are required to execute the application. 单击“选择文件”文本框或文件夹图标,以浏览并选择包含应用程序文件的 .zip 文件。Click the Select a file box or the folder icon to browse to and select a .zip file that contains your application's files.

选择文件后,单击“确定”开始上传到 Azure 存储。After you've selected a file, click OK to begin the upload to Azure Storage. 上传操作完成后,门户会显示通知。When the upload operation is complete, the portal displays a notification. 因上传之文件的大小和网络连接速度不尽相同,此操作可能需要花费一些时间。Depending on the size of the file that you are uploading and the speed of your network connection, this operation may take some time.

警告

上传操作完成之前,请勿关闭“新建应用程序”窗口,Do not close the New application window before the upload operation is complete. 否则上传过程会停止。Doing so stops the upload process.

添加新应用程序包Add a new application package

若要添加现有应用程序的应用程序包版本,请在“应用程序”窗口中选择该应用程序,并单击“包” > “添加”。 To add an application package version for an existing application, select an application in the Applications windows, and click Packages > Add.

Azure 门户中的添加应用程序包边栏选项卡Add application package blade in Azure portal

可以看到,除了“应用程序 ID”文本框已禁用之外,字段与“新建应用程序”窗口中的字段匹配。As you can see, the fields match those of the New application window, but the Application ID box is disabled. 如前面创建新应用程序一样,指定新包的“版本”,浏览到“应用程序包”.zip 文件,并单击“确定”上传包。As you did for the new application, specify the Version for your new package, browse to your Application package .zip file, then click OK to upload the package.

更新或删除应用程序包Update or delete an application package

要更新或删除现有的应用程序包,请打开应用程序的详细信息,单击“包”,单击要修改的应用程序包数据列中的省略号,并选择要执行的操作。To update or delete an existing application package, open the details for the application, click Packages, click the ellipsis in the row of the application package that you want to modify, and select the action that you want to perform.

在 Azure 门户中更新或删除包Update or delete package in Azure portal

UpdateUpdate

单击“更新”时,“更新包”窗口随即出现。When you click Update, the Update package windows is displayed. 此窗口与“新建应用程序包”窗口相似,只不过包选择字段已启用,因此可以指定要上传的新 ZIP 文件。This window is similar to the New application package window, however only the package selection field is enabled, allowing you to specify a new ZIP file to upload.

Azure 门户中的更新包边栏选项卡Update package blade in Azure portal

删除Delete

单击“删除”时,系统会要求确认是否要删除包版本,随后 Batch 从 Azure 存储中删除该包。When you click Delete, you are asked to confirm the deletion of the package version, and Batch deletes the package from Azure Storage. 如果删除应用程序的默认版本,系统会删除应用程序的“默认版本”设置。If you delete the default version of an application, the Default version setting is removed for the application.

删除应用程序Delete application

将应用程序安装在计算节点上Install applications on compute nodes

了解如何使用 Azure 门户管理应用程序包之后,接下来介绍如何使用批处理任务将它们部署到计算节点并运行它们。Now that you've learned how to manage application packages with the Azure portal, we can discuss how to deploy them to compute nodes and run them with Batch tasks.

安装池应用程序包Install pool application packages

要将应用程序包安装在池中的所有计算节点上,需要为池指定一个或多个应用程序包引用。To install an application package on all compute nodes in a pool, specify one or more application package references for the pool. 将每个计算节点加入池以及该节点重新启动或重置映像时,为池指定的应用程序包将安装在该节点上。The application packages that you specify for a pool are installed on each compute node when that node joins the pool, and when the node is rebooted or reimaged.

在 Batch .NET 中,可以在创建新池时指定一个或多个 CloudPool.ApplicationPackageReferences,或将它们添加到现有池。In Batch .NET, specify one or more CloudPool.ApplicationPackageReferences when you create a new pool, or for an existing pool. ApplicationPackageReference 类指定要安装在池的计算节点上的应用程序 ID 和版本。The ApplicationPackageReference class specifies an application ID and version to install on a pool's compute nodes.

// Create the unbound CloudPool
CloudPool myCloudPool =
    batchClient.PoolOperations.CreatePool(
        poolId: "myPool",
        targetDedicatedComputeNodes: 1,
        virtualMachineSize: "standard_d1_v2",
        cloudServiceConfiguration: new CloudServiceConfiguration(osFamily: "5"));

// Specify the application and version to install on the compute nodes
myCloudPool.ApplicationPackageReferences = new List<ApplicationPackageReference>
{
    new ApplicationPackageReference {
        ApplicationId = "litware",
        Version = "1.1001.2b" }
};

// Commit the pool so that it's created in the Batch service. As the nodes join
// the pool, the specified application package is installed on each.
await myCloudPool.CommitAsync();

重要

如果应用程序包部署出于任何原因而失败,Batch 服务会将该节点标记为 unusable,并且不会在该节点上计划执行任何任务。If an application package deployment fails for any reason, the Batch service marks the node unusable, and no tasks are scheduled for execution on that node. 在此情况下,应重启节点,以重新启动包部署。In this case, you should restart the node to reinitiate the package deployment. 重启节点也会在节点上再次启用任务计划。Restarting the node also enables task scheduling again on the node.

安装任务应用程序包Install task application packages

类似于池,可以为任务指定应用程序包引用。Similar to a pool, you specify application package references for a task. 在节点上计划要运行的任务时,请先下载并解压缩包,然后执行任务的命令行。When a task is scheduled to run on a node, the package is downloaded and extracted just before the task's command line is executed. 如果节点上已安装指定的包和版本,则不会下载包,而是使用现有包。If a specified package and version is already installed on the node, the package is not downloaded and the existing package is used.

若要安装任务应用程序包,请配置任务的 CloudTask.ApplicationPackageReferences 属性:To install a task application package, configure the task's CloudTask.ApplicationPackageReferences property:

CloudTask task =
    new CloudTask(
        "litwaretask001",
        "cmd /c %AZ_BATCH_APP_PACKAGE_LITWARE%\\litware.exe -args -here");

task.ApplicationPackageReferences = new List<ApplicationPackageReference>
{
    new ApplicationPackageReference
    {
        ApplicationId = "litware",
        Version = "1.1001.2b"
    }
};

执行安装的应用程序Execute the installed applications

为池或任务指定的包下载并解压缩到节点的 AZ_BATCH_ROOT_DIR 中的命名目录。The packages that you've specified for a pool or task are downloaded and extracted to a named directory within the AZ_BATCH_ROOT_DIR of the node. Batch 还会创建包含命名目录路径的环境变量。Batch also creates an environment variable that contains the path to the named directory. 在引用节点上的应用程序时,任务的命令行使用此环境变量。Your task command lines use this environment variable when referencing the application on the node.

在 Windows 节点上,变量格式如下:On Windows nodes, the variable is in the following format:

Windows:
AZ_BATCH_APP_PACKAGE_APPLICATIONID#version

在 Linux 节点上,该格式略有不同。On Linux nodes, the format is slightly different. 句点 (.)、连字符 (-) 和数字符号 (#) 在环境变量中都会转换为下划线。Periods (.), hyphens (-) and number signs (#) are flattened to underscores in the environment variable. 另请注意,请保留应用程序 ID 的大小写。Also, note that the case of the application ID is preserved. 例如:For example:

Linux:
AZ_BATCH_APP_PACKAGE_applicationid_version

APPLICATIONIDversion 是对应于为部署指定的应用程序和包版本的值。APPLICATIONID and version are values that correspond to the application and package version you've specified for deployment. 例如,如果指定应在 Windows 节点上安装 2.7 版的 blender 应用程序,任务命令行可使用此环境变量来访问其文件:For example, if you specified that version 2.7 of application blender should be installed on Windows nodes, your task command lines would use this environment variable to access its files:

Windows:
AZ_BATCH_APP_PACKAGE_BLENDER#2.7

在 Linux 节点上,按以下格式指定环境变量。On Linux nodes, specify the environment variable in this format. 将句点 (.)、连字符 (-) 和数字符号 (#) 平展为下划线,并保留应用程序 ID 的大小写:Flatten the periods (.), hyphens (-) and number signs (#) to underscores, and preserve the case of the application ID:

Linux:
AZ_BATCH_APP_PACKAGE_blender_2_7

在上传应用程序包时,可以指定要部署到计算节点的默认版本。When you upload an application package, you can specify a default version to deploy to your compute nodes. 如果已指定应用程序的默认版本,可以在引用该应用程序时省略版本后缀。If you have specified a default version for an application, you can omit the version suffix when you reference the application. 可以在 Azure 门户的“应用程序”窗口中指定默认的应用程序版本,如上传和管理应用程序中所述。You can specify the default application version in the Azure portal, in the Applications window, as shown in Upload and manage applications.

例如,如果设置“2.7”作为 blender 应用程序的默认版本,并且任务引用以下环境变量,则 Windows 节点将会执行 2.7 版:For example, if you set "2.7" as the default version for application blender, and your tasks reference the following environment variable, then your Windows nodes will execute version 2.7:

AZ_BATCH_APP_PACKAGE_BLENDER

以下代码片段显示任务命令行示例,其可启动 blender 应用程序的默认版本:The following code snippet shows an example task command line that launches the default version of the blender application:

string taskId = "blendertask01";
string commandLine =
    @"cmd /c %AZ_BATCH_APP_PACKAGE_BLENDER%\blender.exe -args -here";
CloudTask blenderTask = new CloudTask(taskId, commandLine);

提示

有关计算节点环境设置的详细信息,请参阅任务的环境设置For more information about compute node environment settings, see Environment settings for tasks.

更新池的应用程序包Update a pool's application packages

如果已配置现有池的应用程序包,可以指定池的新包。If an existing pool has already been configured with an application package, you can specify a new package for the pool. 如果为池指定新的包引用,请遵循以下规则:If you specify a new package reference for a pool, the following apply:

  • Batch 服务在联接池的所有新节点上以及任何重新启动或重置映像的现有节点上都会安装新指定的包。The Batch service installs the newly specified package on all new nodes that join the pool and on any existing node that is rebooted or reimaged.
  • 在更新包引用时已存在池中的计算节点不自动安装新应用程序包。Compute nodes that are already in the pool when you update the package references do not automatically install the new application package. 这些计算节点必须重新启动或重置映像才能接收新包。These compute nodes must be rebooted or reimaged to receive the new package.
  • 部署新包后,创建的环境变量将反映新的应用程序包引用。When a new package is deployed, the created environment variables reflect the new application package references.

在此示例中,现有池已将应用程序 blender 的 2.7 版设置为其中一个 CloudPool.ApplicationPackageReferencesIn this example, the existing pool has version 2.7 of the blender application configured as one of its CloudPool.ApplicationPackageReferences. 要将池的节点更新为 2.76b 版,请将 ApplicationPackageReference 指定为新版本并提交更改。To update the pool's nodes with version 2.76b, specify a new ApplicationPackageReference with the new version, and commit the change.

string newVersion = "2.76b";
CloudPool boundPool = await batchClient.PoolOperations.GetPoolAsync("myPool");
boundPool.ApplicationPackageReferences = new List<ApplicationPackageReference>
{
    new ApplicationPackageReference {
        ApplicationId = "blender",
        Version = newVersion }
};
await boundPool.CommitAsync();

配置新版本后,Batch 服务将在任何联接池的新节点上安装 2.76b 版。Now that the new version has been configured, the Batch service installs version 2.76b to any new node that joins the pool. 要将 2.76b 安装到已在池中的节点上,请重新启动或重置映像这些节点。To install 2.76b on the nodes that are already in the pool, reboot or reimage them. 请注意,重新启动的节点会保留前面的包部署中的文件。Note that rebooted nodes retain the files from previous package deployments.

列出 Batch 帐户中的应用程序List the applications in a Batch account

可以使用 ApplicationOperations.ListApplicationSummaries 方法列出 Batch 帐户中的应用程序和应用程序包。You can list the applications and their packages in a Batch account by using the ApplicationOperations.ListApplicationSummaries method.

// List the applications and their application packages in the Batch account.
List<ApplicationSummary> applications = await batchClient.ApplicationOperations.ListApplicationSummaries().ToListAsync();
foreach (ApplicationSummary app in applications)
{
    Console.WriteLine("ID: {0} | Display Name: {1}", app.Id, app.DisplayName);

    foreach (string version in app.Versions)
    {
        Console.WriteLine("  {0}", version);
    }
}

总结Wrap up

当客户使用提供的启用 Batch 服务来处理操作时,可以通过应用程序包帮助他们选择作业的应用程序,以及指定要使用的确切版本。With application packages, you can help your customers select the applications for their jobs and specify the exact version to use when processing jobs with your Batch-enabled service. 你还可以在服务中提供让客户上传及跟踪其应用程序的功能。You might also provide the ability for your customers to upload and track their own applications in your service.

后续步骤Next steps