diff --git a/README.md b/README.md index 64d5fd36..2fd1c2b9 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-ai-platform | Delete-dataset | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/delete-dataset.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/delete-dataset.js,samples/README.md) | | Delete-endpoint | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/delete-endpoint.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/delete-endpoint.js,samples/README.md) | | Delete-export-model | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/delete-export-model.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/delete-export-model.js,samples/README.md) | +| Delete-featurestore-sample | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/delete-featurestore-sample.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/delete-featurestore-sample.js,samples/README.md) | | Delete-model | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/delete-model.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/delete-model.js,samples/README.md) | | Deploy-model-custom-trained-model | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/deploy-model-custom-trained-model.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/deploy-model-custom-trained-model.js,samples/README.md) | | Deploy-model | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/deploy-model.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/deploy-model.js,samples/README.md) | @@ -118,6 +119,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-ai-platform | Export-model | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/export-model.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/export-model.js,samples/README.md) | | Get-batch-prediction-job | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/get-batch-prediction-job.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/get-batch-prediction-job.js,samples/README.md) | | Get-custom-job | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/get-custom-job.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/get-custom-job.js,samples/README.md) | +| Get-featurestore-sample | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/get-featurestore-sample.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/get-featurestore-sample.js,samples/README.md) | | Get-hyperparameter-tuning-job | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/get-hyperparameter-tuning-job.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/get-hyperparameter-tuning-job.js,samples/README.md) | | Get-model-evaluation-image-classification | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/get-model-evaluation-image-classification.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/get-model-evaluation-image-classification.js,samples/README.md) | | Get-model-evaluation-image-object-detection | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/get-model-evaluation-image-object-detection.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/get-model-evaluation-image-object-detection.js,samples/README.md) | @@ -143,6 +145,9 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-ai-platform | Import-data-video-object-tracking | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/import-data-video-object-tracking.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/import-data-video-object-tracking.js,samples/README.md) | | Import-data | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/import-data.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/import-data.js,samples/README.md) | | List-endpoints | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/list-endpoints.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/list-endpoints.js,samples/README.md) | +| List-featurestores-async-sample | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/list-featurestores-async-sample.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/list-featurestores-async-sample.js,samples/README.md) | +| List-featurestores-sample | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/list-featurestores-sample.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/list-featurestores-sample.js,samples/README.md) | +| List-featurestores-stream-sample | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/list-featurestores-stream-sample.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/list-featurestores-stream-sample.js,samples/README.md) | | List-model-evaluation-slices | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/list-model-evaluation-slices.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/list-model-evaluation-slices.js,samples/README.md) | | Predict-custom-trained-model | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/predict-custom-trained-model.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/predict-custom-trained-model.js,samples/README.md) | | Predict-image-classification | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/predict-image-classification.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/predict-image-classification.js,samples/README.md) | @@ -154,6 +159,8 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-ai-platform | Predict-text-sentiment-analysis | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/predict-text-sentiment-analysis.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/predict-text-sentiment-analysis.js,samples/README.md) | | Quickstart | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) | | Undeploy-model | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/undeploy-model.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/undeploy-model.js,samples/README.md) | +| Update-featurestore-fixed-nodes-sample | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/update-featurestore-fixed-nodes-sample.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/update-featurestore-fixed-nodes-sample.js,samples/README.md) | +| Update-featurestore-sample | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/update-featurestore-sample.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/update-featurestore-sample.js,samples/README.md) | | Upload-model | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/upload-model.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/upload-model.js,samples/README.md) | diff --git a/samples/README.md b/samples/README.md index 2e59e2c3..5088f2d7 100644 --- a/samples/README.md +++ b/samples/README.md @@ -49,6 +49,7 @@ machine learning development lifecycle. * [Delete-dataset](#delete-dataset) * [Delete-endpoint](#delete-endpoint) * [Delete-export-model](#delete-export-model) + * [Delete-featurestore-sample](#delete-featurestore-sample) * [Delete-model](#delete-model) * [Deploy-model-custom-trained-model](#deploy-model-custom-trained-model) * [Deploy-model](#deploy-model) @@ -56,6 +57,7 @@ machine learning development lifecycle. * [Export-model](#export-model) * [Get-batch-prediction-job](#get-batch-prediction-job) * [Get-custom-job](#get-custom-job) + * [Get-featurestore-sample](#get-featurestore-sample) * [Get-hyperparameter-tuning-job](#get-hyperparameter-tuning-job) * [Get-model-evaluation-image-classification](#get-model-evaluation-image-classification) * [Get-model-evaluation-image-object-detection](#get-model-evaluation-image-object-detection) @@ -81,6 +83,9 @@ machine learning development lifecycle. * [Import-data-video-object-tracking](#import-data-video-object-tracking) * [Import-data](#import-data) * [List-endpoints](#list-endpoints) + * [List-featurestores-async-sample](#list-featurestores-async-sample) + * [List-featurestores-sample](#list-featurestores-sample) + * [List-featurestores-stream-sample](#list-featurestores-stream-sample) * [List-model-evaluation-slices](#list-model-evaluation-slices) * [Predict-custom-trained-model](#predict-custom-trained-model) * [Predict-image-classification](#predict-image-classification) @@ -92,6 +97,8 @@ machine learning development lifecycle. * [Predict-text-sentiment-analysis](#predict-text-sentiment-analysis) * [Quickstart](#quickstart) * [Undeploy-model](#undeploy-model) + * [Update-featurestore-fixed-nodes-sample](#update-featurestore-fixed-nodes-sample) + * [Update-featurestore-sample](#update-featurestore-sample) * [Upload-model](#upload-model) ## Before you begin @@ -687,6 +694,23 @@ __Usage:__ +### Delete-featurestore-sample + +View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/delete-featurestore-sample.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/delete-featurestore-sample.js,samples/README.md) + +__Usage:__ + + +`node samples/delete-featurestore-sample.js` + + +----- + + + + ### Delete-model View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/delete-model.js). @@ -806,6 +830,23 @@ __Usage:__ +### Get-featurestore-sample + +View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/get-featurestore-sample.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/get-featurestore-sample.js,samples/README.md) + +__Usage:__ + + +`node samples/get-featurestore-sample.js` + + +----- + + + + ### Get-hyperparameter-tuning-job View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/get-hyperparameter-tuning-job.js). @@ -1231,6 +1272,57 @@ __Usage:__ +### List-featurestores-async-sample + +View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/list-featurestores-async-sample.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/list-featurestores-async-sample.js,samples/README.md) + +__Usage:__ + + +`node samples/list-featurestores-async-sample.js` + + +----- + + + + +### List-featurestores-sample + +View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/list-featurestores-sample.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/list-featurestores-sample.js,samples/README.md) + +__Usage:__ + + +`node samples/list-featurestores-sample.js` + + +----- + + + + +### List-featurestores-stream-sample + +View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/list-featurestores-stream-sample.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/list-featurestores-stream-sample.js,samples/README.md) + +__Usage:__ + + +`node samples/list-featurestores-stream-sample.js` + + +----- + + + + ### List-model-evaluation-slices View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/list-model-evaluation-slices.js). @@ -1418,6 +1510,40 @@ __Usage:__ +### Update-featurestore-fixed-nodes-sample + +View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/update-featurestore-fixed-nodes-sample.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/update-featurestore-fixed-nodes-sample.js,samples/README.md) + +__Usage:__ + + +`node samples/update-featurestore-fixed-nodes-sample.js` + + +----- + + + + +### Update-featurestore-sample + +View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/update-featurestore-sample.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/update-featurestore-sample.js,samples/README.md) + +__Usage:__ + + +`node samples/update-featurestore-sample.js` + + +----- + + + + ### Upload-model View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/upload-model.js). diff --git a/samples/delete-featurestore-sample.js b/samples/delete-featurestore-sample.js new file mode 100644 index 00000000..e7220eba --- /dev/null +++ b/samples/delete-featurestore-sample.js @@ -0,0 +1,88 @@ +/* + * 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 + * + * https://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. + */ + +/* + * Deletes a single Featurestore. + * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +'use strict'; + +async function main( + project, + featurestoreId, + force = false, + location = 'us-central1', + apiEndpoint = 'us-central1-aiplatform.googleapis.com', + timeout = 60000 +) { + // [START aiplatform_delete_featurestore_sample] + /** + * TODO(developer): Uncomment these variables before running the sample.\ + * (Not necessary if passing values as arguments) + */ + + // const project = 'YOUR_PROJECT_ID'; + // const featurestoreId = 'YOUR_FEATURESTORE_ID'; + // const force = ; + // const location = 'YOUR_PROJECT_LOCATION'; + // const apiEndpoint = 'YOUR_API_ENDPOINT'; + // const timeout = ; + + // Imports the Google Cloud Featurestore Service Client library + const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; + + // Specifies the location of the api endpoint + const clientOptions = { + apiEndpoint: apiEndpoint, + }; + + // Instantiates a client + const featurestoreServiceClient = new FeaturestoreServiceClient( + clientOptions + ); + + async function deleteFeaturestore() { + // Configure the name resource + const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; + + const request = { + name: name, + force: Boolean(force), + }; + + // Delete Featurestore request + const [operation] = await featurestoreServiceClient.deleteFeaturestore( + request, + {timeout: Number(timeout)} + ); + const [response] = await operation.promise(); + + console.log('Delete featurestore response'); + console.log('Raw response:'); + console.log(JSON.stringify(response, null, 2)); + } + deleteFeaturestore(); + // [END aiplatform_delete_featurestore_sample] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); + +main(...process.argv.slice(2)); diff --git a/samples/get-featurestore-sample.js b/samples/get-featurestore-sample.js new file mode 100644 index 00000000..fe6e38f3 --- /dev/null +++ b/samples/get-featurestore-sample.js @@ -0,0 +1,85 @@ +/* + * 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 + * + * https://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. + */ + +/* + * Gets details of a single Featurestore. + * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +'use strict'; + +async function main( + project, + featurestoreId, + location = 'us-central1', + apiEndpoint = 'us-central1-aiplatform.googleapis.com', + timeout = 5000 +) { + // [START aiplatform_get_featurestore_sample] + /** + * TODO(developer): Uncomment these variables before running the sample.\ + * (Not necessary if passing values as arguments) + */ + + // const project = 'YOUR_PROJECT_ID'; + // const featurestoreId = 'YOUR_FEATURESTORE_ID'; + // const location = 'YOUR_PROJECT_LOCATION'; + // const apiEndpoint = 'YOUR_API_ENDPOINT'; + // const timeout = ; + + // Imports the Google Cloud Featurestore Service Client library + const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; + + // Specifies the location of the api endpoint + const clientOptions = { + apiEndpoint: apiEndpoint, + }; + + // Instantiates a client + const featurestoreServiceClient = new FeaturestoreServiceClient( + clientOptions + ); + + async function getFeaturestore() { + // Configure the parent resource + const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; + + const request = { + name: name, + }; + + // Get Featurestore request + const [response] = await featurestoreServiceClient.getFeaturestore( + request, + {timeout: Number(timeout)} + ); + + console.log('Get featurestore response'); + console.log(`Name : ${response.name}`); + console.log('Raw response:'); + console.log(JSON.stringify(response, null, 2)); + } + getFeaturestore(); + // [END aiplatform_get_featurestore_sample] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); + +main(...process.argv.slice(2)); diff --git a/samples/list-featurestores-async-sample.js b/samples/list-featurestores-async-sample.js new file mode 100644 index 00000000..16bbc8f7 --- /dev/null +++ b/samples/list-featurestores-async-sample.js @@ -0,0 +1,84 @@ +/* + * 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 + * + * https://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. + */ + +/* + * Lists Featurestores asynchronously in a given project and location. + * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +'use strict'; + +async function main( + project, + location = 'us-central1', + apiEndpoint = 'us-central1-aiplatform.googleapis.com', + timeout = 5000 +) { + // [START aiplatform_list_featurestores_async_sample] + /** + * TODO(developer): Uncomment these variables before running the sample.\ + * (Not necessary if passing values as arguments) + */ + + // const project = 'YOUR_PROJECT_ID'; + // const location = 'YOUR_PROJECT_LOCATION'; + // const apiEndpoint = 'YOUR_API_ENDPOINT'; + // const timeout = ; + + // Imports the Google Cloud Featurestore Service Client library + const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; + + // Specifies the location of the api endpoint + const clientOptions = { + apiEndpoint: apiEndpoint, + }; + + // Instantiates a client + const featurestoreServiceClient = new FeaturestoreServiceClient( + clientOptions + ); + + async function listFeaturestoresAsync() { + // Configure the parent resource + const parent = `projects/${project}/locations/${location}`; + + const request = { + parent: parent, + }; + + // List featurestores async request + const iterable = await featurestoreServiceClient.listFeaturestoresAsync( + request, + {timeout: Number(timeout)} + ); + + console.log('List featurestores async response'); + console.log('Raw response:'); + for await (const response of iterable) { + console.log(JSON.stringify(response, null, 2)); + } + } + listFeaturestoresAsync(); + // [END aiplatform_list_featurestores_async_sample] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); + +main(...process.argv.slice(2)); diff --git a/samples/list-featurestores-sample.js b/samples/list-featurestores-sample.js new file mode 100644 index 00000000..1bacda43 --- /dev/null +++ b/samples/list-featurestores-sample.js @@ -0,0 +1,82 @@ +/* + * 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 + * + * https://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. + */ + +/* + * Lists Featurestores in a given project and location. + * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +'use strict'; + +async function main( + project, + location = 'us-central1', + apiEndpoint = 'us-central1-aiplatform.googleapis.com', + timeout = 5000 +) { + // [START aiplatform_list_featurestores_sample] + /** + * TODO(developer): Uncomment these variables before running the sample.\ + * (Not necessary if passing values as arguments) + */ + + // const project = 'YOUR_PROJECT_ID'; + // const location = 'YOUR_PROJECT_LOCATION'; + // const apiEndpoint = 'YOUR_API_ENDPOINT'; + // const timeout = ; + + // Imports the Google Cloud Featurestore Service Client library + const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; + + // Specifies the location of the api endpoint + const clientOptions = { + apiEndpoint: apiEndpoint, + }; + + // Instantiates a client + const featurestoreServiceClient = new FeaturestoreServiceClient( + clientOptions + ); + + async function listFeaturestores() { + // Configure the parent resource + const parent = `projects/${project}/locations/${location}`; + + const request = { + parent: parent, + }; + + // List featurestores request + const [response] = await featurestoreServiceClient.listFeaturestores( + request, + {timeout: Number(timeout)} + ); + + console.log('List featurestores response'); + console.log('Raw response:'); + console.log(JSON.stringify(response, null, 2)); + } + listFeaturestores(); + // [END aiplatform_list_featurestores_sample] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); + +main(...process.argv.slice(2)); diff --git a/samples/list-featurestores-stream-sample.js b/samples/list-featurestores-stream-sample.js new file mode 100644 index 00000000..f8515464 --- /dev/null +++ b/samples/list-featurestores-stream-sample.js @@ -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 + * + * https://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. + */ + +/* + * Lists Featurestores using stream in a given project and location. + * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +'use strict'; + +async function main( + project, + location = 'us-central1', + apiEndpoint = 'us-central1-aiplatform.googleapis.com', + timeout = 5000 +) { + // [START aiplatform_list_featurestores_stream_sample] + /** + * TODO(developer): Uncomment these variables before running the sample.\ + * (Not necessary if passing values as arguments) + */ + + // const project = 'YOUR_PROJECT_ID'; + // const location = 'YOUR_PROJECT_LOCATION'; + // const apiEndpoint = 'YOUR_API_ENDPOINT'; + // const timeout = ; + + // Imports the Google Cloud Featurestore Service Client library + const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; + + // Specifies the location of the api endpoint + const clientOptions = { + apiEndpoint: apiEndpoint, + }; + + // Instantiates a client + const featurestoreServiceClient = new FeaturestoreServiceClient( + clientOptions + ); + + async function listFeaturestoresStream() { + // Configure the parent resource + const parent = `projects/${project}/locations/${location}`; + + const request = { + parent: parent, + }; + + // List featurestores stream request + const streamObject = + await featurestoreServiceClient.listFeaturestoresStream(request, { + timeout: Number(timeout), + }); + + console.log('List featurestores stream response'); + console.log('Raw response:'); + + streamObject.on('data', response => { + console.log(JSON.stringify(response, null, 2)); + }); + + streamObject.on('end', () => { + console.log('No more data to read'); + }); + + streamObject.on('close', () => { + console.log('Stream object listFeaturestoresStream is closed'); + }); + } + listFeaturestoresStream(); + // [END aiplatform_list_featurestores_stream_sample] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); + +main(...process.argv.slice(2)); diff --git a/samples/test/featurestore-samples.test.js b/samples/test/featurestore-samples.test.js new file mode 100644 index 00000000..c759ba53 --- /dev/null +++ b/samples/test/featurestore-samples.test.js @@ -0,0 +1,101 @@ +/* + * 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 + * + * https://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. + */ + +'use strict'; + +const {assert} = require('chai'); +const {after, before, describe, it} = require('mocha'); +const uuid = require('uuid').v4; +const cp = require('child_process'); +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + +const project = process.env.CAIP_PROJECT_ID; +const featurestoreId1 = `featurestore_sample_${uuid() + .replace(/-/g, '_') + .slice(10, 20)}`; +const featurestoreId2 = `featurestore_sample_${uuid() + .replace(/-/g, '_') + .slice(10, 20)}`; + +const fixedNodeCount = 1; +const updatedFixedNodeCount = 3; +const minNodeCount = 1; +const maxNodeCount = 3; +const updatedMinNodeCount = 2; +const updatedMaxNodeCount = 4; +const location = 'us-central1'; +const apiEndpoint = 'us-central1-aiplatform.googleapis.com'; + +describe('AI platform featurestore api samples test', async function () { + this.retries(2); + before('should create a featurestore with fixed nodes', async () => { + execSync( + `node ./create-featurestore-fixed-nodes-sample.js ${project} ${featurestoreId1} ${fixedNodeCount} ${location} ${apiEndpoint}` + ); + }); + before('should create a featurestore with autoscaling', async () => { + execSync( + `node ./create-featurestore-sample.js ${project} ${featurestoreId2} ${minNodeCount} ${maxNodeCount} ${location} ${apiEndpoint}` + ); + }); + it('should get the featurestore', async () => { + const stdout = execSync( + `node ./get-featurestore-sample.js ${project} ${featurestoreId1} ${location} ${apiEndpoint}` + ); + assert.match(stdout, /Get featurestore response/); + }); + it('should list the featurestores', async () => { + const stdout = execSync( + `node ./list-featurestores-sample.js ${project} ${location} ${apiEndpoint}` + ); + assert.match(stdout, /List featurestores response/); + }); + it('should list the featurestores asynchronously', async () => { + const stdout = execSync( + `node ./list-featurestores-async-sample.js ${project} ${location} ${apiEndpoint}` + ); + assert.match(stdout, /List featurestores async response/); + }); + it('should list the featurestores in streaming', async () => { + const stdout = execSync( + `node ./list-featurestores-stream-sample.js ${project} ${location} ${apiEndpoint}` + ); + assert.match(stdout, /List featurestores stream response/); + }); + it('should update featurestores fixed nodes', async () => { + const stdout = execSync( + `node ./update-featurestore-fixed-nodes-sample.js ${project} ${featurestoreId1} ${updatedFixedNodeCount} ${location} ${apiEndpoint}` + ); + assert.match(stdout, /Update featurestore fixed nodes response/); + }); + it('should update featurestore autoscaling', async () => { + const stdout = execSync( + `node ./update-featurestore-sample.js ${project} ${featurestoreId2} ${updatedMinNodeCount} ${updatedMaxNodeCount} ${location} ${apiEndpoint}` + ); + assert.match(stdout, /Update featurestore response/); + }); + it('should delete the created featurestore', async () => { + const stdout = execSync( + `node ./delete-featurestore-sample.js ${project} ${featurestoreId1} true ${location}` + ); + assert.match(stdout, /Delete featurestore response/); + }); + after('should delete the created featurestore 2', async () => { + execSync( + `node ./delete-featurestore-sample.js ${project} ${featurestoreId2} true ${location}` + ); + }); +}); diff --git a/samples/update-featurestore-fixed-nodes-sample.js b/samples/update-featurestore-fixed-nodes-sample.js new file mode 100644 index 00000000..dabf8e7f --- /dev/null +++ b/samples/update-featurestore-fixed-nodes-sample.js @@ -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 + * + * https://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. + */ + +/* + * Updates the parameters of a single Featurestore. + * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +'use strict'; + +async function main( + project, + featurestoreId, + fixedNodeCount = 1, + location = 'us-central1', + apiEndpoint = 'us-central1-aiplatform.googleapis.com', + timeout = 600000 +) { + // [START aiplatform_update_featurestore_fixed_nodes_sample] + /** + * TODO(developer): Uncomment these variables before running the sample.\ + * (Not necessary if passing values as arguments) + */ + + // const project = 'YOUR_PROJECT_ID'; + // const featurestoreId = 'YOUR_FEATURESTORE_ID'; + // const fixedNodeCount = ; + // const location = 'YOUR_PROJECT_LOCATION'; + // const apiEndpoint = 'YOUR_API_ENDPOINT'; + // const timeout = ; + + // Imports the Google Cloud Featurestore Service Client library + const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1; + + // Specifies the location of the api endpoint + const clientOptions = { + apiEndpoint: apiEndpoint, + }; + + // Instantiates a client + const featurestoreServiceClient = new FeaturestoreServiceClient( + clientOptions + ); + + async function updateFeaturestoreFixedNodes() { + // Configure the parent resource + const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; + + const featurestore = { + name: parent, + onlineServingConfig: {fixedNodeCount: Number(fixedNodeCount)}, + }; + + const request = { + featurestore: featurestore, + }; + + // Update Featurestore request + const [operation] = await featurestoreServiceClient.updateFeaturestore( + request, + {timeout: Number(timeout)} + ); + const [response] = await operation.promise(); + + console.log('Update featurestore fixed nodes response'); + console.log(`Name : ${response.name}`); + console.log('Raw response:'); + console.log(JSON.stringify(response, null, 2)); + } + updateFeaturestoreFixedNodes(); + // [END aiplatform_update_featurestore_fixed_nodes_sample] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); + +main(...process.argv.slice(2)); diff --git a/samples/update-featurestore-sample.js b/samples/update-featurestore-sample.js new file mode 100644 index 00000000..8cf89b93 --- /dev/null +++ b/samples/update-featurestore-sample.js @@ -0,0 +1,101 @@ +/* + * 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 + * + * https://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. + */ + +/* + * Updates the parameters of a single Featurestore with autoscaling configuration. + * See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running + * the code snippet + */ + +'use strict'; + +async function main( + project, + featurestoreId, + minNodeCount = 1, + maxNodeCount = 3, + location = 'us-central1', + apiEndpoint = 'us-central1-aiplatform.googleapis.com', + timeout = 600000 +) { + // [START aiplatform_update_featurestore_sample] + /** + * TODO(developer): Uncomment these variables before running the sample.\ + * (Not necessary if passing values as arguments) + */ + + // const project = 'YOUR_PROJECT_ID'; + // const featurestoreId = 'YOUR_FEATURESTORE_ID'; + // const minNodeCount = ; + // const maxNodeCount = ; + // const location = 'YOUR_PROJECT_LOCATION'; + // const apiEndpoint = 'YOUR_API_ENDPOINT'; + // const timeout = ; + + // Imports the Google Cloud Featurestore Service Client library + const {FeaturestoreServiceClient} = + require('@google-cloud/aiplatform').v1beta1; + + // Specifies the location of the api endpoint + const clientOptions = { + apiEndpoint: apiEndpoint, + }; + + // Instantiates a client + const featurestoreServiceClient = new FeaturestoreServiceClient( + clientOptions + ); + + async function updateFeaturestore() { + // Configure the parent resource + const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`; + + const featurestore = { + name: parent, + onlineServingConfig: { + scaling: { + minNodeCount: minNodeCount, + maxNodeCount: maxNodeCount, + }, + }, + }; + + const request = { + featurestore: featurestore, + }; + + // Update Featurestore request + const [operation] = await featurestoreServiceClient.updateFeaturestore( + request, + {timeout: Number(timeout)} + ); + const [response] = await operation.promise(); + + console.log('Update featurestore response'); + console.log(`Name : ${response.name}`); + console.log('Raw response:'); + console.log(JSON.stringify(response, null, 2)); + } + updateFeaturestore(); + // [END aiplatform_update_featurestore_sample] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); + +main(...process.argv.slice(2));