Skip to content

Commit

Permalink
chore: migrate to owlbot (#738)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neenu1995 authored Jun 10, 2021
1 parent 1d56299 commit edd5830
Show file tree
Hide file tree
Showing 19 changed files with 29 additions and 55 deletions.
4 changes: 2 additions & 2 deletions automl/snippets/src/main/java/beta/automl/ImportDataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ static void importDataset(String projectId, String datasetId, String path)
System.out.println("Processing import...");

// Start the import job
OperationFuture<Empty, OperationMetadata> operation = client
.importDataAsync(datasetFullId, inputConfig);
OperationFuture<Empty, OperationMetadata> operation =
client.importDataAsync(datasetFullId, inputConfig);

System.out.format("Operation name: %s%n", operation.getName());

Expand Down
2 changes: 0 additions & 2 deletions automl/snippets/src/main/java/beta/automl/ListDatasets.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
// [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.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;
import org.threeten.bp.Duration;

class ListDatasets {

Expand Down
2 changes: 0 additions & 2 deletions automl/snippets/src/main/java/beta/automl/ListModels.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
// [START automl_tables_list_models]
// [START automl_list_models_beta]
import com.google.cloud.automl.v1beta1.AutoMlClient;
import com.google.cloud.automl.v1beta1.AutoMlSettings;
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;
import org.threeten.bp.Duration;

class ListModels {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ static void predict(String projectId, String modelId, String content) throws IOE
// 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();
.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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@

// [START automl_list_models]
import com.google.cloud.automl.v1.AutoMlClient;
import com.google.cloud.automl.v1.AutoMlSettings;
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;
import org.threeten.bp.Duration;

class ListModels {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public static void argsHelper(String[] args, PrintStream out) throws Exception {
importDataParser.addArgument("datasetId");
importDataParser.addArgument("path");


String projectId = System.getenv("PROJECT_ID");
String computeRegion = System.getenv("REGION_NAME");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.cloud.automl.v1beta1.ListModelsRequest;
import com.google.cloud.automl.v1beta1.LocationName;
import com.google.cloud.automl.v1beta1.Model;
import com.google.cloud.automl.v1beta1.ModelName;
import com.google.longrunning.Operation;
import java.io.IOException;
import java.io.PrintStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ static void predict(
String computeRegion,
String modelId,
String filePath,
String scoreThreshold) throws IOException {
String scoreThreshold)
throws IOException {

// Instantiate client for prediction service.
try (PredictionServiceClient predictionClient = PredictionServiceClient.create()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,11 @@
// Imports the Google Cloud client library
import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.automl.v1beta1.AutoMlClient;
import com.google.cloud.automl.v1beta1.ClassificationProto.ClassificationEvaluationMetrics;
import com.google.cloud.automl.v1beta1.ClassificationProto.ClassificationEvaluationMetrics.ConfidenceMetricsEntry;
import com.google.cloud.automl.v1beta1.ImageClassificationModelMetadata;
import com.google.cloud.automl.v1beta1.ListModelEvaluationsRequest;
import com.google.cloud.automl.v1beta1.ListModelsRequest;
import com.google.cloud.automl.v1beta1.LocationName;
import com.google.cloud.automl.v1beta1.Model;
import com.google.cloud.automl.v1beta1.ModelEvaluation;
import com.google.cloud.automl.v1beta1.ModelEvaluationName;
import com.google.cloud.automl.v1beta1.ModelName;
import com.google.cloud.automl.v1beta1.OperationMetadata;
import com.google.longrunning.Operation;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutionException;
import net.sourceforge.argparse4j.ArgumentParsers;
import net.sourceforge.argparse4j.inf.ArgumentParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ public void tearDown() {
public void testCancelOperation() throws IOException {
String operationFullPathId =
String.format(
"projects/%s/locations/%s/operations/%s", PROJECT_ID, "us-central1",
"TCN0000000000");
"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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public void tearDown() {
}

@Test
public void testImportDataset()
throws TimeoutException {
public void testImportDataset() throws TimeoutException {
try {
ImportDataset.importDataset(
PROJECT_ID, "TCN0000000000", BUCKET + "/entity-extraction/dataset.csv");
Expand Down
4 changes: 1 addition & 3 deletions automl/snippets/src/test/java/beta/automl/SetEndpointIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
* Tests for Automl Set Endpoint
*/
/** Tests for Automl Set Endpoint */
@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class SetEndpointIT {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public class TablesBatchPredictBigQueryTest {
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);
"bq://%s.automl_do_not_delete_predict_test.automl_predict_test_table", PROJECT_ID);
private static final String OUTPUT_URI = "bq://" + PROJECT_ID;
private ByteArrayOutputStream bout;
private PrintStream out;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ public void testTablesCreateModel() throws IOException, ExecutionException, Inte
// 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.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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ public void testVisionClassificationCreateModel()
// 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));
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ public void testVisionClassificationCreateModel()
// 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));
String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26));
VideoObjectTrackingCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName);

String got = bout.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,27 @@ public void setUp() throws IOException, InterruptedException {
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();
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);
System.out.printf(
"Backing off for %d milliseconds " + "due to Resource exhaustion.\n",
backOffInMillis);
if (backOffInMillis < 0) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ public void tearDown() {
}

@Test
public void testCreateImportDeleteDataset()
throws IOException, InterruptedException {
public void testCreateImportDeleteDataset() throws IOException, InterruptedException {
try {
DatasetApi.importData(
PROJECT_ID, COMPUTE_REGION, datasetId, "gs://" + BUCKET + "/en-ja-short.csv");
PROJECT_ID, COMPUTE_REGION, datasetId, "gs://" + BUCKET + "/en-ja-short.csv");
String got = bout.toString();
assertThat(got).contains("The Dataset doesn't exist ");
} catch (NotFoundException | ExecutionException | StatusRuntimeException ex) {
Expand Down

0 comments on commit edd5830

Please sign in to comment.