Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 75c1a30

Browse files
authored
feat: Remove need to pass location parameter along (#1093)
* snapshot tests for create cluster * change request to config * More snapshot tests * Refactor constants out * Add generated testcases for partial cluster update * Add header to constants file * Remove need to pass location along * Remove comment * eliminate compile error * lint fix
1 parent 886af7a commit 75c1a30

6 files changed

Lines changed: 32 additions & 42 deletions

File tree

src/cluster.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export interface SetClusterMetadataOptions {
8080
minServeNodes?: number;
8181
maxServeNodes?: number;
8282
cpuUtilizationPercent?: number;
83+
location?: string;
8384
}
8485
export type SetClusterMetadataCallback = GenericOperationCallback<
8586
Operation | null | undefined
@@ -704,11 +705,7 @@ Please use the format 'my-cluster' or '${instance.name}/clusters/my-cluster'.`);
704705
typeof gaxOptionsOrCallback === 'object'
705706
? gaxOptionsOrCallback
706707
: ({} as CallOptions);
707-
const reqOpts = ClusterUtils.getRequestFromMetadata(
708-
metadata,
709-
this?.metadata?.location,
710-
this.name
711-
);
708+
const reqOpts = ClusterUtils.getRequestFromMetadata(metadata, this.name);
712709
this.bigtable.request<Operation>(
713710
{
714711
client: 'BigtableInstanceAdminClient',

src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,15 @@ export class Bigtable {
612612
);
613613
}
614614
ClusterUtils.validateClusterMetadata(cluster);
615+
const clusterClone = Object.assign({}, cluster);
616+
if (clusterClone.location) {
617+
clusterClone.location = Cluster.getLocation_(
618+
this.projectId,
619+
clusterClone.location
620+
);
621+
}
615622
clusters[cluster.id!] = ClusterUtils.getClusterBaseConfig(
616-
cluster,
617-
Cluster.getLocation_(this.projectId, cluster.location!),
623+
clusterClone,
618624
undefined
619625
);
620626
Object.assign(clusters[cluster.id!], {

src/instance.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,15 @@ Please use the format 'my-instance' or '${bigtable.projectName}/instances/my-ins
394394
} as google.bigtable.admin.v2.CreateClusterRequest;
395395
ClusterUtils.validateClusterMetadata(options);
396396
if (!is.empty(options)) {
397+
const optionsClone = Object.assign({}, options);
398+
if (optionsClone.location) {
399+
optionsClone.location = Cluster.getLocation_(
400+
this.bigtable.projectId,
401+
optionsClone.location
402+
);
403+
}
397404
reqOpts.cluster = ClusterUtils.getClusterBaseConfig(
398-
options,
399-
options.location
400-
? Cluster.getLocation_(this.bigtable.projectId, options.location)
401-
: undefined,
405+
optionsClone,
402406
undefined
403407
);
404408
}

src/utils/cluster.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313
// limitations under the License.
1414

1515
import * as protos from '../../protos/protos';
16-
import {
17-
BasicClusterConfig,
18-
ICluster,
19-
SetClusterMetadataOptions,
20-
} from '../cluster';
16+
import {ICluster, SetClusterMetadataOptions} from '../cluster';
2117
import {google} from '../../protos/protos';
2218

2319
export class ClusterUtils {
@@ -28,9 +24,7 @@ export class ClusterUtils {
2824
static incompleteConfigError =
2925
'All of autoscaling configurations must be specified at the same time (min_serve_nodes, max_serve_nodes, and cpu_utilization_percent).';
3026

31-
static validateClusterMetadata(
32-
metadata: SetClusterMetadataOptions | BasicClusterConfig
33-
): void {
27+
static validateClusterMetadata(metadata: SetClusterMetadataOptions): void {
3428
if (metadata.nodes) {
3529
if (
3630
metadata.minServeNodes ||
@@ -92,8 +86,7 @@ export class ClusterUtils {
9286
}
9387

9488
static getClusterBaseConfig(
95-
metadata: SetClusterMetadataOptions | BasicClusterConfig,
96-
location: string | undefined | null,
89+
metadata: SetClusterMetadataOptions,
9790
name: string | undefined
9891
): google.bigtable.admin.v2.ICluster {
9992
let clusterConfig;
@@ -114,6 +107,7 @@ export class ClusterUtils {
114107
},
115108
};
116109
}
110+
const location = metadata?.location;
117111
return Object.assign(
118112
{},
119113
name ? {name} : null,
@@ -125,12 +119,11 @@ export class ClusterUtils {
125119

126120
static getClusterFromMetadata(
127121
metadata: SetClusterMetadataOptions,
128-
location: string | undefined | null,
129122
name: string
130123
): google.bigtable.admin.v2.ICluster {
131124
const cluster: ICluster | SetClusterMetadataOptions = Object.assign(
132125
{},
133-
this.getClusterBaseConfig(metadata, location, name),
126+
this.getClusterBaseConfig(metadata, name),
134127
metadata
135128
);
136129
delete (cluster as SetClusterMetadataOptions).nodes;
@@ -142,11 +135,10 @@ export class ClusterUtils {
142135

143136
static getRequestFromMetadata(
144137
metadata: SetClusterMetadataOptions,
145-
location: string | undefined | null,
146138
name: string
147139
): protos.google.bigtable.admin.v2.IPartialUpdateClusterRequest {
148140
return {
149-
cluster: this.getClusterFromMetadata(metadata, location, name),
141+
cluster: this.getClusterFromMetadata(metadata, name),
150142
updateMask: {paths: this.getUpdateMask(metadata)},
151143
};
152144
}

test/cluster.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,6 @@ describe('Bigtable/Cluster', () => {
10261026

10271027
const expectedReqOpts = ClusterUtils.getRequestFromMetadata(
10281028
options,
1029-
options.location,
10301029
CLUSTER_NAME
10311030
);
10321031

test/utils/cluster.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,17 @@ describe('Bigtable/Utils/Cluster', () => {
2121
it('should translate metadata for a full set of parameters', () => {
2222
const metadata = {
2323
nodes: 1,
24+
location: 'projects/{{projectId}}/locations/us-east4-b',
2425
minServeNodes: 2,
2526
maxServeNodes: 3,
2627
cpuUtilizationPercent: 50,
2728
};
2829
const name = 'cluster1';
29-
const location = 'projects/{{projectId}}/locations/us-east4-b';
30-
const reqOpts = ClusterUtils.getRequestFromMetadata(
31-
metadata,
32-
location,
33-
name
34-
);
30+
const reqOpts = ClusterUtils.getRequestFromMetadata(metadata, name);
3531
assert.deepStrictEqual(reqOpts, {
3632
cluster: {
37-
name: name,
38-
location: location,
33+
name,
34+
location: metadata.location,
3935
serveNodes: metadata.nodes,
4036
clusterConfig: {
4137
clusterAutoscalingConfig: {
@@ -61,21 +57,17 @@ describe('Bigtable/Utils/Cluster', () => {
6157
});
6258
it('should translate metadata for autoscaling parameters', () => {
6359
const metadata = {
60+
location: 'projects/{{projectId}}/locations/us-east4-b',
6461
minServeNodes: 2,
6562
maxServeNodes: 3,
6663
cpuUtilizationPercent: 50,
6764
};
6865
const name = 'cluster1';
69-
const location = 'projects/{{projectId}}/locations/us-east4-b';
70-
const reqOpts = ClusterUtils.getRequestFromMetadata(
71-
metadata,
72-
location,
73-
name
74-
);
66+
const reqOpts = ClusterUtils.getRequestFromMetadata(metadata, name);
7567
assert.deepStrictEqual(reqOpts, {
7668
cluster: {
77-
name: name,
78-
location: location,
69+
name,
70+
location: metadata.location,
7971
clusterConfig: {
8072
clusterAutoscalingConfig: {
8173
autoscalingLimits: {

0 commit comments

Comments
 (0)