Skip to content

Commit 89a1e7d

Browse files
committed
allow no sls config
1 parent 27eb6dd commit 89a1e7d

File tree

2 files changed

+54
-26
lines changed

2 files changed

+54
-26
lines changed

src/javaIndex.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class JavaStartupAcceleration {
154154
info("oss endpoint: " + this.ossEndpoint)
155155
}
156156
await this.genDump();
157-
info("completed");
157+
info("all completed");
158158
}
159159

160160
async enableQuickStart() {
@@ -220,6 +220,7 @@ export class JavaStartupAcceleration {
220220
error(e.stderr.toString());
221221
error(e.stdout.toString());
222222
} finally {
223+
info("start to clean");
223224
/* delete local temp files */
224225
await remove(tmpDir);
225226
await remove(tmpZipFilePath);
@@ -256,15 +257,16 @@ export class JavaStartupAcceleration {
256257

257258
let result = await fcClient.post(`/proxy/${tmpServiceName}/${tmpFunctionName}/action`, body, null);
258259
let data = result.data;
259-
info("server messages: " + data)
260+
info("server messages: " + data);
260261
if (data.indexOf("success") == 0) {
261-
info("dumped successfully")
262+
info("dumped successfully");
262263
} else {
263264
throw new Error("dump encountered error");
264265
}
265266
}
266267

267268
private async downloadAccelerationFiles(fcClient, tmpServiceName: string, tmpFunctionName: string) {
269+
info("downloading");
268270
let sharedDir = join(this.artifactPath, this.sharedDirName);
269271
await ensureDir(sharedDir);
270272
let localFile = join(sharedDir, ARCHIVE_NAME);
@@ -278,9 +280,11 @@ export class JavaStartupAcceleration {
278280

279281
await this.extractTar(sharedDir, localFile);
280282
removeSync(localFile);
283+
info("download completed");
281284
}
282285

283286
private async createTempFunction(fcClient, tmpServiceName: string, tmpFunctionName: string, tmpZipFilePath: string) {
287+
info("assistant function [" + tmpFunctionName + "] creating");
284288
await fcClient.createFunction(tmpServiceName, {
285289
code: {
286290
zipFile: readFileSync(tmpZipFilePath, 'base64'),
@@ -300,10 +304,11 @@ export class JavaStartupAcceleration {
300304
SRPATH: this.tmpSrpath
301305
}
302306
});
303-
info("assistant function [" + tmpFunctionName + "] created")
307+
info("assistant function [" + tmpFunctionName + "] created");
304308
}
305309

306310
private static async createTempTrigger(fcClient, tmpServiceName: string, tmpFunctionName: string, tmpTriggerName: string) {
311+
info("assistant trigger [" + tmpTriggerName + "] creating");
307312
await fcClient.createTrigger(tmpServiceName, tmpFunctionName, {
308313
invocationRole: '',
309314
qualifier: 'LATEST',
@@ -312,10 +317,11 @@ export class JavaStartupAcceleration {
312317
triggerName: tmpTriggerName,
313318
triggerType: 'http'
314319
});
315-
info("assistant trigger [" + tmpTriggerName + "] created")
320+
info("assistant trigger [" + tmpTriggerName + "] created");
316321
}
317322

318323
private async createTempService(fcClient, tmpServiceName) {
324+
info("assistant service [" + tmpServiceName + "] creating");
319325
await fcClient.createService(tmpServiceName, {
320326
description: '用于 Alibaba Dragonwell Acceleration Cache 生成',
321327
serviceName: tmpServiceName,
@@ -324,7 +330,7 @@ export class JavaStartupAcceleration {
324330
nasConfig: this.nasConfig,
325331
vpcConfig: this.vpcConfig,
326332
});
327-
info("assistant service [" + tmpServiceName + "] created")
333+
info("assistant service [" + tmpServiceName + "] created");
328334
}
329335

330336
private async getFCClient() {
@@ -350,11 +356,13 @@ export class JavaStartupAcceleration {
350356
}
351357

352358
private async genZip(dir: string, zipFilePath: string) {
359+
info("zip file creating");
353360
await this.makeZip(dir, zipFilePath);
354361
info("zip file created");
355362
}
356363

357364
private async createZipAndUploadToOSS() {
365+
info("start to upload");
358366
const tmpZipFilePath = join(tmpdir(), this.ossKey);
359367

360368
await this.genZip(this.artifactPath, tmpZipFilePath);

src/javaMain.ts

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ export default class JavaStartupAccelerationComponent {
2121
}
2222
info("parsed args: " + JSON.stringify(args));
2323

24+
let fcEndpoint = await this.getFCEndpoint();
2425
let moduleName = args.moduleName;
2526
let serviceName = await this.getServiceConfig(moduleName, 'name');
2627
let functionName = await this.getFunctionConfig(moduleName, 'name');
27-
let fcEndpoint = await this.getFCEndpoint();
2828
let initializer = await this.getFunctionConfig(moduleName, 'initializer');
2929
let runtime = await this.getFunctionConfig(moduleName, 'runtime');
3030
let region = await this.getModulesProps(moduleName, 'region');
31-
let role = await this.getServiceConfig(moduleName, 'role');
32-
let logConfig = await this.getServiceConfig(moduleName, 'logConfig');
31+
let role = await this.getServiceConfig(moduleName, 'role', false);
32+
let logConfig = await this.getServiceConfig(moduleName, 'logConfig', false);
3333
const access = params?.project?.access || this.defaultAccess;
3434
const credential = await this.getCredential(access);
3535
let codeUri = await this.getFunctionConfig(moduleName, 'codeUri');
@@ -43,7 +43,7 @@ export default class JavaStartupAccelerationComponent {
4343
let uploader = args.uploader;
4444
let ossUtilUrl, ossEndpoint;
4545
if (downloader == OSS) {
46-
ossUtilUrl = await this.getGlobalConfig('ossUtilUrl');
46+
ossUtilUrl = await this.getGlobalConfig('ossUtilUrl', false);
4747
ossEndpoint = await this.getModulesProps(moduleName, 'ossEndpoint', false);
4848
}
4949

@@ -149,62 +149,82 @@ export default class JavaStartupAccelerationComponent {
149149
}
150150
}
151151

152-
async getGlobalConfig(key: string) {
152+
async getGlobalConfig(key: string, errorIfNotExist: boolean = true) {
153153
const yaml = await this.getConfig();
154154
if (yaml) {
155155
try {
156-
return await this.replaceReference(yaml[key]);
156+
let value = await this.replaceReference(yaml[key]);
157+
if (value === undefined) {
158+
throw new Error("key " + key + " does not exist");
159+
}
160+
return value;
157161
} catch (e) {
158-
error('read global config [' + key + '] error');
159-
throw e;
162+
error('read global config [' + key + '] error: ' + e.message);
163+
if (errorIfNotExist) {
164+
throw e;
165+
}
160166
}
161167
}
168+
return null;
162169
}
163170

164171
async getModulesProps(moduleName: string, key: string, errorIfNotExist: boolean = true) {
165172
const yaml = await this.getConfig();
166173
if (yaml) {
167174
try {
168-
return await this.replaceReference(yaml['services'][moduleName]['props'][key]);
175+
let value = await this.replaceReference(yaml['services'][moduleName]['props'][key]);
176+
if (value === undefined) {
177+
throw new Error("key " + key + " does not exist");
178+
}
179+
return value;
169180
} catch (e) {
181+
info('read module prop [' + key + '] error: ' + e.message);
170182
if (errorIfNotExist) {
171183
throw e;
172-
} else {
173-
info('read module prop [' + key + '] error');
174184
}
175185
}
176186
}
187+
return null;
177188
}
178189

179-
async getServiceConfig(moduleName: string, key: string) {
190+
async getServiceConfig(moduleName: string, key: string, errorIfNotExist: boolean = true) {
180191
const yaml = await this.getConfig();
181192
if (yaml) {
182193
try {
183-
return await this.replaceReference(yaml['services'][moduleName]['props']['service'][key]);
194+
let value = await this.replaceReference(yaml['services'][moduleName]['props']['service'][key]);
195+
if (value === undefined) {
196+
throw new Error("key " + key + " does not exist");
197+
}
198+
return value;
184199
} catch (e) {
185-
error('read module config [' + key + '] error');
186-
throw e;
200+
error('read module config [' + key + '] error: ' + e.message);
201+
if (errorIfNotExist) {
202+
throw e;
203+
}
187204
}
188205
}
206+
return null;
189207
}
190208

191209
async getFunctionConfig(moduleName: string, key: string, errorIfNotExist: boolean = true) {
192210
const yaml = await this.getConfig();
193211

194-
let value = null;
195212
if (yaml) {
196213
try {
197-
value = await this.replaceReference(yaml['services'][moduleName]['props']['function'][key]);
214+
let value = await this.replaceReference(yaml['services'][moduleName]['props']['function'][key]);
215+
if (value === undefined) {
216+
throw new Error("key " + key + " does not exist");
217+
}
218+
return value;
198219
} catch (e) {
220+
error('read function config [' + key + '] error: ' + e.message);
199221
if (errorIfNotExist) {
200222
throw e;
201-
} else {
202-
info('function config [' + key + '] does not exist:' + e.message);
203223
}
204224
}
205225
}
206226

207-
return value;
227+
return null;
208228
}
209229

210230
async replaceReference(value) {

0 commit comments

Comments
 (0)