From 01724ddd27c139d88f53a08a77b8a5852028cf12 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Thu, 17 Oct 2019 10:05:10 -0600 Subject: [PATCH 1/8] Move samples and refactor them for simplification --- automl/cloud-client/README.md | 70 +++++++++++++++++++ automl/cloud-client/pom.xml | 68 ++++++++++++++++++ .../com/example}/automl/DeleteDataset.java | 6 +- .../java/com/example}/automl/DeleteModel.java | 6 +- .../com/example}/automl/ExportDataset.java | 6 +- .../java/com/example}/automl/GetDataset.java | 6 +- .../java/com/example}/automl/GetModel.java | 6 +- .../example}/automl/GetModelEvaluation.java | 6 +- .../example}/automl/GetOperationStatus.java | 6 +- .../com/example}/automl/ImportDataset.java | 6 +- .../com/example}/automl/ListDatasets.java | 6 +- .../example}/automl/ListModelEvaluations.java | 6 +- .../java/com/example}/automl/ListModels.java | 6 +- .../example}/automl/ListOperationStatus.java | 6 +- .../automl/TranslateCreateDataset.java | 4 +- .../example/automl/TranslateCreateModel.java | 4 +- .../com/example/automl/TranslatePredict.java | 4 +- .../automl/TranslateDatasetManagementIT.java | 20 +++--- .../automl/TranslateModelManagementIT.java | 6 +- .../example/automl/TranslatePredictIT.java | 62 ++++++++++++++++ .../translate/automl/PredictionApiIT.java | 10 --- 21 files changed, 255 insertions(+), 65 deletions(-) create mode 100644 automl/cloud-client/README.md create mode 100644 automl/cloud-client/pom.xml rename {translate/automl/src/main/java/com/google/cloud/translate => automl/cloud-client/src/main/java/com/example}/automl/DeleteDataset.java (93%) rename {translate/automl/src/main/java/com/google/cloud/translate => automl/cloud-client/src/main/java/com/example}/automl/DeleteModel.java (93%) rename {translate/automl/src/main/java/com/google/cloud/translate => automl/cloud-client/src/main/java/com/example}/automl/ExportDataset.java (94%) rename {translate/automl/src/main/java/com/google/cloud/translate => automl/cloud-client/src/main/java/com/example}/automl/GetDataset.java (95%) rename {translate/automl/src/main/java/com/google/cloud/translate => automl/cloud-client/src/main/java/com/example}/automl/GetModel.java (95%) rename {translate/automl/src/main/java/com/google/cloud/translate => automl/cloud-client/src/main/java/com/example}/automl/GetModelEvaluation.java (94%) rename {translate/automl/src/main/java/com/google/cloud/translate => automl/cloud-client/src/main/java/com/example}/automl/GetOperationStatus.java (94%) rename {translate/automl/src/main/java/com/google/cloud/translate => automl/cloud-client/src/main/java/com/example}/automl/ImportDataset.java (94%) rename {translate/automl/src/main/java/com/google/cloud/translate => automl/cloud-client/src/main/java/com/example}/automl/ListDatasets.java (96%) rename {translate/automl/src/main/java/com/google/cloud/translate => automl/cloud-client/src/main/java/com/example}/automl/ListModelEvaluations.java (94%) rename {translate/automl/src/main/java/com/google/cloud/translate => automl/cloud-client/src/main/java/com/example}/automl/ListModels.java (95%) rename {translate/automl/src/main/java/com/google/cloud/translate => automl/cloud-client/src/main/java/com/example}/automl/ListOperationStatus.java (94%) rename translate/automl/src/main/java/com/google/cloud/translate/automl/CreateDataset.java => automl/cloud-client/src/main/java/com/example/automl/TranslateCreateDataset.java (98%) rename translate/automl/src/main/java/com/google/cloud/translate/automl/CreateModel.java => automl/cloud-client/src/main/java/com/example/automl/TranslateCreateModel.java (97%) rename translate/automl/src/main/java/com/google/cloud/translate/automl/Prediction.java => automl/cloud-client/src/main/java/com/example/automl/TranslatePredict.java (97%) rename translate/automl/src/test/java/com/google/cloud/translate/automl/DatasetIT.java => automl/cloud-client/src/test/java/com/example/automl/TranslateDatasetManagementIT.java (88%) rename translate/automl/src/test/java/com/google/cloud/translate/automl/ModelIT.java => automl/cloud-client/src/test/java/com/example/automl/TranslateModelManagementIT.java (96%) create mode 100644 automl/cloud-client/src/test/java/com/example/automl/TranslatePredictIT.java diff --git a/automl/cloud-client/README.md b/automl/cloud-client/README.md new file mode 100644 index 00000000000..81305f90a50 --- /dev/null +++ b/automl/cloud-client/README.md @@ -0,0 +1,70 @@ +# AutoML Samples + + +Open in Cloud Shell + + +This directory contains samples for the [Google Cloud AutoML APIs](https://cloud.google.com/automl/) - [docs](https://cloud.google.com/automl/docs/) + +We highly reccommend that you refer to the official documentation pages: + +* [AutoML Translation](https://cloud.google.com/translate/automl/docs) + + +This API is part of the larger collection of Cloud Machine Learning APIs. + +These Java samples demonstrates how to access the Cloud AutoML API +using the [Google Cloud Client Library for Java][google-cloud-java]. + +[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java + +## Build the samples + +Install [Maven](http://maven.apache.org/). + +Build your project with: + +``` +mvn clean package +``` + +## Sample Types +There are two types of samples: [Base and API Specific], the base samples make up a set of samples that have code that +is identical or nearly identical for each AutoML Type. Meaning that for "Base" samples you can use them with any AutoML +Type. However, for API Specific samples, there will be a unique sample for each AutoML type. See the below list for more info. + +## Base Samples +### Dataset Management +* [Import Dataset](src/main/java/com/example/automl/ImportDataset.java) +* [List Datasets](src/main/java/com/example/automl/ListDatasets.java) - For each AutoML Type the `metadata` field inside the dataset is unique, therefore each AutoML Type will have a +small section of code to print out the `metadata` field. +* [Get Dataset](src/main/java/com/example/automl/GetDataset.java) - For each AutoML Type the `metadata` field inside the dataset is unique, therefore each AutoML Type will have a +small section of code to print out the `metadata` field. +* [Export Dataset](src/main/java/com/example/automl/ExportDataset.java) +* [Delete Dataset](src/main/java/com/example/automl/DeleteDataset.java) +### Model Management +* [List Models](src/main/java/com/example/automl/ListModels.java) +* [List Model Evaluation](src/main/java/com/example/automl/ListModelEvaluations.java) +* [Get Model](src/main/java/com/example/automl/) +* [Get Model Evaluation](src/main/java/com/example/automl/GetModelEvaluation.java) +* [Delete Model](src/main/java/com/example/automl/DeleteModel.java) + +### Operation Management +* [List Operation Statuses](src/main/java/com/example/automl/ListOperationStatus.java) +* [Get Operation Status](src/main/java/com/example/automl/GetOperationStatus.java) + +## AutoML Type Specific Samples +### Translation +* [Translate Create Dataset](src/main/java/com/example/automl/TranslateCreateDataset.java) +* [Translate Create Model](src/main/java/com/example/automl/TranslateCreateModel.java) +* [Translate Predict](src/main/java/com/example/automl/TranslatePredict.java) \ No newline at end of file diff --git a/automl/cloud-client/pom.xml b/automl/cloud-client/pom.xml new file mode 100644 index 00000000000..8ada1bcd2bf --- /dev/null +++ b/automl/cloud-client/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + com.example.automl + automl-google-cloud-samples + jar + + + + com.google.cloud.samples + shared-configuration + 1.0.11 + + + + 1.8 + 1.8 + UTF-8 + + + + + + com.google.cloud + google-cloud-automl + 0.114.0-beta + + + + com.google.cloud + google-cloud-storage + 1.83.0 + + + net.sourceforge.argparse4j + argparse4j + 0.8.1 + + + + + junit + junit + 4.12 + test + + + com.google.truth + truth + 0.41 + test + + + \ No newline at end of file diff --git a/translate/automl/src/main/java/com/google/cloud/translate/automl/DeleteDataset.java b/automl/cloud-client/src/main/java/com/example/automl/DeleteDataset.java similarity index 93% rename from translate/automl/src/main/java/com/google/cloud/translate/automl/DeleteDataset.java rename to automl/cloud-client/src/main/java/com/example/automl/DeleteDataset.java index e284e9ef4ff..b9fefbea4ec 100644 --- a/translate/automl/src/main/java/com/google/cloud/translate/automl/DeleteDataset.java +++ b/automl/cloud-client/src/main/java/com/example/automl/DeleteDataset.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.cloud.translate.automl; +package com.example.automl; -// [START automl_translate_delete_dataset] +// [START automl_delete_dataset] import com.google.cloud.automl.v1.AutoMlClient; import com.google.cloud.automl.v1.DatasetName; import com.google.protobuf.Empty; @@ -44,4 +44,4 @@ static void deleteDataset(String projectId, String datasetId) { } } } -// [END automl_translate_delete_dataset] +// [END automl_delete_dataset] diff --git a/translate/automl/src/main/java/com/google/cloud/translate/automl/DeleteModel.java b/automl/cloud-client/src/main/java/com/example/automl/DeleteModel.java similarity index 93% rename from translate/automl/src/main/java/com/google/cloud/translate/automl/DeleteModel.java rename to automl/cloud-client/src/main/java/com/example/automl/DeleteModel.java index bddfe867fc0..fcb802bf68c 100644 --- a/translate/automl/src/main/java/com/google/cloud/translate/automl/DeleteModel.java +++ b/automl/cloud-client/src/main/java/com/example/automl/DeleteModel.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.cloud.translate.automl; +package com.example.automl; -// [START automl_translate_delete_model] +// [START automl_delete_model] import com.google.cloud.automl.v1.AutoMlClient; import com.google.cloud.automl.v1.ModelName; import com.google.protobuf.Empty; @@ -48,4 +48,4 @@ static void deleteModel(String projectId, String modelId) { } } } -// [END automl_translate_delete_model] +// [END automl_delete_model] diff --git a/translate/automl/src/main/java/com/google/cloud/translate/automl/ExportDataset.java b/automl/cloud-client/src/main/java/com/example/automl/ExportDataset.java similarity index 94% rename from translate/automl/src/main/java/com/google/cloud/translate/automl/ExportDataset.java rename to automl/cloud-client/src/main/java/com/example/automl/ExportDataset.java index 9f7ab5b3095..03dbc553632 100644 --- a/translate/automl/src/main/java/com/google/cloud/translate/automl/ExportDataset.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ExportDataset.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.cloud.translate.automl; +package com.example.automl; -// [START automl_translate_export_dataset] +// [START automl_export_dataset] import com.google.cloud.automl.v1.AutoMlClient; import com.google.cloud.automl.v1.DatasetName; import com.google.cloud.automl.v1.GcsDestination; @@ -55,4 +55,4 @@ static void exportDataset(String projectId, String datasetId, String gcsUri) { } } } -// [END automl_translate_export_dataset] +// [END automl_export_dataset] diff --git a/translate/automl/src/main/java/com/google/cloud/translate/automl/GetDataset.java b/automl/cloud-client/src/main/java/com/example/automl/GetDataset.java similarity index 95% rename from translate/automl/src/main/java/com/google/cloud/translate/automl/GetDataset.java rename to automl/cloud-client/src/main/java/com/example/automl/GetDataset.java index 8c362494b92..8b13d5b413e 100644 --- a/translate/automl/src/main/java/com/google/cloud/translate/automl/GetDataset.java +++ b/automl/cloud-client/src/main/java/com/example/automl/GetDataset.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.cloud.translate.automl; +package com.example.automl; -// [START automl_translate_get_dataset] +// [START automl_get_dataset] import com.google.cloud.automl.v1.AutoMlClient; import com.google.cloud.automl.v1.Dataset; import com.google.cloud.automl.v1.DatasetName; @@ -62,4 +62,4 @@ static void getDataset(String projectId, String datasetId) { } } } -// [END automl_translate_get_dataset] +// [END automl_get_dataset] diff --git a/translate/automl/src/main/java/com/google/cloud/translate/automl/GetModel.java b/automl/cloud-client/src/main/java/com/example/automl/GetModel.java similarity index 95% rename from translate/automl/src/main/java/com/google/cloud/translate/automl/GetModel.java rename to automl/cloud-client/src/main/java/com/example/automl/GetModel.java index b604a379f26..4b80d34f226 100644 --- a/translate/automl/src/main/java/com/google/cloud/translate/automl/GetModel.java +++ b/automl/cloud-client/src/main/java/com/example/automl/GetModel.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.cloud.translate.automl; +package com.example.automl; -// [START automl_translate_get_model] +// [START automl_get_model] import com.google.cloud.automl.v1.AutoMlClient; import com.google.cloud.automl.v1.Model; import com.google.cloud.automl.v1.ModelName; @@ -56,4 +56,4 @@ static void getModel(String projectId, String modelId) { } } } -// [END automl_translate_get_model] +// [END automl_get_model] diff --git a/translate/automl/src/main/java/com/google/cloud/translate/automl/GetModelEvaluation.java b/automl/cloud-client/src/main/java/com/example/automl/GetModelEvaluation.java similarity index 94% rename from translate/automl/src/main/java/com/google/cloud/translate/automl/GetModelEvaluation.java rename to automl/cloud-client/src/main/java/com/example/automl/GetModelEvaluation.java index 6713d51f212..8364dc2926d 100644 --- a/translate/automl/src/main/java/com/google/cloud/translate/automl/GetModelEvaluation.java +++ b/automl/cloud-client/src/main/java/com/example/automl/GetModelEvaluation.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.cloud.translate.automl; +package com.example.automl; -// [START automl_translate_get_model_evaluation] +// [START automl_get_model_evaluation] import com.google.cloud.automl.v1.AutoMlClient; import com.google.cloud.automl.v1.ModelEvaluation; import com.google.cloud.automl.v1.ModelEvaluationName; @@ -56,4 +56,4 @@ static void getModelEvaluation(String projectId, String modelId, String modelEva } } } -// [END automl_translate_get_model_evaluation] +// [END automl_get_model_evaluation] diff --git a/translate/automl/src/main/java/com/google/cloud/translate/automl/GetOperationStatus.java b/automl/cloud-client/src/main/java/com/example/automl/GetOperationStatus.java similarity index 94% rename from translate/automl/src/main/java/com/google/cloud/translate/automl/GetOperationStatus.java rename to automl/cloud-client/src/main/java/com/example/automl/GetOperationStatus.java index 92970c24e4c..e40716e8ca8 100644 --- a/translate/automl/src/main/java/com/google/cloud/translate/automl/GetOperationStatus.java +++ b/automl/cloud-client/src/main/java/com/example/automl/GetOperationStatus.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.cloud.translate.automl; +package com.example.automl; -// [START automl_translate_get_operation_status] +// [START automl_get_operation_status] import com.google.cloud.automl.v1.AutoMlClient; import com.google.longrunning.Operation; @@ -54,4 +54,4 @@ static void getOperationStatus(String operationFullId) { } } } -// [END automl_translate_get_operation_status] +// [END automl_get_operation_status] diff --git a/translate/automl/src/main/java/com/google/cloud/translate/automl/ImportDataset.java b/automl/cloud-client/src/main/java/com/example/automl/ImportDataset.java similarity index 94% rename from translate/automl/src/main/java/com/google/cloud/translate/automl/ImportDataset.java rename to automl/cloud-client/src/main/java/com/example/automl/ImportDataset.java index e98b5aa38ae..0e1075f7c91 100644 --- a/translate/automl/src/main/java/com/google/cloud/translate/automl/ImportDataset.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ImportDataset.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.cloud.translate.automl; +package com.example.automl; -// [START automl_translate_import_dataset] +// [START automl_import_dataset] import com.google.cloud.automl.v1.AutoMlClient; import com.google.cloud.automl.v1.DatasetName; import com.google.cloud.automl.v1.GcsSource; @@ -57,4 +57,4 @@ static void importDataset(String projectId, String datasetId, String path) { } } } -// [END automl_translate_import_dataset] +// [END automl_import_dataset] diff --git a/translate/automl/src/main/java/com/google/cloud/translate/automl/ListDatasets.java b/automl/cloud-client/src/main/java/com/example/automl/ListDatasets.java similarity index 96% rename from translate/automl/src/main/java/com/google/cloud/translate/automl/ListDatasets.java rename to automl/cloud-client/src/main/java/com/example/automl/ListDatasets.java index 651c0ec0b99..964b818ba9a 100644 --- a/translate/automl/src/main/java/com/google/cloud/translate/automl/ListDatasets.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ListDatasets.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.cloud.translate.automl; +package com.example.automl; -// [START automl_translate_list_dataset] +// [START automl_list_datasets] import com.google.cloud.automl.v1.AutoMlClient; import com.google.cloud.automl.v1.Dataset; import com.google.cloud.automl.v1.ListDatasetsRequest; @@ -70,4 +70,4 @@ static void listDatasets(String projectId) { } } } -// [END automl_translate_list_dataset] +// [END automl_list_datasets] diff --git a/translate/automl/src/main/java/com/google/cloud/translate/automl/ListModelEvaluations.java b/automl/cloud-client/src/main/java/com/example/automl/ListModelEvaluations.java similarity index 94% rename from translate/automl/src/main/java/com/google/cloud/translate/automl/ListModelEvaluations.java rename to automl/cloud-client/src/main/java/com/example/automl/ListModelEvaluations.java index 7cf38b1318b..0cbcacc93da 100644 --- a/translate/automl/src/main/java/com/google/cloud/translate/automl/ListModelEvaluations.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ListModelEvaluations.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.cloud.translate.automl; +package com.example.automl; -// [START automl_translate_list_model_evaluation] +// [START automl_list_model_evaluations] import com.google.cloud.automl.v1.AutoMlClient; import com.google.cloud.automl.v1.ListModelEvaluationsRequest; import com.google.cloud.automl.v1.ModelEvaluation; @@ -60,4 +60,4 @@ static void listModelEvaluations(String projectId, String modelId) { } } } -// [END automl_translate_list_model_evaluation] +// [END automl_list_model_evaluations] diff --git a/translate/automl/src/main/java/com/google/cloud/translate/automl/ListModels.java b/automl/cloud-client/src/main/java/com/example/automl/ListModels.java similarity index 95% rename from translate/automl/src/main/java/com/google/cloud/translate/automl/ListModels.java rename to automl/cloud-client/src/main/java/com/example/automl/ListModels.java index ef18a11eec8..596e45a09c2 100644 --- a/translate/automl/src/main/java/com/google/cloud/translate/automl/ListModels.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ListModels.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.cloud.translate.automl; +package com.example.automl; -// [START automl_translate_list_model] +// [START automl_list_models] import com.google.cloud.automl.v1.AutoMlClient; import com.google.cloud.automl.v1.ListModelsRequest; import com.google.cloud.automl.v1.LocationName; @@ -66,4 +66,4 @@ static void listModels(String projectId) { } } } -// [END automl_translate_list_model] +// [END automl_list_models] diff --git a/translate/automl/src/main/java/com/google/cloud/translate/automl/ListOperationStatus.java b/automl/cloud-client/src/main/java/com/example/automl/ListOperationStatus.java similarity index 94% rename from translate/automl/src/main/java/com/google/cloud/translate/automl/ListOperationStatus.java rename to automl/cloud-client/src/main/java/com/example/automl/ListOperationStatus.java index 4a455d47e40..11299072757 100644 --- a/translate/automl/src/main/java/com/google/cloud/translate/automl/ListOperationStatus.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ListOperationStatus.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.google.cloud.translate.automl; +package com.example.automl; -// [START automl_translate_list_operation_status] +// [START automl_list_operation_status] import com.google.cloud.automl.v1.AutoMlClient; import com.google.cloud.automl.v1.LocationName; import com.google.longrunning.ListOperationsRequest; @@ -62,4 +62,4 @@ static void listOperationStatus(String projectId) { } } } -// [END automl_translate_list_operation_status] +// [END automl_list_operation_status] diff --git a/translate/automl/src/main/java/com/google/cloud/translate/automl/CreateDataset.java b/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateDataset.java similarity index 98% rename from translate/automl/src/main/java/com/google/cloud/translate/automl/CreateDataset.java rename to automl/cloud-client/src/main/java/com/example/automl/TranslateCreateDataset.java index 4b24c85d51e..215e6019f9e 100644 --- a/translate/automl/src/main/java/com/google/cloud/translate/automl/CreateDataset.java +++ b/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateDataset.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.cloud.translate.automl; +package com.example.automl; // [START automl_translate_create_dataset] import com.google.api.gax.longrunning.OperationFuture; @@ -27,7 +27,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -class CreateDataset { +class TranslateCreateDataset { // Create a dataset static void createDataset(String projectId, String displayName) { diff --git a/translate/automl/src/main/java/com/google/cloud/translate/automl/CreateModel.java b/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateModel.java similarity index 97% rename from translate/automl/src/main/java/com/google/cloud/translate/automl/CreateModel.java rename to automl/cloud-client/src/main/java/com/example/automl/TranslateCreateModel.java index b317d0dd801..636d86c86b9 100644 --- a/translate/automl/src/main/java/com/google/cloud/translate/automl/CreateModel.java +++ b/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateModel.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.cloud.translate.automl; +package com.example.automl; // [START automl_translate_create_model] import com.google.api.gax.longrunning.OperationFuture; @@ -27,7 +27,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -class CreateModel { +class TranslateCreateModel { // Create a model static void createModel(String projectId, String datasetId, String displayName) { diff --git a/translate/automl/src/main/java/com/google/cloud/translate/automl/Prediction.java b/automl/cloud-client/src/main/java/com/example/automl/TranslatePredict.java similarity index 97% rename from translate/automl/src/main/java/com/google/cloud/translate/automl/Prediction.java rename to automl/cloud-client/src/main/java/com/example/automl/TranslatePredict.java index 0b9e3e77ee7..359aed66a51 100644 --- a/translate/automl/src/main/java/com/google/cloud/translate/automl/Prediction.java +++ b/automl/cloud-client/src/main/java/com/example/automl/TranslatePredict.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.cloud.translate.automl; +package com.example.automl; // [START automl_translate_predict] import com.google.cloud.automl.v1.ExamplePayload; @@ -28,7 +28,7 @@ import java.nio.file.Files; import java.nio.file.Paths; -class Prediction { +class TranslatePredict { // Predict static void predict(String projectId, String modelId, String filePath) { diff --git a/translate/automl/src/test/java/com/google/cloud/translate/automl/DatasetIT.java b/automl/cloud-client/src/test/java/com/example/automl/TranslateDatasetManagementIT.java similarity index 88% rename from translate/automl/src/test/java/com/google/cloud/translate/automl/DatasetIT.java rename to automl/cloud-client/src/test/java/com/example/automl/TranslateDatasetManagementIT.java index 2793fe81343..6be4695b40e 100644 --- a/translate/automl/src/test/java/com/google/cloud/translate/automl/DatasetIT.java +++ b/automl/cloud-client/src/test/java/com/example/automl/TranslateDatasetManagementIT.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.cloud.translate.automl; +package com.example.automl; import static com.google.common.truth.Truth.assertThat; @@ -36,7 +36,7 @@ /** Tests for Automl translation datasets. */ @RunWith(JUnit4.class) @SuppressWarnings("checkstyle:abbreviationaswordinname") -public class DatasetIT { +public class TranslateDatasetManagementIT { private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); private static final String BUCKET = "gs://" + PROJECT_ID + "-vcm"; @@ -63,15 +63,15 @@ public void testCreateImportDeleteDataset() { // To prevent name collisions when running tests in multiple java versions at once. // AutoML doesn't allow "-", but accepts "_" String datasetName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); + String.format( + "test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); // Act - CreateDataset.createDataset(PROJECT_ID, datasetName); + TranslateCreateDataset.createDataset(PROJECT_ID, datasetName); // Assert String got = bout.toString(); datasetId = got.split("Dataset id: ")[1].split("\n")[0]; - assertThat(got).contains("Dataset id:"); // Act ImportDataset.importDataset(PROJECT_ID, datasetId, BUCKET + "/en-ja-short.csv"); @@ -120,10 +120,10 @@ public void testExportDataset() { assertThat(got).contains("Dataset exported."); Page blobs = - storage.list( - PROJECT_ID + "-vcm", - Storage.BlobListOption.currentDirectory(), - Storage.BlobListOption.prefix("TEST_EXPORT_OUTPUT/")); + storage.list( + PROJECT_ID + "-vcm", + Storage.BlobListOption.currentDirectory(), + Storage.BlobListOption.prefix("TEST_EXPORT_OUTPUT/")); for (Blob blob : blobs.iterateAll()) { Page fileBlobs = @@ -138,4 +138,4 @@ public void testExportDataset() { } } } -} +} \ No newline at end of file diff --git a/translate/automl/src/test/java/com/google/cloud/translate/automl/ModelIT.java b/automl/cloud-client/src/test/java/com/example/automl/TranslateModelManagementIT.java similarity index 96% rename from translate/automl/src/test/java/com/google/cloud/translate/automl/ModelIT.java rename to automl/cloud-client/src/test/java/com/example/automl/TranslateModelManagementIT.java index fde5d9ab529..9fa3a6c7e01 100644 --- a/translate/automl/src/test/java/com/google/cloud/translate/automl/ModelIT.java +++ b/automl/cloud-client/src/test/java/com/example/automl/TranslateModelManagementIT.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.cloud.translate.automl; +package com.example.automl; import static com.google.common.truth.Truth.assertThat; @@ -32,7 +32,7 @@ /** Tests for Automl translation models. */ @RunWith(JUnit4.class) -public class ModelIT { +public class TranslateModelManagementIT { private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); private static final String DATASET_ID = "TRL3946265060617537378"; private static final String MODEL_NAME = "translation_test_create_model"; @@ -108,7 +108,7 @@ public void testOperationStatus() { @Test public void testCreateModel() throws IOException { - CreateModel.createModel(PROJECT_ID, DATASET_ID, MODEL_NAME); + TranslateCreateModel.createModel(PROJECT_ID, DATASET_ID, MODEL_NAME); String got = bout.toString(); assertThat(got).contains("Training started"); diff --git a/automl/cloud-client/src/test/java/com/example/automl/TranslatePredictIT.java b/automl/cloud-client/src/test/java/com/example/automl/TranslatePredictIT.java new file mode 100644 index 00000000000..e543ede78f3 --- /dev/null +++ b/automl/cloud-client/src/test/java/com/example/automl/TranslatePredictIT.java @@ -0,0 +1,62 @@ +/* + * 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. + */ + +package com.example.automl; + +import static com.google.common.truth.Truth.assertThat; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests for translation "Predict" sample. */ +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class TranslatePredictIT { + private static final String COMPUTE_REGION = "us-central1"; + private static final String PROJECT_ID = "java-docs-samples-testing"; + private static final String modelId = "TRL2188848820815848149"; + private static final String filePath = "./resources/input.txt"; + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void testPredict() { + // Act + TranslatePredict.predict(PROJECT_ID, modelId, filePath); + + // Assert + String got = bout.toString(); + assertThat(got).contains("Translated Content"); + } +} \ No newline at end of file diff --git a/translate/automl/src/test/java/com/google/cloud/translate/automl/PredictionApiIT.java b/translate/automl/src/test/java/com/google/cloud/translate/automl/PredictionApiIT.java index c07839041e4..78e47eb3e8e 100644 --- a/translate/automl/src/test/java/com/google/cloud/translate/automl/PredictionApiIT.java +++ b/translate/automl/src/test/java/com/google/cloud/translate/automl/PredictionApiIT.java @@ -59,14 +59,4 @@ public void testPredict() throws Exception { String got = bout.toString(); assertThat(got).contains("Translated Content"); } - - @Test - public void testPrediction() { - // Act - Prediction.predict(PROJECT_ID, modelId, filePath); - - // Assert - String got = bout.toString(); - assertThat(got).contains("Translated Content"); - } } From fd6fb30fa1ce7d5890c3e04d1911b7b9e7ecf177 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Thu, 17 Oct 2019 10:38:08 -0600 Subject: [PATCH 2/8] Add missing resource files --- automl/cloud-client/README.md | 4 +++- automl/cloud-client/resources/input.txt | 1 + .../automl/TranslateDatasetManagementIT.java | 21 +++++++++---------- .../automl/TranslateModelManagementIT.java | 2 +- .../example/automl/TranslatePredictIT.java | 4 ++-- 5 files changed, 17 insertions(+), 15 deletions(-) create mode 100644 automl/cloud-client/resources/input.txt diff --git a/automl/cloud-client/README.md b/automl/cloud-client/README.md index 81305f90a50..0e4f93100c1 100644 --- a/automl/cloud-client/README.md +++ b/automl/cloud-client/README.md @@ -39,7 +39,9 @@ mvn clean package ``` ## Sample Types -There are two types of samples: [Base and API Specific], the base samples make up a set of samples that have code that +There are two types of samples: Base and API Specific + +The base samples make up a set of samples that have code that is identical or nearly identical for each AutoML Type. Meaning that for "Base" samples you can use them with any AutoML Type. However, for API Specific samples, there will be a unique sample for each AutoML type. See the below list for more info. diff --git a/automl/cloud-client/resources/input.txt b/automl/cloud-client/resources/input.txt new file mode 100644 index 00000000000..5aecd6590fc --- /dev/null +++ b/automl/cloud-client/resources/input.txt @@ -0,0 +1 @@ +Tell me how this ends \ No newline at end of file diff --git a/automl/cloud-client/src/test/java/com/example/automl/TranslateDatasetManagementIT.java b/automl/cloud-client/src/test/java/com/example/automl/TranslateDatasetManagementIT.java index 6be4695b40e..3a21f40dcbc 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/TranslateDatasetManagementIT.java +++ b/automl/cloud-client/src/test/java/com/example/automl/TranslateDatasetManagementIT.java @@ -63,8 +63,7 @@ public void testCreateImportDeleteDataset() { // To prevent name collisions when running tests in multiple java versions at once. // AutoML doesn't allow "-", but accepts "_" String datasetName = - String.format( - "test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); + String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); // Act TranslateCreateDataset.createDataset(PROJECT_ID, datasetName); @@ -120,17 +119,17 @@ public void testExportDataset() { assertThat(got).contains("Dataset exported."); Page blobs = - storage.list( - PROJECT_ID + "-vcm", - Storage.BlobListOption.currentDirectory(), - Storage.BlobListOption.prefix("TEST_EXPORT_OUTPUT/")); + storage.list( + PROJECT_ID + "-vcm", + Storage.BlobListOption.currentDirectory(), + Storage.BlobListOption.prefix("TEST_EXPORT_OUTPUT/")); for (Blob blob : blobs.iterateAll()) { Page fileBlobs = - storage.list( - PROJECT_ID + "-vcm", - Storage.BlobListOption.currentDirectory(), - Storage.BlobListOption.prefix(blob.getName())); + storage.list( + PROJECT_ID + "-vcm", + Storage.BlobListOption.currentDirectory(), + Storage.BlobListOption.prefix(blob.getName())); for (Blob fileBlob : fileBlobs.iterateAll()) { if (!fileBlob.isDirectory()) { fileBlob.delete(); @@ -138,4 +137,4 @@ public void testExportDataset() { } } } -} \ No newline at end of file +} diff --git a/automl/cloud-client/src/test/java/com/example/automl/TranslateModelManagementIT.java b/automl/cloud-client/src/test/java/com/example/automl/TranslateModelManagementIT.java index 9fa3a6c7e01..c8fb1da96c6 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/TranslateModelManagementIT.java +++ b/automl/cloud-client/src/test/java/com/example/automl/TranslateModelManagementIT.java @@ -119,4 +119,4 @@ public void testCreateModel() throws IOException { client.getOperationsClient().cancelOperation(operationId); } } -} \ No newline at end of file +} diff --git a/automl/cloud-client/src/test/java/com/example/automl/TranslatePredictIT.java b/automl/cloud-client/src/test/java/com/example/automl/TranslatePredictIT.java index e543ede78f3..65ee34e8ae4 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/TranslatePredictIT.java +++ b/automl/cloud-client/src/test/java/com/example/automl/TranslatePredictIT.java @@ -32,7 +32,7 @@ @SuppressWarnings("checkstyle:abbreviationaswordinname") public class TranslatePredictIT { private static final String COMPUTE_REGION = "us-central1"; - private static final String PROJECT_ID = "java-docs-samples-testing"; + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); private static final String modelId = "TRL2188848820815848149"; private static final String filePath = "./resources/input.txt"; private ByteArrayOutputStream bout; @@ -59,4 +59,4 @@ public void testPredict() { String got = bout.toString(); assertThat(got).contains("Translated Content"); } -} \ No newline at end of file +} From 6879ab3f75f1a24665c4dc1f76e5b7871520ae99 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Thu, 17 Oct 2019 10:50:22 -0600 Subject: [PATCH 3/8] Update GetDataset.java --- .../src/main/java/com/example/automl/GetDataset.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automl/cloud-client/src/main/java/com/example/automl/GetDataset.java b/automl/cloud-client/src/main/java/com/example/automl/GetDataset.java index 8b13d5b413e..704edee8cf4 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/GetDataset.java +++ b/automl/cloud-client/src/main/java/com/example/automl/GetDataset.java @@ -16,7 +16,7 @@ package com.example.automl; -// [START automl_get_dataset] +// [START automl_translate_get_dataset] import com.google.cloud.automl.v1.AutoMlClient; import com.google.cloud.automl.v1.Dataset; import com.google.cloud.automl.v1.DatasetName; @@ -62,4 +62,4 @@ static void getDataset(String projectId, String datasetId) { } } } -// [END automl_get_dataset] +// [END automl_translate_get_dataset] From b2237291630ffe9a158ecf998e4d45f050ca3b13 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Thu, 17 Oct 2019 10:50:42 -0600 Subject: [PATCH 4/8] Update ListDatasets.java --- .../src/main/java/com/example/automl/ListDatasets.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automl/cloud-client/src/main/java/com/example/automl/ListDatasets.java b/automl/cloud-client/src/main/java/com/example/automl/ListDatasets.java index 964b818ba9a..aca4b11fea9 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/ListDatasets.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ListDatasets.java @@ -16,7 +16,7 @@ package com.example.automl; -// [START automl_list_datasets] +// [START automl_translate_list_datasets] import com.google.cloud.automl.v1.AutoMlClient; import com.google.cloud.automl.v1.Dataset; import com.google.cloud.automl.v1.ListDatasetsRequest; @@ -70,4 +70,4 @@ static void listDatasets(String projectId) { } } } -// [END automl_list_datasets] +// [END automl_translate_list_datasets] From e823dcba3a63a4e755c74707847b237137f610e4 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Tue, 22 Oct 2019 16:32:30 -0600 Subject: [PATCH 5/8] Remove output that isn't returned with create --- .../com/example/automl/TranslateCreateDataset.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateDataset.java b/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateDataset.java index 215e6019f9e..ce8e3bf703a 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateDataset.java +++ b/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateDataset.java @@ -65,17 +65,6 @@ static void createDataset(String projectId, String displayName) { String[] names = createdDataset.getName().split("/"); String datasetId = names[names.length - 1]; System.out.format("Dataset id: %s\n", datasetId); - System.out.format("Dataset display name: %s\n", createdDataset.getDisplayName()); - System.out.println("Translation dataset Metadata:"); - System.out.format( - "\tSource language code: %s\n", - createdDataset.getTranslationDatasetMetadata().getSourceLanguageCode()); - System.out.format( - "\tTarget language code: %s\n", - createdDataset.getTranslationDatasetMetadata().getTargetLanguageCode()); - System.out.println("Dataset create time:"); - System.out.format("\tseconds: %s\n", createdDataset.getCreateTime().getSeconds()); - System.out.format("\tnanos: %s\n", createdDataset.getCreateTime().getNanos()); } catch (IOException | InterruptedException | ExecutionException e) { e.printStackTrace(); } From 2e65f1d1ea22d0e1ea44556a5a72c47469a4cd24 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Tue, 29 Oct 2019 11:24:58 -0600 Subject: [PATCH 6/8] Update pom to Java 11 --- automl/cloud-client/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automl/cloud-client/pom.xml b/automl/cloud-client/pom.xml index 8ada1bcd2bf..b5005d21460 100644 --- a/automl/cloud-client/pom.xml +++ b/automl/cloud-client/pom.xml @@ -27,8 +27,8 @@ - 1.8 - 1.8 + 1.11 + 1.11 UTF-8 From 5fd75dc2fa61b8b17499a1b7451aa0d06995c9c6 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Thu, 31 Oct 2019 11:06:17 -0600 Subject: [PATCH 7/8] Update samples to new format --- .../com/example/automl/DeleteDataset.java | 10 +++++++--- .../java/com/example/automl/DeleteModel.java | 10 +++++++--- .../com/example/automl/ExportDataset.java | 12 +++++++---- .../java/com/example/automl/GetDataset.java | 10 +++++++--- .../java/com/example/automl/GetModel.java | 10 +++++++--- .../example/automl/GetModelEvaluation.java | 12 +++++++---- .../example/automl/GetOperationStatus.java | 10 +++++++--- .../com/example/automl/ImportDataset.java | 20 +++++++++++-------- .../java/com/example/automl/ListDatasets.java | 8 ++++++-- .../example/automl/ListModelEvaluations.java | 10 +++++++--- .../java/com/example/automl/ListModels.java | 8 ++++++-- .../example/automl/ListOperationStatus.java | 8 ++++++-- .../automl/TranslateCreateDataset.java | 10 +++++++--- .../example/automl/TranslateCreateModel.java | 12 +++++++---- .../com/example/automl/TranslatePredict.java | 12 +++++++---- 15 files changed, 111 insertions(+), 51 deletions(-) diff --git a/automl/cloud-client/src/main/java/com/example/automl/DeleteDataset.java b/automl/cloud-client/src/main/java/com/example/automl/DeleteDataset.java index b9fefbea4ec..2ade3522ca0 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/DeleteDataset.java +++ b/automl/cloud-client/src/main/java/com/example/automl/DeleteDataset.java @@ -26,11 +26,15 @@ class DeleteDataset { + static void deleteDataset() { + // TODO(developer): Replace these variables before running the sample. + String projectId = "YOUR_PROJECT_ID"; + String datasetId = "YOUR_DATASET_ID"; + deleteDataset(projectId, datasetId); + } + // Delete a dataset static void deleteDataset(String projectId, String datasetId) { - // String projectId = "YOUR_PROJECT_ID"; - // String datasetId = "YOUR_DATASET_ID"; - // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. diff --git a/automl/cloud-client/src/main/java/com/example/automl/DeleteModel.java b/automl/cloud-client/src/main/java/com/example/automl/DeleteModel.java index fcb802bf68c..03813c3d80a 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/DeleteModel.java +++ b/automl/cloud-client/src/main/java/com/example/automl/DeleteModel.java @@ -26,11 +26,15 @@ class DeleteModel { + static void deleteModel() { + // TODO(developer): Replace these variables before running the sample. + String projectId = "YOUR_PROJECT_ID"; + String modelId = "YOUR_MODEL_ID"; + deleteModel(projectId, modelId); + } + // Get a model static void deleteModel(String projectId, String modelId) { - // String projectId = "YOUR_PROJECT_ID"; - // String modelId = "YOUR_MODEL_ID"; - // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. diff --git a/automl/cloud-client/src/main/java/com/example/automl/ExportDataset.java b/automl/cloud-client/src/main/java/com/example/automl/ExportDataset.java index 03dbc553632..a22d920983c 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/ExportDataset.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ExportDataset.java @@ -28,12 +28,16 @@ class ExportDataset { + static void exportDataset() { + // TODO(developer): Replace these variables before running the sample. + String projectId = "YOUR_PROJECT_ID"; + String datasetId = "YOUR_DATASET_ID"; + String gcsUri = "gs://BUCKET_ID/path_to_export/"; + exportDataset(projectId, datasetId, gcsUri); + } + // Export a dataset static void exportDataset(String projectId, String datasetId, String gcsUri) { - // String projectId = "YOUR_PROJECT_ID"; - // String datasetId = "YOUR_DATASET_ID"; - // String gcsUri = "gs://BUCKET_ID/path_to_export/"; - // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. diff --git a/automl/cloud-client/src/main/java/com/example/automl/GetDataset.java b/automl/cloud-client/src/main/java/com/example/automl/GetDataset.java index 704edee8cf4..4f5826a19bc 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/GetDataset.java +++ b/automl/cloud-client/src/main/java/com/example/automl/GetDataset.java @@ -25,11 +25,15 @@ class GetDataset { + static void getDataset() { + // TODO(developer): Replace these variables before running the sample. + String projectId = "YOUR_PROJECT_ID"; + String datasetId = "YOUR_DATASET_ID"; + getDataset(projectId, datasetId); + } + // Get a dataset static void getDataset(String projectId, String datasetId) { - // String projectId = "YOUR_PROJECT_ID"; - // String datasetId = "YOUR_DATASET_ID"; - // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. diff --git a/automl/cloud-client/src/main/java/com/example/automl/GetModel.java b/automl/cloud-client/src/main/java/com/example/automl/GetModel.java index 4b80d34f226..de08a6de84d 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/GetModel.java +++ b/automl/cloud-client/src/main/java/com/example/automl/GetModel.java @@ -25,11 +25,15 @@ class GetModel { + static void getModel() { + // TODO(developer): Replace these variables before running the sample. + String projectId = "YOUR_PROJECT_ID"; + String modelId = "YOUR_MODEL_ID"; + getModel(projectId, modelId); + } + // Get a model static void getModel(String projectId, String modelId) { - // String projectId = "YOUR_PROJECT_ID"; - // String modelId = "YOUR_MODEL_ID"; - // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. diff --git a/automl/cloud-client/src/main/java/com/example/automl/GetModelEvaluation.java b/automl/cloud-client/src/main/java/com/example/automl/GetModelEvaluation.java index 8364dc2926d..be89b11ad40 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/GetModelEvaluation.java +++ b/automl/cloud-client/src/main/java/com/example/automl/GetModelEvaluation.java @@ -25,12 +25,16 @@ class GetModelEvaluation { + static void getModelEvaluation() { + // TODO(developer): Replace these variables before running the sample. + String projectId = "YOUR_PROJECT_ID"; + String modelId = "YOUR_MODEL_ID"; + String modelEvaluationId = "YOUR_MODEL_EVALUATION_ID"; + getModelEvaluation(projectId, modelId, modelEvaluationId); + } + // Get a model evaluation static void getModelEvaluation(String projectId, String modelId, String modelEvaluationId) { - // String projectId = "YOUR_PROJECT_ID"; - // String modelId = "YOUR_MODEL_ID"; - // String modelEvaluationId = "YOUR_MODEL_EVALUATION_ID"; - // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. diff --git a/automl/cloud-client/src/main/java/com/example/automl/GetOperationStatus.java b/automl/cloud-client/src/main/java/com/example/automl/GetOperationStatus.java index e40716e8ca8..639a95827a8 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/GetOperationStatus.java +++ b/automl/cloud-client/src/main/java/com/example/automl/GetOperationStatus.java @@ -24,11 +24,15 @@ class GetOperationStatus { + static void getOperationStatus() { + // TODO(developer): Replace these variables before running the sample. + String operationFullId = + "projects/[projectId]/locations/us-central1/operations/[operationId]"; + getOperationStatus(operationFullId); + } + // Get the status of an operation static void getOperationStatus(String operationFullId) { - // String operationFullId = - // "projects/[projectId]/locations/us-central1/operations/[operationId]"; - // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. diff --git a/automl/cloud-client/src/main/java/com/example/automl/ImportDataset.java b/automl/cloud-client/src/main/java/com/example/automl/ImportDataset.java index 0e1075f7c91..5e2c22df289 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/ImportDataset.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ImportDataset.java @@ -29,15 +29,19 @@ class ImportDataset { - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - static void importDataset(String projectId, String datasetId, String path) { - // String projectId = "YOUR_PROJECT_ID"; - // String datasetId = "YOUR_DATASET_ID"; - // String path = "gs://BUCKET_ID/path_to_training_data.csv"; + static void importDataset() { + // TODO(developer): Replace these variables before running the sample. + String projectId = "YOUR_PROJECT_ID"; + String datasetId = "YOUR_DATASET_ID"; + String path = "gs://BUCKET_ID/path_to_training_data.csv"; + importDataset(projectId, datasetId, path); + } - // Instantiates a client + // Import a dataset + static void importDataset(String projectId, String datasetId, String path) { + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. After completing all of your requests, call + // the "close" method on the client to safely clean up any remaining background resources. try (AutoMlClient client = AutoMlClient.create()) { // Get the complete path of the dataset. DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId); diff --git a/automl/cloud-client/src/main/java/com/example/automl/ListDatasets.java b/automl/cloud-client/src/main/java/com/example/automl/ListDatasets.java index aca4b11fea9..8453d54be32 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/ListDatasets.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ListDatasets.java @@ -26,10 +26,14 @@ class ListDatasets { + static void listDatasets() { + // TODO(developer): Replace these variables before running the sample. + String projectId = "YOUR_PROJECT_ID"; + listDatasets(projectId); + } + // List the datasets static void listDatasets(String projectId) { - // String projectId = "YOUR_PROJECT_ID"; - // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. diff --git a/automl/cloud-client/src/main/java/com/example/automl/ListModelEvaluations.java b/automl/cloud-client/src/main/java/com/example/automl/ListModelEvaluations.java index 0cbcacc93da..c90519f59f5 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/ListModelEvaluations.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ListModelEvaluations.java @@ -26,11 +26,15 @@ class ListModelEvaluations { + static void listModelEvaluations() { + // TODO(developer): Replace these variables before running the sample. + String projectId = "YOUR_PROJECT_ID"; + String modelId = "YOUR_MODEL_ID"; + listModelEvaluations(projectId, modelId); + } + // List model evaluations static void listModelEvaluations(String projectId, String modelId) { - // String projectId = "YOUR_PROJECT_ID"; - // String modelId = "YOUR_MODEL_ID"; - // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. diff --git a/automl/cloud-client/src/main/java/com/example/automl/ListModels.java b/automl/cloud-client/src/main/java/com/example/automl/ListModels.java index 596e45a09c2..454a9abf64f 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/ListModels.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ListModels.java @@ -26,10 +26,14 @@ class ListModels { + static void listModels() { + // TODO(developer): Replace these variables before running the sample. + String projectId = "YOUR_PROJECT_ID"; + listModels(projectId); + } + // List models static void listModels(String projectId) { - // String projectId = "YOUR_PROJECT_ID"; - // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. diff --git a/automl/cloud-client/src/main/java/com/example/automl/ListOperationStatus.java b/automl/cloud-client/src/main/java/com/example/automl/ListOperationStatus.java index 11299072757..02cef5420a4 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/ListOperationStatus.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ListOperationStatus.java @@ -26,10 +26,14 @@ class ListOperationStatus { + static void listOperationStatus() { + // TODO(developer): Replace these variables before running the sample. + String projectId = "YOUR_PROJECT_ID"; + listOperationStatus(projectId); + } + // Get the status of an operation static void listOperationStatus(String projectId) { - // String projectId = "YOUR_PROJECT_ID"; - // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. diff --git a/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateDataset.java b/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateDataset.java index ce8e3bf703a..836a166537d 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateDataset.java +++ b/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateDataset.java @@ -29,11 +29,15 @@ class TranslateCreateDataset { + static void createDataset() { + // TODO(developer): Replace these variables before running the sample. + String projectId = "YOUR_PROJECT_ID"; + String displayName = "YOUR_DATASET_NAME"; + createDataset(projectId, displayName); + } + // Create a dataset static void createDataset(String projectId, String displayName) { - // String projectId = "YOUR_PROJECT_ID"; - // String displayName = "YOUR_DATASET_NAME"; - // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. diff --git a/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateModel.java b/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateModel.java index 636d86c86b9..3237074688d 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateModel.java +++ b/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateModel.java @@ -29,12 +29,16 @@ class TranslateCreateModel { + static void createModel() { + // TODO(developer): Replace these variables before running the sample. + String projectId = "YOUR_PROJECT_ID"; + String datasetId = "YOUR_DATASET_ID"; + String displayName = "YOUR_DATASET_NAME"; + createModel(projectId, datasetId, displayName); + } + // Create a model static void createModel(String projectId, String datasetId, String displayName) { - // String projectId = "YOUR_PROJECT_ID"; - // String datasetId = "YOUR_DATASET_ID"; - // String displayName = "YOUR_DATASET_NAME"; - // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. diff --git a/automl/cloud-client/src/main/java/com/example/automl/TranslatePredict.java b/automl/cloud-client/src/main/java/com/example/automl/TranslatePredict.java index 359aed66a51..0003a979242 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/TranslatePredict.java +++ b/automl/cloud-client/src/main/java/com/example/automl/TranslatePredict.java @@ -30,12 +30,16 @@ class TranslatePredict { + static void predict() { + // TODO(developer): Replace these variables before running the sample. + String projectId = "YOUR_PROJECT_ID"; + String modelId = "YOUR_MODEL_ID"; + String filePath = "path_to_local_file.txt"; + predict(projectId, modelId, filePath); + } + // Predict static void predict(String projectId, String modelId, String filePath) { - // String projectId = "YOUR_PROJECT_ID"; - // String modelId = "YOUR_MODEL_ID"; - // String filePath = "path_to_local_file.txt"; - // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. From 5ffeb2f546e338792de7a20201573cf19a3d08e1 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Thu, 31 Oct 2019 11:40:16 -0600 Subject: [PATCH 8/8] Use throw exception instead of catch --- .../main/java/com/example/automl/DeleteDataset.java | 7 +++---- .../main/java/com/example/automl/DeleteModel.java | 7 +++---- .../main/java/com/example/automl/ExportDataset.java | 7 +++---- .../main/java/com/example/automl/GetDataset.java | 13 ++++++------- .../src/main/java/com/example/automl/GetModel.java | 6 ++---- .../java/com/example/automl/GetModelEvaluation.java | 7 +++---- .../java/com/example/automl/GetOperationStatus.java | 9 +++------ .../main/java/com/example/automl/ImportDataset.java | 7 +++---- .../main/java/com/example/automl/ListDatasets.java | 6 ++---- .../com/example/automl/ListModelEvaluations.java | 6 ++---- .../main/java/com/example/automl/ListModels.java | 6 ++---- .../com/example/automl/ListOperationStatus.java | 6 ++---- .../com/example/automl/TranslateCreateDataset.java | 7 +++---- .../com/example/automl/TranslateCreateModel.java | 7 +++---- .../java/com/example/automl/TranslatePredict.java | 6 ++---- .../automl/TranslateDatasetManagementIT.java | 11 +++++++---- .../example/automl/TranslateModelManagementIT.java | 7 ++++--- .../java/com/example/automl/TranslatePredictIT.java | 5 +++-- 18 files changed, 56 insertions(+), 74 deletions(-) diff --git a/automl/cloud-client/src/main/java/com/example/automl/DeleteDataset.java b/automl/cloud-client/src/main/java/com/example/automl/DeleteDataset.java index 2ade3522ca0..9c8660b24e9 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/DeleteDataset.java +++ b/automl/cloud-client/src/main/java/com/example/automl/DeleteDataset.java @@ -26,7 +26,7 @@ class DeleteDataset { - static void deleteDataset() { + static void deleteDataset() throws IOException, ExecutionException, InterruptedException { // TODO(developer): Replace these variables before running the sample. String projectId = "YOUR_PROJECT_ID"; String datasetId = "YOUR_DATASET_ID"; @@ -34,7 +34,8 @@ static void deleteDataset() { } // Delete a dataset - static void deleteDataset(String projectId, String datasetId) { + static void deleteDataset(String projectId, String datasetId) + throws IOException, ExecutionException, InterruptedException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. @@ -43,8 +44,6 @@ static void deleteDataset(String projectId, String datasetId) { DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId); Empty response = client.deleteDatasetAsync(datasetFullId).get(); System.out.format("Dataset deleted. %s\n", response); - } catch (IOException | InterruptedException | ExecutionException e) { - e.printStackTrace(); } } } diff --git a/automl/cloud-client/src/main/java/com/example/automl/DeleteModel.java b/automl/cloud-client/src/main/java/com/example/automl/DeleteModel.java index 03813c3d80a..e885db9dc91 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/DeleteModel.java +++ b/automl/cloud-client/src/main/java/com/example/automl/DeleteModel.java @@ -26,7 +26,7 @@ class DeleteModel { - static void deleteModel() { + static void deleteModel() throws IOException, ExecutionException, InterruptedException { // TODO(developer): Replace these variables before running the sample. String projectId = "YOUR_PROJECT_ID"; String modelId = "YOUR_MODEL_ID"; @@ -34,7 +34,8 @@ static void deleteModel() { } // Get a model - static void deleteModel(String projectId, String modelId) { + static void deleteModel(String projectId, String modelId) + throws IOException, ExecutionException, InterruptedException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. @@ -47,8 +48,6 @@ static void deleteModel(String projectId, String modelId) { System.out.println("Model deletion started..."); System.out.println(String.format("Model deleted. %s", response)); - } catch (IOException | InterruptedException | ExecutionException e) { - e.printStackTrace(); } } } diff --git a/automl/cloud-client/src/main/java/com/example/automl/ExportDataset.java b/automl/cloud-client/src/main/java/com/example/automl/ExportDataset.java index a22d920983c..ae8818d97ad 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/ExportDataset.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ExportDataset.java @@ -28,7 +28,7 @@ class ExportDataset { - static void exportDataset() { + static void exportDataset() throws IOException, ExecutionException, InterruptedException { // TODO(developer): Replace these variables before running the sample. String projectId = "YOUR_PROJECT_ID"; String datasetId = "YOUR_DATASET_ID"; @@ -37,7 +37,8 @@ static void exportDataset() { } // Export a dataset - static void exportDataset(String projectId, String datasetId, String gcsUri) { + static void exportDataset(String projectId, String datasetId, String gcsUri) + throws IOException, ExecutionException, InterruptedException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. @@ -54,8 +55,6 @@ static void exportDataset(String projectId, String datasetId, String gcsUri) { System.out.println("Processing export..."); Empty response = client.exportDataAsync(datasetFullId, outputConfig).get(); System.out.format("Dataset exported. %s\n", response); - } catch (IOException | InterruptedException | ExecutionException e) { - e.printStackTrace(); } } } diff --git a/automl/cloud-client/src/main/java/com/example/automl/GetDataset.java b/automl/cloud-client/src/main/java/com/example/automl/GetDataset.java index 4f5826a19bc..4e8d36117b7 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/GetDataset.java +++ b/automl/cloud-client/src/main/java/com/example/automl/GetDataset.java @@ -17,6 +17,7 @@ package com.example.automl; // [START automl_translate_get_dataset] + import com.google.cloud.automl.v1.AutoMlClient; import com.google.cloud.automl.v1.Dataset; import com.google.cloud.automl.v1.DatasetName; @@ -25,15 +26,15 @@ class GetDataset { - static void getDataset() { + static void getDataset() throws IOException { // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String datasetId = "YOUR_DATASET_ID"; - getDataset(projectId, datasetId); + String projectId = "YOUR_PROJECT_ID"; + String datasetId = "YOUR_DATASET_ID"; + getDataset(projectId, datasetId); } // Get a dataset - static void getDataset(String projectId, String datasetId) { + static void getDataset(String projectId, String datasetId) throws IOException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. @@ -61,8 +62,6 @@ static void getDataset(String projectId, String datasetId) { System.out.println("Dataset create time:"); System.out.format("\tseconds: %s\n", dataset.getCreateTime().getSeconds()); System.out.format("\tnanos: %s\n", dataset.getCreateTime().getNanos()); - } catch (IOException e) { - e.printStackTrace(); } } } diff --git a/automl/cloud-client/src/main/java/com/example/automl/GetModel.java b/automl/cloud-client/src/main/java/com/example/automl/GetModel.java index de08a6de84d..e555a700fdb 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/GetModel.java +++ b/automl/cloud-client/src/main/java/com/example/automl/GetModel.java @@ -25,7 +25,7 @@ class GetModel { - static void getModel() { + static void getModel() throws IOException { // TODO(developer): Replace these variables before running the sample. String projectId = "YOUR_PROJECT_ID"; String modelId = "YOUR_MODEL_ID"; @@ -33,7 +33,7 @@ static void getModel() { } // Get a model - static void getModel(String projectId, String modelId) { + static void getModel(String projectId, String modelId) throws IOException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. @@ -55,8 +55,6 @@ static void getModel(String projectId, String modelId) { System.out.format("\tseconds: %s\n", model.getCreateTime().getSeconds()); System.out.format("\tnanos: %s\n", model.getCreateTime().getNanos()); System.out.format("Model deployment state: %s\n", model.getDeploymentState()); - } catch (IOException e) { - e.printStackTrace(); } } } diff --git a/automl/cloud-client/src/main/java/com/example/automl/GetModelEvaluation.java b/automl/cloud-client/src/main/java/com/example/automl/GetModelEvaluation.java index be89b11ad40..3048f6648a4 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/GetModelEvaluation.java +++ b/automl/cloud-client/src/main/java/com/example/automl/GetModelEvaluation.java @@ -25,7 +25,7 @@ class GetModelEvaluation { - static void getModelEvaluation() { + static void getModelEvaluation() throws IOException { // TODO(developer): Replace these variables before running the sample. String projectId = "YOUR_PROJECT_ID"; String modelId = "YOUR_MODEL_ID"; @@ -34,7 +34,8 @@ static void getModelEvaluation() { } // Get a model evaluation - static void getModelEvaluation(String projectId, String modelId, String modelEvaluationId) { + static void getModelEvaluation(String projectId, String modelId, String modelEvaluationId) + throws IOException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. @@ -55,8 +56,6 @@ static void getModelEvaluation(String projectId, String modelId, String modelEva "Evalution Example Count: %d\n", modelEvaluation.getEvaluatedExampleCount()); System.out.format( "Model Evaluation Metrics: %s\n", modelEvaluation.getTranslationEvaluationMetrics()); - } catch (IOException e) { - e.printStackTrace(); } } } diff --git a/automl/cloud-client/src/main/java/com/example/automl/GetOperationStatus.java b/automl/cloud-client/src/main/java/com/example/automl/GetOperationStatus.java index 639a95827a8..5c12d41f0e2 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/GetOperationStatus.java +++ b/automl/cloud-client/src/main/java/com/example/automl/GetOperationStatus.java @@ -24,15 +24,14 @@ class GetOperationStatus { - static void getOperationStatus() { + static void getOperationStatus() throws IOException { // TODO(developer): Replace these variables before running the sample. - String operationFullId = - "projects/[projectId]/locations/us-central1/operations/[operationId]"; + String operationFullId = "projects/[projectId]/locations/us-central1/operations/[operationId]"; getOperationStatus(operationFullId); } // Get the status of an operation - static void getOperationStatus(String operationFullId) { + static void getOperationStatus(String operationFullId) throws IOException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. @@ -53,8 +52,6 @@ static void getOperationStatus(String operationFullId) { System.out.format("\t\tError code: %s\n", operation.getError().getCode()); System.out.format("\t\tError message: %s\n", operation.getError().getMessage()); } - } catch (IOException e) { - e.printStackTrace(); } } } diff --git a/automl/cloud-client/src/main/java/com/example/automl/ImportDataset.java b/automl/cloud-client/src/main/java/com/example/automl/ImportDataset.java index 5e2c22df289..2b40ef33f4d 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/ImportDataset.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ImportDataset.java @@ -29,7 +29,7 @@ class ImportDataset { - static void importDataset() { + static void importDataset() throws IOException, ExecutionException, InterruptedException { // TODO(developer): Replace these variables before running the sample. String projectId = "YOUR_PROJECT_ID"; String datasetId = "YOUR_DATASET_ID"; @@ -38,7 +38,8 @@ static void importDataset() { } // Import a dataset - static void importDataset(String projectId, String datasetId, String path) { + static void importDataset(String projectId, String datasetId, String path) + throws IOException, ExecutionException, InterruptedException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. @@ -56,8 +57,6 @@ static void importDataset(String projectId, String datasetId, String path) { Empty response = client.importDataAsync(datasetFullId, inputConfig).get(); System.out.format("Dataset imported. %s\n", response); - } catch (IOException | InterruptedException | ExecutionException e) { - e.printStackTrace(); } } } diff --git a/automl/cloud-client/src/main/java/com/example/automl/ListDatasets.java b/automl/cloud-client/src/main/java/com/example/automl/ListDatasets.java index 8453d54be32..aca86c1c7f1 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/ListDatasets.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ListDatasets.java @@ -26,14 +26,14 @@ class ListDatasets { - static void listDatasets() { + static void listDatasets() throws IOException { // TODO(developer): Replace these variables before running the sample. String projectId = "YOUR_PROJECT_ID"; listDatasets(projectId); } // List the datasets - static void listDatasets(String projectId) { + static void listDatasets(String projectId) throws IOException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. @@ -69,8 +69,6 @@ static void listDatasets(String projectId) { System.out.format("\tseconds: %s\n", dataset.getCreateTime().getSeconds()); System.out.format("\tnanos: %s\n", dataset.getCreateTime().getNanos()); } - } catch (IOException e) { - e.printStackTrace(); } } } diff --git a/automl/cloud-client/src/main/java/com/example/automl/ListModelEvaluations.java b/automl/cloud-client/src/main/java/com/example/automl/ListModelEvaluations.java index c90519f59f5..8172f9dfc00 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/ListModelEvaluations.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ListModelEvaluations.java @@ -26,7 +26,7 @@ class ListModelEvaluations { - static void listModelEvaluations() { + static void listModelEvaluations() throws IOException { // TODO(developer): Replace these variables before running the sample. String projectId = "YOUR_PROJECT_ID"; String modelId = "YOUR_MODEL_ID"; @@ -34,7 +34,7 @@ static void listModelEvaluations() { } // List model evaluations - static void listModelEvaluations(String projectId, String modelId) { + static void listModelEvaluations(String projectId, String modelId) throws IOException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. @@ -59,8 +59,6 @@ static void listModelEvaluations(String projectId, String modelId) { System.out.format( "Model Evaluation Metrics: %s\n\n", modelEvaluation.getTranslationEvaluationMetrics()); } - } catch (IOException e) { - e.printStackTrace(); } } } diff --git a/automl/cloud-client/src/main/java/com/example/automl/ListModels.java b/automl/cloud-client/src/main/java/com/example/automl/ListModels.java index 454a9abf64f..67644664397 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/ListModels.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ListModels.java @@ -26,14 +26,14 @@ class ListModels { - static void listModels() { + static void listModels() throws IOException { // TODO(developer): Replace these variables before running the sample. String projectId = "YOUR_PROJECT_ID"; listModels(projectId); } // List models - static void listModels(String projectId) { + static void listModels(String projectId) throws IOException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. @@ -65,8 +65,6 @@ static void listModels(String projectId) { System.out.format("\tnanos: %s\n", model.getCreateTime().getNanos()); System.out.format("Model deployment state: %s\n", model.getDeploymentState()); } - } catch (IOException e) { - e.printStackTrace(); } } } diff --git a/automl/cloud-client/src/main/java/com/example/automl/ListOperationStatus.java b/automl/cloud-client/src/main/java/com/example/automl/ListOperationStatus.java index 02cef5420a4..c26ca327704 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/ListOperationStatus.java +++ b/automl/cloud-client/src/main/java/com/example/automl/ListOperationStatus.java @@ -26,14 +26,14 @@ class ListOperationStatus { - static void listOperationStatus() { + static void listOperationStatus() throws IOException { // TODO(developer): Replace these variables before running the sample. String projectId = "YOUR_PROJECT_ID"; listOperationStatus(projectId); } // Get the status of an operation - static void listOperationStatus(String projectId) { + static void listOperationStatus(String projectId) throws IOException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. @@ -61,8 +61,6 @@ static void listOperationStatus(String projectId) { System.out.format("\t\tError message: %s\n\n", operation.getError().getMessage()); } } - } catch (IOException e) { - e.printStackTrace(); } } } diff --git a/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateDataset.java b/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateDataset.java index 836a166537d..103ea1eca86 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateDataset.java +++ b/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateDataset.java @@ -29,7 +29,7 @@ class TranslateCreateDataset { - static void createDataset() { + static void createDataset() throws IOException, ExecutionException, InterruptedException { // TODO(developer): Replace these variables before running the sample. String projectId = "YOUR_PROJECT_ID"; String displayName = "YOUR_DATASET_NAME"; @@ -37,7 +37,8 @@ static void createDataset() { } // Create a dataset - static void createDataset(String projectId, String displayName) { + static void createDataset(String projectId, String displayName) + throws IOException, ExecutionException, InterruptedException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. @@ -69,8 +70,6 @@ static void createDataset(String projectId, String displayName) { String[] names = createdDataset.getName().split("/"); String datasetId = names[names.length - 1]; System.out.format("Dataset id: %s\n", datasetId); - } catch (IOException | InterruptedException | ExecutionException e) { - e.printStackTrace(); } } } diff --git a/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateModel.java b/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateModel.java index 3237074688d..2fca0c38905 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateModel.java +++ b/automl/cloud-client/src/main/java/com/example/automl/TranslateCreateModel.java @@ -29,7 +29,7 @@ class TranslateCreateModel { - static void createModel() { + static void createModel() throws IOException, ExecutionException, InterruptedException { // TODO(developer): Replace these variables before running the sample. String projectId = "YOUR_PROJECT_ID"; String datasetId = "YOUR_DATASET_ID"; @@ -38,7 +38,8 @@ static void createModel() { } // Create a model - static void createModel(String projectId, String datasetId, String displayName) { + static void createModel(String projectId, String datasetId, String displayName) + throws IOException, ExecutionException, InterruptedException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. @@ -60,8 +61,6 @@ static void createModel(String projectId, String datasetId, String displayName) client.createModelAsync(projectLocation, model); System.out.format("Training operation name: %s\n", future.getInitialFuture().get().getName()); System.out.println("Training started..."); - } catch (IOException | InterruptedException | ExecutionException e) { - e.printStackTrace(); } } } diff --git a/automl/cloud-client/src/main/java/com/example/automl/TranslatePredict.java b/automl/cloud-client/src/main/java/com/example/automl/TranslatePredict.java index 0003a979242..ccd2aaa1a4e 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/TranslatePredict.java +++ b/automl/cloud-client/src/main/java/com/example/automl/TranslatePredict.java @@ -30,7 +30,7 @@ class TranslatePredict { - static void predict() { + static void predict() throws IOException { // TODO(developer): Replace these variables before running the sample. String projectId = "YOUR_PROJECT_ID"; String modelId = "YOUR_MODEL_ID"; @@ -39,7 +39,7 @@ static void predict() { } // Predict - static void predict(String projectId, String modelId, String filePath) { + static void predict(String projectId, String modelId, String filePath) throws IOException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. @@ -58,8 +58,6 @@ static void predict(String projectId, String modelId, String filePath) { TextSnippet translatedContent = response.getPayload(0).getTranslation().getTranslatedContent(); System.out.println(String.format("Translated Content: %s", translatedContent.getContent())); - } catch (IOException e) { - e.printStackTrace(); } } } diff --git a/automl/cloud-client/src/test/java/com/example/automl/TranslateDatasetManagementIT.java b/automl/cloud-client/src/test/java/com/example/automl/TranslateDatasetManagementIT.java index 3a21f40dcbc..d7589a6cbde 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/TranslateDatasetManagementIT.java +++ b/automl/cloud-client/src/test/java/com/example/automl/TranslateDatasetManagementIT.java @@ -24,8 +24,10 @@ import com.google.cloud.storage.StorageOptions; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.PrintStream; import java.util.UUID; +import java.util.concurrent.ExecutionException; import org.junit.After; import org.junit.Before; @@ -58,7 +60,8 @@ public void tearDown() { } @Test - public void testCreateImportDeleteDataset() { + public void testCreateImportDeleteDataset() + throws IOException, ExecutionException, InterruptedException { // Create a random dataset name with a length of 32 characters (max allowed by AutoML) // To prevent name collisions when running tests in multiple java versions at once. // AutoML doesn't allow "-", but accepts "_" @@ -88,7 +91,7 @@ public void testCreateImportDeleteDataset() { } @Test - public void testListDataset() { + public void testListDataset() throws IOException { // Act ListDatasets.listDatasets(PROJECT_ID); @@ -98,7 +101,7 @@ public void testListDataset() { } @Test - public void testGetDataset() { + public void testGetDataset() throws IOException { // Act GetDataset.getDataset(PROJECT_ID, getdatasetId); @@ -109,7 +112,7 @@ public void testGetDataset() { } @Test - public void testExportDataset() { + public void testExportDataset() throws IOException, ExecutionException, InterruptedException { ExportDataset.exportDataset(PROJECT_ID, getdatasetId, BUCKET + "/TEST_EXPORT_OUTPUT/"); Storage storage = StorageOptions.getDefaultInstance().getService(); diff --git a/automl/cloud-client/src/test/java/com/example/automl/TranslateModelManagementIT.java b/automl/cloud-client/src/test/java/com/example/automl/TranslateModelManagementIT.java index c8fb1da96c6..fe3ae302ac8 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/TranslateModelManagementIT.java +++ b/automl/cloud-client/src/test/java/com/example/automl/TranslateModelManagementIT.java @@ -23,6 +23,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.util.concurrent.ExecutionException; import org.junit.After; import org.junit.Before; @@ -54,7 +55,7 @@ public void tearDown() { } @Test - public void testModelApi() { + public void testModelApi() throws IOException { // LIST MODELS ListModels.listModels(PROJECT_ID); String got = bout.toString(); @@ -88,7 +89,7 @@ public void testModelApi() { } @Test - public void testOperationStatus() { + public void testOperationStatus() throws IOException { // Act ListOperationStatus.listOperationStatus(PROJECT_ID); @@ -107,7 +108,7 @@ public void testOperationStatus() { } @Test - public void testCreateModel() throws IOException { + public void testCreateModel() throws IOException, ExecutionException, InterruptedException { TranslateCreateModel.createModel(PROJECT_ID, DATASET_ID, MODEL_NAME); String got = bout.toString(); diff --git a/automl/cloud-client/src/test/java/com/example/automl/TranslatePredictIT.java b/automl/cloud-client/src/test/java/com/example/automl/TranslatePredictIT.java index 65ee34e8ae4..e56ec6d6dec 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/TranslatePredictIT.java +++ b/automl/cloud-client/src/test/java/com/example/automl/TranslatePredictIT.java @@ -19,7 +19,9 @@ import static com.google.common.truth.Truth.assertThat; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.PrintStream; +import java.util.concurrent.ExecutionException; import org.junit.After; import org.junit.Before; @@ -31,7 +33,6 @@ @RunWith(JUnit4.class) @SuppressWarnings("checkstyle:abbreviationaswordinname") public class TranslatePredictIT { - private static final String COMPUTE_REGION = "us-central1"; private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); private static final String modelId = "TRL2188848820815848149"; private static final String filePath = "./resources/input.txt"; @@ -51,7 +52,7 @@ public void tearDown() { } @Test - public void testPredict() { + public void testPredict() throws IOException { // Act TranslatePredict.predict(PROJECT_ID, modelId, filePath);