From 0392815c0894107ce56086e6587048143085c51b Mon Sep 17 00:00:00 2001 From: Brad Miro Date: Mon, 7 Oct 2019 18:05:51 -0400 Subject: [PATCH 01/15] refactored and added tags to infinite speech streaming sample (#1605) --- .../speech/InfiniteStreamRecognize.java | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/speech/cloud-client/src/main/java/com/example/speech/InfiniteStreamRecognize.java b/speech/cloud-client/src/main/java/com/example/speech/InfiniteStreamRecognize.java index fd4d460ddff..b49d52e5497 100644 --- a/speech/cloud-client/src/main/java/com/example/speech/InfiniteStreamRecognize.java +++ b/speech/cloud-client/src/main/java/com/example/speech/InfiniteStreamRecognize.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Google LLC + * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package com.example.speech; -// [START speech_transcribe_infinite_streaming] +// [START speech_transcribe_infinite_streaming_imports] import com.google.api.gax.rpc.ClientStream; import com.google.api.gax.rpc.ResponseObserver; @@ -43,13 +43,13 @@ import javax.sound.sampled.DataLine.Info; import javax.sound.sampled.TargetDataLine; +// [END speech_transcribe_infinite_streaming_imports] + public class InfiniteStreamRecognize { - private static final int STREAMING_LIMIT = 290000; // ~5 minutes +// [START speech_transcribe_infinite_streaming_globals] - public static final String RED = "\033[0;31m"; - public static final String GREEN = "\033[0;32m"; - public static final String YELLOW = "\033[0;33m"; + private static final int STREAMING_LIMIT = 290000; // ~5 minutes // Creating shared object private static volatile BlockingQueue sharedQueue = new LinkedBlockingQueue(); @@ -68,6 +68,19 @@ public class InfiniteStreamRecognize { private static StreamController referenceToStreamController; private static ByteString tempByteString; +// [END speech_transcribe_infinite_streaming_globals] + + public static String convertMillisToDate(double milliSeconds) { + long millis = (long) milliSeconds; + DecimalFormat format = new DecimalFormat(); + format.setMinimumIntegerDigits(2); + return String.format("%s:%s /", + format.format(TimeUnit.MILLISECONDS.toMinutes(millis)), + format.format(TimeUnit.MILLISECONDS.toSeconds(millis) + - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))) + ); + } +// [START speech_transcribe_infinite_streaming_main] public static void main(String... args) { InfiniteStreamRecognizeOptions options = InfiniteStreamRecognizeOptions.fromFlags(args); if (options == null) { @@ -82,17 +95,7 @@ public static void main(String... args) { System.out.println("Exception caught: " + e); } } - - public static String convertMillisToDate(double milliSeconds) { - long millis = (long) milliSeconds; - DecimalFormat format = new DecimalFormat(); - format.setMinimumIntegerDigits(2); - return String.format("%s:%s /", - format.format(TimeUnit.MILLISECONDS.toMinutes(millis)), - format.format(TimeUnit.MILLISECONDS.toSeconds(millis) - - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))) - ); - } +// [END speech_transcribe_infinite_streaming_main] /** Performs infinite streaming speech recognition */ public static void infiniteStreamingRecognize(String languageCode) throws Exception { @@ -102,7 +105,6 @@ class MicBuffer implements Runnable { @Override public void run() { - System.out.println(YELLOW); System.out.println("Start speaking...Press Ctrl-C to stop"); targetDataLine.start(); byte[] data = new byte[BYTES_PER_BUFFER]; @@ -134,7 +136,8 @@ public void run() { public void onStart(StreamController controller) { referenceToStreamController = controller; } - + + // [START speech_transcribe_infinite_streaming_output] public void onResponse(StreamingRecognizeResponse response) { responses.add(response); StreamingRecognitionResult result = response.getResultsList().get(0); @@ -146,8 +149,6 @@ public void onResponse(StreamingRecognizeResponse response) { SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); if (result.getIsFinal()) { - System.out.print(GREEN); - System.out.print("\033[2K\r"); System.out.printf("%s: %s [confidence: %.2f]\n", convertMillisToDate(correctedTime), alternative.getTranscript(), @@ -156,15 +157,13 @@ public void onResponse(StreamingRecognizeResponse response) { isFinalEndTime = resultEndTimeInMS; lastTranscriptWasFinal = true; } else { - System.out.print(RED); - System.out.print("\033[2K\r"); System.out.printf("%s: %s", convertMillisToDate(correctedTime), alternative.getTranscript() ); lastTranscriptWasFinal = false; } } - + // [END speech_transcribe_infinite_streaming_output] public void onComplete() { } @@ -213,6 +212,8 @@ public void onError(Throwable t) { micThread.start(); long startTime = System.currentTimeMillis(); + + // [START speech_transcribe_infinite_streaming_generator] while (true) { @@ -247,7 +248,6 @@ public void onError(Throwable t) { .setStreamingConfig(streamingRecognitionConfig) .build(); - System.out.println(YELLOW); System.out.printf("%d: RESTARTING REQUEST\n", restartCounter * STREAMING_LIMIT); startTime = System.currentTimeMillis(); @@ -296,7 +296,7 @@ public void onError(Throwable t) { audioInput.add(tempByteString); } - + // [END speech_transcribe_infinite_streaming_generator] clientStream.send(request); } } catch (Exception e) { @@ -306,4 +306,3 @@ public void onError(Throwable t) { } } -// [END speech_transcribe_infinite_streaming] From 0078c4a4752b0b814c467c9ce7c2f5b2eec1cbcd Mon Sep 17 00:00:00 2001 From: bradmiro Date: Thu, 10 Oct 2019 11:53:15 -0400 Subject: [PATCH 02/15] Changed 'main' region tag --- .../java/com/example/speech/InfiniteStreamRecognize.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/speech/cloud-client/src/main/java/com/example/speech/InfiniteStreamRecognize.java b/speech/cloud-client/src/main/java/com/example/speech/InfiniteStreamRecognize.java index b49d52e5497..0ce6e46ec07 100644 --- a/speech/cloud-client/src/main/java/com/example/speech/InfiniteStreamRecognize.java +++ b/speech/cloud-client/src/main/java/com/example/speech/InfiniteStreamRecognize.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Google LLC + * Copyright 2018 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -95,7 +95,6 @@ public static void main(String... args) { System.out.println("Exception caught: " + e); } } -// [END speech_transcribe_infinite_streaming_main] /** Performs infinite streaming speech recognition */ public static void infiniteStreamingRecognize(String languageCode) throws Exception { @@ -121,6 +120,7 @@ public void run() { } } } + // Creating microphone input buffer thread MicBuffer micrunnable = new MicBuffer(); @@ -136,7 +136,8 @@ public void run() { public void onStart(StreamController controller) { referenceToStreamController = controller; } - +// [END speech_transcribe_infinite_streaming_main] + // [START speech_transcribe_infinite_streaming_output] public void onResponse(StreamingRecognizeResponse response) { responses.add(response); From a69558d15218f73cca468ebcc2ac3099602c7dd6 Mon Sep 17 00:00:00 2001 From: bradmiro Date: Tue, 15 Oct 2019 15:46:39 +0200 Subject: [PATCH 03/15] Removed extra lines around tags and changed client import to v1 --- .../speech/InfiniteStreamRecognize.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/speech/cloud-client/src/main/java/com/example/speech/InfiniteStreamRecognize.java b/speech/cloud-client/src/main/java/com/example/speech/InfiniteStreamRecognize.java index 0ce6e46ec07..00f51fa25a2 100644 --- a/speech/cloud-client/src/main/java/com/example/speech/InfiniteStreamRecognize.java +++ b/speech/cloud-client/src/main/java/com/example/speech/InfiniteStreamRecognize.java @@ -17,17 +17,16 @@ package com.example.speech; // [START speech_transcribe_infinite_streaming_imports] - import com.google.api.gax.rpc.ClientStream; import com.google.api.gax.rpc.ResponseObserver; import com.google.api.gax.rpc.StreamController; -import com.google.cloud.speech.v1p1beta1.RecognitionConfig; -import com.google.cloud.speech.v1p1beta1.SpeechClient; -import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1p1beta1.StreamingRecognitionConfig; -import com.google.cloud.speech.v1p1beta1.StreamingRecognitionResult; -import com.google.cloud.speech.v1p1beta1.StreamingRecognizeRequest; -import com.google.cloud.speech.v1p1beta1.StreamingRecognizeResponse; +import com.google.cloud.speech.v1.RecognitionConfig; +import com.google.cloud.speech.v1.SpeechClient; +import com.google.cloud.speech.v1.SpeechRecognitionAlternative; +import com.google.cloud.speech.v1.StreamingRecognitionConfig; +import com.google.cloud.speech.v1.StreamingRecognitionResult; +import com.google.cloud.speech.v1.StreamingRecognizeRequest; +import com.google.cloud.speech.v1.StreamingRecognizeResponse; import com.google.protobuf.ByteString; import com.google.protobuf.Duration; @@ -42,13 +41,11 @@ import javax.sound.sampled.DataLine; import javax.sound.sampled.DataLine.Info; import javax.sound.sampled.TargetDataLine; - // [END speech_transcribe_infinite_streaming_imports] public class InfiniteStreamRecognize { // [START speech_transcribe_infinite_streaming_globals] - private static final int STREAMING_LIMIT = 290000; // ~5 minutes // Creating shared object @@ -67,7 +64,6 @@ public class InfiniteStreamRecognize { private static boolean lastTranscriptWasFinal = false; private static StreamController referenceToStreamController; private static ByteString tempByteString; - // [END speech_transcribe_infinite_streaming_globals] public static String convertMillisToDate(double milliSeconds) { @@ -215,7 +211,6 @@ public void onError(Throwable t) { long startTime = System.currentTimeMillis(); // [START speech_transcribe_infinite_streaming_generator] - while (true) { long estimatedTime = System.currentTimeMillis() - startTime; From 69eeae6fd6b9f31a73adb25e6b185b34d623d5ea Mon Sep 17 00:00:00 2001 From: bradmiro Date: Wed, 13 Nov 2019 19:11:05 -0500 Subject: [PATCH 04/15] Create dataproc directory and add CreateCluster sample --- dataproc/pom.xml | 45 +++++++++ dataproc/src/main/java/CreateCluster.java | 63 +++++++++++++ dataproc/src/test/java/CreateClusterTest.java | 93 +++++++++++++++++++ 3 files changed, 201 insertions(+) create mode 100644 dataproc/pom.xml create mode 100644 dataproc/src/main/java/CreateCluster.java create mode 100644 dataproc/src/test/java/CreateClusterTest.java diff --git a/dataproc/pom.xml b/dataproc/pom.xml new file mode 100644 index 00000000000..5ad4603aa99 --- /dev/null +++ b/dataproc/pom.xml @@ -0,0 +1,45 @@ + + + 4.0.0 + + com.example + dataproc + 1.0-SNAPSHOT + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + UTF-8 + -Xlint:unchecked + -Xlint:deprecation + true + + + + + + + + + + junit + junit + 4.13-beta-2 + + + com.google.cloud + google-cloud-dataproc + 0.117.0 + + + + \ No newline at end of file diff --git a/dataproc/src/main/java/CreateCluster.java b/dataproc/src/main/java/CreateCluster.java new file mode 100644 index 00000000000..c298661c1ef --- /dev/null +++ b/dataproc/src/main/java/CreateCluster.java @@ -0,0 +1,63 @@ +/* + * Copyright 2019 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [START create_cluster] +import com.google.cloud.dataproc.v1.Cluster; +import com.google.cloud.dataproc.v1.ClusterConfig; +import com.google.cloud.dataproc.v1.ClusterControllerClient; +import com.google.cloud.dataproc.v1.ClusterControllerSettings; +import com.google.cloud.dataproc.v1.InstanceGroupConfig; +import java.io.IOException; + +public class CreateCluster { + + public void createCluster(String projectId, String region, String clusterName) + throws IOException { + + String myEndpoint = String.format("%s-dataproc.googleapis.com:443", region); + + // Configure the settings for the cluster controller client + ClusterControllerSettings clusterControllerSettings = + ClusterControllerSettings.newBuilder().setEndpoint(myEndpoint).build(); + + // Create a cluster controller client with the configured settings + try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create(clusterControllerSettings)) { + + // Configure the settings for our cluster + 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(); + + // Create the cluster object with the desired cluster config + Cluster cluster = Cluster.newBuilder().setClusterName(clusterName).setConfig(clusterConfig).build(); + + // Create the cluster + Cluster response = clusterControllerClient.createClusterAsync(projectId, region, cluster).get(); + + // Print out the response + System.out.println(response); + + } catch (Exception e) { + System.out.println("Error during cluster creation connection: \n" + e.toString()); + } + } +} +// [END create_cluster] \ No newline at end of file diff --git a/dataproc/src/test/java/CreateClusterTest.java b/dataproc/src/test/java/CreateClusterTest.java new file mode 100644 index 00000000000..60c963bfbbc --- /dev/null +++ b/dataproc/src/test/java/CreateClusterTest.java @@ -0,0 +1,93 @@ +/* + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import static junit.framework.TestCase.assertNotNull; +import static org.hamcrest.MatcherAssert.assertThat; + +import com.google.cloud.dataproc.v1.ClusterControllerClient; +import com.google.cloud.dataproc.v1.ClusterControllerSettings; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; +import org.hamcrest.CoreMatchers; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class CreateClusterTest { + + private static final String BASE_CLUSTER_NAME = "test-cluster"; + private static final String REGION = "us-central1"; + + private static String projectId; + private String clusterName; + private ByteArrayOutputStream bout; + + private static void requireEnv(String varName) { + assertNotNull( + System.getenv(varName), + "Environment variable '%s' is required to perform these tests.".format(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnv("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnv("GOOGLE_CLOUD_PROJECT"); + projectId = System.getenv("GOOGLE_CLOUD_PROJECT"); + System.out.println(String.format("projectId - %s", projectId)); + } + + @Before + public void setUp(){ + clusterName = String.format("%s-%s", BASE_CLUSTER_NAME, UUID.randomUUID().toString()); + + bout = new ByteArrayOutputStream(); + System.setOut(new PrintStream(bout)); + } + + @Test + public void createClusterTest() throws Exception { + CreateCluster createCluster = new CreateCluster(); + + createCluster.createCluster(projectId, REGION, clusterName); + String output = bout.toString(); + + assertThat(output, CoreMatchers.containsString("cluster-uuid")); + } + + @After + public void tearDown() throws IOException { + String myEndpoint = String.format("%s-dataproc.googleapis.com:443", REGION); + + ClusterControllerSettings clusterControllerSettings = + ClusterControllerSettings.newBuilder().setEndpoint(myEndpoint).build(); + + try (ClusterControllerClient clusterControllerClient = + ClusterControllerClient.create(clusterControllerSettings)) { + + clusterControllerClient.deleteClusterAsync(projectId, REGION, clusterName).get(); + + } catch (Exception e) { + System.out.println("Error during cluster deletion: \n" + e.toString()); + } + } + +} From de1aa3ddf5ee4c18ddc15a607f733657c129a452 Mon Sep 17 00:00:00 2001 From: bradmiro Date: Wed, 13 Nov 2019 19:14:56 -0500 Subject: [PATCH 05/15] reverting changes to speech infinite streaming sample --- .../speech/InfiniteStreamRecognize.java | 63 ++++++++++--------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/speech/cloud-client/src/main/java/com/example/speech/InfiniteStreamRecognize.java b/speech/cloud-client/src/main/java/com/example/speech/InfiniteStreamRecognize.java index 00f51fa25a2..fd4d460ddff 100644 --- a/speech/cloud-client/src/main/java/com/example/speech/InfiniteStreamRecognize.java +++ b/speech/cloud-client/src/main/java/com/example/speech/InfiniteStreamRecognize.java @@ -16,17 +16,18 @@ package com.example.speech; -// [START speech_transcribe_infinite_streaming_imports] +// [START speech_transcribe_infinite_streaming] + import com.google.api.gax.rpc.ClientStream; import com.google.api.gax.rpc.ResponseObserver; import com.google.api.gax.rpc.StreamController; -import com.google.cloud.speech.v1.RecognitionConfig; -import com.google.cloud.speech.v1.SpeechClient; -import com.google.cloud.speech.v1.SpeechRecognitionAlternative; -import com.google.cloud.speech.v1.StreamingRecognitionConfig; -import com.google.cloud.speech.v1.StreamingRecognitionResult; -import com.google.cloud.speech.v1.StreamingRecognizeRequest; -import com.google.cloud.speech.v1.StreamingRecognizeResponse; +import com.google.cloud.speech.v1p1beta1.RecognitionConfig; +import com.google.cloud.speech.v1p1beta1.SpeechClient; +import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative; +import com.google.cloud.speech.v1p1beta1.StreamingRecognitionConfig; +import com.google.cloud.speech.v1p1beta1.StreamingRecognitionResult; +import com.google.cloud.speech.v1p1beta1.StreamingRecognizeRequest; +import com.google.cloud.speech.v1p1beta1.StreamingRecognizeResponse; import com.google.protobuf.ByteString; import com.google.protobuf.Duration; @@ -41,13 +42,15 @@ import javax.sound.sampled.DataLine; import javax.sound.sampled.DataLine.Info; import javax.sound.sampled.TargetDataLine; -// [END speech_transcribe_infinite_streaming_imports] public class InfiniteStreamRecognize { -// [START speech_transcribe_infinite_streaming_globals] private static final int STREAMING_LIMIT = 290000; // ~5 minutes + public static final String RED = "\033[0;31m"; + public static final String GREEN = "\033[0;32m"; + public static final String YELLOW = "\033[0;33m"; + // Creating shared object private static volatile BlockingQueue sharedQueue = new LinkedBlockingQueue(); private static TargetDataLine targetDataLine; @@ -64,19 +67,7 @@ public class InfiniteStreamRecognize { private static boolean lastTranscriptWasFinal = false; private static StreamController referenceToStreamController; private static ByteString tempByteString; -// [END speech_transcribe_infinite_streaming_globals] - public static String convertMillisToDate(double milliSeconds) { - long millis = (long) milliSeconds; - DecimalFormat format = new DecimalFormat(); - format.setMinimumIntegerDigits(2); - return String.format("%s:%s /", - format.format(TimeUnit.MILLISECONDS.toMinutes(millis)), - format.format(TimeUnit.MILLISECONDS.toSeconds(millis) - - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))) - ); - } -// [START speech_transcribe_infinite_streaming_main] public static void main(String... args) { InfiniteStreamRecognizeOptions options = InfiniteStreamRecognizeOptions.fromFlags(args); if (options == null) { @@ -92,6 +83,17 @@ public static void main(String... args) { } } + public static String convertMillisToDate(double milliSeconds) { + long millis = (long) milliSeconds; + DecimalFormat format = new DecimalFormat(); + format.setMinimumIntegerDigits(2); + return String.format("%s:%s /", + format.format(TimeUnit.MILLISECONDS.toMinutes(millis)), + format.format(TimeUnit.MILLISECONDS.toSeconds(millis) + - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))) + ); + } + /** Performs infinite streaming speech recognition */ public static void infiniteStreamingRecognize(String languageCode) throws Exception { @@ -100,6 +102,7 @@ class MicBuffer implements Runnable { @Override public void run() { + System.out.println(YELLOW); System.out.println("Start speaking...Press Ctrl-C to stop"); targetDataLine.start(); byte[] data = new byte[BYTES_PER_BUFFER]; @@ -116,7 +119,6 @@ public void run() { } } } - // Creating microphone input buffer thread MicBuffer micrunnable = new MicBuffer(); @@ -132,9 +134,7 @@ public void run() { public void onStart(StreamController controller) { referenceToStreamController = controller; } -// [END speech_transcribe_infinite_streaming_main] - // [START speech_transcribe_infinite_streaming_output] public void onResponse(StreamingRecognizeResponse response) { responses.add(response); StreamingRecognitionResult result = response.getResultsList().get(0); @@ -146,6 +146,8 @@ public void onResponse(StreamingRecognizeResponse response) { SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); if (result.getIsFinal()) { + System.out.print(GREEN); + System.out.print("\033[2K\r"); System.out.printf("%s: %s [confidence: %.2f]\n", convertMillisToDate(correctedTime), alternative.getTranscript(), @@ -154,13 +156,15 @@ public void onResponse(StreamingRecognizeResponse response) { isFinalEndTime = resultEndTimeInMS; lastTranscriptWasFinal = true; } else { + System.out.print(RED); + System.out.print("\033[2K\r"); System.out.printf("%s: %s", convertMillisToDate(correctedTime), alternative.getTranscript() ); lastTranscriptWasFinal = false; } } - // [END speech_transcribe_infinite_streaming_output] + public void onComplete() { } @@ -209,8 +213,7 @@ public void onError(Throwable t) { micThread.start(); long startTime = System.currentTimeMillis(); - - // [START speech_transcribe_infinite_streaming_generator] + while (true) { long estimatedTime = System.currentTimeMillis() - startTime; @@ -244,6 +247,7 @@ public void onError(Throwable t) { .setStreamingConfig(streamingRecognitionConfig) .build(); + System.out.println(YELLOW); System.out.printf("%d: RESTARTING REQUEST\n", restartCounter * STREAMING_LIMIT); startTime = System.currentTimeMillis(); @@ -292,7 +296,7 @@ public void onError(Throwable t) { audioInput.add(tempByteString); } - // [END speech_transcribe_infinite_streaming_generator] + clientStream.send(request); } } catch (Exception e) { @@ -302,3 +306,4 @@ public void onError(Throwable t) { } } +// [END speech_transcribe_infinite_streaming] From 73f3116666f80b854a836bbf056eb6b6de86c6ff Mon Sep 17 00:00:00 2001 From: bradmiro Date: Thu, 14 Nov 2019 15:13:50 -0500 Subject: [PATCH 06/15] Added java versions to pom --- dataproc/pom.xml | 5 +++++ dataproc/src/test/java/CreateClusterTest.java | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dataproc/pom.xml b/dataproc/pom.xml index 5ad4603aa99..ccbdf7dd21d 100644 --- a/dataproc/pom.xml +++ b/dataproc/pom.xml @@ -8,6 +8,11 @@ dataproc 1.0-SNAPSHOT + + 1.8 + 1.8 + + diff --git a/dataproc/src/test/java/CreateClusterTest.java b/dataproc/src/test/java/CreateClusterTest.java index 60c963bfbbc..0442ba4fbda 100644 --- a/dataproc/src/test/java/CreateClusterTest.java +++ b/dataproc/src/test/java/CreateClusterTest.java @@ -44,7 +44,8 @@ public class CreateClusterTest { private static void requireEnv(String varName) { assertNotNull( System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); + String.format("Environment variable '%s' is required to perform these tests.", varName) + ); } @BeforeClass @@ -83,7 +84,7 @@ public void tearDown() throws IOException { try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create(clusterControllerSettings)) { - clusterControllerClient.deleteClusterAsync(projectId, REGION, clusterName).get(); + clusterControllerClient.deleteClusterAsync(projectId, REGION, clusterName).get(); } catch (Exception e) { System.out.println("Error during cluster deletion: \n" + e.toString()); From 6cfccf69beb9eb4d0f919620b2730811bbb02eb6 Mon Sep 17 00:00:00 2001 From: bradmiro Date: Fri, 15 Nov 2019 13:33:27 -0500 Subject: [PATCH 07/15] Several changes to file formatting as per request in the PR --- dataproc/pom.xml | 21 ++++---- dataproc/src/main/java/CreateCluster.java | 53 ++++++++++++------- dataproc/src/test/java/CreateClusterTest.java | 19 +++---- 3 files changed, 52 insertions(+), 41 deletions(-) diff --git a/dataproc/pom.xml b/dataproc/pom.xml index ccbdf7dd21d..40067e1acd4 100644 --- a/dataproc/pom.xml +++ b/dataproc/pom.xml @@ -8,9 +8,20 @@ dataproc 1.0-SNAPSHOT + + + com.google.cloud.samples + shared-configuration + SPECIFY_LATEST_VERSION + + 1.8 1.8 + UTF-8 @@ -20,14 +31,6 @@ org.apache.maven.plugins maven-compiler-plugin 3.8.1 - - 1.8 - 1.8 - UTF-8 - -Xlint:unchecked - -Xlint:deprecation - true - @@ -38,7 +41,7 @@ junit junit - 4.13-beta-2 + 4.12 com.google.cloud diff --git a/dataproc/src/main/java/CreateCluster.java b/dataproc/src/main/java/CreateCluster.java index c298661c1ef..4382af2adcb 100644 --- a/dataproc/src/main/java/CreateCluster.java +++ b/dataproc/src/main/java/CreateCluster.java @@ -15,48 +15,63 @@ */ // [START create_cluster] +import com.google.api.core.ApiFuture; import com.google.cloud.dataproc.v1.Cluster; import com.google.cloud.dataproc.v1.ClusterConfig; import com.google.cloud.dataproc.v1.ClusterControllerClient; import com.google.cloud.dataproc.v1.ClusterControllerSettings; +import com.google.cloud.dataproc.v1.ClusterOperationMetadata; import com.google.cloud.dataproc.v1.InstanceGroupConfig; +import com.google.api.gax.longrunning.OperationFuture; import java.io.IOException; +import java.util.concurrent.ExecutionException; public class CreateCluster { - public void createCluster(String projectId, String region, String clusterName) + public static void createCluster(String projectId, String region, String clusterName) throws IOException { - String myEndpoint = String.format("%s-dataproc.googleapis.com:443", region); // Configure the settings for the cluster controller client ClusterControllerSettings clusterControllerSettings = ClusterControllerSettings.newBuilder().setEndpoint(myEndpoint).build(); - // Create a cluster controller client with the configured settings - try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create(clusterControllerSettings)) { - + // Create a cluster controller client with the configured settings. We only need to create + // the client once, and can be reused for multiple requests. Using a try-with-resources + // will close the client for us, but this can also be done manually with the .close() method. + try (ClusterControllerClient clusterControllerClient = ClusterControllerClient + .create(clusterControllerSettings)) { // Configure the settings for our cluster - 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(); - + 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(); // Create the cluster object with the desired cluster config - Cluster cluster = Cluster.newBuilder().setClusterName(clusterName).setConfig(clusterConfig).build(); + Cluster cluster = Cluster.newBuilder() + .setClusterName(clusterName) + .setConfig(clusterConfig) + .build(); - // Create the cluster + // Create a request to create a Dataproc cluster. Cluster response = clusterControllerClient.createClusterAsync(projectId, region, cluster).get(); // Print out the response - System.out.println(response); + System.out.println( + String.format("Cluster created successfully: %s", response.getClusterName()) + ); - } catch (Exception e) { - System.out.println("Error during cluster creation connection: \n" + e.toString()); + } catch (IOException e) { + System.out.println("Error creating the cluster controller client: \n" + e.toString()); + } catch (InterruptedException | ExecutionException e) { + System.out.println("Error during cluster creation request: \n" + e.toString()); } } } diff --git a/dataproc/src/test/java/CreateClusterTest.java b/dataproc/src/test/java/CreateClusterTest.java index 0442ba4fbda..ce257de7a3d 100644 --- a/dataproc/src/test/java/CreateClusterTest.java +++ b/dataproc/src/test/java/CreateClusterTest.java @@ -37,7 +37,7 @@ public class CreateClusterTest { private static final String BASE_CLUSTER_NAME = "test-cluster"; private static final String REGION = "us-central1"; - private static String projectId; + private static String projectId = System.getenv("GOOGLE_CLOUD_PROJECT");; private String clusterName; private ByteArrayOutputStream bout; @@ -52,8 +52,6 @@ private static void requireEnv(String varName) { public static void checkRequirements() { requireEnv("GOOGLE_APPLICATION_CREDENTIALS"); requireEnv("GOOGLE_CLOUD_PROJECT"); - projectId = System.getenv("GOOGLE_CLOUD_PROJECT"); - System.out.println(String.format("projectId - %s", projectId)); } @Before @@ -66,29 +64,24 @@ public void setUp(){ @Test public void createClusterTest() throws Exception { - CreateCluster createCluster = new CreateCluster(); - - createCluster.createCluster(projectId, REGION, clusterName); + CreateCluster.createCluster(projectId, REGION, clusterName); String output = bout.toString(); - assertThat(output, CoreMatchers.containsString("cluster-uuid")); + assertThat(output, CoreMatchers.containsString(clusterName)); } @After public void tearDown() throws IOException { String myEndpoint = String.format("%s-dataproc.googleapis.com:443", REGION); - ClusterControllerSettings clusterControllerSettings = ClusterControllerSettings.newBuilder().setEndpoint(myEndpoint).build(); - try (ClusterControllerClient clusterControllerClient = - ClusterControllerClient.create(clusterControllerSettings)) { - + try (ClusterControllerClient clusterControllerClient = ClusterControllerClient + .create()) { clusterControllerClient.deleteClusterAsync(projectId, REGION, clusterName).get(); } catch (Exception e) { System.out.println("Error during cluster deletion: \n" + e.toString()); } } - -} +} \ No newline at end of file From 1421f57677d2c55d7a912f8af1bfc98aaaa98644 Mon Sep 17 00:00:00 2001 From: bradmiro Date: Fri, 15 Nov 2019 13:37:00 -0500 Subject: [PATCH 08/15] Added comments to exceptions in CreateCluster, expanded exceptions and femoved endpoint configuring in CreateClusterTest.java --- dataproc/src/main/java/CreateCluster.java | 4 ++++ dataproc/src/test/java/CreateClusterTest.java | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dataproc/src/main/java/CreateCluster.java b/dataproc/src/main/java/CreateCluster.java index 4382af2adcb..baa1aae4768 100644 --- a/dataproc/src/main/java/CreateCluster.java +++ b/dataproc/src/main/java/CreateCluster.java @@ -69,8 +69,12 @@ public static void createCluster(String projectId, String region, String cluster ); } catch (IOException e) { + // Likely this would occur due to issues authenticating with GCP. Make sure the environment + // variable GOOGLE_APPLICATION_CREDENTIALS is configured. System.out.println("Error creating the cluster controller client: \n" + e.toString()); } catch (InterruptedException | ExecutionException e) { + // Common issues for this include needing to increase compute engine quotas or a cluster of + // the same name already exists. System.out.println("Error during cluster creation request: \n" + e.toString()); } } diff --git a/dataproc/src/test/java/CreateClusterTest.java b/dataproc/src/test/java/CreateClusterTest.java index ce257de7a3d..fba1737253a 100644 --- a/dataproc/src/test/java/CreateClusterTest.java +++ b/dataproc/src/test/java/CreateClusterTest.java @@ -72,10 +72,6 @@ public void createClusterTest() throws Exception { @After public void tearDown() throws IOException { - String myEndpoint = String.format("%s-dataproc.googleapis.com:443", REGION); - ClusterControllerSettings clusterControllerSettings = - ClusterControllerSettings.newBuilder().setEndpoint(myEndpoint).build(); - try (ClusterControllerClient clusterControllerClient = ClusterControllerClient .create()) { clusterControllerClient.deleteClusterAsync(projectId, REGION, clusterName).get(); From 30f4b42c339582f1bc189499f7a7e6794c076d8f Mon Sep 17 00:00:00 2001 From: bradmiro Date: Fri, 15 Nov 2019 13:52:15 -0500 Subject: [PATCH 09/15] Fixed version for parent config --- dataproc/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dataproc/pom.xml b/dataproc/pom.xml index 40067e1acd4..5d4cfcc9603 100644 --- a/dataproc/pom.xml +++ b/dataproc/pom.xml @@ -15,7 +15,7 @@ com.google.cloud.samples shared-configuration - SPECIFY_LATEST_VERSION + 1.0.11 From c4b1d82af6b485cdc73bf106485304d45dab68be Mon Sep 17 00:00:00 2001 From: bradmiro Date: Fri, 15 Nov 2019 13:58:13 -0500 Subject: [PATCH 10/15] Added clarity to futures requests by expanding variables --- dataproc/src/main/java/CreateCluster.java | 6 ++++-- dataproc/src/test/java/CreateClusterTest.java | 10 ++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dataproc/src/main/java/CreateCluster.java b/dataproc/src/main/java/CreateCluster.java index baa1aae4768..221de1c2d55 100644 --- a/dataproc/src/main/java/CreateCluster.java +++ b/dataproc/src/main/java/CreateCluster.java @@ -60,8 +60,10 @@ public static void createCluster(String projectId, String region, String cluster .setConfig(clusterConfig) .build(); - // Create a request to create a Dataproc cluster. - Cluster response = clusterControllerClient.createClusterAsync(projectId, region, cluster).get(); + // Send a request to create a Dataproc cluster. + OperationFuture createClusterAsyncRequest = + clusterControllerClient.createClusterAsync(projectId, region, cluster); + Cluster response = createClusterAsyncRequest.get(); // Print out the response System.out.println( diff --git a/dataproc/src/test/java/CreateClusterTest.java b/dataproc/src/test/java/CreateClusterTest.java index fba1737253a..8333db55c81 100644 --- a/dataproc/src/test/java/CreateClusterTest.java +++ b/dataproc/src/test/java/CreateClusterTest.java @@ -17,12 +17,16 @@ import static junit.framework.TestCase.assertNotNull; import static org.hamcrest.MatcherAssert.assertThat; +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; import java.io.IOException; import java.io.PrintStream; import java.util.UUID; +import java.util.concurrent.ExecutionException; import org.hamcrest.CoreMatchers; import org.junit.After; import org.junit.Before; @@ -74,9 +78,11 @@ public void createClusterTest() throws Exception { public void tearDown() throws IOException { try (ClusterControllerClient clusterControllerClient = ClusterControllerClient .create()) { - clusterControllerClient.deleteClusterAsync(projectId, REGION, clusterName).get(); + OperationFuture deleteClusterAsyncRequest = clusterControllerClient + .deleteClusterAsync(projectId, REGION, clusterName); + deleteClusterAsyncRequest.get(); - } catch (Exception e) { + } catch (IOException | InterruptedException | ExecutionException e) { System.out.println("Error during cluster deletion: \n" + e.toString()); } } From 85aff43ab90f9770d409c28b35e658ec56a36c86 Mon Sep 17 00:00:00 2001 From: bradmiro Date: Fri, 15 Nov 2019 14:15:17 -0500 Subject: [PATCH 11/15] Fixed linting errors --- dataproc/src/main/java/CreateCluster.java | 1 - dataproc/src/test/java/CreateClusterTest.java | 11 +++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/dataproc/src/main/java/CreateCluster.java b/dataproc/src/main/java/CreateCluster.java index 221de1c2d55..161802b2307 100644 --- a/dataproc/src/main/java/CreateCluster.java +++ b/dataproc/src/main/java/CreateCluster.java @@ -15,7 +15,6 @@ */ // [START create_cluster] -import com.google.api.core.ApiFuture; import com.google.cloud.dataproc.v1.Cluster; import com.google.cloud.dataproc.v1.ClusterConfig; import com.google.cloud.dataproc.v1.ClusterControllerClient; diff --git a/dataproc/src/test/java/CreateClusterTest.java b/dataproc/src/test/java/CreateClusterTest.java index 8333db55c81..eecc3b50941 100644 --- a/dataproc/src/test/java/CreateClusterTest.java +++ b/dataproc/src/test/java/CreateClusterTest.java @@ -19,7 +19,6 @@ 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; @@ -41,7 +40,7 @@ public class CreateClusterTest { private static final String BASE_CLUSTER_NAME = "test-cluster"; private static final String REGION = "us-central1"; - private static String projectId = System.getenv("GOOGLE_CLOUD_PROJECT");; + private static String projectId = System.getenv("GOOGLE_CLOUD_PROJECT"); private String clusterName; private ByteArrayOutputStream bout; @@ -59,7 +58,7 @@ public static void checkRequirements() { } @Before - public void setUp(){ + public void setUp() { clusterName = String.format("%s-%s", BASE_CLUSTER_NAME, UUID.randomUUID().toString()); bout = new ByteArrayOutputStream(); @@ -75,11 +74,11 @@ public void createClusterTest() throws Exception { } @After - public void tearDown() throws IOException { + public void tearDown() { try (ClusterControllerClient clusterControllerClient = ClusterControllerClient .create()) { - OperationFuture deleteClusterAsyncRequest = clusterControllerClient - .deleteClusterAsync(projectId, REGION, clusterName); + OperationFuture deleteClusterAsyncRequest = + clusterControllerClient.deleteClusterAsync(projectId, REGION, clusterName); deleteClusterAsyncRequest.get(); } catch (IOException | InterruptedException | ExecutionException e) { From f65765e13ecc5fa56c9b395e3cb8893bb66932dc Mon Sep 17 00:00:00 2001 From: bradmiro Date: Fri, 15 Nov 2019 14:24:47 -0500 Subject: [PATCH 12/15] Fixed import ordering --- dataproc/src/main/java/CreateCluster.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dataproc/src/main/java/CreateCluster.java b/dataproc/src/main/java/CreateCluster.java index 161802b2307..d47b794e40e 100644 --- a/dataproc/src/main/java/CreateCluster.java +++ b/dataproc/src/main/java/CreateCluster.java @@ -15,13 +15,13 @@ */ // [START create_cluster] +import com.google.api.gax.longrunning.OperationFuture; import com.google.cloud.dataproc.v1.Cluster; import com.google.cloud.dataproc.v1.ClusterConfig; import com.google.cloud.dataproc.v1.ClusterControllerClient; import com.google.cloud.dataproc.v1.ClusterControllerSettings; import com.google.cloud.dataproc.v1.ClusterOperationMetadata; import com.google.cloud.dataproc.v1.InstanceGroupConfig; -import com.google.api.gax.longrunning.OperationFuture; import java.io.IOException; import java.util.concurrent.ExecutionException; From 6beb303d57c942780d02aa885d693665cd148616 Mon Sep 17 00:00:00 2001 From: bradmiro Date: Fri, 15 Nov 2019 15:38:48 -0500 Subject: [PATCH 13/15] Moved exceptions to function level in dataproc create cluster sample + test --- dataproc/src/main/java/CreateCluster.java | 5 +++-- dataproc/src/test/java/CreateClusterTest.java | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/dataproc/src/main/java/CreateCluster.java b/dataproc/src/main/java/CreateCluster.java index d47b794e40e..a5e5f4264a1 100644 --- a/dataproc/src/main/java/CreateCluster.java +++ b/dataproc/src/main/java/CreateCluster.java @@ -23,12 +23,13 @@ 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 { public static void createCluster(String projectId, String region, String clusterName) - throws IOException { + throws IOException, InterruptedException { String myEndpoint = String.format("%s-dataproc.googleapis.com:443", region); // Configure the settings for the cluster controller client @@ -73,7 +74,7 @@ public static void createCluster(String projectId, String region, String cluster // Likely this would occur due to issues authenticating with GCP. Make sure the environment // variable GOOGLE_APPLICATION_CREDENTIALS is configured. System.out.println("Error creating the cluster controller client: \n" + e.toString()); - } catch (InterruptedException | ExecutionException e) { + } catch (ExecutionException e) { // Common issues for this include needing to increase compute engine quotas or a cluster of // the same name already exists. System.out.println("Error during cluster creation request: \n" + e.toString()); diff --git a/dataproc/src/test/java/CreateClusterTest.java b/dataproc/src/test/java/CreateClusterTest.java index eecc3b50941..39ab75f8233 100644 --- a/dataproc/src/test/java/CreateClusterTest.java +++ b/dataproc/src/test/java/CreateClusterTest.java @@ -66,7 +66,7 @@ public void setUp() { } @Test - public void createClusterTest() throws Exception { + public void createClusterTest() throws IOException, InterruptedException { CreateCluster.createCluster(projectId, REGION, clusterName); String output = bout.toString(); @@ -74,14 +74,14 @@ public void createClusterTest() throws Exception { } @After - public void tearDown() { + public void tearDown() throws IOException, InterruptedException { try (ClusterControllerClient clusterControllerClient = ClusterControllerClient .create()) { OperationFuture deleteClusterAsyncRequest = clusterControllerClient.deleteClusterAsync(projectId, REGION, clusterName); deleteClusterAsyncRequest.get(); - } catch (IOException | InterruptedException | ExecutionException e) { + } catch (ExecutionException e) { System.out.println("Error during cluster deletion: \n" + e.toString()); } } From b7c68c85964511ffdf01b113d5376df99cf2e56f Mon Sep 17 00:00:00 2001 From: bradmiro Date: Fri, 15 Nov 2019 18:24:51 -0500 Subject: [PATCH 14/15] Re-added endpoint to test, changed region tags to include 'dataproc', slight mod to pom --- dataproc/pom.xml | 4 +++- dataproc/src/main/java/CreateCluster.java | 9 ++++----- dataproc/src/test/java/CreateClusterTest.java | 8 +++++++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/dataproc/pom.xml b/dataproc/pom.xml index 5d4cfcc9603..c76d7084fef 100644 --- a/dataproc/pom.xml +++ b/dataproc/pom.xml @@ -11,12 +11,13 @@ com.google.cloud.samples shared-configuration 1.0.11 +--> + 1.8 @@ -42,6 +43,7 @@ junit junit 4.12 + test com.google.cloud diff --git a/dataproc/src/main/java/CreateCluster.java b/dataproc/src/main/java/CreateCluster.java index a5e5f4264a1..f68852e8e2e 100644 --- a/dataproc/src/main/java/CreateCluster.java +++ b/dataproc/src/main/java/CreateCluster.java @@ -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; @@ -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 { @@ -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 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()) ); @@ -81,4 +80,4 @@ public static void createCluster(String projectId, String region, String cluster } } } -// [END create_cluster] \ No newline at end of file +// [END dataproc_create_cluster] \ No newline at end of file diff --git a/dataproc/src/test/java/CreateClusterTest.java b/dataproc/src/test/java/CreateClusterTest.java index 39ab75f8233..800856b02dc 100644 --- a/dataproc/src/test/java/CreateClusterTest.java +++ b/dataproc/src/test/java/CreateClusterTest.java @@ -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; @@ -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 deleteClusterAsyncRequest = clusterControllerClient.deleteClusterAsync(projectId, REGION, clusterName); deleteClusterAsyncRequest.get(); From a97fc8794560ebfb20e312935c4b138d30fdb80b Mon Sep 17 00:00:00 2001 From: bradmiro Date: Fri, 15 Nov 2019 18:34:31 -0500 Subject: [PATCH 15/15] fix to pom --- dataproc/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dataproc/pom.xml b/dataproc/pom.xml index c76d7084fef..649a6823aed 100644 --- a/dataproc/pom.xml +++ b/dataproc/pom.xml @@ -11,12 +11,13 @@ com.google.cloud.samples shared-configuration 1.0.11 ---> +