@geek-fun/serverlessinsight 0.8.2 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +15 -0
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +33 -0
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +359 -0
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +15 -0
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +154 -0
- package/.serverlessinsight/state-insight-volc-destroy-app-insight-volc-destroy.json.backup +1 -0
- package/README.md +26 -18
- package/README.zh-CN.md +19 -6
- package/dist/package.json +5 -2
- package/dist/src/commands/deploy.js +87 -4
- package/dist/src/commands/destroy.js +61 -10
- package/dist/src/commands/forceUnlock.js +8 -0
- package/dist/src/commands/index.js +34 -2
- package/dist/src/commands/login.js +195 -0
- package/dist/src/commands/logout.js +17 -0
- package/dist/src/commands/show.js +15 -7
- package/dist/src/commands/whoami.js +20 -0
- package/dist/src/common/aliyunClient/apigwOperations.js +363 -30
- package/dist/src/common/aliyunClient/esOperations.js +43 -29
- package/dist/src/common/aliyunClient/fc3Operations.js +481 -207
- package/dist/src/common/aliyunClient/ossOperations.js +165 -13
- package/dist/src/common/aliyunClient/rdsOperations.js +143 -39
- package/dist/src/common/aliyunClient/slsOperations.js +90 -28
- package/dist/src/common/aliyunClient/tablestoreOperations.js +25 -22
- package/dist/src/common/apiClient.js +102 -0
- package/dist/src/common/constants.js +13 -4
- package/dist/src/common/credentialStore.js +94 -0
- package/dist/src/common/credentials.js +2 -0
- package/dist/src/common/eventQueue.js +208 -0
- package/dist/src/common/hashUtils.js +87 -11
- package/dist/src/common/imsClient.js +1 -0
- package/dist/src/common/index.js +3 -0
- package/dist/src/common/lockManager.js +61 -54
- package/dist/src/common/logger.js +2 -0
- package/dist/src/common/polling.js +54 -0
- package/dist/src/common/reportResourceEvent.js +8 -0
- package/dist/src/common/runtimeMapper.js +11 -12
- package/dist/src/common/stateBackend/index.js +10 -1
- package/dist/src/common/stateBackend/localStateBackend.js +4 -1
- package/dist/src/common/stateBackend/remoteStateBackend.js +10 -4
- package/dist/src/common/stateBackend/saasStateBackend.js +266 -0
- package/dist/src/common/stateManager.js +186 -14
- package/dist/src/common/tencentClient/clsOperations.js +137 -0
- package/dist/src/common/tencentClient/cosOperations.js +180 -3
- package/dist/src/common/tencentClient/esOperations.js +110 -46
- package/dist/src/common/tencentClient/index.js +43 -2
- package/dist/src/common/tencentClient/scfOperations.js +266 -133
- package/dist/src/common/tencentClient/tdsqlcClusterMapper.js +81 -0
- package/dist/src/common/tencentClient/tdsqlcOperations.js +93 -99
- package/dist/src/common/triggerMapper.js +36 -0
- package/dist/src/common/volcengineClient/apigwOperations.js +539 -159
- package/dist/src/common/volcengineClient/iamOperations.js +91 -48
- package/dist/src/common/volcengineClient/index.js +46 -21
- package/dist/src/common/volcengineClient/stsOperations.js +32 -0
- package/dist/src/common/volcengineClient/tlsOperations.js +305 -171
- package/dist/src/common/volcengineClient/tosOperations.js +78 -19
- package/dist/src/common/volcengineClient/vefaasOperations.js +272 -54
- package/dist/src/lang/en.js +107 -1
- package/dist/src/lang/zh-CN.js +107 -1
- package/dist/src/parser/eventParser.js +2 -0
- package/dist/src/parser/functionParser.js +96 -65
- package/dist/src/parser/index.js +7 -4
- package/dist/src/stack/aliyunStack/apigwExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/apigwPlanner.js +16 -10
- package/dist/src/stack/aliyunStack/apigwResource.js +334 -125
- package/dist/src/stack/aliyunStack/apigwTypes.js +35 -4
- package/dist/src/stack/aliyunStack/databaseExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/databasePlanner.js +13 -1
- package/dist/src/stack/aliyunStack/databaseResource.js +135 -40
- package/dist/src/stack/aliyunStack/deployer.js +2 -2
- package/dist/src/stack/aliyunStack/destroyer.js +27 -2
- package/dist/src/stack/aliyunStack/fc3Executor.js +25 -2
- package/dist/src/stack/aliyunStack/fc3Planner.js +11 -1
- package/dist/src/stack/aliyunStack/fc3Resource.js +416 -94
- package/dist/src/stack/aliyunStack/ossExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/ossPlanner.js +15 -1
- package/dist/src/stack/aliyunStack/ossResource.js +267 -219
- package/dist/src/stack/aliyunStack/sharedLogProject.js +137 -0
- package/dist/src/stack/aliyunStack/tablestoreExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/tablestorePlanner.js +13 -1
- package/dist/src/stack/aliyunStack/tablestoreResource.js +54 -20
- package/dist/src/stack/alreadyExists.js +26 -0
- package/dist/src/stack/ownershipTag.js +58 -0
- package/dist/src/stack/rfsStack/index.js +3 -1
- package/dist/src/stack/scfStack/cosExecutor.js +39 -1
- package/dist/src/stack/scfStack/cosPlanner.js +11 -1
- package/dist/src/stack/scfStack/cosResource.js +167 -64
- package/dist/src/stack/scfStack/deployer.js +2 -2
- package/dist/src/stack/scfStack/destroyer.js +15 -2
- package/dist/src/stack/scfStack/esServerlessExecutor.js +39 -1
- package/dist/src/stack/scfStack/esServerlessPlanner.js +11 -1
- package/dist/src/stack/scfStack/esServerlessResource.js +88 -23
- package/dist/src/stack/scfStack/scfExecutor.js +39 -1
- package/dist/src/stack/scfStack/scfPlanner.js +21 -3
- package/dist/src/stack/scfStack/scfResource.js +686 -24
- package/dist/src/stack/scfStack/scfTypes.js +6 -0
- package/dist/src/stack/scfStack/sharedLogset.js +126 -0
- package/dist/src/stack/scfStack/tdsqlcExecutor.js +39 -1
- package/dist/src/stack/scfStack/tdsqlcPlanner.js +12 -1
- package/dist/src/stack/scfStack/tdsqlcResource.js +95 -16
- package/dist/src/stack/scfStack/tdsqlcTypes.js +5 -1
- package/dist/src/stack/volcengineStack/apigwExecutor.js +39 -1
- package/dist/src/stack/volcengineStack/apigwPlanner.js +25 -53
- package/dist/src/stack/volcengineStack/apigwResource.js +434 -222
- package/dist/src/stack/volcengineStack/apigwTypes.js +85 -66
- package/dist/src/stack/volcengineStack/deployer.js +49 -14
- package/dist/src/stack/volcengineStack/destroyer.js +13 -1
- package/dist/src/stack/volcengineStack/index.js +1 -2
- package/dist/src/stack/volcengineStack/sharedLogProject.js +190 -0
- package/dist/src/stack/volcengineStack/tosExecutor.js +25 -2
- package/dist/src/stack/volcengineStack/tosPlanner.js +11 -1
- package/dist/src/stack/volcengineStack/tosResource.js +82 -27
- package/dist/src/stack/volcengineStack/tosTypes.js +12 -0
- package/dist/src/stack/volcengineStack/vefaasExecutor.js +25 -2
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +78 -2
- package/dist/src/stack/volcengineStack/vefaasResource.js +194 -144
- package/dist/src/stack/volcengineStack/vefaasTypes.js +1 -3
- package/dist/src/types/domains/backend.js +1 -0
- package/dist/src/types/domains/state.js +32 -1
- package/dist/src/validator/eventSchema.js +10 -0
- package/dist/src/validator/functionSchema.js +37 -12
- package/dist/src/validator/iacSchema.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -2
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureGatewayLogstore = exports.ensureFunctionLogstore = exports.releaseSharedSlsProjectIfUnused = exports.isSharedProjectOwnedByApp = exports.adoptSharedSlsProjectState = exports.buildSharedProjectResourceState = exports.ensureSharedSlsProject = exports.resolveSharedProjectName = exports.buildSharedProjectName = exports.SHARED_LOG_PROJECT_KEY = void 0;
|
|
4
|
+
const common_1 = require("../../common");
|
|
5
|
+
const logger_1 = require("../../common/logger");
|
|
6
|
+
const lang_1 = require("../../lang");
|
|
7
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
8
|
+
/**
|
|
9
|
+
* Issue #214: one shared SLS project per app×stage, tracked in the stage-level
|
|
10
|
+
* `shared` slot under the provider-neutral key 'logs.project'. Function and
|
|
11
|
+
* gateway logstores stay nested under their owning resource inside the shared
|
|
12
|
+
* project; the shared project is released by the destroyer once the provider
|
|
13
|
+
* reports zero remaining logstores.
|
|
14
|
+
*/
|
|
15
|
+
exports.SHARED_LOG_PROJECT_KEY = 'logs.project';
|
|
16
|
+
const buildSharedProjectName = (app, stage) => `${app}-${stage}-sls`;
|
|
17
|
+
exports.buildSharedProjectName = buildSharedProjectName;
|
|
18
|
+
const resolveSharedProjectName = (shared) => {
|
|
19
|
+
const instanceId = shared.instances?.[0]?.id;
|
|
20
|
+
return instanceId ?? shared.definition?.projectName;
|
|
21
|
+
};
|
|
22
|
+
exports.resolveSharedProjectName = resolveSharedProjectName;
|
|
23
|
+
const ensureSharedSlsProject = async (context, client, state) => {
|
|
24
|
+
const shared = state
|
|
25
|
+
? (0, common_1.getSharedResource)(state, context.stage, exports.SHARED_LOG_PROJECT_KEY)
|
|
26
|
+
: undefined;
|
|
27
|
+
const existingName = shared ? (0, exports.resolveSharedProjectName)(shared) : undefined;
|
|
28
|
+
const projectName = existingName ?? (0, exports.buildSharedProjectName)(context.app, context.stage);
|
|
29
|
+
// A local shared-state entry is never trusted blindly: the provider must
|
|
30
|
+
// confirm the project exists and carries this app's shared ownership tag
|
|
31
|
+
// before it is reused. A foreign or untagged project is refused; a stale
|
|
32
|
+
// entry (project gone from provider) falls through to creation.
|
|
33
|
+
const existingProject = await client.sls.getProject(projectName);
|
|
34
|
+
if (existingProject) {
|
|
35
|
+
if (await (0, exports.isSharedProjectOwnedByApp)(context, client, projectName)) {
|
|
36
|
+
if (!existingName) {
|
|
37
|
+
logger_1.logger.info(lang_1.lang.__('SHARED_SLS_PROJECT_ADOPTED', { projectName }));
|
|
38
|
+
}
|
|
39
|
+
return { projectName };
|
|
40
|
+
}
|
|
41
|
+
throw new Error(lang_1.lang.__('SLS_PROJECT_FOREIGN_OWNED', { projectName }));
|
|
42
|
+
}
|
|
43
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_SLS_PROJECT', { projectName }));
|
|
44
|
+
await client.sls.createProject(projectName);
|
|
45
|
+
await client.sls.addTags({
|
|
46
|
+
resourceType: 'project',
|
|
47
|
+
resourceId: projectName,
|
|
48
|
+
tags: [
|
|
49
|
+
{
|
|
50
|
+
key: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
51
|
+
value: (0, ownershipTag_1.buildSharedOwnershipTagValue)(context.app, exports.SHARED_LOG_PROJECT_KEY),
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
return { projectName };
|
|
56
|
+
};
|
|
57
|
+
exports.ensureSharedSlsProject = ensureSharedSlsProject;
|
|
58
|
+
const buildSharedProjectResourceState = (context, result) => ({
|
|
59
|
+
mode: 'managed',
|
|
60
|
+
region: context.region,
|
|
61
|
+
definition: {
|
|
62
|
+
projectName: result.projectName,
|
|
63
|
+
region: context.region,
|
|
64
|
+
stage: context.stage,
|
|
65
|
+
},
|
|
66
|
+
instances: [
|
|
67
|
+
{
|
|
68
|
+
sid: (0, common_1.buildSid)('aliyun', 'sls_project', context.stage, result.projectName),
|
|
69
|
+
type: 'ALIYUN_SLS_PROJECT',
|
|
70
|
+
id: result.projectName,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
lastUpdated: new Date().toISOString(),
|
|
74
|
+
});
|
|
75
|
+
exports.buildSharedProjectResourceState = buildSharedProjectResourceState;
|
|
76
|
+
const adoptSharedSlsProjectState = (context, projectName) => (0, exports.buildSharedProjectResourceState)(context, { projectName });
|
|
77
|
+
exports.adoptSharedSlsProjectState = adoptSharedSlsProjectState;
|
|
78
|
+
/**
|
|
79
|
+
* Exact app-scope ownership check for an SLS project. The caller must verify
|
|
80
|
+
* the project exists (getProject) before reading its tags; a foreign or
|
|
81
|
+
* untagged project is never adopted (issue #214).
|
|
82
|
+
*/
|
|
83
|
+
const isSharedProjectOwnedByApp = async (context, client, projectName) => {
|
|
84
|
+
const tags = await client.sls.getProjectTags(projectName);
|
|
85
|
+
return (0, ownershipTag_1.isOwnedByApp)(context.app, exports.SHARED_LOG_PROJECT_KEY, tags.map((t) => ({ Key: t.key, Value: t.value })));
|
|
86
|
+
};
|
|
87
|
+
exports.isSharedProjectOwnedByApp = isSharedProjectOwnedByApp;
|
|
88
|
+
const releaseSharedSlsProjectIfUnused = async (context, client, shared) => {
|
|
89
|
+
if (!shared) {
|
|
90
|
+
return 'absent';
|
|
91
|
+
}
|
|
92
|
+
const projectName = (0, exports.resolveSharedProjectName)(shared);
|
|
93
|
+
if (!projectName) {
|
|
94
|
+
return 'absent';
|
|
95
|
+
}
|
|
96
|
+
const project = await client.sls.getProject(projectName);
|
|
97
|
+
if (!project) {
|
|
98
|
+
return 'absent';
|
|
99
|
+
}
|
|
100
|
+
// Only ever delete a project we own. A foreign or untagged project is
|
|
101
|
+
// retained — the tracked entry may be stale and must not be torn down.
|
|
102
|
+
if (!(await (0, exports.isSharedProjectOwnedByApp)(context, client, projectName))) {
|
|
103
|
+
return 'retained';
|
|
104
|
+
}
|
|
105
|
+
const logstores = await client.sls.listLogStores(projectName);
|
|
106
|
+
if (logstores.length > 0) {
|
|
107
|
+
logger_1.logger.info(lang_1.lang.__('SHARED_SLS_PROJECT_IN_USE', {
|
|
108
|
+
projectName,
|
|
109
|
+
count: String(logstores.length),
|
|
110
|
+
}));
|
|
111
|
+
return 'retained';
|
|
112
|
+
}
|
|
113
|
+
await client.sls.deleteProject(projectName);
|
|
114
|
+
return 'deleted';
|
|
115
|
+
};
|
|
116
|
+
exports.releaseSharedSlsProjectIfUnused = releaseSharedSlsProjectIfUnused;
|
|
117
|
+
const ensureLogstoreInSharedProject = async (context, client, projectName, logstoreName) => {
|
|
118
|
+
const existing = await client.sls.getLogstore(projectName, logstoreName);
|
|
119
|
+
if (existing) {
|
|
120
|
+
return { logstoreName };
|
|
121
|
+
}
|
|
122
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_SLS_LOGSTORE', { logstoreName }));
|
|
123
|
+
await client.sls.createLogstore(projectName, logstoreName);
|
|
124
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_SLS_INDEX', { logstoreName }));
|
|
125
|
+
await client.sls.createIndex(projectName, logstoreName);
|
|
126
|
+
logger_1.logger.info(lang_1.lang.__('SLS_LOGSTORE_WAITING', { project: projectName, logstore: logstoreName }));
|
|
127
|
+
await client.sls.waitForLogstore(projectName, logstoreName);
|
|
128
|
+
return { logstoreName };
|
|
129
|
+
};
|
|
130
|
+
const ensureFunctionLogstore = async (context, client, projectName) => {
|
|
131
|
+
return ensureLogstoreInSharedProject(context, client, projectName, `${context.service}-${context.stage}-fn-logs`);
|
|
132
|
+
};
|
|
133
|
+
exports.ensureFunctionLogstore = ensureFunctionLogstore;
|
|
134
|
+
const ensureGatewayLogstore = async (context, client, projectName) => {
|
|
135
|
+
return ensureLogstoreInSharedProject(context, client, projectName, `${context.service}-${context.stage}-apigw-logs`);
|
|
136
|
+
};
|
|
137
|
+
exports.ensureGatewayLogstore = ensureGatewayLogstore;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeTablePlan = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
4
5
|
const tablestoreResource_1 = require("./tablestoreResource");
|
|
5
6
|
const common_1 = require("../../common");
|
|
7
|
+
const reportResourceEvent_1 = require("../../common/reportResourceEvent");
|
|
6
8
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
9
|
const lang_1 = require("../../lang");
|
|
8
10
|
const executeCreateAction = async (context, table, currentState) => {
|
|
@@ -74,13 +76,26 @@ const executeTablePlan = async (context, plan, tables, initialState, onStateChan
|
|
|
74
76
|
const successfulItems = [];
|
|
75
77
|
let currentState = initialState;
|
|
76
78
|
for (const item of plan.items) {
|
|
79
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
80
|
+
type: 'resource_pre',
|
|
81
|
+
logicalId: item.logicalId,
|
|
82
|
+
resourceType: item.resourceType,
|
|
83
|
+
action: item.action,
|
|
84
|
+
...(item.drifted ? { message: 'resource drifted' } : {}),
|
|
85
|
+
});
|
|
86
|
+
const __siStartedAt = Date.now();
|
|
77
87
|
try {
|
|
78
88
|
const newState = await executeSingleItem(context, item, tablesMap, currentState);
|
|
79
89
|
if (newState !== null) {
|
|
80
90
|
currentState = newState;
|
|
81
91
|
successfulItems.push(item);
|
|
92
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
93
|
+
type: 'resource_complete',
|
|
94
|
+
logicalId: item.logicalId,
|
|
95
|
+
durationMs: Date.now() - __siStartedAt,
|
|
96
|
+
});
|
|
82
97
|
if (onStateChange) {
|
|
83
|
-
onStateChange(currentState);
|
|
98
|
+
await onStateChange(currentState);
|
|
84
99
|
common_1.logger.debug(lang_1.lang.__('STATE_PERSISTED_AFTER_OPERATION', {
|
|
85
100
|
action: item.action,
|
|
86
101
|
resourceId: item.logicalId,
|
|
@@ -89,6 +104,29 @@ const executeTablePlan = async (context, plan, tables, initialState, onStateChan
|
|
|
89
104
|
}
|
|
90
105
|
}
|
|
91
106
|
catch (error) {
|
|
107
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
108
|
+
type: 'resource_failed',
|
|
109
|
+
logicalId: item.logicalId,
|
|
110
|
+
severity: 'error',
|
|
111
|
+
durationMs: Date.now() - __siStartedAt,
|
|
112
|
+
error: {
|
|
113
|
+
message: error instanceof Error ? error.message : String(error),
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
if (error instanceof types_1.PartialResourceError) {
|
|
117
|
+
const updatedState = error.updatedState;
|
|
118
|
+
if (onStateChange) {
|
|
119
|
+
await onStateChange(updatedState);
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
state: updatedState,
|
|
123
|
+
partialFailure: {
|
|
124
|
+
failedItem: item,
|
|
125
|
+
error: error.cause,
|
|
126
|
+
successfulItems,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
92
130
|
return {
|
|
93
131
|
state: currentState,
|
|
94
132
|
partialFailure: {
|
|
@@ -25,7 +25,19 @@ const generateTablePlan = async (context, state, tables) => {
|
|
|
25
25
|
const currentState = (0, stateManager_1.getResource)(state, logicalId);
|
|
26
26
|
const config = (0, tablestoreTypes_1.tableToTableStoreConfig)(table);
|
|
27
27
|
const desiredDefinition = (0, tablestoreTypes_1.extractTableStoreDefinition)(config);
|
|
28
|
-
if (!currentState) {
|
|
28
|
+
if (!currentState || currentState.status === 'tainted') {
|
|
29
|
+
// No usable local state: probe the provider before planning create.
|
|
30
|
+
// Aliyun Tablestore (OTS) supports only instance-level tags — table
|
|
31
|
+
// ownership cannot be verified, so tag-based adoption is IMPOSSIBLE.
|
|
32
|
+
// If a same-named table already exists it may belong to another
|
|
33
|
+
// project: fail fast in the plan instead of letting the executor
|
|
34
|
+
// discover the collision mid-deploy.
|
|
35
|
+
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
36
|
+
const tablestoreClient = client.tablestore(config.instanceName);
|
|
37
|
+
const remoteTable = await tablestoreClient.getTable(config.tableName);
|
|
38
|
+
if (remoteTable) {
|
|
39
|
+
throw new Error(`Table ${config.tableName} already exists in provider but ownership cannot be verified (no table-level tags). Refusing to adopt — resolve manually.`);
|
|
40
|
+
}
|
|
29
41
|
return {
|
|
30
42
|
logicalId,
|
|
31
43
|
action: 'create',
|
|
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.deleteTableResource = exports.updateTableResource = exports.readTableResource = exports.createTableResource = void 0;
|
|
4
4
|
const aliyunClient_1 = require("../../common/aliyunClient");
|
|
5
5
|
const common_1 = require("../../common");
|
|
6
|
+
const types_1 = require("../../types");
|
|
6
7
|
const tablestoreTypes_1 = require("./tablestoreTypes");
|
|
8
|
+
const alreadyExists_1 = require("../alreadyExists");
|
|
7
9
|
const logger_1 = require("../../common/logger");
|
|
8
10
|
const buildTableStoreInstanceFromProvider = (info, sid, instanceName, clusterType) => {
|
|
9
11
|
return {
|
|
@@ -27,6 +29,8 @@ const buildTableStoreInstanceFromProvider = (info, sid, instanceName, clusterTyp
|
|
|
27
29
|
maxVersions: info.tableOptions.maxVersions ?? null,
|
|
28
30
|
maxTimeDeviation: info.tableOptions.maxTimeDeviation ?? null,
|
|
29
31
|
allowUpdate: info.tableOptions.allowUpdate ?? null,
|
|
32
|
+
bloomFilterType: info.tableOptions.bloomFilterType ?? null,
|
|
33
|
+
blockSize: info.tableOptions.blockSize ?? null,
|
|
30
34
|
}
|
|
31
35
|
: undefined,
|
|
32
36
|
streamDetails: info.streamDetails
|
|
@@ -37,39 +41,69 @@ const buildTableStoreInstanceFromProvider = (info, sid, instanceName, clusterTyp
|
|
|
37
41
|
lastEnableTime: info.streamDetails.lastEnableTime ?? null,
|
|
38
42
|
}
|
|
39
43
|
: undefined,
|
|
44
|
+
tableStatus: info.tableStatus ?? null,
|
|
45
|
+
definedColumn: info.definedColumn ?? [],
|
|
46
|
+
indexMetas: info.indexMetas ?? [],
|
|
47
|
+
shardSplits: info.shardSplits ?? [],
|
|
40
48
|
};
|
|
41
49
|
};
|
|
42
50
|
const createTableResource = async (context, table, state) => {
|
|
43
51
|
const config = (0, tablestoreTypes_1.tableToTableStoreConfig)(table);
|
|
44
52
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
45
53
|
const tablestoreClient = client.tablestore(config.instanceName);
|
|
46
|
-
|
|
47
|
-
await tablestoreClient.createTable({
|
|
48
|
-
tableName: config.tableName,
|
|
49
|
-
primaryKey: config.primaryKey,
|
|
50
|
-
reservedThroughput: config.reservedThroughput,
|
|
51
|
-
tableOptions: config.tableOptions,
|
|
52
|
-
});
|
|
53
|
-
// Wait for table to be ready
|
|
54
|
-
await tablestoreClient.waitForTableReady(config.tableName);
|
|
55
|
-
// Refresh state from provider to get all attributes
|
|
56
|
-
const tableInfo = await tablestoreClient.getTable(config.tableName);
|
|
57
|
-
if (!tableInfo) {
|
|
58
|
-
throw new Error(`Failed to refresh state for table: ${config.tableName}`);
|
|
59
|
-
}
|
|
54
|
+
const logicalId = `tables.${table.key}`;
|
|
60
55
|
const definition = (0, tablestoreTypes_1.extractTableStoreDefinition)(config);
|
|
61
56
|
const sid = (0, common_1.buildSid)('aliyun', 'ots', context.stage, `${config.instanceName}/${config.tableName}`);
|
|
62
|
-
const
|
|
57
|
+
const taintedResourceState = {
|
|
63
58
|
mode: 'managed',
|
|
64
59
|
region: context.region,
|
|
65
60
|
definition,
|
|
66
|
-
instances: [
|
|
67
|
-
buildTableStoreInstanceFromProvider(tableInfo, sid, config.instanceName, config.clusterType),
|
|
68
|
-
],
|
|
61
|
+
instances: [],
|
|
69
62
|
lastUpdated: new Date().toISOString(),
|
|
63
|
+
status: 'tainted',
|
|
70
64
|
};
|
|
71
|
-
const
|
|
72
|
-
|
|
65
|
+
const stateAfterDependents = (0, common_1.setResource)(state, logicalId, taintedResourceState);
|
|
66
|
+
try {
|
|
67
|
+
// Create table
|
|
68
|
+
await tablestoreClient.createTable({
|
|
69
|
+
tableName: config.tableName,
|
|
70
|
+
primaryKey: config.primaryKey,
|
|
71
|
+
reservedThroughput: config.reservedThroughput,
|
|
72
|
+
tableOptions: config.tableOptions,
|
|
73
|
+
});
|
|
74
|
+
// Wait for table to be ready
|
|
75
|
+
await tablestoreClient.waitForTableReady(config.tableName);
|
|
76
|
+
// Refresh state from provider to get all attributes
|
|
77
|
+
const tableInfo = await tablestoreClient.getTable(config.tableName);
|
|
78
|
+
if (!tableInfo) {
|
|
79
|
+
throw new Error(`Failed to refresh state for table: ${config.tableName}`);
|
|
80
|
+
}
|
|
81
|
+
const resourceState = {
|
|
82
|
+
mode: 'managed',
|
|
83
|
+
region: context.region,
|
|
84
|
+
definition,
|
|
85
|
+
instances: [
|
|
86
|
+
buildTableStoreInstanceFromProvider(tableInfo, sid, config.instanceName, config.clusterType),
|
|
87
|
+
],
|
|
88
|
+
lastUpdated: new Date().toISOString(),
|
|
89
|
+
};
|
|
90
|
+
return (0, common_1.setResource)(stateAfterDependents, logicalId, resourceState);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
// Aliyun Tablestore (OTS) does NOT support table-level tags — only
|
|
94
|
+
// instance-level. Without a tag, ownership of a pre-existing table cannot
|
|
95
|
+
// be verified, so tag-based idempotent adoption is IMPOSSIBLE. On a create
|
|
96
|
+
// collision we therefore ALWAYS refuse to adopt (never take over a table
|
|
97
|
+
// that may belong to another project): persist the tainted state and let
|
|
98
|
+
// the user resolve manually.
|
|
99
|
+
if ((0, alreadyExists_1.isResourceAlreadyExistsError)(error, ['OTSObjectAlreadyExist', 'OTSInstanceAlreadyExist'])) {
|
|
100
|
+
const existingTable = await tablestoreClient.getTable(config.tableName);
|
|
101
|
+
if (existingTable) {
|
|
102
|
+
throw new types_1.PartialResourceError(stateAfterDependents, new Error(`Table ${config.tableName} already exists in provider but ownership cannot be verified (Tablestore does not support table-level tags). Refusing to adopt — resolve manually.`));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
throw new types_1.PartialResourceError(stateAfterDependents, error instanceof Error ? error : new Error(String(error)));
|
|
106
|
+
}
|
|
73
107
|
};
|
|
74
108
|
exports.createTableResource = createTableResource;
|
|
75
109
|
const readTableResource = async (context, instanceName, tableName) => {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isResourceAlreadyExistsError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Generic "resource already exists" detector for create-time errors, shared
|
|
6
|
+
* across all providers. Cloud SDKs report collisions with different shapes:
|
|
7
|
+
* - Tencent: code ResourceInUse, message "指定的Function已存在,请勿重复创建"
|
|
8
|
+
* - Aliyun: code...AlreadyExists / message "already exists" / ResourceExhausted
|
|
9
|
+
* - Volcengine: code...Conflict / message "already exist"
|
|
10
|
+
*
|
|
11
|
+
* Deliberately does NOT match timeouts/network errors — those must propagate so
|
|
12
|
+
* a missing resource is never silently swallowed. Callers can pass provider-
|
|
13
|
+
* specific extra codes that only their SDK emits.
|
|
14
|
+
*/
|
|
15
|
+
const isResourceAlreadyExistsError = (error, extraCodes = []) => {
|
|
16
|
+
const code = error && typeof error === 'object' && 'code' in error && typeof error.code === 'string'
|
|
17
|
+
? error.code.toLowerCase()
|
|
18
|
+
: '';
|
|
19
|
+
const message = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
|
|
20
|
+
const providerCodes = extraCodes.map((c) => c.toLowerCase());
|
|
21
|
+
return (code.includes('resourceinuse') ||
|
|
22
|
+
message.includes('已存在') ||
|
|
23
|
+
message.includes('already exist') ||
|
|
24
|
+
providerCodes.some((c) => code.includes(c)));
|
|
25
|
+
};
|
|
26
|
+
exports.isResourceAlreadyExistsError = isResourceAlreadyExistsError;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isOwnedByApp = exports.buildSharedOwnershipTagValue = exports.SHARED_SCOPE = exports.isOwnedByStack = exports.parseOwnershipTagValue = exports.buildOwnershipTagValue = exports.OWNERSHIP_TAG_KEY = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Ownership tag stamped on provider resources at create time so a deploy can
|
|
6
|
+
* idempotently adopt a resource that exists in the cloud but is missing from
|
|
7
|
+
* local state (e.g. state was reset or a previous run failed mid-way).
|
|
8
|
+
*
|
|
9
|
+
* The value encodes BOTH the owning stack and the logical id:
|
|
10
|
+
* `${app}-${service}:${logicalId}` e.g. "fn-url-probe:functions.probe"
|
|
11
|
+
*
|
|
12
|
+
* A single tag is enough because the cloud resource name is already globally
|
|
13
|
+
* unique per provider; the tag only needs to prove ownership so an unrelated
|
|
14
|
+
* same-named resource is never adopted (that would corrupt state and let a
|
|
15
|
+
* later destroy remove a resource that was never ours).
|
|
16
|
+
*/
|
|
17
|
+
exports.OWNERSHIP_TAG_KEY = 'si-owned-by';
|
|
18
|
+
const buildOwnershipTagValue = (context, logicalId) => `${context.app}-${context.service}:${logicalId}`;
|
|
19
|
+
exports.buildOwnershipTagValue = buildOwnershipTagValue;
|
|
20
|
+
const parseOwnershipTagValue = (value) => {
|
|
21
|
+
if (!value)
|
|
22
|
+
return null;
|
|
23
|
+
const idx = value.indexOf(':');
|
|
24
|
+
if (idx <= 0)
|
|
25
|
+
return null;
|
|
26
|
+
return { stack: value.slice(0, idx), logicalId: value.slice(idx + 1) };
|
|
27
|
+
};
|
|
28
|
+
exports.parseOwnershipTagValue = parseOwnershipTagValue;
|
|
29
|
+
const isOwnedByStack = (context, logicalId, tags) => {
|
|
30
|
+
if (!tags)
|
|
31
|
+
return false;
|
|
32
|
+
const tag = tags.find((t) => t.Key === exports.OWNERSHIP_TAG_KEY);
|
|
33
|
+
if (!tag?.Value)
|
|
34
|
+
return false;
|
|
35
|
+
const parsed = (0, exports.parseOwnershipTagValue)(tag.Value);
|
|
36
|
+
if (!parsed)
|
|
37
|
+
return false;
|
|
38
|
+
return parsed.stack === `${context.app}-${context.service}` && parsed.logicalId === logicalId;
|
|
39
|
+
};
|
|
40
|
+
exports.isOwnedByStack = isOwnedByStack;
|
|
41
|
+
/**
|
|
42
|
+
* App-scoped ownership for resources shared across services of one app
|
|
43
|
+
* (issue #214 unified log container). Exact full-value match by design:
|
|
44
|
+
* per-service stacks have no claim on shared resources, so only the
|
|
45
|
+
* owning app may adopt them.
|
|
46
|
+
*/
|
|
47
|
+
exports.SHARED_SCOPE = 'shared';
|
|
48
|
+
const buildSharedOwnershipTagValue = (app, logicalId) => `${app}:${exports.SHARED_SCOPE}:${logicalId}`;
|
|
49
|
+
exports.buildSharedOwnershipTagValue = buildSharedOwnershipTagValue;
|
|
50
|
+
const isOwnedByApp = (app, logicalId, tags) => {
|
|
51
|
+
if (!tags)
|
|
52
|
+
return false;
|
|
53
|
+
const tag = tags.find((t) => t.Key === exports.OWNERSHIP_TAG_KEY);
|
|
54
|
+
if (!tag?.Value)
|
|
55
|
+
return false;
|
|
56
|
+
return tag.Value === (0, exports.buildSharedOwnershipTagValue)(app, logicalId);
|
|
57
|
+
};
|
|
58
|
+
exports.isOwnedByApp = isOwnedByApp;
|
|
@@ -23,10 +23,12 @@ provider "huaweicloud" {
|
|
|
23
23
|
stack.appendHcl(hcl);
|
|
24
24
|
};
|
|
25
25
|
class RfsStack {
|
|
26
|
+
iac;
|
|
27
|
+
context;
|
|
28
|
+
hcl = '';
|
|
26
29
|
constructor(iac, context = (0, common_1.getContext)()) {
|
|
27
30
|
this.iac = iac;
|
|
28
31
|
this.context = context;
|
|
29
|
-
this.hcl = '';
|
|
30
32
|
provider(this, context);
|
|
31
33
|
(0, function_1.resolveFunction)(this, iac.functions, context, `${iac.app}-${iac.service}`);
|
|
32
34
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeBucketPlan = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
4
5
|
const cosResource_1 = require("./cosResource");
|
|
5
6
|
const common_1 = require("../../common");
|
|
7
|
+
const reportResourceEvent_1 = require("../../common/reportResourceEvent");
|
|
6
8
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
9
|
const lang_1 = require("../../lang");
|
|
8
10
|
const executeCreateAction = async (context, bucket, currentState) => {
|
|
@@ -61,13 +63,26 @@ const executeBucketPlan = async (context, plan, buckets, initialState, onStateCh
|
|
|
61
63
|
const successfulItems = [];
|
|
62
64
|
let currentState = initialState;
|
|
63
65
|
for (const item of plan.items) {
|
|
66
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
67
|
+
type: 'resource_pre',
|
|
68
|
+
logicalId: item.logicalId,
|
|
69
|
+
resourceType: item.resourceType,
|
|
70
|
+
action: item.action,
|
|
71
|
+
...(item.drifted ? { message: 'resource drifted' } : {}),
|
|
72
|
+
});
|
|
73
|
+
const __siStartedAt = Date.now();
|
|
64
74
|
try {
|
|
65
75
|
const newState = await executeSingleItem(context, item, bucketsMap, currentState);
|
|
66
76
|
if (newState !== null) {
|
|
67
77
|
currentState = newState;
|
|
68
78
|
successfulItems.push(item);
|
|
79
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
80
|
+
type: 'resource_complete',
|
|
81
|
+
logicalId: item.logicalId,
|
|
82
|
+
durationMs: Date.now() - __siStartedAt,
|
|
83
|
+
});
|
|
69
84
|
if (onStateChange) {
|
|
70
|
-
onStateChange(currentState);
|
|
85
|
+
await onStateChange(currentState);
|
|
71
86
|
common_1.logger.debug(lang_1.lang.__('STATE_PERSISTED_AFTER_OPERATION', {
|
|
72
87
|
action: item.action,
|
|
73
88
|
resourceId: item.logicalId,
|
|
@@ -76,6 +91,29 @@ const executeBucketPlan = async (context, plan, buckets, initialState, onStateCh
|
|
|
76
91
|
}
|
|
77
92
|
}
|
|
78
93
|
catch (error) {
|
|
94
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
95
|
+
type: 'resource_failed',
|
|
96
|
+
logicalId: item.logicalId,
|
|
97
|
+
severity: 'error',
|
|
98
|
+
durationMs: Date.now() - __siStartedAt,
|
|
99
|
+
error: {
|
|
100
|
+
message: error instanceof Error ? error.message : String(error),
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
if (error instanceof types_1.PartialResourceError) {
|
|
104
|
+
const updatedState = error.updatedState;
|
|
105
|
+
if (onStateChange) {
|
|
106
|
+
await onStateChange(updatedState);
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
state: updatedState,
|
|
110
|
+
partialFailure: {
|
|
111
|
+
failedItem: item,
|
|
112
|
+
error: error.cause,
|
|
113
|
+
successfulItems,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
79
117
|
return {
|
|
80
118
|
state: currentState,
|
|
81
119
|
partialFailure: {
|
|
@@ -5,6 +5,7 @@ const tencentClient_1 = require("../../common/tencentClient");
|
|
|
5
5
|
const cosTypes_1 = require("./cosTypes");
|
|
6
6
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
7
|
const hashUtils_1 = require("../../common/hashUtils");
|
|
8
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
8
9
|
const planBucketDeletion = (logicalId, definition) => ({
|
|
9
10
|
logicalId,
|
|
10
11
|
action: 'delete',
|
|
@@ -25,7 +26,16 @@ const generateBucketPlan = async (context, state, buckets) => {
|
|
|
25
26
|
const currentState = (0, stateManager_1.getResource)(state, logicalId);
|
|
26
27
|
const config = (0, cosTypes_1.bucketToCosBucketConfig)(bucket, context.region);
|
|
27
28
|
const desiredDefinition = (0, cosTypes_1.extractCosBucketDefinition)(config);
|
|
28
|
-
if (!currentState) {
|
|
29
|
+
if (!currentState || currentState.status === 'tainted') {
|
|
30
|
+
// No usable local state: probe the provider before planning create.
|
|
31
|
+
// If a same-named bucket already exists WITHOUT our ownership tag it
|
|
32
|
+
// may belong to another project — fail fast in the plan instead of
|
|
33
|
+
// letting the executor discover it mid-deploy.
|
|
34
|
+
const client = (0, tencentClient_1.createTencentClient)(context);
|
|
35
|
+
const remoteBucket = await client.cos.getBucket(bucket.name, context.region);
|
|
36
|
+
if (remoteBucket && !(0, ownershipTag_1.isOwnedByStack)(context, logicalId, remoteBucket.Tags)) {
|
|
37
|
+
throw new Error(`Bucket ${bucket.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`);
|
|
38
|
+
}
|
|
29
39
|
return {
|
|
30
40
|
logicalId,
|
|
31
41
|
action: 'create',
|