1313// limitations under the License.
1414
1515const snippets = {
16- create : ( instanceId , appProfileId ) => {
16+ create : async ( instanceId , appProfileId ) => {
1717 // [START bigtable_api_create_app_profile]
18- const { Bigtable} = require ( '@google-cloud/bigtable' ) ;
19- const bigtable = new Bigtable ( ) ;
20- const instance = bigtable . instance ( instanceId ) ;
21- const appProfile = instance . appProfile ( appProfileId ) ;
22- // set routing policy, required for creating an app-profile
23- const options = {
24- routing : 'any' ,
18+ const { BigtableInstanceAdminClient} = require ( '@google-cloud/bigtable' ) . v2 ;
19+ const instanceAdminClient = new BigtableInstanceAdminClient ( ) ;
20+ const projectId = await instanceAdminClient . getProjectId ( ) ;
21+
22+ const appProfile = {
23+ name : instanceAdminClient . appProfilePath (
24+ projectId ,
25+ instanceId ,
26+ appProfileId ,
27+ ) ,
28+ multiClusterRoutingUseAny : { } ,
29+ } ;
30+
31+ const request = {
32+ parent : instanceAdminClient . instancePath ( projectId , instanceId ) ,
33+ appProfileId : appProfileId ,
34+ appProfile : appProfile ,
2535 } ;
2636
27- appProfile
28- . create ( options )
37+ instanceAdminClient
38+ . createAppProfile ( request )
2939 . then ( result => {
3040 const appProfile = result [ 0 ] ;
3141 const apiResponse = result [ 1 ] ;
@@ -36,15 +46,22 @@ const snippets = {
3646 // [END bigtable_api_create_app_profile]
3747 } ,
3848
39- delete : ( instanceId , appProfileId ) => {
49+ delete : async ( instanceId , appProfileId ) => {
4050 // [START bigtable_api_delete_app_profile]
41- const { Bigtable} = require ( '@google-cloud/bigtable' ) ;
42- const bigtable = new Bigtable ( ) ;
43- const instance = bigtable . instance ( instanceId ) ;
44- const appProfile = instance . appProfile ( appProfileId ) ;
51+ const { BigtableInstanceAdminClient} = require ( '@google-cloud/bigtable' ) . v2 ;
52+ const instanceAdminClient = new BigtableInstanceAdminClient ( ) ;
53+ const projectId = await instanceAdminClient . getProjectId ( ) ;
54+
55+ const request = {
56+ name : instanceAdminClient . appProfilePath (
57+ projectId ,
58+ instanceId ,
59+ appProfileId ,
60+ ) ,
61+ } ;
4562
46- appProfile
47- . delete ( )
63+ instanceAdminClient
64+ . deleteAppProfile ( request )
4865 . then ( result => {
4966 const apiResponse = result [ 0 ] ;
5067 } )
@@ -54,33 +71,50 @@ const snippets = {
5471 // [END bigtable_api_delete_app_profile]
5572 } ,
5673
57- exists : ( instanceId , appProfileId ) => {
74+ exists : async ( instanceId , appProfileId ) => {
5875 // [START bigtable_api_exists_app_profile]
59- const { Bigtable} = require ( '@google-cloud/bigtable' ) ;
60- const bigtable = new Bigtable ( ) ;
61- const instance = bigtable . instance ( instanceId ) ;
62- const appProfile = instance . appProfile ( appProfileId ) ;
76+ const { BigtableInstanceAdminClient} = require ( '@google-cloud/bigtable' ) . v2 ;
77+ const instanceAdminClient = new BigtableInstanceAdminClient ( ) ;
78+ const projectId = await instanceAdminClient . getProjectId ( ) ;
6379
64- appProfile
65- . exists ( )
66- . then ( result => {
67- const exists = result [ 0 ] ;
68- } )
69- . catch ( err => {
80+ const request = {
81+ name : instanceAdminClient . appProfilePath (
82+ projectId ,
83+ instanceId ,
84+ appProfileId ,
85+ ) ,
86+ } ;
87+
88+ try {
89+ await instanceAdminClient . getAppProfile ( request ) ;
90+ console . log ( 'App profile exists.' ) ;
91+ } catch ( err ) {
92+ if ( err . code === 5 ) {
93+ console . log ( 'App profile does not exist.' ) ;
94+ } else {
7095 // Handle the error.
71- } ) ;
96+ console . error ( err ) ;
97+ }
98+ }
7299 // [END bigtable_api_exists_app_profile]
73100 } ,
74101
75- get : ( instanceId , appProfileId ) => {
102+ get : async ( instanceId , appProfileId ) => {
76103 // [START bigtable_api_get_app_profile]
77- const { Bigtable} = require ( '@google-cloud/bigtable' ) ;
78- const bigtable = new Bigtable ( ) ;
79- const instance = bigtable . instance ( instanceId ) ;
80- const appProfile = instance . appProfile ( appProfileId ) ;
104+ const { BigtableInstanceAdminClient} = require ( '@google-cloud/bigtable' ) . v2 ;
105+ const instanceAdminClient = new BigtableInstanceAdminClient ( ) ;
106+ const projectId = await instanceAdminClient . getProjectId ( ) ;
107+
108+ const request = {
109+ name : instanceAdminClient . appProfilePath (
110+ projectId ,
111+ instanceId ,
112+ appProfileId ,
113+ ) ,
114+ } ;
81115
82- appProfile
83- . get ( )
116+ instanceAdminClient
117+ . getAppProfile ( request )
84118 . then ( result => {
85119 const appProfile = result [ 0 ] ;
86120 const apiResponse = result [ 1 ] ;
@@ -91,15 +125,22 @@ const snippets = {
91125 // [END bigtable_api_get_app_profile]
92126 } ,
93127
94- getMeta : ( instanceId , appProfileId ) => {
128+ getMeta : async ( instanceId , appProfileId ) => {
95129 // [START bigtable_api_app_profile_get_meta]
96- const { Bigtable} = require ( '@google-cloud/bigtable' ) ;
97- const bigtable = new Bigtable ( ) ;
98- const instance = bigtable . instance ( instanceId ) ;
99- const appProfile = instance . appProfile ( appProfileId ) ;
130+ const { BigtableInstanceAdminClient} = require ( '@google-cloud/bigtable' ) . v2 ;
131+ const instanceAdminClient = new BigtableInstanceAdminClient ( ) ;
132+ const projectId = await instanceAdminClient . getProjectId ( ) ;
100133
101- appProfile
102- . getMetadata ( )
134+ const request = {
135+ name : instanceAdminClient . appProfilePath (
136+ projectId ,
137+ instanceId ,
138+ appProfileId ,
139+ ) ,
140+ } ;
141+
142+ instanceAdminClient
143+ . getAppProfile ( request )
103144 . then ( result => {
104145 const metadata = result [ 0 ] ;
105146 const apiResponse = result [ 1 ] ;
@@ -110,22 +151,31 @@ const snippets = {
110151 // [END bigtable_api_app_profile_get_meta]
111152 } ,
112153
113- setMeta : ( instanceId , appProfileId , clusterId ) => {
154+ setMeta : async ( instanceId , appProfileId , clusterId ) => {
114155 // [START bigtable_api_app_profile_set_meta]
115- const { Bigtable} = require ( '@google-cloud/bigtable' ) ;
116- const bigtable = new Bigtable ( ) ;
117- const instance = bigtable . instance ( instanceId ) ;
118- const cluster = instance . cluster ( clusterId ) ;
119- const appProfile = instance . appProfile ( appProfileId ) ;
156+ const { BigtableInstanceAdminClient} = require ( '@google-cloud/bigtable' ) . v2 ;
157+ const instanceAdminClient = new BigtableInstanceAdminClient ( ) ;
158+ const projectId = await instanceAdminClient . getProjectId ( ) ;
120159
121- const metadata = {
160+ const appProfile = {
161+ name : instanceAdminClient . appProfilePath (
162+ projectId ,
163+ instanceId ,
164+ appProfileId ,
165+ ) ,
122166 description : 'My Updated App Profile' ,
123- routing : cluster ,
124- allowTransactionalWrites : true ,
167+ multiClusterRoutingUseAny : { } ,
168+ } ;
169+
170+ const request = {
171+ appProfile : appProfile ,
172+ updateMask : {
173+ paths : [ 'description' , 'multi_cluster_routing_use_any' ] ,
174+ } ,
125175 } ;
126176
127- appProfile
128- . setMetadata ( metadata )
177+ instanceAdminClient
178+ . updateAppProfile ( request )
129179 . then ( result => {
130180 const apiResponse = result [ 0 ] ;
131181 } )
0 commit comments