diff --git a/java-aiplatform/README.md b/java-aiplatform/README.md index d86b7dda58c5..17acb0e266da 100644 --- a/java-aiplatform/README.md +++ b/java-aiplatform/README.md @@ -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/java-aiplatform/samples/snippets/src/main/java/aiplatform/CreateFeatureSample.java b/java-aiplatform/samples/snippets/src/main/java/aiplatform/CreateFeatureSample.java new file mode 100644 index 000000000000..10c18736f20f --- /dev/null +++ b/java-aiplatform/samples/snippets/src/main/java/aiplatform/CreateFeatureSample.java @@ -0,0 +1,108 @@ +/* + * 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"; + ValueType valueType = ValueType.STRING; + 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); + } + + 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(); + + // 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).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()); + featurestoreServiceClient.close(); + } + } +} +// [END aiplatform_create_feature_sample] diff --git a/java-aiplatform/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java b/java-aiplatform/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java new file mode 100644 index 000000000000..bc77d5c804e7 --- /dev/null +++ b/java-aiplatform/samples/snippets/src/main/java/aiplatform/DeleteFeatureSample.java @@ -0,0 +1,90 @@ +/* + * 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."); + featurestoreServiceClient.close(); + } + } +} +// [END aiplatform_delete_feature_sample] diff --git a/java-aiplatform/samples/snippets/src/main/java/aiplatform/GetFeatureSample.java b/java-aiplatform/samples/snippets/src/main/java/aiplatform/GetFeatureSample.java new file mode 100644 index 000000000000..f7e38adf1a9c --- /dev/null +++ b/java-aiplatform/samples/snippets/src/main/java/aiplatform/GetFeatureSample.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. + * + * + * 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); + featurestoreServiceClient.close(); + } + } +} +// [END aiplatform_get_feature_sample] diff --git a/java-aiplatform/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java b/java-aiplatform/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java new file mode 100644 index 000000000000..5cc41ec8cd7b --- /dev/null +++ b/java-aiplatform/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java @@ -0,0 +1,83 @@ +/* + * 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; + } + } + featurestoreServiceClient.close(); + } + } +} +// [END aiplatform_list_features_async_sample] diff --git a/java-aiplatform/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java b/java-aiplatform/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java new file mode 100644 index 000000000000..b17eeb35e488 --- /dev/null +++ b/java-aiplatform/samples/snippets/src/main/java/aiplatform/ListFeaturesSample.java @@ -0,0 +1,72 @@ +/* + * 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); + } + featurestoreServiceClient.close(); + } + } +} +// [END aiplatform_list_features_sample] diff --git a/java-aiplatform/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.java b/java-aiplatform/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.java new file mode 100644 index 000000000000..595fe18c533a --- /dev/null +++ b/java-aiplatform/samples/snippets/src/main/java/aiplatform/SearchFeaturesAsyncSample.java @@ -0,0 +1,81 @@ +/* + * 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; + } + } + featurestoreServiceClient.close(); + } + } +} +// [END aiplatform_search_features_async_sample] diff --git a/java-aiplatform/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.java b/java-aiplatform/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.java new file mode 100644 index 000000000000..62309a5a99ea --- /dev/null +++ b/java-aiplatform/samples/snippets/src/main/java/aiplatform/SearchFeaturesSample.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. + * + * + * 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); + } + featurestoreServiceClient.close(); + } + } +} +// [END aiplatform_search_features_sample] diff --git a/java-aiplatform/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java b/java-aiplatform/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java new file mode 100644 index 000000000000..a68ada038ac0 --- /dev/null +++ b/java-aiplatform/samples/snippets/src/main/java/aiplatform/UpdateFeatureSample.java @@ -0,0 +1,79 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * Update 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()); + featurestoreServiceClient.close(); + } + } +} +// [END aiplatform_update_feature_sample] diff --git a/java-aiplatform/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java b/java-aiplatform/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java new file mode 100644 index 000000000000..a0f939675611 --- /dev/null +++ b/java-aiplatform/samples/snippets/src/test/java/aiplatform/FeatureSamplesTest.java @@ -0,0 +1,156 @@ +/* + * 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.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.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 ValueType VALUE_TYPE = ValueType.STRING; + private static final String DESCRIPTION = "Test Description"; + 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 = "featurestore_sample"; + + private static void requireEnvVar(String varName) { + String errorMessage = + String.format("Environment variable '%s' is required to perform these tests.", varName); + assertNotNull(errorMessage, System.getenv(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnvVar("UCAIP_PROJECT_ID"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + originalPrintStream = System.out; + System.setOut(out); + } + + @After + public void tearDown() + throws InterruptedException, ExecutionException, IOException, TimeoutException { + + System.out.flush(); + System.setOut(originalPrintStream); + } + + @Test + public void testFeatureSamples() + throws IOException, InterruptedException, ExecutionException, TimeoutException { + + // 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); + + // 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, + 900); + + // 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, 300); + + // Assert + String deleteFeatureResponse = bout.toString(); + assertThat(deleteFeatureResponse).contains("Deleted Feature"); + } +}