Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 44 additions & 14 deletions app/app/main/measureManagerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on my phone so could be wrong but this looks unused.

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) {
Expand All @@ -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();
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion copyright.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
OpenStudio
Copyright (c) 2008-2020, Alliance for Sustainable Energy
Copyright (c) 2008-2023, Alliance for Sustainable Energy
All Rights Reserved.


Expand Down
2 changes: 1 addition & 1 deletion license.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2008-2020, Alliance for Sustainable Energy.
Copyright (c) 2008-2023, Alliance for Sustainable Energy.
All rights reserved.

NOTICE
Expand Down