diff --git a/automl/pom.xml b/automl/pom.xml deleted file mode 100644 index b8138df5b7c..00000000000 --- a/automl/pom.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - 4.0.0 - com.example.automl - automl-snippets - jar - Google Cloud Auto ML Snippets - https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/automl - - - - com.google.cloud.samples - shared-configuration - 1.2.0 - - - - 1.8 - 1.8 - UTF-8 - - - - - - - - com.google.cloud - libraries-bom - 26.32.0 - pom - import - - - - - - - com.google.cloud - google-cloud-automl - - - com.google.cloud - google-cloud-bigquery - - - com.google.cloud - google-cloud-storage - - - - net.sourceforge.argparse4j - argparse4j - 0.9.0 - - - junit - junit - 4.13.2 - test - - - com.google.truth - truth - 1.4.0 - test - - - com.google.cloud - google-cloud-core - test - tests - - - - - diff --git a/automl/resources/dandelion.jpg b/automl/resources/dandelion.jpg deleted file mode 100644 index 326e4c1bf53..00000000000 Binary files a/automl/resources/dandelion.jpg and /dev/null differ diff --git a/automl/resources/input.txt b/automl/resources/input.txt deleted file mode 100644 index 5aecd6590fc..00000000000 --- a/automl/resources/input.txt +++ /dev/null @@ -1 +0,0 @@ -Tell me how this ends \ No newline at end of file diff --git a/automl/resources/salad.jpg b/automl/resources/salad.jpg deleted file mode 100644 index a7f960b5030..00000000000 Binary files a/automl/resources/salad.jpg and /dev/null differ diff --git a/automl/resources/test.png b/automl/resources/test.png deleted file mode 100644 index 653342a46e5..00000000000 Binary files a/automl/resources/test.png and /dev/null differ diff --git a/automl/src/main/java/beta/automl/BatchPredict.java b/automl/src/main/java/beta/automl/BatchPredict.java deleted file mode 100644 index 8eab116c971..00000000000 --- a/automl/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; - -abstract 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..."); - 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/automl/src/main/java/beta/automl/CancelOperation.java b/automl/src/main/java/beta/automl/CancelOperation.java deleted file mode 100644 index 1e0e4fd2a71..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/DeleteDataset.java b/automl/src/main/java/beta/automl/DeleteDataset.java deleted file mode 100644 index 9ef47c5c2fa..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/DeleteModel.java b/automl/src/main/java/beta/automl/DeleteModel.java deleted file mode 100644 index 77cc99bb2c9..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/DeployModel.java b/automl/src/main/java/beta/automl/DeployModel.java deleted file mode 100644 index 55a3105dd1c..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/GetModel.java b/automl/src/main/java/beta/automl/GetModel.java deleted file mode 100644 index 710b78053eb..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/GetModelEvaluation.java b/automl/src/main/java/beta/automl/GetModelEvaluation.java deleted file mode 100644 index 74f35f5a74e..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/GetOperationStatus.java b/automl/src/main/java/beta/automl/GetOperationStatus.java deleted file mode 100644 index 77dc703407e..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/ImportDataset.java b/automl/src/main/java/beta/automl/ImportDataset.java deleted file mode 100644 index 72f19b19233..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/ListDatasets.java b/automl/src/main/java/beta/automl/ListDatasets.java deleted file mode 100644 index 7e624aa6fef..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/ListModelEvaluations.java b/automl/src/main/java/beta/automl/ListModelEvaluations.java deleted file mode 100644 index 2fad4ea8e76..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/ListModels.java b/automl/src/main/java/beta/automl/ListModels.java deleted file mode 100644 index 87d1b0a7f10..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/SetEndpoint.java b/automl/src/main/java/beta/automl/SetEndpoint.java deleted file mode 100644 index 4718b220a23..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/TablesBatchPredictBigQuery.java b/automl/src/main/java/beta/automl/TablesBatchPredictBigQuery.java deleted file mode 100644 index b0bc37f262e..00000000000 --- a/automl/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; - -abstract 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..."); - future.get(); - System.out.println("Batch Prediction results saved to BigQuery."); - } - } -} -// [END automl_tables_batch_predict_bq] diff --git a/automl/src/main/java/beta/automl/TablesCreateDataset.java b/automl/src/main/java/beta/automl/TablesCreateDataset.java deleted file mode 100644 index b5390f33705..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/TablesCreateModel.java b/automl/src/main/java/beta/automl/TablesCreateModel.java deleted file mode 100644 index 9c95119e17a..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/TablesGetModel.java b/automl/src/main/java/beta/automl/TablesGetModel.java deleted file mode 100644 index 443491252b5..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/TablesImportDataset.java b/automl/src/main/java/beta/automl/TablesImportDataset.java deleted file mode 100644 index ce0e5fc16f0..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/TablesPredict.java b/automl/src/main/java/beta/automl/TablesPredict.java deleted file mode 100644 index fd2257c899e..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/UndeployModel.java b/automl/src/main/java/beta/automl/UndeployModel.java deleted file mode 100644 index 7325f519dba..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/VideoClassificationCreateDataset.java b/automl/src/main/java/beta/automl/VideoClassificationCreateDataset.java deleted file mode 100644 index 1fe70c9f2b2..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/VideoClassificationCreateModel.java b/automl/src/main/java/beta/automl/VideoClassificationCreateModel.java deleted file mode 100644 index 94f3407d442..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/VideoObjectTrackingCreateDataset.java b/automl/src/main/java/beta/automl/VideoObjectTrackingCreateDataset.java deleted file mode 100644 index 61b2a1ada3a..00000000000 --- a/automl/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/automl/src/main/java/beta/automl/VideoObjectTrackingCreateModel.java b/automl/src/main/java/beta/automl/VideoObjectTrackingCreateModel.java deleted file mode 100644 index 29df7866613..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/BatchPredict.java b/automl/src/main/java/com/example/automl/BatchPredict.java deleted file mode 100644 index 03a0055155c..00000000000 --- a/automl/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; - -abstract 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..."); - future.get(); - System.out.println("Batch Prediction results saved to specified Cloud Storage bucket."); - } - } -} -// [END automl_batch_predict] diff --git a/automl/src/main/java/com/example/automl/DeleteDataset.java b/automl/src/main/java/com/example/automl/DeleteDataset.java deleted file mode 100644 index fcb6e2e913c..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/DeleteModel.java b/automl/src/main/java/com/example/automl/DeleteModel.java deleted file mode 100644 index 66969ff75d4..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/DeployModel.java b/automl/src/main/java/com/example/automl/DeployModel.java deleted file mode 100644 index ecc338cf37e..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/ExportDataset.java b/automl/src/main/java/com/example/automl/ExportDataset.java deleted file mode 100644 index 812869b9a56..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/GetDataset.java b/automl/src/main/java/com/example/automl/GetDataset.java deleted file mode 100644 index e1028d7052d..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/GetModel.java b/automl/src/main/java/com/example/automl/GetModel.java deleted file mode 100644 index 70b97905c2e..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/GetModelEvaluation.java b/automl/src/main/java/com/example/automl/GetModelEvaluation.java deleted file mode 100644 index 694888d53fa..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/GetOperationStatus.java b/automl/src/main/java/com/example/automl/GetOperationStatus.java deleted file mode 100644 index 07bfe02933d..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/ImportDataset.java b/automl/src/main/java/com/example/automl/ImportDataset.java deleted file mode 100644 index 3ead88326b3..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/LanguageEntityExtractionCreateDataset.java b/automl/src/main/java/com/example/automl/LanguageEntityExtractionCreateDataset.java deleted file mode 100644 index 7adf18dc623..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/LanguageEntityExtractionCreateModel.java b/automl/src/main/java/com/example/automl/LanguageEntityExtractionCreateModel.java deleted file mode 100644 index f2da97894df..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/LanguageEntityExtractionPredict.java b/automl/src/main/java/com/example/automl/LanguageEntityExtractionPredict.java deleted file mode 100644 index 065990613b3..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/LanguageSentimentAnalysisCreateDataset.java b/automl/src/main/java/com/example/automl/LanguageSentimentAnalysisCreateDataset.java deleted file mode 100644 index 6ab0be85851..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/LanguageSentimentAnalysisCreateModel.java b/automl/src/main/java/com/example/automl/LanguageSentimentAnalysisCreateModel.java deleted file mode 100644 index 04af77592e5..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/LanguageSentimentAnalysisPredict.java b/automl/src/main/java/com/example/automl/LanguageSentimentAnalysisPredict.java deleted file mode 100644 index 65945c26023..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/LanguageTextClassificationCreateDataset.java b/automl/src/main/java/com/example/automl/LanguageTextClassificationCreateDataset.java deleted file mode 100644 index 9332c06a246..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/LanguageTextClassificationCreateModel.java b/automl/src/main/java/com/example/automl/LanguageTextClassificationCreateModel.java deleted file mode 100644 index bf26db03101..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/LanguageTextClassificationPredict.java b/automl/src/main/java/com/example/automl/LanguageTextClassificationPredict.java deleted file mode 100644 index e2da94aa121..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/ListDatasets.java b/automl/src/main/java/com/example/automl/ListDatasets.java deleted file mode 100644 index b766a673ff4..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/ListModelEvaluations.java b/automl/src/main/java/com/example/automl/ListModelEvaluations.java deleted file mode 100644 index 5b25ec08fe7..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/ListModels.java b/automl/src/main/java/com/example/automl/ListModels.java deleted file mode 100644 index c24f09b28ae..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/ListOperationStatus.java b/automl/src/main/java/com/example/automl/ListOperationStatus.java deleted file mode 100644 index a980d41bad5..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/TranslateCreateDataset.java b/automl/src/main/java/com/example/automl/TranslateCreateDataset.java deleted file mode 100644 index 77769bdbec4..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/TranslateCreateModel.java b/automl/src/main/java/com/example/automl/TranslateCreateModel.java deleted file mode 100644 index cddd597c6bb..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/TranslatePredict.java b/automl/src/main/java/com/example/automl/TranslatePredict.java deleted file mode 100644 index 2385b831c44..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/UndeployModel.java b/automl/src/main/java/com/example/automl/UndeployModel.java deleted file mode 100644 index e7ef532e94d..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/VisionClassificationCreateDataset.java b/automl/src/main/java/com/example/automl/VisionClassificationCreateDataset.java deleted file mode 100644 index f3e2d951d01..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/VisionClassificationCreateModel.java b/automl/src/main/java/com/example/automl/VisionClassificationCreateModel.java deleted file mode 100644 index ea4da40b1d6..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/VisionClassificationDeployModelNodeCount.java b/automl/src/main/java/com/example/automl/VisionClassificationDeployModelNodeCount.java deleted file mode 100644 index c2d27f3a132..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/VisionClassificationPredict.java b/automl/src/main/java/com/example/automl/VisionClassificationPredict.java deleted file mode 100644 index 6f110cf9eff..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/VisionObjectDetectionCreateDataset.java b/automl/src/main/java/com/example/automl/VisionObjectDetectionCreateDataset.java deleted file mode 100644 index 874099d537d..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/VisionObjectDetectionCreateModel.java b/automl/src/main/java/com/example/automl/VisionObjectDetectionCreateModel.java deleted file mode 100644 index 2e0ccbc43d9..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/VisionObjectDetectionDeployModelNodeCount.java b/automl/src/main/java/com/example/automl/VisionObjectDetectionDeployModelNodeCount.java deleted file mode 100644 index 42621d3e87f..00000000000 --- a/automl/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/automl/src/main/java/com/example/automl/VisionObjectDetectionPredict.java b/automl/src/main/java/com/example/automl/VisionObjectDetectionPredict.java deleted file mode 100644 index 8d7dec6b357..00000000000 --- a/automl/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/automl/src/test/java/beta/automl/BatchPredictTest.java b/automl/src/test/java/beta/automl/BatchPredictTest.java deleted file mode 100644 index db8b6377c45..00000000000 --- a/automl/src/test/java/beta/automl/BatchPredictTest.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.testing.junit4.MultipleAttemptsRule; -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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class BatchPredictTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - 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 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(); - PrintStream 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/automl/src/test/java/beta/automl/CancelOperationTest.java b/automl/src/test/java/beta/automl/CancelOperationTest.java deleted file mode 100644 index 30ae1177463..00000000000 --- a/automl/src/test/java/beta/automl/CancelOperationTest.java +++ /dev/null @@ -1,91 +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 com.google.cloud.testing.junit4.MultipleAttemptsRule; -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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class CancelOperationTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - - private ByteArrayOutputStream bout; - 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(); - PrintStream 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/automl/src/test/java/beta/automl/DeleteDatasetTest.java b/automl/src/test/java/beta/automl/DeleteDatasetTest.java deleted file mode 100644 index 794a795e8aa..00000000000 --- a/automl/src/test/java/beta/automl/DeleteDatasetTest.java +++ /dev/null @@ -1,105 +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 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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class DeleteDatasetTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - 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(); - PrintStream 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/automl/src/test/java/beta/automl/DeleteModelTest.java b/automl/src/test/java/beta/automl/DeleteModelTest.java deleted file mode 100644 index b69cababe76..00000000000 --- a/automl/src/test/java/beta/automl/DeleteModelTest.java +++ /dev/null @@ -1,86 +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 com.google.cloud.testing.junit4.MultipleAttemptsRule; -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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class DeleteModelTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - 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(); - PrintStream 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/automl/src/test/java/beta/automl/DeployModelTest.java b/automl/src/test/java/beta/automl/DeployModelTest.java deleted file mode 100644 index 2e3ce08d98e..00000000000 --- a/automl/src/test/java/beta/automl/DeployModelTest.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.cloud.testing.junit4.MultipleAttemptsRule; -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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class DeployModelTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = "TEN0000000000000000000"; - private ByteArrayOutputStream bout; - 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(); - PrintStream 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/automl/src/test/java/beta/automl/GetModelEvaluationTest.java b/automl/src/test/java/beta/automl/GetModelEvaluationTest.java deleted file mode 100644 index 8c789f883ba..00000000000 --- a/automl/src/test/java/beta/automl/GetModelEvaluationTest.java +++ /dev/null @@ -1,100 +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 com.google.cloud.testing.junit4.MultipleAttemptsRule; -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.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class GetModelEvaluationTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - 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 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(); - PrintStream 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/automl/src/test/java/beta/automl/GetModelTest.java b/automl/src/test/java/beta/automl/GetModelTest.java deleted file mode 100644 index d8e2b5c1b2c..00000000000 --- a/automl/src/test/java/beta/automl/GetModelTest.java +++ /dev/null @@ -1,80 +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.testing.junit4.MultipleAttemptsRule; -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.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class GetModelTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - 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 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(); - PrintStream 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/automl/src/test/java/beta/automl/GetOperationStatusTest.java b/automl/src/test/java/beta/automl/GetOperationStatusTest.java deleted file mode 100644 index 2a9b5c228de..00000000000 --- a/automl/src/test/java/beta/automl/GetOperationStatusTest.java +++ /dev/null @@ -1,93 +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.cloud.testing.junit4.MultipleAttemptsRule; -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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class GetOperationStatusTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private String operationId; - private ByteArrayOutputStream bout; - 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(); - PrintStream 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/automl/src/test/java/beta/automl/ImportDatasetTest.java b/automl/src/test/java/beta/automl/ImportDatasetTest.java deleted file mode 100644 index 45a95385d5c..00000000000 --- a/automl/src/test/java/beta/automl/ImportDatasetTest.java +++ /dev/null @@ -1,89 +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 com.google.cloud.testing.junit4.MultipleAttemptsRule; -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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class ImportDatasetTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - 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 ByteArrayOutputStream bout; - 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(); - PrintStream 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/automl/src/test/java/beta/automl/ListDatasetsTest.java b/automl/src/test/java/beta/automl/ListDatasetsTest.java deleted file mode 100644 index 3a9c45e1d17..00000000000 --- a/automl/src/test/java/beta/automl/ListDatasetsTest.java +++ /dev/null @@ -1,79 +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.testing.junit4.MultipleAttemptsRule; -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.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class ListDatasetsTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - 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(); - PrintStream 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/automl/src/test/java/beta/automl/ListModelEvaluationsTest.java b/automl/src/test/java/beta/automl/ListModelEvaluationsTest.java deleted file mode 100644 index d6deda9de7e..00000000000 --- a/automl/src/test/java/beta/automl/ListModelEvaluationsTest.java +++ /dev/null @@ -1,80 +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.testing.junit4.MultipleAttemptsRule; -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.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class ListModelEvaluationsTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - 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 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(); - PrintStream 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/automl/src/test/java/beta/automl/ListModelsTest.java b/automl/src/test/java/beta/automl/ListModelsTest.java deleted file mode 100644 index 67deb9da3ee..00000000000 --- a/automl/src/test/java/beta/automl/ListModelsTest.java +++ /dev/null @@ -1,81 +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.testing.junit4.MultipleAttemptsRule; -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.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class ListModelsTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - 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(); - PrintStream 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/automl/src/test/java/beta/automl/SetEndpointIT.java b/automl/src/test/java/beta/automl/SetEndpointIT.java deleted file mode 100644 index 51a08314c23..00000000000 --- a/automl/src/test/java/beta/automl/SetEndpointIT.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 com.google.cloud.testing.junit4.MultipleAttemptsRule; -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.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Tests for Automl Set Endpoint */ -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class SetEndpointIT { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private ByteArrayOutputStream bout; - 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(); - PrintStream 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/automl/src/test/java/beta/automl/TablesBatchPredictBigQueryTest.java b/automl/src/test/java/beta/automl/TablesBatchPredictBigQueryTest.java deleted file mode 100644 index 184a889dc67..00000000000 --- a/automl/src/test/java/beta/automl/TablesBatchPredictBigQueryTest.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.testing.junit4.MultipleAttemptsRule; -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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class TablesBatchPredictBigQueryTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - - 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 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(); - PrintStream 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/automl/src/test/java/beta/automl/TablesCreateDatasetTest.java b/automl/src/test/java/beta/automl/TablesCreateDatasetTest.java deleted file mode 100644 index d8bc81ef59a..00000000000 --- a/automl/src/test/java/beta/automl/TablesCreateDatasetTest.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.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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class TablesCreateDatasetTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - 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(); - PrintStream 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/automl/src/test/java/beta/automl/TablesCreateModelTest.java b/automl/src/test/java/beta/automl/TablesCreateModelTest.java deleted file mode 100644 index d13ec984bdc..00000000000 --- a/automl/src/test/java/beta/automl/TablesCreateModelTest.java +++ /dev/null @@ -1,95 +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.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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class TablesCreateModelTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - - 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 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(); - PrintStream 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/automl/src/test/java/beta/automl/TablesGetModelTest.java b/automl/src/test/java/beta/automl/TablesGetModelTest.java deleted file mode 100644 index 80a52c5b237..00000000000 --- a/automl/src/test/java/beta/automl/TablesGetModelTest.java +++ /dev/null @@ -1,79 +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.testing.junit4.MultipleAttemptsRule; -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.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class TablesGetModelTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = "TBL7473655411900416000"; - private ByteArrayOutputStream bout; - 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(); - PrintStream 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/automl/src/test/java/beta/automl/TablesImportDatasetTest.java b/automl/src/test/java/beta/automl/TablesImportDatasetTest.java deleted file mode 100644 index fc36afd9272..00000000000 --- a/automl/src/test/java/beta/automl/TablesImportDatasetTest.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 beta.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.concurrent.ExecutionException; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class TablesImportDatasetTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - 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(); - PrintStream 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/automl/src/test/java/beta/automl/TablesPredictTest.java b/automl/src/test/java/beta/automl/TablesPredictTest.java deleted file mode 100644 index b1410a3930a..00000000000 --- a/automl/src/test/java/beta/automl/TablesPredictTest.java +++ /dev/null @@ -1,120 +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.cloud.testing.junit4.MultipleAttemptsRule; -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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class TablesPredictTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String MODEL_ID = "TBL7972827093840953344"; - private ByteArrayOutputStream bout; - 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(); - PrintStream 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/automl/src/test/java/beta/automl/UndeployModelTest.java b/automl/src/test/java/beta/automl/UndeployModelTest.java deleted file mode 100644 index 9740fa86cab..00000000000 --- a/automl/src/test/java/beta/automl/UndeployModelTest.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.cloud.testing.junit4.MultipleAttemptsRule; -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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class UndeployModelTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = "TEN0000000000000000000"; - private ByteArrayOutputStream bout; - 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(); - PrintStream 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/automl/src/test/java/beta/automl/VideoClassificationCreateDatasetTest.java b/automl/src/test/java/beta/automl/VideoClassificationCreateDatasetTest.java deleted file mode 100644 index 174fe37e6c7..00000000000 --- a/automl/src/test/java/beta/automl/VideoClassificationCreateDatasetTest.java +++ /dev/null @@ -1,95 +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 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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VideoClassificationCreateDatasetTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - 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(); - PrintStream 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/automl/src/test/java/beta/automl/VideoClassificationCreateModelTest.java b/automl/src/test/java/beta/automl/VideoClassificationCreateModelTest.java deleted file mode 100644 index 4dc9df168f0..00000000000 --- a/automl/src/test/java/beta/automl/VideoClassificationCreateModelTest.java +++ /dev/null @@ -1,93 +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.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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VideoClassificationCreateModelTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String DATASET_ID = "VCN00000000000000"; - private ByteArrayOutputStream bout; - 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(); - PrintStream 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/automl/src/test/java/beta/automl/VideoObjectTrackingCreateDatasetTest.java b/automl/src/test/java/beta/automl/VideoObjectTrackingCreateDatasetTest.java deleted file mode 100644 index 63c8a66bdb1..00000000000 --- a/automl/src/test/java/beta/automl/VideoObjectTrackingCreateDatasetTest.java +++ /dev/null @@ -1,95 +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 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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VideoObjectTrackingCreateDatasetTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - 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(); - PrintStream 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/automl/src/test/java/beta/automl/VideoObjectTrackingCreateModelTest.java b/automl/src/test/java/beta/automl/VideoObjectTrackingCreateModelTest.java deleted file mode 100644 index fca9e38ff5a..00000000000 --- a/automl/src/test/java/beta/automl/VideoObjectTrackingCreateModelTest.java +++ /dev/null @@ -1,95 +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.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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VideoObjectTrackingCreateModelTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String DATASET_ID = "VOT0000000000000000"; - private ByteArrayOutputStream bout; - 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(); - PrintStream 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/automl/src/test/java/com/example/automl/BatchPredictTest.java b/automl/src/test/java/com/example/automl/BatchPredictTest.java deleted file mode 100644 index 98c0846bc96..00000000000 --- a/automl/src/test/java/com/example/automl/BatchPredictTest.java +++ /dev/null @@ -1,89 +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.cloud.testing.junit4.MultipleAttemptsRule; -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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class BatchPredictTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - 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 originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", 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(); - PrintStream 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/automl/src/test/java/com/example/automl/DeleteDatasetTest.java b/automl/src/test/java/com/example/automl/DeleteDatasetTest.java deleted file mode 100644 index def0431c7bc..00000000000 --- a/automl/src/test/java/com/example/automl/DeleteDatasetTest.java +++ /dev/null @@ -1,96 +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.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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class DeleteDatasetTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - private String datasetId; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", 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(); - PrintStream 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/automl/src/test/java/com/example/automl/DeleteModelTest.java b/automl/src/test/java/com/example/automl/DeleteModelTest.java deleted file mode 100644 index 40bf14b55fe..00000000000 --- a/automl/src/test/java/com/example/automl/DeleteModelTest.java +++ /dev/null @@ -1,84 +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.concurrent.ExecutionException; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class DeleteModelTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/DeployModelTest.java b/automl/src/test/java/com/example/automl/DeployModelTest.java deleted file mode 100644 index 28208289aaf..00000000000 --- a/automl/src/test/java/com/example/automl/DeployModelTest.java +++ /dev/null @@ -1,85 +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.concurrent.ExecutionException; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class DeployModelTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = "TEN0000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/ExportDatasetTest.java b/automl/src/test/java/com/example/automl/ExportDatasetTest.java deleted file mode 100644 index fe823e40812..00000000000 --- a/automl/src/test/java/com/example/automl/ExportDatasetTest.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 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.concurrent.ExecutionException; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class ExportDatasetTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - 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 originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", 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(); - PrintStream 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/automl/src/test/java/com/example/automl/GetDatasetTest.java b/automl/src/test/java/com/example/automl/GetDatasetTest.java deleted file mode 100644 index 9daf0c15a68..00000000000 --- a/automl/src/test/java/com/example/automl/GetDatasetTest.java +++ /dev/null @@ -1,79 +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.cloud.testing.junit4.MultipleAttemptsRule; -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.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class GetDatasetTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - 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 originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", 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(); - PrintStream 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/automl/src/test/java/com/example/automl/GetModelEvaluationTest.java b/automl/src/test/java/com/example/automl/GetModelEvaluationTest.java deleted file mode 100644 index f29a8b1e66b..00000000000 --- a/automl/src/test/java/com/example/automl/GetModelEvaluationTest.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 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 org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class GetModelEvaluationTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - 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 originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", 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(); - PrintStream 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/automl/src/test/java/com/example/automl/GetModelTest.java b/automl/src/test/java/com/example/automl/GetModelTest.java deleted file mode 100644 index be2404ad5b1..00000000000 --- a/automl/src/test/java/com/example/automl/GetModelTest.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 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 org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class GetModelTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - 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 originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", 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(); - PrintStream 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/automl/src/test/java/com/example/automl/GetOperationStatusTest.java b/automl/src/test/java/com/example/automl/GetOperationStatusTest.java deleted file mode 100644 index 7ddb70b1287..00000000000 --- a/automl/src/test/java/com/example/automl/GetOperationStatusTest.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 com.google.cloud.testing.junit4.MultipleAttemptsRule; -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.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class GetOperationStatusTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private String operationId; - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() throws IOException { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/ImportDatasetTest.java b/automl/src/test/java/com/example/automl/ImportDatasetTest.java deleted file mode 100644 index 6b07e7a5ffe..00000000000 --- a/automl/src/test/java/com/example/automl/ImportDatasetTest.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 com.google.api.gax.rpc.NotFoundException; -import com.google.cloud.testing.junit4.MultipleAttemptsRule; -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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class ImportDatasetTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - 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 originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/LanguageEntityExtractionCreateDatasetTest.java b/automl/src/test/java/com/example/automl/LanguageEntityExtractionCreateDatasetTest.java deleted file mode 100644 index 65f1ac25fad..00000000000 --- a/automl/src/test/java/com/example/automl/LanguageEntityExtractionCreateDatasetTest.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 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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class LanguageEntityExtractionCreateDatasetTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - private String datasetId; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java b/automl/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java deleted file mode 100644 index c1896347972..00000000000 --- a/automl/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java +++ /dev/null @@ -1,91 +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.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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class LanguageEntityExtractionCreateModelTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String DATASET_ID = "TEN0000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/LanguageEntityExtractionPredictTest.java b/automl/src/test/java/com/example/automl/LanguageEntityExtractionPredictTest.java deleted file mode 100644 index b990a450a39..00000000000 --- a/automl/src/test/java/com/example/automl/LanguageEntityExtractionPredictTest.java +++ /dev/null @@ -1,98 +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 com.google.cloud.testing.junit4.MultipleAttemptsRule; -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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class LanguageEntityExtractionPredictTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - 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 originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", 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(); - PrintStream 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/automl/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateDatasetTest.java b/automl/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateDatasetTest.java deleted file mode 100644 index 4be69247705..00000000000 --- a/automl/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateDatasetTest.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 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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class LanguageSentimentAnalysisCreateDatasetTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - private String datasetId; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java b/automl/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java deleted file mode 100644 index 8ab18ba1367..00000000000 --- a/automl/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.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 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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class LanguageSentimentAnalysisCreateModelTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String DATASET_ID = "TST00000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/LanguageSentimentAnalysisPredictTest.java b/automl/src/test/java/com/example/automl/LanguageSentimentAnalysisPredictTest.java deleted file mode 100644 index 2a2b5f2fc3f..00000000000 --- a/automl/src/test/java/com/example/automl/LanguageSentimentAnalysisPredictTest.java +++ /dev/null @@ -1,98 +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 com.google.cloud.testing.junit4.MultipleAttemptsRule; -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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class LanguageSentimentAnalysisPredictTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - 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 originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", 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(); - PrintStream 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/automl/src/test/java/com/example/automl/LanguageTextClassificationCreateDatasetTest.java b/automl/src/test/java/com/example/automl/LanguageTextClassificationCreateDatasetTest.java deleted file mode 100644 index 1cc9161ca07..00000000000 --- a/automl/src/test/java/com/example/automl/LanguageTextClassificationCreateDatasetTest.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 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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class LanguageTextClassificationCreateDatasetTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - private String datasetId; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java b/automl/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java deleted file mode 100644 index 6aa35a46d16..00000000000 --- a/automl/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.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 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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class LanguageTextClassificationCreateModelTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String DATASET_ID = "TCN00000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/LanguageTextClassificationPredictTest.java b/automl/src/test/java/com/example/automl/LanguageTextClassificationPredictTest.java deleted file mode 100644 index 1ae0b49cfe3..00000000000 --- a/automl/src/test/java/com/example/automl/LanguageTextClassificationPredictTest.java +++ /dev/null @@ -1,98 +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 com.google.cloud.testing.junit4.MultipleAttemptsRule; -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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class LanguageTextClassificationPredictTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - 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 originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", 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(); - PrintStream 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/automl/src/test/java/com/example/automl/ListDatasetsTest.java b/automl/src/test/java/com/example/automl/ListDatasetsTest.java deleted file mode 100644 index 1708ad1515f..00000000000 --- a/automl/src/test/java/com/example/automl/ListDatasetsTest.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 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 org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class ListDatasetsTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/ListModelEvaluationsTest.java b/automl/src/test/java/com/example/automl/ListModelEvaluationsTest.java deleted file mode 100644 index e507d399177..00000000000 --- a/automl/src/test/java/com/example/automl/ListModelEvaluationsTest.java +++ /dev/null @@ -1,79 +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.cloud.testing.junit4.MultipleAttemptsRule; -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.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class ListModelEvaluationsTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - 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 originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", 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(); - PrintStream 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/automl/src/test/java/com/example/automl/ListModelsTest.java b/automl/src/test/java/com/example/automl/ListModelsTest.java deleted file mode 100644 index 8c251806b9a..00000000000 --- a/automl/src/test/java/com/example/automl/ListModelsTest.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 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 org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class ListModelsTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/ListOperationStatusTest.java b/automl/src/test/java/com/example/automl/ListOperationStatusTest.java deleted file mode 100644 index 588b1f86212..00000000000 --- a/automl/src/test/java/com/example/automl/ListOperationStatusTest.java +++ /dev/null @@ -1,141 +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.cloud.testing.junit4.MultipleAttemptsRule; -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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class ListOperationStatusTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() throws IOException, InterruptedException { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/TranslateCreateDatasetTest.java b/automl/src/test/java/com/example/automl/TranslateCreateDatasetTest.java deleted file mode 100644 index fe64e5bc541..00000000000 --- a/automl/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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class TranslateCreateDatasetTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - private String got; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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); - } - - @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/automl/src/test/java/com/example/automl/TranslateCreateModelTest.java b/automl/src/test/java/com/example/automl/TranslateCreateModelTest.java deleted file mode 100644 index 1f197bd704f..00000000000 --- a/automl/src/test/java/com/example/automl/TranslateCreateModelTest.java +++ /dev/null @@ -1,93 +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.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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -// Tests for Automl translation models. -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class TranslateCreateModelTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String DATASET_ID = "TRL00000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/TranslatePredictTest.java b/automl/src/test/java/com/example/automl/TranslatePredictTest.java deleted file mode 100644 index 08b584b9916..00000000000 --- a/automl/src/test/java/com/example/automl/TranslatePredictTest.java +++ /dev/null @@ -1,85 +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 org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -// Tests for translation "Predict" sample. -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class TranslatePredictTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - 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 originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", 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(); - PrintStream 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/automl/src/test/java/com/example/automl/UndeployModelTest.java b/automl/src/test/java/com/example/automl/UndeployModelTest.java deleted file mode 100644 index f0aa8ad2b70..00000000000 --- a/automl/src/test/java/com/example/automl/UndeployModelTest.java +++ /dev/null @@ -1,86 +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.concurrent.ExecutionException; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class UndeployModelTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = "TEN0000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/VisionClassificationCreateDatasetTest.java b/automl/src/test/java/com/example/automl/VisionClassificationCreateDatasetTest.java deleted file mode 100644 index 67a66ae5af0..00000000000 --- a/automl/src/test/java/com/example/automl/VisionClassificationCreateDatasetTest.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 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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VisionClassificationCreateDatasetTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - private String datasetId; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java b/automl/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java deleted file mode 100644 index b23e7a062ab..00000000000 --- a/automl/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java +++ /dev/null @@ -1,89 +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.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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VisionClassificationCreateModelTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String DATASET_ID = "ICN000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/VisionClassificationDeployModelNodeCountTest.java b/automl/src/test/java/com/example/automl/VisionClassificationDeployModelNodeCountTest.java deleted file mode 100644 index 68523487b15..00000000000 --- a/automl/src/test/java/com/example/automl/VisionClassificationDeployModelNodeCountTest.java +++ /dev/null @@ -1,87 +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.concurrent.ExecutionException; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class VisionClassificationDeployModelNodeCountTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = "ICN0000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/VisionClassificationPredictTest.java b/automl/src/test/java/com/example/automl/VisionClassificationPredictTest.java deleted file mode 100644 index 32642df53a6..00000000000 --- a/automl/src/test/java/com/example/automl/VisionClassificationPredictTest.java +++ /dev/null @@ -1,98 +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 com.google.cloud.testing.junit4.MultipleAttemptsRule; -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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VisionClassificationPredictTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - 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 originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", 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(); - PrintStream 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/automl/src/test/java/com/example/automl/VisionObjectDetectionCreateDatasetTest.java b/automl/src/test/java/com/example/automl/VisionObjectDetectionCreateDatasetTest.java deleted file mode 100644 index 5070c1e04b2..00000000000 --- a/automl/src/test/java/com/example/automl/VisionObjectDetectionCreateDatasetTest.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 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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VisionObjectDetectionCreateDatasetTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - private String datasetId; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java b/automl/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java deleted file mode 100644 index f18f8a4ab35..00000000000 --- a/automl/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java +++ /dev/null @@ -1,89 +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.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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VisionObjectDetectionCreateModelTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String DATASET_ID = "IOD0000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/VisionObjectDetectionDeployModelNodeCountTest.java b/automl/src/test/java/com/example/automl/VisionObjectDetectionDeployModelNodeCountTest.java deleted file mode 100644 index 604f3a2d924..00000000000 --- a/automl/src/test/java/com/example/automl/VisionObjectDetectionDeployModelNodeCountTest.java +++ /dev/null @@ -1,87 +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.concurrent.ExecutionException; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -public class VisionObjectDetectionDeployModelNodeCountTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = "0000000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", varName)); - - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - PrintStream 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/automl/src/test/java/com/example/automl/VisionObjectDetectionPredictTest.java b/automl/src/test/java/com/example/automl/VisionObjectDetectionPredictTest.java deleted file mode 100644 index 6b705cc5048..00000000000 --- a/automl/src/test/java/com/example/automl/VisionObjectDetectionPredictTest.java +++ /dev/null @@ -1,99 +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 com.google.cloud.testing.junit4.MultipleAttemptsRule; -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.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@Ignore("This test is ignored because the legacy version of AutoML API is deprecated") -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class VisionObjectDetectionPredictTest { - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - 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 originalPrintStream; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - String.format("Environment variable '%s' is required to perform these tests.", 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(); - PrintStream 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:"); - } -}