Skip to content

Commit 1d2fb6b

Browse files
bradmirochingor13
authored andcommitted
samples: fix: small updates to dataproc sample, test and pom (#1738)
* refactored and added tags to infinite speech streaming sample (#1605) * Changed 'main' region tag * Removed extra lines around tags and changed client import to v1 * Create dataproc directory and add CreateCluster sample * reverting changes to speech infinite streaming sample * Added java versions to pom * Several changes to file formatting as per request in the PR * Added comments to exceptions in CreateCluster, expanded exceptions and femoved endpoint configuring in CreateClusterTest.java * Fixed version for parent config * Added clarity to futures requests by expanding variables * Fixed linting errors * Fixed import ordering * Moved exceptions to function level in dataproc create cluster sample + test * Re-added endpoint to test, changed region tags to include 'dataproc', slight mod to pom * fix to pom
1 parent 0baedc3 commit 1d2fb6b

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

dataproc/snippets/src/main/java/CreateCluster.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
// [START create_cluster]
17+
// [START dataproc_create_cluster]
1818
import com.google.api.gax.longrunning.OperationFuture;
1919
import com.google.cloud.dataproc.v1.Cluster;
2020
import com.google.cloud.dataproc.v1.ClusterConfig;
@@ -23,7 +23,6 @@
2323
import com.google.cloud.dataproc.v1.ClusterOperationMetadata;
2424
import com.google.cloud.dataproc.v1.InstanceGroupConfig;
2525
import java.io.IOException;
26-
import java.io.InterruptedIOException;
2726
import java.util.concurrent.ExecutionException;
2827

2928
public class CreateCluster {
@@ -60,12 +59,12 @@ public static void createCluster(String projectId, String region, String cluster
6059
.setConfig(clusterConfig)
6160
.build();
6261

63-
// Send a request to create a Dataproc cluster.
62+
// Create the Cloud Dataproc cluster
6463
OperationFuture<Cluster, ClusterOperationMetadata> createClusterAsyncRequest =
6564
clusterControllerClient.createClusterAsync(projectId, region, cluster);
6665
Cluster response = createClusterAsyncRequest.get();
6766

68-
// Print out the response
67+
// Print out a success message
6968
System.out.println(
7069
String.format("Cluster created successfully: %s", response.getClusterName())
7170
);
@@ -81,4 +80,4 @@ public static void createCluster(String projectId, String region, String cluster
8180
}
8281
}
8382
}
84-
// [END create_cluster]
83+
// [END dataproc_create_cluster]

dataproc/snippets/src/test/java/CreateClusterTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.google.api.gax.longrunning.OperationFuture;
2121
import com.google.cloud.dataproc.v1.ClusterControllerClient;
22+
import com.google.cloud.dataproc.v1.ClusterControllerSettings;
2223
import com.google.cloud.dataproc.v1.ClusterOperationMetadata;
2324
import com.google.protobuf.Empty;
2425
import java.io.ByteArrayOutputStream;
@@ -75,8 +76,13 @@ public void createClusterTest() throws IOException, InterruptedException {
7576

7677
@After
7778
public void tearDown() throws IOException, InterruptedException {
79+
String myEndpoint = String.format("%s-dataproc.googleapis.com:443", REGION);
80+
81+
ClusterControllerSettings clusterControllerSettings =
82+
ClusterControllerSettings.newBuilder().setEndpoint(myEndpoint).build();
83+
7884
try (ClusterControllerClient clusterControllerClient = ClusterControllerClient
79-
.create()) {
85+
.create(clusterControllerSettings)) {
8086
OperationFuture<Empty, ClusterOperationMetadata> deleteClusterAsyncRequest =
8187
clusterControllerClient.deleteClusterAsync(projectId, REGION, clusterName);
8288
deleteClusterAsyncRequest.get();

0 commit comments

Comments
 (0)