与 AWS SDK或DescribeJobQueues一起使用 CLI - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

与 AWS SDK或DescribeJobQueues一起使用 CLI

以下代码示例演示如何使用 DescribeJobQueues

操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:

CLI
AWS CLI

描述任务队列

此示例描述了 HighPriority 任务队列。

命令:

aws batch describe-job-queues --job-queues HighPriority

输出:

{ "jobQueues": [ { "status": "VALID", "jobQueueArn": "arn:aws:batch:us-east-1:012345678910:job-queue/HighPriority", "computeEnvironmentOrder": [ { "computeEnvironment": "arn:aws:batch:us-east-1:012345678910:compute-environment/C4OnDemand", "order": 1 } ], "statusReason": "JobQueue Healthy", "priority": 1, "state": "ENABLED", "jobQueueName": "HighPriority" } ] }
Java
SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

/** * Asynchronously describes the job queue associated with the specified compute environment. * * @param computeEnvironmentName the name of the compute environment to find the associated job queue for * @return a {@link CompletableFuture} that, when completed, contains the job queue ARN associated with the specified compute environment * @throws RuntimeException if the job queue description fails */ public CompletableFuture<String> describeJobQueueAsync(String computeEnvironmentName) { DescribeJobQueuesRequest describeJobQueuesRequest = DescribeJobQueuesRequest.builder() .build(); CompletableFuture<DescribeJobQueuesResponse> responseFuture = getAsyncClient().describeJobQueues(describeJobQueuesRequest); return responseFuture.whenComplete((describeJobQueuesResponse, ex) -> { if (describeJobQueuesResponse != null) { String jobQueueARN; for (JobQueueDetail jobQueueDetail : describeJobQueuesResponse.jobQueues()) { for (ComputeEnvironmentOrder computeEnvironmentOrder : jobQueueDetail.computeEnvironmentOrder()) { String computeEnvironment = computeEnvironmentOrder.computeEnvironment(); String name = getComputeEnvironmentName(computeEnvironment); if (name.equals(computeEnvironmentName)) { jobQueueARN = jobQueueDetail.jobQueueArn(); logger.info("Job queue ARN associated with the compute environment: " + jobQueueARN); } } } } else { throw new RuntimeException("Failed to describe job queue: " + ex.getMessage(), ex); } }).thenApply(describeJobQueuesResponse -> { String jobQueueARN = ""; for (JobQueueDetail jobQueueDetail : describeJobQueuesResponse.jobQueues()) { for (ComputeEnvironmentOrder computeEnvironmentOrder : jobQueueDetail.computeEnvironmentOrder()) { String computeEnvironment = computeEnvironmentOrder.computeEnvironment(); String name = getComputeEnvironmentName(computeEnvironment); if (name.equals(computeEnvironmentName)) { jobQueueARN = jobQueueDetail.jobQueueArn(); } } } return jobQueueARN; }); }
  • 有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 DescribeJobQueues” 中的。