From 56349ed40cb45672e42bb3f0db9cb142a81b0d5e Mon Sep 17 00:00:00 2001 From: sai-chaithu Date: Fri, 24 Jun 2022 20:07:16 +0530 Subject: [PATCH 1/3] feat(samples): added all entity type samples --- .../CreateEntityTypeMonitoringSample.java | 95 ++++++++++ .../aiplatform/CreateEntityTypeSample.java | 84 +++++++++ .../aiplatform/DeleteEntityTypeSample.java | 79 ++++++++ .../java/aiplatform/GetEntityTypeSample.java | 67 +++++++ .../ListEntityTypesAsyncSample.java | 78 ++++++++ .../aiplatform/ListEntityTypesSample.java | 66 +++++++ .../UpdateEntityTypeMonitoringSample.java | 79 ++++++++ .../aiplatform/UpdateEntityTypeSample.java | 71 +++++++ .../aiplatform/EntityTypeSamplesTest.java | 175 ++++++++++++++++++ 9 files changed, 794 insertions(+) create mode 100644 samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java create mode 100644 samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java create mode 100644 samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java create mode 100644 samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.java create mode 100644 samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java create mode 100644 samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java create mode 100644 samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java create mode 100644 samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java create mode 100644 samples/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java diff --git a/samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java b/samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java new file mode 100644 index 000000000..eddc74e4c --- /dev/null +++ b/samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java @@ -0,0 +1,95 @@ +/* + * Copyright 2022 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. + * + * + * Create an entity type so that you can create its related features. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_create_entity_type_monitoring_sample] + +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.aiplatform.v1.CreateEntityTypeOperationMetadata; +import com.google.cloud.aiplatform.v1.CreateEntityTypeRequest; +import com.google.cloud.aiplatform.v1.EntityType; +import com.google.cloud.aiplatform.v1.FeaturestoreMonitoringConfig; +import com.google.cloud.aiplatform.v1.FeaturestoreMonitoringConfig.SnapshotAnalysis; +import com.google.cloud.aiplatform.v1.FeaturestoreName; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class CreateEntityTypeMonitoringSample { + + public static void main(String[] args) + throws IOException, InterruptedException, ExecutionException, TimeoutException { + // TODO(developer): Replace these variables before running the sample. + String project = "YOUR_PROJECT_ID"; + String featurestoreId = "YOUR_FEATURESTORE_ID"; + String entityTypeId = "YOUR_ENTITY_TYPE_ID"; + String description = "YOUR_ENTITY_TYPE_DESCRIPTION"; + int monitoringIntervalDays = 1; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + int timeout = 300; + createEntityTypeMonitoringSample(project, featurestoreId, entityTypeId, description, + monitoringIntervalDays, location, endpoint, timeout); + } + + static void createEntityTypeMonitoringSample(String project, String featurestoreId, + String entityTypeId, String description, int monitoringIntervalDays, String location, + String endpoint, int timeout) + throws IOException, InterruptedException, ExecutionException, TimeoutException { + + FeaturestoreServiceSettings featurestoreServiceSettings = + FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).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 (FeaturestoreServiceClient featurestoreServiceClient = + FeaturestoreServiceClient.create(featurestoreServiceSettings)) { + + FeaturestoreMonitoringConfig featurestoreMonitoringConfig = + FeaturestoreMonitoringConfig.newBuilder() + .setSnapshotAnalysis( + SnapshotAnalysis.newBuilder().setMonitoringIntervalDays(monitoringIntervalDays)) + .build(); + + EntityType entityType = EntityType.newBuilder().setDescription(description) + .setMonitoringConfig(featurestoreMonitoringConfig).build(); + + CreateEntityTypeRequest createEntityTypeRequest = CreateEntityTypeRequest.newBuilder() + .setParent(FeaturestoreName.of(project, location, featurestoreId).toString()) + .setEntityType(entityType).setEntityTypeId(entityTypeId).build(); + + OperationFuture entityTypeFuture = + featurestoreServiceClient.createEntityTypeAsync(createEntityTypeRequest); + System.out.format("Operation name: %s%n", + entityTypeFuture.getInitialFuture().get().getName()); + System.out.println("Waiting for operation to finish..."); + EntityType entityTypeResponse = entityTypeFuture.get(timeout, TimeUnit.SECONDS); + System.out.println("Create Entity Type Monitoring Response"); + System.out.format("Name: %s%n", entityTypeResponse.getName()); + } + } +} +// [END aiplatform_create_entity_type_monitoring_sample] \ No newline at end of file diff --git a/samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java b/samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java new file mode 100644 index 000000000..048841167 --- /dev/null +++ b/samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java @@ -0,0 +1,84 @@ +/* + * Copyright 2022 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. + * + * + * Create an entity type so that you can create its related features. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_create_entity_type_sample] + +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.aiplatform.v1.CreateEntityTypeOperationMetadata; +import com.google.cloud.aiplatform.v1.CreateEntityTypeRequest; +import com.google.cloud.aiplatform.v1.EntityType; +import com.google.cloud.aiplatform.v1.FeaturestoreName; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class CreateEntityTypeSample { + + public static void main(String[] args) + throws IOException, InterruptedException, ExecutionException, TimeoutException { + // TODO(developer): Replace these variables before running the sample. + String project = "YOUR_PROJECT_ID"; + String featurestoreId = "YOUR_FEATURESTORE_ID"; + String entityTypeId = "YOUR_ENTITY_TYPE_ID"; + String description = "YOUR_ENTITY_TYPE_DESCRIPTION"; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + int timeout = 300; + createEntityTypeSample(project, featurestoreId, entityTypeId, description, location, endpoint, + timeout); + } + + static void createEntityTypeSample(String project, String featurestoreId, String entityTypeId, + String description, String location, String endpoint, int timeout) + throws IOException, InterruptedException, ExecutionException, TimeoutException { + + FeaturestoreServiceSettings featurestoreServiceSettings = + FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).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 (FeaturestoreServiceClient featurestoreServiceClient = + FeaturestoreServiceClient.create(featurestoreServiceSettings)) { + + EntityType entityType = EntityType.newBuilder().setDescription(description).build(); + + CreateEntityTypeRequest createEntityTypeRequest = CreateEntityTypeRequest.newBuilder() + .setParent(FeaturestoreName.of(project, location, featurestoreId).toString()) + .setEntityType(entityType).setEntityTypeId(entityTypeId).build(); + + OperationFuture entityTypeFuture = + featurestoreServiceClient.createEntityTypeAsync(createEntityTypeRequest); + System.out.format("Operation name: %s%n", + entityTypeFuture.getInitialFuture().get().getName()); + System.out.println("Waiting for operation to finish..."); + EntityType entityTypeResponse = entityTypeFuture.get(timeout, TimeUnit.SECONDS); + System.out.println("Create Entity Type Response"); + System.out.format("Name: %s%n", entityTypeResponse.getName()); + } + } +} +// [END aiplatform_create_entity_type_sample] \ No newline at end of file diff --git a/samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java b/samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java new file mode 100644 index 000000000..ac53f083c --- /dev/null +++ b/samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java @@ -0,0 +1,79 @@ +/* + * Copyright 2022 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. + * + * + * Delete an entity type from featurestore resource. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_delete_entity_type_sample] + +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.aiplatform.v1.DeleteEntityTypeRequest; +import com.google.cloud.aiplatform.v1.DeleteOperationMetadata; +import com.google.cloud.aiplatform.v1.EntityTypeName; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import com.google.protobuf.Empty; +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class DeleteEntityTypeSample { + + public static void main(String[] args) + throws IOException, InterruptedException, ExecutionException, TimeoutException { + // TODO(developer): Replace these variables before running the sample. + String project = "YOUR_PROJECT_ID"; + String featurestoreId = "YOUR_FEATURESTORE_ID"; + String entityTypeId = "YOUR_ENTITY_TYPE_ID"; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + int timeout = 300; + deleteEntityTypeSample(project, featurestoreId, entityTypeId, location, endpoint, timeout); + } + + static void deleteEntityTypeSample(String project, String featurestoreId, String entityTypeId, + String location, String endpoint, int timeout) + throws IOException, InterruptedException, ExecutionException, TimeoutException { + + FeaturestoreServiceSettings featurestoreServiceSettings = + FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).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 (FeaturestoreServiceClient featurestoreServiceClient = + FeaturestoreServiceClient.create(featurestoreServiceSettings)) { + + DeleteEntityTypeRequest deleteEntityTypeRequest = DeleteEntityTypeRequest.newBuilder() + .setName(EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) + .setForce(true).build(); + + OperationFuture operationFuture = + featurestoreServiceClient.deleteEntityTypeAsync(deleteEntityTypeRequest); + System.out.format("Operation name: %s%n", operationFuture.getInitialFuture().get().getName()); + System.out.println("Waiting for operation to finish..."); + operationFuture.get(timeout, TimeUnit.SECONDS); + + System.out.format("Deleted Entity Type."); + } + } +} +// [END aiplatform_delete_entity_type_sample] \ No newline at end of file diff --git a/samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.java b/samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.java new file mode 100644 index 000000000..55b18637c --- /dev/null +++ b/samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.java @@ -0,0 +1,67 @@ +/* + * Copyright 2022 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. + * + * + * Get entity type details. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_get_entity_type_sample] + +import com.google.cloud.aiplatform.v1.EntityType; +import com.google.cloud.aiplatform.v1.EntityTypeName; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import com.google.cloud.aiplatform.v1.GetEntityTypeRequest; +import java.io.IOException; + +public class GetEntityTypeSample { + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String project = "YOUR_PROJECT_ID"; + String featurestoreId = "YOUR_FEATURESTORE_ID"; + String entityTypeId = "YOUR_ENTITY_TYPE_ID"; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + getEntityTypeSample(project, featurestoreId, entityTypeId, location, endpoint); + } + + static void getEntityTypeSample(String project, String featurestoreId, String entityTypeId, + String location, String endpoint) throws IOException { + + FeaturestoreServiceSettings featurestoreServiceSettings = + FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).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 (FeaturestoreServiceClient featurestoreServiceClient = + FeaturestoreServiceClient.create(featurestoreServiceSettings)) { + + GetEntityTypeRequest getEntityTypeRequest = GetEntityTypeRequest.newBuilder() + .setName(EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) + .build(); + + EntityType entityType = featurestoreServiceClient.getEntityType(getEntityTypeRequest); + System.out.println("Get Entity Type Response"); + System.out.println(entityType); + } + } +} +// [END aiplatform_get_entity_type_sample] \ No newline at end of file diff --git a/samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java b/samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java new file mode 100644 index 000000000..1a750372c --- /dev/null +++ b/samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java @@ -0,0 +1,78 @@ +/* + * Copyright 2022 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. + * + * + * List available entity type details of an existing featurestore resource. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_list_entity_types_async_sample] + +import com.google.cloud.aiplatform.v1.EntityType; +import com.google.cloud.aiplatform.v1.FeaturestoreName; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import com.google.cloud.aiplatform.v1.ListEntityTypesRequest; +import com.google.cloud.aiplatform.v1.ListEntityTypesResponse; +import com.google.common.base.Strings; +import java.io.IOException; + +public class ListEntityTypesAsyncSample { + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String project = "YOUR_PROJECT_ID"; + String featurestoreId = "YOUR_FEATURESTORE_ID"; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + listEntityTypesAsyncSample(project, featurestoreId, location, endpoint); + } + + static void listEntityTypesAsyncSample(String project, String featurestoreId, String location, + String endpoint) throws IOException { + + FeaturestoreServiceSettings featurestoreServiceSettings = + FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).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 (FeaturestoreServiceClient featurestoreServiceClient = + FeaturestoreServiceClient.create(featurestoreServiceSettings)) { + + ListEntityTypesRequest listEntityTypeRequest = ListEntityTypesRequest.newBuilder() + .setParent(FeaturestoreName.of(project, location, featurestoreId).toString()).build(); + System.out.println("List Entity Types Async Response"); + while (true) { + ListEntityTypesResponse listEntityTypesResponse = + featurestoreServiceClient.listEntityTypesCallable().call(listEntityTypeRequest); + for (EntityType element : listEntityTypesResponse.getEntityTypesList()) { + System.out.println(element); + } + String nextPageToken = listEntityTypesResponse.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + listEntityTypeRequest = + listEntityTypeRequest.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END aiplatform_list_entity_types_async_sample] \ No newline at end of file diff --git a/samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java b/samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java new file mode 100644 index 000000000..f4fd062b8 --- /dev/null +++ b/samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java @@ -0,0 +1,66 @@ +/* + * Copyright 2022 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. + * + * + * List available entity type details of an existing featurestore resource. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_list_entity_types_sample] + +import com.google.cloud.aiplatform.v1.EntityType; +import com.google.cloud.aiplatform.v1.FeaturestoreName; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import com.google.cloud.aiplatform.v1.ListEntityTypesRequest; +import java.io.IOException; + +public class ListEntityTypesSample { + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String project = "YOUR_PROJECT_ID"; + String featurestoreId = "YOUR_FEATURESTORE_ID"; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + listEntityTypesSample(project, featurestoreId, location, endpoint); + } + + static void listEntityTypesSample(String project, String featurestoreId, String location, + String endpoint) throws IOException { + + FeaturestoreServiceSettings featurestoreServiceSettings = + FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).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 (FeaturestoreServiceClient featurestoreServiceClient = + FeaturestoreServiceClient.create(featurestoreServiceSettings)) { + + ListEntityTypesRequest listEntityTypeRequest = ListEntityTypesRequest.newBuilder() + .setParent(FeaturestoreName.of(project, location, featurestoreId).toString()).build(); + System.out.println("List Entity Types Response"); + for (EntityType element : featurestoreServiceClient.listEntityTypes(listEntityTypeRequest) + .iterateAll()) { + System.out.println(element); + } + } + } +} +// [END aiplatform_list_entity_types_sample] \ No newline at end of file diff --git a/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java b/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java new file mode 100644 index 000000000..8a843db90 --- /dev/null +++ b/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java @@ -0,0 +1,79 @@ +/* + * Copyright 2022 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. + * + * + * Update entity type. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_update_entity_type_monitoring_sample] + +import com.google.cloud.aiplatform.v1.EntityType; +import com.google.cloud.aiplatform.v1.EntityTypeName; +import com.google.cloud.aiplatform.v1.FeaturestoreMonitoringConfig; +import com.google.cloud.aiplatform.v1.FeaturestoreMonitoringConfig.SnapshotAnalysis; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import com.google.cloud.aiplatform.v1.UpdateEntityTypeRequest; +import java.io.IOException; + +public class UpdateEntityTypeMonitoringSample { + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String project = "YOUR_PROJECT_ID"; + String featurestoreId = "YOUR_FEATURESTORE_ID"; + String entityTypeId = "YOUR_ENTITY_TYPE_ID"; + int monitoringIntervalDays = 1; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + updateEntityTypeMonitoringSample(project, featurestoreId, entityTypeId, monitoringIntervalDays, + location, endpoint); + } + + static void updateEntityTypeMonitoringSample(String project, String featurestoreId, + String entityTypeId, int monitoringIntervalDays, String location, String endpoint) + throws IOException { + + FeaturestoreServiceSettings featurestoreServiceSettings = + FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).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 (FeaturestoreServiceClient featurestoreServiceClient = + FeaturestoreServiceClient.create(featurestoreServiceSettings)) { + FeaturestoreMonitoringConfig featurestoreMonitoringConfig = + FeaturestoreMonitoringConfig.newBuilder() + .setSnapshotAnalysis( + SnapshotAnalysis.newBuilder().setMonitoringIntervalDays(monitoringIntervalDays)) + .build(); + EntityType entityType = EntityType.newBuilder() + .setName(EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) + .setMonitoringConfig(featurestoreMonitoringConfig).build(); + + UpdateEntityTypeRequest updateEntityTypeRequest = + UpdateEntityTypeRequest.newBuilder().setEntityType(entityType).build(); + EntityType entityTypeResponse = + featurestoreServiceClient.updateEntityType(updateEntityTypeRequest); + System.out.println("Update Entity Type Monitoring Response"); + System.out.println(entityTypeResponse); + } + } +} +// [END aiplatform_update_entity_type_monitoring_sample] \ No newline at end of file diff --git a/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java b/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java new file mode 100644 index 000000000..4091c0012 --- /dev/null +++ b/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java @@ -0,0 +1,71 @@ +/* + * Copyright 2022 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. + * + * + * Update entity type. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_update_entity_type_sample] + +import com.google.cloud.aiplatform.v1.EntityType; +import com.google.cloud.aiplatform.v1.EntityTypeName; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import com.google.cloud.aiplatform.v1.UpdateEntityTypeRequest; +import java.io.IOException; + +public class UpdateEntityTypeSample { + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String project = "YOUR_PROJECT_ID"; + String featurestoreId = "YOUR_FEATURESTORE_ID"; + String entityTypeId = "YOUR_ENTITY_TYPE_ID"; + String description = "Update Description"; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + updateEntityTypeSample(project, featurestoreId, entityTypeId, description, location, endpoint); + } + + static void updateEntityTypeSample(String project, String featurestoreId, String entityTypeId, + String description, String location, String endpoint) throws IOException { + + FeaturestoreServiceSettings featurestoreServiceSettings = + FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).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 (FeaturestoreServiceClient featurestoreServiceClient = + FeaturestoreServiceClient.create(featurestoreServiceSettings)) { + + EntityType entityType = EntityType.newBuilder() + .setName(EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) + .setDescription(description).build(); + + UpdateEntityTypeRequest updateEntityTypeRequest = + UpdateEntityTypeRequest.newBuilder().setEntityType(entityType).build(); + EntityType entityTypeResponse = + featurestoreServiceClient.updateEntityType(updateEntityTypeRequest); + System.out.println("Update Entity Type Response"); + System.out.println(entityTypeResponse); + } + } +} +// [END aiplatform_update_entity_type_sample] \ No newline at end of file diff --git a/samples/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java b/samples/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java new file mode 100644 index 000000000..867d4199d --- /dev/null +++ b/samples/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java @@ -0,0 +1,175 @@ +/* + * Copyright 2022 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 aiplatform; + +import static com.google.common.truth.Truth.assertThat; +import static junit.framework.TestCase.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class EntityTypeSamplesTest { + + private static final String PROJECT_ID = System.getenv("UCAIP_PROJECT_ID"); + private static final int MIN_NODE_COUNT = 1; + private static final int MAX_NODE_COUNT = 5; + private static final String DESCRIPTION = "Test Description"; + private static final int MONITORING_INTERVAL_DAYS = 1; + private static final boolean USE_FORCE = true; + private static final String LOCATION = "us-central1"; + private static final String ENDPOINT = "us-central1-aiplatform.googleapis.com:443"; + private static final int TIMEOUT = 900; + private ByteArrayOutputStream bout; + private PrintStream out; + private PrintStream originalPrintStream; + private String featurestoreId; + + private static void requireEnvVar(String varName) { + String errorMessage = + String.format("Environment variable '%s' is required to perform these tests.", varName); + assertNotNull(errorMessage, System.getenv(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnvVar("UCAIP_PROJECT_ID"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + originalPrintStream = System.out; + System.setOut(out); + } + + @After + public void tearDown() + throws InterruptedException, ExecutionException, IOException, TimeoutException { + + // Delete the featurestore + DeleteFeaturestoreSample.deleteFeaturestoreSample(PROJECT_ID, featurestoreId, USE_FORCE, + LOCATION, ENDPOINT, 60); + + // Assert + String deleteFeaturestoreResponse = bout.toString(); + assertThat(deleteFeaturestoreResponse).contains("Deleted Featurestore"); + System.out.flush(); + System.setOut(originalPrintStream); + } + + @Test + public void testEntityTypeSamples() + throws IOException, InterruptedException, ExecutionException, TimeoutException { + // Create the featurestore + String tempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 26); + String id = String.format("temp_create_featurestore_test_%s", tempUuid); + CreateFeaturestoreSample.createFeaturestoreSample(PROJECT_ID, id, MIN_NODE_COUNT, + MAX_NODE_COUNT, LOCATION, ENDPOINT, TIMEOUT); + + // Assert + String createFeaturestoreResponse = bout.toString(); + assertThat(createFeaturestoreResponse).contains("Create Featurestore Response"); + featurestoreId = + createFeaturestoreResponse.split("Name: ")[1].split("featurestores/")[1].split("\n")[0] + .trim(); + + // Create the entity type + String entityTypeTempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 16); + String entityTypeId = String.format("temp_create_entity_type_test_%s", entityTypeTempUuid); + CreateEntityTypeSample.createEntityTypeSample(PROJECT_ID, featurestoreId, entityTypeId, + DESCRIPTION, LOCATION, ENDPOINT, TIMEOUT); + + // Assert + String createEntityTypeResponse = bout.toString(); + assertThat(createEntityTypeResponse).contains("Create Entity Type Response"); + + // Get the entity type + GetEntityTypeSample.getEntityTypeSample(PROJECT_ID, featurestoreId, entityTypeId, LOCATION, + ENDPOINT); + + // Assert + String getEntityTypeResponse = bout.toString(); + assertThat(getEntityTypeResponse).contains("Get Entity Type Response"); + + // Create the entity type + String entityTypeMonitoringTempUuid = + UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 16); + String entityTypeMonitoringId = + String.format("temp_create_entity_type_test_%s", entityTypeMonitoringTempUuid); + CreateEntityTypeMonitoringSample.createEntityTypeMonitoringSample(PROJECT_ID, featurestoreId, + entityTypeMonitoringId, DESCRIPTION, MONITORING_INTERVAL_DAYS, LOCATION, ENDPOINT, TIMEOUT); + + // Assert + String createEntityTypeMonitoringResponse = bout.toString(); + assertThat(createEntityTypeMonitoringResponse) + .contains("Create Entity Type Monitoring Response"); + + // List entity types + ListEntityTypesSample.listEntityTypesSample(PROJECT_ID, featurestoreId, LOCATION, ENDPOINT); + + // Assert + String listEntityTypeResponse = bout.toString(); + assertThat(listEntityTypeResponse).contains("List Entity Types Response"); + + // Update the entity type + UpdateEntityTypeSample.updateEntityTypeSample(PROJECT_ID, featurestoreId, entityTypeId, + DESCRIPTION, LOCATION, ENDPOINT); + + // Assert + String updateEntityTypeResponse = bout.toString(); + assertThat(updateEntityTypeResponse).contains("Update Entity Type Response"); + + // Update the entity type + UpdateEntityTypeMonitoringSample.updateEntityTypeMonitoringSample(PROJECT_ID, featurestoreId, + entityTypeId, MONITORING_INTERVAL_DAYS, LOCATION, ENDPOINT); + + // Assert + String updateEntityTypeMonitoringResponse = bout.toString(); + assertThat(updateEntityTypeMonitoringResponse) + .contains("Update Entity Type Monitoring Response"); + + // List entity types + ListEntityTypesAsyncSample.listEntityTypesAsyncSample(PROJECT_ID, featurestoreId, LOCATION, + ENDPOINT); + + // Assert + String listEntityTypeAsyncResponse = bout.toString(); + assertThat(listEntityTypeAsyncResponse).contains("List Entity Types Async Response"); + + // Delete the entity type + DeleteEntityTypeSample.deleteEntityTypeSample(PROJECT_ID, featurestoreId, entityTypeId, + LOCATION, ENDPOINT, TIMEOUT); + + // Assert + String deleteEntityTypeResponse = bout.toString(); + assertThat(deleteEntityTypeResponse).contains("Deleted Entity Type"); + + } +} From a6de671ec496a9a64bf7841be1e08699f6fceed7 Mon Sep 17 00:00:00 2001 From: sai-chaithu Date: Tue, 28 Jun 2022 14:35:26 +0530 Subject: [PATCH 2/3] feat(samples): update all entity type samples --- .../main/java/aiplatform/CreateEntityTypeMonitoringSample.java | 3 ++- .../src/main/java/aiplatform/CreateEntityTypeSample.java | 3 ++- .../src/main/java/aiplatform/DeleteEntityTypeSample.java | 3 ++- .../snippets/src/main/java/aiplatform/GetEntityTypeSample.java | 3 ++- .../src/main/java/aiplatform/ListEntityTypesAsyncSample.java | 3 ++- .../src/main/java/aiplatform/ListEntityTypesSample.java | 3 ++- .../main/java/aiplatform/UpdateEntityTypeMonitoringSample.java | 3 ++- .../src/main/java/aiplatform/UpdateEntityTypeSample.java | 3 ++- .../src/test/java/aiplatform/EntityTypeSamplesTest.java | 1 + 9 files changed, 17 insertions(+), 8 deletions(-) diff --git a/samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java b/samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java index eddc74e4c..625ebdcdb 100644 --- a/samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java +++ b/samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java @@ -92,4 +92,5 @@ static void createEntityTypeMonitoringSample(String project, String featurestore } } } -// [END aiplatform_create_entity_type_monitoring_sample] \ No newline at end of file +// [END aiplatform_create_entity_type_monitoring_sample] + diff --git a/samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java b/samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java index 048841167..795ffc6fe 100644 --- a/samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java +++ b/samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java @@ -81,4 +81,5 @@ static void createEntityTypeSample(String project, String featurestoreId, String } } } -// [END aiplatform_create_entity_type_sample] \ No newline at end of file +// [END aiplatform_create_entity_type_sample] + diff --git a/samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java b/samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java index ac53f083c..e78729a69 100644 --- a/samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java +++ b/samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java @@ -76,4 +76,5 @@ static void deleteEntityTypeSample(String project, String featurestoreId, String } } } -// [END aiplatform_delete_entity_type_sample] \ No newline at end of file +// [END aiplatform_delete_entity_type_sample] + diff --git a/samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.java b/samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.java index 55b18637c..ace468152 100644 --- a/samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.java +++ b/samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.java @@ -64,4 +64,5 @@ static void getEntityTypeSample(String project, String featurestoreId, String en } } } -// [END aiplatform_get_entity_type_sample] \ No newline at end of file +// [END aiplatform_get_entity_type_sample] + diff --git a/samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java b/samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java index 1a750372c..45039fb5b 100644 --- a/samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java +++ b/samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java @@ -75,4 +75,5 @@ static void listEntityTypesAsyncSample(String project, String featurestoreId, St } } } -// [END aiplatform_list_entity_types_async_sample] \ No newline at end of file +// [END aiplatform_list_entity_types_async_sample] + diff --git a/samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java b/samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java index f4fd062b8..92ada6fe2 100644 --- a/samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java +++ b/samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java @@ -63,4 +63,5 @@ static void listEntityTypesSample(String project, String featurestoreId, String } } } -// [END aiplatform_list_entity_types_sample] \ No newline at end of file +// [END aiplatform_list_entity_types_sample] + diff --git a/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java b/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java index 8a843db90..d97862536 100644 --- a/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java +++ b/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java @@ -76,4 +76,5 @@ static void updateEntityTypeMonitoringSample(String project, String featurestore } } } -// [END aiplatform_update_entity_type_monitoring_sample] \ No newline at end of file +// [END aiplatform_update_entity_type_monitoring_sample] + diff --git a/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java b/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java index 4091c0012..ca10632ad 100644 --- a/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java +++ b/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java @@ -68,4 +68,5 @@ static void updateEntityTypeSample(String project, String featurestoreId, String } } } -// [END aiplatform_update_entity_type_sample] \ No newline at end of file +// [END aiplatform_update_entity_type_sample] + diff --git a/samples/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java b/samples/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java index 867d4199d..5a86fb006 100644 --- a/samples/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java +++ b/samples/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java @@ -173,3 +173,4 @@ public void testEntityTypeSamples() } } + From 7e63941d9a9b6b11b6d437eceab79248a92ea0ac Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 28 Jun 2022 11:46:32 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 8 ++++ .../CreateEntityTypeMonitoringSample.java | 46 +++++++++++++------ .../aiplatform/CreateEntityTypeSample.java | 30 +++++++----- .../aiplatform/DeleteEntityTypeSample.java | 21 ++++++--- .../java/aiplatform/GetEntityTypeSample.java | 18 ++++---- .../ListEntityTypesAsyncSample.java | 11 +++-- .../aiplatform/ListEntityTypesSample.java | 15 +++--- .../UpdateEntityTypeMonitoringSample.java | 25 ++++++---- .../aiplatform/UpdateEntityTypeSample.java | 22 ++++++--- .../aiplatform/EntityTypeSamplesTest.java | 45 ++++++++++-------- 10 files changed, 153 insertions(+), 88 deletions(-) diff --git a/README.md b/README.md index a3059d27e..f0d29d00b 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,8 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-aiplatform/tr | Create Dataset Text Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CreateDatasetTextSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CreateDatasetTextSample.java) | | Create Dataset Video Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CreateDatasetVideoSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CreateDatasetVideoSample.java) | | Create Endpoint Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CreateEndpointSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CreateEndpointSample.java) | +| Create Entity Type Monitoring Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java) | +| Create Entity Type Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java) | | Create Featurestore Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CreateFeaturestoreSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CreateFeaturestoreSample.java) | | Create Hyperparameter Tuning Job Python Package Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CreateHyperparameterTuningJobPythonPackageSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CreateHyperparameterTuningJobPythonPackageSample.java) | | Create Hyperparameter Tuning Job Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CreateHyperparameterTuningJobSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CreateHyperparameterTuningJobSample.java) | @@ -138,6 +140,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-aiplatform/tr | Delete Data Labeling Job Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeleteDataLabelingJobSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/DeleteDataLabelingJobSample.java) | | Delete Dataset Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeleteDatasetSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/DeleteDatasetSample.java) | | Delete Endpoint Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeleteEndpointSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/DeleteEndpointSample.java) | +| Delete Entity Type Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java) | | Delete Export Model Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeleteExportModelSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/DeleteExportModelSample.java) | | Delete Featurestore Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeleteFeaturestoreSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/DeleteFeaturestoreSample.java) | | Delete Model Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeleteModelSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/DeleteModelSample.java) | @@ -148,6 +151,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-aiplatform/tr | Export Model Tabular Classification Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ExportModelTabularClassificationSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ExportModelTabularClassificationSample.java) | | Export Model Video Action Recognition Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ExportModelVideoActionRecognitionSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ExportModelVideoActionRecognitionSample.java) | | Get Batch Prediction Job Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/GetBatchPredictionJobSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/GetBatchPredictionJobSample.java) | +| Get Entity Type Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.java) | | Get Hyperparameter Tuning Job Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/GetHyperparameterTuningJobSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/GetHyperparameterTuningJobSample.java) | | Get Model Evaluation Image Classification Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/GetModelEvaluationImageClassificationSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/GetModelEvaluationImageClassificationSample.java) | | Get Model Evaluation Image Object Detection Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/GetModelEvaluationImageObjectDetectionSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/GetModelEvaluationImageObjectDetectionSample.java) | @@ -171,6 +175,8 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-aiplatform/tr | Import Data Video Action Recognition Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ImportDataVideoActionRecognitionSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ImportDataVideoActionRecognitionSample.java) | | Import Data Video Classification Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ImportDataVideoClassificationSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ImportDataVideoClassificationSample.java) | | Import Data Video Object Tracking Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ImportDataVideoObjectTrackingSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ImportDataVideoObjectTrackingSample.java) | +| List Entity Types Async Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java) | +| List Entity Types Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java) | | List Model Evaluation Slice Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ListModelEvaluationSliceSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ListModelEvaluationSliceSample.java) | | Predict Custom Trained Model Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/PredictCustomTrainedModelSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/PredictCustomTrainedModelSample.java) | | Predict Image Classification Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/PredictImageClassificationSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/PredictImageClassificationSample.java) | @@ -181,6 +187,8 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-aiplatform/tr | Predict Text Entity Extraction Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/PredictTextEntityExtractionSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/PredictTextEntityExtractionSample.java) | | Predict Text Sentiment Analysis Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/PredictTextSentimentAnalysisSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/PredictTextSentimentAnalysisSample.java) | | Undeploy Model Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/UndeployModelSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/UndeployModelSample.java) | +| Update Entity Type Monitoring Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java) | +| Update Entity Type Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java) | | Upload Model Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/UploadModelSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/UploadModelSample.java) | diff --git a/samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java b/samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java index 625ebdcdb..b234d0324 100644 --- a/samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java +++ b/samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java @@ -15,7 +15,7 @@ * * * Create an entity type so that you can create its related features. See - * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running * the code snippet */ @@ -50,13 +50,26 @@ public static void main(String[] args) String location = "us-central1"; String endpoint = "us-central1-aiplatform.googleapis.com:443"; int timeout = 300; - createEntityTypeMonitoringSample(project, featurestoreId, entityTypeId, description, - monitoringIntervalDays, location, endpoint, timeout); + createEntityTypeMonitoringSample( + project, + featurestoreId, + entityTypeId, + description, + monitoringIntervalDays, + location, + endpoint, + timeout); } - static void createEntityTypeMonitoringSample(String project, String featurestoreId, - String entityTypeId, String description, int monitoringIntervalDays, String location, - String endpoint, int timeout) + static void createEntityTypeMonitoringSample( + String project, + String featurestoreId, + String entityTypeId, + String description, + int monitoringIntervalDays, + String location, + String endpoint, + int timeout) throws IOException, InterruptedException, ExecutionException, TimeoutException { FeaturestoreServiceSettings featurestoreServiceSettings = @@ -74,17 +87,23 @@ static void createEntityTypeMonitoringSample(String project, String featurestore SnapshotAnalysis.newBuilder().setMonitoringIntervalDays(monitoringIntervalDays)) .build(); - EntityType entityType = EntityType.newBuilder().setDescription(description) - .setMonitoringConfig(featurestoreMonitoringConfig).build(); + EntityType entityType = + EntityType.newBuilder() + .setDescription(description) + .setMonitoringConfig(featurestoreMonitoringConfig) + .build(); - CreateEntityTypeRequest createEntityTypeRequest = CreateEntityTypeRequest.newBuilder() - .setParent(FeaturestoreName.of(project, location, featurestoreId).toString()) - .setEntityType(entityType).setEntityTypeId(entityTypeId).build(); + CreateEntityTypeRequest createEntityTypeRequest = + CreateEntityTypeRequest.newBuilder() + .setParent(FeaturestoreName.of(project, location, featurestoreId).toString()) + .setEntityType(entityType) + .setEntityTypeId(entityTypeId) + .build(); OperationFuture entityTypeFuture = featurestoreServiceClient.createEntityTypeAsync(createEntityTypeRequest); - System.out.format("Operation name: %s%n", - entityTypeFuture.getInitialFuture().get().getName()); + System.out.format( + "Operation name: %s%n", entityTypeFuture.getInitialFuture().get().getName()); System.out.println("Waiting for operation to finish..."); EntityType entityTypeResponse = entityTypeFuture.get(timeout, TimeUnit.SECONDS); System.out.println("Create Entity Type Monitoring Response"); @@ -93,4 +112,3 @@ static void createEntityTypeMonitoringSample(String project, String featurestore } } // [END aiplatform_create_entity_type_monitoring_sample] - diff --git a/samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java b/samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java index 795ffc6fe..012ac1961 100644 --- a/samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java +++ b/samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java @@ -15,7 +15,7 @@ * * * Create an entity type so that you can create its related features. See - * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running * the code snippet */ @@ -47,12 +47,18 @@ public static void main(String[] args) String location = "us-central1"; String endpoint = "us-central1-aiplatform.googleapis.com:443"; int timeout = 300; - createEntityTypeSample(project, featurestoreId, entityTypeId, description, location, endpoint, - timeout); + createEntityTypeSample( + project, featurestoreId, entityTypeId, description, location, endpoint, timeout); } - static void createEntityTypeSample(String project, String featurestoreId, String entityTypeId, - String description, String location, String endpoint, int timeout) + static void createEntityTypeSample( + String project, + String featurestoreId, + String entityTypeId, + String description, + String location, + String endpoint, + int timeout) throws IOException, InterruptedException, ExecutionException, TimeoutException { FeaturestoreServiceSettings featurestoreServiceSettings = @@ -66,14 +72,17 @@ static void createEntityTypeSample(String project, String featurestoreId, String EntityType entityType = EntityType.newBuilder().setDescription(description).build(); - CreateEntityTypeRequest createEntityTypeRequest = CreateEntityTypeRequest.newBuilder() - .setParent(FeaturestoreName.of(project, location, featurestoreId).toString()) - .setEntityType(entityType).setEntityTypeId(entityTypeId).build(); + CreateEntityTypeRequest createEntityTypeRequest = + CreateEntityTypeRequest.newBuilder() + .setParent(FeaturestoreName.of(project, location, featurestoreId).toString()) + .setEntityType(entityType) + .setEntityTypeId(entityTypeId) + .build(); OperationFuture entityTypeFuture = featurestoreServiceClient.createEntityTypeAsync(createEntityTypeRequest); - System.out.format("Operation name: %s%n", - entityTypeFuture.getInitialFuture().get().getName()); + System.out.format( + "Operation name: %s%n", entityTypeFuture.getInitialFuture().get().getName()); System.out.println("Waiting for operation to finish..."); EntityType entityTypeResponse = entityTypeFuture.get(timeout, TimeUnit.SECONDS); System.out.println("Create Entity Type Response"); @@ -82,4 +91,3 @@ static void createEntityTypeSample(String project, String featurestoreId, String } } // [END aiplatform_create_entity_type_sample] - diff --git a/samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java b/samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java index e78729a69..00e7c5e36 100644 --- a/samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java +++ b/samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java @@ -15,7 +15,7 @@ * * * Delete an entity type from featurestore resource. See - * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running * the code snippet */ @@ -49,8 +49,13 @@ public static void main(String[] args) deleteEntityTypeSample(project, featurestoreId, entityTypeId, location, endpoint, timeout); } - static void deleteEntityTypeSample(String project, String featurestoreId, String entityTypeId, - String location, String endpoint, int timeout) + static void deleteEntityTypeSample( + String project, + String featurestoreId, + String entityTypeId, + String location, + String endpoint, + int timeout) throws IOException, InterruptedException, ExecutionException, TimeoutException { FeaturestoreServiceSettings featurestoreServiceSettings = @@ -62,9 +67,12 @@ static void deleteEntityTypeSample(String project, String featurestoreId, String try (FeaturestoreServiceClient featurestoreServiceClient = FeaturestoreServiceClient.create(featurestoreServiceSettings)) { - DeleteEntityTypeRequest deleteEntityTypeRequest = DeleteEntityTypeRequest.newBuilder() - .setName(EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) - .setForce(true).build(); + DeleteEntityTypeRequest deleteEntityTypeRequest = + DeleteEntityTypeRequest.newBuilder() + .setName( + EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) + .setForce(true) + .build(); OperationFuture operationFuture = featurestoreServiceClient.deleteEntityTypeAsync(deleteEntityTypeRequest); @@ -77,4 +85,3 @@ static void deleteEntityTypeSample(String project, String featurestoreId, String } } // [END aiplatform_delete_entity_type_sample] - diff --git a/samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.java b/samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.java index ace468152..f9e83f223 100644 --- a/samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.java +++ b/samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.java @@ -14,8 +14,8 @@ * limitations under the License. * * - * Get entity type details. See - * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * Get entity type details. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running * the code snippet */ @@ -42,8 +42,9 @@ public static void main(String[] args) throws IOException { getEntityTypeSample(project, featurestoreId, entityTypeId, location, endpoint); } - static void getEntityTypeSample(String project, String featurestoreId, String entityTypeId, - String location, String endpoint) throws IOException { + static void getEntityTypeSample( + String project, String featurestoreId, String entityTypeId, String location, String endpoint) + throws IOException { FeaturestoreServiceSettings featurestoreServiceSettings = FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); @@ -54,9 +55,11 @@ static void getEntityTypeSample(String project, String featurestoreId, String en try (FeaturestoreServiceClient featurestoreServiceClient = FeaturestoreServiceClient.create(featurestoreServiceSettings)) { - GetEntityTypeRequest getEntityTypeRequest = GetEntityTypeRequest.newBuilder() - .setName(EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) - .build(); + GetEntityTypeRequest getEntityTypeRequest = + GetEntityTypeRequest.newBuilder() + .setName( + EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) + .build(); EntityType entityType = featurestoreServiceClient.getEntityType(getEntityTypeRequest); System.out.println("Get Entity Type Response"); @@ -65,4 +68,3 @@ static void getEntityTypeSample(String project, String featurestoreId, String en } } // [END aiplatform_get_entity_type_sample] - diff --git a/samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java b/samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java index 45039fb5b..b429a642c 100644 --- a/samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java +++ b/samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java @@ -43,8 +43,8 @@ public static void main(String[] args) throws IOException { listEntityTypesAsyncSample(project, featurestoreId, location, endpoint); } - static void listEntityTypesAsyncSample(String project, String featurestoreId, String location, - String endpoint) throws IOException { + static void listEntityTypesAsyncSample( + String project, String featurestoreId, String location, String endpoint) throws IOException { FeaturestoreServiceSettings featurestoreServiceSettings = FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); @@ -55,8 +55,10 @@ static void listEntityTypesAsyncSample(String project, String featurestoreId, St try (FeaturestoreServiceClient featurestoreServiceClient = FeaturestoreServiceClient.create(featurestoreServiceSettings)) { - ListEntityTypesRequest listEntityTypeRequest = ListEntityTypesRequest.newBuilder() - .setParent(FeaturestoreName.of(project, location, featurestoreId).toString()).build(); + ListEntityTypesRequest listEntityTypeRequest = + ListEntityTypesRequest.newBuilder() + .setParent(FeaturestoreName.of(project, location, featurestoreId).toString()) + .build(); System.out.println("List Entity Types Async Response"); while (true) { ListEntityTypesResponse listEntityTypesResponse = @@ -76,4 +78,3 @@ static void listEntityTypesAsyncSample(String project, String featurestoreId, St } } // [END aiplatform_list_entity_types_async_sample] - diff --git a/samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java b/samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java index 92ada6fe2..1160216c4 100644 --- a/samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java +++ b/samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java @@ -41,8 +41,8 @@ public static void main(String[] args) throws IOException { listEntityTypesSample(project, featurestoreId, location, endpoint); } - static void listEntityTypesSample(String project, String featurestoreId, String location, - String endpoint) throws IOException { + static void listEntityTypesSample( + String project, String featurestoreId, String location, String endpoint) throws IOException { FeaturestoreServiceSettings featurestoreServiceSettings = FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); @@ -53,15 +53,16 @@ static void listEntityTypesSample(String project, String featurestoreId, String try (FeaturestoreServiceClient featurestoreServiceClient = FeaturestoreServiceClient.create(featurestoreServiceSettings)) { - ListEntityTypesRequest listEntityTypeRequest = ListEntityTypesRequest.newBuilder() - .setParent(FeaturestoreName.of(project, location, featurestoreId).toString()).build(); + ListEntityTypesRequest listEntityTypeRequest = + ListEntityTypesRequest.newBuilder() + .setParent(FeaturestoreName.of(project, location, featurestoreId).toString()) + .build(); System.out.println("List Entity Types Response"); - for (EntityType element : featurestoreServiceClient.listEntityTypes(listEntityTypeRequest) - .iterateAll()) { + for (EntityType element : + featurestoreServiceClient.listEntityTypes(listEntityTypeRequest).iterateAll()) { System.out.println(element); } } } } // [END aiplatform_list_entity_types_sample] - diff --git a/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java b/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java index d97862536..3133b146f 100644 --- a/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java +++ b/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java @@ -14,7 +14,7 @@ * limitations under the License. * * - * Update entity type. See + * Update entity type. See * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running * the code snippet */ @@ -42,12 +42,17 @@ public static void main(String[] args) throws IOException { int monitoringIntervalDays = 1; String location = "us-central1"; String endpoint = "us-central1-aiplatform.googleapis.com:443"; - updateEntityTypeMonitoringSample(project, featurestoreId, entityTypeId, monitoringIntervalDays, - location, endpoint); + updateEntityTypeMonitoringSample( + project, featurestoreId, entityTypeId, monitoringIntervalDays, location, endpoint); } - static void updateEntityTypeMonitoringSample(String project, String featurestoreId, - String entityTypeId, int monitoringIntervalDays, String location, String endpoint) + static void updateEntityTypeMonitoringSample( + String project, + String featurestoreId, + String entityTypeId, + int monitoringIntervalDays, + String location, + String endpoint) throws IOException { FeaturestoreServiceSettings featurestoreServiceSettings = @@ -63,9 +68,12 @@ static void updateEntityTypeMonitoringSample(String project, String featurestore .setSnapshotAnalysis( SnapshotAnalysis.newBuilder().setMonitoringIntervalDays(monitoringIntervalDays)) .build(); - EntityType entityType = EntityType.newBuilder() - .setName(EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) - .setMonitoringConfig(featurestoreMonitoringConfig).build(); + EntityType entityType = + EntityType.newBuilder() + .setName( + EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) + .setMonitoringConfig(featurestoreMonitoringConfig) + .build(); UpdateEntityTypeRequest updateEntityTypeRequest = UpdateEntityTypeRequest.newBuilder().setEntityType(entityType).build(); @@ -77,4 +85,3 @@ static void updateEntityTypeMonitoringSample(String project, String featurestore } } // [END aiplatform_update_entity_type_monitoring_sample] - diff --git a/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java b/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java index ca10632ad..bd7af2650 100644 --- a/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java +++ b/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java @@ -14,7 +14,7 @@ * limitations under the License. * * - * Update entity type. See + * Update entity type. See * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running * the code snippet */ @@ -43,8 +43,14 @@ public static void main(String[] args) throws IOException { updateEntityTypeSample(project, featurestoreId, entityTypeId, description, location, endpoint); } - static void updateEntityTypeSample(String project, String featurestoreId, String entityTypeId, - String description, String location, String endpoint) throws IOException { + static void updateEntityTypeSample( + String project, + String featurestoreId, + String entityTypeId, + String description, + String location, + String endpoint) + throws IOException { FeaturestoreServiceSettings featurestoreServiceSettings = FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); @@ -55,9 +61,12 @@ static void updateEntityTypeSample(String project, String featurestoreId, String try (FeaturestoreServiceClient featurestoreServiceClient = FeaturestoreServiceClient.create(featurestoreServiceSettings)) { - EntityType entityType = EntityType.newBuilder() - .setName(EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) - .setDescription(description).build(); + EntityType entityType = + EntityType.newBuilder() + .setName( + EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) + .setDescription(description) + .build(); UpdateEntityTypeRequest updateEntityTypeRequest = UpdateEntityTypeRequest.newBuilder().setEntityType(entityType).build(); @@ -69,4 +78,3 @@ static void updateEntityTypeSample(String project, String featurestoreId, String } } // [END aiplatform_update_entity_type_sample] - diff --git a/samples/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java b/samples/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java index 5a86fb006..41227c71c 100644 --- a/samples/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java +++ b/samples/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java @@ -74,8 +74,8 @@ public void tearDown() throws InterruptedException, ExecutionException, IOException, TimeoutException { // Delete the featurestore - DeleteFeaturestoreSample.deleteFeaturestoreSample(PROJECT_ID, featurestoreId, USE_FORCE, - LOCATION, ENDPOINT, 60); + DeleteFeaturestoreSample.deleteFeaturestoreSample( + PROJECT_ID, featurestoreId, USE_FORCE, LOCATION, ENDPOINT, 60); // Assert String deleteFeaturestoreResponse = bout.toString(); @@ -90,8 +90,8 @@ public void testEntityTypeSamples() // Create the featurestore String tempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 26); String id = String.format("temp_create_featurestore_test_%s", tempUuid); - CreateFeaturestoreSample.createFeaturestoreSample(PROJECT_ID, id, MIN_NODE_COUNT, - MAX_NODE_COUNT, LOCATION, ENDPOINT, TIMEOUT); + CreateFeaturestoreSample.createFeaturestoreSample( + PROJECT_ID, id, MIN_NODE_COUNT, MAX_NODE_COUNT, LOCATION, ENDPOINT, TIMEOUT); // Assert String createFeaturestoreResponse = bout.toString(); @@ -103,16 +103,16 @@ public void testEntityTypeSamples() // Create the entity type String entityTypeTempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 16); String entityTypeId = String.format("temp_create_entity_type_test_%s", entityTypeTempUuid); - CreateEntityTypeSample.createEntityTypeSample(PROJECT_ID, featurestoreId, entityTypeId, - DESCRIPTION, LOCATION, ENDPOINT, TIMEOUT); + CreateEntityTypeSample.createEntityTypeSample( + PROJECT_ID, featurestoreId, entityTypeId, DESCRIPTION, LOCATION, ENDPOINT, TIMEOUT); // Assert String createEntityTypeResponse = bout.toString(); assertThat(createEntityTypeResponse).contains("Create Entity Type Response"); // Get the entity type - GetEntityTypeSample.getEntityTypeSample(PROJECT_ID, featurestoreId, entityTypeId, LOCATION, - ENDPOINT); + GetEntityTypeSample.getEntityTypeSample( + PROJECT_ID, featurestoreId, entityTypeId, LOCATION, ENDPOINT); // Assert String getEntityTypeResponse = bout.toString(); @@ -123,8 +123,15 @@ public void testEntityTypeSamples() UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 16); String entityTypeMonitoringId = String.format("temp_create_entity_type_test_%s", entityTypeMonitoringTempUuid); - CreateEntityTypeMonitoringSample.createEntityTypeMonitoringSample(PROJECT_ID, featurestoreId, - entityTypeMonitoringId, DESCRIPTION, MONITORING_INTERVAL_DAYS, LOCATION, ENDPOINT, TIMEOUT); + CreateEntityTypeMonitoringSample.createEntityTypeMonitoringSample( + PROJECT_ID, + featurestoreId, + entityTypeMonitoringId, + DESCRIPTION, + MONITORING_INTERVAL_DAYS, + LOCATION, + ENDPOINT, + TIMEOUT); // Assert String createEntityTypeMonitoringResponse = bout.toString(); @@ -139,16 +146,16 @@ public void testEntityTypeSamples() assertThat(listEntityTypeResponse).contains("List Entity Types Response"); // Update the entity type - UpdateEntityTypeSample.updateEntityTypeSample(PROJECT_ID, featurestoreId, entityTypeId, - DESCRIPTION, LOCATION, ENDPOINT); + UpdateEntityTypeSample.updateEntityTypeSample( + PROJECT_ID, featurestoreId, entityTypeId, DESCRIPTION, LOCATION, ENDPOINT); // Assert String updateEntityTypeResponse = bout.toString(); assertThat(updateEntityTypeResponse).contains("Update Entity Type Response"); // Update the entity type - UpdateEntityTypeMonitoringSample.updateEntityTypeMonitoringSample(PROJECT_ID, featurestoreId, - entityTypeId, MONITORING_INTERVAL_DAYS, LOCATION, ENDPOINT); + UpdateEntityTypeMonitoringSample.updateEntityTypeMonitoringSample( + PROJECT_ID, featurestoreId, entityTypeId, MONITORING_INTERVAL_DAYS, LOCATION, ENDPOINT); // Assert String updateEntityTypeMonitoringResponse = bout.toString(); @@ -156,21 +163,19 @@ public void testEntityTypeSamples() .contains("Update Entity Type Monitoring Response"); // List entity types - ListEntityTypesAsyncSample.listEntityTypesAsyncSample(PROJECT_ID, featurestoreId, LOCATION, - ENDPOINT); + ListEntityTypesAsyncSample.listEntityTypesAsyncSample( + PROJECT_ID, featurestoreId, LOCATION, ENDPOINT); // Assert String listEntityTypeAsyncResponse = bout.toString(); assertThat(listEntityTypeAsyncResponse).contains("List Entity Types Async Response"); // Delete the entity type - DeleteEntityTypeSample.deleteEntityTypeSample(PROJECT_ID, featurestoreId, entityTypeId, - LOCATION, ENDPOINT, TIMEOUT); + DeleteEntityTypeSample.deleteEntityTypeSample( + PROJECT_ID, featurestoreId, entityTypeId, LOCATION, ENDPOINT, TIMEOUT); // Assert String deleteEntityTypeResponse = bout.toString(); assertThat(deleteEntityTypeResponse).contains("Deleted Entity Type"); - } } -