如何使用 Java 客户端 SDK 列出所有正在运行的 GCP Dataflow 作业

问题描述 投票:0回答:1

我想知道是否可以使用 Java 客户端 SDK 列出所有正在运行的数据流作业。

我想我可能需要使用:

JobsV1Beta3Client jobsV1Beta3Client = JobsV1Beta3Client.create();
jobsV1Beta3Client.listJobs(...)

但我不知道应该在 listJobs 方法中放入什么。

java google-cloud-dataflow
1个回答
1
投票

您可以参考这些 Dataflow 代码示例,因为它演示了如何列出作业。

import com.google.dataflow.v1beta3.Job;
import com.google.dataflow.v1beta3.JobView;
import com.google.dataflow.v1beta3.JobsV1Beta3Client;
import com.google.dataflow.v1beta3.ListJobsRequest;

public class SyncListJobs {

  public static void main(String[] args) throws Exception {
    syncListJobs();
  }

  public static void syncListJobs() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (JobsV1Beta3Client jobsV1Beta3Client = JobsV1Beta3Client.create()) {
      ListJobsRequest request =
          ListJobsRequest.newBuilder()
              .setProjectId("projectId-894832108")
              .setView(JobView.forNumber(0))
              .setPageSize(883849137)
              .setPageToken("pageToken873572522")
              .setLocation("location1901043637")
              .build();
      for (Job element : jobsV1Beta3Client.listJobs(request).iterateAll()) {
        // doThingsWith(element);
      }
    }
  }
}
import com.google.api.core.ApiFuture;
import com.google.dataflow.v1beta3.Job;
import com.google.dataflow.v1beta3.JobView;
import com.google.dataflow.v1beta3.JobsV1Beta3Client;
import com.google.dataflow.v1beta3.ListJobsRequest;

public class AsyncListJobs {

  public static void main(String[] args) throws Exception {
    asyncListJobs();
  }

  public static void asyncListJobs() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (JobsV1Beta3Client jobsV1Beta3Client = JobsV1Beta3Client.create()) {
      ListJobsRequest request =
          ListJobsRequest.newBuilder()
              .setProjectId("projectId-894832108")
              .setView(JobView.forNumber(0))
              .setPageSize(883849137)
              .setPageToken("pageToken873572522")
              .setLocation("location1901043637")
              .build();
      ApiFuture<Job> future = jobsV1Beta3Client.listJobsPagedCallable().futureCall(request);
      // Do something.
      for (Job element : future.get().iterateAll()) {
        // doThingsWith(element);
      }
    }
  }
}

我还发现了一些可以提供帮助的旧帖子:

© www.soinside.com 2019 - 2024. All rights reserved.