Skip to content

Commit a6f0990

Browse files
committed
fix(cynosdb): add offline step for remove
1 parent 30d6ecc commit a6f0990

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

__tests__/cynosdb.test.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const {
44
sleep,
55
generatePwd,
66
isValidPwd,
7-
offlineCluster,
87
} = require('../src/modules/cynosdb/utils');
98

109
describe('Cynosdb', () => {
@@ -186,12 +185,6 @@ describe('Cynosdb', () => {
186185

187186
const detail = await getClusterDetail(client.capi, clusterId);
188187
expect(res).toEqual(true);
189-
expect(detail.Status).toBe('isolated');
190-
});
191-
192-
test('[SERVERLESS] offline', async () => {
193-
await sleep(300);
194-
const res = await offlineCluster(client.capi, clusterId);
195-
expect(res).toBeUndefined();
188+
expect(detail).toBeUndefined();
196189
});
197190
});

src/modules/cynosdb/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const {
44
getClusterDetail,
55
getClusterInstances,
66
isolateCluster,
7+
offlineCluster,
78
generatePwd,
89
formatConnectOutput,
910
resetPwd,
@@ -156,6 +157,7 @@ class Cynosdb {
156157
if (clusterDetail && clusterDetail.ClusterId) {
157158
// need circle for deleting, after host status is 6, then we can delete it
158159
await isolateCluster(this.capi, clusterId);
160+
await offlineCluster(this.capi, clusterId);
159161
}
160162
return true;
161163
}

src/modules/cynosdb/utils.js

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const {
66
IsolateCluster,
77
ResetAccountPassword,
88
DescribeServerlessInstanceSpecs,
9-
OfflineCluster,
9+
// OfflineCluster,
10+
OfflineInstance,
1011
DescribeInstances,
1112
OpenWan,
1213
CloseWan,
@@ -248,40 +249,45 @@ async function isolateCluster(capi, clusterId) {
248249
* @param {*} clusterId cluster id
249250
* @param {*} instanceId instance id
250251
*/
251-
async function offlineInstance(capi, clusterId, instanceId) {
252-
console.log(`Start offlining CynosDB instance id: ${instanceId}`);
253-
await OfflineCluster(capi, {
254-
ClusterId: clusterId,
255-
InstanceIdList: [instanceId],
256-
});
257-
const detail = await waitResponse({
258-
callback: async () => getInstanceDetail(capi, clusterId),
259-
targetResponse: undefined,
260-
timeout: TIMEOUT,
261-
});
262-
console.log(`Offlined CynosDB instance id: ${instanceId}`);
263-
return detail;
264-
}
265-
266-
/**
267-
* offline db cluster
268-
* @param {object} capi capi client
269-
* @param {string} clusterId cluster id
270-
*/
271252
async function offlineCluster(capi, clusterId) {
272-
console.log(`Start offlining CynosDB cluster id: ${clusterId}`);
273-
await OfflineCluster(capi, {
253+
// 1. get cluster instances
254+
const instances = await getClusterInstances(capi, clusterId);
255+
const instanceIds = instances.map((item) => item.InstanceId);
256+
console.log(`Start offlining CynosDB id: ${clusterId}`);
257+
258+
await OfflineInstance(capi, {
274259
ClusterId: clusterId,
260+
InstanceIdList: instanceIds,
275261
});
262+
276263
const detail = await waitResponse({
277264
callback: async () => getClusterDetail(capi, clusterId),
278265
targetResponse: undefined,
279266
timeout: TIMEOUT,
280267
});
281-
console.log(`Offlined CynosDB cluster id: ${clusterId}.`);
268+
console.log(`Offlined CynosDB id: ${clusterId}`);
282269
return detail;
283270
}
284271

272+
// /**
273+
// * offline db cluster
274+
// * @param {object} capi capi client
275+
// * @param {string} clusterId cluster id
276+
// */
277+
// async function offlineCluster(capi, clusterId) {
278+
// console.log(`Start offlining CynosDB cluster id: ${clusterId}`);
279+
// await OfflineCluster(capi, {
280+
// ClusterId: clusterId,
281+
// });
282+
// const detail = await waitResponse({
283+
// callback: async () => getClusterDetail(capi, clusterId),
284+
// targetResponse: undefined,
285+
// timeout: TIMEOUT,
286+
// });
287+
// console.log(`Offlined CynosDB cluster id: ${clusterId}.`);
288+
// return detail;
289+
// }
290+
285291
async function resetPwd(capi, inputs) {
286292
console.log(
287293
`Start reset password for CynosDB cluster id: ${inputs.clusterId}, account: ${inputs.adminName}`,
@@ -358,7 +364,6 @@ module.exports = {
358364
getClusterInstances,
359365
isolateCluster,
360366
offlineCluster,
361-
offlineInstance,
362367
getInstanceDetail,
363368
openPublicAccess,
364369
closePublicAccess,

0 commit comments

Comments
 (0)