-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* work in progress - broken * Add autoscaling options to interface * Work in progress on function for setting metadata * Fixed some tests that were broken due to the chang * Cluster.ts in test file * Update cluster creation to accept new parameters * Fix for failing test * Enhance system tests for cluster * Add another test * condense tests * Added more tests * Test improvements * Change update mask to get manual scaling right * Added validation for cluster creation configs * Refactor cluster object in tests * Another cluster id refactor * Remove TODO that no longer applies * Code reorganization for test cases * Fix the test so that it breaks for good reason * update mask push fix * Add nodes in all calls to update and create cluste * Add license headers * correct copyright year * Add singlequote * Add a validation * Update test descriptions * refactor to use one check metadata function * Fix tests as specifying nodes is required anyway * should added to test case descriptions * PR updates * validation error * Remove call to get metadata * PR updates
- Loading branch information
1 parent
033bfc8
commit e5f6fdb
Showing
9 changed files
with
667 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
// 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. | ||
|
||
import * as protos from '../../protos/protos'; | ||
import { | ||
BasicClusterConfig, | ||
ICluster, | ||
SetClusterMetadataOptions, | ||
} from '../cluster'; | ||
import {google} from '../../protos/protos'; | ||
|
||
export class ClusterUtils { | ||
static noConfigError = | ||
'Must specify either serve_nodes or all of the autoscaling configurations (min_serve_nodes, max_serve_nodes, and cpu_utilization_percent).'; | ||
static allConfigError = | ||
'Cannot specify both serve_nodes and autoscaling configurations (min_serve_nodes, max_serve_nodes, and cpu_utilization_percent).'; | ||
static incompleteConfigError = | ||
'All of autoscaling configurations must be specified at the same time (min_serve_nodes, max_serve_nodes, and cpu_utilization_percent).'; | ||
|
||
static validateClusterMetadata( | ||
metadata: SetClusterMetadataOptions | BasicClusterConfig | ||
): void { | ||
if (metadata.nodes) { | ||
if ( | ||
metadata.minServeNodes || | ||
metadata.maxServeNodes || | ||
metadata.cpuUtilizationPercent | ||
) { | ||
throw new Error(this.allConfigError); | ||
} | ||
} else { | ||
if ( | ||
metadata.minServeNodes || | ||
metadata.maxServeNodes || | ||
metadata.cpuUtilizationPercent | ||
) { | ||
if ( | ||
!( | ||
metadata.minServeNodes && | ||
metadata.maxServeNodes && | ||
metadata.cpuUtilizationPercent | ||
) | ||
) { | ||
throw new Error(this.incompleteConfigError); | ||
} | ||
} else { | ||
throw new Error(this.noConfigError); | ||
} | ||
} | ||
} | ||
static getUpdateMask(metadata: SetClusterMetadataOptions): string[] { | ||
const updateMask: string[] = []; | ||
if (metadata.nodes) { | ||
updateMask.push('serve_nodes'); | ||
if ( | ||
!( | ||
metadata.minServeNodes || | ||
metadata.maxServeNodes || | ||
metadata.cpuUtilizationPercent | ||
) | ||
) { | ||
updateMask.push('cluster_config.cluster_autoscaling_config'); | ||
} | ||
} | ||
if (metadata.minServeNodes) { | ||
updateMask.push( | ||
'cluster_config.cluster_autoscaling_config.autoscaling_limits.min_serve_nodes' | ||
); | ||
} | ||
if (metadata.maxServeNodes) { | ||
updateMask.push( | ||
'cluster_config.cluster_autoscaling_config.autoscaling_limits.max_serve_nodes' | ||
); | ||
} | ||
if (metadata.cpuUtilizationPercent) { | ||
updateMask.push( | ||
'cluster_config.cluster_autoscaling_config.autoscaling_targets.cpu_utilization_percent' | ||
); | ||
} | ||
return updateMask; | ||
} | ||
|
||
static getClusterBaseConfig( | ||
metadata: SetClusterMetadataOptions | BasicClusterConfig, | ||
location: string | undefined | null, | ||
name: string | undefined | ||
): google.bigtable.admin.v2.ICluster { | ||
let clusterConfig; | ||
if ( | ||
metadata.cpuUtilizationPercent || | ||
metadata.minServeNodes || | ||
metadata.maxServeNodes | ||
) { | ||
clusterConfig = { | ||
clusterAutoscalingConfig: { | ||
autoscalingTargets: { | ||
cpuUtilizationPercent: metadata.cpuUtilizationPercent, | ||
}, | ||
autoscalingLimits: { | ||
minServeNodes: metadata.minServeNodes, | ||
maxServeNodes: metadata.maxServeNodes, | ||
}, | ||
}, | ||
}; | ||
} | ||
return Object.assign( | ||
{}, | ||
name ? {name} : null, | ||
location ? {location} : null, | ||
clusterConfig ? {clusterConfig} : null, | ||
metadata.nodes ? {serveNodes: metadata.nodes} : null | ||
); | ||
} | ||
|
||
static getClusterFromMetadata( | ||
metadata: SetClusterMetadataOptions, | ||
location: string | undefined | null, | ||
name: string | ||
): google.bigtable.admin.v2.ICluster { | ||
const cluster: ICluster | SetClusterMetadataOptions = Object.assign( | ||
{}, | ||
this.getClusterBaseConfig(metadata, location, name), | ||
metadata | ||
); | ||
delete (cluster as SetClusterMetadataOptions).nodes; | ||
delete (cluster as SetClusterMetadataOptions).minServeNodes; | ||
delete (cluster as SetClusterMetadataOptions).maxServeNodes; | ||
delete (cluster as SetClusterMetadataOptions).cpuUtilizationPercent; | ||
return cluster as ICluster; | ||
} | ||
|
||
static getRequestFromMetadata( | ||
metadata: SetClusterMetadataOptions, | ||
location: string | undefined | null, | ||
name: string | ||
): protos.google.bigtable.admin.v2.IPartialUpdateClusterRequest { | ||
return { | ||
cluster: this.getClusterFromMetadata(metadata, location, name), | ||
updateMask: {paths: this.getUpdateMask(metadata)}, | ||
}; | ||
} | ||
} |
Oops, something went wrong.