1313// limitations under the License.
1414
1515const snippets = {
16- create : async ( instanceId , appProfileId ) => {
16+ create : ( instanceId , appProfileId ) => {
1717 // [START bigtable_api_create_app_profile]
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 ,
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' ,
3525 } ;
3626
37- instanceAdminClient
38- . createAppProfile ( request )
27+ appProfile
28+ . create ( options )
3929 . then ( result => {
4030 const appProfile = result [ 0 ] ;
4131 const apiResponse = result [ 1 ] ;
@@ -46,22 +36,15 @@ const snippets = {
4636 // [END bigtable_api_create_app_profile]
4737 } ,
4838
49- delete : async ( instanceId , appProfileId ) => {
39+ delete : ( instanceId , appProfileId ) => {
5040 // [START bigtable_api_delete_app_profile]
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- } ;
41+ const { Bigtable} = require ( '@google-cloud/bigtable' ) ;
42+ const bigtable = new Bigtable ( ) ;
43+ const instance = bigtable . instance ( instanceId ) ;
44+ const appProfile = instance . appProfile ( appProfileId ) ;
6245
63- instanceAdminClient
64- . deleteAppProfile ( request )
46+ appProfile
47+ . delete ( )
6548 . then ( result => {
6649 const apiResponse = result [ 0 ] ;
6750 } )
@@ -71,50 +54,33 @@ const snippets = {
7154 // [END bigtable_api_delete_app_profile]
7255 } ,
7356
74- exists : async ( instanceId , appProfileId ) => {
57+ exists : ( instanceId , appProfileId ) => {
7558 // [START bigtable_api_exists_app_profile]
76- const { BigtableInstanceAdminClient} = require ( '@google-cloud/bigtable' ) . v2 ;
77- const instanceAdminClient = new BigtableInstanceAdminClient ( ) ;
78- const projectId = await instanceAdminClient . getProjectId ( ) ;
59+ const { Bigtable} = require ( '@google-cloud/bigtable' ) ;
60+ const bigtable = new Bigtable ( ) ;
61+ const instance = bigtable . instance ( instanceId ) ;
62+ const appProfile = instance . appProfile ( appProfileId ) ;
7963
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 {
64+ appProfile
65+ . exists ( )
66+ . then ( result => {
67+ const exists = result [ 0 ] ;
68+ } )
69+ . catch ( err => {
9570 // Handle the error.
96- console . error ( err ) ;
97- }
98- }
71+ } ) ;
9972 // [END bigtable_api_exists_app_profile]
10073 } ,
10174
102- get : async ( instanceId , appProfileId ) => {
75+ get : ( instanceId , appProfileId ) => {
10376 // [START bigtable_api_get_app_profile]
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- } ;
77+ const { Bigtable} = require ( '@google-cloud/bigtable' ) ;
78+ const bigtable = new Bigtable ( ) ;
79+ const instance = bigtable . instance ( instanceId ) ;
80+ const appProfile = instance . appProfile ( appProfileId ) ;
11581
116- instanceAdminClient
117- . getAppProfile ( request )
82+ appProfile
83+ . get ( )
11884 . then ( result => {
11985 const appProfile = result [ 0 ] ;
12086 const apiResponse = result [ 1 ] ;
@@ -125,22 +91,15 @@ const snippets = {
12591 // [END bigtable_api_get_app_profile]
12692 } ,
12793
128- getMeta : async ( instanceId , appProfileId ) => {
94+ getMeta : ( instanceId , appProfileId ) => {
12995 // [START bigtable_api_app_profile_get_meta]
130- const { BigtableInstanceAdminClient} = require ( '@google-cloud/bigtable' ) . v2 ;
131- const instanceAdminClient = new BigtableInstanceAdminClient ( ) ;
132- const projectId = await instanceAdminClient . getProjectId ( ) ;
96+ const { Bigtable} = require ( '@google-cloud/bigtable' ) ;
97+ const bigtable = new Bigtable ( ) ;
98+ const instance = bigtable . instance ( instanceId ) ;
99+ const appProfile = instance . appProfile ( appProfileId ) ;
133100
134- const request = {
135- name : instanceAdminClient . appProfilePath (
136- projectId ,
137- instanceId ,
138- appProfileId ,
139- ) ,
140- } ;
141-
142- instanceAdminClient
143- . getAppProfile ( request )
101+ appProfile
102+ . getMetadata ( )
144103 . then ( result => {
145104 const metadata = result [ 0 ] ;
146105 const apiResponse = result [ 1 ] ;
@@ -151,31 +110,22 @@ const snippets = {
151110 // [END bigtable_api_app_profile_get_meta]
152111 } ,
153112
154- setMeta : async ( instanceId , appProfileId , clusterId ) => {
113+ setMeta : ( instanceId , appProfileId , clusterId ) => {
155114 // [START bigtable_api_app_profile_set_meta]
156- const { BigtableInstanceAdminClient} = require ( '@google-cloud/bigtable' ) . v2 ;
157- const instanceAdminClient = new BigtableInstanceAdminClient ( ) ;
158- const projectId = await instanceAdminClient . getProjectId ( ) ;
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 ) ;
159120
160- const appProfile = {
161- name : instanceAdminClient . appProfilePath (
162- projectId ,
163- instanceId ,
164- appProfileId ,
165- ) ,
121+ const metadata = {
166122 description : 'My Updated App Profile' ,
167- multiClusterRoutingUseAny : { } ,
168- } ;
169-
170- const request = {
171- appProfile : appProfile ,
172- updateMask : {
173- paths : [ 'description' , 'multi_cluster_routing_use_any' ] ,
174- } ,
123+ routing : cluster ,
124+ allowTransactionalWrites : true ,
175125 } ;
176126
177- instanceAdminClient
178- . updateAppProfile ( request )
127+ appProfile
128+ . setMetadata ( metadata )
179129 . then ( result => {
180130 const apiResponse = result [ 0 ] ;
181131 } )
0 commit comments