Skip to content

Commit

Permalink
feat(samples): added all entity type samples (#976)
Browse files Browse the repository at this point in the history
* feat(samples): added all entity type samples

* feat(samples): update all entity type samples

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
sai-chaithu and gcf-owl-bot[bot] authored Jul 8, 2022
1 parent 4284464 commit f496d8a
Show file tree
Hide file tree
Showing 10 changed files with 868 additions and 0 deletions.
8 changes: 8 additions & 0 deletions java-aiplatform/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -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<EntityType, CreateEntityTypeOperationMetadata> 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]
Original file line number Diff line number Diff line change
@@ -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<EntityType, CreateEntityTypeOperationMetadata> 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]
Original file line number Diff line number Diff line change
@@ -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<Empty, DeleteOperationMetadata> 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]
Original file line number Diff line number Diff line change
@@ -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]
Loading

0 comments on commit f496d8a

Please sign in to comment.