diff --git a/java-aiplatform/README.md b/java-aiplatform/README.md index a3059d27e713..f0d29d00b215 100644 --- a/java-aiplatform/README.md +++ b/java-aiplatform/README.md @@ -118,6 +118,8 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-aiplatform/tr | Create Dataset Text Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CreateDatasetTextSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CreateDatasetTextSample.java) | | Create Dataset Video Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CreateDatasetVideoSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CreateDatasetVideoSample.java) | | Create Endpoint Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CreateEndpointSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CreateEndpointSample.java) | +| Create Entity Type Monitoring Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java) | +| Create Entity Type Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java) | | Create Featurestore Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CreateFeaturestoreSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CreateFeaturestoreSample.java) | | Create Hyperparameter Tuning Job Python Package Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CreateHyperparameterTuningJobPythonPackageSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CreateHyperparameterTuningJobPythonPackageSample.java) | | Create Hyperparameter Tuning Job Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CreateHyperparameterTuningJobSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CreateHyperparameterTuningJobSample.java) | @@ -138,6 +140,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-aiplatform/tr | Delete Data Labeling Job Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeleteDataLabelingJobSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/DeleteDataLabelingJobSample.java) | | Delete Dataset Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeleteDatasetSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/DeleteDatasetSample.java) | | Delete Endpoint Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeleteEndpointSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/DeleteEndpointSample.java) | +| Delete Entity Type Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java) | | Delete Export Model Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeleteExportModelSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/DeleteExportModelSample.java) | | Delete Featurestore Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeleteFeaturestoreSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/DeleteFeaturestoreSample.java) | | Delete Model Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeleteModelSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/DeleteModelSample.java) | @@ -148,6 +151,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-aiplatform/tr | Export Model Tabular Classification Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ExportModelTabularClassificationSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ExportModelTabularClassificationSample.java) | | Export Model Video Action Recognition Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ExportModelVideoActionRecognitionSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ExportModelVideoActionRecognitionSample.java) | | Get Batch Prediction Job Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/GetBatchPredictionJobSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/GetBatchPredictionJobSample.java) | +| Get Entity Type Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.java) | | Get Hyperparameter Tuning Job Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/GetHyperparameterTuningJobSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/GetHyperparameterTuningJobSample.java) | | Get Model Evaluation Image Classification Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/GetModelEvaluationImageClassificationSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/GetModelEvaluationImageClassificationSample.java) | | Get Model Evaluation Image Object Detection Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/GetModelEvaluationImageObjectDetectionSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/GetModelEvaluationImageObjectDetectionSample.java) | @@ -171,6 +175,8 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-aiplatform/tr | Import Data Video Action Recognition Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ImportDataVideoActionRecognitionSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ImportDataVideoActionRecognitionSample.java) | | Import Data Video Classification Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ImportDataVideoClassificationSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ImportDataVideoClassificationSample.java) | | Import Data Video Object Tracking Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ImportDataVideoObjectTrackingSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ImportDataVideoObjectTrackingSample.java) | +| List Entity Types Async Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java) | +| List Entity Types Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java) | | List Model Evaluation Slice Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ListModelEvaluationSliceSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ListModelEvaluationSliceSample.java) | | Predict Custom Trained Model Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/PredictCustomTrainedModelSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/PredictCustomTrainedModelSample.java) | | Predict Image Classification Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/PredictImageClassificationSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/PredictImageClassificationSample.java) | @@ -181,6 +187,8 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-aiplatform/tr | Predict Text Entity Extraction Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/PredictTextEntityExtractionSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/PredictTextEntityExtractionSample.java) | | Predict Text Sentiment Analysis Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/PredictTextSentimentAnalysisSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/PredictTextSentimentAnalysisSample.java) | | Undeploy Model Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/UndeployModelSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/UndeployModelSample.java) | +| Update Entity Type Monitoring Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java) | +| Update Entity Type Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java) | | Upload Model Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/UploadModelSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/UploadModelSample.java) | diff --git a/java-aiplatform/samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java b/java-aiplatform/samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java new file mode 100644 index 000000000000..b234d032497c --- /dev/null +++ b/java-aiplatform/samples/snippets/src/main/java/aiplatform/CreateEntityTypeMonitoringSample.java @@ -0,0 +1,114 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * Create an entity type so that you can create its related features. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_create_entity_type_monitoring_sample] + +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.aiplatform.v1.CreateEntityTypeOperationMetadata; +import com.google.cloud.aiplatform.v1.CreateEntityTypeRequest; +import com.google.cloud.aiplatform.v1.EntityType; +import com.google.cloud.aiplatform.v1.FeaturestoreMonitoringConfig; +import com.google.cloud.aiplatform.v1.FeaturestoreMonitoringConfig.SnapshotAnalysis; +import com.google.cloud.aiplatform.v1.FeaturestoreName; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class CreateEntityTypeMonitoringSample { + + public static void main(String[] args) + throws IOException, InterruptedException, ExecutionException, TimeoutException { + // TODO(developer): Replace these variables before running the sample. + String project = "YOUR_PROJECT_ID"; + String featurestoreId = "YOUR_FEATURESTORE_ID"; + String entityTypeId = "YOUR_ENTITY_TYPE_ID"; + String description = "YOUR_ENTITY_TYPE_DESCRIPTION"; + int monitoringIntervalDays = 1; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + int timeout = 300; + createEntityTypeMonitoringSample( + project, + featurestoreId, + entityTypeId, + description, + monitoringIntervalDays, + location, + endpoint, + timeout); + } + + static void createEntityTypeMonitoringSample( + String project, + String featurestoreId, + String entityTypeId, + String description, + int monitoringIntervalDays, + String location, + String endpoint, + int timeout) + throws IOException, InterruptedException, ExecutionException, TimeoutException { + + FeaturestoreServiceSettings featurestoreServiceSettings = + FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); + + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. After completing all of your requests, call + // the "close" method on the client to safely clean up any remaining background resources. + try (FeaturestoreServiceClient featurestoreServiceClient = + FeaturestoreServiceClient.create(featurestoreServiceSettings)) { + + FeaturestoreMonitoringConfig featurestoreMonitoringConfig = + FeaturestoreMonitoringConfig.newBuilder() + .setSnapshotAnalysis( + SnapshotAnalysis.newBuilder().setMonitoringIntervalDays(monitoringIntervalDays)) + .build(); + + EntityType entityType = + EntityType.newBuilder() + .setDescription(description) + .setMonitoringConfig(featurestoreMonitoringConfig) + .build(); + + CreateEntityTypeRequest createEntityTypeRequest = + CreateEntityTypeRequest.newBuilder() + .setParent(FeaturestoreName.of(project, location, featurestoreId).toString()) + .setEntityType(entityType) + .setEntityTypeId(entityTypeId) + .build(); + + OperationFuture entityTypeFuture = + featurestoreServiceClient.createEntityTypeAsync(createEntityTypeRequest); + System.out.format( + "Operation name: %s%n", entityTypeFuture.getInitialFuture().get().getName()); + System.out.println("Waiting for operation to finish..."); + EntityType entityTypeResponse = entityTypeFuture.get(timeout, TimeUnit.SECONDS); + System.out.println("Create Entity Type Monitoring Response"); + System.out.format("Name: %s%n", entityTypeResponse.getName()); + } + } +} +// [END aiplatform_create_entity_type_monitoring_sample] diff --git a/java-aiplatform/samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java b/java-aiplatform/samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java new file mode 100644 index 000000000000..012ac19615ec --- /dev/null +++ b/java-aiplatform/samples/snippets/src/main/java/aiplatform/CreateEntityTypeSample.java @@ -0,0 +1,93 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * Create an entity type so that you can create its related features. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_create_entity_type_sample] + +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.aiplatform.v1.CreateEntityTypeOperationMetadata; +import com.google.cloud.aiplatform.v1.CreateEntityTypeRequest; +import com.google.cloud.aiplatform.v1.EntityType; +import com.google.cloud.aiplatform.v1.FeaturestoreName; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class CreateEntityTypeSample { + + public static void main(String[] args) + throws IOException, InterruptedException, ExecutionException, TimeoutException { + // TODO(developer): Replace these variables before running the sample. + String project = "YOUR_PROJECT_ID"; + String featurestoreId = "YOUR_FEATURESTORE_ID"; + String entityTypeId = "YOUR_ENTITY_TYPE_ID"; + String description = "YOUR_ENTITY_TYPE_DESCRIPTION"; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + int timeout = 300; + createEntityTypeSample( + project, featurestoreId, entityTypeId, description, location, endpoint, timeout); + } + + static void createEntityTypeSample( + String project, + String featurestoreId, + String entityTypeId, + String description, + String location, + String endpoint, + int timeout) + throws IOException, InterruptedException, ExecutionException, TimeoutException { + + FeaturestoreServiceSettings featurestoreServiceSettings = + FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); + + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. After completing all of your requests, call + // the "close" method on the client to safely clean up any remaining background resources. + try (FeaturestoreServiceClient featurestoreServiceClient = + FeaturestoreServiceClient.create(featurestoreServiceSettings)) { + + EntityType entityType = EntityType.newBuilder().setDescription(description).build(); + + CreateEntityTypeRequest createEntityTypeRequest = + CreateEntityTypeRequest.newBuilder() + .setParent(FeaturestoreName.of(project, location, featurestoreId).toString()) + .setEntityType(entityType) + .setEntityTypeId(entityTypeId) + .build(); + + OperationFuture entityTypeFuture = + featurestoreServiceClient.createEntityTypeAsync(createEntityTypeRequest); + System.out.format( + "Operation name: %s%n", entityTypeFuture.getInitialFuture().get().getName()); + System.out.println("Waiting for operation to finish..."); + EntityType entityTypeResponse = entityTypeFuture.get(timeout, TimeUnit.SECONDS); + System.out.println("Create Entity Type Response"); + System.out.format("Name: %s%n", entityTypeResponse.getName()); + } + } +} +// [END aiplatform_create_entity_type_sample] diff --git a/java-aiplatform/samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java b/java-aiplatform/samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java new file mode 100644 index 000000000000..00e7c5e36af8 --- /dev/null +++ b/java-aiplatform/samples/snippets/src/main/java/aiplatform/DeleteEntityTypeSample.java @@ -0,0 +1,87 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * Delete an entity type from featurestore resource. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_delete_entity_type_sample] + +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.aiplatform.v1.DeleteEntityTypeRequest; +import com.google.cloud.aiplatform.v1.DeleteOperationMetadata; +import com.google.cloud.aiplatform.v1.EntityTypeName; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import com.google.protobuf.Empty; +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class DeleteEntityTypeSample { + + public static void main(String[] args) + throws IOException, InterruptedException, ExecutionException, TimeoutException { + // TODO(developer): Replace these variables before running the sample. + String project = "YOUR_PROJECT_ID"; + String featurestoreId = "YOUR_FEATURESTORE_ID"; + String entityTypeId = "YOUR_ENTITY_TYPE_ID"; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + int timeout = 300; + deleteEntityTypeSample(project, featurestoreId, entityTypeId, location, endpoint, timeout); + } + + static void deleteEntityTypeSample( + String project, + String featurestoreId, + String entityTypeId, + String location, + String endpoint, + int timeout) + throws IOException, InterruptedException, ExecutionException, TimeoutException { + + FeaturestoreServiceSettings featurestoreServiceSettings = + FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); + + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. After completing all of your requests, call + // the "close" method on the client to safely clean up any remaining background resources. + try (FeaturestoreServiceClient featurestoreServiceClient = + FeaturestoreServiceClient.create(featurestoreServiceSettings)) { + + DeleteEntityTypeRequest deleteEntityTypeRequest = + DeleteEntityTypeRequest.newBuilder() + .setName( + EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) + .setForce(true) + .build(); + + OperationFuture operationFuture = + featurestoreServiceClient.deleteEntityTypeAsync(deleteEntityTypeRequest); + System.out.format("Operation name: %s%n", operationFuture.getInitialFuture().get().getName()); + System.out.println("Waiting for operation to finish..."); + operationFuture.get(timeout, TimeUnit.SECONDS); + + System.out.format("Deleted Entity Type."); + } + } +} +// [END aiplatform_delete_entity_type_sample] diff --git a/java-aiplatform/samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.java b/java-aiplatform/samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.java new file mode 100644 index 000000000000..f9e83f223ba4 --- /dev/null +++ b/java-aiplatform/samples/snippets/src/main/java/aiplatform/GetEntityTypeSample.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 entity type details. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_get_entity_type_sample] + +import com.google.cloud.aiplatform.v1.EntityType; +import com.google.cloud.aiplatform.v1.EntityTypeName; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import com.google.cloud.aiplatform.v1.GetEntityTypeRequest; +import java.io.IOException; + +public class GetEntityTypeSample { + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String project = "YOUR_PROJECT_ID"; + String featurestoreId = "YOUR_FEATURESTORE_ID"; + String entityTypeId = "YOUR_ENTITY_TYPE_ID"; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + getEntityTypeSample(project, featurestoreId, entityTypeId, location, endpoint); + } + + static void getEntityTypeSample( + String project, String featurestoreId, String entityTypeId, String location, String endpoint) + throws IOException { + + FeaturestoreServiceSettings featurestoreServiceSettings = + FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); + + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. After completing all of your requests, call + // the "close" method on the client to safely clean up any remaining background resources. + try (FeaturestoreServiceClient featurestoreServiceClient = + FeaturestoreServiceClient.create(featurestoreServiceSettings)) { + + GetEntityTypeRequest getEntityTypeRequest = + GetEntityTypeRequest.newBuilder() + .setName( + EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) + .build(); + + EntityType entityType = featurestoreServiceClient.getEntityType(getEntityTypeRequest); + System.out.println("Get Entity Type Response"); + System.out.println(entityType); + } + } +} +// [END aiplatform_get_entity_type_sample] diff --git a/java-aiplatform/samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java b/java-aiplatform/samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java new file mode 100644 index 000000000000..b429a642c53d --- /dev/null +++ b/java-aiplatform/samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java @@ -0,0 +1,80 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * List available entity type details of an existing featurestore resource. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_list_entity_types_async_sample] + +import com.google.cloud.aiplatform.v1.EntityType; +import com.google.cloud.aiplatform.v1.FeaturestoreName; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import com.google.cloud.aiplatform.v1.ListEntityTypesRequest; +import com.google.cloud.aiplatform.v1.ListEntityTypesResponse; +import com.google.common.base.Strings; +import java.io.IOException; + +public class ListEntityTypesAsyncSample { + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String project = "YOUR_PROJECT_ID"; + String featurestoreId = "YOUR_FEATURESTORE_ID"; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + listEntityTypesAsyncSample(project, featurestoreId, location, endpoint); + } + + static void listEntityTypesAsyncSample( + String project, String featurestoreId, String location, String endpoint) throws IOException { + + FeaturestoreServiceSettings featurestoreServiceSettings = + FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); + + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. After completing all of your requests, call + // the "close" method on the client to safely clean up any remaining background resources. + try (FeaturestoreServiceClient featurestoreServiceClient = + FeaturestoreServiceClient.create(featurestoreServiceSettings)) { + + ListEntityTypesRequest listEntityTypeRequest = + ListEntityTypesRequest.newBuilder() + .setParent(FeaturestoreName.of(project, location, featurestoreId).toString()) + .build(); + System.out.println("List Entity Types Async Response"); + while (true) { + ListEntityTypesResponse listEntityTypesResponse = + featurestoreServiceClient.listEntityTypesCallable().call(listEntityTypeRequest); + for (EntityType element : listEntityTypesResponse.getEntityTypesList()) { + System.out.println(element); + } + String nextPageToken = listEntityTypesResponse.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + listEntityTypeRequest = + listEntityTypeRequest.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END aiplatform_list_entity_types_async_sample] diff --git a/java-aiplatform/samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java b/java-aiplatform/samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java new file mode 100644 index 000000000000..1160216c4b8e --- /dev/null +++ b/java-aiplatform/samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.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 entity type details of an existing featurestore resource. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_list_entity_types_sample] + +import com.google.cloud.aiplatform.v1.EntityType; +import com.google.cloud.aiplatform.v1.FeaturestoreName; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import com.google.cloud.aiplatform.v1.ListEntityTypesRequest; +import java.io.IOException; + +public class ListEntityTypesSample { + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String project = "YOUR_PROJECT_ID"; + String featurestoreId = "YOUR_FEATURESTORE_ID"; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + listEntityTypesSample(project, featurestoreId, location, endpoint); + } + + static void listEntityTypesSample( + String project, String featurestoreId, String location, String endpoint) throws IOException { + + FeaturestoreServiceSettings featurestoreServiceSettings = + FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); + + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. After completing all of your requests, call + // the "close" method on the client to safely clean up any remaining background resources. + try (FeaturestoreServiceClient featurestoreServiceClient = + FeaturestoreServiceClient.create(featurestoreServiceSettings)) { + + ListEntityTypesRequest listEntityTypeRequest = + ListEntityTypesRequest.newBuilder() + .setParent(FeaturestoreName.of(project, location, featurestoreId).toString()) + .build(); + System.out.println("List Entity Types Response"); + for (EntityType element : + featurestoreServiceClient.listEntityTypes(listEntityTypeRequest).iterateAll()) { + System.out.println(element); + } + } + } +} +// [END aiplatform_list_entity_types_sample] diff --git a/java-aiplatform/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java b/java-aiplatform/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java new file mode 100644 index 000000000000..3133b146f8b1 --- /dev/null +++ b/java-aiplatform/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeMonitoringSample.java @@ -0,0 +1,87 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * Update entity type. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_update_entity_type_monitoring_sample] + +import com.google.cloud.aiplatform.v1.EntityType; +import com.google.cloud.aiplatform.v1.EntityTypeName; +import com.google.cloud.aiplatform.v1.FeaturestoreMonitoringConfig; +import com.google.cloud.aiplatform.v1.FeaturestoreMonitoringConfig.SnapshotAnalysis; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import com.google.cloud.aiplatform.v1.UpdateEntityTypeRequest; +import java.io.IOException; + +public class UpdateEntityTypeMonitoringSample { + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String project = "YOUR_PROJECT_ID"; + String featurestoreId = "YOUR_FEATURESTORE_ID"; + String entityTypeId = "YOUR_ENTITY_TYPE_ID"; + int monitoringIntervalDays = 1; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + updateEntityTypeMonitoringSample( + project, featurestoreId, entityTypeId, monitoringIntervalDays, location, endpoint); + } + + static void updateEntityTypeMonitoringSample( + String project, + String featurestoreId, + String entityTypeId, + int monitoringIntervalDays, + String location, + String endpoint) + throws IOException { + + FeaturestoreServiceSettings featurestoreServiceSettings = + FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); + + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. After completing all of your requests, call + // the "close" method on the client to safely clean up any remaining background resources. + try (FeaturestoreServiceClient featurestoreServiceClient = + FeaturestoreServiceClient.create(featurestoreServiceSettings)) { + FeaturestoreMonitoringConfig featurestoreMonitoringConfig = + FeaturestoreMonitoringConfig.newBuilder() + .setSnapshotAnalysis( + SnapshotAnalysis.newBuilder().setMonitoringIntervalDays(monitoringIntervalDays)) + .build(); + EntityType entityType = + EntityType.newBuilder() + .setName( + EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) + .setMonitoringConfig(featurestoreMonitoringConfig) + .build(); + + UpdateEntityTypeRequest updateEntityTypeRequest = + UpdateEntityTypeRequest.newBuilder().setEntityType(entityType).build(); + EntityType entityTypeResponse = + featurestoreServiceClient.updateEntityType(updateEntityTypeRequest); + System.out.println("Update Entity Type Monitoring Response"); + System.out.println(entityTypeResponse); + } + } +} +// [END aiplatform_update_entity_type_monitoring_sample] diff --git a/java-aiplatform/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java b/java-aiplatform/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java new file mode 100644 index 000000000000..bd7af2650206 --- /dev/null +++ b/java-aiplatform/samples/snippets/src/main/java/aiplatform/UpdateEntityTypeSample.java @@ -0,0 +1,80 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * Update entity type. See + * https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +package aiplatform; + +// [START aiplatform_update_entity_type_sample] + +import com.google.cloud.aiplatform.v1.EntityType; +import com.google.cloud.aiplatform.v1.EntityTypeName; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; +import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; +import com.google.cloud.aiplatform.v1.UpdateEntityTypeRequest; +import java.io.IOException; + +public class UpdateEntityTypeSample { + + public static void main(String[] args) throws IOException { + // TODO(developer): Replace these variables before running the sample. + String project = "YOUR_PROJECT_ID"; + String featurestoreId = "YOUR_FEATURESTORE_ID"; + String entityTypeId = "YOUR_ENTITY_TYPE_ID"; + String description = "Update Description"; + String location = "us-central1"; + String endpoint = "us-central1-aiplatform.googleapis.com:443"; + updateEntityTypeSample(project, featurestoreId, entityTypeId, description, location, endpoint); + } + + static void updateEntityTypeSample( + String project, + String featurestoreId, + String entityTypeId, + String description, + String location, + String endpoint) + throws IOException { + + FeaturestoreServiceSettings featurestoreServiceSettings = + FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); + + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. After completing all of your requests, call + // the "close" method on the client to safely clean up any remaining background resources. + try (FeaturestoreServiceClient featurestoreServiceClient = + FeaturestoreServiceClient.create(featurestoreServiceSettings)) { + + EntityType entityType = + EntityType.newBuilder() + .setName( + EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString()) + .setDescription(description) + .build(); + + UpdateEntityTypeRequest updateEntityTypeRequest = + UpdateEntityTypeRequest.newBuilder().setEntityType(entityType).build(); + EntityType entityTypeResponse = + featurestoreServiceClient.updateEntityType(updateEntityTypeRequest); + System.out.println("Update Entity Type Response"); + System.out.println(entityTypeResponse); + } + } +} +// [END aiplatform_update_entity_type_sample] diff --git a/java-aiplatform/samples/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java b/java-aiplatform/samples/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java new file mode 100644 index 000000000000..41227c71c939 --- /dev/null +++ b/java-aiplatform/samples/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java @@ -0,0 +1,181 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package aiplatform; + +import static com.google.common.truth.Truth.assertThat; +import static junit.framework.TestCase.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class EntityTypeSamplesTest { + + private static final String PROJECT_ID = System.getenv("UCAIP_PROJECT_ID"); + private static final int MIN_NODE_COUNT = 1; + private static final int MAX_NODE_COUNT = 5; + private static final String DESCRIPTION = "Test Description"; + private static final int MONITORING_INTERVAL_DAYS = 1; + private static final boolean USE_FORCE = true; + private static final String LOCATION = "us-central1"; + private static final String ENDPOINT = "us-central1-aiplatform.googleapis.com:443"; + private static final int TIMEOUT = 900; + private ByteArrayOutputStream bout; + private PrintStream out; + private PrintStream originalPrintStream; + private String featurestoreId; + + private static void requireEnvVar(String varName) { + String errorMessage = + String.format("Environment variable '%s' is required to perform these tests.", varName); + assertNotNull(errorMessage, System.getenv(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnvVar("UCAIP_PROJECT_ID"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + originalPrintStream = System.out; + System.setOut(out); + } + + @After + public void tearDown() + throws InterruptedException, ExecutionException, IOException, TimeoutException { + + // Delete the featurestore + DeleteFeaturestoreSample.deleteFeaturestoreSample( + PROJECT_ID, featurestoreId, USE_FORCE, LOCATION, ENDPOINT, 60); + + // Assert + String deleteFeaturestoreResponse = bout.toString(); + assertThat(deleteFeaturestoreResponse).contains("Deleted Featurestore"); + System.out.flush(); + System.setOut(originalPrintStream); + } + + @Test + public void testEntityTypeSamples() + throws IOException, InterruptedException, ExecutionException, TimeoutException { + // Create the featurestore + String tempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 26); + String id = String.format("temp_create_featurestore_test_%s", tempUuid); + CreateFeaturestoreSample.createFeaturestoreSample( + PROJECT_ID, id, MIN_NODE_COUNT, MAX_NODE_COUNT, LOCATION, ENDPOINT, TIMEOUT); + + // Assert + String createFeaturestoreResponse = bout.toString(); + assertThat(createFeaturestoreResponse).contains("Create Featurestore Response"); + featurestoreId = + createFeaturestoreResponse.split("Name: ")[1].split("featurestores/")[1].split("\n")[0] + .trim(); + + // Create the entity type + String entityTypeTempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 16); + String entityTypeId = String.format("temp_create_entity_type_test_%s", entityTypeTempUuid); + CreateEntityTypeSample.createEntityTypeSample( + PROJECT_ID, featurestoreId, entityTypeId, DESCRIPTION, LOCATION, ENDPOINT, TIMEOUT); + + // Assert + String createEntityTypeResponse = bout.toString(); + assertThat(createEntityTypeResponse).contains("Create Entity Type Response"); + + // Get the entity type + GetEntityTypeSample.getEntityTypeSample( + PROJECT_ID, featurestoreId, entityTypeId, LOCATION, ENDPOINT); + + // Assert + String getEntityTypeResponse = bout.toString(); + assertThat(getEntityTypeResponse).contains("Get Entity Type Response"); + + // Create the entity type + String entityTypeMonitoringTempUuid = + UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 16); + String entityTypeMonitoringId = + String.format("temp_create_entity_type_test_%s", entityTypeMonitoringTempUuid); + CreateEntityTypeMonitoringSample.createEntityTypeMonitoringSample( + PROJECT_ID, + featurestoreId, + entityTypeMonitoringId, + DESCRIPTION, + MONITORING_INTERVAL_DAYS, + LOCATION, + ENDPOINT, + TIMEOUT); + + // Assert + String createEntityTypeMonitoringResponse = bout.toString(); + assertThat(createEntityTypeMonitoringResponse) + .contains("Create Entity Type Monitoring Response"); + + // List entity types + ListEntityTypesSample.listEntityTypesSample(PROJECT_ID, featurestoreId, LOCATION, ENDPOINT); + + // Assert + String listEntityTypeResponse = bout.toString(); + assertThat(listEntityTypeResponse).contains("List Entity Types Response"); + + // Update the entity type + UpdateEntityTypeSample.updateEntityTypeSample( + PROJECT_ID, featurestoreId, entityTypeId, DESCRIPTION, LOCATION, ENDPOINT); + + // Assert + String updateEntityTypeResponse = bout.toString(); + assertThat(updateEntityTypeResponse).contains("Update Entity Type Response"); + + // Update the entity type + UpdateEntityTypeMonitoringSample.updateEntityTypeMonitoringSample( + PROJECT_ID, featurestoreId, entityTypeId, MONITORING_INTERVAL_DAYS, LOCATION, ENDPOINT); + + // Assert + String updateEntityTypeMonitoringResponse = bout.toString(); + assertThat(updateEntityTypeMonitoringResponse) + .contains("Update Entity Type Monitoring Response"); + + // List entity types + ListEntityTypesAsyncSample.listEntityTypesAsyncSample( + PROJECT_ID, featurestoreId, LOCATION, ENDPOINT); + + // Assert + String listEntityTypeAsyncResponse = bout.toString(); + assertThat(listEntityTypeAsyncResponse).contains("List Entity Types Async Response"); + + // Delete the entity type + DeleteEntityTypeSample.deleteEntityTypeSample( + PROJECT_ID, featurestoreId, entityTypeId, LOCATION, ENDPOINT, TIMEOUT); + + // Assert + String deleteEntityTypeResponse = bout.toString(); + assertThat(deleteEntityTypeResponse).contains("Deleted Entity Type"); + } +}