diff --git a/app/app/main/measureManagerService.js b/app/app/main/measureManagerService.js index b73fb75f..6f26656d 100644 --- a/app/app/main/measureManagerService.js +++ b/app/app/main/measureManagerService.js @@ -59,9 +59,18 @@ export class MeasureManager { return vm.mmReadyDeferred.promise; } + sleep(milliseconds) { + var start = new Date().getTime(); + for (var i = 0; i < 1e7; i++) { + if ((new Date().getTime() - start) > milliseconds){ + break; + } + } + } + startMeasureManager() { const vm = this; - + let str = ''; // find an open port portfinder.getPortPromise({ port: 3100, @@ -70,12 +79,12 @@ export class MeasureManager { vm.port = port; vm.$log.info('Measure Manager port: ', vm.port); - vm.$log.info('Start Measure Manager Server: ', vm.cliPath, ' measure -s ', vm.port); - vm.cli = vm.spawn(vm.cliPath, ['measure', '-s', vm.port]); + vm.$log.info('Start Measure Manager Server: ', vm.cliPath, 'labs measure -s ', vm.port); + let the_cmd = vm.cliPath + ' labs'; + vm.cli = vm.spawn(vm.cliPath, ['labs', 'measure', '-s', vm.port], { cwd: '.', stdio : 'pipe' }); vm.cli.stdout.on('data', (data) => { // record errors if (data.indexOf('<0>') !== -1) { - // WARNING vm.$log.warn(`MeasureManager WARNING: ${data}`); vm.Message.appendMeasureManagerError({type: 'warning', data: data.toString()}); } else if (data.indexOf('<1>') !== -1) { @@ -88,30 +97,35 @@ export class MeasureManager { vm.Message.appendMeasureManagerError({type: 'fatal', data: data.toString()}); } else { - if (vm.Message.showDebug()) vm.$log.debug(`MeasureManager: ${data}`); + if (vm.Message.showDebug()) vm.$log.debug(`MeasureManager: ${data}`); } + // check that the mm was started correctly: resolve readyDeferred - const str = data.toString(); + str = data.toString(); if (str.indexOf('WEBrick::HTTPServer#start: pid=') !== -1) { - if (vm.Message.showDebug()) vm.$log.debug('Found WEBrick Start!, resolve promise'); + vm.$log.info('Found WEBrick Start, MeasureManager is running'); vm.mmReadyDeferred.resolve(); } // TODO: THIS IS TEMPORARY (windows): else if (str.indexOf('Only one usage of each socket address') !== -1) { - if (vm.Message.showDebug()) vm.$log.debug('WEBrick already running...assuming MeasureManager is already up'); + vm.$log.info('WEBrick already running...assuming MeasureManager is already up'); vm.mmReadyDeferred.resolve(); } // TODO: THIS IS TEMPORARY (mac): else if (str.indexOf('Error: Address already in use') !== -1) { - if (vm.Message.showDebug()) vm.$log.debug('WEBrick already running...assuming MeasureManager is already up'); + vm.$log.info('WEBrick already running...assuming MeasureManager is already running'); + vm.mmReadyDeferred.resolve(); + } + else if (str.indexOf('MeasureManager Ready') !== -1) { + // New labs command MeasureManager + vm.$log.info("LABS command 'MeasureManagerReady' detected. MeasureManager is running!"); vm.mmReadyDeferred.resolve(); } - }); vm.cli.stderr.on('data', (data) => { vm.$log.info(`MeasureManager: ${data}`); // check that the mm was started correctly: resolve readyDeferred - const str = data.toString(); + str = data.toString(); if (str.indexOf('WEBrick::HTTPServer#start: pid=') !== -1) { if (vm.Message.showDebug()) vm.$log.debug('Found WEBrick Start!, resolve promise'); vm.mmReadyDeferred.resolve(); @@ -127,10 +141,25 @@ export class MeasureManager { vm.mmReadyDeferred.resolve(); } }); + vm.cli.on('error', (err) => { + console.log('Failed to start measure manager'); + }); + vm.cli.on('message', (msg) => { + console.log(`child message due to receipt of signal ${msg}`); + }); + vm.cli.on('close', (code) => { vm.$log.info(`Measure Manager exited with code ${code}`); }); - }).catch(() => vm.$log.error('Error locating an open port for measure manager.')); + vm.cli.on('exit', (code) => { + if (code !== 0) { + const msg = `Failed with code = ${code}`; + } + }); + + }).catch((err) => { + vm.$log.error('Error locating an open port for measure manager.') + }); } stopMeasureManager() { @@ -249,7 +278,6 @@ export class MeasureManager { // reset MeasureManagerErrors when a new action vm.Message.resetMeasureManagerErrors(); - return vm.$http.post(`${vm.url}:${vm.port}/set`, params) .then(res => { vm.$log.info('Measure Manager setMyMeasuresDir Success!, status: ', res.status); @@ -289,7 +317,9 @@ export class MeasureManager { .then(res => { vm.$log.info('Measure Manager download_bcl_measure Success!, status: ', res.status); vm.$log.info('Data: ', res.data); - return res.data[0]; + // KAF: format of res.data has changed with labs MM + //return res.data[0]; + return res.data }) .catch(res => { vm.$log.error('Measure Manager download_bcl_measure Error: ', res.data); diff --git a/copyright.txt b/copyright.txt index 22166f0d..d0787b46 100644 --- a/copyright.txt +++ b/copyright.txt @@ -1,5 +1,5 @@ OpenStudio -Copyright (c) 2008-2020, Alliance for Sustainable Energy +Copyright (c) 2008-2023, Alliance for Sustainable Energy All Rights Reserved. diff --git a/license.txt b/license.txt index 8152cae1..848a45fd 100644 --- a/license.txt +++ b/license.txt @@ -1,4 +1,4 @@ -Copyright (c) 2008-2020, Alliance for Sustainable Energy. +Copyright (c) 2008-2023, Alliance for Sustainable Energy. All rights reserved. NOTICE