From 9c2f71747221a2048edb5812878effdbad3cafe5 Mon Sep 17 00:00:00 2001 From: stephwang Date: Mon, 1 Jun 2020 20:33:21 -0400 Subject: [PATCH 1/4] bug: fix importData sample in order to bump libraries-bom version --- vision/automl/pom.xml | 2 +- .../vision/samples/automl/DatasetApi.java | 22 ++++++++++++++--- .../vision/samples/automl/DatasetApiIT.java | 24 +++++++++---------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/vision/automl/pom.xml b/vision/automl/pom.xml index 064a7d82922..dae6b87e1a6 100644 --- a/vision/automl/pom.xml +++ b/vision/automl/pom.xml @@ -43,7 +43,7 @@ com.google.cloud libraries-bom - 4.4.1 + 5.5.0 pom import diff --git a/vision/automl/src/main/java/com/google/cloud/vision/samples/automl/DatasetApi.java b/vision/automl/src/main/java/com/google/cloud/vision/samples/automl/DatasetApi.java index bcf5ec74614..5f673e8431e 100644 --- a/vision/automl/src/main/java/com/google/cloud/vision/samples/automl/DatasetApi.java +++ b/vision/automl/src/main/java/com/google/cloud/vision/samples/automl/DatasetApi.java @@ -17,6 +17,7 @@ package com.google.cloud.vision.samples.automl; // Imports the Google Cloud client library +import com.google.api.gax.longrunning.OperationFuture; import com.google.cloud.automl.v1beta1.AutoMlClient; import com.google.cloud.automl.v1beta1.ClassificationProto.ClassificationType; import com.google.cloud.automl.v1beta1.Dataset; @@ -28,9 +29,12 @@ import com.google.cloud.automl.v1beta1.ListDatasetsRequest; import com.google.cloud.automl.v1beta1.LocationName; import com.google.cloud.automl.v1beta1.OutputConfig; +import com.google.cloud.automl.v1beta1.OperationMetadata; import com.google.protobuf.Empty; import java.io.IOException; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import net.sourceforge.argparse4j.ArgumentParsers; import net.sourceforge.argparse4j.inf.ArgumentParser; import net.sourceforge.argparse4j.inf.ArgumentParserException; @@ -211,9 +215,21 @@ static void importData(String projectId, String computeRegion, String datasetId, // Import data from the input URI InputConfig inputConfig = InputConfig.newBuilder().setGcsSource(gcsSource).build(); System.out.println("Processing import..."); - Empty response = client.importDataAsync(datasetFullId.toString(), inputConfig).get(); - System.out.println(String.format("Dataset imported. %s", response)); - } catch (IOException | InterruptedException | ExecutionException e) { + + // Start the import job + OperationFuture operation = client + .importDataAsync(datasetFullId, inputConfig); + + // More info on gax longrunning Operation: + // http://googleapis.github.io/gax-java/1.4.1/apidocs/com/google/api/gax/grpc/OperationFuture.html + System.out.format("Operation name: %s%n", operation.getName()); + + // If you want to wait for the operation to finish, adjust the timeout appropriately. The + // operation will still run if you choose not to wait for it to complete. You can check the + // status of your operation using the operation's name. + Empty response = operation.get(5, TimeUnit.MINUTES); + System.out.format("Dataset imported. %s%n", response); + } catch (IOException | InterruptedException | ExecutionException | TimeoutException e) { e.printStackTrace(); } } diff --git a/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java b/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java index 04cc0a6f4d2..93b71484b34 100644 --- a/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java +++ b/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java @@ -60,29 +60,29 @@ public void testCreateImportDeleteDataset() { String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); // Act DatasetApi.createDataset(PROJECT_ID, COMPUTE_REGION, datasetName, false); - - // Assert - String got = bout.toString(); + // + // // Assert + // String got = bout.toString(); datasetId = bout.toString() .split("\n")[0] .split("/")[(bout.toString().split("\n")[0]).split("/").length - 1]; - assertThat(got).contains("Dataset id:"); + // assertThat(got).contains("Dataset id:"); // Act DatasetApi.importData( - PROJECT_ID, COMPUTE_REGION, datasetId, "gs://" + BUCKET + "/flower_traindata.csv"); + PROJECT_ID, COMPUTE_REGION, datasetId, "gs://" + BUCKET + "/flower_traindata_concise.csv"); // Assert - got = bout.toString(); + String got = bout.toString(); assertThat(got).contains("Dataset id:"); - // Act - DatasetApi.deleteDataset(PROJECT_ID, COMPUTE_REGION, datasetId); - - // Assert - got = bout.toString(); - assertThat(got).contains("Dataset deleted."); + // // Act + // DatasetApi.deleteDataset(PROJECT_ID, COMPUTE_REGION, datasetId); + // + // // Assert + // got = bout.toString(); + // assertThat(got).contains("Dataset deleted."); } @Test From 6f4bd9260ba8d67ccbf47ec6e799507bd4a44ad6 Mon Sep 17 00:00:00 2001 From: stephwang Date: Mon, 1 Jun 2020 20:35:10 -0400 Subject: [PATCH 2/4] remove debugging changes --- .../vision/samples/automl/DatasetApiIT.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java b/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java index 93b71484b34..350c7709582 100644 --- a/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java +++ b/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java @@ -60,14 +60,14 @@ public void testCreateImportDeleteDataset() { String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); // Act DatasetApi.createDataset(PROJECT_ID, COMPUTE_REGION, datasetName, false); - // - // // Assert - // String got = bout.toString(); + + // Assert + got = bout.toString(); datasetId = bout.toString() .split("\n")[0] .split("/")[(bout.toString().split("\n")[0]).split("/").length - 1]; - // assertThat(got).contains("Dataset id:"); + assertThat(got).contains("Dataset id:"); // Act DatasetApi.importData( @@ -77,12 +77,12 @@ public void testCreateImportDeleteDataset() { String got = bout.toString(); assertThat(got).contains("Dataset id:"); - // // Act - // DatasetApi.deleteDataset(PROJECT_ID, COMPUTE_REGION, datasetId); - // - // // Assert - // got = bout.toString(); - // assertThat(got).contains("Dataset deleted."); + // Act + DatasetApi.deleteDataset(PROJECT_ID, COMPUTE_REGION, datasetId); + + // Assert + got = bout.toString(); + assertThat(got).contains("Dataset deleted."); } @Test From 064f2c15421d0156b6ef58ed3b9f8715886ebe3b Mon Sep 17 00:00:00 2001 From: stephwang Date: Mon, 1 Jun 2020 20:35:49 -0400 Subject: [PATCH 3/4] remove debugging changes --- .../com/google/cloud/vision/samples/automl/DatasetApiIT.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java b/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java index 350c7709582..1bf330bb502 100644 --- a/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java +++ b/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java @@ -62,7 +62,7 @@ public void testCreateImportDeleteDataset() { DatasetApi.createDataset(PROJECT_ID, COMPUTE_REGION, datasetName, false); // Assert - got = bout.toString(); + String got = bout.toString(); datasetId = bout.toString() .split("\n")[0] @@ -74,7 +74,7 @@ public void testCreateImportDeleteDataset() { PROJECT_ID, COMPUTE_REGION, datasetId, "gs://" + BUCKET + "/flower_traindata_concise.csv"); // Assert - String got = bout.toString(); + got = bout.toString(); assertThat(got).contains("Dataset id:"); // Act From d61fc9c76d3e66f8dc0bbdfb591642e7aae9100e Mon Sep 17 00:00:00 2001 From: stephwang Date: Mon, 1 Jun 2020 21:48:09 -0400 Subject: [PATCH 4/4] format code --- .../com/google/cloud/vision/samples/automl/DatasetApi.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vision/automl/src/main/java/com/google/cloud/vision/samples/automl/DatasetApi.java b/vision/automl/src/main/java/com/google/cloud/vision/samples/automl/DatasetApi.java index 5f673e8431e..48b7cb17197 100644 --- a/vision/automl/src/main/java/com/google/cloud/vision/samples/automl/DatasetApi.java +++ b/vision/automl/src/main/java/com/google/cloud/vision/samples/automl/DatasetApi.java @@ -28,8 +28,8 @@ import com.google.cloud.automl.v1beta1.InputConfig; import com.google.cloud.automl.v1beta1.ListDatasetsRequest; import com.google.cloud.automl.v1beta1.LocationName; -import com.google.cloud.automl.v1beta1.OutputConfig; import com.google.cloud.automl.v1beta1.OperationMetadata; +import com.google.cloud.automl.v1beta1.OutputConfig; import com.google.protobuf.Empty; import java.io.IOException; import java.util.concurrent.ExecutionException; @@ -217,8 +217,8 @@ static void importData(String projectId, String computeRegion, String datasetId, System.out.println("Processing import..."); // Start the import job - OperationFuture operation = client - .importDataAsync(datasetFullId, inputConfig); + OperationFuture operation = + client.importDataAsync(datasetFullId, inputConfig); // More info on gax longrunning Operation: // http://googleapis.github.io/gax-java/1.4.1/apidocs/com/google/api/gax/grpc/OperationFuture.html