Skip to content

Commit 43255aa

Browse files
sai-chaithugcf-owl-bot[bot]alicejli
authored
feat(samples): add remaining featurestore api samples (#974)
* Added Featurestore Samples * feat(samples): add remaining featurestore api samples (googleapis#945) * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * feat(samples): update all featurestore samples * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 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> Co-authored-by: Alice <[email protected]>
1 parent e7cb3c3 commit 43255aa

File tree

7 files changed

+638
-0
lines changed

7 files changed

+638
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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 a featurestore resource to contain entity types and 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_featurestore_fixed_nodes_sample]
25+
26+
import com.google.api.gax.longrunning.OperationFuture;
27+
import com.google.cloud.aiplatform.v1beta1.CreateFeaturestoreOperationMetadata;
28+
import com.google.cloud.aiplatform.v1beta1.CreateFeaturestoreRequest;
29+
import com.google.cloud.aiplatform.v1beta1.Featurestore;
30+
import com.google.cloud.aiplatform.v1beta1.Featurestore.OnlineServingConfig;
31+
import com.google.cloud.aiplatform.v1beta1.FeaturestoreServiceClient;
32+
import com.google.cloud.aiplatform.v1beta1.FeaturestoreServiceSettings;
33+
import com.google.cloud.aiplatform.v1beta1.LocationName;
34+
import java.io.IOException;
35+
import java.util.concurrent.ExecutionException;
36+
import java.util.concurrent.TimeUnit;
37+
import java.util.concurrent.TimeoutException;
38+
39+
public class CreateFeaturestoreFixedNodesSample {
40+
41+
public static void main(String[] args)
42+
throws IOException, InterruptedException, ExecutionException, TimeoutException {
43+
// TODO(developer): Replace these variables before running the sample.
44+
String project = "YOUR_PROJECT_ID";
45+
String featurestoreId = "YOUR_FEATURESTORE_ID";
46+
int fixedNodeCount = 1;
47+
String location = "us-central1";
48+
String endpoint = "us-central1-aiplatform.googleapis.com:443";
49+
int timeout = 900;
50+
createFeaturestoreFixedNodesSample(
51+
project, featurestoreId, fixedNodeCount, location, endpoint, timeout);
52+
}
53+
54+
static void createFeaturestoreFixedNodesSample(
55+
String project,
56+
String featurestoreId,
57+
int fixedNodeCount,
58+
String location,
59+
String endpoint,
60+
int timeout)
61+
throws IOException, InterruptedException, ExecutionException, TimeoutException {
62+
63+
FeaturestoreServiceSettings featurestoreServiceSettings =
64+
FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build();
65+
66+
// Initialize client that will be used to send requests. This client only needs to be created
67+
// once, and can be reused for multiple requests. After completing all of your requests, call
68+
// the "close" method on the client to safely clean up any remaining background resources.
69+
try (FeaturestoreServiceClient featurestoreServiceClient =
70+
FeaturestoreServiceClient.create(featurestoreServiceSettings)) {
71+
72+
OnlineServingConfig.Builder builderValue =
73+
OnlineServingConfig.newBuilder().setFixedNodeCount(fixedNodeCount);
74+
Featurestore featurestore =
75+
Featurestore.newBuilder().setOnlineServingConfig(builderValue).build();
76+
77+
CreateFeaturestoreRequest createFeaturestoreRequest =
78+
CreateFeaturestoreRequest.newBuilder()
79+
.setParent(LocationName.of(project, location).toString())
80+
.setFeaturestore(featurestore)
81+
.setFeaturestoreId(featurestoreId)
82+
.build();
83+
84+
OperationFuture<Featurestore, CreateFeaturestoreOperationMetadata> featurestoreFuture =
85+
featurestoreServiceClient.createFeaturestoreAsync(createFeaturestoreRequest);
86+
System.out.format(
87+
"Operation name: %s%n", featurestoreFuture.getInitialFuture().get().getName());
88+
System.out.println("Waiting for operation to finish...");
89+
Featurestore featurestoreResponse = featurestoreFuture.get(timeout, TimeUnit.SECONDS);
90+
System.out.println("Create Featurestore Response");
91+
System.out.format("Name: %s%n", featurestoreResponse.getName());
92+
}
93+
}
94+
}
95+
// [END aiplatform_create_featurestore_fixed_nodes_sample]
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
* Gets details of a single featurestore. 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_featurestore_sample]
25+
26+
import com.google.cloud.aiplatform.v1beta1.Featurestore;
27+
import com.google.cloud.aiplatform.v1beta1.FeaturestoreName;
28+
import com.google.cloud.aiplatform.v1beta1.FeaturestoreServiceClient;
29+
import com.google.cloud.aiplatform.v1beta1.FeaturestoreServiceSettings;
30+
import com.google.cloud.aiplatform.v1beta1.GetFeaturestoreRequest;
31+
import java.io.IOException;
32+
33+
public class GetFeaturestoreSample {
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 location = "us-central1";
40+
String endpoint = "us-central1-aiplatform.googleapis.com:443";
41+
getFeaturestoreSample(project, featurestoreId, location, endpoint);
42+
}
43+
44+
static void getFeaturestoreSample(
45+
String project, String featurestoreId, String location, String endpoint) throws IOException {
46+
47+
FeaturestoreServiceSettings featurestoreServiceSettings =
48+
FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build();
49+
50+
// Initialize client that will be used to send requests. This client only needs to be created
51+
// once, and can be reused for multiple requests. After completing all of your requests, call
52+
// the "close" method on the client to safely clean up any remaining background resources.
53+
try (FeaturestoreServiceClient featurestoreServiceClient =
54+
FeaturestoreServiceClient.create(featurestoreServiceSettings)) {
55+
56+
GetFeaturestoreRequest getFeaturestoreRequest =
57+
GetFeaturestoreRequest.newBuilder()
58+
.setName(FeaturestoreName.of(project, location, featurestoreId).toString())
59+
.build();
60+
61+
Featurestore featurestore = featurestoreServiceClient.getFeaturestore(getFeaturestoreRequest);
62+
System.out.println("Get Featurestore Response");
63+
System.out.println(featurestore);
64+
}
65+
}
66+
}
67+
// [END aiplatform_get_featurestore_sample]
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
* List available featurestore 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_list_featurestores_async_sample]
25+
26+
import com.google.cloud.aiplatform.v1.Featurestore;
27+
import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient;
28+
import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings;
29+
import com.google.cloud.aiplatform.v1.ListFeaturestoresRequest;
30+
import com.google.cloud.aiplatform.v1.ListFeaturestoresResponse;
31+
import com.google.cloud.aiplatform.v1.LocationName;
32+
import com.google.common.base.Strings;
33+
import java.io.IOException;
34+
35+
public class ListFeaturestoresAsyncSample {
36+
37+
public static void main(String[] args) throws IOException {
38+
// TODO(developer): Replace these variables before running the sample.
39+
String project = "YOUR_PROJECT_ID";
40+
String location = "us-central1";
41+
String endpoint = "us-central1-aiplatform.googleapis.com:443";
42+
listFeaturestoresAsyncSample(project, location, endpoint);
43+
}
44+
45+
static void listFeaturestoresAsyncSample(String project, String location, String endpoint)
46+
throws IOException {
47+
FeaturestoreServiceSettings featurestoreServiceSettings =
48+
FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build();
49+
50+
// Initialize client that will be used to send requests. This client only needs to be created
51+
// once, and can be reused for multiple requests. After completing all of your requests, call
52+
// the "close" method on the client to safely clean up any remaining background resources.
53+
try (FeaturestoreServiceClient featurestoreServiceClient =
54+
FeaturestoreServiceClient.create(featurestoreServiceSettings)) {
55+
56+
ListFeaturestoresRequest listFeaturestoresRequest =
57+
ListFeaturestoresRequest.newBuilder()
58+
.setParent(LocationName.of(project, location).toString())
59+
.build();
60+
System.out.println("List Featurestores Async Response");
61+
while (true) {
62+
ListFeaturestoresResponse listFeaturestoresResponse =
63+
featurestoreServiceClient.listFeaturestoresCallable().call(listFeaturestoresRequest);
64+
for (Featurestore element : listFeaturestoresResponse.getFeaturestoresList()) {
65+
System.out.println(element);
66+
}
67+
String nextPageToken = listFeaturestoresResponse.getNextPageToken();
68+
if (!Strings.isNullOrEmpty(nextPageToken)) {
69+
listFeaturestoresRequest =
70+
listFeaturestoresRequest.toBuilder().setPageToken(nextPageToken).build();
71+
} else {
72+
break;
73+
}
74+
}
75+
}
76+
}
77+
}
78+
// [END aiplatform_list_featurestores_async_sample]
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
* List available featurestore 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_list_featurestores_sample]
25+
26+
import com.google.cloud.aiplatform.v1.Featurestore;
27+
import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient;
28+
import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings;
29+
import com.google.cloud.aiplatform.v1.ListFeaturestoresRequest;
30+
import com.google.cloud.aiplatform.v1.LocationName;
31+
import java.io.IOException;
32+
33+
public class ListFeaturestoresSample {
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 location = "us-central1";
39+
String endpoint = "us-central1-aiplatform.googleapis.com:443";
40+
listFeaturestoresSample(project, location, endpoint);
41+
}
42+
43+
static void listFeaturestoresSample(String project, String location, String endpoint)
44+
throws IOException {
45+
FeaturestoreServiceSettings featurestoreServiceSettings =
46+
FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build();
47+
48+
// Initialize client that will be used to send requests. This client only needs to be created
49+
// once, and can be reused for multiple requests. After completing all of your requests, call
50+
// the "close" method on the client to safely clean up any remaining background resources.
51+
try (FeaturestoreServiceClient featurestoreServiceClient =
52+
FeaturestoreServiceClient.create(featurestoreServiceSettings)) {
53+
54+
ListFeaturestoresRequest listFeaturestoresRequest =
55+
ListFeaturestoresRequest.newBuilder()
56+
.setParent(LocationName.of(project, location).toString())
57+
.build();
58+
59+
System.out.println("List Featurestores Response");
60+
for (Featurestore element :
61+
featurestoreServiceClient.listFeaturestores(listFeaturestoresRequest).iterateAll()) {
62+
System.out.println(element);
63+
}
64+
}
65+
}
66+
}
67+
// [END aiplatform_list_featurestores_sample]

0 commit comments

Comments
 (0)