Skip to content

Commit f496d8a

Browse files
feat(samples): added all entity type samples (#976)
* 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>
1 parent 4284464 commit f496d8a

10 files changed

+868
-0
lines changed

java-aiplatform/README.md

+8
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*
17+
* Create an entity type so that you can create its related features. See
18+
* https://cloud.google.com/vertex-ai/docs/featurestore/setup before running
19+
* the code snippet
20+
*/
21+
22+
package aiplatform;
23+
24+
// [START aiplatform_create_entity_type_monitoring_sample]
25+
26+
import com.google.api.gax.longrunning.OperationFuture;
27+
import com.google.cloud.aiplatform.v1.CreateEntityTypeOperationMetadata;
28+
import com.google.cloud.aiplatform.v1.CreateEntityTypeRequest;
29+
import com.google.cloud.aiplatform.v1.EntityType;
30+
import com.google.cloud.aiplatform.v1.FeaturestoreMonitoringConfig;
31+
import com.google.cloud.aiplatform.v1.FeaturestoreMonitoringConfig.SnapshotAnalysis;
32+
import com.google.cloud.aiplatform.v1.FeaturestoreName;
33+
import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient;
34+
import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings;
35+
import java.io.IOException;
36+
import java.util.concurrent.ExecutionException;
37+
import java.util.concurrent.TimeUnit;
38+
import java.util.concurrent.TimeoutException;
39+
40+
public class CreateEntityTypeMonitoringSample {
41+
42+
public static void main(String[] args)
43+
throws IOException, InterruptedException, ExecutionException, TimeoutException {
44+
// TODO(developer): Replace these variables before running the sample.
45+
String project = "YOUR_PROJECT_ID";
46+
String featurestoreId = "YOUR_FEATURESTORE_ID";
47+
String entityTypeId = "YOUR_ENTITY_TYPE_ID";
48+
String description = "YOUR_ENTITY_TYPE_DESCRIPTION";
49+
int monitoringIntervalDays = 1;
50+
String location = "us-central1";
51+
String endpoint = "us-central1-aiplatform.googleapis.com:443";
52+
int timeout = 300;
53+
createEntityTypeMonitoringSample(
54+
project,
55+
featurestoreId,
56+
entityTypeId,
57+
description,
58+
monitoringIntervalDays,
59+
location,
60+
endpoint,
61+
timeout);
62+
}
63+
64+
static void createEntityTypeMonitoringSample(
65+
String project,
66+
String featurestoreId,
67+
String entityTypeId,
68+
String description,
69+
int monitoringIntervalDays,
70+
String location,
71+
String endpoint,
72+
int timeout)
73+
throws IOException, InterruptedException, ExecutionException, TimeoutException {
74+
75+
FeaturestoreServiceSettings featurestoreServiceSettings =
76+
FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build();
77+
78+
// Initialize client that will be used to send requests. This client only needs to be created
79+
// once, and can be reused for multiple requests. After completing all of your requests, call
80+
// the "close" method on the client to safely clean up any remaining background resources.
81+
try (FeaturestoreServiceClient featurestoreServiceClient =
82+
FeaturestoreServiceClient.create(featurestoreServiceSettings)) {
83+
84+
FeaturestoreMonitoringConfig featurestoreMonitoringConfig =
85+
FeaturestoreMonitoringConfig.newBuilder()
86+
.setSnapshotAnalysis(
87+
SnapshotAnalysis.newBuilder().setMonitoringIntervalDays(monitoringIntervalDays))
88+
.build();
89+
90+
EntityType entityType =
91+
EntityType.newBuilder()
92+
.setDescription(description)
93+
.setMonitoringConfig(featurestoreMonitoringConfig)
94+
.build();
95+
96+
CreateEntityTypeRequest createEntityTypeRequest =
97+
CreateEntityTypeRequest.newBuilder()
98+
.setParent(FeaturestoreName.of(project, location, featurestoreId).toString())
99+
.setEntityType(entityType)
100+
.setEntityTypeId(entityTypeId)
101+
.build();
102+
103+
OperationFuture<EntityType, CreateEntityTypeOperationMetadata> entityTypeFuture =
104+
featurestoreServiceClient.createEntityTypeAsync(createEntityTypeRequest);
105+
System.out.format(
106+
"Operation name: %s%n", entityTypeFuture.getInitialFuture().get().getName());
107+
System.out.println("Waiting for operation to finish...");
108+
EntityType entityTypeResponse = entityTypeFuture.get(timeout, TimeUnit.SECONDS);
109+
System.out.println("Create Entity Type Monitoring Response");
110+
System.out.format("Name: %s%n", entityTypeResponse.getName());
111+
}
112+
}
113+
}
114+
// [END aiplatform_create_entity_type_monitoring_sample]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*
17+
* Create an entity type so that you can create its related features. See
18+
* https://cloud.google.com/vertex-ai/docs/featurestore/setup before running
19+
* the code snippet
20+
*/
21+
22+
package aiplatform;
23+
24+
// [START aiplatform_create_entity_type_sample]
25+
26+
import com.google.api.gax.longrunning.OperationFuture;
27+
import com.google.cloud.aiplatform.v1.CreateEntityTypeOperationMetadata;
28+
import com.google.cloud.aiplatform.v1.CreateEntityTypeRequest;
29+
import com.google.cloud.aiplatform.v1.EntityType;
30+
import com.google.cloud.aiplatform.v1.FeaturestoreName;
31+
import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient;
32+
import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings;
33+
import java.io.IOException;
34+
import java.util.concurrent.ExecutionException;
35+
import java.util.concurrent.TimeUnit;
36+
import java.util.concurrent.TimeoutException;
37+
38+
public class CreateEntityTypeSample {
39+
40+
public static void main(String[] args)
41+
throws IOException, InterruptedException, ExecutionException, TimeoutException {
42+
// TODO(developer): Replace these variables before running the sample.
43+
String project = "YOUR_PROJECT_ID";
44+
String featurestoreId = "YOUR_FEATURESTORE_ID";
45+
String entityTypeId = "YOUR_ENTITY_TYPE_ID";
46+
String description = "YOUR_ENTITY_TYPE_DESCRIPTION";
47+
String location = "us-central1";
48+
String endpoint = "us-central1-aiplatform.googleapis.com:443";
49+
int timeout = 300;
50+
createEntityTypeSample(
51+
project, featurestoreId, entityTypeId, description, location, endpoint, timeout);
52+
}
53+
54+
static void createEntityTypeSample(
55+
String project,
56+
String featurestoreId,
57+
String entityTypeId,
58+
String description,
59+
String location,
60+
String endpoint,
61+
int timeout)
62+
throws IOException, InterruptedException, ExecutionException, TimeoutException {
63+
64+
FeaturestoreServiceSettings featurestoreServiceSettings =
65+
FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build();
66+
67+
// Initialize client that will be used to send requests. This client only needs to be created
68+
// once, and can be reused for multiple requests. After completing all of your requests, call
69+
// the "close" method on the client to safely clean up any remaining background resources.
70+
try (FeaturestoreServiceClient featurestoreServiceClient =
71+
FeaturestoreServiceClient.create(featurestoreServiceSettings)) {
72+
73+
EntityType entityType = EntityType.newBuilder().setDescription(description).build();
74+
75+
CreateEntityTypeRequest createEntityTypeRequest =
76+
CreateEntityTypeRequest.newBuilder()
77+
.setParent(FeaturestoreName.of(project, location, featurestoreId).toString())
78+
.setEntityType(entityType)
79+
.setEntityTypeId(entityTypeId)
80+
.build();
81+
82+
OperationFuture<EntityType, CreateEntityTypeOperationMetadata> entityTypeFuture =
83+
featurestoreServiceClient.createEntityTypeAsync(createEntityTypeRequest);
84+
System.out.format(
85+
"Operation name: %s%n", entityTypeFuture.getInitialFuture().get().getName());
86+
System.out.println("Waiting for operation to finish...");
87+
EntityType entityTypeResponse = entityTypeFuture.get(timeout, TimeUnit.SECONDS);
88+
System.out.println("Create Entity Type Response");
89+
System.out.format("Name: %s%n", entityTypeResponse.getName());
90+
}
91+
}
92+
}
93+
// [END aiplatform_create_entity_type_sample]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*
17+
* Delete an entity type from featurestore resource. See
18+
* https://cloud.google.com/vertex-ai/docs/featurestore/setup before running
19+
* the code snippet
20+
*/
21+
22+
package aiplatform;
23+
24+
// [START aiplatform_delete_entity_type_sample]
25+
26+
import com.google.api.gax.longrunning.OperationFuture;
27+
import com.google.cloud.aiplatform.v1.DeleteEntityTypeRequest;
28+
import com.google.cloud.aiplatform.v1.DeleteOperationMetadata;
29+
import com.google.cloud.aiplatform.v1.EntityTypeName;
30+
import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient;
31+
import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings;
32+
import com.google.protobuf.Empty;
33+
import java.io.IOException;
34+
import java.util.concurrent.ExecutionException;
35+
import java.util.concurrent.TimeUnit;
36+
import java.util.concurrent.TimeoutException;
37+
38+
public class DeleteEntityTypeSample {
39+
40+
public static void main(String[] args)
41+
throws IOException, InterruptedException, ExecutionException, TimeoutException {
42+
// TODO(developer): Replace these variables before running the sample.
43+
String project = "YOUR_PROJECT_ID";
44+
String featurestoreId = "YOUR_FEATURESTORE_ID";
45+
String entityTypeId = "YOUR_ENTITY_TYPE_ID";
46+
String location = "us-central1";
47+
String endpoint = "us-central1-aiplatform.googleapis.com:443";
48+
int timeout = 300;
49+
deleteEntityTypeSample(project, featurestoreId, entityTypeId, location, endpoint, timeout);
50+
}
51+
52+
static void deleteEntityTypeSample(
53+
String project,
54+
String featurestoreId,
55+
String entityTypeId,
56+
String location,
57+
String endpoint,
58+
int timeout)
59+
throws IOException, InterruptedException, ExecutionException, TimeoutException {
60+
61+
FeaturestoreServiceSettings featurestoreServiceSettings =
62+
FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build();
63+
64+
// Initialize client that will be used to send requests. This client only needs to be created
65+
// once, and can be reused for multiple requests. After completing all of your requests, call
66+
// the "close" method on the client to safely clean up any remaining background resources.
67+
try (FeaturestoreServiceClient featurestoreServiceClient =
68+
FeaturestoreServiceClient.create(featurestoreServiceSettings)) {
69+
70+
DeleteEntityTypeRequest deleteEntityTypeRequest =
71+
DeleteEntityTypeRequest.newBuilder()
72+
.setName(
73+
EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString())
74+
.setForce(true)
75+
.build();
76+
77+
OperationFuture<Empty, DeleteOperationMetadata> operationFuture =
78+
featurestoreServiceClient.deleteEntityTypeAsync(deleteEntityTypeRequest);
79+
System.out.format("Operation name: %s%n", operationFuture.getInitialFuture().get().getName());
80+
System.out.println("Waiting for operation to finish...");
81+
operationFuture.get(timeout, TimeUnit.SECONDS);
82+
83+
System.out.format("Deleted Entity Type.");
84+
}
85+
}
86+
}
87+
// [END aiplatform_delete_entity_type_sample]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*
17+
* Get entity type details. See
18+
* https://cloud.google.com/vertex-ai/docs/featurestore/setup before running
19+
* the code snippet
20+
*/
21+
22+
package aiplatform;
23+
24+
// [START aiplatform_get_entity_type_sample]
25+
26+
import com.google.cloud.aiplatform.v1.EntityType;
27+
import com.google.cloud.aiplatform.v1.EntityTypeName;
28+
import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient;
29+
import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings;
30+
import com.google.cloud.aiplatform.v1.GetEntityTypeRequest;
31+
import java.io.IOException;
32+
33+
public class GetEntityTypeSample {
34+
35+
public static void main(String[] args) throws IOException {
36+
// TODO(developer): Replace these variables before running the sample.
37+
String project = "YOUR_PROJECT_ID";
38+
String featurestoreId = "YOUR_FEATURESTORE_ID";
39+
String entityTypeId = "YOUR_ENTITY_TYPE_ID";
40+
String location = "us-central1";
41+
String endpoint = "us-central1-aiplatform.googleapis.com:443";
42+
getEntityTypeSample(project, featurestoreId, entityTypeId, location, endpoint);
43+
}
44+
45+
static void getEntityTypeSample(
46+
String project, String featurestoreId, String entityTypeId, String location, String endpoint)
47+
throws IOException {
48+
49+
FeaturestoreServiceSettings featurestoreServiceSettings =
50+
FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build();
51+
52+
// Initialize client that will be used to send requests. This client only needs to be created
53+
// once, and can be reused for multiple requests. After completing all of your requests, call
54+
// the "close" method on the client to safely clean up any remaining background resources.
55+
try (FeaturestoreServiceClient featurestoreServiceClient =
56+
FeaturestoreServiceClient.create(featurestoreServiceSettings)) {
57+
58+
GetEntityTypeRequest getEntityTypeRequest =
59+
GetEntityTypeRequest.newBuilder()
60+
.setName(
61+
EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString())
62+
.build();
63+
64+
EntityType entityType = featurestoreServiceClient.getEntityType(getEntityTypeRequest);
65+
System.out.println("Get Entity Type Response");
66+
System.out.println(entityType);
67+
}
68+
}
69+
}
70+
// [END aiplatform_get_entity_type_sample]

0 commit comments

Comments
 (0)