Skip to content

Commit 7cac56c

Browse files
CopilotBlankll
andauthored
Migrate Aliyun Database Resources (RDS & ES Serverless) to state-based management engine (#146)
This pull request adds support for managing Alibaba Cloud RDS (Relational Database Service) and ES (Elasticsearch Serverless) resources in the codebase. It introduces new client initializations, operation modules, and type definitions for both services, and updates ESLint and dependencies accordingly. **New Alibaba Cloud service support:** * Added `@alicloud/rds20140815` and `@alicloud/es-serverless20230627` dependencies to `package.json` to enable RDS and ES Serverless operations. * Initialized `RdsClient` and `EsServerlessClient` in `src/common/aliyunClient/index.ts`, including endpoint configuration and exporting their operation creators. [[1]](diffhunk://#diff-f3f90b061baa39815fc9e43d17033101d09035011ad0334569a1d351bdbe8760R7-R8) [[2]](diffhunk://#diff-f3f90b061baa39815fc9e43d17033101d09035011ad0334569a1d351bdbe8760R19-R26) [[3]](diffhunk://#diff-f3f90b061baa39815fc9e43d17033101d09035011ad0334569a1d351bdbe8760R67-R74) [[4]](diffhunk://#diff-f3f90b061baa39815fc9e43d17033101d09035011ad0334569a1d351bdbe8760R83-R84) [[5]](diffhunk://#diff-f3f90b061baa39815fc9e43d17033101d09035011ad0334569a1d351bdbe8760R99-R100) **New operation modules:** * Added `src/common/aliyunClient/rdsOperations.ts` to provide functions for creating, retrieving, updating, and deleting RDS instances, with status polling and error handling. * Added `src/common/aliyunClient/esOperations.ts` to provide similar CRUD operations for ES Serverless applications, including status polling and error handling. **Code quality improvements:** * Enabled the ESLint rule `@typescript-eslint/no-unused-vars` with exceptions for variables prefixed with `_`, improving code cleanliness without breaking convention for intentionally unused variables. * Removed an unnecessary ESLint disable comment in `src/common/stateManager.ts` for cleaner code. <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>[MIGRATION] Migrate Aliyun Database Resources to Terraform-like State Engine</issue_title> > <issue_description>## Summary > Migrate Aliyun database resources (RDS Serverless, Elasticsearch Serverless) from ROS template-based deployment to the unified Terraform-like state management engine. > > ## Background > Currently, Aliyun databases are managed via ROS CDK constructs in `src/stack/rosStack/database.ts`. This must now be migrated to a new architecture based on state management with strict separation of provider-agnostic and provider-specific logic. > > ## Updated Architecture > ``` > ┌─────────────────────────────────────────┐ > │ Resource / Planner / Executor Layer │ ← Provider-agnostic business logic > │ (Pure functions, no SDK imports) │ > └─────────────────────────────────────────┘ > ↓ > ┌─────────────────────────────────────────┐ > │ Functional Client Layer │ ← Encapsulated SDK operations > │ (aliyunClient.ts, tencentClient.ts) │ > └─────────────────────────────────────────┘ > ↓ > ┌─────────────────────────────────────────┐ > │ Cloud Provider SDKs │ ← @alicloud/*, tencentcloud-* > └─────────────────────────────────────────┘ > ``` > > - **Resource/Planner/Executor Layer:** Pure, provider-agnostic business logic for resources, drift/planning, execution. No direct SDK import or cloud-specific code. (See: `databaseResource.ts`, `databasePlanner.ts`, `databaseExecutor.ts`) > - **Functional Client Layer:** Encapsulates all SDK operations. E.g. `aliyunClient.ts` abstracts Aliyun API/SDK calls for RDS, ES, etc. This is the *only* layer with cloud SDK imports or API calls. New functional clients must be implemented for supported clouds. > - **Cloud Provider SDKs:** External dependencies such as `@alicloud/ros-cdk-rds`, `@alicloud/ros-cdk-elasticsearch-serverless`, `tencentcloud-*` SDKs, etc. > > ## Current Implementation (to be migrated) > - **File**: [`src/stack/rosStack/database.ts`](https://github.com/geek-fun/serverlessinsight/blob/master/src/stack/rosStack/database.ts) > - Supports: RDS MySQL/PostgreSQL/MSSQL Serverless, Elasticsearch Serverless > - Uses `@alicloud/ros-cdk-rds`, `@alicloud/ros-cdk-elasticsearch-serverless` > > ## Target Implementation > Create new modules under `src/stack/aliyunStack/` as per new architecture: > - **Client**: `aliyunClient.ts` > - **Types**: `rdsTypes.ts`, `esServerlessTypes.ts` > - **Resource:** `databaseResource.ts` > - **Planner:** `databasePlanner.ts` > - **Executor:** `databaseExecutor.ts` > > ## Requirements > ### 1. RDS Serverless Functional Client > ```typescript > export const createRdsInstance = async (context: Context, config: RdsConfig): Promise<string> > export const getRdsInstance = async (context: Context, instanceId: string): Promise<RdsInfo | null> > export const updateRdsInstance = async (context: Context, instanceId: string, config: RdsConfig): Promise<void> > export const deleteRdsInstance = async (context: Context, instanceId: string): Promise<void> > ``` > ### 2. Elasticsearch Serverless Functional Client > ```typescript > export const createEsApp = async (context: Context, config: EsConfig): Promise<string> > export const getEsApp = async (context: Context, appId: string): Promise<EsInfo | null> > export const updateEsApp = async (context: Context, appId: string, config: EsConfig): Promise<void> > export const deleteEsApp = async (context: Context, appId: string): Promise<void> > ``` > ### 3. Handle Features > - RDS Serverless: MySQL 5.7/8.0, PostgreSQL 14/15/16, MSSQL 2016-2019 > - Elasticsearch Serverless with basic auth > - Auto-scaling configuration (min/max CU) > - Storage configuration > - Network/VPC settings > ### 4. State Types > Add to `ResourceTypeEnum`: > - `ALIYUN_RDS_SERVERLESS` > - `ALIYUN_ES_SERVERLESS` > > ## Acceptance Criteria > - [ ] RDS Serverless instances can be managed via state > - [ ] Elasticsearch Serverless apps can be managed via state > - [ ] Configuration changes trigger proper updates > - [ ] Drift detection works for database resources > > ## References > - Current ROS implementation: [`src/stack/rosStack/database.ts`](https://github.com/geek-fun/serverlessinsight/blob/master/src/stack/rosStack/database.ts) > - Tencent TDSQL-C pattern: [`src/stack/scfStack/tdsqlcPlanner.ts`](https://github.com/geek-fun/serverlessinsight/blob/master/src/stack/scfStack/tdsqlcPlanner.ts) > - See more architecture discussion in the documentation or RFCs.</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #130 <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Blankll <28639911+Blankll@users.noreply.github.com> Co-authored-by: Blankll <zilisheng1996@gmail.com>
1 parent 2edb344 commit 7cac56c

File tree

18 files changed

+2324
-1
lines changed

18 files changed

+2324
-1
lines changed

eslint.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ export default [
4545
'@typescript-eslint/no-empty-object-type': 'error',
4646
'@typescript-eslint/no-unsafe-function-type': 'error',
4747
'@typescript-eslint/no-wrapper-object-types': 'error',
48+
'@typescript-eslint/no-unused-vars': [
49+
'error',
50+
{
51+
argsIgnorePattern: '^_',
52+
varsIgnorePattern: '^_',
53+
},
54+
],
4855
},
4956
},
5057
];

package-lock.json

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@
5151
"dependencies": {
5252
"@alicloud/cloudapi20160714": "^4.7.8",
5353
"@alicloud/ecs20140526": "^7.4.2",
54+
"@alicloud/es-serverless20230627": "^2.2.0",
5455
"@alicloud/fc20230330": "^4.6.6",
5556
"@alicloud/ims20190815": "^2.3.2",
5657
"@alicloud/nas20170626": "^3.1.4",
5758
"@alicloud/openapi-client": "^0.4.15",
5859
"@alicloud/ram20150501": "^1.2.0",
60+
"@alicloud/rds20140815": "^13.1.0",
5961
"@alicloud/ros-cdk-apigateway": "^1.11.0",
6062
"@alicloud/ros-cdk-core": "^1.11.0",
6163
"@alicloud/ros-cdk-dns": "^1.11.0",

0 commit comments

Comments
 (0)