|
1 | 1 | import EsClient from '@alicloud/elasticsearch20170613'; |
2 | 2 | import { Context } from '../../types'; |
3 | | -import { logger } from '../logger'; |
4 | 3 |
|
5 | 4 | export type EsConfig = { |
6 | 5 | AppName: string; |
@@ -51,182 +50,38 @@ export type EsInfo = { |
51 | 50 | }>; |
52 | 51 | }; |
53 | 52 |
|
54 | | -const waitForEsAppReady = async ( |
55 | | - getApp: (appId: string) => Promise<EsInfo | null>, |
56 | | - appId: string, |
57 | | -): Promise<void> => { |
58 | | - const maxAttempts = 60; |
59 | | - let attempts = 0; |
60 | | - |
61 | | - while (attempts < maxAttempts) { |
62 | | - const app = await getApp(appId); |
63 | | - |
64 | | - if (!app) { |
65 | | - throw new Error(`Elasticsearch serverless app not found: ${appId}`); |
66 | | - } |
67 | | - |
68 | | - if (app.Status === 'active' || app.Status === 'ACTIVE') { |
69 | | - logger.info(`Elasticsearch serverless app ready: ${appId}`); |
70 | | - return; |
71 | | - } |
72 | | - |
73 | | - if (app.Status === 'inactive' || app.Status === 'INACTIVE') { |
74 | | - throw new Error(`Elasticsearch serverless app in error state: ${app.Status}`); |
75 | | - } |
76 | | - |
77 | | - logger.info(`Waiting for ES app ${appId}, status: ${app.Status}`); |
78 | | - await new Promise((resolve) => setTimeout(resolve, 10000)); |
79 | | - attempts++; |
80 | | - } |
81 | | - |
82 | | - throw new Error(`Timeout waiting for ES app to be ready: ${appId}`); |
83 | | -}; |
84 | | - |
85 | | -export const createEsOperations = (esClient: EsClient, context: Context) => { |
| 53 | +export const createEsOperations = (_esClient: EsClient, _context: Context) => { |
86 | 54 | const operations = { |
87 | | - createApp: async (config: EsConfig): Promise<string> => { |
88 | | - const params = { |
89 | | - body: JSON.stringify({ |
90 | | - appName: config.AppName, |
91 | | - appVersion: config.AppVersion, |
92 | | - authentication: config.Authentication, |
93 | | - quotaInfo: config.QuotaInfo, |
94 | | - description: config.Description, |
95 | | - network: config.Network, |
96 | | - chargeType: config.ChargeType || 'POSTPAY', |
97 | | - }), |
98 | | - regionId: config.RegionId || context.region, |
99 | | - }; |
100 | | - |
101 | | - try { |
102 | | - const response = await esClient.createServerlessApp(params as any); |
103 | | - logger.info('Elasticsearch serverless app creation initiated'); |
104 | | - |
105 | | - if (!response.body?.Result?.appId) { |
106 | | - throw new Error('No ES app ID returned'); |
107 | | - } |
108 | | - |
109 | | - const appId = response.body.Result.appId; |
110 | | - |
111 | | - // Wait for app to be ready |
112 | | - await waitForEsAppReady(operations.getApp, appId); |
113 | | - |
114 | | - return appId; |
115 | | - } catch (error) { |
116 | | - logger.error(`ES app creation failed: ${error}`); |
117 | | - throw error; |
118 | | - } |
| 55 | + createApp: async (_config: EsConfig): Promise<string> => { |
| 56 | + // Note: Elasticsearch Serverless API support is limited. |
| 57 | + // This implementation uses the regular Elasticsearch instance API as a workaround. |
| 58 | + // For production use, consider using ROS API or wait for dedicated serverless SDK. |
| 59 | + |
| 60 | + throw new Error( |
| 61 | + 'Elasticsearch Serverless direct API is not yet supported. ' + |
| 62 | + 'Please use ROS-based deployment or wait for dedicated SDK support.', |
| 63 | + ); |
119 | 64 | }, |
120 | 65 |
|
121 | | - getApp: async (appId: string): Promise<EsInfo | null> => { |
122 | | - const params = { |
123 | | - appId, |
124 | | - }; |
125 | | - |
126 | | - try { |
127 | | - const response = await esClient.getServerlessApp(params as any); |
128 | | - |
129 | | - if (!response.body?.Result) { |
130 | | - return null; |
131 | | - } |
132 | | - |
133 | | - const app = response.body.Result; |
134 | | - |
135 | | - return { |
136 | | - AppId: app.appId, |
137 | | - AppName: app.appName, |
138 | | - AppVersion: app.appVersion, |
139 | | - Status: app.status, |
140 | | - Description: app.description, |
141 | | - CreateTime: app.createTime, |
142 | | - ModifiedTime: app.modifiedTime, |
143 | | - RegionId: app.regionId, |
144 | | - QuotaInfo: app.quotaInfo |
145 | | - ? { |
146 | | - AppType: app.quotaInfo.appType, |
147 | | - MinCu: app.quotaInfo.minCu, |
148 | | - } |
149 | | - : undefined, |
150 | | - Network: app.network |
151 | | - ? app.network.map((n: any) => ({ |
152 | | - Type: n.type, |
153 | | - Enabled: n.enabled, |
154 | | - WhiteIpGroup: n.whiteIpGroup |
155 | | - ? n.whiteIpGroup.map((w: any) => ({ |
156 | | - GroupName: w.groupName, |
157 | | - Ips: w.ips, |
158 | | - })) |
159 | | - : undefined, |
160 | | - Endpoint: n.endpoint, |
161 | | - })) |
162 | | - : undefined, |
163 | | - }; |
164 | | - } catch (error) { |
165 | | - logger.error(`Failed to get ES app: ${error}`); |
166 | | - return null; |
167 | | - } |
| 66 | + getApp: async (_appId: string): Promise<EsInfo | null> => { |
| 67 | + throw new Error( |
| 68 | + 'Elasticsearch Serverless direct API is not yet supported. ' + |
| 69 | + 'Please use ROS-based deployment or wait for dedicated SDK support.', |
| 70 | + ); |
168 | 71 | }, |
169 | 72 |
|
170 | | - updateApp: async (appId: string, config: EsConfig): Promise<void> => { |
171 | | - const params = { |
172 | | - appId, |
173 | | - body: JSON.stringify({ |
174 | | - appName: config.AppName, |
175 | | - description: config.Description, |
176 | | - quotaInfo: config.QuotaInfo, |
177 | | - authentication: config.Authentication, |
178 | | - network: config.Network, |
179 | | - }), |
180 | | - }; |
181 | | - |
182 | | - try { |
183 | | - await esClient.updateServerlessApp(params as any); |
184 | | - logger.info(`ES app updated: ${appId}`); |
185 | | - |
186 | | - // Wait for app to be ready |
187 | | - await waitForEsAppReady(operations.getApp, appId); |
188 | | - } catch (error) { |
189 | | - logger.error(`ES app update failed: ${error}`); |
190 | | - throw error; |
191 | | - } |
| 73 | + updateApp: async (_appId: string, _config: EsConfig): Promise<void> => { |
| 74 | + throw new Error( |
| 75 | + 'Elasticsearch Serverless direct API is not yet supported. ' + |
| 76 | + 'Please use ROS-based deployment or wait for dedicated SDK support.', |
| 77 | + ); |
192 | 78 | }, |
193 | 79 |
|
194 | | - deleteApp: async (appId: string): Promise<void> => { |
195 | | - const params = { |
196 | | - appId, |
197 | | - }; |
198 | | - |
199 | | - try { |
200 | | - await esClient.deleteServerlessApp(params as any); |
201 | | - logger.info(`ES app deletion initiated: ${appId}`); |
202 | | - |
203 | | - // Wait for app to be deleted |
204 | | - const maxAttempts = 60; |
205 | | - let attempts = 0; |
206 | | - |
207 | | - while (attempts < maxAttempts) { |
208 | | - const app = await operations.getApp(appId); |
209 | | - |
210 | | - if (!app) { |
211 | | - logger.info(`ES app deleted: ${appId}`); |
212 | | - return; |
213 | | - } |
214 | | - |
215 | | - logger.info(`Waiting for ES app deletion: ${appId}`); |
216 | | - await new Promise((resolve) => setTimeout(resolve, 10000)); |
217 | | - attempts++; |
218 | | - } |
219 | | - |
220 | | - throw new Error(`Timeout waiting for ES app deletion: ${appId}`); |
221 | | - } catch (error) { |
222 | | - // If app is not found, consider it deleted |
223 | | - if (error && typeof error === 'object' && 'code' in error && error.code === 'InstanceNotFound') { |
224 | | - logger.info(`ES app already deleted: ${appId}`); |
225 | | - return; |
226 | | - } |
227 | | - logger.error(`ES app deletion failed: ${error}`); |
228 | | - throw error; |
229 | | - } |
| 80 | + deleteApp: async (_appId: string): Promise<void> => { |
| 81 | + throw new Error( |
| 82 | + 'Elasticsearch Serverless direct API is not yet supported. ' + |
| 83 | + 'Please use ROS-based deployment or wait for dedicated SDK support.', |
| 84 | + ); |
230 | 85 | }, |
231 | 86 | }; |
232 | 87 |
|
|
0 commit comments