From aa2e4ade91e5ae95086d997461d8ca9c2f37dc0b Mon Sep 17 00:00:00 2001 From: Elliot Levin Date: Thu, 6 May 2021 11:00:34 +1000 Subject: [PATCH] Allow overriding of local openwhisk jvm args (#402) * Allow overriding of local openwhisk JVM args * Move JVM args after existing system property * add tests for AIO_OW_JVM_ARGS env var for app:run command * cleanup linting; use aioConfig instead of process.env Co-authored-by: Elliot Levin Co-authored-by: Jesse MacFadyen --- src/lib/app-helper.js | 10 ++++++---- test/commands/lib/app-helper.test.js | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/lib/app-helper.js b/src/lib/app-helper.js index 09e2b3fd..6ff2a2ae 100644 --- a/src/lib/app-helper.js +++ b/src/lib/app-helper.js @@ -18,7 +18,7 @@ const { getToken, context } = require('@adobe/aio-lib-ims') const { CLI } = require('@adobe/aio-lib-ims/src/context') const fetch = require('node-fetch') const chalk = require('chalk') -const config = require('@adobe/aio-lib-core-config') +const aioConfig = require('@adobe/aio-lib-core-config') const { AIO_CONFIG_WORKSPACE_SERVICES, AIO_CONFIG_ORG_SERVICES } = require('./defaults') const { EOL } = require('os') @@ -288,7 +288,9 @@ function waitFor (t) { /** @private */ async function runOpenWhiskJar (jarFile, runtimeConfigFile, apihost, waitInitTime, waitPeriodTime, timeout, /* istanbul ignore next */ execaOptions = {}) { aioLogger.debug(`runOpenWhiskJar - jarFile: ${jarFile} runtimeConfigFile ${runtimeConfigFile} apihost: ${apihost} waitInitTime: ${waitInitTime} waitPeriodTime: ${waitPeriodTime} timeout: ${timeout}`) - const proc = execa('java', ['-jar', '-Dwhisk.concurrency-limit.max=10', jarFile, '-m', runtimeConfigFile, '--no-ui', '--disable-color-logging'], execaOptions) + const jvmConfig = aioConfig.get('ow.jvm.args') + const jvmArgs = jvmConfig ? jvmConfig.split(' ') : [] + const proc = execa('java', ['-jar', '-Dwhisk.concurrency-limit.max=10', ...jvmArgs, jarFile, '-m', runtimeConfigFile, '--no-ui', '--disable-color-logging'], execaOptions) const endTime = Date.now() + timeout await waitFor(waitInitTime) @@ -334,7 +336,7 @@ function setWorkspaceServicesConfig (serviceProperties) { name: s.name, code: s.sdkCode })) - config.set(AIO_CONFIG_WORKSPACE_SERVICES, serviceConfig, true) + aioConfig.set(AIO_CONFIG_WORKSPACE_SERVICES, serviceConfig, true) aioLogger.debug(`set aio config ${AIO_CONFIG_WORKSPACE_SERVICES}: ${JSON.stringify(serviceConfig, null, 2)}`) } @@ -349,7 +351,7 @@ function setOrgServicesConfig (supportedServices) { code: s.code, type: s.type })) - config.set(AIO_CONFIG_ORG_SERVICES, orgServiceConfig, true) + aioConfig.set(AIO_CONFIG_ORG_SERVICES, orgServiceConfig, true) aioLogger.debug(`set aio config ${AIO_CONFIG_ORG_SERVICES}: ${JSON.stringify(orgServiceConfig, null, 2)}`) } diff --git a/test/commands/lib/app-helper.test.js b/test/commands/lib/app-helper.test.js index 811cd4d4..a589778e 100644 --- a/test/commands/lib/app-helper.test.js +++ b/test/commands/lib/app-helper.test.js @@ -520,13 +520,28 @@ test('runOpenWhiskJar ok', async () => { fetch.mockReturnValue({ ok: true }) execa.mockReturnValue({ stdout: jest.fn() }) - const result = appHelper.runOpenWhiskJar() + const result = appHelper.runOpenWhiskJar('jar', 'conf') await expect(result).resolves.toEqual({ proc: expect.any(Object) }) expect(fetch).toHaveBeenCalledTimes(1) - expect(execa).toHaveBeenCalledTimes(1) + expect(execa).toHaveBeenCalledWith('java', expect.arrayContaining(['jar', 'conf']), {}) +}) + +test('runOpenWhiskJar with AIO_OW_JVM_ARGS env var is passed to execa', async () => { + fetch.mockReturnValue({ ok: true }) + execa.mockReturnValue({ stdout: jest.fn() }) + + config.get.mockReturnValueOnce('arg1 arg2') + + const result = appHelper.runOpenWhiskJar('jar', 'conf') + + await expect(result).resolves.toEqual({ + proc: expect.any(Object) + }) + expect(fetch).toHaveBeenCalledTimes(1) + expect(execa).toHaveBeenCalledWith('java', expect.arrayContaining(['arg1', 'arg2', 'jar', 'conf']), {}) }) test('waitForOpenWhiskReadiness timeout', async () => {