From f78179f9114ae41c7decac9e735997d87cfda7a5 Mon Sep 17 00:00:00 2001 From: Stephanie Wang Date: Mon, 1 Jun 2020 22:00:05 -0400 Subject: [PATCH] bug: fix importData sample in order to bump libraries-bom version (#3011) Fixes #2943 --- vision/automl/pom.xml | 2 +- .../vision/samples/automl/DatasetApi.java | 22 ++++++++++++++++--- .../vision/samples/automl/DatasetApiIT.java | 2 +- 3 files changed, 21 insertions(+), 5 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..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 @@ -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; @@ -27,10 +28,13 @@ 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.OperationMetadata; import com.google.cloud.automl.v1beta1.OutputConfig; 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..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 @@ -71,7 +71,7 @@ public void testCreateImportDeleteDataset() { // 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();