【问题标题】:Perform a task on Azure batch在 Azure 批处理上执行任务
【发布时间】:2017-11-22 12:06:47
【问题描述】:

我是 Azure 批处理的新手。我必须在池中的节点上执行一项任务。

我使用的方法是我拥有想要在节点上运行的代码。我正在制作 .class 文件 jar 的 zip 并上传到我的 Azure 存储帐户,然后获取应用程序 ID 并将其放入 ApplicationPackageReference 并添加到我的工作任务中。

String applicationId= "TaskPerformApplicationPack";
ApplicationPackageReference reference = new ApplicationPackageReference().withApplicationId(applicationId);
List<ApplicationPackageReference> list = new ArrayList<ApplicationPackageReference>();
list.add(reference);
TaskAddParameter taskToAdd = new TaskAddParameter().withId("mytask2").withApplicationPackageReferences(list);
taskToAdd.withCommandLine(String.format("java -jar task.jar"));


batchClient.taskOperations().createTask(jobId, taskToAdd);

现在当我运行它时,我的任务失败并给出一个错误

对指定 Azure Blob 之一的访问被拒绝

如何使用 azure 批处理作业任务在节点上运行特定代码?

【问题讨论】:

    标签: azure azure-storage azure-batch


    【解决方案1】:

    我认为一个好的起点是:(我已经介绍了大多数有用的链接以及下面的指导文档,他们将详细说明环境级别变量等的使用,我还包含了一些示例链接作为好吧。) 希望下面的材料和示例对您有所帮助。 :)

    此外,如果池较旧,我建议您重新创建它,以确保您的节点以最新版本运行。

    从文章中进一步补充:也看这里:Application Packages with VM configuration

    特别是this 链接将引导您完成如何在代码中使用它的指导过程:无论是资源文件还是包,您都需要确保它们已上传并可在批处理级别使用。

    连同像这样的示例:(下面是一个池级别的 pkg 示例)

    // Create the unbound CloudPool
    CloudPool myCloudPool =
        batchClient.PoolOperations.CreatePool(
            poolId: "myPool",
            targetDedicatedComputeNodes: 1,
            virtualMachineSize: "small",
            cloudServiceConfiguration: new CloudServiceConfiguration(osFamily: "4"));
    
    // Specify the application and version to install on the compute nodes
    myCloudPool.ApplicationPackageReferences = new List<ApplicationPackageReference>
    {
        new ApplicationPackageReference {
            ApplicationId = "litware",
            Version = "1.1" }
    };
    
    // 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();
    

    对于任务级别表单,示例上方的链接是:(确保您已正确执行here 中提到的步骤。

    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.1"
        }
    };
    

    进一步补充:无论是CloudServiceCOhnfiguration 还是VirtualMachineConfiguration,应用程序包是**a .zip file**,其中包含运行应用程序的任务所需的应用程序二进制文件和支持文件。每个应用程序包代表应用程序的特定版本。来自参考:4

    我试了一下并尝试并成功了,所以我无法复制上面的错误,看起来你可能遗漏了一些东西。

    【讨论】:

      猜你喜欢
      • 2020-02-02
      • 2021-08-02
      • 1970-01-01
      • 1970-01-01
      • 2018-04-19
      • 1970-01-01
      • 2015-10-18
      • 1970-01-01
      • 2013-06-11
      相关资源
      最近更新 更多