From ce3685f88b436a3d24e5fc53637b9c58110ffe0a Mon Sep 17 00:00:00 2001 From: kflemin <2205659+kflemin@users.noreply.github.com> Date: Fri, 22 Sep 2023 12:17:30 -0600 Subject: [PATCH 1/2] testing out new labs MeasureManager --- app/app/main/measureManagerService.js | 71 +++++++++++++++++++++++---- copyright.txt | 2 +- license.txt | 2 +- 3 files changed, 63 insertions(+), 12 deletions(-) diff --git a/app/app/main/measureManagerService.js b/app/app/main/measureManagerService.js index b73fb75f..a31f5550 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,16 @@ 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); + console.log(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 + // KF Note: I think the "labs command is experimental warning will/should show up + // here. that might not be good. vm.$log.warn(`MeasureManager WARNING: ${data}`); vm.Message.appendMeasureManagerError({type: 'warning', data: data.toString()}); } else if (data.indexOf('<1>') !== -1) { @@ -88,10 +101,11 @@ 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.mmReadyDeferred.resolve(); @@ -106,12 +120,17 @@ export class MeasureManager { if (vm.Message.showDebug()) vm.$log.debug('WEBrick already running...assuming MeasureManager is already up'); vm.mmReadyDeferred.resolve(); } - + else if (str.indexOf('Serving on: ') !== -1) { + // KF Note: I would expect that we end up here (if the warning isn't picked up) + // but we don't seem to get here when we should + console.log("LABS command Serving on... detected. MM 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 +146,40 @@ 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}`; + } + }); + + // KF Note: new labs MM is not returning anything at all (or in time) but it is + // up and running. sleep 2 second and then try to use it + vm.sleep(2 * 1000); + let the_url = vm.url + ":" + vm.port; + console.log("Measure Manager URL: ", the_url) + vm.$http.get(the_url) + .then(res => { + vm.$log.info('MeasureManager status: ', res.data); + console.log("MM pinged and it seemed started!") + vm.mmReadyDeferred.resolve(); + }) + .catch(res => { + vm.$log.error('MeasureManager is not up and running: ', res.data); + }); + + }).catch((err) => { + vm.$log.error('Error locating an open port for measure manager.') + }); } stopMeasureManager() { @@ -230,6 +279,7 @@ export class MeasureManager { // Returns the path to the myMeasures directory getMyMeasuresDir() { const vm = this; + console.log("GetMyMeasuresDir url: ", `${vm.url}:${vm.port}`) return vm.$http.get(`${vm.url}:${vm.port}`, { params: {} }) @@ -249,7 +299,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 +338,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 From cf0d2dd25d8f02e99bfe0549e0635367989aba2e Mon Sep 17 00:00:00 2001 From: kflemin <2205659+kflemin@users.noreply.github.com> Date: Thu, 28 Sep 2023 09:45:14 -0600 Subject: [PATCH 2/2] cleanup for labs measure manager --- app/app/main/measureManagerService.js | 33 +++++---------------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/app/app/main/measureManagerService.js b/app/app/main/measureManagerService.js index a31f5550..6f26656d 100644 --- a/app/app/main/measureManagerService.js +++ b/app/app/main/measureManagerService.js @@ -80,15 +80,11 @@ export class MeasureManager { vm.$log.info('Measure Manager port: ', vm.port); vm.$log.info('Start Measure Manager Server: ', vm.cliPath, 'labs measure -s ', vm.port); - console.log(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 - // KF Note: I think the "labs command is experimental warning will/should show up - // here. that might not be good. vm.$log.warn(`MeasureManager WARNING: ${data}`); vm.Message.appendMeasureManagerError({type: 'warning', data: data.toString()}); } else if (data.indexOf('<1>') !== -1) { @@ -107,23 +103,22 @@ export class MeasureManager { // check that the mm was started correctly: resolve readyDeferred 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('Serving on: ') !== -1) { - // KF Note: I would expect that we end up here (if the warning isn't picked up) - // but we don't seem to get here when we should - console.log("LABS command Serving on... detected. MM is running!") + else if (str.indexOf('MeasureManager Ready') !== -1) { + // New labs command MeasureManager + vm.$log.info("LABS command 'MeasureManagerReady' detected. MeasureManager is running!"); vm.mmReadyDeferred.resolve(); } }); @@ -162,21 +157,6 @@ export class MeasureManager { } }); - // KF Note: new labs MM is not returning anything at all (or in time) but it is - // up and running. sleep 2 second and then try to use it - vm.sleep(2 * 1000); - let the_url = vm.url + ":" + vm.port; - console.log("Measure Manager URL: ", the_url) - vm.$http.get(the_url) - .then(res => { - vm.$log.info('MeasureManager status: ', res.data); - console.log("MM pinged and it seemed started!") - vm.mmReadyDeferred.resolve(); - }) - .catch(res => { - vm.$log.error('MeasureManager is not up and running: ', res.data); - }); - }).catch((err) => { vm.$log.error('Error locating an open port for measure manager.') }); @@ -279,7 +259,6 @@ export class MeasureManager { // Returns the path to the myMeasures directory getMyMeasuresDir() { const vm = this; - console.log("GetMyMeasuresDir url: ", `${vm.url}:${vm.port}`) return vm.$http.get(`${vm.url}:${vm.port}`, { params: {} })