From c04b425ab7174e8bb8b1b8691b62b40cf6b2fa54 Mon Sep 17 00:00:00 2001 From: sai-chaithu Date: Tue, 28 Jun 2022 13:48:43 +0530 Subject: [PATCH 1/5] feat(samples): add all feature samples --- .../java/aiplatform/CreateFeatureSample.java | 89 ++++++++ .../java/aiplatform/DeleteFeatureSample.java | 82 +++++++ .../java/aiplatform/GetFeatureSample.java | 70 ++++++ .../aiplatform/ListFeaturesAsyncSample.java | 79 +++++++ .../java/aiplatform/ListFeaturesSample.java | 68 ++++++ .../aiplatform/SearchFeaturesAsyncSample.java | 78 +++++++ .../java/aiplatform/SearchFeaturesSample.java | 65 ++++++ .../java/aiplatform/UpdateFeatureSample.java | 69 ++++++ .../java/aiplatform/FeatureSamplesTest.java | 210 ++++++++++++++++++ 9 files changed, 810 insertions(+) create mode 100644 samples/snippets/src/main/java/aiplatform/CreateFeatureSample.java create mode 100644 samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java create mode 100644 samples/snippets/src/main/java/aiplatform/GetFeatureSample.java create mode 100644 samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java create mode 100644 samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java create mode 100644 samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.java create mode 100644 samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.java create mode 100644 samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java create mode 100644 samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java diff --git a/samples/snippets/src/main/java/aiplatform/CreateFeatureSample.java b/samples/snippets/src/main/java/aiplatform/CreateFeatureSample.java new file mode 100644 index 000000000..aa60b872c --- /dev/null +++ b/samples/snippets/src/main/java/aiplatform/CreateFeatureSample.java @@ -0,0 +1,89 @@ +/* + * 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 a single feature for an existing entity type. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_create_feature_sample] + +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.aiplatform.v1.CreateFeatureOperationMetadata; +import com.google.cloud.aiplatform.v1.CreateFeatureRequest; +import com.google.cloud.aiplatform.v1.EntityTypeName; +import com.google.cloud.aiplatform.v1.Feature; +import com.google.cloud.aiplatform.v1.Feature.ValueType; +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 CreateFeatureSample { + + 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 featureId = "YOUR_FEATURE_ID"; + String description = "YOUR_FEATURE_DESCRIPTION"; + String valueType = "YOUR_FEATURE_VALUE_TYPE"; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + int timeout = 300; + createFeatureSample(project, featurestoreId, entityTypeId, featureId, description, valueType, + location, endpoint, timeout); + } + + static void createFeatureSample(String project, String featurestoreId, String entityTypeId, + String featureId, String description, String valueType, 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)) { + + Feature feature = Feature.newBuilder().setDescription(description) + .setValueType(ValueType.valueOf(valueType)) + // .setDisableMonitoring(disableMonitoring) + .build(); + + CreateFeatureRequest createFeatureRequest = CreateFeatureRequest.newBuilder() + .setParent(EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) + .setFeature(feature).setFeatureId(featureId).build(); + + OperationFuture featureFuture = + featurestoreServiceClient.createFeatureAsync(createFeatureRequest); + System.out.format("Operation name: %s%n", featureFuture.getInitialFuture().get().getName()); + System.out.println("Waiting for operation to finish..."); + Feature featureResponse = featureFuture.get(timeout, TimeUnit.SECONDS); + System.out.println("Create Feature Response"); + System.out.format("Name: %s%n", featureResponse.getName()); + } + } +} +// [END aiplatform_create_feature_sample] \ No newline at end of file diff --git a/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java b/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java new file mode 100644 index 000000000..7fe5404f6 --- /dev/null +++ b/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java @@ -0,0 +1,82 @@ +/* + * 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 a single feature from an existing entity type. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_delete_Feature_sample] + +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.aiplatform.v1.DeleteFeatureRequest; +import com.google.cloud.aiplatform.v1.DeleteOperationMetadata; +import com.google.cloud.aiplatform.v1.FeatureName; +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 DeleteFeatureSample { + + 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 featureId = "YOUR_FEATURE_ID"; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + int timeout = 300; + + deleteFeatureSample(project, featurestoreId, entityTypeId, featureId, location, endpoint, + timeout); + } + + static void deleteFeatureSample(String project, String featurestoreId, String entityTypeId, + String featureId, 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)) { + + DeleteFeatureRequest deleteFeatureRequest = DeleteFeatureRequest.newBuilder() + .setName( + FeatureName.of(project, location, featurestoreId, entityTypeId, featureId).toString()) + .build(); + + OperationFuture operationFuture = + featurestoreServiceClient.deleteFeatureAsync(deleteFeatureRequest); + 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 Feature."); + } + } +} +// [END aiplatform_delete_Feature_sample] \ No newline at end of file diff --git a/samples/snippets/src/main/java/aiplatform/GetFeatureSample.java b/samples/snippets/src/main/java/aiplatform/GetFeatureSample.java new file mode 100644 index 000000000..9d67b1757 --- /dev/null +++ b/samples/snippets/src/main/java/aiplatform/GetFeatureSample.java @@ -0,0 +1,70 @@ +/* + * 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 feature details. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_get_feature_sample] + +import com.google.cloud.aiplatform.v1.Feature; +import com.google.cloud.aiplatform.v1.FeatureName; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import com.google.cloud.aiplatform.v1.GetFeatureRequest; +import java.io.IOException; + +public class GetFeatureSample { + + 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 featureId = "YOUR_FEATURE_ID"; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + + getFeatureSample(project, featurestoreId, entityTypeId, featureId, location, endpoint); + } + + static void getFeatureSample(String project, String featurestoreId, String entityTypeId, + String featureId, 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)) { + + GetFeatureRequest getFeatureRequest = GetFeatureRequest.newBuilder() + .setName( + FeatureName.of(project, location, featurestoreId, entityTypeId, featureId).toString()) + .build(); + + Feature feature = featurestoreServiceClient.getFeature(getFeatureRequest); + System.out.println("Get Feature Response"); + System.out.println(feature); + } + } +} +// [END aiplatform_get_feature_sample] \ No newline at end of file diff --git a/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java b/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java new file mode 100644 index 000000000..b797a7f75 --- /dev/null +++ b/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.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. + * + * + * List available feature details. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_list_features_async_sample] + +import com.google.cloud.aiplatform.v1.EntityTypeName; +import com.google.cloud.aiplatform.v1.Feature; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import com.google.cloud.aiplatform.v1.ListFeaturesRequest; +import com.google.cloud.aiplatform.v1.ListFeaturesResponse; +import com.google.common.base.Strings; +import java.io.IOException; + +public class ListFeaturesAsyncSample { + + 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"; + + listFeaturesAsyncSample(project, featurestoreId, entityTypeId, location, endpoint); + } + + static void listFeaturesAsyncSample(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)) { + + ListFeaturesRequest listFeaturesRequest = ListFeaturesRequest.newBuilder() + .setParent(EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) + .build(); + System.out.println("List Features Async Response"); + while (true) { + ListFeaturesResponse listFeaturesResponse = + featurestoreServiceClient.listFeaturesCallable().call(listFeaturesRequest); + for (Feature element : listFeaturesResponse.getFeaturesList()) { + System.out.println(element); + } + String nextPageToken = listFeaturesResponse.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + listFeaturesRequest = listFeaturesRequest.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END aiplatform_list_features_async_sample] \ No newline at end of file diff --git a/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java b/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java new file mode 100644 index 000000000..4d25e18c1 --- /dev/null +++ b/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java @@ -0,0 +1,68 @@ +/* + * 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 feature details. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_list_features_sample] + +import com.google.cloud.aiplatform.v1.EntityTypeName; +import com.google.cloud.aiplatform.v1.Feature; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import com.google.cloud.aiplatform.v1.ListFeaturesRequest; +import java.io.IOException; + +public class ListFeaturesSample { + + 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"; + + listFeaturesSample(project, featurestoreId, entityTypeId, location, endpoint); + } + + static void listFeaturesSample(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)) { + + ListFeaturesRequest listFeaturesRequest = ListFeaturesRequest.newBuilder() + .setParent(EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) + .build(); + System.out.println("List Features Response"); + for (Feature element : featurestoreServiceClient.listFeatures(listFeaturesRequest) + .iterateAll()) { + System.out.println(element); + } + } + } +} +// [END aiplatform_list_features_sample] \ No newline at end of file diff --git a/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.java b/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.java new file mode 100644 index 000000000..96e97b2d4 --- /dev/null +++ b/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.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. + * + * + * Search for featurestore resources. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_search_features_async_sample] + +import com.google.cloud.aiplatform.v1.Feature; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import com.google.cloud.aiplatform.v1.LocationName; +import com.google.cloud.aiplatform.v1.SearchFeaturesRequest; +import com.google.cloud.aiplatform.v1.SearchFeaturesResponse; +import com.google.common.base.Strings; +import java.io.IOException; + +public class SearchFeaturesAsyncSample { + + public static void main(String[] args) + throws IOException { + // TODO(developer): Replace these variables before running the sample. + String project = "YOUR_PROJECT_ID"; + String query = "YOUR_QUERY"; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + searchFeaturesAsyncSample(project, query, location, endpoint); + } + + static void searchFeaturesAsyncSample(String project, String query, 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)) { + + SearchFeaturesRequest searchFeaturesRequest = SearchFeaturesRequest.newBuilder() + .setLocation(LocationName.of(project, location).toString()).setQuery(query).build(); + System.out.println("Search Features Async Response"); + while (true) { + SearchFeaturesResponse response = + featurestoreServiceClient.searchFeaturesCallable().call(searchFeaturesRequest); + for (Feature element : response.getFeaturesList()) { + System.out.println(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + searchFeaturesRequest = + searchFeaturesRequest.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END aiplatform_search_features_async_sample] \ No newline at end of file diff --git a/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.java b/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.java new file mode 100644 index 000000000..750955820 --- /dev/null +++ b/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.java @@ -0,0 +1,65 @@ +/* + * 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. + * + * + * Search for featurestore resources. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_search_features_sample] + +import com.google.cloud.aiplatform.v1.Feature; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import com.google.cloud.aiplatform.v1.LocationName; +import com.google.cloud.aiplatform.v1.SearchFeaturesRequest; +import java.io.IOException; + +public class SearchFeaturesSample { + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String project = "YOUR_PROJECT_ID"; + String query = "YOUR_QUERY"; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + searchFeaturesSample(project, query, location, endpoint); + } + + static void searchFeaturesSample(String project, String query, 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)) { + + SearchFeaturesRequest searchFeaturesRequest = SearchFeaturesRequest.newBuilder() + .setLocation(LocationName.of(project, location).toString()).setQuery(query).build(); + System.out.println("Search Features Response"); + for (Feature element : featurestoreServiceClient.searchFeatures(searchFeaturesRequest) + .iterateAll()) { + System.out.println(element); + } + } + } +} +// [END aiplatform_search_features_sample] \ No newline at end of file diff --git a/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java b/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java new file mode 100644 index 000000000..2e58cab79 --- /dev/null +++ b/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java @@ -0,0 +1,69 @@ +/* + * 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 feature. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_update_feature_sample] + +import com.google.cloud.aiplatform.v1.Feature; +import com.google.cloud.aiplatform.v1.FeatureName; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import com.google.cloud.aiplatform.v1.UpdateFeatureRequest; +import java.io.IOException; + +public class UpdateFeatureSample { + + 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 featureId = "YOUR_FEATURE_ID"; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + updateFeatureSample(project, featurestoreId, entityTypeId, featureId, location, endpoint); + } + + static void updateFeatureSample(String project, String featurestoreId, String entityTypeId, + String featureId, 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)) { + + Feature feature = Feature.newBuilder() + .setName( + FeatureName.of(project, location, featurestoreId, entityTypeId, featureId).toString()) + .setDescription("sample feature title updated").build(); + + UpdateFeatureRequest request = UpdateFeatureRequest.newBuilder().setFeature(feature).build(); + Feature featureResponse = featurestoreServiceClient.updateFeature(request); + System.out.println("Update Feature Response"); + System.out.format("Name: %s%n", featureResponse.getName()); + } + } +} +// [END aiplatform_update_feature_sample] \ No newline at end of file diff --git a/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java b/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java new file mode 100644 index 000000000..60d5f982b --- /dev/null +++ b/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java @@ -0,0 +1,210 @@ +/* + * 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 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.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +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 FeatureSamplesTest { + + 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 VALUE_TYPE = "STRING"; + private static final String DESCRIPTION = "Test Description"; + private static final boolean USE_FORCE = true; + private static final String QUERY = "value_type=STRING"; + 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); + } + + 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()); + } + } + + @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 testFeatureSamples() + 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, 900); + + // 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(PROJECT_ID, featurestoreId, entityTypeId, + DESCRIPTION, LOCATION, ENDPOINT, TIMEOUT); + + // Assert + String createEntityTypeResponse = bout.toString(); + assertThat(createEntityTypeResponse).contains("Create Entity Type Response"); + + // Create the feature + String featureTempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 26); + String featureId = String.format("temp_create_feature_test_%s", featureTempUuid); + CreateFeatureSample.createFeatureSample(PROJECT_ID, featurestoreId, entityTypeId, featureId, + DESCRIPTION, VALUE_TYPE, LOCATION, ENDPOINT, TIMEOUT); + + // Assert + String createFeatureResponse = bout.toString(); + assertThat(createFeatureResponse).contains("Create Feature Response"); + + // Get the feature + GetFeatureSample.getFeatureSample(PROJECT_ID, featurestoreId, entityTypeId, featureId, LOCATION, + ENDPOINT); + + // Assert + String getFeatureResponse = bout.toString(); + assertThat(getFeatureResponse).contains("Get Feature Response"); + + // List features + ListFeaturesSample.listFeaturesSample(PROJECT_ID, featurestoreId, entityTypeId, LOCATION, + ENDPOINT); + + // Assert + String listfeatureResponse = bout.toString(); + assertThat(listfeatureResponse).contains("List Features Response"); + + // List features + ListFeaturesAsyncSample.listFeaturesAsyncSample(PROJECT_ID, featurestoreId, entityTypeId, + LOCATION, ENDPOINT); + + // Assert + String listfeatureAsyncResponse = bout.toString(); + assertThat(listfeatureAsyncResponse).contains("List Features Async Response"); + + // Search features + SearchFeaturesSample.searchFeaturesSample(PROJECT_ID, QUERY, LOCATION, ENDPOINT); + + // Assert + String searchFeaturesResponse = bout.toString(); + assertThat(searchFeaturesResponse).contains("Search Features Response"); + + // Search features + SearchFeaturesAsyncSample.searchFeaturesAsyncSample(PROJECT_ID, QUERY, LOCATION, ENDPOINT); + + // Assert + String searchFeaturesAsyncResponse = bout.toString(); + assertThat(searchFeaturesAsyncResponse).contains("Search Features Async Response"); + + // Delete the feature + DeleteFeatureSample.deleteFeatureSample(PROJECT_ID, featurestoreId, entityTypeId, featureId, + LOCATION, ENDPOINT, TIMEOUT); + + // Assert + String deleteFeatureResponse = bout.toString(); + assertThat(deleteFeatureResponse).contains("Deleted Feature"); + + } +} From 361aed3b5bacd168a83ca20c0963fa891087ddd7 Mon Sep 17 00:00:00 2001 From: sai-chaithu Date: Tue, 28 Jun 2022 14:41:31 +0530 Subject: [PATCH 2/5] feat(samples): update all feature samples --- .../snippets/src/main/java/aiplatform/CreateFeatureSample.java | 3 ++- .../snippets/src/main/java/aiplatform/DeleteFeatureSample.java | 3 ++- .../snippets/src/main/java/aiplatform/GetFeatureSample.java | 3 ++- .../src/main/java/aiplatform/ListFeaturesAsyncSample.java | 3 ++- .../snippets/src/main/java/aiplatform/ListFeaturesSample.java | 3 ++- .../src/main/java/aiplatform/SearchFeaturesAsyncSample.java | 3 ++- .../src/main/java/aiplatform/SearchFeaturesSample.java | 3 ++- .../snippets/src/main/java/aiplatform/UpdateFeatureSample.java | 3 ++- .../snippets/src/test/java/aiplatform/FeatureSamplesTest.java | 1 + 9 files changed, 17 insertions(+), 8 deletions(-) diff --git a/samples/snippets/src/main/java/aiplatform/CreateFeatureSample.java b/samples/snippets/src/main/java/aiplatform/CreateFeatureSample.java index aa60b872c..a49d2447e 100644 --- a/samples/snippets/src/main/java/aiplatform/CreateFeatureSample.java +++ b/samples/snippets/src/main/java/aiplatform/CreateFeatureSample.java @@ -86,4 +86,5 @@ static void createFeatureSample(String project, String featurestoreId, String en } } } -// [END aiplatform_create_feature_sample] \ No newline at end of file +// [END aiplatform_create_feature_sample] + diff --git a/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java b/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java index 7fe5404f6..257392c24 100644 --- a/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java +++ b/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java @@ -79,4 +79,5 @@ static void deleteFeatureSample(String project, String featurestoreId, String en } } } -// [END aiplatform_delete_Feature_sample] \ No newline at end of file +// [END aiplatform_delete_Feature_sample] + diff --git a/samples/snippets/src/main/java/aiplatform/GetFeatureSample.java b/samples/snippets/src/main/java/aiplatform/GetFeatureSample.java index 9d67b1757..112403df8 100644 --- a/samples/snippets/src/main/java/aiplatform/GetFeatureSample.java +++ b/samples/snippets/src/main/java/aiplatform/GetFeatureSample.java @@ -67,4 +67,5 @@ static void getFeatureSample(String project, String featurestoreId, String entit } } } -// [END aiplatform_get_feature_sample] \ No newline at end of file +// [END aiplatform_get_feature_sample] + diff --git a/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java b/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java index b797a7f75..7493a8482 100644 --- a/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java +++ b/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java @@ -76,4 +76,5 @@ static void listFeaturesAsyncSample(String project, String featurestoreId, Strin } } } -// [END aiplatform_list_features_async_sample] \ No newline at end of file +// [END aiplatform_list_features_async_sample] + diff --git a/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java b/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java index 4d25e18c1..1b72dc135 100644 --- a/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java +++ b/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java @@ -65,4 +65,5 @@ static void listFeaturesSample(String project, String featurestoreId, String ent } } } -// [END aiplatform_list_features_sample] \ No newline at end of file +// [END aiplatform_list_features_sample] + diff --git a/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.java b/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.java index 96e97b2d4..39bfc37a2 100644 --- a/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.java +++ b/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.java @@ -75,4 +75,5 @@ static void searchFeaturesAsyncSample(String project, String query, String locat } } } -// [END aiplatform_search_features_async_sample] \ No newline at end of file +// [END aiplatform_search_features_async_sample] + diff --git a/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.java b/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.java index 750955820..33488c3aa 100644 --- a/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.java +++ b/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.java @@ -62,4 +62,5 @@ static void searchFeaturesSample(String project, String query, String location, } } } -// [END aiplatform_search_features_sample] \ No newline at end of file +// [END aiplatform_search_features_sample] + diff --git a/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java b/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java index 2e58cab79..5628aa262 100644 --- a/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java +++ b/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java @@ -66,4 +66,5 @@ static void updateFeatureSample(String project, String featurestoreId, String en } } } -// [END aiplatform_update_feature_sample] \ No newline at end of file +// [END aiplatform_update_feature_sample] + diff --git a/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java b/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java index 60d5f982b..28aa7c4b4 100644 --- a/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java +++ b/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java @@ -208,3 +208,4 @@ public void testFeatureSamples() } } + From c70d153f6249bbb0e1377c2bb90d2513a2d85f4b Mon Sep 17 00:00:00 2001 From: sai-chaithu Date: Thu, 14 Jul 2022 14:45:16 +0530 Subject: [PATCH 3/5] feat(samples): updated the feature samples with close method call and separate timeouts --- .../java/aiplatform/CreateFeatureSample.java | 10 ++-- .../java/aiplatform/DeleteFeatureSample.java | 6 +-- .../java/aiplatform/GetFeatureSample.java | 1 + .../aiplatform/ListFeaturesAsyncSample.java | 1 + .../java/aiplatform/ListFeaturesSample.java | 1 + .../aiplatform/SearchFeaturesAsyncSample.java | 1 + .../java/aiplatform/SearchFeaturesSample.java | 1 + .../java/aiplatform/UpdateFeatureSample.java | 1 + .../java/aiplatform/FeatureSamplesTest.java | 52 +++---------------- 9 files changed, 21 insertions(+), 53 deletions(-) diff --git a/samples/snippets/src/main/java/aiplatform/CreateFeatureSample.java b/samples/snippets/src/main/java/aiplatform/CreateFeatureSample.java index a49d2447e..6be6b1aa7 100644 --- a/samples/snippets/src/main/java/aiplatform/CreateFeatureSample.java +++ b/samples/snippets/src/main/java/aiplatform/CreateFeatureSample.java @@ -46,16 +46,16 @@ public static void main(String[] args) String entityTypeId = "YOUR_ENTITY_TYPE_ID"; String featureId = "YOUR_FEATURE_ID"; String description = "YOUR_FEATURE_DESCRIPTION"; - String valueType = "YOUR_FEATURE_VALUE_TYPE"; + ValueType valueType = ValueType.STRING; String location = "us-central1"; String endpoint = "us-central1-aiplatform.googleapis.com:443"; - int timeout = 300; + int timeout = 900; createFeatureSample(project, featurestoreId, entityTypeId, featureId, description, valueType, location, endpoint, timeout); } static void createFeatureSample(String project, String featurestoreId, String entityTypeId, - String featureId, String description, String valueType, String location, String endpoint, + String featureId, String description, ValueType valueType, String location, String endpoint, int timeout) throws IOException, InterruptedException, ExecutionException, TimeoutException { FeaturestoreServiceSettings featurestoreServiceSettings = @@ -68,8 +68,7 @@ static void createFeatureSample(String project, String featurestoreId, String en FeaturestoreServiceClient.create(featurestoreServiceSettings)) { Feature feature = Feature.newBuilder().setDescription(description) - .setValueType(ValueType.valueOf(valueType)) - // .setDisableMonitoring(disableMonitoring) + .setValueType(valueType) .build(); CreateFeatureRequest createFeatureRequest = CreateFeatureRequest.newBuilder() @@ -83,6 +82,7 @@ static void createFeatureSample(String project, String featurestoreId, String en Feature featureResponse = featureFuture.get(timeout, TimeUnit.SECONDS); System.out.println("Create Feature Response"); System.out.format("Name: %s%n", featureResponse.getName()); + featurestoreServiceClient.close(); } } } diff --git a/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java b/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java index 257392c24..062840051 100644 --- a/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java +++ b/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java @@ -21,7 +21,7 @@ package aiplatform; -// [START aiplatform_delete_Feature_sample] +// [START aiplatform_delete_feature_sample] import com.google.api.gax.longrunning.OperationFuture; import com.google.cloud.aiplatform.v1.DeleteFeatureRequest; @@ -74,10 +74,10 @@ static void deleteFeatureSample(String project, String featurestoreId, String en 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 Feature."); + featurestoreServiceClient.close(); } } } -// [END aiplatform_delete_Feature_sample] +// [END aiplatform_delete_feature_sample] diff --git a/samples/snippets/src/main/java/aiplatform/GetFeatureSample.java b/samples/snippets/src/main/java/aiplatform/GetFeatureSample.java index 112403df8..697aab41b 100644 --- a/samples/snippets/src/main/java/aiplatform/GetFeatureSample.java +++ b/samples/snippets/src/main/java/aiplatform/GetFeatureSample.java @@ -64,6 +64,7 @@ static void getFeatureSample(String project, String featurestoreId, String entit Feature feature = featurestoreServiceClient.getFeature(getFeatureRequest); System.out.println("Get Feature Response"); System.out.println(feature); + featurestoreServiceClient.close(); } } } diff --git a/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java b/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java index 7493a8482..6a38e81df 100644 --- a/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java +++ b/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java @@ -73,6 +73,7 @@ static void listFeaturesAsyncSample(String project, String featurestoreId, Strin break; } } + featurestoreServiceClient.close(); } } } diff --git a/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java b/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java index 1b72dc135..cdd76c494 100644 --- a/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java +++ b/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java @@ -62,6 +62,7 @@ static void listFeaturesSample(String project, String featurestoreId, String ent .iterateAll()) { System.out.println(element); } + featurestoreServiceClient.close(); } } } diff --git a/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.java b/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.java index 39bfc37a2..ebb2d0ea1 100644 --- a/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.java +++ b/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.java @@ -72,6 +72,7 @@ static void searchFeaturesAsyncSample(String project, String query, String locat break; } } + featurestoreServiceClient.close(); } } } diff --git a/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.java b/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.java index 33488c3aa..084b9e99e 100644 --- a/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.java +++ b/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.java @@ -59,6 +59,7 @@ static void searchFeaturesSample(String project, String query, String location, .iterateAll()) { System.out.println(element); } + featurestoreServiceClient.close(); } } } diff --git a/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java b/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java index 5628aa262..68d1f12d6 100644 --- a/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java +++ b/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java @@ -63,6 +63,7 @@ static void updateFeatureSample(String project, String featurestoreId, String en Feature featureResponse = featurestoreServiceClient.updateFeature(request); System.out.println("Update Feature Response"); System.out.format("Name: %s%n", featureResponse.getName()); + featurestoreServiceClient.close(); } } } diff --git a/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java b/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java index 28aa7c4b4..fcd4faec7 100644 --- a/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java +++ b/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java @@ -19,19 +19,12 @@ import static com.google.common.truth.Truth.assertThat; import static junit.framework.TestCase.assertNotNull; -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 com.google.cloud.aiplatform.v1.Feature.ValueType; 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.TimeUnit; import java.util.concurrent.TimeoutException; import org.junit.After; import org.junit.Before; @@ -46,13 +39,12 @@ public class FeatureSamplesTest { 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 VALUE_TYPE = "STRING"; + private static final ValueType VALUE_TYPE = ValueType.STRING; private static final String DESCRIPTION = "Test Description"; private static final boolean USE_FORCE = true; private static final String QUERY = "value_type=STRING"; 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; @@ -77,36 +69,6 @@ public void setUp() { originalPrintStream = System.out; System.setOut(out); } - - 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()); - } - } @After public void tearDown() @@ -114,7 +76,7 @@ public void tearDown() // Delete the featurestore DeleteFeaturestoreSample.deleteFeaturestoreSample(PROJECT_ID, featurestoreId, USE_FORCE, - LOCATION, ENDPOINT, 60); + LOCATION, ENDPOINT, 300); // Assert String deleteFeaturestoreResponse = bout.toString(); @@ -143,8 +105,8 @@ public void testFeatureSamples() // 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(PROJECT_ID, featurestoreId, entityTypeId, - DESCRIPTION, LOCATION, ENDPOINT, TIMEOUT); + CreateEntityTypeSample.createEntityTypeSample(PROJECT_ID, featurestoreId, entityTypeId, + DESCRIPTION, LOCATION, ENDPOINT, 900); // Assert String createEntityTypeResponse = bout.toString(); @@ -154,7 +116,7 @@ public void testFeatureSamples() String featureTempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 26); String featureId = String.format("temp_create_feature_test_%s", featureTempUuid); CreateFeatureSample.createFeatureSample(PROJECT_ID, featurestoreId, entityTypeId, featureId, - DESCRIPTION, VALUE_TYPE, LOCATION, ENDPOINT, TIMEOUT); + DESCRIPTION, VALUE_TYPE, LOCATION, ENDPOINT, 900); // Assert String createFeatureResponse = bout.toString(); @@ -200,7 +162,7 @@ public void testFeatureSamples() // Delete the feature DeleteFeatureSample.deleteFeatureSample(PROJECT_ID, featurestoreId, entityTypeId, featureId, - LOCATION, ENDPOINT, TIMEOUT); + LOCATION, ENDPOINT, 300); // Assert String deleteFeatureResponse = bout.toString(); From 471b4c66c9b2e63fa4d1efada64a1a935039fb07 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 14 Jul 2022 15:03:59 +0000 Subject: [PATCH 4/5] =?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 | 12 ++++- .../java/aiplatform/CreateFeatureSample.java | 44 +++++++++++----- .../java/aiplatform/DeleteFeatureSample.java | 27 ++++++---- .../java/aiplatform/GetFeatureSample.java | 25 +++++---- .../aiplatform/ListFeaturesAsyncSample.java | 18 ++++--- .../java/aiplatform/ListFeaturesSample.java | 22 ++++---- .../aiplatform/SearchFeaturesAsyncSample.java | 19 +++---- .../java/aiplatform/SearchFeaturesSample.java | 16 +++--- .../java/aiplatform/UpdateFeatureSample.java | 26 ++++++---- .../java/aiplatform/FeatureSamplesTest.java | 52 +++++++++++-------- 10 files changed, 161 insertions(+), 100 deletions(-) diff --git a/README.md b/README.md index 8820b7d4a..6ab6e070d 100644 --- a/README.md +++ b/README.md @@ -45,13 +45,13 @@ implementation 'com.google.cloud:google-cloud-aiplatform' If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-aiplatform:3.0.0' +implementation 'com.google.cloud:google-cloud-aiplatform:3.1.0' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-aiplatform" % "3.0.0" +libraryDependencies += "com.google.cloud" % "google-cloud-aiplatform" % "3.1.0" ``` ## Authentication @@ -120,6 +120,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-aiplatform/tr | 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 Feature Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CreateFeatureSample.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/CreateFeatureSample.java) | | Create Featurestore Fixed Nodes Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CreateFeaturestoreFixedNodesSample.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/CreateFeaturestoreFixedNodesSample.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) | @@ -143,6 +144,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-aiplatform/tr | 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 Feature Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.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/DeleteFeatureSample.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) | | Delete Training Pipeline Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeleteTrainingPipelineSample.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/DeleteTrainingPipelineSample.java) | @@ -153,6 +155,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-aiplatform/tr | 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 Feature Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/GetFeatureSample.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/GetFeatureSample.java) | | Get Featurestore Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/GetFeaturestoreSample.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/GetFeaturestoreSample.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) | @@ -179,6 +182,8 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-aiplatform/tr | 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 Features Async Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.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/ListFeaturesAsyncSample.java) | +| List Features Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.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/ListFeaturesSample.java) | | List Featurestores Async Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ListFeaturestoresAsyncSample.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/ListFeaturestoresAsyncSample.java) | | List Featurestores Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ListFeaturestoresSample.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/ListFeaturestoresSample.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) | @@ -190,9 +195,12 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-aiplatform/tr | Predict Text Classification Single Label Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/PredictTextClassificationSingleLabelSample.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/PredictTextClassificationSingleLabelSample.java) | | 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) | +| Search Features Async Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.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/SearchFeaturesAsyncSample.java) | +| Search Features Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.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/SearchFeaturesSample.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) | +| Update Feature Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.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/UpdateFeatureSample.java) | | Update Featurestore Fixed Nodes Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/UpdateFeaturestoreFixedNodesSample.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/UpdateFeaturestoreFixedNodesSample.java) | | Update Featurestore Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/UpdateFeaturestoreSample.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/UpdateFeaturestoreSample.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/CreateFeatureSample.java b/samples/snippets/src/main/java/aiplatform/CreateFeatureSample.java index 6be6b1aa7..10c18736f 100644 --- a/samples/snippets/src/main/java/aiplatform/CreateFeatureSample.java +++ b/samples/snippets/src/main/java/aiplatform/CreateFeatureSample.java @@ -15,7 +15,7 @@ * * * Create a single feature for an existing entity type. 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,29 @@ public static void main(String[] args) String location = "us-central1"; String endpoint = "us-central1-aiplatform.googleapis.com:443"; int timeout = 900; - createFeatureSample(project, featurestoreId, entityTypeId, featureId, description, valueType, - location, endpoint, timeout); + createFeatureSample( + project, + featurestoreId, + entityTypeId, + featureId, + description, + valueType, + location, + endpoint, + timeout); } - static void createFeatureSample(String project, String featurestoreId, String entityTypeId, - String featureId, String description, ValueType valueType, String location, String endpoint, - int timeout) throws IOException, InterruptedException, ExecutionException, TimeoutException { + static void createFeatureSample( + String project, + String featurestoreId, + String entityTypeId, + String featureId, + String description, + ValueType valueType, + String location, + String endpoint, + int timeout) + throws IOException, InterruptedException, ExecutionException, TimeoutException { FeaturestoreServiceSettings featurestoreServiceSettings = FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); @@ -67,13 +83,16 @@ static void createFeatureSample(String project, String featurestoreId, String en try (FeaturestoreServiceClient featurestoreServiceClient = FeaturestoreServiceClient.create(featurestoreServiceSettings)) { - Feature feature = Feature.newBuilder().setDescription(description) - .setValueType(valueType) - .build(); + Feature feature = + Feature.newBuilder().setDescription(description).setValueType(valueType).build(); - CreateFeatureRequest createFeatureRequest = CreateFeatureRequest.newBuilder() - .setParent(EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) - .setFeature(feature).setFeatureId(featureId).build(); + CreateFeatureRequest createFeatureRequest = + CreateFeatureRequest.newBuilder() + .setParent( + EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) + .setFeature(feature) + .setFeatureId(featureId) + .build(); OperationFuture featureFuture = featurestoreServiceClient.createFeatureAsync(createFeatureRequest); @@ -87,4 +106,3 @@ static void createFeatureSample(String project, String featurestoreId, String en } } // [END aiplatform_create_feature_sample] - diff --git a/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java b/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java index 062840051..bc77d5c80 100644 --- a/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java +++ b/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java @@ -15,7 +15,7 @@ * * * Delete a single feature from an existing entity type. 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 */ @@ -48,12 +48,18 @@ public static void main(String[] args) String endpoint = "us-central1-aiplatform.googleapis.com:443"; int timeout = 300; - deleteFeatureSample(project, featurestoreId, entityTypeId, featureId, location, endpoint, - timeout); + deleteFeatureSample( + project, featurestoreId, entityTypeId, featureId, location, endpoint, timeout); } - static void deleteFeatureSample(String project, String featurestoreId, String entityTypeId, - String featureId, String location, String endpoint, int timeout) + static void deleteFeatureSample( + String project, + String featurestoreId, + String entityTypeId, + String featureId, + String location, + String endpoint, + int timeout) throws IOException, InterruptedException, ExecutionException, TimeoutException { FeaturestoreServiceSettings featurestoreServiceSettings = FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); @@ -64,10 +70,12 @@ static void deleteFeatureSample(String project, String featurestoreId, String en try (FeaturestoreServiceClient featurestoreServiceClient = FeaturestoreServiceClient.create(featurestoreServiceSettings)) { - DeleteFeatureRequest deleteFeatureRequest = DeleteFeatureRequest.newBuilder() - .setName( - FeatureName.of(project, location, featurestoreId, entityTypeId, featureId).toString()) - .build(); + DeleteFeatureRequest deleteFeatureRequest = + DeleteFeatureRequest.newBuilder() + .setName( + FeatureName.of(project, location, featurestoreId, entityTypeId, featureId) + .toString()) + .build(); OperationFuture operationFuture = featurestoreServiceClient.deleteFeatureAsync(deleteFeatureRequest); @@ -80,4 +88,3 @@ static void deleteFeatureSample(String project, String featurestoreId, String en } } // [END aiplatform_delete_feature_sample] - diff --git a/samples/snippets/src/main/java/aiplatform/GetFeatureSample.java b/samples/snippets/src/main/java/aiplatform/GetFeatureSample.java index 697aab41b..f7e38adf1 100644 --- a/samples/snippets/src/main/java/aiplatform/GetFeatureSample.java +++ b/samples/snippets/src/main/java/aiplatform/GetFeatureSample.java @@ -14,8 +14,8 @@ * limitations under the License. * * - * Get feature details. See - * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * Get feature details. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running * the code snippet */ @@ -44,8 +44,14 @@ public static void main(String[] args) throws IOException { getFeatureSample(project, featurestoreId, entityTypeId, featureId, location, endpoint); } - static void getFeatureSample(String project, String featurestoreId, String entityTypeId, - String featureId, String location, String endpoint) throws IOException { + static void getFeatureSample( + String project, + String featurestoreId, + String entityTypeId, + String featureId, + String location, + String endpoint) + throws IOException { FeaturestoreServiceSettings featurestoreServiceSettings = FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); @@ -56,10 +62,12 @@ static void getFeatureSample(String project, String featurestoreId, String entit try (FeaturestoreServiceClient featurestoreServiceClient = FeaturestoreServiceClient.create(featurestoreServiceSettings)) { - GetFeatureRequest getFeatureRequest = GetFeatureRequest.newBuilder() - .setName( - FeatureName.of(project, location, featurestoreId, entityTypeId, featureId).toString()) - .build(); + GetFeatureRequest getFeatureRequest = + GetFeatureRequest.newBuilder() + .setName( + FeatureName.of(project, location, featurestoreId, entityTypeId, featureId) + .toString()) + .build(); Feature feature = featurestoreServiceClient.getFeature(getFeatureRequest); System.out.println("Get Feature Response"); @@ -69,4 +77,3 @@ static void getFeatureSample(String project, String featurestoreId, String entit } } // [END aiplatform_get_feature_sample] - diff --git a/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java b/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java index 6a38e81df..5cc41ec8c 100644 --- a/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java +++ b/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java @@ -14,8 +14,8 @@ * limitations under the License. * * - * List available feature details. See - * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * List available feature details. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running * the code snippet */ @@ -45,8 +45,9 @@ public static void main(String[] args) throws IOException { listFeaturesAsyncSample(project, featurestoreId, entityTypeId, location, endpoint); } - static void listFeaturesAsyncSample(String project, String featurestoreId, String entityTypeId, - String location, String endpoint) throws IOException { + static void listFeaturesAsyncSample( + String project, String featurestoreId, String entityTypeId, String location, String endpoint) + throws IOException { FeaturestoreServiceSettings featurestoreServiceSettings = FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); @@ -56,9 +57,11 @@ static void listFeaturesAsyncSample(String project, String featurestoreId, Strin try (FeaturestoreServiceClient featurestoreServiceClient = FeaturestoreServiceClient.create(featurestoreServiceSettings)) { - ListFeaturesRequest listFeaturesRequest = ListFeaturesRequest.newBuilder() - .setParent(EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) - .build(); + ListFeaturesRequest listFeaturesRequest = + ListFeaturesRequest.newBuilder() + .setParent( + EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) + .build(); System.out.println("List Features Async Response"); while (true) { ListFeaturesResponse listFeaturesResponse = @@ -78,4 +81,3 @@ static void listFeaturesAsyncSample(String project, String featurestoreId, Strin } } // [END aiplatform_list_features_async_sample] - diff --git a/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java b/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java index cdd76c494..b17eeb35e 100644 --- a/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java +++ b/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java @@ -14,8 +14,8 @@ * limitations under the License. * * - * List available feature details. See - * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * List available feature details. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running * the code snippet */ @@ -43,8 +43,9 @@ public static void main(String[] args) throws IOException { listFeaturesSample(project, featurestoreId, entityTypeId, location, endpoint); } - static void listFeaturesSample(String project, String featurestoreId, String entityTypeId, - String location, String endpoint) throws IOException { + static void listFeaturesSample( + String project, String featurestoreId, String entityTypeId, String location, String endpoint) + throws IOException { FeaturestoreServiceSettings featurestoreServiceSettings = FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); @@ -54,12 +55,14 @@ static void listFeaturesSample(String project, String featurestoreId, String ent try (FeaturestoreServiceClient featurestoreServiceClient = FeaturestoreServiceClient.create(featurestoreServiceSettings)) { - ListFeaturesRequest listFeaturesRequest = ListFeaturesRequest.newBuilder() - .setParent(EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) - .build(); + ListFeaturesRequest listFeaturesRequest = + ListFeaturesRequest.newBuilder() + .setParent( + EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) + .build(); System.out.println("List Features Response"); - for (Feature element : featurestoreServiceClient.listFeatures(listFeaturesRequest) - .iterateAll()) { + for (Feature element : + featurestoreServiceClient.listFeatures(listFeaturesRequest).iterateAll()) { System.out.println(element); } featurestoreServiceClient.close(); @@ -67,4 +70,3 @@ static void listFeaturesSample(String project, String featurestoreId, String ent } } // [END aiplatform_list_features_sample] - diff --git a/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.java b/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.java index ebb2d0ea1..595fe18c5 100644 --- a/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.java +++ b/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.java @@ -14,8 +14,8 @@ * limitations under the License. * * - * Search for featurestore resources. See - * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * Search for featurestore resources. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running * the code snippet */ @@ -34,8 +34,7 @@ public class SearchFeaturesAsyncSample { - public static void main(String[] args) - throws IOException { + public static void main(String[] args) throws IOException { // TODO(developer): Replace these variables before running the sample. String project = "YOUR_PROJECT_ID"; String query = "YOUR_QUERY"; @@ -44,8 +43,8 @@ public static void main(String[] args) searchFeaturesAsyncSample(project, query, location, endpoint); } - static void searchFeaturesAsyncSample(String project, String query, String location, - String endpoint) throws IOException { + static void searchFeaturesAsyncSample( + String project, String query, String location, String endpoint) throws IOException { FeaturestoreServiceSettings featurestoreServiceSettings = FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); @@ -55,8 +54,11 @@ static void searchFeaturesAsyncSample(String project, String query, String locat try (FeaturestoreServiceClient featurestoreServiceClient = FeaturestoreServiceClient.create(featurestoreServiceSettings)) { - SearchFeaturesRequest searchFeaturesRequest = SearchFeaturesRequest.newBuilder() - .setLocation(LocationName.of(project, location).toString()).setQuery(query).build(); + SearchFeaturesRequest searchFeaturesRequest = + SearchFeaturesRequest.newBuilder() + .setLocation(LocationName.of(project, location).toString()) + .setQuery(query) + .build(); System.out.println("Search Features Async Response"); while (true) { SearchFeaturesResponse response = @@ -77,4 +79,3 @@ static void searchFeaturesAsyncSample(String project, String query, String locat } } // [END aiplatform_search_features_async_sample] - diff --git a/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.java b/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.java index 084b9e99e..62309a5a9 100644 --- a/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.java +++ b/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.java @@ -14,8 +14,8 @@ * limitations under the License. * * - * Search for featurestore resources. See - * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * Search for featurestore resources. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running * the code snippet */ @@ -52,11 +52,14 @@ static void searchFeaturesSample(String project, String query, String location, try (FeaturestoreServiceClient featurestoreServiceClient = FeaturestoreServiceClient.create(featurestoreServiceSettings)) { - SearchFeaturesRequest searchFeaturesRequest = SearchFeaturesRequest.newBuilder() - .setLocation(LocationName.of(project, location).toString()).setQuery(query).build(); + SearchFeaturesRequest searchFeaturesRequest = + SearchFeaturesRequest.newBuilder() + .setLocation(LocationName.of(project, location).toString()) + .setQuery(query) + .build(); System.out.println("Search Features Response"); - for (Feature element : featurestoreServiceClient.searchFeatures(searchFeaturesRequest) - .iterateAll()) { + for (Feature element : + featurestoreServiceClient.searchFeatures(searchFeaturesRequest).iterateAll()) { System.out.println(element); } featurestoreServiceClient.close(); @@ -64,4 +67,3 @@ static void searchFeaturesSample(String project, String query, String location, } } // [END aiplatform_search_features_sample] - diff --git a/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java b/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java index 68d1f12d6..a68ada038 100644 --- a/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java +++ b/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java @@ -14,8 +14,8 @@ * limitations under the License. * * - * Update feature. See - * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * Update feature. 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 { updateFeatureSample(project, featurestoreId, entityTypeId, featureId, location, endpoint); } - static void updateFeatureSample(String project, String featurestoreId, String entityTypeId, - String featureId, String location, String endpoint) throws IOException { + static void updateFeatureSample( + String project, + String featurestoreId, + String entityTypeId, + String featureId, + String location, + String endpoint) + throws IOException { FeaturestoreServiceSettings featurestoreServiceSettings = FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); @@ -54,10 +60,13 @@ static void updateFeatureSample(String project, String featurestoreId, String en try (FeaturestoreServiceClient featurestoreServiceClient = FeaturestoreServiceClient.create(featurestoreServiceSettings)) { - Feature feature = Feature.newBuilder() - .setName( - FeatureName.of(project, location, featurestoreId, entityTypeId, featureId).toString()) - .setDescription("sample feature title updated").build(); + Feature feature = + Feature.newBuilder() + .setName( + FeatureName.of(project, location, featurestoreId, entityTypeId, featureId) + .toString()) + .setDescription("sample feature title updated") + .build(); UpdateFeatureRequest request = UpdateFeatureRequest.newBuilder().setFeature(feature).build(); Feature featureResponse = featurestoreServiceClient.updateFeature(request); @@ -68,4 +77,3 @@ static void updateFeatureSample(String project, String featurestoreId, String en } } // [END aiplatform_update_feature_sample] - diff --git a/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java b/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java index fcd4faec7..47bb8a401 100644 --- a/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java +++ b/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java @@ -69,19 +69,19 @@ public void setUp() { 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, 300); + DeleteFeaturestoreSample.deleteFeaturestoreSample( + PROJECT_ID, featurestoreId, USE_FORCE, LOCATION, ENDPOINT, 300); // Assert String deleteFeaturestoreResponse = bout.toString(); assertThat(deleteFeaturestoreResponse).contains("Deleted Featurestore"); - + System.out.flush(); System.setOut(originalPrintStream); } @@ -101,12 +101,12 @@ public void testFeatureSamples() 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, 900); + CreateEntityTypeSample.createEntityTypeSample( + PROJECT_ID, featurestoreId, entityTypeId, DESCRIPTION, LOCATION, ENDPOINT, 900); // Assert String createEntityTypeResponse = bout.toString(); @@ -115,59 +115,65 @@ public void testFeatureSamples() // Create the feature String featureTempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 26); String featureId = String.format("temp_create_feature_test_%s", featureTempUuid); - CreateFeatureSample.createFeatureSample(PROJECT_ID, featurestoreId, entityTypeId, featureId, - DESCRIPTION, VALUE_TYPE, LOCATION, ENDPOINT, 900); + CreateFeatureSample.createFeatureSample( + PROJECT_ID, + featurestoreId, + entityTypeId, + featureId, + DESCRIPTION, + VALUE_TYPE, + LOCATION, + ENDPOINT, + 900); // Assert String createFeatureResponse = bout.toString(); assertThat(createFeatureResponse).contains("Create Feature Response"); - + // Get the feature - GetFeatureSample.getFeatureSample(PROJECT_ID, featurestoreId, entityTypeId, featureId, LOCATION, - ENDPOINT); + GetFeatureSample.getFeatureSample( + PROJECT_ID, featurestoreId, entityTypeId, featureId, LOCATION, ENDPOINT); // Assert String getFeatureResponse = bout.toString(); assertThat(getFeatureResponse).contains("Get Feature Response"); // List features - ListFeaturesSample.listFeaturesSample(PROJECT_ID, featurestoreId, entityTypeId, LOCATION, - ENDPOINT); + ListFeaturesSample.listFeaturesSample( + PROJECT_ID, featurestoreId, entityTypeId, LOCATION, ENDPOINT); // Assert String listfeatureResponse = bout.toString(); assertThat(listfeatureResponse).contains("List Features Response"); // List features - ListFeaturesAsyncSample.listFeaturesAsyncSample(PROJECT_ID, featurestoreId, entityTypeId, - LOCATION, ENDPOINT); + ListFeaturesAsyncSample.listFeaturesAsyncSample( + PROJECT_ID, featurestoreId, entityTypeId, LOCATION, ENDPOINT); // Assert String listfeatureAsyncResponse = bout.toString(); assertThat(listfeatureAsyncResponse).contains("List Features Async Response"); - + // Search features SearchFeaturesSample.searchFeaturesSample(PROJECT_ID, QUERY, LOCATION, ENDPOINT); // Assert String searchFeaturesResponse = bout.toString(); assertThat(searchFeaturesResponse).contains("Search Features Response"); - + // Search features SearchFeaturesAsyncSample.searchFeaturesAsyncSample(PROJECT_ID, QUERY, LOCATION, ENDPOINT); // Assert String searchFeaturesAsyncResponse = bout.toString(); assertThat(searchFeaturesAsyncResponse).contains("Search Features Async Response"); - + // Delete the feature - DeleteFeatureSample.deleteFeatureSample(PROJECT_ID, featurestoreId, entityTypeId, featureId, - LOCATION, ENDPOINT, 300); + DeleteFeatureSample.deleteFeatureSample( + PROJECT_ID, featurestoreId, entityTypeId, featureId, LOCATION, ENDPOINT, 300); // Assert String deleteFeatureResponse = bout.toString(); assertThat(deleteFeatureResponse).contains("Deleted Feature"); - } } - From 96c42a9e11a17f35c80b1b53d2653a909ebc4884 Mon Sep 17 00:00:00 2001 From: sai-chaithu Date: Wed, 27 Jul 2022 14:35:48 +0530 Subject: [PATCH 5/5] feat(samples): update test with fixed featurestoreId --- .../java/aiplatform/FeatureSamplesTest.java | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java b/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java index 47bb8a401..a0f939675 100644 --- a/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java +++ b/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java @@ -37,18 +37,15 @@ public class FeatureSamplesTest { 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 ValueType VALUE_TYPE = ValueType.STRING; private static final String DESCRIPTION = "Test Description"; - private static final boolean USE_FORCE = true; private static final String QUERY = "value_type=STRING"; private static final String LOCATION = "us-central1"; private static final String ENDPOINT = "us-central1-aiplatform.googleapis.com:443"; private ByteArrayOutputStream bout; private PrintStream out; private PrintStream originalPrintStream; - private String featurestoreId; + private String featurestoreId = "featurestore_sample"; private static void requireEnvVar(String varName) { String errorMessage = @@ -74,14 +71,6 @@ public void setUp() { public void tearDown() throws InterruptedException, ExecutionException, IOException, TimeoutException { - // Delete the featurestore - DeleteFeaturestoreSample.deleteFeaturestoreSample( - PROJECT_ID, featurestoreId, USE_FORCE, LOCATION, ENDPOINT, 300); - - // Assert - String deleteFeaturestoreResponse = bout.toString(); - assertThat(deleteFeaturestoreResponse).contains("Deleted Featurestore"); - System.out.flush(); System.setOut(originalPrintStream); } @@ -89,18 +78,6 @@ public void tearDown() @Test public void testFeatureSamples() 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, 900); - - // 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);