使用java代码向dataproc集群添加标签

ltskdhd1  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(324)

我是gcp的新手,目前我正在寻找使用java创建dataproc集群,并为其添加某些标签。
对于集群创建,我使用以下代码:

String clusterName = "XXXXXX";
    String projectId   = "YYYYYY";
    String region      = "us-central1";

    String myEndpoint = String.format("%s-dataproc.googleapis.com:443", region);

    ClusterControllerSettings clusterControllerSettings = ClusterControllerSettings.newBuilder()
            .setEndpoint(myEndpoint).build();

    ClusterControllerClient clusterControllerClient = ClusterControllerClient
            .create(clusterControllerSettings);

        InstanceGroupConfig masterConfig = InstanceGroupConfig.newBuilder().setMachineTypeUri("n1-standard-1")
                .setNumInstances(1).build();
        InstanceGroupConfig workerConfig = InstanceGroupConfig.newBuilder().setMachineTypeUri("n1-standard-1")
                .setNumInstances(2).build();
        ClusterConfig clusterConfig = ClusterConfig.newBuilder()
                .setMasterConfig(masterConfig).setWorkerConfig(workerConfig).build();

        Cluster cluster = Cluster.newBuilder().setClusterName(clusterName).setConfig(clusterConfig).build();

        OperationFuture<Cluster, ClusterOperationMetadata> createClusterAsyncRequest = clusterControllerClient
                .createClusterAsync(projectId, region, cluster);
        Cluster response = createClusterAsyncRequest.get();

集群创建工作正常。但是我不能在使用java代码创建集群的过程中添加标签。有什么建议吗?
gcp控制台的标签看起来像this:labels

lskq00tm

lskq00tm1#

javaapi已经支持这一点了。我相信你可以按照这里的建议给集群添加标签

相关问题