2
votes

I am new to GCP and currently i am looking to create a Dataproc Cluster using Java and add certain labels to it.

For cluster creation, i am using the following code:

    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();

Cluster creation is working fine. But i am not able to add labels to the cluster during creation using java code. Any suggestions?

Labels from GCP Console looks like this:labels

1
Please ask the Developers to introduce add label options in java-dataprocMahboob

1 Answers

1
votes

Java API already supports that. I believe you can add label to the cluster as suggested here