|
| 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] |
0 commit comments