diff --git a/automl/snippets/src/main/java/com/google/cloud/translate/automl/DatasetApi.java b/automl/snippets/src/main/java/com/google/cloud/translate/automl/DatasetApi.java index fa03c6fd50a..32f0c0641a0 100644 --- a/automl/snippets/src/main/java/com/google/cloud/translate/automl/DatasetApi.java +++ b/automl/snippets/src/main/java/com/google/cloud/translate/automl/DatasetApi.java @@ -75,30 +75,6 @@ public static void importData( } // [END automl_translate_import_data] - // [START automl_translate_delete_dataset] - /** - * Delete a dataset. - * - * @param projectId the Google Cloud Project ID. - * @param computeRegion the Region name. (e.g., "us-central1"). - * @param datasetId the Id of the dataset. - */ - public static void deleteDataset(String projectId, String computeRegion, String datasetId) - throws IOException, InterruptedException, ExecutionException { - // Instantiates a client - try (AutoMlClient client = AutoMlClient.create()) { - - // Get the full path of the dataset. - DatasetName datasetFullId = DatasetName.of(projectId, computeRegion, datasetId); - - // Delete a dataset. - Empty response = client.deleteDatasetAsync(datasetFullId).get(); - - System.out.println(String.format("Dataset deleted. %s", response)); - } - } - // [END automl_translate_delete_dataset] - public static void main(String[] args) throws Exception { DatasetApi datasetApi = new DatasetApi(); datasetApi.argsHelper(args, System.out); @@ -112,8 +88,6 @@ public static void argsHelper(String[] args, PrintStream out) throws Exception { importDataParser.addArgument("datasetId"); importDataParser.addArgument("path"); - Subparser deleteDatasetParser = subparsers.addParser("delete_dataset"); - deleteDatasetParser.addArgument("datasetId"); String projectId = System.getenv("PROJECT_ID"); String computeRegion = System.getenv("REGION_NAME"); @@ -124,9 +98,6 @@ public static void argsHelper(String[] args, PrintStream out) throws Exception { if (ns.get("command").equals("import_data")) { importData(projectId, computeRegion, ns.getString("datasetId"), ns.getString("path")); } - if (ns.get("command").equals("delete_dataset")) { - deleteDataset(projectId, computeRegion, ns.getString("datasetId")); - } } catch (ArgumentParserException e) { parser.handleError(e); } diff --git a/automl/snippets/src/main/java/com/google/cloud/translate/automl/ModelApi.java b/automl/snippets/src/main/java/com/google/cloud/translate/automl/ModelApi.java index 900fd4f09ea..54f5a337e46 100644 --- a/automl/snippets/src/main/java/com/google/cloud/translate/automl/ModelApi.java +++ b/automl/snippets/src/main/java/com/google/cloud/translate/automl/ModelApi.java @@ -23,10 +23,8 @@ import com.google.cloud.automl.v1beta1.Model; import com.google.cloud.automl.v1beta1.ModelName; import com.google.longrunning.Operation; -import com.google.protobuf.Empty; import java.io.IOException; import java.io.PrintStream; -import java.util.concurrent.ExecutionException; import net.sourceforge.argparse4j.ArgumentParsers; import net.sourceforge.argparse4j.inf.ArgumentParser; import net.sourceforge.argparse4j.inf.ArgumentParserException; @@ -83,65 +81,6 @@ public static void listModels(String projectId, String computeRegion, String fil } // [END automl_translate_list_models] - // [START automl_translate_get_model] - /** - * Demonstrates using the AutoML client to get model details. - * - * @param projectId the Id of the project. - * @param computeRegion the Region name. - * @param modelId the Id of the model. - * @throws IOException on Input/Output errors. - */ - public static void getModel(String projectId, String computeRegion, String modelId) - throws IOException { - // Instantiates a client - 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.println(String.format("Model name: %s", model.getName())); - System.out.println( - String.format( - "Model id: %s", model.getName().split("/")[model.getName().split("/").length - 1])); - System.out.println(String.format("Model display name: %s", model.getDisplayName())); - System.out.println("Model create time:"); - System.out.println(String.format("\tseconds: %s", model.getCreateTime().getSeconds())); - System.out.println(String.format("\tnanos: %s", model.getCreateTime().getNanos())); - System.out.println(String.format("Model deployment state: %s", model.getDeploymentState())); - } - } - // [END automl_translate_get_model] - - // [START automl_translate_delete_model] - /** - * Demonstrates using the AutoML client to delete a model. - * - * @param projectId the Id of the project. - * @param computeRegion the Region name. - * @param modelId the Id of the model. - * @throws Exception on AutoML Client errors - */ - public static void deleteModel(String projectId, String computeRegion, String modelId) - throws InterruptedException, ExecutionException, IOException { - // Instantiates a client - try (AutoMlClient client = AutoMlClient.create()) { - - // Get the full path of the model. - ModelName modelFullId = ModelName.of(projectId, computeRegion, modelId); - - // Delete a model. - Empty response = client.deleteModelAsync(modelFullId).get(); - - System.out.println("Model deletion started..."); - } - } - // [END automl_translate_delete_model] - // [START automl_translate_get_operation_status] /** * Demonstrates using the AutoML client to get operation status. @@ -179,12 +118,6 @@ public static void argsHelper(String[] args, PrintStream out) throws Exception { Subparser listModelParser = subparsers.addParser("list_models"); listModelParser.addArgument("filter").nargs("?").setDefault(""); - Subparser getModelParser = subparsers.addParser("get_model"); - getModelParser.addArgument("modelId"); - - Subparser deleteModelParser = subparsers.addParser("delete_model"); - deleteModelParser.addArgument("modelId"); - Subparser getOperationStatusParser = subparsers.addParser("get_operation_status"); getOperationStatusParser.addArgument("operationFullId"); @@ -197,12 +130,6 @@ public static void argsHelper(String[] args, PrintStream out) throws Exception { if (ns.get("command").equals("list_models")) { listModels(projectId, computeRegion, ns.getString("filter")); } - if (ns.get("command").equals("get_model")) { - getModel(projectId, computeRegion, ns.getString("modelId")); - } - if (ns.get("command").equals("delete_model")) { - deleteModel(projectId, computeRegion, ns.getString("modelId")); - } if (ns.get("command").equals("get_operation_status")) { getOperationStatus(ns.getString("operationFullId")); } diff --git a/automl/snippets/src/main/java/com/google/cloud/vision/ClassificationDeployModel.java b/automl/snippets/src/main/java/com/google/cloud/vision/ClassificationDeployModel.java deleted file mode 100644 index 2dd81b40afe..00000000000 --- a/automl/snippets/src/main/java/com/google/cloud/vision/ClassificationDeployModel.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud.vision; - -// [START automl_vision_classification_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 ClassificationDeployModel { - - // Deploy a model - static void classificationDeployModel(String projectId, String modelId) - throws IOException, ExecutionException, InterruptedException { - // String projectId = "YOUR_PROJECT_ID"; - // String modelId = "YOUR_MODEL_ID"; - - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (AutoMlClient client = AutoMlClient.create()) { - - // Get the full path of the model. - ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId); - - // Build deploy model request. - DeployModelRequest deployModelRequest = - DeployModelRequest.newBuilder().setName(modelFullId.toString()).build(); - - // Deploy a model with the deploy model request. - OperationFuture future = - client.deployModelAsync(deployModelRequest); - - future.get(); - - // Display the deployment details of model. - System.out.println("Model deployment finished"); - } - } -} -// [END automl_vision_classification_deploy_model] diff --git a/automl/snippets/src/main/java/com/google/cloud/vision/ModelApi.java b/automl/snippets/src/main/java/com/google/cloud/vision/ModelApi.java deleted file mode 100644 index e8b3b3aa0d2..00000000000 --- a/automl/snippets/src/main/java/com/google/cloud/vision/ModelApi.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2018 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud.vision; - -// Imports the Google Cloud client library -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; - -/** - * Google Cloud AutoML Vision API sample application. Example usage: mvn package exec:java - * -Dexec.mainClass ='com.google.cloud.vision.samples.automl.ModelApi' -Dexec.args='create_model - * [datasetId] test_model' - */ -public class ModelApi { - - // [START automl_vision_create_model] - /** - * Demonstrates using the AutoML client to create a model. - * - * @param projectId the Id of the project. - * @param computeRegion the Region name. - * @param dataSetId the Id of the dataset to which model is created. - * @param modelName the Name of the model. - * @param trainBudget the Budget for training the model. - */ - static void createModel( - String projectId, - String computeRegion, - String dataSetId, - String modelName, - String trainBudget) throws IOException, ExecutionException, InterruptedException { - // Instantiates a client - try (AutoMlClient client = AutoMlClient.create()) { - - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, computeRegion); - - // Set model metadata. - ImageClassificationModelMetadata imageClassificationModelMetadata = - Long.valueOf(trainBudget) == 0 - ? ImageClassificationModelMetadata.newBuilder().build() - : ImageClassificationModelMetadata.newBuilder() - .setTrainBudgetMilliNodeHours(Long.valueOf(trainBudget)) - .build(); - - // Set model name and model metadata for the image dataset. - Model myModel = - Model.newBuilder() - .setDisplayName(modelName) - .setDatasetId(dataSetId) - .setImageClassificationModelMetadata(imageClassificationModelMetadata) - .build(); - - // Create a model with the model metadata in the region. - OperationFuture response = - client.createModelAsync(projectLocation, myModel); - - System.out.println( - String.format( - "Training operation name: %s", response.getInitialFuture().get().getName())); - System.out.println("Training started..."); - } - } - // [END automl_vision_create_model] -} diff --git a/automl/snippets/src/test/java/com/google/cloud/translate/automl/ModelApiIT.java b/automl/snippets/src/test/java/com/google/cloud/translate/automl/ModelApiIT.java index 214a4a5a221..1d0f28198a2 100644 --- a/automl/snippets/src/test/java/com/google/cloud/translate/automl/ModelApiIT.java +++ b/automl/snippets/src/test/java/com/google/cloud/translate/automl/ModelApiIT.java @@ -62,12 +62,5 @@ public void testModelApi() throws Exception { String got = bout.toString(); modelId = got.split("\n")[1].split("/")[got.split("\n")[1].split("/").length - 1]; assertThat(got).contains("Model id:"); - - // Act - ModelApi.getModel(PROJECT_ID, COMPUTE_REGION, modelId); - - // Assert - got = bout.toString(); - assertThat(got).contains("Model name:"); } } diff --git a/automl/snippets/src/test/java/com/google/cloud/vision/ClassificationDeployModelIT.java b/automl/snippets/src/test/java/com/google/cloud/vision/ClassificationDeployModelIT.java index 06d4f9beae2..d71f0d5c550 100644 --- a/automl/snippets/src/test/java/com/google/cloud/vision/ClassificationDeployModelIT.java +++ b/automl/snippets/src/test/java/com/google/cloud/vision/ClassificationDeployModelIT.java @@ -48,20 +48,6 @@ public void tearDown() { System.setOut(originalPrintStream); } - @Test - public void testClassificationDeployModelApi() { - // As model deployment can take a long time, instead try to deploy a - // nonexistent model and confirm that the model was not found, but other - // elements of the request were valid. - try { - ClassificationDeployModel.classificationDeployModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("The model does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("The model does not exist"); - } - } - @Test public void testClassificationUndeployModelApi() { // As model deployment can take a long time, instead try to deploy a