Skip to content

Commit 121b68f

Browse files
suryaguthikondagcf-owl-bot[bot]
authored andcommitted
feat(samples): add create-featurestore samples (#317)
* added create-featurestore-sample.js and create-featurestore-sample.test.js * feat(samples): added createFeaturestore sample (#313) * feat(samples): added remaining featurestore samples (#313) * removed the extraneous files * feat(samples): added create-featurestore sample (#313) * feat(samples): added variation of create-featurestore sample (#313) * 🦉 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 955939d commit 121b68f

4 files changed

+331
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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 with fixed nodes configuration 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+
fixedNodeCount = 1,
29+
location = 'us-central1',
30+
apiEndpoint = 'us-central1-aiplatform.googleapis.com',
31+
timeout = 900000
32+
) {
33+
// [START aiplatform_create_featurestore_fixed_nodes_sample]
34+
/**
35+
* TODO(developer): Uncomment these variables before running the sample.\
36+
* (Not necessary if passing values as arguments)
37+
*/
38+
39+
// const project = 'YOUR_PROJECT_ID';
40+
// const featurestoreId = 'YOUR_FEATURESTORE_ID';
41+
// const fixedNodeCount = <NO_OF_NODES>;
42+
// const location = 'YOUR_PROJECT_LOCATION';
43+
// const apiEndpoint = 'YOUR_API_ENDPOINT';
44+
// const timeout = <TIMEOUT_IN_MILLI_SECONDS>;
45+
46+
// Imports the Google Cloud Featurestore Service Client library
47+
const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1;
48+
49+
// Specifies the location of the api endpoint
50+
const clientOptions = {
51+
apiEndpoint: apiEndpoint,
52+
};
53+
54+
// Instantiates a client
55+
const featurestoreServiceClient = new FeaturestoreServiceClient(
56+
clientOptions
57+
);
58+
59+
async function createFeaturestoreFixedNodes() {
60+
// Configure the parent resource
61+
const parent = `projects/${project}/locations/${location}`;
62+
63+
const featurestore = {
64+
onlineServingConfig: {fixedNodeCount: Number(fixedNodeCount)},
65+
};
66+
67+
const request = {
68+
parent: parent,
69+
featurestore: featurestore,
70+
featurestoreId: featurestoreId,
71+
};
72+
73+
// Create Featurestore request
74+
const [operation] = await featurestoreServiceClient.createFeaturestore(
75+
request,
76+
{timeout: Number(timeout)}
77+
);
78+
const [response] = await operation.promise();
79+
80+
console.log('Create featurestore fixed nodes response');
81+
console.log(`Name : ${response.name}`);
82+
console.log('Raw response:');
83+
console.log(JSON.stringify(response, null, 2));
84+
}
85+
createFeaturestoreFixedNodes();
86+
// [END aiplatform_create_featurestore_fixed_nodes_sample]
87+
}
88+
89+
process.on('unhandledRejection', err => {
90+
console.error(err.message);
91+
process.exitCode = 1;
92+
});
93+
94+
main(...process.argv.slice(2));

Diff for: ai-platform/snippets/create-featurestore-sample.js

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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));
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+
* 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+
'use strict';
18+
19+
const {assert} = require('chai');
20+
const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1;
21+
const {after, describe, it} = require('mocha');
22+
const uuid = require('uuid').v4;
23+
const cp = require('child_process');
24+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
25+
26+
const project = process.env.CAIP_PROJECT_ID;
27+
const featurestoreId = `featurestore_sample_${uuid()
28+
.replace(/-/g, '_')
29+
.slice(10, 20)}`;
30+
const fixedNodeCount = 1;
31+
const location = 'us-central1';
32+
const apiEndpoint = 'us-central1-aiplatform.googleapis.com';
33+
34+
// Instantiates a featurestore clients
35+
const featurestoreServiceClient = new FeaturestoreServiceClient({
36+
apiEndpoint: apiEndpoint,
37+
});
38+
39+
const deleteFeaturestore = async () => {
40+
// Configure the name resource
41+
const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`;
42+
43+
const request = {
44+
name: name,
45+
force: true,
46+
};
47+
48+
// Delete Featurestore request
49+
const [operation] = await featurestoreServiceClient.deleteFeaturestore(
50+
request,
51+
{timeout: 60000}
52+
);
53+
await operation.promise();
54+
};
55+
56+
describe('AI platform create featurestore with fixed nodes', async function () {
57+
this.retries(2);
58+
it('should create a featurestore', async () => {
59+
const stdout = execSync(
60+
`node ./create-featurestore-fixed-nodes-sample.js ${project} ${featurestoreId} ${fixedNodeCount} ${location} ${apiEndpoint}`
61+
);
62+
assert.match(stdout, /Create featurestore fixed nodes response/);
63+
});
64+
after('should delete the created featurestore', async () => {
65+
await deleteFeaturestore();
66+
});
67+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
'use strict';
18+
19+
const {assert} = require('chai');
20+
const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1;
21+
const {after, describe, it} = require('mocha');
22+
const uuid = require('uuid').v4;
23+
const cp = require('child_process');
24+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
25+
26+
const project = process.env.CAIP_PROJECT_ID;
27+
const featurestoreId = `featurestore_sample_${uuid()
28+
.replace(/-/g, '_')
29+
.slice(10, 20)}`;
30+
const minNodeCount = 1;
31+
const maxNodeCount = 5;
32+
const location = 'us-central1';
33+
const apiEndpoint = 'us-central1-aiplatform.googleapis.com';
34+
35+
// Instantiates a featurestore clients
36+
const featurestoreServiceClient = new FeaturestoreServiceClient({
37+
apiEndpoint: apiEndpoint,
38+
});
39+
40+
const deleteFeaturestore = async () => {
41+
// Configure the name resource
42+
const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`;
43+
44+
const request = {
45+
name: name,
46+
force: true,
47+
};
48+
49+
// Delete Featurestore request
50+
const [operation] = await featurestoreServiceClient.deleteFeaturestore(
51+
request,
52+
{timeout: 60000}
53+
);
54+
await operation.promise();
55+
};
56+
57+
describe('AI platform create featurestore', async function () {
58+
this.retries(2);
59+
it('should create a featurestore', async () => {
60+
const stdout = execSync(
61+
`node ./create-featurestore-sample.js ${project} ${featurestoreId} ${minNodeCount} ${maxNodeCount} ${location} ${apiEndpoint}`
62+
);
63+
assert.match(stdout, /Create featurestore response/);
64+
});
65+
after('should delete the created featurestore', async () => {
66+
await deleteFeaturestore();
67+
});
68+
});

0 commit comments

Comments
 (0)