diff --git a/README.md b/README.md index cfa0b41b9..66518efbd 100644 --- a/README.md +++ b/README.md @@ -75,20 +75,20 @@ If you are using Maven without BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies: ```Groovy -implementation platform('com.google.cloud:libraries-bom:26.1.4') +implementation platform('com.google.cloud:libraries-bom:26.1.5') implementation 'com.google.cloud:google-cloud-automl' ``` If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-automl:2.5.0' +implementation 'com.google.cloud:google-cloud-automl:2.6.0' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-automl" % "2.5.0" +libraryDependencies += "com.google.cloud" % "google-cloud-automl" % "2.6.0" ``` ## Authentication @@ -143,74 +143,12 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-automl/tree/m | Sample | Source Code | Try it | | --------------------------- | --------------------------------- | ------ | -| Batch Predict | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/BatchPredict.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/BatchPredict.java) | -| Cancel Operation | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/CancelOperation.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/CancelOperation.java) | -| Delete Dataset | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/DeleteDataset.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/DeleteDataset.java) | -| Delete Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/DeleteModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/DeleteModel.java) | -| Deploy Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/DeployModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/DeployModel.java) | -| Get Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/GetModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/GetModel.java) | -| Get Model Evaluation | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/GetModelEvaluation.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/GetModelEvaluation.java) | -| Get Operation Status | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/GetOperationStatus.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/GetOperationStatus.java) | -| Import Dataset | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/ImportDataset.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/ImportDataset.java) | -| List Datasets | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/ListDatasets.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/ListDatasets.java) | -| List Model Evaluations | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/ListModelEvaluations.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/ListModelEvaluations.java) | -| List Models | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/ListModels.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/ListModels.java) | -| Set Endpoint | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/SetEndpoint.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/SetEndpoint.java) | -| Tables Batch Predict Big Query | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/TablesBatchPredictBigQuery.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/TablesBatchPredictBigQuery.java) | -| Tables Create Dataset | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/TablesCreateDataset.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/TablesCreateDataset.java) | -| Tables Create Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/TablesCreateModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/TablesCreateModel.java) | -| Tables Get Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/TablesGetModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/TablesGetModel.java) | -| Tables Import Dataset | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/TablesImportDataset.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/TablesImportDataset.java) | -| Tables Predict | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/TablesPredict.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/TablesPredict.java) | -| Undeploy Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/UndeployModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/UndeployModel.java) | -| Video Classification Create Dataset | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/VideoClassificationCreateDataset.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/VideoClassificationCreateDataset.java) | -| Video Classification Create Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/VideoClassificationCreateModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/VideoClassificationCreateModel.java) | -| Video Object Tracking Create Dataset | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/VideoObjectTrackingCreateDataset.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/VideoObjectTrackingCreateDataset.java) | -| Video Object Tracking Create Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/beta/automl/VideoObjectTrackingCreateModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/beta/automl/VideoObjectTrackingCreateModel.java) | -| Batch Predict | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/BatchPredict.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/BatchPredict.java) | -| Delete Dataset | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/DeleteDataset.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/DeleteDataset.java) | -| Delete Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/DeleteModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/DeleteModel.java) | -| Deploy Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/DeployModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/DeployModel.java) | -| Export Dataset | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/ExportDataset.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/ExportDataset.java) | -| Get Dataset | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/GetDataset.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/GetDataset.java) | -| Get Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/GetModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/GetModel.java) | -| Get Model Evaluation | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/GetModelEvaluation.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/GetModelEvaluation.java) | -| Get Operation Status | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/GetOperationStatus.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/GetOperationStatus.java) | -| Import Dataset | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/ImportDataset.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/ImportDataset.java) | -| Language Entity Extraction Create Dataset | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/LanguageEntityExtractionCreateDataset.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/LanguageEntityExtractionCreateDataset.java) | -| Language Entity Extraction Create Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/LanguageEntityExtractionCreateModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/LanguageEntityExtractionCreateModel.java) | -| Language Entity Extraction Predict | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/LanguageEntityExtractionPredict.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/LanguageEntityExtractionPredict.java) | -| Language Sentiment Analysis Create Dataset | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/LanguageSentimentAnalysisCreateDataset.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/LanguageSentimentAnalysisCreateDataset.java) | -| Language Sentiment Analysis Create Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/LanguageSentimentAnalysisCreateModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/LanguageSentimentAnalysisCreateModel.java) | -| Language Sentiment Analysis Predict | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/LanguageSentimentAnalysisPredict.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/LanguageSentimentAnalysisPredict.java) | -| Language Text Classification Create Dataset | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/LanguageTextClassificationCreateDataset.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/LanguageTextClassificationCreateDataset.java) | -| Language Text Classification Create Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/LanguageTextClassificationCreateModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/LanguageTextClassificationCreateModel.java) | -| Language Text Classification Predict | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/LanguageTextClassificationPredict.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/LanguageTextClassificationPredict.java) | -| List Datasets | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/ListDatasets.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/ListDatasets.java) | -| List Model Evaluations | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/ListModelEvaluations.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/ListModelEvaluations.java) | -| List Models | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/ListModels.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/ListModels.java) | -| List Operation Status | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/ListOperationStatus.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/ListOperationStatus.java) | -| Translate Create Dataset | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/TranslateCreateDataset.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/TranslateCreateDataset.java) | -| Translate Create Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/TranslateCreateModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/TranslateCreateModel.java) | -| Translate Predict | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/TranslatePredict.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/TranslatePredict.java) | -| Undeploy Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/UndeployModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/UndeployModel.java) | -| Vision Classification Create Dataset | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/VisionClassificationCreateDataset.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/VisionClassificationCreateDataset.java) | -| Vision Classification Create Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/VisionClassificationCreateModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/VisionClassificationCreateModel.java) | -| Vision Classification Deploy Model Node Count | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/VisionClassificationDeployModelNodeCount.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/VisionClassificationDeployModelNodeCount.java) | -| Vision Classification Predict | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/VisionClassificationPredict.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/VisionClassificationPredict.java) | -| Vision Object Detection Create Dataset | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionCreateDataset.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionCreateDataset.java) | -| Vision Object Detection Create Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionCreateModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionCreateModel.java) | -| Vision Object Detection Deploy Model Node Count | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionDeployModelNodeCount.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionDeployModelNodeCount.java) | -| Vision Object Detection Predict | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionPredict.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionPredict.java) | | Dataset Api | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/google/cloud/translate/automl/DatasetApi.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/translate/automl/DatasetApi.java) | | Model Api | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/google/cloud/translate/automl/ModelApi.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/translate/automl/ModelApi.java) | | Classification Undeploy Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/google/cloud/vision/ClassificationUndeployModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/vision/ClassificationUndeployModel.java) | | Prediction Api | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/google/cloud/vision/PredictionApi.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/vision/PredictionApi.java) | -| Classification Deploy Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ClassificationDeployModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ClassificationDeployModel.java) | -| Classification Deploy Model Node Count | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ClassificationDeployModelNodeCount.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ClassificationDeployModelNodeCount.java) | | Classification Undeploy Model | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ClassificationUndeployModel.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ClassificationUndeployModel.java) | | Model Api | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ModelApi.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ModelApi.java) | -| Object Detection Deploy Model Node Count | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ObjectDetectionDeployModelNodeCount.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ObjectDetectionDeployModelNodeCount.java) | | Prediction Api | [source code](https://github.com/googleapis/java-automl/blob/main/samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/PredictionApi.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-automl&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/PredictionApi.java) | diff --git a/samples/snippets/src/main/java/beta/automl/BatchPredict.java b/samples/snippets/src/main/java/beta/automl/BatchPredict.java deleted file mode 100644 index 4684f7079..000000000 --- a/samples/snippets/src/main/java/beta/automl/BatchPredict.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_tables_batch_predict] -// [START automl_batch_predict_beta] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1beta1.BatchPredictInputConfig; -import com.google.cloud.automl.v1beta1.BatchPredictOutputConfig; -import com.google.cloud.automl.v1beta1.BatchPredictRequest; -import com.google.cloud.automl.v1beta1.BatchPredictResult; -import com.google.cloud.automl.v1beta1.GcsDestination; -import com.google.cloud.automl.v1beta1.GcsSource; -import com.google.cloud.automl.v1beta1.ModelName; -import com.google.cloud.automl.v1beta1.OperationMetadata; -import com.google.cloud.automl.v1beta1.PredictionServiceClient; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class BatchPredict { - - static void batchPredict() throws IOException, ExecutionException, InterruptedException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String modelId = "YOUR_MODEL_ID"; - String inputUri = "gs://YOUR_BUCKET_ID/path_to_your_input_csv_or_jsonl"; - String outputUri = "gs://YOUR_BUCKET_ID/path_to_save_results/"; - batchPredict(projectId, modelId, inputUri, outputUri); - } - - static void batchPredict(String projectId, String modelId, String inputUri, String outputUri) - 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. - try (PredictionServiceClient client = PredictionServiceClient.create()) { - // Get the full path of the model. - ModelName name = ModelName.of(projectId, "us-central1", modelId); - - // Configure the source of the file from a GCS bucket - GcsSource gcsSource = GcsSource.newBuilder().addInputUris(inputUri).build(); - BatchPredictInputConfig inputConfig = - BatchPredictInputConfig.newBuilder().setGcsSource(gcsSource).build(); - - // Configure where to store the output in a GCS bucket - GcsDestination gcsDestination = - GcsDestination.newBuilder().setOutputUriPrefix(outputUri).build(); - BatchPredictOutputConfig outputConfig = - BatchPredictOutputConfig.newBuilder().setGcsDestination(gcsDestination).build(); - - // Build the request that will be sent to the API - BatchPredictRequest request = - BatchPredictRequest.newBuilder() - .setName(name.toString()) - .setInputConfig(inputConfig) - .setOutputConfig(outputConfig) - .build(); - - // Start an asynchronous request - OperationFuture future = - client.batchPredictAsync(request); - - System.out.println("Waiting for operation to complete..."); - BatchPredictResult response = future.get(); - System.out.println("Batch Prediction results saved to specified Cloud Storage bucket."); - } - } -} -// [END automl_batch_predict_beta] -// [END automl_tables_batch_predict] diff --git a/samples/snippets/src/main/java/beta/automl/CancelOperation.java b/samples/snippets/src/main/java/beta/automl/CancelOperation.java deleted file mode 100644 index 1e0e4fd2a..000000000 --- a/samples/snippets/src/main/java/beta/automl/CancelOperation.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_cancel_operation_beta] - -import com.google.cloud.automl.v1beta1.AutoMlClient; -import io.grpc.StatusRuntimeException; -import java.io.IOException; - -class CancelOperation { - - static void cancelOperation() throws IOException, InterruptedException, StatusRuntimeException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String location = "us-central1"; - String operationId = "YOUR_OPERATION_ID"; - String operationFullId = - String.format("projects/%s/locations/%s/operations/%s", projectId, location, operationId); - cancelOperation(operationFullId); - } - - static void cancelOperation(String operationFullId) - throws IOException, InterruptedException, StatusRuntimeException { - // 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()) { - client.getOperationsClient().cancelOperation(operationFullId); - System.out.println("Operation cancelled"); - } - } -} -// [END automl_cancel_operation_beta] diff --git a/samples/snippets/src/main/java/beta/automl/DeleteDataset.java b/samples/snippets/src/main/java/beta/automl/DeleteDataset.java deleted file mode 100644 index 9ef47c5c2..000000000 --- a/samples/snippets/src/main/java/beta/automl/DeleteDataset.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_delete_dataset_beta] -// [START automl_tables_delete_dataset] -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.DatasetName; -import com.google.protobuf.Empty; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class 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"; - deleteDataset(projectId, datasetId); - } - - // Delete a dataset - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the dataset. - DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId); - Empty response = client.deleteDatasetAsync(datasetFullId).get(); - System.out.format("Dataset deleted. %s%n", response); - } - } -} -// [END automl_tables_delete_dataset] -// [END automl_delete_dataset_beta] diff --git a/samples/snippets/src/main/java/beta/automl/DeleteModel.java b/samples/snippets/src/main/java/beta/automl/DeleteModel.java deleted file mode 100644 index 77cc99bb2..000000000 --- a/samples/snippets/src/main/java/beta/automl/DeleteModel.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_tables_delete_model] -// [START automl_delete_model_beta] -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.ModelName; -import com.google.protobuf.Empty; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class DeleteModel { - - public static void main(String[] args) - throws IOException, ExecutionException, InterruptedException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String modelId = "YOUR_MODEL_ID"; - deleteModel(projectId, modelId); - } - - // Delete a model - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the model. - ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId); - - // Delete a model. - Empty response = client.deleteModelAsync(modelFullId).get(); - - System.out.println("Model deletion started..."); - System.out.println(String.format("Model deleted. %s", response)); - } - } -} -// [END automl_delete_model_beta] -// [END automl_tables_delete_model] diff --git a/samples/snippets/src/main/java/beta/automl/DeployModel.java b/samples/snippets/src/main/java/beta/automl/DeployModel.java deleted file mode 100644 index 55a3105dd..000000000 --- a/samples/snippets/src/main/java/beta/automl/DeployModel.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_tables_deploy_model] -// [START automl_deploy_model_beta] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.DeployModelRequest; -import com.google.cloud.automl.v1beta1.ModelName; -import com.google.cloud.automl.v1beta1.OperationMetadata; -import com.google.protobuf.Empty; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class DeployModel { - - public static void main(String[] args) - throws IOException, ExecutionException, InterruptedException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String modelId = "YOUR_MODEL_ID"; - deployModel(projectId, modelId); - } - - // Deploy a model for prediction - static void deployModel(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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the model. - ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId); - DeployModelRequest request = - DeployModelRequest.newBuilder().setName(modelFullId.toString()).build(); - OperationFuture future = client.deployModelAsync(request); - - future.get(); - System.out.println("Model deployment finished"); - } - } -} -// [END automl_deploy_model_beta] -// [END automl_tables_deploy_model] diff --git a/samples/snippets/src/main/java/beta/automl/GetModel.java b/samples/snippets/src/main/java/beta/automl/GetModel.java deleted file mode 100644 index 710b78053..000000000 --- a/samples/snippets/src/main/java/beta/automl/GetModel.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_get_model_beta] -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.Model; -import com.google.cloud.automl.v1beta1.ModelName; -import io.grpc.StatusRuntimeException; -import java.io.IOException; - -class GetModel { - - static void getModel() throws IOException, StatusRuntimeException { - // 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) - throws IOException, StatusRuntimeException { - // 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 full path of the model. - ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId); - Model model = client.getModel(modelFullId); - - // Display the model information. - System.out.format("Model name: %s%n", model.getName()); - // To get the model id, you have to parse it out of the `name` field. As models Ids are - // required for other methods. - // Name Format: `projects/{project_id}/locations/{location_id}/models/{model_id}` - String[] names = model.getName().split("/"); - String retrievedModelId = names[names.length - 1]; - System.out.format("Model id: %s%n", retrievedModelId); - System.out.format("Model display name: %s%n", model.getDisplayName()); - System.out.println("Model create time:"); - 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()); - } - } -} -// [END automl_get_model_beta] diff --git a/samples/snippets/src/main/java/beta/automl/GetModelEvaluation.java b/samples/snippets/src/main/java/beta/automl/GetModelEvaluation.java deleted file mode 100644 index 74f35f5a7..000000000 --- a/samples/snippets/src/main/java/beta/automl/GetModelEvaluation.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_video_classification_get_model_evaluation_beta] -// [START automl_video_object_tracking_get_model_evaluation_beta] -// [START automl_tables_get_model_evaluation] -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.ModelEvaluation; -import com.google.cloud.automl.v1beta1.ModelEvaluationName; -import java.io.IOException; - -class 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"; - String modelEvaluationId = "YOUR_MODEL_EVALUATION_ID"; - getModelEvaluation(projectId, modelId, modelEvaluationId); - } - - // Get a model evaluation - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the model evaluation. - ModelEvaluationName modelEvaluationFullId = - ModelEvaluationName.of(projectId, "us-central1", modelId, modelEvaluationId); - - // Get complete detail of the model evaluation. - ModelEvaluation modelEvaluation = client.getModelEvaluation(modelEvaluationFullId); - - System.out.format("Model Evaluation Name: %s%n", modelEvaluation.getName()); - System.out.format("Model Annotation Spec Id: %s", modelEvaluation.getAnnotationSpecId()); - System.out.println("Create Time:"); - System.out.format("\tseconds: %s%n", modelEvaluation.getCreateTime().getSeconds()); - System.out.format("\tnanos: %s", modelEvaluation.getCreateTime().getNanos() / 1e9); - System.out.format( - "Evalution Example Count: %d%n", modelEvaluation.getEvaluatedExampleCount()); - - // [END automl_video_object_tracking_get_model_evaluation_beta] - System.out.format( - "Classification Model Evaluation Metrics: %s%n", - modelEvaluation.getClassificationEvaluationMetrics()); - // [END automl_video_classification_get_model_evaluation_beta] - - // [START automl_video_object_tracking_get_model_evaluation_beta] - System.out.format( - "Video Object Tracking Evaluation Metrics: %s%n", - modelEvaluation.getVideoObjectTrackingEvaluationMetrics()); - // [START automl_video_classification_get_model_evaluation_beta] - } - } -} -// [END automl_tables_get_model_evaluation] -// [END automl_video_object_tracking_get_model_evaluation_beta] -// [END automl_video_classification_get_model_evaluation_beta] diff --git a/samples/snippets/src/main/java/beta/automl/GetOperationStatus.java b/samples/snippets/src/main/java/beta/automl/GetOperationStatus.java deleted file mode 100644 index 77dc70340..000000000 --- a/samples/snippets/src/main/java/beta/automl/GetOperationStatus.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_get_operation_status_beta] -// [START automl_tables_get_operation_status] -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.longrunning.Operation; -import java.io.IOException; - -class GetOperationStatus { - - static void getOperationStatus() throws IOException { - // 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) 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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the latest state of a long-running operation. - Operation operation = client.getOperationsClient().getOperation(operationFullId); - - // Display operation details. - System.out.println("Operation details:"); - System.out.format("\tName: %s%n", operation.getName()); - System.out.format("\tMetadata Type Url: %s%n", operation.getMetadata().getTypeUrl()); - System.out.format("\tDone: %s%n", operation.getDone()); - if (operation.hasResponse()) { - System.out.format("\tResponse Type Url: %s%n", operation.getResponse().getTypeUrl()); - } - if (operation.hasError()) { - System.out.println("\tResponse:"); - System.out.format("\t\tError code: %s%n", operation.getError().getCode()); - System.out.format("\t\tError message: %s%n", operation.getError().getMessage()); - } - } - } -} -// [END automl_tables_get_operation_status] -// [END automl_get_operation_status_beta] diff --git a/samples/snippets/src/main/java/beta/automl/ImportDataset.java b/samples/snippets/src/main/java/beta/automl/ImportDataset.java deleted file mode 100644 index 72f19b192..000000000 --- a/samples/snippets/src/main/java/beta/automl/ImportDataset.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_import_dataset_beta] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.api.gax.retrying.RetrySettings; -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.AutoMlSettings; -import com.google.cloud.automl.v1beta1.DatasetName; -import com.google.cloud.automl.v1beta1.GcsSource; -import com.google.cloud.automl.v1beta1.InputConfig; -import com.google.cloud.automl.v1beta1.OperationMetadata; -import com.google.protobuf.Empty; -import java.io.IOException; -import java.util.Arrays; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import org.threeten.bp.Duration; - -class ImportDataset { - - public static void main(String[] args) - throws IOException, ExecutionException, InterruptedException, TimeoutException { - // 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); - } - - // Import a dataset - static void importDataset(String projectId, String datasetId, String path) - throws IOException, ExecutionException, InterruptedException, TimeoutException { - Duration totalTimeout = Duration.ofMinutes(45); - RetrySettings retrySettings = RetrySettings.newBuilder().setTotalTimeout(totalTimeout).build(); - AutoMlSettings.Builder builder = AutoMlSettings.newBuilder(); - builder.importDataSettings().setRetrySettings(retrySettings).build(); - AutoMlSettings settings = builder.build(); - - // 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(settings)) { - // Get the complete path of the dataset. - DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId); - - // Get multiple Google Cloud Storage URIs to import data from - GcsSource gcsSource = - GcsSource.newBuilder().addAllInputUris(Arrays.asList(path.split(","))).build(); - - // Import data from the input URI - InputConfig inputConfig = InputConfig.newBuilder().setGcsSource(gcsSource).build(); - System.out.println("Processing import..."); - - // Start the import job - OperationFuture operation = - client.importDataAsync(datasetFullId, inputConfig); - - 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(45, TimeUnit.MINUTES); - System.out.format("Dataset imported. %s%n", response); - } catch (TimeoutException e) { - System.out.println("The operation's polling period was not long enough."); - System.out.println("You can use the Operation's name to get the current status."); - System.out.println("The import job is still running and will complete as expected."); - throw e; - } - } -} -// [END automl_import_dataset_beta] diff --git a/samples/snippets/src/main/java/beta/automl/ListDatasets.java b/samples/snippets/src/main/java/beta/automl/ListDatasets.java deleted file mode 100644 index 7e624aa6f..000000000 --- a/samples/snippets/src/main/java/beta/automl/ListDatasets.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_video_classification_list_datasets_beta] -// [START automl_video_object_tracking_list_datasets_beta] -// [START automl_tables_list_datasets] -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.Dataset; -import com.google.cloud.automl.v1beta1.ListDatasetsRequest; -import com.google.cloud.automl.v1beta1.LocationName; -import java.io.IOException; - -class 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) 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - ListDatasetsRequest request = - ListDatasetsRequest.newBuilder().setParent(projectLocation.toString()).build(); - - // List all the datasets available in the region by applying filter. - System.out.println("List of datasets:"); - for (Dataset dataset : client.listDatasets(request).iterateAll()) { - // Display the dataset information - System.out.format("%nDataset name: %s%n", dataset.getName()); - // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are - // required for other methods. - // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}` - String[] names = dataset.getName().split("/"); - String retrievedDatasetId = names[names.length - 1]; - System.out.format("Dataset id: %s%n", retrievedDatasetId); - System.out.format("Dataset display name: %s%n", dataset.getDisplayName()); - System.out.println("Dataset create time:"); - System.out.format("\tseconds: %s%n", dataset.getCreateTime().getSeconds()); - System.out.format("\tnanos: %s%n", dataset.getCreateTime().getNanos()); - - // [END automl_video_object_tracking_list_datasets_beta] - // [END automl_tables_list_datasets] - System.out.format( - "Video classification dataset metadata: %s%n", - dataset.getVideoClassificationDatasetMetadata()); - // [END automl_video_classification_list_datasets_beta] - - // [START automl_video_object_tracking_list_datasets_beta] - System.out.format( - "Video object tracking dataset metadata: %s%n", - dataset.getVideoObjectTrackingDatasetMetadata()); - // [END automl_video_object_tracking_list_datasets_beta] - - // [START automl_tables_list_datasets] - System.out.format("Tables dataset metadata: %s%n", dataset.getTablesDatasetMetadata()); - - // [START automl_video_classification_list_datasets_beta] - // [START automl_video_object_tracking_list_datasets_beta] - } - } - } -} -// [END automl_video_classification_list_datasets_beta] -// [END automl_video_object_tracking_list_datasets_beta] -// [END automl_tables_list_datasets] diff --git a/samples/snippets/src/main/java/beta/automl/ListModelEvaluations.java b/samples/snippets/src/main/java/beta/automl/ListModelEvaluations.java deleted file mode 100644 index 2fad4ea8e..000000000 --- a/samples/snippets/src/main/java/beta/automl/ListModelEvaluations.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 beta.automl; - -// [START automl_tables_list_model_evaluations] -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.ListModelEvaluationsRequest; -import com.google.cloud.automl.v1beta1.ModelEvaluation; -import com.google.cloud.automl.v1beta1.ModelName; -import java.io.IOException; - -class ListModelEvaluations { - - public static void main(String[] args) throws IOException { - // 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) 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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the model. - ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId); - ListModelEvaluationsRequest modelEvaluationsrequest = - ListModelEvaluationsRequest.newBuilder().setParent(modelFullId.toString()).build(); - - // List all the model evaluations in the model by applying filter. - System.out.println("List of model evaluations:"); - for (ModelEvaluation modelEvaluation : - client.listModelEvaluations(modelEvaluationsrequest).iterateAll()) { - - System.out.format("Model Evaluation Name: %s%n", modelEvaluation.getName()); - System.out.format("Model Annotation Spec Id: %s", modelEvaluation.getAnnotationSpecId()); - System.out.println("Create Time:"); - System.out.format("\tseconds: %s%n", modelEvaluation.getCreateTime().getSeconds()); - System.out.format("\tnanos: %s", modelEvaluation.getCreateTime().getNanos() / 1e9); - System.out.format( - "Evalution Example Count: %d%n", modelEvaluation.getEvaluatedExampleCount()); - - System.out.format( - "Tables Model Evaluation Metrics: %s%n", - modelEvaluation.getClassificationEvaluationMetrics()); - } - } - } -} -// [END automl_tables_list_model_evaluations] diff --git a/samples/snippets/src/main/java/beta/automl/ListModels.java b/samples/snippets/src/main/java/beta/automl/ListModels.java deleted file mode 100644 index 87d1b0a7f..000000000 --- a/samples/snippets/src/main/java/beta/automl/ListModels.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_tables_list_models] -// [START automl_list_models_beta] -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.ListModelsRequest; -import com.google.cloud.automl.v1beta1.LocationName; -import com.google.cloud.automl.v1beta1.Model; -import java.io.IOException; - -class ListModels { - - static void listModels() throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - listModels(projectId); - } - - // List the models available in the specified location - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - - // Create list models request. - ListModelsRequest listModelsRequest = - ListModelsRequest.newBuilder() - .setParent(projectLocation.toString()) - .setFilter("") - .build(); - - // List all the models available in the region by applying filter. - System.out.println("List of models:"); - for (Model model : client.listModels(listModelsRequest).iterateAll()) { - // Display the model information. - System.out.format("Model name: %s%n", model.getName()); - // To get the model id, you have to parse it out of the `name` field. As models Ids are - // required for other methods. - // Name Format: `projects/{project_id}/locations/{location_id}/models/{model_id}` - String[] names = model.getName().split("/"); - String retrievedModelId = names[names.length - 1]; - System.out.format("Model id: %s%n", retrievedModelId); - System.out.format("Model display name: %s%n", model.getDisplayName()); - System.out.println("Model create time:"); - 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()); - } - } - } -} -// [END automl_list_models_beta] -// [END automl_tables_list_models] diff --git a/samples/snippets/src/main/java/beta/automl/SetEndpoint.java b/samples/snippets/src/main/java/beta/automl/SetEndpoint.java deleted file mode 100644 index 4718b220a..000000000 --- a/samples/snippets/src/main/java/beta/automl/SetEndpoint.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 beta.automl; - -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.AutoMlSettings; -import com.google.cloud.automl.v1beta1.Dataset; -import com.google.cloud.automl.v1beta1.ListDatasetsRequest; -import com.google.cloud.automl.v1beta1.LocationName; -import java.io.IOException; - -class SetEndpoint { - - // Change your endpoint - static void setEndpoint(String projectId) throws IOException { - // [START automl_set_endpoint] - AutoMlSettings settings = - AutoMlSettings.newBuilder().setEndpoint("eu-automl.googleapis.com:443").build(); - - // 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. - AutoMlClient client = AutoMlClient.create(settings); - - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "eu"); - // [END automl_set_endpoint] - - ListDatasetsRequest request = - ListDatasetsRequest.newBuilder() - .setParent(projectLocation.toString()) - .setFilter("translation_dataset_metadata:*") - .build(); - // List all the datasets available - System.out.println("List of datasets:"); - for (Dataset dataset : client.listDatasets(request).iterateAll()) { - System.out.println(dataset); - } - client.close(); - } -} diff --git a/samples/snippets/src/main/java/beta/automl/TablesBatchPredictBigQuery.java b/samples/snippets/src/main/java/beta/automl/TablesBatchPredictBigQuery.java deleted file mode 100644 index 73e964da4..000000000 --- a/samples/snippets/src/main/java/beta/automl/TablesBatchPredictBigQuery.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_tables_batch_predict_bq] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1beta1.BatchPredictInputConfig; -import com.google.cloud.automl.v1beta1.BatchPredictOutputConfig; -import com.google.cloud.automl.v1beta1.BatchPredictRequest; -import com.google.cloud.automl.v1beta1.BatchPredictResult; -import com.google.cloud.automl.v1beta1.BigQueryDestination; -import com.google.cloud.automl.v1beta1.BigQuerySource; -import com.google.cloud.automl.v1beta1.ModelName; -import com.google.cloud.automl.v1beta1.OperationMetadata; -import com.google.cloud.automl.v1beta1.PredictionServiceClient; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class TablesBatchPredictBigQuery { - - static void batchPredict() throws IOException, ExecutionException, InterruptedException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String modelId = "YOUR_MODEL_ID"; - String inputUri = "bq://YOUR_PROJECT_ID.bqDatasetID.bqTableId"; - String outputUri = "bq://YOUR_PROJECT_ID"; - batchPredict(projectId, modelId, inputUri, outputUri); - } - - static void batchPredict(String projectId, String modelId, String inputUri, String outputUri) - 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. - try (PredictionServiceClient client = PredictionServiceClient.create()) { - // Get the full path of the model. - ModelName name = ModelName.of(projectId, "us-central1", modelId); - - // Configure the source of the file from BigQuery - BigQuerySource bigQuerySource = BigQuerySource.newBuilder().setInputUri(inputUri).build(); - BatchPredictInputConfig inputConfig = - BatchPredictInputConfig.newBuilder().setBigquerySource(bigQuerySource).build(); - - // Configure where to store the output in BigQuery - BigQueryDestination bigQueryDestination = - BigQueryDestination.newBuilder().setOutputUri(outputUri).build(); - BatchPredictOutputConfig outputConfig = - BatchPredictOutputConfig.newBuilder().setBigqueryDestination(bigQueryDestination).build(); - - // Build the request that will be sent to the API - BatchPredictRequest request = - BatchPredictRequest.newBuilder() - .setName(name.toString()) - .setInputConfig(inputConfig) - .setOutputConfig(outputConfig) - .build(); - - // Start an asynchronous request - OperationFuture future = - client.batchPredictAsync(request); - - System.out.println("Waiting for operation to complete..."); - BatchPredictResult response = future.get(); - System.out.println("Batch Prediction results saved to BigQuery."); - } - } -} -// [END automl_tables_batch_predict_bq] diff --git a/samples/snippets/src/main/java/beta/automl/TablesCreateDataset.java b/samples/snippets/src/main/java/beta/automl/TablesCreateDataset.java deleted file mode 100644 index b5390f337..000000000 --- a/samples/snippets/src/main/java/beta/automl/TablesCreateDataset.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_tables_create_dataset] -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.Dataset; -import com.google.cloud.automl.v1beta1.LocationName; -import com.google.cloud.automl.v1beta1.TablesDatasetMetadata; -import java.io.IOException; - -class TablesCreateDataset { - - public static void main(String[] args) throws IOException { - // 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) 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - TablesDatasetMetadata metadata = TablesDatasetMetadata.newBuilder().build(); - Dataset dataset = - Dataset.newBuilder() - .setDisplayName(displayName) - .setTablesDatasetMetadata(metadata) - .build(); - - Dataset createdDataset = client.createDataset(projectLocation, dataset); - - // Display the dataset information. - System.out.format("Dataset name: %s%n", createdDataset.getName()); - // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are - // required for other methods. - // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}` - String[] names = createdDataset.getName().split("/"); - String datasetId = names[names.length - 1]; - System.out.format("Dataset id: %s%n", datasetId); - } - } -} -// [END automl_tables_create_dataset] diff --git a/samples/snippets/src/main/java/beta/automl/TablesCreateModel.java b/samples/snippets/src/main/java/beta/automl/TablesCreateModel.java deleted file mode 100644 index 9c95119e1..000000000 --- a/samples/snippets/src/main/java/beta/automl/TablesCreateModel.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_tables_create_model] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.ColumnSpec; -import com.google.cloud.automl.v1beta1.ColumnSpecName; -import com.google.cloud.automl.v1beta1.LocationName; -import com.google.cloud.automl.v1beta1.Model; -import com.google.cloud.automl.v1beta1.OperationMetadata; -import com.google.cloud.automl.v1beta1.TablesModelMetadata; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class TablesCreateModel { - - public static void main(String[] args) - throws IOException, ExecutionException, InterruptedException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String datasetId = "YOUR_DATASET_ID"; - String tableSpecId = "YOUR_TABLE_SPEC_ID"; - String columnSpecId = "YOUR_COLUMN_SPEC_ID"; - String displayName = "YOUR_DATASET_NAME"; - createModel(projectId, datasetId, tableSpecId, columnSpecId, displayName); - } - - // Create a model - static void createModel( - String projectId, - String datasetId, - String tableSpecId, - String columnSpecId, - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - - // Get the complete path of the column. - ColumnSpecName columnSpecName = - ColumnSpecName.of(projectId, "us-central1", datasetId, tableSpecId, columnSpecId); - - // Build the get column spec. - ColumnSpec targetColumnSpec = - ColumnSpec.newBuilder().setName(columnSpecName.toString()).build(); - - // Set model metadata. - TablesModelMetadata metadata = - TablesModelMetadata.newBuilder() - .setTargetColumnSpec(targetColumnSpec) - .setTrainBudgetMilliNodeHours(24000) - .build(); - - Model model = - Model.newBuilder() - .setDisplayName(displayName) - .setDatasetId(datasetId) - .setTablesModelMetadata(metadata) - .build(); - - // Create a model with the model metadata in the region. - OperationFuture future = - client.createModelAsync(projectLocation, model); - // OperationFuture.get() will block until the model is created, which may take several hours. - // You can use OperationFuture.getInitialFuture to get a future representing the initial - // response to the request, which contains information while the operation is in progress. - System.out.format("Training operation name: %s%n", future.getInitialFuture().get().getName()); - System.out.println("Training started..."); - } - } -} -// [END automl_tables_create_model] diff --git a/samples/snippets/src/main/java/beta/automl/TablesGetModel.java b/samples/snippets/src/main/java/beta/automl/TablesGetModel.java deleted file mode 100644 index 443491252..000000000 --- a/samples/snippets/src/main/java/beta/automl/TablesGetModel.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_tables_get_model] - -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.Model; -import com.google.cloud.automl.v1beta1.ModelName; -import com.google.cloud.automl.v1beta1.TablesModelColumnInfo; -import io.grpc.StatusRuntimeException; -import java.io.IOException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; - -public class TablesGetModel { - - public static void main(String[] args) throws IOException, StatusRuntimeException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String region = "YOUR_REGION"; - String modelId = "YOUR_MODEL_ID"; - getModel(projectId, region, modelId); - } - - // Demonstrates using the AutoML client to get model details. - public static void getModel(String projectId, String computeRegion, String modelId) - throws IOException, StatusRuntimeException { - // 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 full path of the model. - ModelName modelFullId = ModelName.of(projectId, computeRegion, modelId); - - // Get complete detail of the model. - Model model = client.getModel(modelFullId); - - // Display the model information. - System.out.format("Model name: %s%n", model.getName()); - System.out.format( - "Model Id: %s\n", model.getName().split("/")[model.getName().split("/").length - 1]); - System.out.format("Model display name: %s%n", model.getDisplayName()); - System.out.format("Dataset Id: %s%n", model.getDatasetId()); - System.out.println("Tables Model Metadata: "); - System.out.format( - "\tTraining budget: %s%n", model.getTablesModelMetadata().getTrainBudgetMilliNodeHours()); - System.out.format( - "\tTraining cost: %s%n", model.getTablesModelMetadata().getTrainBudgetMilliNodeHours()); - - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); - String createTime = - dateFormat.format(new java.util.Date(model.getCreateTime().getSeconds() * 1000)); - System.out.format("Model create time: %s%n", createTime); - - System.out.format("Model deployment state: %s%n", model.getDeploymentState()); - - // Get features of top importance - for (TablesModelColumnInfo info : - model.getTablesModelMetadata().getTablesModelColumnInfoList()) { - System.out.format( - "Column: %s - Importance: %.2f%n", - info.getColumnDisplayName(), info.getFeatureImportance()); - } - } - } -} -// [END automl_tables_get_model] diff --git a/samples/snippets/src/main/java/beta/automl/TablesImportDataset.java b/samples/snippets/src/main/java/beta/automl/TablesImportDataset.java deleted file mode 100644 index ce0e5fc16..000000000 --- a/samples/snippets/src/main/java/beta/automl/TablesImportDataset.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_tables_import_data] -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.BigQuerySource; -import com.google.cloud.automl.v1beta1.DatasetName; -import com.google.cloud.automl.v1beta1.GcsSource; -import com.google.cloud.automl.v1beta1.InputConfig; -import com.google.protobuf.Empty; -import java.io.IOException; -import java.util.Arrays; -import java.util.concurrent.ExecutionException; - -class TablesImportDataset { - - public static void main(String[] args) - throws IOException, ExecutionException, InterruptedException { - // 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//data.csv or bq://project_id.dataset_id.table_id"; - importDataset(projectId, datasetId, path); - } - - // Import a dataset via BigQuery or Google Cloud Storage - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the complete path of the dataset. - DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId); - - InputConfig.Builder inputConfigBuilder = InputConfig.newBuilder(); - - // Determine which source type was used for the input path (BigQuery or GCS) - if (path.startsWith("bq")) { - // Get training data file to be imported from a BigQuery source. - BigQuerySource.Builder bigQuerySource = BigQuerySource.newBuilder(); - bigQuerySource.setInputUri(path); - inputConfigBuilder.setBigquerySource(bigQuerySource); - } else { - // Get multiple Google Cloud Storage URIs to import data from - GcsSource gcsSource = - GcsSource.newBuilder().addAllInputUris(Arrays.asList(path.split(","))).build(); - inputConfigBuilder.setGcsSource(gcsSource); - } - - // Import data from the input URI - System.out.println("Processing import..."); - - Empty response = client.importDataAsync(datasetFullId, inputConfigBuilder.build()).get(); - System.out.format("Dataset imported. %s%n", response); - } - } -} -// [END automl_tables_import_data] diff --git a/samples/snippets/src/main/java/beta/automl/TablesPredict.java b/samples/snippets/src/main/java/beta/automl/TablesPredict.java deleted file mode 100644 index fd2257c89..000000000 --- a/samples/snippets/src/main/java/beta/automl/TablesPredict.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_tables_predict] -import com.google.cloud.automl.v1beta1.AnnotationPayload; -import com.google.cloud.automl.v1beta1.ExamplePayload; -import com.google.cloud.automl.v1beta1.ModelName; -import com.google.cloud.automl.v1beta1.PredictRequest; -import com.google.cloud.automl.v1beta1.PredictResponse; -import com.google.cloud.automl.v1beta1.PredictionServiceClient; -import com.google.cloud.automl.v1beta1.Row; -import com.google.cloud.automl.v1beta1.TablesAnnotation; -import com.google.protobuf.Value; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -class TablesPredict { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String modelId = "YOUR_MODEL_ID"; - // Values should match the input expected by your model. - List values = new ArrayList<>(); - // values.add(Value.newBuilder().setBoolValue(true).build()); - // values.add(Value.newBuilder().setNumberValue(10).build()); - // values.add(Value.newBuilder().setStringValue("YOUR_STRING").build()); - predict(projectId, modelId, values); - } - - static void predict(String projectId, String modelId, List values) 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. - try (PredictionServiceClient client = PredictionServiceClient.create()) { - // Get the full path of the model. - ModelName name = ModelName.of(projectId, "us-central1", modelId); - Row row = Row.newBuilder().addAllValues(values).build(); - ExamplePayload payload = ExamplePayload.newBuilder().setRow(row).build(); - - // Feature importance gives you visibility into how the features in a specific prediction - // request informed the resulting prediction. For more info, see: - // https://cloud.google.com/automl-tables/docs/features#local - PredictRequest request = - PredictRequest.newBuilder() - .setName(name.toString()) - .setPayload(payload) - .putParams("feature_importance", "true") - .build(); - - PredictResponse response = client.predict(request); - - System.out.println("Prediction results:"); - for (AnnotationPayload annotationPayload : response.getPayloadList()) { - TablesAnnotation tablesAnnotation = annotationPayload.getTables(); - System.out.format( - "Classification label: %s%n", tablesAnnotation.getValue().getStringValue()); - System.out.format("Classification score: %.3f%n", tablesAnnotation.getScore()); - // Get features of top importance - tablesAnnotation - .getTablesModelColumnInfoList() - .forEach( - info -> - System.out.format( - "\tColumn: %s - Importance: %.2f%n", - info.getColumnDisplayName(), info.getFeatureImportance())); - } - } - } -} -// [END automl_tables_predict] diff --git a/samples/snippets/src/main/java/beta/automl/UndeployModel.java b/samples/snippets/src/main/java/beta/automl/UndeployModel.java deleted file mode 100644 index 7325f519d..000000000 --- a/samples/snippets/src/main/java/beta/automl/UndeployModel.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_tables_undeploy_model] -// [START automl_undeploy_model_beta] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.ModelName; -import com.google.cloud.automl.v1beta1.OperationMetadata; -import com.google.cloud.automl.v1beta1.UndeployModelRequest; -import com.google.protobuf.Empty; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class UndeployModel { - - static void undeployModel() throws IOException, ExecutionException, InterruptedException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String modelId = "YOUR_MODEL_ID"; - undeployModel(projectId, modelId); - } - - // Undeploy a model from prediction - static void undeployModel(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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the model. - ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId); - UndeployModelRequest request = - UndeployModelRequest.newBuilder().setName(modelFullId.toString()).build(); - OperationFuture future = client.undeployModelAsync(request); - - future.get(); - System.out.println("Model undeployment finished"); - } - } -} -// [END automl_undeploy_model_beta] -// [END automl_tables_undeploy_model] diff --git a/samples/snippets/src/main/java/beta/automl/VideoClassificationCreateDataset.java b/samples/snippets/src/main/java/beta/automl/VideoClassificationCreateDataset.java deleted file mode 100644 index 1fe70c9f2..000000000 --- a/samples/snippets/src/main/java/beta/automl/VideoClassificationCreateDataset.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_video_classification_create_dataset_beta] -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.Dataset; -import com.google.cloud.automl.v1beta1.LocationName; -import com.google.cloud.automl.v1beta1.VideoClassificationDatasetMetadata; -import java.io.IOException; - -class VideoClassificationCreateDataset { - - public static void main(String[] args) throws IOException { - // 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) 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - VideoClassificationDatasetMetadata metadata = - VideoClassificationDatasetMetadata.newBuilder().build(); - Dataset dataset = - Dataset.newBuilder() - .setDisplayName(displayName) - .setVideoClassificationDatasetMetadata(metadata) - .build(); - - Dataset createdDataset = client.createDataset(projectLocation, dataset); - - // Display the dataset information. - System.out.format("Dataset name: %s%n", createdDataset.getName()); - // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are - // required for other methods. - // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}` - String[] names = createdDataset.getName().split("/"); - String datasetId = names[names.length - 1]; - System.out.format("Dataset id: %s%n", datasetId); - } - } -} -// [END automl_video_classification_create_dataset_beta] diff --git a/samples/snippets/src/main/java/beta/automl/VideoClassificationCreateModel.java b/samples/snippets/src/main/java/beta/automl/VideoClassificationCreateModel.java deleted file mode 100644 index 94f3407d4..000000000 --- a/samples/snippets/src/main/java/beta/automl/VideoClassificationCreateModel.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_video_classification_create_model_beta] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.LocationName; -import com.google.cloud.automl.v1beta1.Model; -import com.google.cloud.automl.v1beta1.OperationMetadata; -import com.google.cloud.automl.v1beta1.VideoClassificationModelMetadata; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class VideoClassificationCreateModel { - - public static void main(String[] args) - throws IOException, ExecutionException, InterruptedException { - // 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) - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - // Set model metadata. - VideoClassificationModelMetadata metadata = - VideoClassificationModelMetadata.newBuilder().build(); - Model model = - Model.newBuilder() - .setDisplayName(displayName) - .setDatasetId(datasetId) - .setVideoClassificationModelMetadata(metadata) - .build(); - - // Create a model with the model metadata in the region. - OperationFuture future = - client.createModelAsync(projectLocation, model); - // OperationFuture.get() will block until the model is created, which may take several hours. - // You can use OperationFuture.getInitialFuture to get a future representing the initial - // response to the request, which contains information while the operation is in progress. - System.out.format("Training operation name: %s%n", future.getInitialFuture().get().getName()); - System.out.println("Training started..."); - } - } -} -// [END automl_video_classification_create_model_beta] diff --git a/samples/snippets/src/main/java/beta/automl/VideoObjectTrackingCreateDataset.java b/samples/snippets/src/main/java/beta/automl/VideoObjectTrackingCreateDataset.java deleted file mode 100644 index 61b2a1ada..000000000 --- a/samples/snippets/src/main/java/beta/automl/VideoObjectTrackingCreateDataset.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_video_object_tracking_create_dataset_beta] -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.Dataset; -import com.google.cloud.automl.v1beta1.LocationName; -import com.google.cloud.automl.v1beta1.VideoObjectTrackingDatasetMetadata; -import java.io.IOException; - -class VideoObjectTrackingCreateDataset { - - public static void main(String[] args) throws IOException { - // 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) 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - VideoObjectTrackingDatasetMetadata metadata = - VideoObjectTrackingDatasetMetadata.newBuilder().build(); - Dataset dataset = - Dataset.newBuilder() - .setDisplayName(displayName) - .setVideoObjectTrackingDatasetMetadata(metadata) - .build(); - - Dataset createdDataset = client.createDataset(projectLocation, dataset); - - // Display the dataset information. - System.out.format("Dataset name: %s%n", createdDataset.getName()); - // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are - // required for other methods. - // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}` - String[] names = createdDataset.getName().split("/"); - String datasetId = names[names.length - 1]; - System.out.format("Dataset id: %s%n", datasetId); - } - } -} -// [END automl_video_object_tracking_create_dataset_beta] diff --git a/samples/snippets/src/main/java/beta/automl/VideoObjectTrackingCreateModel.java b/samples/snippets/src/main/java/beta/automl/VideoObjectTrackingCreateModel.java deleted file mode 100644 index 29df78666..000000000 --- a/samples/snippets/src/main/java/beta/automl/VideoObjectTrackingCreateModel.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -// [START automl_video_object_tracking_create_model_beta] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.LocationName; -import com.google.cloud.automl.v1beta1.Model; -import com.google.cloud.automl.v1beta1.OperationMetadata; -import com.google.cloud.automl.v1beta1.VideoObjectTrackingModelMetadata; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class VideoObjectTrackingCreateModel { - - public static void main(String[] args) - throws IOException, ExecutionException, InterruptedException { - // 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) - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - // Set model metadata. - VideoObjectTrackingModelMetadata metadata = - VideoObjectTrackingModelMetadata.newBuilder().build(); - Model model = - Model.newBuilder() - .setDisplayName(displayName) - .setDatasetId(datasetId) - .setVideoObjectTrackingModelMetadata(metadata) - .build(); - - // Create a model with the model metadata in the region. - OperationFuture future = - client.createModelAsync(projectLocation, model); - // OperationFuture.get() will block until the model is created, which may take several hours. - // You can use OperationFuture.getInitialFuture to get a future representing the initial - // response to the request, which contains information while the operation is in progress. - System.out.format("Training operation name: %s%n", future.getInitialFuture().get().getName()); - System.out.println("Training started..."); - } - } -} -// [END automl_video_object_tracking_create_model_beta] diff --git a/samples/snippets/src/main/java/com/example/automl/BatchPredict.java b/samples/snippets/src/main/java/com/example/automl/BatchPredict.java deleted file mode 100644 index da1e0afe5..000000000 --- a/samples/snippets/src/main/java/com/example/automl/BatchPredict.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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; - -// [START automl_batch_predict] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.BatchPredictInputConfig; -import com.google.cloud.automl.v1.BatchPredictOutputConfig; -import com.google.cloud.automl.v1.BatchPredictRequest; -import com.google.cloud.automl.v1.BatchPredictResult; -import com.google.cloud.automl.v1.GcsDestination; -import com.google.cloud.automl.v1.GcsSource; -import com.google.cloud.automl.v1.ModelName; -import com.google.cloud.automl.v1.OperationMetadata; -import com.google.cloud.automl.v1.PredictionServiceClient; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class BatchPredict { - - static void batchPredict() throws IOException, ExecutionException, InterruptedException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String modelId = "YOUR_MODEL_ID"; - String inputUri = "gs://YOUR_BUCKET_ID/path_to_your_input_csv_or_jsonl"; - String outputUri = "gs://YOUR_BUCKET_ID/path_to_save_results/"; - batchPredict(projectId, modelId, inputUri, outputUri); - } - - static void batchPredict(String projectId, String modelId, String inputUri, String outputUri) - 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. - try (PredictionServiceClient client = PredictionServiceClient.create()) { - // Get the full path of the model. - ModelName name = ModelName.of(projectId, "us-central1", modelId); - GcsSource gcsSource = GcsSource.newBuilder().addInputUris(inputUri).build(); - BatchPredictInputConfig inputConfig = - BatchPredictInputConfig.newBuilder().setGcsSource(gcsSource).build(); - GcsDestination gcsDestination = - GcsDestination.newBuilder().setOutputUriPrefix(outputUri).build(); - BatchPredictOutputConfig outputConfig = - BatchPredictOutputConfig.newBuilder().setGcsDestination(gcsDestination).build(); - BatchPredictRequest request = - BatchPredictRequest.newBuilder() - .setName(name.toString()) - .setInputConfig(inputConfig) - .setOutputConfig(outputConfig) - .build(); - - OperationFuture future = - client.batchPredictAsync(request); - - System.out.println("Waiting for operation to complete..."); - BatchPredictResult response = future.get(); - System.out.println("Batch Prediction results saved to specified Cloud Storage bucket."); - } - } -} -// [END automl_batch_predict] diff --git a/samples/snippets/src/main/java/com/example/automl/DeleteDataset.java b/samples/snippets/src/main/java/com/example/automl/DeleteDataset.java deleted file mode 100644 index fcb6e2e91..000000000 --- a/samples/snippets/src/main/java/com/example/automl/DeleteDataset.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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; - -// [START automl_delete_dataset] -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.DatasetName; -import com.google.protobuf.Empty; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class 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"; - deleteDataset(projectId, datasetId); - } - - // Delete a dataset - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the dataset. - DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId); - Empty response = client.deleteDatasetAsync(datasetFullId).get(); - System.out.format("Dataset deleted. %s\n", response); - } - } -} -// [END automl_delete_dataset] diff --git a/samples/snippets/src/main/java/com/example/automl/DeleteModel.java b/samples/snippets/src/main/java/com/example/automl/DeleteModel.java deleted file mode 100644 index 66969ff75..000000000 --- a/samples/snippets/src/main/java/com/example/automl/DeleteModel.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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; - -// [START automl_delete_model] -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.ModelName; -import com.google.protobuf.Empty; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class DeleteModel { - - public static void main(String[] args) - throws IOException, ExecutionException, InterruptedException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String modelId = "YOUR_MODEL_ID"; - deleteModel(projectId, modelId); - } - - // Delete a model - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the model. - ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId); - - // Delete a model. - Empty response = client.deleteModelAsync(modelFullId).get(); - - System.out.println("Model deletion started..."); - System.out.println(String.format("Model deleted. %s", response)); - } - } -} -// [END automl_delete_model] diff --git a/samples/snippets/src/main/java/com/example/automl/DeployModel.java b/samples/snippets/src/main/java/com/example/automl/DeployModel.java deleted file mode 100644 index ecc338cf3..000000000 --- a/samples/snippets/src/main/java/com/example/automl/DeployModel.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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; - -// [START automl_deploy_model] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.DeployModelRequest; -import com.google.cloud.automl.v1.ModelName; -import com.google.cloud.automl.v1.OperationMetadata; -import com.google.protobuf.Empty; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class DeployModel { - - public static void main(String[] args) - throws IOException, ExecutionException, InterruptedException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String modelId = "YOUR_MODEL_ID"; - deployModel(projectId, modelId); - } - - // Deploy a model for prediction - static void deployModel(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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the model. - ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId); - DeployModelRequest request = - DeployModelRequest.newBuilder().setName(modelFullId.toString()).build(); - OperationFuture future = client.deployModelAsync(request); - - future.get(); - System.out.println("Model deployment finished"); - } - } -} -// [END automl_deploy_model] diff --git a/samples/snippets/src/main/java/com/example/automl/ExportDataset.java b/samples/snippets/src/main/java/com/example/automl/ExportDataset.java deleted file mode 100644 index 812869b9a..000000000 --- a/samples/snippets/src/main/java/com/example/automl/ExportDataset.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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; - -// [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; -import com.google.cloud.automl.v1.OutputConfig; -import com.google.protobuf.Empty; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class 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"; - String gcsUri = "gs://BUCKET_ID/path_to_export/"; - exportDataset(projectId, datasetId, gcsUri); - } - - // Export a dataset to a GCS bucket - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the complete path of the dataset. - DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId); - GcsDestination gcsDestination = - GcsDestination.newBuilder().setOutputUriPrefix(gcsUri).build(); - - // Export the dataset to the output URI. - OutputConfig outputConfig = - OutputConfig.newBuilder().setGcsDestination(gcsDestination).build(); - - System.out.println("Processing export..."); - Empty response = client.exportDataAsync(datasetFullId, outputConfig).get(); - System.out.format("Dataset exported. %s\n", response); - } - } -} -// [END automl_export_dataset] diff --git a/samples/snippets/src/main/java/com/example/automl/GetDataset.java b/samples/snippets/src/main/java/com/example/automl/GetDataset.java deleted file mode 100644 index e1028d705..000000000 --- a/samples/snippets/src/main/java/com/example/automl/GetDataset.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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; - -// [START automl_language_entity_extraction_get_dataset] -// [START automl_language_sentiment_analysis_get_dataset] -// [START automl_language_text_classification_get_dataset] -// [START automl_translate_get_dataset] -// [START automl_vision_classification_get_dataset] -// [START automl_vision_object_detection_get_dataset] -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.Dataset; -import com.google.cloud.automl.v1.DatasetName; -import java.io.IOException; - -class 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); - } - - // Get a dataset - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the complete path of the dataset. - DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId); - Dataset dataset = client.getDataset(datasetFullId); - - // Display the dataset information - System.out.format("Dataset name: %s\n", dataset.getName()); - // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are - // required for other methods. - // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}` - String[] names = dataset.getName().split("/"); - String retrievedDatasetId = names[names.length - 1]; - System.out.format("Dataset id: %s\n", retrievedDatasetId); - System.out.format("Dataset display name: %s\n", dataset.getDisplayName()); - System.out.println("Dataset create time:"); - System.out.format("\tseconds: %s\n", dataset.getCreateTime().getSeconds()); - System.out.format("\tnanos: %s\n", dataset.getCreateTime().getNanos()); - // [END automl_language_sentiment_analysis_get_dataset] - // [END automl_language_text_classification_get_dataset] - // [END automl_translate_get_dataset] - // [END automl_vision_classification_get_dataset] - // [END automl_vision_object_detection_get_dataset] - System.out.format( - "Text extraction dataset metadata: %s\n", dataset.getTextExtractionDatasetMetadata()); - // [END automl_language_entity_extraction_get_dataset] - - // [START automl_language_sentiment_analysis_get_dataset] - System.out.format( - "Text sentiment dataset metadata: %s\n", dataset.getTextSentimentDatasetMetadata()); - // [END automl_language_sentiment_analysis_get_dataset] - - // [START automl_language_text_classification_get_dataset] - System.out.format( - "Text classification dataset metadata: %s\n", - dataset.getTextClassificationDatasetMetadata()); - // [END automl_language_text_classification_get_dataset] - - // [START automl_translate_get_dataset] - System.out.println("Translation dataset metadata:"); - System.out.format( - "\tSource language code: %s\n", - dataset.getTranslationDatasetMetadata().getSourceLanguageCode()); - System.out.format( - "\tTarget language code: %s\n", - dataset.getTranslationDatasetMetadata().getTargetLanguageCode()); - // [END automl_translate_get_dataset] - - // [START automl_vision_classification_get_dataset] - System.out.format( - "Image classification dataset metadata: %s\n", - dataset.getImageClassificationDatasetMetadata()); - // [END automl_vision_classification_get_dataset] - - // [START automl_vision_object_detection_get_dataset] - System.out.format( - "Image object detection dataset metadata: %s\n", - dataset.getImageObjectDetectionDatasetMetadata()); - // [START automl_language_entity_extraction_get_dataset] - // [START automl_language_sentiment_analysis_get_dataset] - // [START automl_language_text_classification_get_dataset] - // [START automl_translate_get_dataset] - // [START automl_vision_classification_get_dataset] - } - } -} -// [END automl_language_entity_extraction_get_dataset] -// [END automl_language_sentiment_analysis_get_dataset] -// [END automl_language_text_classification_get_dataset] -// [END automl_translate_get_dataset] -// [END automl_vision_classification_get_dataset] -// [END automl_vision_object_detection_get_dataset] diff --git a/samples/snippets/src/main/java/com/example/automl/GetModel.java b/samples/snippets/src/main/java/com/example/automl/GetModel.java deleted file mode 100644 index 70b97905c..000000000 --- a/samples/snippets/src/main/java/com/example/automl/GetModel.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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; - -// [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; -import java.io.IOException; - -class 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"; - getModel(projectId, modelId); - } - - // Get a model - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the model. - ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId); - Model model = client.getModel(modelFullId); - - // Display the model information. - System.out.format("Model name: %s\n", model.getName()); - // To get the model id, you have to parse it out of the `name` field. As models Ids are - // required for other methods. - // Name Format: `projects/{project_id}/locations/{location_id}/models/{model_id}` - String[] names = model.getName().split("/"); - String retrievedModelId = names[names.length - 1]; - System.out.format("Model id: %s\n", retrievedModelId); - System.out.format("Model display name: %s\n", model.getDisplayName()); - System.out.println("Model create time:"); - 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()); - } - } -} -// [END automl_get_model] diff --git a/samples/snippets/src/main/java/com/example/automl/GetModelEvaluation.java b/samples/snippets/src/main/java/com/example/automl/GetModelEvaluation.java deleted file mode 100644 index 694888d53..000000000 --- a/samples/snippets/src/main/java/com/example/automl/GetModelEvaluation.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * 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; - -// [START automl_language_entity_extraction_get_model_evaluation] -// [START automl_language_sentiment_analysis_get_model_evaluation] -// [START automl_language_text_classification_get_model_evaluation] -// [START automl_translate_get_model_evaluation] -// [START automl_vision_classification_get_model_evaluation] -// [START automl_vision_object_detection_get_model_evaluation] - -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.ModelEvaluation; -import com.google.cloud.automl.v1.ModelEvaluationName; -import java.io.IOException; - -class 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"; - String modelEvaluationId = "YOUR_MODEL_EVALUATION_ID"; - getModelEvaluation(projectId, modelId, modelEvaluationId); - } - - // Get a model evaluation - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the model evaluation. - ModelEvaluationName modelEvaluationFullId = - ModelEvaluationName.of(projectId, "us-central1", modelId, modelEvaluationId); - - // Get complete detail of the model evaluation. - ModelEvaluation modelEvaluation = client.getModelEvaluation(modelEvaluationFullId); - - System.out.format("Model Evaluation Name: %s\n", modelEvaluation.getName()); - System.out.format("Model Annotation Spec Id: %s", modelEvaluation.getAnnotationSpecId()); - System.out.println("Create Time:"); - System.out.format("\tseconds: %s\n", modelEvaluation.getCreateTime().getSeconds()); - System.out.format("\tnanos: %s", modelEvaluation.getCreateTime().getNanos() / 1e9); - System.out.format( - "Evalution Example Count: %d\n", modelEvaluation.getEvaluatedExampleCount()); - // [END automl_language_sentiment_analysis_get_model_evaluation] - // [END automl_language_text_classification_get_model_evaluation] - // [END automl_translate_get_model_evaluation] - // [END automl_vision_classification_get_model_evaluation] - // [END automl_vision_object_detection_get_model_evaluation] - System.out.format( - "Entity Extraction Model Evaluation Metrics: %s\n", - modelEvaluation.getTextExtractionEvaluationMetrics()); - // [END automl_language_entity_extraction_get_model_evaluation] - - // [START automl_language_sentiment_analysis_get_model_evaluation] - System.out.format( - "Sentiment Analysis Model Evaluation Metrics: %s\n", - modelEvaluation.getTextSentimentEvaluationMetrics()); - // [END automl_language_sentiment_analysis_get_model_evaluation] - - // [START automl_language_text_classification_get_model_evaluation] - // [START automl_vision_classification_get_model_evaluation] - System.out.format( - "Classification Model Evaluation Metrics: %s\n", - modelEvaluation.getClassificationEvaluationMetrics()); - // [END automl_language_text_classification_get_model_evaluation] - // [END automl_vision_classification_get_model_evaluation] - - // [START automl_translate_get_model_evaluation] - System.out.format( - "Translate Model Evaluation Metrics: %s\n", - modelEvaluation.getTranslationEvaluationMetrics()); - // [END automl_translate_get_model_evaluation] - - // [START automl_vision_object_detection_get_model_evaluation] - System.out.format( - "Object Detection Model Evaluation Metrics: %s\n", - modelEvaluation.getImageObjectDetectionEvaluationMetrics()); - // [START automl_language_entity_extraction_get_model_evaluation] - // [START automl_language_sentiment_analysis_get_model_evaluation] - // [START automl_language_text_classification_get_model_evaluation] - // [START automl_translate_get_model_evaluation] - // [START automl_vision_classification_get_model_evaluation] - } - } -} -// [END automl_language_entity_extraction_get_model_evaluation] -// [END automl_language_sentiment_analysis_get_model_evaluation] -// [END automl_language_text_classification_get_model_evaluation] -// [END automl_translate_get_model_evaluation] -// [END automl_vision_classification_get_model_evaluation] -// [END automl_vision_object_detection_get_model_evaluation] diff --git a/samples/snippets/src/main/java/com/example/automl/GetOperationStatus.java b/samples/snippets/src/main/java/com/example/automl/GetOperationStatus.java deleted file mode 100644 index 07bfe0293..000000000 --- a/samples/snippets/src/main/java/com/example/automl/GetOperationStatus.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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; - -// [START automl_get_operation_status] -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.longrunning.Operation; -import java.io.IOException; - -class GetOperationStatus { - - static void getOperationStatus() throws IOException { - // 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) 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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the latest state of a long-running operation. - Operation operation = client.getOperationsClient().getOperation(operationFullId); - - // Display operation details. - System.out.println("Operation details:"); - System.out.format("\tName: %s\n", operation.getName()); - System.out.format("\tMetadata Type Url: %s\n", operation.getMetadata().getTypeUrl()); - System.out.format("\tDone: %s\n", operation.getDone()); - if (operation.hasResponse()) { - System.out.format("\tResponse Type Url: %s\n", operation.getResponse().getTypeUrl()); - } - if (operation.hasError()) { - System.out.println("\tResponse:"); - System.out.format("\t\tError code: %s\n", operation.getError().getCode()); - System.out.format("\t\tError message: %s\n", operation.getError().getMessage()); - } - } - } -} -// [END automl_get_operation_status] diff --git a/samples/snippets/src/main/java/com/example/automl/ImportDataset.java b/samples/snippets/src/main/java/com/example/automl/ImportDataset.java deleted file mode 100644 index 3ead88326..000000000 --- a/samples/snippets/src/main/java/com/example/automl/ImportDataset.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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; - -// [START automl_import_dataset] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.DatasetName; -import com.google.cloud.automl.v1.GcsSource; -import com.google.cloud.automl.v1.InputConfig; -import com.google.cloud.automl.v1.OperationMetadata; -import com.google.protobuf.Empty; -import java.io.IOException; -import java.util.Arrays; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -class ImportDataset { - - public static void main(String[] args) - throws IOException, ExecutionException, InterruptedException, TimeoutException { - // 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); - } - - // Import a dataset - static void importDataset(String projectId, String datasetId, String path) - throws IOException, ExecutionException, InterruptedException, TimeoutException { - // 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); - - // Get multiple Google Cloud Storage URIs to import data from - GcsSource gcsSource = - GcsSource.newBuilder().addAllInputUris(Arrays.asList(path.split(","))).build(); - - // Import data from the input URI - InputConfig inputConfig = InputConfig.newBuilder().setGcsSource(gcsSource).build(); - System.out.println("Processing import..."); - - // Start the import job - OperationFuture operation = - client.importDataAsync(datasetFullId, inputConfig); - - 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(45, TimeUnit.MINUTES); - System.out.format("Dataset imported. %s%n", response); - } catch (TimeoutException e) { - System.out.println("The operation's polling period was not long enough."); - System.out.println("You can use the Operation's name to get the current status."); - System.out.println("The import job is still running and will complete as expected."); - throw e; - } - } -} -// [END automl_import_dataset] diff --git a/samples/snippets/src/main/java/com/example/automl/LanguageEntityExtractionCreateDataset.java b/samples/snippets/src/main/java/com/example/automl/LanguageEntityExtractionCreateDataset.java deleted file mode 100644 index 7adf18dc6..000000000 --- a/samples/snippets/src/main/java/com/example/automl/LanguageEntityExtractionCreateDataset.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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; - -// [START automl_language_entity_extraction_create_dataset] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.Dataset; -import com.google.cloud.automl.v1.LocationName; -import com.google.cloud.automl.v1.OperationMetadata; -import com.google.cloud.automl.v1.TextExtractionDatasetMetadata; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class LanguageEntityExtractionCreateDataset { - - 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"; - createDataset(projectId, displayName); - } - - // Create a dataset - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - - TextExtractionDatasetMetadata metadata = TextExtractionDatasetMetadata.newBuilder().build(); - Dataset dataset = - Dataset.newBuilder() - .setDisplayName(displayName) - .setTextExtractionDatasetMetadata(metadata) - .build(); - OperationFuture future = - client.createDatasetAsync(projectLocation, dataset); - - Dataset createdDataset = future.get(); - - // Display the dataset information. - System.out.format("Dataset name: %s\n", createdDataset.getName()); - // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are - // required for other methods. - // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}` - String[] names = createdDataset.getName().split("/"); - String datasetId = names[names.length - 1]; - System.out.format("Dataset id: %s\n", datasetId); - } - } -} -// [END automl_language_entity_extraction_create_dataset] diff --git a/samples/snippets/src/main/java/com/example/automl/LanguageEntityExtractionCreateModel.java b/samples/snippets/src/main/java/com/example/automl/LanguageEntityExtractionCreateModel.java deleted file mode 100644 index f2da97894..000000000 --- a/samples/snippets/src/main/java/com/example/automl/LanguageEntityExtractionCreateModel.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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; - -// [START automl_language_entity_extraction_create_model] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.LocationName; -import com.google.cloud.automl.v1.Model; -import com.google.cloud.automl.v1.OperationMetadata; -import com.google.cloud.automl.v1.TextExtractionModelMetadata; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class LanguageEntityExtractionCreateModel { - - 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"; - String displayName = "YOUR_DATASET_NAME"; - createModel(projectId, datasetId, displayName); - } - - // Create a model - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - // Set model metadata. - TextExtractionModelMetadata metadata = TextExtractionModelMetadata.newBuilder().build(); - Model model = - Model.newBuilder() - .setDisplayName(displayName) - .setDatasetId(datasetId) - .setTextExtractionModelMetadata(metadata) - .build(); - - // Create a model with the model metadata in the region. - OperationFuture future = - client.createModelAsync(projectLocation, model); - // OperationFuture.get() will block until the model is created, which may take several hours. - // You can use OperationFuture.getInitialFuture to get a future representing the initial - // response to the request, which contains information while the operation is in progress. - System.out.format("Training operation name: %s\n", future.getInitialFuture().get().getName()); - System.out.println("Training started..."); - } - } -} -// [END automl_language_entity_extraction_create_model] diff --git a/samples/snippets/src/main/java/com/example/automl/LanguageEntityExtractionPredict.java b/samples/snippets/src/main/java/com/example/automl/LanguageEntityExtractionPredict.java deleted file mode 100644 index 065990613..000000000 --- a/samples/snippets/src/main/java/com/example/automl/LanguageEntityExtractionPredict.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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; - -// [START automl_language_entity_extraction_predict] -import com.google.cloud.automl.v1.AnnotationPayload; -import com.google.cloud.automl.v1.ExamplePayload; -import com.google.cloud.automl.v1.ModelName; -import com.google.cloud.automl.v1.PredictRequest; -import com.google.cloud.automl.v1.PredictResponse; -import com.google.cloud.automl.v1.PredictionServiceClient; -import com.google.cloud.automl.v1.TextSegment; -import com.google.cloud.automl.v1.TextSnippet; -import java.io.IOException; - -class LanguageEntityExtractionPredict { - - static void predict() throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String modelId = "YOUR_MODEL_ID"; - String content = "text to predict"; - predict(projectId, modelId, content); - } - - static void predict(String projectId, String modelId, String content) 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. - try (PredictionServiceClient client = PredictionServiceClient.create()) { - // Get the full path of the model. - ModelName name = ModelName.of(projectId, "us-central1", modelId); - - // For available mime types, see: - // https://cloud.google.com/automl/docs/reference/rest/v1/projects.locations.models/predict#textsnippet - TextSnippet textSnippet = - TextSnippet.newBuilder() - .setContent(content) - .setMimeType("text/plain") // Types: text/plain, text/html - .build(); - ExamplePayload payload = ExamplePayload.newBuilder().setTextSnippet(textSnippet).build(); - PredictRequest predictRequest = - PredictRequest.newBuilder().setName(name.toString()).setPayload(payload).build(); - - PredictResponse response = client.predict(predictRequest); - - for (AnnotationPayload annotationPayload : response.getPayloadList()) { - System.out.format("Text Extract Entity Type: %s\n", annotationPayload.getDisplayName()); - System.out.format("Text score: %.2f\n", annotationPayload.getTextExtraction().getScore()); - TextSegment textSegment = annotationPayload.getTextExtraction().getTextSegment(); - System.out.format("Text Extract Entity Content: %s\n", textSegment.getContent()); - System.out.format("Text Start Offset: %s\n", textSegment.getStartOffset()); - System.out.format("Text End Offset: %s\n\n", textSegment.getEndOffset()); - } - } - } -} -// [END automl_language_entity_extraction_predict] diff --git a/samples/snippets/src/main/java/com/example/automl/LanguageSentimentAnalysisCreateDataset.java b/samples/snippets/src/main/java/com/example/automl/LanguageSentimentAnalysisCreateDataset.java deleted file mode 100644 index 6ab0be858..000000000 --- a/samples/snippets/src/main/java/com/example/automl/LanguageSentimentAnalysisCreateDataset.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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; - -// [START automl_language_sentiment_analysis_create_dataset] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.Dataset; -import com.google.cloud.automl.v1.LocationName; -import com.google.cloud.automl.v1.OperationMetadata; -import com.google.cloud.automl.v1.TextSentimentDatasetMetadata; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class LanguageSentimentAnalysisCreateDataset { - - 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"; - createDataset(projectId, displayName); - } - - // Create a dataset - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - // Specify the text classification type for the dataset. - TextSentimentDatasetMetadata metadata = - TextSentimentDatasetMetadata.newBuilder() - .setSentimentMax(4) // Possible max sentiment score: 1-10 - .build(); - Dataset dataset = - Dataset.newBuilder() - .setDisplayName(displayName) - .setTextSentimentDatasetMetadata(metadata) - .build(); - OperationFuture future = - client.createDatasetAsync(projectLocation, dataset); - - Dataset createdDataset = future.get(); - - // Display the dataset information. - System.out.format("Dataset name: %s\n", createdDataset.getName()); - // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are - // required for other methods. - // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}` - String[] names = createdDataset.getName().split("/"); - String datasetId = names[names.length - 1]; - System.out.format("Dataset id: %s\n", datasetId); - } - } -} -// [END automl_language_sentiment_analysis_create_dataset] diff --git a/samples/snippets/src/main/java/com/example/automl/LanguageSentimentAnalysisCreateModel.java b/samples/snippets/src/main/java/com/example/automl/LanguageSentimentAnalysisCreateModel.java deleted file mode 100644 index 04af77592..000000000 --- a/samples/snippets/src/main/java/com/example/automl/LanguageSentimentAnalysisCreateModel.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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; - -// [START automl_language_sentiment_analysis_create_model] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.LocationName; -import com.google.cloud.automl.v1.Model; -import com.google.cloud.automl.v1.OperationMetadata; -import com.google.cloud.automl.v1.TextSentimentModelMetadata; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class LanguageSentimentAnalysisCreateModel { - - 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"; - String displayName = "YOUR_DATASET_NAME"; - createModel(projectId, datasetId, displayName); - } - - // Create a model - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - // Set model metadata. - System.out.println(datasetId); - TextSentimentModelMetadata metadata = TextSentimentModelMetadata.newBuilder().build(); - Model model = - Model.newBuilder() - .setDisplayName(displayName) - .setDatasetId(datasetId) - .setTextSentimentModelMetadata(metadata) - .build(); - - // Create a model with the model metadata in the region. - OperationFuture future = - client.createModelAsync(projectLocation, model); - // OperationFuture.get() will block until the model is created, which may take several hours. - // You can use OperationFuture.getInitialFuture to get a future representing the initial - // response to the request, which contains information while the operation is in progress. - System.out.format("Training operation name: %s\n", future.getInitialFuture().get().getName()); - System.out.println("Training started..."); - } - } -} -// [END automl_language_sentiment_analysis_create_model] diff --git a/samples/snippets/src/main/java/com/example/automl/LanguageSentimentAnalysisPredict.java b/samples/snippets/src/main/java/com/example/automl/LanguageSentimentAnalysisPredict.java deleted file mode 100644 index 65945c260..000000000 --- a/samples/snippets/src/main/java/com/example/automl/LanguageSentimentAnalysisPredict.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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; - -// [START automl_language_sentiment_analysis_predict] -import com.google.cloud.automl.v1.AnnotationPayload; -import com.google.cloud.automl.v1.ExamplePayload; -import com.google.cloud.automl.v1.ModelName; -import com.google.cloud.automl.v1.PredictRequest; -import com.google.cloud.automl.v1.PredictResponse; -import com.google.cloud.automl.v1.PredictionServiceClient; -import com.google.cloud.automl.v1.TextSnippet; -import java.io.IOException; - -class LanguageSentimentAnalysisPredict { - - static void predict() throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String modelId = "YOUR_MODEL_ID"; - String content = "text to predict"; - predict(projectId, modelId, content); - } - - static void predict(String projectId, String modelId, String content) 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. - try (PredictionServiceClient client = PredictionServiceClient.create()) { - // Get the full path of the model. - ModelName name = ModelName.of(projectId, "us-central1", modelId); - - // For available mime types, see: - // https://cloud.google.com/automl/docs/reference/rest/v1/projects.locations.models/predict#textsnippet - TextSnippet textSnippet = - TextSnippet.newBuilder() - .setContent(content) - .setMimeType("text/plain") // Types: text/plain, text/html - .build(); - ExamplePayload payload = ExamplePayload.newBuilder().setTextSnippet(textSnippet).build(); - PredictRequest predictRequest = - PredictRequest.newBuilder().setName(name.toString()).setPayload(payload).build(); - - PredictResponse response = client.predict(predictRequest); - - for (AnnotationPayload annotationPayload : response.getPayloadList()) { - System.out.format("Predicted class name: %s\n", annotationPayload.getDisplayName()); - System.out.format( - "Predicted sentiment score: %d\n", annotationPayload.getTextSentiment().getSentiment()); - } - } - } -} -// [END automl_language_sentiment_analysis_predict] diff --git a/samples/snippets/src/main/java/com/example/automl/LanguageTextClassificationCreateDataset.java b/samples/snippets/src/main/java/com/example/automl/LanguageTextClassificationCreateDataset.java deleted file mode 100644 index 9332c06a2..000000000 --- a/samples/snippets/src/main/java/com/example/automl/LanguageTextClassificationCreateDataset.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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; - -// [START automl_language_text_classification_create_dataset] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.ClassificationType; -import com.google.cloud.automl.v1.Dataset; -import com.google.cloud.automl.v1.LocationName; -import com.google.cloud.automl.v1.OperationMetadata; -import com.google.cloud.automl.v1.TextClassificationDatasetMetadata; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class LanguageTextClassificationCreateDataset { - - public static void main(String[] args) - throws IOException, ExecutionException, InterruptedException { - // 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) - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - - // Specify the classification type - // Types: - // MultiLabel: Multiple labels are allowed for one example. - // MultiClass: At most one label is allowed per example. - ClassificationType classificationType = ClassificationType.MULTILABEL; - - // Specify the text classification type for the dataset. - TextClassificationDatasetMetadata metadata = - TextClassificationDatasetMetadata.newBuilder() - .setClassificationType(classificationType) - .build(); - Dataset dataset = - Dataset.newBuilder() - .setDisplayName(displayName) - .setTextClassificationDatasetMetadata(metadata) - .build(); - OperationFuture future = - client.createDatasetAsync(projectLocation, dataset); - - Dataset createdDataset = future.get(); - - // Display the dataset information. - System.out.format("Dataset name: %s\n", createdDataset.getName()); - // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are - // required for other methods. - // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}` - String[] names = createdDataset.getName().split("/"); - String datasetId = names[names.length - 1]; - System.out.format("Dataset id: %s\n", datasetId); - } - } -} -// [END automl_language_text_classification_create_dataset] diff --git a/samples/snippets/src/main/java/com/example/automl/LanguageTextClassificationCreateModel.java b/samples/snippets/src/main/java/com/example/automl/LanguageTextClassificationCreateModel.java deleted file mode 100644 index bf26db031..000000000 --- a/samples/snippets/src/main/java/com/example/automl/LanguageTextClassificationCreateModel.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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; - -// [START automl_language_text_classification_create_model] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.LocationName; -import com.google.cloud.automl.v1.Model; -import com.google.cloud.automl.v1.OperationMetadata; -import com.google.cloud.automl.v1.TextClassificationModelMetadata; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class LanguageTextClassificationCreateModel { - - public static void main(String[] args) - throws IOException, ExecutionException, InterruptedException { - // 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) - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - // Set model metadata. - TextClassificationModelMetadata metadata = - TextClassificationModelMetadata.newBuilder().build(); - Model model = - Model.newBuilder() - .setDisplayName(displayName) - .setDatasetId(datasetId) - .setTextClassificationModelMetadata(metadata) - .build(); - - // Create a model with the model metadata in the region. - OperationFuture future = - client.createModelAsync(projectLocation, model); - // OperationFuture.get() will block until the model is created, which may take several hours. - // You can use OperationFuture.getInitialFuture to get a future representing the initial - // response to the request, which contains information while the operation is in progress. - System.out.format("Training operation name: %s\n", future.getInitialFuture().get().getName()); - System.out.println("Training started..."); - } - } -} -// [END automl_language_text_classification_create_model] diff --git a/samples/snippets/src/main/java/com/example/automl/LanguageTextClassificationPredict.java b/samples/snippets/src/main/java/com/example/automl/LanguageTextClassificationPredict.java deleted file mode 100644 index e2da94aa1..000000000 --- a/samples/snippets/src/main/java/com/example/automl/LanguageTextClassificationPredict.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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; - -// [START automl_language_text_classification_predict] -import com.google.cloud.automl.v1.AnnotationPayload; -import com.google.cloud.automl.v1.ExamplePayload; -import com.google.cloud.automl.v1.ModelName; -import com.google.cloud.automl.v1.PredictRequest; -import com.google.cloud.automl.v1.PredictResponse; -import com.google.cloud.automl.v1.PredictionServiceClient; -import com.google.cloud.automl.v1.TextSnippet; -import java.io.IOException; - -class LanguageTextClassificationPredict { - - public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String modelId = "YOUR_MODEL_ID"; - String content = "text to predict"; - predict(projectId, modelId, content); - } - - static void predict(String projectId, String modelId, String content) 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. - try (PredictionServiceClient client = PredictionServiceClient.create()) { - // Get the full path of the model. - ModelName name = ModelName.of(projectId, "us-central1", modelId); - - // For available mime types, see: - // https://cloud.google.com/automl/docs/reference/rest/v1/projects.locations.models/predict#textsnippet - TextSnippet textSnippet = - TextSnippet.newBuilder() - .setContent(content) - .setMimeType("text/plain") // Types: text/plain, text/html - .build(); - ExamplePayload payload = ExamplePayload.newBuilder().setTextSnippet(textSnippet).build(); - PredictRequest predictRequest = - PredictRequest.newBuilder().setName(name.toString()).setPayload(payload).build(); - - PredictResponse response = client.predict(predictRequest); - - for (AnnotationPayload annotationPayload : response.getPayloadList()) { - System.out.format("Predicted class name: %s\n", annotationPayload.getDisplayName()); - System.out.format( - "Predicted sentiment score: %.2f\n\n", - annotationPayload.getClassification().getScore()); - } - } - } -} -// [END automl_language_text_classification_predict] diff --git a/samples/snippets/src/main/java/com/example/automl/ListDatasets.java b/samples/snippets/src/main/java/com/example/automl/ListDatasets.java deleted file mode 100644 index b766a673f..000000000 --- a/samples/snippets/src/main/java/com/example/automl/ListDatasets.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * 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; - -// [START automl_language_entity_extraction_list_datasets] -// [START automl_language_sentiment_analysis_list_datasets] -// [START automl_language_text_classification_list_datasets] -// [START automl_translate_list_datasets] -// [START automl_vision_classification_list_datasets] -// [START automl_vision_object_detection_list_datasets] -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.Dataset; -import com.google.cloud.automl.v1.ListDatasetsRequest; -import com.google.cloud.automl.v1.LocationName; -import java.io.IOException; - -class 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) 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - ListDatasetsRequest request = - ListDatasetsRequest.newBuilder().setParent(projectLocation.toString()).build(); - - // List all the datasets available in the region by applying filter. - System.out.println("List of datasets:"); - for (Dataset dataset : client.listDatasets(request).iterateAll()) { - // Display the dataset information - System.out.format("\nDataset name: %s\n", dataset.getName()); - // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are - // required for other methods. - // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}` - String[] names = dataset.getName().split("/"); - String retrievedDatasetId = names[names.length - 1]; - System.out.format("Dataset id: %s\n", retrievedDatasetId); - System.out.format("Dataset display name: %s\n", dataset.getDisplayName()); - System.out.println("Dataset create time:"); - System.out.format("\tseconds: %s\n", dataset.getCreateTime().getSeconds()); - System.out.format("\tnanos: %s\n", dataset.getCreateTime().getNanos()); - // [END automl_language_sentiment_analysis_list_datasets] - // [END automl_language_text_classification_list_datasets] - // [END automl_translate_list_datasets] - // [END automl_vision_classification_list_datasets] - // [END automl_vision_object_detection_list_datasets] - System.out.format( - "Text extraction dataset metadata: %s\n", dataset.getTextExtractionDatasetMetadata()); - // [END automl_language_entity_extraction_list_datasets] - - // [START automl_language_sentiment_analysis_list_datasets] - System.out.format( - "Text sentiment dataset metadata: %s\n", dataset.getTextSentimentDatasetMetadata()); - // [END automl_language_sentiment_analysis_list_datasets] - - // [START automl_language_text_classification_list_datasets] - System.out.format( - "Text classification dataset metadata: %s\n", - dataset.getTextClassificationDatasetMetadata()); - // [END automl_language_text_classification_list_datasets] - - // [START automl_translate_list_datasets] - System.out.println("Translation dataset metadata:"); - System.out.format( - "\tSource language code: %s\n", - dataset.getTranslationDatasetMetadata().getSourceLanguageCode()); - System.out.format( - "\tTarget language code: %s\n", - dataset.getTranslationDatasetMetadata().getTargetLanguageCode()); - // [END automl_translate_list_datasets] - - // [START automl_vision_classification_list_datasets] - System.out.format( - "Image classification dataset metadata: %s\n", - dataset.getImageClassificationDatasetMetadata()); - // [END automl_vision_classification_list_datasets] - - // [START automl_vision_object_detection_list_datasets] - System.out.format( - "Image object detection dataset metadata: %s\n", - dataset.getImageObjectDetectionDatasetMetadata()); - // [START automl_language_entity_extraction_list_datasets] - // [START automl_language_sentiment_analysis_list_datasets] - // [START automl_language_text_classification_list_datasets] - // [START automl_translate_list_datasets] - // [START automl_vision_classification_list_datasets] - } - } - } -} -// [END automl_language_entity_extraction_list_datasets] -// [END automl_language_sentiment_analysis_list_datasets] -// [END automl_language_text_classification_list_datasets] -// [END automl_translate_list_datasets] -// [END automl_vision_classification_list_datasets] -// [END automl_vision_object_detection_list_datasets] diff --git a/samples/snippets/src/main/java/com/example/automl/ListModelEvaluations.java b/samples/snippets/src/main/java/com/example/automl/ListModelEvaluations.java deleted file mode 100644 index 5b25ec08f..000000000 --- a/samples/snippets/src/main/java/com/example/automl/ListModelEvaluations.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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; - -// [START automl_language_entity_extraction_list_model_evaluations] -// [START automl_language_sentiment_analysis_list_model_evaluations] -// [START automl_language_text_classification_list_model_evaluations] -// [START automl_translate_list_model_evaluations] -// [START automl_vision_classification_list_model_evaluations] -// [START automl_vision_object_detection_list_model_evaluations] - -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.ListModelEvaluationsRequest; -import com.google.cloud.automl.v1.ModelEvaluation; -import com.google.cloud.automl.v1.ModelName; -import java.io.IOException; - -class ListModelEvaluations { - - public static void main(String[] args) throws IOException { - // 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) 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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the model. - ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId); - ListModelEvaluationsRequest modelEvaluationsrequest = - ListModelEvaluationsRequest.newBuilder().setParent(modelFullId.toString()).build(); - - // List all the model evaluations in the model by applying filter. - System.out.println("List of model evaluations:"); - for (ModelEvaluation modelEvaluation : - client.listModelEvaluations(modelEvaluationsrequest).iterateAll()) { - - System.out.format("Model Evaluation Name: %s\n", modelEvaluation.getName()); - System.out.format("Model Annotation Spec Id: %s", modelEvaluation.getAnnotationSpecId()); - System.out.println("Create Time:"); - System.out.format("\tseconds: %s\n", modelEvaluation.getCreateTime().getSeconds()); - System.out.format("\tnanos: %s", modelEvaluation.getCreateTime().getNanos() / 1e9); - System.out.format( - "Evalution Example Count: %d\n", modelEvaluation.getEvaluatedExampleCount()); - // [END automl_language_sentiment_analysis_list_model_evaluations] - // [END automl_language_text_classification_list_model_evaluations] - // [END automl_translate_list_model_evaluations] - // [END automl_vision_classification_list_model_evaluations] - // [END automl_vision_object_detection_list_model_evaluations] - System.out.format( - "Entity Extraction Model Evaluation Metrics: %s\n", - modelEvaluation.getTextExtractionEvaluationMetrics()); - // [END automl_language_entity_extraction_list_model_evaluations] - - // [START automl_language_sentiment_analysis_list_model_evaluations] - System.out.format( - "Sentiment Analysis Model Evaluation Metrics: %s\n", - modelEvaluation.getTextSentimentEvaluationMetrics()); - // [END automl_language_sentiment_analysis_list_model_evaluations] - - // [START automl_language_text_classification_list_model_evaluations] - // [START automl_vision_classification_list_model_evaluations] - System.out.format( - "Classification Model Evaluation Metrics: %s\n", - modelEvaluation.getClassificationEvaluationMetrics()); - // [END automl_language_text_classification_list_model_evaluations] - // [END automl_vision_classification_list_model_evaluations] - - // [START automl_translate_list_model_evaluations] - System.out.format( - "Translate Model Evaluation Metrics: %s\n", - modelEvaluation.getTranslationEvaluationMetrics()); - // [END automl_translate_list_model_evaluations] - - // [START automl_vision_object_detection_list_model_evaluations] - System.out.format( - "Object Detection Model Evaluation Metrics: %s\n", - modelEvaluation.getImageObjectDetectionEvaluationMetrics()); - // [START automl_language_entity_extraction_list_model_evaluations] - // [START automl_language_sentiment_analysis_list_model_evaluations] - // [START automl_language_text_classification_list_model_evaluations] - // [START automl_translate_list_model_evaluations] - // [START automl_vision_classification_list_model_evaluations] - } - } - } -} -// [END automl_language_entity_extraction_list_model_evaluations] -// [END automl_language_sentiment_analysis_list_model_evaluations] -// [END automl_language_text_classification_list_model_evaluations] -// [END automl_translate_list_model_evaluations] -// [END automl_vision_classification_list_model_evaluations] -// [END automl_vision_object_detection_list_model_evaluations] diff --git a/samples/snippets/src/main/java/com/example/automl/ListModels.java b/samples/snippets/src/main/java/com/example/automl/ListModels.java deleted file mode 100644 index c24f09b28..000000000 --- a/samples/snippets/src/main/java/com/example/automl/ListModels.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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; - -// [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; -import com.google.cloud.automl.v1.Model; -import java.io.IOException; - -class ListModels { - - static void listModels() throws IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - listModels(projectId); - } - - // List the models available in the specified location - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - - // Create list models request. - ListModelsRequest listModelsRequest = - ListModelsRequest.newBuilder() - .setParent(projectLocation.toString()) - .setFilter("") - .build(); - - // List all the models available in the region by applying filter. - System.out.println("List of models:"); - for (Model model : client.listModels(listModelsRequest).iterateAll()) { - // Display the model information. - System.out.format("Model name: %s\n", model.getName()); - // To get the model id, you have to parse it out of the `name` field. As models Ids are - // required for other methods. - // Name Format: `projects/{project_id}/locations/{location_id}/models/{model_id}` - String[] names = model.getName().split("/"); - String retrievedModelId = names[names.length - 1]; - System.out.format("Model id: %s\n", retrievedModelId); - System.out.format("Model display name: %s\n", model.getDisplayName()); - System.out.println("Model create time:"); - 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()); - } - } - } -} -// [END automl_list_models] diff --git a/samples/snippets/src/main/java/com/example/automl/ListOperationStatus.java b/samples/snippets/src/main/java/com/example/automl/ListOperationStatus.java deleted file mode 100644 index a980d41ba..000000000 --- a/samples/snippets/src/main/java/com/example/automl/ListOperationStatus.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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; - -// [START automl_list_operation_status] -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.LocationName; -import com.google.longrunning.ListOperationsRequest; -import com.google.longrunning.Operation; -import java.io.IOException; - -class 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) 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - - // Create list operations request. - ListOperationsRequest listrequest = - ListOperationsRequest.newBuilder().setName(projectLocation.toString()).build(); - - // List all the operations names available in the region by applying filter. - for (Operation operation : - client.getOperationsClient().listOperations(listrequest).iterateAll()) { - System.out.println("Operation details:"); - System.out.format("\tName: %s\n", operation.getName()); - System.out.format("\tMetadata Type Url: %s\n", operation.getMetadata().getTypeUrl()); - System.out.format("\tDone: %s\n", operation.getDone()); - if (operation.hasResponse()) { - System.out.format("\tResponse Type Url: %s\n", operation.getResponse().getTypeUrl()); - } - if (operation.hasError()) { - System.out.println("\tResponse:"); - System.out.format("\t\tError code: %s\n", operation.getError().getCode()); - System.out.format("\t\tError message: %s\n\n", operation.getError().getMessage()); - } - } - } - } -} -// [END automl_list_operation_status] diff --git a/samples/snippets/src/main/java/com/example/automl/TranslateCreateDataset.java b/samples/snippets/src/main/java/com/example/automl/TranslateCreateDataset.java deleted file mode 100644 index 77769bdbe..000000000 --- a/samples/snippets/src/main/java/com/example/automl/TranslateCreateDataset.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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; - -// [START automl_translate_create_dataset] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.Dataset; -import com.google.cloud.automl.v1.LocationName; -import com.google.cloud.automl.v1.OperationMetadata; -import com.google.cloud.automl.v1.TranslationDatasetMetadata; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class TranslateCreateDataset { - - public static void main(String[] args) - throws IOException, ExecutionException, InterruptedException { - // 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) - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - - // Specify the source and target language. - TranslationDatasetMetadata translationDatasetMetadata = - TranslationDatasetMetadata.newBuilder() - .setSourceLanguageCode("en") - .setTargetLanguageCode("ja") - .build(); - Dataset dataset = - Dataset.newBuilder() - .setDisplayName(displayName) - .setTranslationDatasetMetadata(translationDatasetMetadata) - .build(); - OperationFuture future = - client.createDatasetAsync(projectLocation, dataset); - - Dataset createdDataset = future.get(); - - // Display the dataset information. - System.out.format("Dataset name: %s\n", createdDataset.getName()); - // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are - // required for other methods. - // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}` - String[] names = createdDataset.getName().split("/"); - String datasetId = names[names.length - 1]; - System.out.format("Dataset id: %s\n", datasetId); - } - } -} -// [END automl_translate_create_dataset] diff --git a/samples/snippets/src/main/java/com/example/automl/TranslateCreateModel.java b/samples/snippets/src/main/java/com/example/automl/TranslateCreateModel.java deleted file mode 100644 index cddd597c6..000000000 --- a/samples/snippets/src/main/java/com/example/automl/TranslateCreateModel.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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; - -// [START automl_translate_create_model] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.LocationName; -import com.google.cloud.automl.v1.Model; -import com.google.cloud.automl.v1.OperationMetadata; -import com.google.cloud.automl.v1.TranslationModelMetadata; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class TranslateCreateModel { - - public static void main(String[] args) - throws IOException, ExecutionException, InterruptedException { - // 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) - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - TranslationModelMetadata translationModelMetadata = - TranslationModelMetadata.newBuilder().build(); - Model model = - Model.newBuilder() - .setDisplayName(displayName) - .setDatasetId(datasetId) - .setTranslationModelMetadata(translationModelMetadata) - .build(); - - // Create a model with the model metadata in the region. - OperationFuture future = - client.createModelAsync(projectLocation, model); - // OperationFuture.get() will block until the model is created, which may take several hours. - // You can use OperationFuture.getInitialFuture to get a future representing the initial - // response to the request, which contains information while the operation is in progress. - System.out.format("Training operation name: %s\n", future.getInitialFuture().get().getName()); - System.out.println("Training started..."); - } - } -} -// [END automl_translate_create_model] diff --git a/samples/snippets/src/main/java/com/example/automl/TranslatePredict.java b/samples/snippets/src/main/java/com/example/automl/TranslatePredict.java deleted file mode 100644 index 2385b831c..000000000 --- a/samples/snippets/src/main/java/com/example/automl/TranslatePredict.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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; - -// [START automl_translate_predict] -import com.google.cloud.automl.v1.ExamplePayload; -import com.google.cloud.automl.v1.ModelName; -import com.google.cloud.automl.v1.PredictRequest; -import com.google.cloud.automl.v1.PredictResponse; -import com.google.cloud.automl.v1.PredictionServiceClient; -import com.google.cloud.automl.v1.TextSnippet; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; - -class TranslatePredict { - - public static void main(String[] args) throws IOException { - // 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); - } - - 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. - try (PredictionServiceClient client = PredictionServiceClient.create()) { - // Get the full path of the model. - ModelName name = ModelName.of(projectId, "us-central1", modelId); - - String content = new String(Files.readAllBytes(Paths.get(filePath))); - - TextSnippet textSnippet = TextSnippet.newBuilder().setContent(content).build(); - ExamplePayload payload = ExamplePayload.newBuilder().setTextSnippet(textSnippet).build(); - PredictRequest predictRequest = - PredictRequest.newBuilder().setName(name.toString()).setPayload(payload).build(); - - PredictResponse response = client.predict(predictRequest); - TextSnippet translatedContent = - response.getPayload(0).getTranslation().getTranslatedContent(); - System.out.format("Translated Content: %s\n", translatedContent.getContent()); - } - } -} -// [END automl_translate_predict] diff --git a/samples/snippets/src/main/java/com/example/automl/UndeployModel.java b/samples/snippets/src/main/java/com/example/automl/UndeployModel.java deleted file mode 100644 index e7ef532e9..000000000 --- a/samples/snippets/src/main/java/com/example/automl/UndeployModel.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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; - -// [START automl_undeploy_model] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.ModelName; -import com.google.cloud.automl.v1.OperationMetadata; -import com.google.cloud.automl.v1.UndeployModelRequest; -import com.google.protobuf.Empty; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class UndeployModel { - - static void undeployModel() throws IOException, ExecutionException, InterruptedException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String modelId = "YOUR_MODEL_ID"; - undeployModel(projectId, modelId); - } - - // Undeploy a model from prediction - static void undeployModel(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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the model. - ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId); - UndeployModelRequest request = - UndeployModelRequest.newBuilder().setName(modelFullId.toString()).build(); - OperationFuture future = client.undeployModelAsync(request); - - future.get(); - System.out.println("Model undeployment finished"); - } - } -} -// [END automl_undeploy_model] diff --git a/samples/snippets/src/main/java/com/example/automl/VisionClassificationCreateDataset.java b/samples/snippets/src/main/java/com/example/automl/VisionClassificationCreateDataset.java deleted file mode 100644 index f3e2d951d..000000000 --- a/samples/snippets/src/main/java/com/example/automl/VisionClassificationCreateDataset.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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; - -// [START automl_vision_classification_create_dataset] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.ClassificationType; -import com.google.cloud.automl.v1.Dataset; -import com.google.cloud.automl.v1.ImageClassificationDatasetMetadata; -import com.google.cloud.automl.v1.LocationName; -import com.google.cloud.automl.v1.OperationMetadata; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class VisionClassificationCreateDataset { - - public static void main(String[] args) - throws IOException, ExecutionException, InterruptedException { - // 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) - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - - // Specify the classification type - // Types: - // MultiLabel: Multiple labels are allowed for one example. - // MultiClass: At most one label is allowed per example. - ClassificationType classificationType = ClassificationType.MULTILABEL; - ImageClassificationDatasetMetadata metadata = - ImageClassificationDatasetMetadata.newBuilder() - .setClassificationType(classificationType) - .build(); - Dataset dataset = - Dataset.newBuilder() - .setDisplayName(displayName) - .setImageClassificationDatasetMetadata(metadata) - .build(); - OperationFuture future = - client.createDatasetAsync(projectLocation, dataset); - - Dataset createdDataset = future.get(); - - // Display the dataset information. - System.out.format("Dataset name: %s\n", createdDataset.getName()); - // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are - // required for other methods. - // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}` - String[] names = createdDataset.getName().split("/"); - String datasetId = names[names.length - 1]; - System.out.format("Dataset id: %s\n", datasetId); - } - } -} -// [END automl_vision_classification_create_dataset] diff --git a/samples/snippets/src/main/java/com/example/automl/VisionClassificationCreateModel.java b/samples/snippets/src/main/java/com/example/automl/VisionClassificationCreateModel.java deleted file mode 100644 index ea4da40b1..000000000 --- a/samples/snippets/src/main/java/com/example/automl/VisionClassificationCreateModel.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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; - -// [START automl_vision_classification_create_model] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.ImageClassificationModelMetadata; -import com.google.cloud.automl.v1.LocationName; -import com.google.cloud.automl.v1.Model; -import com.google.cloud.automl.v1.OperationMetadata; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class VisionClassificationCreateModel { - - public static void main(String[] args) - throws IOException, ExecutionException, InterruptedException { - // 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) - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - // Set model metadata. - ImageClassificationModelMetadata metadata = - ImageClassificationModelMetadata.newBuilder().setTrainBudgetMilliNodeHours(24000).build(); - Model model = - Model.newBuilder() - .setDisplayName(displayName) - .setDatasetId(datasetId) - .setImageClassificationModelMetadata(metadata) - .build(); - - // Create a model with the model metadata in the region. - OperationFuture future = - client.createModelAsync(projectLocation, model); - // OperationFuture.get() will block until the model is created, which may take several hours. - // You can use OperationFuture.getInitialFuture to get a future representing the initial - // response to the request, which contains information while the operation is in progress. - System.out.format("Training operation name: %s\n", future.getInitialFuture().get().getName()); - System.out.println("Training started..."); - } - } -} -// [END automl_vision_classification_create_model] diff --git a/samples/snippets/src/main/java/com/example/automl/VisionClassificationDeployModelNodeCount.java b/samples/snippets/src/main/java/com/example/automl/VisionClassificationDeployModelNodeCount.java deleted file mode 100644 index c2d27f3a1..000000000 --- a/samples/snippets/src/main/java/com/example/automl/VisionClassificationDeployModelNodeCount.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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; - -// [START automl_vision_classification_deploy_model_node_count] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.DeployModelRequest; -import com.google.cloud.automl.v1.ImageClassificationModelDeploymentMetadata; -import com.google.cloud.automl.v1.ModelName; -import com.google.cloud.automl.v1.OperationMetadata; -import com.google.protobuf.Empty; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class VisionClassificationDeployModelNodeCount { - - static void visionClassificationDeployModelNodeCount() - throws InterruptedException, ExecutionException, IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String modelId = "YOUR_MODEL_ID"; - visionClassificationDeployModelNodeCount(projectId, modelId); - } - - // Deploy a model for prediction with a specified node count (can be used to redeploy a model) - static void visionClassificationDeployModelNodeCount(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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the model. - ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId); - ImageClassificationModelDeploymentMetadata metadata = - ImageClassificationModelDeploymentMetadata.newBuilder().setNodeCount(2).build(); - DeployModelRequest request = - DeployModelRequest.newBuilder() - .setName(modelFullId.toString()) - .setImageClassificationModelDeploymentMetadata(metadata) - .build(); - OperationFuture future = client.deployModelAsync(request); - - future.get(); - System.out.println("Model deployment finished"); - } - } -} -// [END automl_vision_classification_deploy_model_node_count] diff --git a/samples/snippets/src/main/java/com/example/automl/VisionClassificationPredict.java b/samples/snippets/src/main/java/com/example/automl/VisionClassificationPredict.java deleted file mode 100644 index 6f110cf9e..000000000 --- a/samples/snippets/src/main/java/com/example/automl/VisionClassificationPredict.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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; - -// [START automl_vision_classification_predict] -import com.google.cloud.automl.v1.AnnotationPayload; -import com.google.cloud.automl.v1.ExamplePayload; -import com.google.cloud.automl.v1.Image; -import com.google.cloud.automl.v1.ModelName; -import com.google.cloud.automl.v1.PredictRequest; -import com.google.cloud.automl.v1.PredictResponse; -import com.google.cloud.automl.v1.PredictionServiceClient; -import com.google.protobuf.ByteString; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; - -class VisionClassificationPredict { - - public static void main(String[] args) throws IOException { - // 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.jpg"; - predict(projectId, modelId, 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. - try (PredictionServiceClient client = PredictionServiceClient.create()) { - // Get the full path of the model. - ModelName name = ModelName.of(projectId, "us-central1", modelId); - ByteString content = ByteString.copyFrom(Files.readAllBytes(Paths.get(filePath))); - Image image = Image.newBuilder().setImageBytes(content).build(); - ExamplePayload payload = ExamplePayload.newBuilder().setImage(image).build(); - PredictRequest predictRequest = - PredictRequest.newBuilder() - .setName(name.toString()) - .setPayload(payload) - .putParams( - "score_threshold", "0.8") // [0.0-1.0] Only produce results higher than this value - .build(); - - PredictResponse response = client.predict(predictRequest); - - for (AnnotationPayload annotationPayload : response.getPayloadList()) { - System.out.format("Predicted class name: %s\n", annotationPayload.getDisplayName()); - System.out.format( - "Predicted class score: %.2f\n", annotationPayload.getClassification().getScore()); - } - } - } -} -// [END automl_vision_classification_predict] diff --git a/samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionCreateDataset.java b/samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionCreateDataset.java deleted file mode 100644 index 874099d53..000000000 --- a/samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionCreateDataset.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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; - -// [START automl_vision_object_detection_create_dataset] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.Dataset; -import com.google.cloud.automl.v1.ImageObjectDetectionDatasetMetadata; -import com.google.cloud.automl.v1.LocationName; -import com.google.cloud.automl.v1.OperationMetadata; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class VisionObjectDetectionCreateDataset { - - 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"; - createDataset(projectId, displayName); - } - - // Create a dataset - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - - ImageObjectDetectionDatasetMetadata metadata = - ImageObjectDetectionDatasetMetadata.newBuilder().build(); - Dataset dataset = - Dataset.newBuilder() - .setDisplayName(displayName) - .setImageObjectDetectionDatasetMetadata(metadata) - .build(); - OperationFuture future = - client.createDatasetAsync(projectLocation, dataset); - - Dataset createdDataset = future.get(); - - // Display the dataset information. - System.out.format("Dataset name: %s\n", createdDataset.getName()); - // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are - // required for other methods. - // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}` - String[] names = createdDataset.getName().split("/"); - String datasetId = names[names.length - 1]; - System.out.format("Dataset id: %s\n", datasetId); - } - } -} -// [END automl_vision_object_detection_create_dataset] diff --git a/samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionCreateModel.java b/samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionCreateModel.java deleted file mode 100644 index 2e0ccbc43..000000000 --- a/samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionCreateModel.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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; - -// [START automl_vision_object_detection_create_model] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.ImageObjectDetectionModelMetadata; -import com.google.cloud.automl.v1.LocationName; -import com.google.cloud.automl.v1.Model; -import com.google.cloud.automl.v1.OperationMetadata; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class VisionObjectDetectionCreateModel { - - 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"; - String displayName = "YOUR_DATASET_NAME"; - createModel(projectId, datasetId, displayName); - } - - // Create a model - 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. - try (AutoMlClient client = AutoMlClient.create()) { - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, "us-central1"); - // Set model metadata. - ImageObjectDetectionModelMetadata metadata = - ImageObjectDetectionModelMetadata.newBuilder().build(); - Model model = - Model.newBuilder() - .setDisplayName(displayName) - .setDatasetId(datasetId) - .setImageObjectDetectionModelMetadata(metadata) - .build(); - - // Create a model with the model metadata in the region. - OperationFuture future = - client.createModelAsync(projectLocation, model); - // OperationFuture.get() will block until the model is created, which may take several hours. - // You can use OperationFuture.getInitialFuture to get a future representing the initial - // response to the request, which contains information while the operation is in progress. - System.out.format("Training operation name: %s\n", future.getInitialFuture().get().getName()); - System.out.println("Training started..."); - } - } -} -// [END automl_vision_object_detection_create_model] diff --git a/samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionDeployModelNodeCount.java b/samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionDeployModelNodeCount.java deleted file mode 100644 index 42621d3e8..000000000 --- a/samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionDeployModelNodeCount.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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; - -// [START automl_vision_object_detection_deploy_model_node_count] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.DeployModelRequest; -import com.google.cloud.automl.v1.ImageObjectDetectionModelDeploymentMetadata; -import com.google.cloud.automl.v1.ModelName; -import com.google.cloud.automl.v1.OperationMetadata; -import com.google.protobuf.Empty; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class VisionObjectDetectionDeployModelNodeCount { - - static void visionObjectDetectionDeployModelNodeCount() - throws InterruptedException, ExecutionException, IOException { - // TODO(developer): Replace these variables before running the sample. - String projectId = "YOUR_PROJECT_ID"; - String modelId = "YOUR_MODEL_ID"; - visionObjectDetectionDeployModelNodeCount(projectId, modelId); - } - - // Deploy a model for prediction with a specified node count (can be used to redeploy a model) - static void visionObjectDetectionDeployModelNodeCount(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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the model. - ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId); - ImageObjectDetectionModelDeploymentMetadata metadata = - ImageObjectDetectionModelDeploymentMetadata.newBuilder().setNodeCount(2).build(); - DeployModelRequest request = - DeployModelRequest.newBuilder() - .setName(modelFullId.toString()) - .setImageObjectDetectionModelDeploymentMetadata(metadata) - .build(); - OperationFuture future = client.deployModelAsync(request); - - future.get(); - System.out.println("Model deployment finished"); - } - } -} -// [END automl_vision_object_detection_deploy_model_node_count] diff --git a/samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionPredict.java b/samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionPredict.java deleted file mode 100644 index 8d7dec6b3..000000000 --- a/samples/snippets/src/main/java/com/example/automl/VisionObjectDetectionPredict.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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; - -// [START automl_vision_object_detection_predict] -import com.google.cloud.automl.v1.AnnotationPayload; -import com.google.cloud.automl.v1.BoundingPoly; -import com.google.cloud.automl.v1.ExamplePayload; -import com.google.cloud.automl.v1.Image; -import com.google.cloud.automl.v1.ModelName; -import com.google.cloud.automl.v1.NormalizedVertex; -import com.google.cloud.automl.v1.PredictRequest; -import com.google.cloud.automl.v1.PredictResponse; -import com.google.cloud.automl.v1.PredictionServiceClient; -import com.google.protobuf.ByteString; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; - -class VisionObjectDetectionPredict { - - static void predict() throws IOException { - // 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.jpg"; - predict(projectId, modelId, 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. - try (PredictionServiceClient client = PredictionServiceClient.create()) { - // Get the full path of the model. - ModelName name = ModelName.of(projectId, "us-central1", modelId); - ByteString content = ByteString.copyFrom(Files.readAllBytes(Paths.get(filePath))); - Image image = Image.newBuilder().setImageBytes(content).build(); - ExamplePayload payload = ExamplePayload.newBuilder().setImage(image).build(); - PredictRequest predictRequest = - PredictRequest.newBuilder() - .setName(name.toString()) - .setPayload(payload) - .putParams( - "score_threshold", "0.5") // [0.0-1.0] Only produce results higher than this value - .build(); - - PredictResponse response = client.predict(predictRequest); - for (AnnotationPayload annotationPayload : response.getPayloadList()) { - System.out.format("Predicted class name: %s\n", annotationPayload.getDisplayName()); - System.out.format( - "Predicted class score: %.2f\n", - annotationPayload.getImageObjectDetection().getScore()); - BoundingPoly boundingPoly = annotationPayload.getImageObjectDetection().getBoundingBox(); - System.out.println("Normalized Vertices:"); - for (NormalizedVertex vertex : boundingPoly.getNormalizedVerticesList()) { - System.out.format("\tX: %.2f, Y: %.2f\n", vertex.getX(), vertex.getY()); - } - } - } - } -} -// [END automl_vision_object_detection_predict] diff --git a/samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ClassificationDeployModel.java b/samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ClassificationDeployModel.java deleted file mode 100644 index 63da52ead..000000000 --- a/samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ClassificationDeployModel.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.google.cloud.vision.samples.automl; - -// [START automl_vision_classification_deploy_model] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.DeployModelRequest; -import com.google.cloud.automl.v1beta1.ModelName; -import com.google.cloud.automl.v1beta1.OperationMetadata; -import com.google.protobuf.Empty; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class ClassificationDeployModel { - - // Deploy a model - static void classificationDeployModel(String projectId, String modelId) - throws IOException, ExecutionException, InterruptedException { - // 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. - try (AutoMlClient client = AutoMlClient.create()) { - - // Get the full path of the model. - ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId); - - // Build deploy model request. - DeployModelRequest deployModelRequest = - DeployModelRequest.newBuilder().setName(modelFullId.toString()).build(); - - // Deploy a model with the deploy model request. - OperationFuture future = - client.deployModelAsync(deployModelRequest); - - future.get(); - - // Display the deployment details of model. - System.out.println("Model deployment finished"); - } - } -} -// [END automl_vision_classification_deploy_model] diff --git a/samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ClassificationDeployModelNodeCount.java b/samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ClassificationDeployModelNodeCount.java deleted file mode 100644 index 655cd7218..000000000 --- a/samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ClassificationDeployModelNodeCount.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.google.cloud.vision.samples.automl; - -// [START automl_vision_classification_deploy_model_node_count] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.DeployModelRequest; -import com.google.cloud.automl.v1beta1.ImageClassificationModelDeploymentMetadata; -import com.google.cloud.automl.v1beta1.ModelName; -import com.google.cloud.automl.v1beta1.OperationMetadata; -import com.google.protobuf.Empty; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class ClassificationDeployModelNodeCount { - - // Deploy a model with a specified node count - static void classificationDeployModelNodeCount(String projectId, String modelId) - throws IOException, ExecutionException, InterruptedException { - // 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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the model. - ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId); - - // Set how many nodes the model is deployed on - ImageClassificationModelDeploymentMetadata deploymentMetadata = - ImageClassificationModelDeploymentMetadata.newBuilder().setNodeCount(2).build(); - - DeployModelRequest request = - DeployModelRequest.newBuilder() - .setName(modelFullId.toString()) - .setImageClassificationModelDeploymentMetadata(deploymentMetadata) - .build(); - // Deploy the model - OperationFuture future = client.deployModelAsync(request); - future.get(); - System.out.println("Model deployment on 2 nodes finished"); - } - } -} -// [END automl_vision_classification_deploy_model_node_count] diff --git a/samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ObjectDetectionDeployModelNodeCount.java b/samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ObjectDetectionDeployModelNodeCount.java deleted file mode 100644 index cd6de5c5b..000000000 --- a/samples/snippets/src/main/java/com/google/cloud/vision/samples/automl/ObjectDetectionDeployModelNodeCount.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.google.cloud.vision.samples.automl; - -// [START automl_vision_object_detection_deploy_model_node_count] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.DeployModelRequest; -import com.google.cloud.automl.v1beta1.ImageObjectDetectionModelDeploymentMetadata; -import com.google.cloud.automl.v1beta1.ModelName; -import com.google.cloud.automl.v1beta1.OperationMetadata; -import com.google.protobuf.Empty; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class ObjectDetectionDeployModelNodeCount { - - static void objectDetectionDeployModelNodeCount(String projectId, String modelId) - throws IOException, ExecutionException, InterruptedException { - // 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. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the model. - ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId); - - // Set how many nodes the model is deployed on - ImageObjectDetectionModelDeploymentMetadata deploymentMetadata = - ImageObjectDetectionModelDeploymentMetadata.newBuilder().setNodeCount(2).build(); - - DeployModelRequest request = - DeployModelRequest.newBuilder() - .setName(modelFullId.toString()) - .setImageObjectDetectionModelDeploymentMetadata(deploymentMetadata) - .build(); - // Deploy the model - OperationFuture future = client.deployModelAsync(request); - future.get(); - System.out.println("Model deployment on 2 nodes finished"); - } - } -} -// [END automl_vision_object_detection_deploy_model_node_count] diff --git a/samples/snippets/src/test/java/beta/automl/BatchPredictTest.java b/samples/snippets/src/test/java/beta/automl/BatchPredictTest.java deleted file mode 100644 index 96c783b65..000000000 --- a/samples/snippets/src/test/java/beta/automl/BatchPredictTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class BatchPredictTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String BUCKET_ID = PROJECT_ID + "-lcm"; - private static final String MODEL_ID = "VCN0000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testBatchPredict() { - // As batch prediction can take a long time. Try to batch predict on a model and confirm that - // the model was not found, but other elements of the request were valid. - try { - String inputUri = String.format("gs://%s/entity-extraction/input.csv", BUCKET_ID); - String outputUri = String.format("gs://%s/TEST_BATCH_PREDICT/", BUCKET_ID); - BatchPredict.batchPredict(PROJECT_ID, MODEL_ID, inputUri, outputUri); - String got = bout.toString(); - assertThat(got).contains("does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/beta/automl/CancelOperationTest.java b/samples/snippets/src/test/java/beta/automl/CancelOperationTest.java deleted file mode 100644 index 2a3d9ab70..000000000 --- a/samples/snippets/src/test/java/beta/automl/CancelOperationTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.api.gax.rpc.NotFoundException; -import io.grpc.StatusRuntimeException; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class CancelOperationTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testCancelOperation() throws IOException { - String operationFullPathId = - String.format( - "projects/%s/locations/%s/operations/%s", PROJECT_ID, "us-central1", "TCN0000000000"); - // Any cancelled operation on models or datasets will be hidden once the operations are flagged - // as failed operations - // which makes them hard to delete in the teardown. - try { - CancelOperation.cancelOperation(operationFullPathId); - String got = bout.toString(); - assertThat(got).contains("not found"); - } catch (NotFoundException | StatusRuntimeException | InterruptedException e) { - assertThat(e.getMessage()).contains("not found"); - } - } -} diff --git a/samples/snippets/src/test/java/beta/automl/DeleteDatasetTest.java b/samples/snippets/src/test/java/beta/automl/DeleteDatasetTest.java deleted file mode 100644 index 5f98603ba..000000000 --- a/samples/snippets/src/test/java/beta/automl/DeleteDatasetTest.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.Dataset; -import com.google.cloud.automl.v1beta1.LocationName; -import com.google.cloud.automl.v1beta1.TextExtractionDatasetMetadata; -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class DeleteDatasetTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private String datasetId; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() throws IOException { - // Create a fake dataset to be deleted - // 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 "_" - String datasetName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - try (AutoMlClient client = AutoMlClient.create()) { - LocationName projectLocation = LocationName.of(PROJECT_ID, "us-central1"); - TextExtractionDatasetMetadata metadata = TextExtractionDatasetMetadata.newBuilder().build(); - Dataset dataset = - Dataset.newBuilder() - .setDisplayName(datasetName) - .setTextExtractionDatasetMetadata(metadata) - .build(); - Dataset createdDataset = client.createDataset(projectLocation, dataset); - String[] names = createdDataset.getName().split("/"); - datasetId = names[names.length - 1]; - } - - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testDeleteDataset() throws IOException, ExecutionException, InterruptedException { - DeleteDataset.deleteDataset(PROJECT_ID, datasetId); - String got = bout.toString(); - assertThat(got).contains("Dataset deleted."); - } -} diff --git a/samples/snippets/src/test/java/beta/automl/DeleteModelTest.java b/samples/snippets/src/test/java/beta/automl/DeleteModelTest.java deleted file mode 100644 index fe03799dc..000000000 --- a/samples/snippets/src/test/java/beta/automl/DeleteModelTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class DeleteModelTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testDeleteModel() { - // As model creation can take many hours, instead try to delete a - // nonexistent model and confirm that the model was not found, but other - // elements of the request were valid. - try { - DeleteModel.deleteModel(PROJECT_ID, "TRL0000000000000000000"); - String got = bout.toString(); - assertThat(got).contains("The model does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("The model does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/beta/automl/DeployModelTest.java b/samples/snippets/src/test/java/beta/automl/DeployModelTest.java deleted file mode 100644 index 144d6aa01..000000000 --- a/samples/snippets/src/test/java/beta/automl/DeployModelTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class DeployModelTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = "TEN0000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testDeployModel() { - // As model deployment can take a long time, instead try to deploy a - // nonexistent model and confirm that the model was not found, but other - // elements of the request were valid. - try { - DeployModel.deployModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("The model does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("The model does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/beta/automl/GetModelEvaluationTest.java b/samples/snippets/src/test/java/beta/automl/GetModelEvaluationTest.java deleted file mode 100644 index 42a00f2b1..000000000 --- a/samples/snippets/src/test/java/beta/automl/GetModelEvaluationTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.ListModelEvaluationsRequest; -import com.google.cloud.automl.v1.ModelEvaluation; -import com.google.cloud.automl.v1.ModelName; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class GetModelEvaluationTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = System.getenv("ENTITY_EXTRACTION_MODEL_ID"); - private String modelEvaluationId; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - requireEnvVar("ENTITY_EXTRACTION_MODEL_ID"); - } - - @Before - public void setUp() throws IOException { - // Get a model evaluation ID from the List request first to be used in the Get call - try (AutoMlClient client = AutoMlClient.create()) { - ModelName modelFullId = ModelName.of(PROJECT_ID, "us-central1", MODEL_ID); - ListModelEvaluationsRequest modelEvaluationsrequest = - ListModelEvaluationsRequest.newBuilder().setParent(modelFullId.toString()).build(); - ModelEvaluation modelEvaluation = - client - .listModelEvaluations(modelEvaluationsrequest) - .getPage() - .getValues() - .iterator() - .next(); - modelEvaluationId = modelEvaluation.getName().split("/modelEvaluations/")[1]; - } - - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testGetModelEvaluation() throws IOException { - GetModelEvaluation.getModelEvaluation(PROJECT_ID, MODEL_ID, modelEvaluationId); - String got = bout.toString(); - assertThat(got).contains("Model Evaluation Name:"); - } -} diff --git a/samples/snippets/src/test/java/beta/automl/GetModelTest.java b/samples/snippets/src/test/java/beta/automl/GetModelTest.java deleted file mode 100644 index 7b80ec291..000000000 --- a/samples/snippets/src/test/java/beta/automl/GetModelTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class GetModelTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = System.getenv("ENTITY_EXTRACTION_MODEL_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - requireEnvVar("ENTITY_EXTRACTION_MODEL_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testGetModel() throws IOException { - GetModel.getModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("Model id: " + MODEL_ID); - } -} diff --git a/samples/snippets/src/test/java/beta/automl/GetOperationStatusTest.java b/samples/snippets/src/test/java/beta/automl/GetOperationStatusTest.java deleted file mode 100644 index 7f63f1ca2..000000000 --- a/samples/snippets/src/test/java/beta/automl/GetOperationStatusTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.LocationName; -import com.google.longrunning.ListOperationsRequest; -import com.google.longrunning.Operation; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class GetOperationStatusTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private String operationId; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() throws IOException { - // Use list operations to get a single operation id for the get call. - try (AutoMlClient client = AutoMlClient.create()) { - LocationName projectLocation = LocationName.of(PROJECT_ID, "us-central1"); - ListOperationsRequest request = - ListOperationsRequest.newBuilder().setName(projectLocation.toString()).build(); - Operation operation = - client.getOperationsClient().listOperations(request).iterateAll().iterator().next(); - operationId = operation.getName(); - } - - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testGetOperationStatus() throws IOException { - GetOperationStatus.getOperationStatus(operationId); - String got = bout.toString(); - assertThat(got).contains("Operation details:"); - } -} diff --git a/samples/snippets/src/test/java/beta/automl/ImportDatasetTest.java b/samples/snippets/src/test/java/beta/automl/ImportDatasetTest.java deleted file mode 100644 index 126838785..000000000 --- a/samples/snippets/src/test/java/beta/automl/ImportDatasetTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.api.gax.rpc.NotFoundException; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class ImportDatasetTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String BUCKET_ID = PROJECT_ID + "-lcm"; - private static final String BUCKET = "gs://" + BUCKET_ID; - private String datasetId; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testImportDataset() throws TimeoutException { - try { - ImportDataset.importDataset( - PROJECT_ID, "TCN0000000000", BUCKET + "/entity-extraction/dataset.csv"); - String got = bout.toString(); - assertThat(got).contains("doesn't exist"); - } catch (NotFoundException | IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("doesn't exist"); - } - } -} diff --git a/samples/snippets/src/test/java/beta/automl/ListDatasetsTest.java b/samples/snippets/src/test/java/beta/automl/ListDatasetsTest.java deleted file mode 100644 index 62bdf6144..000000000 --- a/samples/snippets/src/test/java/beta/automl/ListDatasetsTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class ListDatasetsTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testListDataset() throws IOException { - ListDatasets.listDatasets(PROJECT_ID); - String got = bout.toString(); - assertThat(got).contains("Dataset id:"); - } -} diff --git a/samples/snippets/src/test/java/beta/automl/ListModelEvaluationsTest.java b/samples/snippets/src/test/java/beta/automl/ListModelEvaluationsTest.java deleted file mode 100644 index d8c4cb6ac..000000000 --- a/samples/snippets/src/test/java/beta/automl/ListModelEvaluationsTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class ListModelEvaluationsTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = System.getenv("ENTITY_EXTRACTION_MODEL_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - requireEnvVar("ENTITY_EXTRACTION_MODEL_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testListModelEvaluations() throws IOException { - ListModelEvaluations.listModelEvaluations(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("Model Evaluation Name:"); - } -} diff --git a/samples/snippets/src/test/java/beta/automl/ListModelsTest.java b/samples/snippets/src/test/java/beta/automl/ListModelsTest.java deleted file mode 100644 index 6b70440d6..000000000 --- a/samples/snippets/src/test/java/beta/automl/ListModelsTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class ListModelsTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - // Skipping this test until backend is cleaned up. - // https://github.com/googleapis/java-automl/issues/291 - @Test - @Ignore - public void testListModels() throws IOException { - ListModels.listModels(PROJECT_ID); - String got = bout.toString(); - assertThat(got).contains("Model id:"); - } -} diff --git a/samples/snippets/src/test/java/beta/automl/SetEndpointIT.java b/samples/snippets/src/test/java/beta/automl/SetEndpointIT.java deleted file mode 100644 index b74742e71..000000000 --- a/samples/snippets/src/test/java/beta/automl/SetEndpointIT.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Tests for Automl Set Endpoint */ -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class SetEndpointIT { - - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testSetEndpoint() throws IOException { - // Act - SetEndpoint.setEndpoint(PROJECT_ID); - - // Assert - String got = bout.toString(); - assertThat(got).contains("display_name: \"do_not_delete_eu\""); - } -} diff --git a/samples/snippets/src/test/java/beta/automl/TablesBatchPredictBigQueryTest.java b/samples/snippets/src/test/java/beta/automl/TablesBatchPredictBigQueryTest.java deleted file mode 100644 index 173564c13..000000000 --- a/samples/snippets/src/test/java/beta/automl/TablesBatchPredictBigQueryTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class TablesBatchPredictBigQueryTest { - - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String MODEL_ID = "TBL0000000000000000000"; - private static final String INPUT_URI = - String.format( - "bq://%s.automl_do_not_delete_predict_test.automl_predict_test_table", PROJECT_ID); - private static final String OUTPUT_URI = "bq://" + PROJECT_ID; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testTablesBigQueryBatchPredict() { - // As batch prediction can take a long time. Try to batch predict on a model and confirm that - // the model was not found, but other elements of the request were valid. - try { - TablesBatchPredictBigQuery.batchPredict(PROJECT_ID, MODEL_ID, INPUT_URI, OUTPUT_URI); - String got = bout.toString(); - assertThat(got).contains("does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/beta/automl/TablesCreateDatasetTest.java b/samples/snippets/src/test/java/beta/automl/TablesCreateDatasetTest.java deleted file mode 100644 index d5aab148f..000000000 --- a/samples/snippets/src/test/java/beta/automl/TablesCreateDatasetTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class TablesCreateDatasetTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private String datasetId; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() throws InterruptedException, ExecutionException, IOException { - // Delete the created dataset - DeleteDataset.deleteDataset(PROJECT_ID, datasetId); - System.setOut(originalPrintStream); - } - - @Test - public void testTablesCreateDataset() - 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 "_" - String datasetName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - TablesCreateDataset.createDataset(PROJECT_ID, datasetName); - - String got = bout.toString(); - assertThat(got).contains("Dataset id:"); - datasetId = got.split("Dataset id: ")[1].split("\n")[0]; - } -} diff --git a/samples/snippets/src/test/java/beta/automl/TablesCreateModelTest.java b/samples/snippets/src/test/java/beta/automl/TablesCreateModelTest.java deleted file mode 100644 index 996daae23..000000000 --- a/samples/snippets/src/test/java/beta/automl/TablesCreateModelTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class TablesCreateModelTest { - - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String DATASET_ID = "TBL00000000000000000000"; - private static final String TABLE_SPEC_ID = "3172574831249981440"; - private static final String COLUMN_SPEC_ID = "3224682886313541632"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private String operationId; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testTablesCreateModel() throws IOException, ExecutionException, InterruptedException { - try { - // 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 "_" - String modelName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - TablesCreateModel.createModel( - PROJECT_ID, DATASET_ID, TABLE_SPEC_ID, COLUMN_SPEC_ID, modelName); - String got = bout.toString(); - assertThat(got).contains("Dataset does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("Dataset does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/beta/automl/TablesGetModelTest.java b/samples/snippets/src/test/java/beta/automl/TablesGetModelTest.java deleted file mode 100644 index dd76b0646..000000000 --- a/samples/snippets/src/test/java/beta/automl/TablesGetModelTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class TablesGetModelTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = "TBL7473655411900416000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testGetModel() throws IOException { - GetModel.getModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("Model id: " + MODEL_ID); - } -} diff --git a/samples/snippets/src/test/java/beta/automl/TablesImportDatasetTest.java b/samples/snippets/src/test/java/beta/automl/TablesImportDatasetTest.java deleted file mode 100644 index c6c52f375..000000000 --- a/samples/snippets/src/test/java/beta/automl/TablesImportDatasetTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class TablesImportDatasetTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testTablesImportDataset() { - try { - TablesImportDataset.importDataset( - PROJECT_ID, "TEN0000000000000000000", "gs://cloud-ml-tables-data/bank-marketing.csv"); - String got = bout.toString(); - assertThat(got).contains("The Dataset doesn't exist or is inaccessible for use with AutoMl."); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()) - .contains("The Dataset doesn't exist or is inaccessible for use with AutoMl."); - } - } -} diff --git a/samples/snippets/src/test/java/beta/automl/TablesPredictTest.java b/samples/snippets/src/test/java/beta/automl/TablesPredictTest.java deleted file mode 100644 index 0abb04b2e..000000000 --- a/samples/snippets/src/test/java/beta/automl/TablesPredictTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.DeployModelRequest; -import com.google.cloud.automl.v1.Model; -import com.google.cloud.automl.v1.ModelName; -import com.google.protobuf.Value; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ExecutionException; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class TablesPredictTest { - - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String MODEL_ID = "TBL7972827093840953344"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() throws IOException, ExecutionException, InterruptedException { - // Verify that the model is deployed for prediction - try (AutoMlClient client = AutoMlClient.create()) { - ModelName modelFullId = ModelName.of(PROJECT_ID, "us-central1", MODEL_ID); - Model model = client.getModel(modelFullId); - if (model.getDeploymentState() == Model.DeploymentState.UNDEPLOYED) { - // Deploy the model if not deployed - DeployModelRequest request = - DeployModelRequest.newBuilder().setName(modelFullId.toString()).build(); - client.deployModelAsync(request).get(); - } - } - - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testTablesPredict() throws IOException { - List values = new ArrayList<>(); - values.add(Value.newBuilder().setNumberValue(39).build()); // Age - values.add(Value.newBuilder().setStringValue("technician").build()); // Job - values.add(Value.newBuilder().setStringValue("married").build()); // MaritalStatus - values.add(Value.newBuilder().setStringValue("secondary").build()); // Education - values.add(Value.newBuilder().setStringValue("no").build()); // Default - values.add(Value.newBuilder().setNumberValue(52).build()); // Balance - values.add(Value.newBuilder().setStringValue("no").build()); // Housing - values.add(Value.newBuilder().setStringValue("no").build()); // Loan - values.add(Value.newBuilder().setStringValue("cellular").build()); // Contact - values.add(Value.newBuilder().setNumberValue(12).build()); // Day - values.add(Value.newBuilder().setStringValue("aug").build()); // Month - values.add(Value.newBuilder().setNumberValue(96).build()); // Duration - values.add(Value.newBuilder().setNumberValue(2).build()); // Campaign - values.add(Value.newBuilder().setNumberValue(-1).build()); // PDays - values.add(Value.newBuilder().setNumberValue(0).build()); // Previous - values.add(Value.newBuilder().setStringValue("unknown").build()); // POutcome - - TablesPredict.predict(PROJECT_ID, MODEL_ID, values); - - String got = bout.toString(); - assertThat(got).contains("Prediction results:"); - } -} diff --git a/samples/snippets/src/test/java/beta/automl/UndeployModelTest.java b/samples/snippets/src/test/java/beta/automl/UndeployModelTest.java deleted file mode 100644 index 4ec06dabf..000000000 --- a/samples/snippets/src/test/java/beta/automl/UndeployModelTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class UndeployModelTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = "TEN0000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testUndeployModel() { - // As model deployment can take a long time, instead try to deploy a - // nonexistent model and confirm that the model was not found, but other - // elements of the request were valid. - try { - UndeployModel.undeployModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("The model does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("The model does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/beta/automl/VideoClassificationCreateDatasetTest.java b/samples/snippets/src/test/java/beta/automl/VideoClassificationCreateDatasetTest.java deleted file mode 100644 index a29435f28..000000000 --- a/samples/snippets/src/test/java/beta/automl/VideoClassificationCreateDatasetTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.DatasetName; -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VideoClassificationCreateDatasetTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private String datasetId; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() throws InterruptedException, ExecutionException, IOException { - // Delete the created dataset - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the dataset. - DatasetName datasetFullId = DatasetName.of(PROJECT_ID, "us-central1", datasetId); - client.deleteDatasetAsync(datasetFullId).get(); - } - System.setOut(originalPrintStream); - } - - @Test - public void testCreateDataset() 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 "_" - String datasetName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - VideoClassificationCreateDataset.createDataset(PROJECT_ID, datasetName); - - String got = bout.toString(); - assertThat(got).contains("Dataset id:"); - datasetId = got.split("Dataset id: ")[1].split("\n")[0]; - } -} diff --git a/samples/snippets/src/test/java/beta/automl/VideoClassificationCreateModelTest.java b/samples/snippets/src/test/java/beta/automl/VideoClassificationCreateModelTest.java deleted file mode 100644 index 233a6af23..000000000 --- a/samples/snippets/src/test/java/beta/automl/VideoClassificationCreateModelTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VideoClassificationCreateModelTest { - - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String DATASET_ID = "VCN00000000000000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private String operationId; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testVisionClassificationCreateModel() - throws IOException, ExecutionException, InterruptedException { - try { - // 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 "_" - String modelName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - VideoClassificationCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); - String got = bout.toString(); - assertThat(got).contains("Dataset does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("Dataset does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/beta/automl/VideoObjectTrackingCreateDatasetTest.java b/samples/snippets/src/test/java/beta/automl/VideoObjectTrackingCreateDatasetTest.java deleted file mode 100644 index db458e5ce..000000000 --- a/samples/snippets/src/test/java/beta/automl/VideoObjectTrackingCreateDatasetTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.DatasetName; -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VideoObjectTrackingCreateDatasetTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private String datasetId; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() throws InterruptedException, ExecutionException, IOException { - // Delete the created dataset - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the dataset. - DatasetName datasetFullId = DatasetName.of(PROJECT_ID, "us-central1", datasetId); - client.deleteDatasetAsync(datasetFullId).get(); - } - System.setOut(originalPrintStream); - } - - @Test - public void testCreateDataset() 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 "_" - String datasetName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - VideoObjectTrackingCreateDataset.createDataset(PROJECT_ID, datasetName); - - String got = bout.toString(); - assertThat(got).contains("Dataset id:"); - datasetId = got.split("Dataset id: ")[1].split("\n")[0]; - } -} diff --git a/samples/snippets/src/test/java/beta/automl/VideoObjectTrackingCreateModelTest.java b/samples/snippets/src/test/java/beta/automl/VideoObjectTrackingCreateModelTest.java deleted file mode 100644 index 04df91b36..000000000 --- a/samples/snippets/src/test/java/beta/automl/VideoObjectTrackingCreateModelTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2020 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 beta.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VideoObjectTrackingCreateModelTest { - - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String DATASET_ID = "VOT0000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private String operationId; - - private static String requireEnvVar(String varName) { - String value = System.getenv(varName); - assertNotNull( - "Environment variable " + varName + " is required to perform these tests.", - System.getenv(varName)); - return value; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testVisionClassificationCreateModel() - throws IOException, ExecutionException, InterruptedException { - - try { - // 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 "_" - String modelName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - VideoObjectTrackingCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); - - String got = bout.toString(); - assertThat(got).contains("Dataset does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("Dataset does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/BatchPredictTest.java b/samples/snippets/src/test/java/com/example/automl/BatchPredictTest.java deleted file mode 100644 index 29dfa3305..000000000 --- a/samples/snippets/src/test/java/com/example/automl/BatchPredictTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class BatchPredictTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String BUCKET_ID = PROJECT_ID + "-lcm"; - private static final String MODEL_ID = "TEN0000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - requireEnvVar("ENTITY_EXTRACTION_MODEL_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testBatchPredict() { - // As batch prediction can take a long time. Try to batch predict on a model and confirm that - // the model was not found, but other elements of the request were valid. - try { - String inputUri = String.format("gs://%s/entity-extraction/input.jsonl", BUCKET_ID); - String outputUri = String.format("gs://%s/TEST_BATCH_PREDICT/", BUCKET_ID); - BatchPredict.batchPredict(PROJECT_ID, MODEL_ID, inputUri, outputUri); - String got = bout.toString(); - assertThat(got).contains("does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/DeleteDatasetTest.java b/samples/snippets/src/test/java/com/example/automl/DeleteDatasetTest.java deleted file mode 100644 index fd4f96171..000000000 --- a/samples/snippets/src/test/java/com/example/automl/DeleteDatasetTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class DeleteDatasetTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private String datasetId; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() throws InterruptedException, ExecutionException, IOException { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Create a fake dataset to be deleted - // 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 "_" - String datasetName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - LanguageEntityExtractionCreateDataset.createDataset(PROJECT_ID, datasetName); - String got = bout.toString(); - datasetId = got.split("Dataset id: ")[1].split("\n")[0]; - - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testDeleteDataset() throws IOException, ExecutionException, InterruptedException { - DeleteDataset.deleteDataset(PROJECT_ID, datasetId); - String got = bout.toString(); - assertThat(got).contains("Dataset deleted."); - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/DeleteModelTest.java b/samples/snippets/src/test/java/com/example/automl/DeleteModelTest.java deleted file mode 100644 index 96b5c59ff..000000000 --- a/samples/snippets/src/test/java/com/example/automl/DeleteModelTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class DeleteModelTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testDeleteModel() { - // As model creation can take many hours, instead try to delete a - // nonexistent model and confirm that the model was not found, but other - // elements of the request were valid. - try { - DeleteModel.deleteModel(PROJECT_ID, "TRL0000000000000000000"); - String got = bout.toString(); - assertThat(got).contains("The model does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("The model does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/DeployModelTest.java b/samples/snippets/src/test/java/com/example/automl/DeployModelTest.java deleted file mode 100644 index 5ad7f5607..000000000 --- a/samples/snippets/src/test/java/com/example/automl/DeployModelTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class DeployModelTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = "TEN0000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testDeployModel() { - // As model deployment can take a long time, instead try to deploy a - // nonexistent model and confirm that the model was not found, but other - // elements of the request were valid. - try { - DeployModel.deployModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("The model does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("The model does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/ExportDatasetTest.java b/samples/snippets/src/test/java/com/example/automl/ExportDatasetTest.java deleted file mode 100644 index 6dc3a7ed6..000000000 --- a/samples/snippets/src/test/java/com/example/automl/ExportDatasetTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class ExportDatasetTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String DATASET_ID = "TEN0000000000000000000"; - private static final String BUCKET_ID = PROJECT_ID + "-lcm"; - private static final String BUCKET = "gs://" + BUCKET_ID; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - requireEnvVar("ENTITY_EXTRACTION_DATASET_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testExportDataset() throws IOException, ExecutionException, InterruptedException { - // As exporting a dataset can take a long time and only one operation can be run on a dataset - // at once. Try to export a nonexistent dataset and confirm that the dataset was not found, but - // other elements of the request were valid. - try { - ExportDataset.exportDataset(PROJECT_ID, DATASET_ID, BUCKET + "/TEST_EXPORT_OUTPUT/"); - String got = bout.toString(); - assertThat(got).contains("The Dataset doesn't exist or is inaccessible for use with AutoMl."); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()) - .contains("The Dataset doesn't exist or is inaccessible for use with AutoMl."); - } - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/GetDatasetTest.java b/samples/snippets/src/test/java/com/example/automl/GetDatasetTest.java deleted file mode 100644 index 50629da4f..000000000 --- a/samples/snippets/src/test/java/com/example/automl/GetDatasetTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class GetDatasetTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String DATASET_ID = System.getenv("ENTITY_EXTRACTION_DATASET_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - requireEnvVar("ENTITY_EXTRACTION_DATASET_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testGetDataset() throws IOException { - GetDataset.getDataset(PROJECT_ID, DATASET_ID); - String got = bout.toString(); - assertThat(got).contains("Dataset id:"); - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/GetModelEvaluationTest.java b/samples/snippets/src/test/java/com/example/automl/GetModelEvaluationTest.java deleted file mode 100644 index 74e4f1678..000000000 --- a/samples/snippets/src/test/java/com/example/automl/GetModelEvaluationTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class GetModelEvaluationTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = System.getenv("ENTITY_EXTRACTION_MODEL_ID"); - private String modelEvaluationId; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - requireEnvVar("ENTITY_EXTRACTION_MODEL_ID"); - } - - @Before - public void setUp() throws IOException { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // Get a model evaluation ID from the List request first to be used in the Get call - ListModelEvaluations.listModelEvaluations(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - modelEvaluationId = got.split(MODEL_ID + "/modelEvaluations/")[1].split("\n")[0]; - assertThat(got).contains("Model Evaluation Name:"); - - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testGetModelEvaluation() throws IOException { - GetModelEvaluation.getModelEvaluation(PROJECT_ID, MODEL_ID, modelEvaluationId); - String got = bout.toString(); - assertThat(got).contains("Model Evaluation Name:"); - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/GetModelTest.java b/samples/snippets/src/test/java/com/example/automl/GetModelTest.java deleted file mode 100644 index dc375d88a..000000000 --- a/samples/snippets/src/test/java/com/example/automl/GetModelTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class GetModelTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = System.getenv("ENTITY_EXTRACTION_MODEL_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - requireEnvVar("ENTITY_EXTRACTION_MODEL_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testGetModel() throws IOException { - GetModel.getModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("Model id: " + MODEL_ID); - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/GetOperationStatusTest.java b/samples/snippets/src/test/java/com/example/automl/GetOperationStatusTest.java deleted file mode 100644 index bc233a9a6..000000000 --- a/samples/snippets/src/test/java/com/example/automl/GetOperationStatusTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class GetOperationStatusTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private String operationId; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() throws IOException { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - ListOperationStatus.listOperationStatus(PROJECT_ID); - String got = bout.toString(); - operationId = got.split("\n")[1].split(":")[1].trim(); - assertThat(got).contains("Operation details:"); - - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testGetOperationStatus() throws IOException { - GetOperationStatus.getOperationStatus(operationId); - String got = bout.toString(); - assertThat(got).contains("Operation details:"); - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/ImportDatasetTest.java b/samples/snippets/src/test/java/com/example/automl/ImportDatasetTest.java deleted file mode 100644 index 727df922d..000000000 --- a/samples/snippets/src/test/java/com/example/automl/ImportDatasetTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -import com.google.api.gax.rpc.NotFoundException; -import io.grpc.StatusRuntimeException; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class ImportDatasetTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String DATASET_ID = "TEN0000000000000000000"; - private static final String BUCKET_ID = PROJECT_ID + "-lcm"; - private static final String BUCKET = "gs://" + BUCKET_ID; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - System.setOut(originalPrintStream); - } - - @Test - public void testImportDataset() throws InterruptedException, TimeoutException, IOException { - - try { - ImportDataset.importDataset( - PROJECT_ID, DATASET_ID, BUCKET + "/entity-extraction/dataset.csv"); - String got = bout.toString(); - assertThat(got).contains("The Dataset doesn't exist "); - } catch (NotFoundException | ExecutionException | StatusRuntimeException ex) { - assertThat(ex.getMessage()).contains("The Dataset doesn't exist"); - } - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/LanguageEntityExtractionCreateDatasetTest.java b/samples/snippets/src/test/java/com/example/automl/LanguageEntityExtractionCreateDatasetTest.java deleted file mode 100644 index decbfeb36..000000000 --- a/samples/snippets/src/test/java/com/example/automl/LanguageEntityExtractionCreateDatasetTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class LanguageEntityExtractionCreateDatasetTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private String datasetId; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() throws InterruptedException, ExecutionException, IOException { - // Delete the created dataset - DeleteDataset.deleteDataset(PROJECT_ID, datasetId); - System.setOut(originalPrintStream); - } - - @Test - public void testCreateDataset() 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 "_" - String datasetName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - LanguageEntityExtractionCreateDataset.createDataset(PROJECT_ID, datasetName); - - String got = bout.toString(); - assertThat(got).contains("Dataset id:"); - datasetId = got.split("Dataset id: ")[1].split("\n")[0]; - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java b/samples/snippets/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java deleted file mode 100644 index 21baebcc9..000000000 --- a/samples/snippets/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class LanguageEntityExtractionCreateModelTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String DATASET_ID = "TEN0000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testLanguageEntityExtractionCreateModel() { - // As entity extraction does not let you cancel model creation, instead try to create a model - // from a nonexistent dataset, but other elements of the request were valid. - try { - // 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 "_" - String modelName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - LanguageEntityExtractionCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); - String got = bout.toString(); - assertThat(got).contains("Dataset does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("Dataset does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/LanguageEntityExtractionPredictTest.java b/samples/snippets/src/test/java/com/example/automl/LanguageEntityExtractionPredictTest.java deleted file mode 100644 index bf553f4b3..000000000 --- a/samples/snippets/src/test/java/com/example/automl/LanguageEntityExtractionPredictTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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 static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.DeployModelRequest; -import com.google.cloud.automl.v1.Model; -import com.google.cloud.automl.v1.ModelName; -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class LanguageEntityExtractionPredictTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = System.getenv("ENTITY_EXTRACTION_MODEL_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - requireEnvVar("AUTOML_PROJECT_ID"); - requireEnvVar("ENTITY_EXTRACTION_MODEL_ID"); - } - - @Before - public void setUp() throws IOException, ExecutionException, InterruptedException { - // Verify that the model is deployed for prediction - try (AutoMlClient client = AutoMlClient.create()) { - ModelName modelFullId = ModelName.of(PROJECT_ID, "us-central1", MODEL_ID); - Model model = client.getModel(modelFullId); - if (model.getDeploymentState() == Model.DeploymentState.UNDEPLOYED) { - // Deploy the model if not deployed - DeployModelRequest request = - DeployModelRequest.newBuilder().setName(modelFullId.toString()).build(); - client.deployModelAsync(request).get(); - } - } - - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testPredict() throws IOException { - String text = "Constitutional mutations in the WT1 gene in patients with Denys-Drash syndrome."; - LanguageEntityExtractionPredict.predict(PROJECT_ID, MODEL_ID, text); - String got = bout.toString(); - assertThat(got).contains("Text Extract Entity Type:"); - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateDatasetTest.java b/samples/snippets/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateDatasetTest.java deleted file mode 100644 index 7e0657729..000000000 --- a/samples/snippets/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateDatasetTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class LanguageSentimentAnalysisCreateDatasetTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private String datasetId; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() throws InterruptedException, ExecutionException, IOException { - // Delete the created dataset - DeleteDataset.deleteDataset(PROJECT_ID, datasetId); - System.setOut(originalPrintStream); - } - - @Test - public void testCreateDataset() 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 "_" - String datasetName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - LanguageSentimentAnalysisCreateDataset.createDataset(PROJECT_ID, datasetName); - - String got = bout.toString(); - assertThat(got).contains("Dataset id:"); - datasetId = got.split("Dataset id: ")[1].split("\n")[0]; - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java b/samples/snippets/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java deleted file mode 100644 index 8d28cf810..000000000 --- a/samples/snippets/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class LanguageSentimentAnalysisCreateModelTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String DATASET_ID = "TST00000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - System.setOut(originalPrintStream); - } - - @Test - public void testLanguageSentimentAnalysisCreateModel() { - // Create a model from a nonexistent dataset. - try { - // 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 "_" - String modelName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - LanguageSentimentAnalysisCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); - String got = bout.toString(); - assertThat(got).contains("Dataset does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("Dataset does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/LanguageSentimentAnalysisPredictTest.java b/samples/snippets/src/test/java/com/example/automl/LanguageSentimentAnalysisPredictTest.java deleted file mode 100644 index 665712719..000000000 --- a/samples/snippets/src/test/java/com/example/automl/LanguageSentimentAnalysisPredictTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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 static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.DeployModelRequest; -import com.google.cloud.automl.v1.Model; -import com.google.cloud.automl.v1.ModelName; -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class LanguageSentimentAnalysisPredictTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = System.getenv("SENTIMENT_ANALYSIS_MODEL_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - requireEnvVar("SENTIMENT_ANALYSIS_MODEL_ID"); - } - - @Before - public void setUp() throws IOException, ExecutionException, InterruptedException { - // Verify that the model is deployed for prediction - try (AutoMlClient client = AutoMlClient.create()) { - ModelName modelFullId = ModelName.of(PROJECT_ID, "us-central1", MODEL_ID); - Model model = client.getModel(modelFullId); - if (model.getDeploymentState() == Model.DeploymentState.UNDEPLOYED) { - // Deploy the model if not deployed - DeployModelRequest request = - DeployModelRequest.newBuilder().setName(modelFullId.toString()).build(); - client.deployModelAsync(request).get(); - } - } - - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testPredict() throws IOException { - String text = "Hopefully this Claritin kicks in soon"; - LanguageSentimentAnalysisPredict.predict(PROJECT_ID, MODEL_ID, text); - String got = bout.toString(); - assertThat(got).contains("Predicted sentiment score:"); - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/LanguageTextClassificationCreateDatasetTest.java b/samples/snippets/src/test/java/com/example/automl/LanguageTextClassificationCreateDatasetTest.java deleted file mode 100644 index b4c43c519..000000000 --- a/samples/snippets/src/test/java/com/example/automl/LanguageTextClassificationCreateDatasetTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class LanguageTextClassificationCreateDatasetTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private String datasetId; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() throws InterruptedException, ExecutionException, IOException { - // Delete the created dataset - DeleteDataset.deleteDataset(PROJECT_ID, datasetId); - System.setOut(originalPrintStream); - } - - @Test - public void testCreateDataset() 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 "_" - String datasetName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - LanguageTextClassificationCreateDataset.createDataset(PROJECT_ID, datasetName); - - String got = bout.toString(); - assertThat(got).contains("Dataset id:"); - datasetId = got.split("Dataset id: ")[1].split("\n")[0]; - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java b/samples/snippets/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java deleted file mode 100644 index 14bd5098d..000000000 --- a/samples/snippets/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class LanguageTextClassificationCreateModelTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String DATASET_ID = "TCN00000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - System.setOut(originalPrintStream); - } - - @Test - public void testLanguageTextClassificationCreateModel() { - // Create a model from a nonexistent dataset. - try { - // 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 "_" - String modelName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - LanguageTextClassificationCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); - String got = bout.toString(); - assertThat(got).contains("Dataset does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("Dataset does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/LanguageTextClassificationPredictTest.java b/samples/snippets/src/test/java/com/example/automl/LanguageTextClassificationPredictTest.java deleted file mode 100644 index f27234e74..000000000 --- a/samples/snippets/src/test/java/com/example/automl/LanguageTextClassificationPredictTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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 static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.DeployModelRequest; -import com.google.cloud.automl.v1.Model; -import com.google.cloud.automl.v1.ModelName; -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class LanguageTextClassificationPredictTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = System.getenv("TEXT_CLASSIFICATION_MODEL_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - requireEnvVar("TEXT_CLASSIFICATION_MODEL_ID"); - } - - @Before - public void setUp() throws IOException, ExecutionException, InterruptedException { - // Verify that the model is deployed for prediction - try (AutoMlClient client = AutoMlClient.create()) { - ModelName modelFullId = ModelName.of(PROJECT_ID, "us-central1", MODEL_ID); - Model model = client.getModel(modelFullId); - if (model.getDeploymentState() == Model.DeploymentState.UNDEPLOYED) { - // Deploy the model if not deployed - DeployModelRequest request = - DeployModelRequest.newBuilder().setName(modelFullId.toString()).build(); - client.deployModelAsync(request).get(); - } - } - - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testPredict() throws IOException { - String text = "Fruit and nut flavour"; - LanguageTextClassificationPredict.predict(PROJECT_ID, MODEL_ID, text); - String got = bout.toString(); - assertThat(got).contains("Predicted class name:"); - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/ListDatasetsTest.java b/samples/snippets/src/test/java/com/example/automl/ListDatasetsTest.java deleted file mode 100644 index df2a91892..000000000 --- a/samples/snippets/src/test/java/com/example/automl/ListDatasetsTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class ListDatasetsTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testListDataset() throws IOException { - ListDatasets.listDatasets(PROJECT_ID); - String got = bout.toString(); - assertThat(got).contains("Dataset id:"); - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/ListModelEvaluationsTest.java b/samples/snippets/src/test/java/com/example/automl/ListModelEvaluationsTest.java deleted file mode 100644 index 7d7d08e31..000000000 --- a/samples/snippets/src/test/java/com/example/automl/ListModelEvaluationsTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class ListModelEvaluationsTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = System.getenv("ENTITY_EXTRACTION_MODEL_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - requireEnvVar("ENTITY_EXTRACTION_MODEL_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testListModelEvaluations() throws IOException { - ListModelEvaluations.listModelEvaluations(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("Model Evaluation Name:"); - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/ListModelsTest.java b/samples/snippets/src/test/java/com/example/automl/ListModelsTest.java deleted file mode 100644 index df6c986bf..000000000 --- a/samples/snippets/src/test/java/com/example/automl/ListModelsTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class ListModelsTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testListModels() throws IOException { - ListModels.listModels(PROJECT_ID); - String got = bout.toString(); - assertThat(got).contains("Model id:"); - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/ListOperationStatusTest.java b/samples/snippets/src/test/java/com/example/automl/ListOperationStatusTest.java deleted file mode 100644 index 5a4779a42..000000000 --- a/samples/snippets/src/test/java/com/example/automl/ListOperationStatusTest.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -import com.google.api.client.util.ExponentialBackOff; -import com.google.api.gax.rpc.ResourceExhaustedException; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.LocationName; -import com.google.longrunning.ListOperationsRequest; -import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class ListOperationStatusTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() throws IOException, InterruptedException { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - - // if the LRO status count more than 300, delete half of operations. - try (AutoMlClient client = AutoMlClient.create()) { - OperationsClient operationsClient = client.getOperationsClient(); - LocationName projectLocation = LocationName.of(PROJECT_ID, "us-central1"); - ListOperationsRequest listRequest = - ListOperationsRequest.newBuilder().setName(projectLocation.toString()).build(); - List operationFullPathsToBeDeleted = new ArrayList<>(); - for (Operation operation : operationsClient.listOperations(listRequest).iterateAll()) { - // collect unused operation into the list. - // Filter: deleting already done operations. - if (operation.getDone() && !operation.hasError()) { - operationFullPathsToBeDeleted.add(operation.getName()); - } - } - - if (operationFullPathsToBeDeleted.size() > 300) { - System.out.println("Cleaning up..."); - - for (String operationFullPath : - operationFullPathsToBeDeleted.subList(0, operationFullPathsToBeDeleted.size() / 2)) { - // retry_interval * (random value in range [1 - rand_factor, 1 + rand_factor]) - ExponentialBackOff exponentialBackOff = - new ExponentialBackOff.Builder() - .setInitialIntervalMillis(60000) - .setMaxElapsedTimeMillis(300000) - .setRandomizationFactor(0.5) - .setMultiplier(1.1) - .setMaxIntervalMillis(80000) - .build(); - - // delete unused operations. - try { - operationsClient.deleteOperation(operationFullPath); - } catch (ResourceExhaustedException ex) { - // exponential back off and retry. - long backOffInMillis = exponentialBackOff.nextBackOffMillis(); - System.out.printf( - "Backing off for %d milliseconds " + "due to Resource exhaustion.\n", - backOffInMillis); - if (backOffInMillis < 0) { - break; - } - System.out.println("Backing off" + backOffInMillis); - TimeUnit.MILLISECONDS.sleep(backOffInMillis); - } catch (Exception ex) { - throw ex; - } - } - } else { - // Clear the list since we wont anything with the list. - operationFullPathsToBeDeleted.clear(); - } - } - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testOperationStatus() throws IOException { - ListOperationStatus.listOperationStatus(PROJECT_ID); - String got = bout.toString(); - assertThat(got).contains("Operation details:"); - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/TranslateCreateDatasetTest.java b/samples/snippets/src/test/java/com/example/automl/TranslateCreateDatasetTest.java deleted file mode 100644 index 6fd75eff9..000000000 --- a/samples/snippets/src/test/java/com/example/automl/TranslateCreateDatasetTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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 static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.testing.junit4.MultipleAttemptsRule; -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; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class TranslateCreateDatasetTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private String got; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() throws InterruptedException, ExecutionException, IOException { - String datasetId = got.split("Dataset id: ")[1].split("\n")[0]; - - // Delete the created dataset - DeleteDataset.deleteDataset(PROJECT_ID, datasetId); - System.setOut(originalPrintStream); - } - - @Rule public MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - - @Test - public void testCreateDataset() 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 "_" - String datasetName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - TranslateCreateDataset.createDataset(PROJECT_ID, datasetName); - - got = bout.toString(); - assertThat(got).contains("Dataset id:"); - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/TranslateCreateModelTest.java b/samples/snippets/src/test/java/com/example/automl/TranslateCreateModelTest.java deleted file mode 100644 index 65ce99331..000000000 --- a/samples/snippets/src/test/java/com/example/automl/TranslateCreateModelTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -// Tests for Automl translation models. -@RunWith(JUnit4.class) -public class TranslateCreateModelTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String DATASET_ID = "TRL00000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - System.setOut(originalPrintStream); - } - - @Test - public void testTranslateCreateModel() { - // Create a model from a nonexistent dataset. - try { - // 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 "_" - String modelName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - TranslateCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); - String got = bout.toString(); - // After setting DATASET_ID, change line below to - // assertThat(got).contains("Training started..."); - assertThat(got).contains("Dataset does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - // After setting DATASET_ID, change line below to - // assertThat(e.getMessage()).contains("Training started..."); - assertThat(e.getMessage()).contains("Dataset does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/TranslatePredictTest.java b/samples/snippets/src/test/java/com/example/automl/TranslatePredictTest.java deleted file mode 100644 index 8713ab993..000000000 --- a/samples/snippets/src/test/java/com/example/automl/TranslatePredictTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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 static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -// Tests for translation "Predict" sample. -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class TranslatePredictTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String modelId = System.getenv("TRANSLATION_MODEL_ID"); - private static final String filePath = "./resources/input.txt"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - requireEnvVar("TRANSLATION_MODEL_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testPredict() throws IOException { - // Act - TranslatePredict.predict(PROJECT_ID, modelId, filePath); - - // Assert - String got = bout.toString(); - assertThat(got).contains("Translated Content"); - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/UndeployModelTest.java b/samples/snippets/src/test/java/com/example/automl/UndeployModelTest.java deleted file mode 100644 index 02d480a67..000000000 --- a/samples/snippets/src/test/java/com/example/automl/UndeployModelTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class UndeployModelTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = "TEN0000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testUndeployModel() { - // As model deployment can take a long time, instead try to deploy a - // nonexistent model and confirm that the model was not found, but other - // elements of the request were valid. - try { - UndeployModel.undeployModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("The model does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("The model does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/VisionClassificationCreateDatasetTest.java b/samples/snippets/src/test/java/com/example/automl/VisionClassificationCreateDatasetTest.java deleted file mode 100644 index bf8b759cb..000000000 --- a/samples/snippets/src/test/java/com/example/automl/VisionClassificationCreateDatasetTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VisionClassificationCreateDatasetTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private String datasetId; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() throws InterruptedException, ExecutionException, IOException { - // Delete the created dataset - DeleteDataset.deleteDataset(PROJECT_ID, datasetId); - System.setOut(originalPrintStream); - } - - @Test - public void testCreateDataset() 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 "_" - String datasetName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - VisionClassificationCreateDataset.createDataset(PROJECT_ID, datasetName); - - String got = bout.toString(); - assertThat(got).contains("Dataset id:"); - datasetId = got.split("Dataset id: ")[1].split("\n")[0]; - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java b/samples/snippets/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java deleted file mode 100644 index 1fac2cccb..000000000 --- a/samples/snippets/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VisionClassificationCreateModelTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String DATASET_ID = "ICN000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private String operationId; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - System.setOut(originalPrintStream); - } - - @Test - public void testVisionClassificationCreateModel() { - // Create a model from a nonexistent dataset. - try { - // 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 "_" - String modelName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - VisionClassificationCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); - String got = bout.toString(); - assertThat(got).contains("Dataset does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("Dataset does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/VisionClassificationDeployModelNodeCountTest.java b/samples/snippets/src/test/java/com/example/automl/VisionClassificationDeployModelNodeCountTest.java deleted file mode 100644 index 2414c00a5..000000000 --- a/samples/snippets/src/test/java/com/example/automl/VisionClassificationDeployModelNodeCountTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class VisionClassificationDeployModelNodeCountTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = "ICN0000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testDeployModelWithNodeCount() { - // As model deployment can take a long time, instead try to deploy a - // nonexistent model and confirm that the model was not found, but other - // elements of the request were valid. - try { - VisionClassificationDeployModelNodeCount.visionClassificationDeployModelNodeCount( - PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("The model does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("The model does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/VisionClassificationPredictTest.java b/samples/snippets/src/test/java/com/example/automl/VisionClassificationPredictTest.java deleted file mode 100644 index e4c3af69a..000000000 --- a/samples/snippets/src/test/java/com/example/automl/VisionClassificationPredictTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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 static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.DeployModelRequest; -import com.google.cloud.automl.v1.Model; -import com.google.cloud.automl.v1.ModelName; -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VisionClassificationPredictTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = System.getenv("VISION_CLASSIFICATION_MODEL_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - requireEnvVar("VISION_CLASSIFICATION_MODEL_ID"); - } - - @Before - public void setUp() throws IOException, ExecutionException, InterruptedException { - // Verify that the model is deployed for prediction - try (AutoMlClient client = AutoMlClient.create()) { - ModelName modelFullId = ModelName.of(PROJECT_ID, "us-central1", MODEL_ID); - Model model = client.getModel(modelFullId); - if (model.getDeploymentState() == Model.DeploymentState.UNDEPLOYED) { - // Deploy the model if not deployed - DeployModelRequest request = - DeployModelRequest.newBuilder().setName(modelFullId.toString()).build(); - client.deployModelAsync(request).get(); - } - } - - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testPredict() throws IOException { - String filePath = "resources/test.png"; - VisionClassificationPredict.predict(PROJECT_ID, MODEL_ID, filePath); - String got = bout.toString(); - assertThat(got).contains("Predicted class name:"); - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/VisionObjectDetectionCreateDatasetTest.java b/samples/snippets/src/test/java/com/example/automl/VisionObjectDetectionCreateDatasetTest.java deleted file mode 100644 index 20e6e1c5a..000000000 --- a/samples/snippets/src/test/java/com/example/automl/VisionObjectDetectionCreateDatasetTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VisionObjectDetectionCreateDatasetTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private String datasetId; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() throws InterruptedException, ExecutionException, IOException { - // Delete the created dataset - DeleteDataset.deleteDataset(PROJECT_ID, datasetId); - System.setOut(originalPrintStream); - } - - @Test - public void testCreateDataset() 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 "_" - String datasetName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - VisionObjectDetectionCreateDataset.createDataset(PROJECT_ID, datasetName); - - String got = bout.toString(); - assertThat(got).contains("Dataset id:"); - datasetId = got.split("Dataset id: ")[1].split("\n")[0]; - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java b/samples/snippets/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java deleted file mode 100644 index 3bd4228f8..000000000 --- a/samples/snippets/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2020 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VisionObjectDetectionCreateModelTest { - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String DATASET_ID = "IOD0000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - System.setOut(originalPrintStream); - } - - @Test - public void testVisionObjectDetectionCreateModel() { - // Create a model from a nonexistent dataset. - try { - // 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 "_" - String modelName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - VisionObjectDetectionCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); - String got = bout.toString(); - assertThat(got).contains("Dataset does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("Dataset does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/VisionObjectDetectionDeployModelNodeCountTest.java b/samples/snippets/src/test/java/com/example/automl/VisionObjectDetectionDeployModelNodeCountTest.java deleted file mode 100644 index b218d2e59..000000000 --- a/samples/snippets/src/test/java/com/example/automl/VisionObjectDetectionDeployModelNodeCountTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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 static junit.framework.TestCase.assertNotNull; - -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class VisionObjectDetectionDeployModelNodeCountTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = "0000000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testDeployModelWithNodeCount() { - // As model deployment can take a long time, instead try to deploy a - // nonexistent model and confirm that the model was not found, but other - // elements of the request were valid. - try { - VisionObjectDetectionDeployModelNodeCount.visionObjectDetectionDeployModelNodeCount( - PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("The model does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("The model does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/com/example/automl/VisionObjectDetectionPredictTest.java b/samples/snippets/src/test/java/com/example/automl/VisionObjectDetectionPredictTest.java deleted file mode 100644 index 1580c94b3..000000000 --- a/samples/snippets/src/test/java/com/example/automl/VisionObjectDetectionPredictTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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 static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.DeployModelRequest; -import com.google.cloud.automl.v1.Model; -import com.google.cloud.automl.v1.ModelName; -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; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VisionObjectDetectionPredictTest { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = System.getenv("OBJECT_DETECTION_MODEL_ID"); - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - requireEnvVar("OBJECT_DETECTION_MODEL_ID"); - } - - @Before - public void setUp() throws IOException, ExecutionException, InterruptedException { - // Verify that the model is deployed for prediction - try (AutoMlClient client = AutoMlClient.create()) { - ModelName modelFullId = ModelName.of(PROJECT_ID, "us-central1", MODEL_ID); - Model model = client.getModel(modelFullId); - if (model.getDeploymentState() == Model.DeploymentState.UNDEPLOYED) { - // Deploy the model if not deployed - DeployModelRequest request = - DeployModelRequest.newBuilder().setName(modelFullId.toString()).build(); - client.deployModelAsync(request).get(); - } - } - - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - // restores print statements in the original method - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testPredict() throws IOException { - String filePath = "resources/salad.jpg"; - VisionObjectDetectionPredict.predict(PROJECT_ID, MODEL_ID, filePath); - String got = bout.toString(); - assertThat(got).contains("X:"); - assertThat(got).contains("Y:"); - } -} diff --git a/samples/snippets/src/test/java/com/google/cloud/vision/ClassificationDeployModelIT.java b/samples/snippets/src/test/java/com/google/cloud/vision/ClassificationDeployModelIT.java deleted file mode 100644 index d71f0d5c5..000000000 --- a/samples/snippets/src/test/java/com/google/cloud/vision/ClassificationDeployModelIT.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.google.cloud.vision; - -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; -import org.junit.Test; - -@SuppressWarnings("checkstyle:AbbreviationAsWordInName") -public class ClassificationDeployModelIT { - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String MODEL_ID = "ICN0000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testClassificationUndeployModelApi() { - // As model deployment can take a long time, instead try to deploy a - // nonexistent model and confirm that the model was not found, but other - // elements of the request were valid. - try { - ClassificationUndeployModel.classificationUndeployModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("The model does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("The model does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/com/google/cloud/vision/samples/automl/ClassificationDeployModelIT.java b/samples/snippets/src/test/java/com/google/cloud/vision/samples/automl/ClassificationDeployModelIT.java deleted file mode 100644 index fa49c779f..000000000 --- a/samples/snippets/src/test/java/com/google/cloud/vision/samples/automl/ClassificationDeployModelIT.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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.google.cloud.vision.samples.automl; - -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; -import org.junit.Test; - -public class ClassificationDeployModelIT { - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String MODEL_ID = "ICN0000000000000000000"; - 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 testClassificationDeployModelApi() { - // As model deployment can take a long time, instead try to deploy a - // nonexistent model and confirm that the model was not found, but other - // elements of the request were valid. - try { - ClassificationDeployModel.classificationDeployModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("The model does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("The model does not exist"); - } - } - - @Test - public void testClassificationUndeployModelApi() { - // As model deployment can take a long time, instead try to deploy a - // nonexistent model and confirm that the model was not found, but other - // elements of the request were valid. - try { - ClassificationUndeployModel.classificationUndeployModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("The model does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("The model does not exist"); - } - } - - @Test - public void testClassificationDeployModelNodeCountApi() { - // As model deployment can take a long time, instead try to deploy a - // nonexistent model and confirm that the model was not found, but other - // elements of the request were valid. - try { - ClassificationDeployModelNodeCount.classificationDeployModelNodeCount(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("The model does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("The model does not exist"); - } - } -} diff --git a/samples/snippets/src/test/java/com/google/cloud/vision/samples/automl/ObjectDetectionDeployModelNodeCountIT.java b/samples/snippets/src/test/java/com/google/cloud/vision/samples/automl/ObjectDetectionDeployModelNodeCountIT.java deleted file mode 100644 index 54a7f48dd..000000000 --- a/samples/snippets/src/test/java/com/google/cloud/vision/samples/automl/ObjectDetectionDeployModelNodeCountIT.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.google.cloud.vision.samples.automl; - -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; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Tests for vision "Deploy Model Node Count" sample. */ -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class ObjectDetectionDeployModelNodeCountIT { - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String MODEL_ID = "0000000000000000000000"; - 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 testObjectDetectionDeployModelNodeCountApi() { - // As model deployment can take a long time, instead try to deploy a - // nonexistent model and confirm that the model was not found, but other - // elements of the request were valid. - try { - ObjectDetectionDeployModelNodeCount.objectDetectionDeployModelNodeCount(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("The model does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("The model does not exist"); - } - } -}