|
| 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 | + * https://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 | +/* |
| 18 | + * Creates a new Featurestore in a given project and location. |
| 19 | + * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running |
| 20 | + * the code snippet |
| 21 | + */ |
| 22 | + |
| 23 | +'use strict'; |
| 24 | + |
| 25 | +async function main( |
| 26 | + project, |
| 27 | + featurestoreId, |
| 28 | + minNodeCount = 1, |
| 29 | + maxNodeCount = 5, |
| 30 | + location = 'us-central1', |
| 31 | + apiEndpoint = 'us-central1-aiplatform.googleapis.com', |
| 32 | + timeout = 900000 |
| 33 | +) { |
| 34 | + // [START aiplatform_create_featurestore_sample] |
| 35 | + /** |
| 36 | + * TODO(developer): Uncomment these variables before running the sample.\ |
| 37 | + * (Not necessary if passing values as arguments) |
| 38 | + */ |
| 39 | + |
| 40 | + // const project = 'YOUR_PROJECT_ID'; |
| 41 | + // const featurestoreId = 'YOUR_FEATURESTORE_ID'; |
| 42 | + // const minNodeCount = <MINIMUM_NO_OF_NODES>; |
| 43 | + // const maxNodeCount = <MAXIMUM_NO_OF_NODES>; |
| 44 | + // const location = 'YOUR_PROJECT_LOCATION'; |
| 45 | + // const apiEndpoint = 'YOUR_API_ENDPOINT'; |
| 46 | + // const timeout = <TIMEOUT_IN_MILLI_SECONDS>; |
| 47 | + |
| 48 | + // Imports the Google Cloud Featurestore Service Client library |
| 49 | + const {FeaturestoreServiceClient} = |
| 50 | + require('@google-cloud/aiplatform').v1beta1; |
| 51 | + |
| 52 | + // Specifies the location of the api endpoint |
| 53 | + const clientOptions = { |
| 54 | + apiEndpoint: apiEndpoint, |
| 55 | + }; |
| 56 | + |
| 57 | + // Instantiates a client |
| 58 | + const featurestoreServiceClient = new FeaturestoreServiceClient( |
| 59 | + clientOptions |
| 60 | + ); |
| 61 | + |
| 62 | + async function createFeaturestore() { |
| 63 | + // Configure the parent resource |
| 64 | + const parent = `projects/${project}/locations/${location}`; |
| 65 | + |
| 66 | + const featurestore = { |
| 67 | + onlineServingConfig: { |
| 68 | + scaling: { |
| 69 | + minNodeCount: minNodeCount, |
| 70 | + maxNodeCount: maxNodeCount, |
| 71 | + }, |
| 72 | + }, |
| 73 | + }; |
| 74 | + |
| 75 | + const request = { |
| 76 | + parent: parent, |
| 77 | + featurestore: featurestore, |
| 78 | + featurestoreId: featurestoreId, |
| 79 | + }; |
| 80 | + |
| 81 | + // Create Featurestore request |
| 82 | + const [operation] = await featurestoreServiceClient.createFeaturestore( |
| 83 | + request, |
| 84 | + {timeout: Number(timeout)} |
| 85 | + ); |
| 86 | + const [response] = await operation.promise(); |
| 87 | + |
| 88 | + console.log('Create featurestore response'); |
| 89 | + console.log(`Name : ${response.name}`); |
| 90 | + console.log('Raw response:'); |
| 91 | + console.log(JSON.stringify(response, null, 2)); |
| 92 | + } |
| 93 | + createFeaturestore(); |
| 94 | + // [END aiplatform_create_featurestore_sample] |
| 95 | +} |
| 96 | + |
| 97 | +process.on('unhandledRejection', err => { |
| 98 | + console.error(err.message); |
| 99 | + process.exitCode = 1; |
| 100 | +}); |
| 101 | + |
| 102 | +main(...process.argv.slice(2)); |
0 commit comments