mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
Display simulator status in tree-view
Remove unneeded files anymore
This commit is contained in:
parent
19dc2e55c3
commit
ac19c3c48d
3 changed files with 1 additions and 235 deletions
|
@ -67,7 +67,7 @@ class NodeTree extends React.Component {
|
|||
var parent = { title: node.name, subtitle: node.endpoint, id: node._id, config: node.config, children: [], expanded: true };
|
||||
|
||||
node.simulators.forEach((simulator) => {
|
||||
parent.children.push({ title: simulator.name });
|
||||
parent.children.push({ title: simulator.name, subtitle: simulator.id != null ? 'Online' : 'Offline' });
|
||||
});
|
||||
|
||||
treeData.push(parent);
|
||||
|
|
|
@ -1,106 +0,0 @@
|
|||
/**
|
||||
* File: simulators-data-manager.js
|
||||
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
|
||||
* Date: 02.03.2017
|
||||
*
|
||||
* This file is part of VILLASweb.
|
||||
*
|
||||
* VILLASweb is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* VILLASweb is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with VILLASweb. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
||||
import RestDataManager from './rest-data-manager';
|
||||
import RestAPI from '../api/rest-api';
|
||||
import AppDispatcher from '../app-dispatcher';
|
||||
|
||||
function isRunning(simulator) {
|
||||
// get path to nodes.json and simulator name
|
||||
var path = simulator.endpoint.substring(0, simulator.endpoint.lastIndexOf('/'));
|
||||
|
||||
var url = 'http://' + path + '/api/v1';
|
||||
var body = {
|
||||
action: 'nodes',
|
||||
id: '1234' /// @todo use random generated id
|
||||
};
|
||||
|
||||
// send request
|
||||
RestAPI.post(url, body).then(response => {
|
||||
// check if simulator is running
|
||||
simulator.running = false;
|
||||
|
||||
if (response.id === body.id) {
|
||||
response.response.forEach(sim => {
|
||||
if (sim.name === simulator.name) {
|
||||
simulator.running = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
AppDispatcher.dispatch({
|
||||
type: 'simulators/running',
|
||||
simulator: simulator,
|
||||
running: simulator.running
|
||||
});
|
||||
}).catch(error => {
|
||||
simulator.running = false;
|
||||
|
||||
AppDispatcher.dispatch({
|
||||
type: 'simulators/running',
|
||||
simulator: simulator,
|
||||
running: simulator.running
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class SimulatorsDataManager extends RestDataManager {
|
||||
constructor() {
|
||||
super('simulator', '/simulators', [ '_id', 'name', 'endpoint' ]);
|
||||
|
||||
this._timers = [];
|
||||
}
|
||||
|
||||
startRunningDetection(obj) {
|
||||
const simulator = JSON.parse(JSON.stringify(obj));
|
||||
|
||||
// check if timer is already running
|
||||
const index = this._timers.findIndex(timer => {
|
||||
return timer.simulator === simulator._id;
|
||||
});
|
||||
|
||||
if (index !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// do first request for fast response time
|
||||
isRunning(simulator);
|
||||
|
||||
// start new timer
|
||||
const timerID = setInterval(isRunning, 5000, simulator);
|
||||
this._timers.push({ id: timerID, simulator: simulator._id });
|
||||
}
|
||||
|
||||
stopRunningDetection(simulator) {
|
||||
// remove timer
|
||||
const index = this._timers.findIndex(timer => {
|
||||
return timer.simulator === simulator._id;
|
||||
});
|
||||
|
||||
if (index !== -1) {
|
||||
// stop timer and delete from list
|
||||
clearInterval(this._timers[index].id);
|
||||
this._timers.splice(index, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new SimulatorsDataManager();
|
|
@ -1,128 +0,0 @@
|
|||
/**
|
||||
* File: villas-store.js
|
||||
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
|
||||
* Date: 02.03.2017
|
||||
*
|
||||
* This file is part of VILLASweb.
|
||||
*
|
||||
* VILLASweb is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* VILLASweb is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with VILLASweb. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
||||
import ArrayStore from './array-store';
|
||||
import SimulatorsDataManager from '../data-managers/simulators-data-manager';
|
||||
import NotificationsDataManager from '../data-managers/notifications-data-manager';
|
||||
|
||||
class SimulatorStore extends ArrayStore {
|
||||
constructor() {
|
||||
super('simulators', SimulatorsDataManager);
|
||||
}
|
||||
|
||||
reduce(state, action) {
|
||||
var simulator;
|
||||
|
||||
switch (action.type) {
|
||||
|
||||
case 'simulators/added':
|
||||
SimulatorsDataManager.startRunningDetection(action.data);
|
||||
|
||||
return super.reduce(state, action);
|
||||
|
||||
case 'simulators/removed':
|
||||
SimulatorsDataManager.stopRunningDetection(action.original);
|
||||
|
||||
return super.reduce(state, action);
|
||||
|
||||
case 'simulators/start-edit':
|
||||
// An update will be requested, stop the 'runningDetection' already
|
||||
SimulatorsDataManager.stopRunningDetection(action.data);
|
||||
|
||||
return super.reduce(state, action);
|
||||
|
||||
case 'simulators/edited':
|
||||
// The update was done, resume the 'runningDetection'
|
||||
SimulatorsDataManager.startRunningDetection(action.data);
|
||||
|
||||
return super.reduce(state, action);
|
||||
|
||||
case 'simulators/loaded':
|
||||
// get simulator running state
|
||||
if (Array.isArray(action.data)) {
|
||||
action.data.forEach((simulator) => {
|
||||
SimulatorsDataManager.startRunningDetection(simulator);
|
||||
});
|
||||
} else {
|
||||
SimulatorsDataManager.startRunningDetection(action.data);
|
||||
}
|
||||
|
||||
return super.reduce(state, action);
|
||||
|
||||
case 'simulators/running':
|
||||
// check if simulator running state changed
|
||||
simulator = state.find(element => element._id === action.simulator._id );
|
||||
|
||||
// is this simulator still in the state? update it only if state changed
|
||||
if (simulator && simulator.running !== action.simulator.running) {
|
||||
state = this.updateElements(state, [ action.simulator ]);
|
||||
}
|
||||
|
||||
return state;
|
||||
|
||||
case 'simulatorData/opened':
|
||||
// get simulator
|
||||
simulator = state.find(element => {
|
||||
return element._id === action.identifier;
|
||||
});
|
||||
|
||||
if (action.firstOpen === false) {
|
||||
NotificationsDataManager.addNotification({
|
||||
title: 'Simulator online',
|
||||
message: 'Simulator \'' + simulator.name + '\' went online.',
|
||||
level: 'info'
|
||||
});
|
||||
}
|
||||
|
||||
// restart requesting again
|
||||
SimulatorsDataManager.stopRunningDetection(simulator);
|
||||
|
||||
return state;
|
||||
|
||||
case 'simulatorData/closed':
|
||||
// get simulator
|
||||
simulator = state.find(element => {
|
||||
return element._id === action.identifier;
|
||||
});
|
||||
|
||||
// update running state
|
||||
simulator.running = false;
|
||||
|
||||
if (action.notification) {
|
||||
NotificationsDataManager.addNotification({
|
||||
title: 'Simulator offline',
|
||||
message: 'Simulator \'' + simulator.name + '\' went offline.',
|
||||
level: 'info'
|
||||
});
|
||||
|
||||
// restart requesting again
|
||||
SimulatorsDataManager.startRunningDetection(simulator);
|
||||
}
|
||||
|
||||
return this.updateElements(state, [ simulator ]);
|
||||
|
||||
default:
|
||||
return super.reduce(state, action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new SimulatorStore();
|
Loading…
Add table
Reference in a new issue