Skip to content

Commit

Permalink
samples: fix: small updates to dataproc sample, test and pom (#1738)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bradmiro authored and chingor13 committed Aug 3, 2020
1 parent 0baedc3 commit 1d2fb6b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 4 additions & 5 deletions dataproc/snippets/src/main/java/CreateCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

// [START create_cluster]
// [START dataproc_create_cluster]
import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.dataproc.v1.Cluster;
import com.google.cloud.dataproc.v1.ClusterConfig;
Expand All @@ -23,7 +23,6 @@
import com.google.cloud.dataproc.v1.ClusterOperationMetadata;
import com.google.cloud.dataproc.v1.InstanceGroupConfig;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.concurrent.ExecutionException;

public class CreateCluster {
Expand Down Expand Up @@ -60,12 +59,12 @@ public static void createCluster(String projectId, String region, String cluster
.setConfig(clusterConfig)
.build();

// Send a request to create a Dataproc cluster.
// Create the Cloud Dataproc cluster
OperationFuture<Cluster, ClusterOperationMetadata> createClusterAsyncRequest =
clusterControllerClient.createClusterAsync(projectId, region, cluster);
Cluster response = createClusterAsyncRequest.get();

// Print out the response
// Print out a success message
System.out.println(
String.format("Cluster created successfully: %s", response.getClusterName())
);
Expand All @@ -81,4 +80,4 @@ public static void createCluster(String projectId, String region, String cluster
}
}
}
// [END create_cluster]
// [END dataproc_create_cluster]
8 changes: 7 additions & 1 deletion dataproc/snippets/src/test/java/CreateClusterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.dataproc.v1.ClusterControllerClient;
import com.google.cloud.dataproc.v1.ClusterControllerSettings;
import com.google.cloud.dataproc.v1.ClusterOperationMetadata;
import com.google.protobuf.Empty;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -75,8 +76,13 @@ public void createClusterTest() throws IOException, InterruptedException {

@After
public void tearDown() throws IOException, InterruptedException {
String myEndpoint = String.format("%s-dataproc.googleapis.com:443", REGION);

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

try (ClusterControllerClient clusterControllerClient = ClusterControllerClient
.create()) {
.create(clusterControllerSettings)) {
OperationFuture<Empty, ClusterOperationMetadata> deleteClusterAsyncRequest =
clusterControllerClient.deleteClusterAsync(projectId, REGION, clusterName);
deleteClusterAsyncRequest.get();
Expand Down

0 comments on commit 1d2fb6b

Please sign in to comment.