@@ -16,7 +16,6 @@ const which = require('which')
1616const aioLogger = require ( '@adobe/aio-lib-core-logging' ) ( '@adobe/aio-cli-plugin-app:lib-app-helper' , { provider : 'debug' } )
1717const { getToken, context } = require ( '@adobe/aio-lib-ims' )
1818const { CLI } = require ( '@adobe/aio-lib-ims/src/context' )
19- const { createFetch } = require ( '@adobe/aio-lib-core-networking' )
2019const chalk = require ( 'chalk' )
2120const aioConfig = require ( '@adobe/aio-lib-core-config' )
2221const { AIO_CONFIG_WORKSPACE_SERVICES , AIO_CONFIG_ORG_SERVICES } = require ( './defaults' )
@@ -262,116 +261,6 @@ function writeConfig (file, config) {
262261 )
263262}
264263
265- /** @private */
266- async function isDockerRunning ( ) {
267- // todo more checks
268- const args = [ 'info' ]
269- try {
270- await execa ( 'docker' , args )
271- return true
272- } catch ( error ) {
273- aioLogger . debug ( 'Error spawning docker info: ' + error )
274- }
275- return false
276- }
277-
278- /** @private */
279- async function hasDockerCLI ( ) {
280- // todo check min version
281- try {
282- const result = await execa ( 'docker' , [ '-v' ] )
283- aioLogger . debug ( 'docker version : ' + result . stdout )
284- return true
285- } catch ( error ) {
286- aioLogger . debug ( 'Error spawning docker info: ' + error )
287- }
288- return false
289- }
290-
291- /** @private */
292- async function hasJavaCLI ( ) {
293- // todo check min version
294- try {
295- const result = await execa ( 'java' , [ '-version' ] )
296- // stderr is where the version is printed out for
297- aioLogger . debug ( 'java version : ' + result . stderr )
298- return true
299- } catch ( error ) {
300- aioLogger . debug ( 'Error spawning java info: ' + error )
301- }
302- return false
303- }
304-
305- /** @private */
306- async function downloadOWJar ( url , outFile ) {
307- aioLogger . debug ( `downloadOWJar - url: ${ url } outFile: ${ outFile } ` )
308- let response
309- try {
310- const fetch = createFetch ( )
311- response = await fetch ( url )
312- } catch ( e ) {
313- aioLogger . debug ( `connection error while downloading '${ url } '` , e )
314- throw new Error ( `connection error while downloading '${ url } ', are you online?` )
315- }
316- if ( ! response . ok ) throw new Error ( `unexpected response while downloading '${ url } ': ${ response . statusText } ` )
317- fs . ensureDirSync ( path . dirname ( outFile ) )
318- const fstream = fs . createWriteStream ( outFile )
319-
320- return new Promise ( ( resolve , reject ) => {
321- response . body . pipe ( fstream )
322- response . body . on ( 'error' , ( err ) => {
323- reject ( err )
324- } )
325- fstream . on ( 'finish' , ( ) => {
326- resolve ( )
327- } )
328- } )
329- }
330-
331- /** @private */
332- async function waitForOpenWhiskReadiness ( host , endTime , period , timeout , lastStatus , waitFunc ) {
333- if ( Date . now ( ) > endTime ) {
334- throw new Error ( `local openwhisk stack startup timed out after ${ timeout } ms due to ${ lastStatus } ` )
335- }
336-
337- let ok , status
338-
339- try {
340- const fetch = createFetch ( )
341- const response = await fetch ( host + '/api/v1' )
342- ok = response . ok
343- status = response . statusText
344- } catch ( e ) {
345- ok = false
346- status = e . toString ( )
347- }
348-
349- if ( ! ok ) {
350- await waitFunc ( period )
351- return waitForOpenWhiskReadiness ( host , endTime , period , timeout , status , waitFunc )
352- }
353- }
354-
355- /** @private */
356- function waitFor ( t ) {
357- return new Promise ( resolve => setTimeout ( resolve , t ) )
358- }
359-
360- /** @private */
361- async function runOpenWhiskJar ( jarFile , runtimeConfigFile , apihost , waitInitTime , waitPeriodTime , timeout , /* istanbul ignore next */ execaOptions = { } ) {
362- aioLogger . debug ( `runOpenWhiskJar - jarFile: ${ jarFile } runtimeConfigFile ${ runtimeConfigFile } apihost: ${ apihost } waitInitTime: ${ waitInitTime } waitPeriodTime: ${ waitPeriodTime } timeout: ${ timeout } ` )
363- const jvmConfig = aioConfig . get ( 'ow.jvm.args' )
364- const jvmArgs = jvmConfig ? jvmConfig . split ( ' ' ) : [ ]
365- const proc = execa ( 'java' , [ '-jar' , '-Dwhisk.concurrency-limit.max=10' , ...jvmArgs , jarFile , '-m' , runtimeConfigFile , '--no-ui' , '--disable-color-logging' ] , execaOptions )
366-
367- const endTime = Date . now ( ) + timeout
368- await waitFor ( waitInitTime )
369- await waitForOpenWhiskReadiness ( apihost , endTime , waitPeriodTime , timeout , null , waitFor )
370-
371- // must wrap in an object as execa return value is awaitable
372- return { proc }
373- }
374-
375264/**
376265 *
377266 *Converts a service array to an input string that can be consumed by generator-aio-app
@@ -599,14 +488,8 @@ module.exports = {
599488 removeProtocolFromURL,
600489 urlJoin,
601490 checkFile,
602- hasDockerCLI,
603- hasJavaCLI,
604- isDockerRunning,
605491 writeConfig,
606- downloadOWJar,
607- runOpenWhiskJar,
608492 servicesToGeneratorInput,
609- waitForOpenWhiskReadiness,
610493 warnIfOverwriteServicesInProductionWorkspace,
611494 setOrgServicesConfig,
612495 setWorkspaceServicesConfig,
0 commit comments