mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
Merge branch 'fix-statusupdate' into 'master'
Fix status update of ICs See merge request acs/public/villas/web!71
This commit is contained in:
commit
aec3a31c00
6 changed files with 113 additions and 166 deletions
|
@ -44,67 +44,6 @@ class IcDataDataManager {
|
|||
}
|
||||
}
|
||||
|
||||
getStatus(url,socketname,token,icid,ic){
|
||||
RestAPI.get(url, null).then(response => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ic-status/status-received',
|
||||
data: response,
|
||||
token: token,
|
||||
socketname: socketname,
|
||||
icid: icid,
|
||||
ic: ic
|
||||
});
|
||||
if(!ic.managedexternally){
|
||||
let tempIC = ic;
|
||||
tempIC.state = response.state;
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ics/start-edit',
|
||||
data: tempIC,
|
||||
token: token,
|
||||
});
|
||||
}
|
||||
}).catch(error => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ic-status/status-error',
|
||||
error: error
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
restart(url,socketname,token){
|
||||
RestAPI.post(url, null).then(response => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ic-status/restart-successful',
|
||||
data: response,
|
||||
token: token,
|
||||
socketname: socketname,
|
||||
});
|
||||
}).catch(error => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ic-status/restart-error',
|
||||
error: error
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
shutdown(url,socketname,token){
|
||||
RestAPI.post(url, null).then(response => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ic-status/shutdown-successful',
|
||||
data: response,
|
||||
token: token,
|
||||
socketname: socketname,
|
||||
});
|
||||
}).catch(error => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ic-status/shutdown-error',
|
||||
error: error
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
closeAll() {
|
||||
// close every open socket
|
||||
for (var identifier in this._sockets) {
|
||||
|
|
|
@ -71,7 +71,7 @@ class ICDialog extends React.Component {
|
|||
<h5>Status:</h5>
|
||||
|
||||
<ReactJson
|
||||
src={this.props.icStatus}
|
||||
src={this.props.ic.statusupdateraw}
|
||||
name={false}
|
||||
displayDataTypes={false}
|
||||
displayObjectSize={false}
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
/**
|
||||
* 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 '../common/array-store';
|
||||
import ICDataDataManager from './ic-data-data-manager';
|
||||
|
||||
class ICStatusStore extends ArrayStore {
|
||||
constructor() {
|
||||
super('ic-status', ICDataDataManager);
|
||||
}
|
||||
|
||||
|
||||
reduce(state, action) {
|
||||
switch(action.type) {
|
||||
|
||||
case 'ic-status/get-status':
|
||||
ICDataDataManager.getStatus(action.url, action.socketname, action.token, action.icid, action.ic);
|
||||
return super.reduce(state, action);
|
||||
|
||||
case 'ic-status/status-received':
|
||||
let tempData = action.data;
|
||||
tempData.icID = action.icid;
|
||||
|
||||
return this.updateElements(state, [tempData]);
|
||||
|
||||
case 'ic-status/status-error':
|
||||
console.log("status error");
|
||||
return state;
|
||||
|
||||
case 'ic-status/restart':
|
||||
ICDataDataManager.restart(action.url, action.socketname, action.token);
|
||||
return state;
|
||||
|
||||
case 'ic-status/restart-successful':
|
||||
return state;
|
||||
|
||||
case 'ic-status/restart-error':
|
||||
console.log("restart error");
|
||||
return state;
|
||||
|
||||
case 'ic-status/shutdown':
|
||||
ICDataDataManager.shutdown(action.url, action.socketname, action.token);
|
||||
return state;
|
||||
|
||||
case 'ic-status/shutdown-successful':
|
||||
return state;
|
||||
|
||||
case 'ic-status/shutdown-error':
|
||||
console.log("shutdown error");
|
||||
return state;
|
||||
|
||||
default:
|
||||
return super.reduce(state, action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new ICStatusStore();
|
|
@ -76,6 +76,51 @@ class InfrastructureComponentStore extends ArrayStore {
|
|||
console.log(action.error);
|
||||
return state;
|
||||
|
||||
case 'ics/get-status':
|
||||
ICsDataManager.getStatus(action.url, action.token, action.ic);
|
||||
return super.reduce(state, action);
|
||||
|
||||
case 'ics/status-received':
|
||||
let tempIC = action.ic;
|
||||
if(!tempIC.managedexternally){
|
||||
tempIC.state = action.data.state;
|
||||
tempIC.statusupdateraw = action.data;
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ics/start-edit',
|
||||
data: tempIC,
|
||||
token: action.token,
|
||||
});
|
||||
}
|
||||
return super.reduce(state, action);
|
||||
|
||||
case 'ics/status-error':
|
||||
console.log("status error:", action.error);
|
||||
return super.reduce(state, action);
|
||||
|
||||
case 'ics/restart':
|
||||
ICsDataManager.restart(action.url, action.token);
|
||||
return super.reduce(state, action);
|
||||
|
||||
case 'ics/restart-successful':
|
||||
console.log("restart response:", action.data);
|
||||
return super.reduce(state, action);
|
||||
|
||||
case 'ics/restart-error':
|
||||
console.log("restart error:", action.error);
|
||||
return super.reduce(state, action);
|
||||
|
||||
case 'ics/shutdown':
|
||||
ICsDataManager.shutdown(action.url, action.token);
|
||||
return super.reduce(state, action);
|
||||
|
||||
case 'ics/shutdown-successful':
|
||||
console.log("shutdown response:", action.data);
|
||||
return super.reduce(state, action);
|
||||
|
||||
case 'ics/shutdown-error':
|
||||
console.log("shutdown error:", action.error);
|
||||
return super.reduce(state, action);
|
||||
|
||||
default:
|
||||
return super.reduce(state, action);
|
||||
}
|
||||
|
|
|
@ -20,23 +20,69 @@ import RestAPI from '../common/api/rest-api';
|
|||
import AppDispatcher from '../common/app-dispatcher';
|
||||
|
||||
class IcsDataManager extends RestDataManager {
|
||||
constructor() {
|
||||
super('ic', '/ic');
|
||||
}
|
||||
constructor() {
|
||||
super('ic', '/ic');
|
||||
}
|
||||
|
||||
doActions(ic, action, token = null) {
|
||||
RestAPI.post(this.makeURL(this.url + '/' + ic.id + '/action'), action, token).then(response => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ics/action-started',
|
||||
data: response
|
||||
});
|
||||
}).catch(error => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ics/action-error',
|
||||
error
|
||||
});
|
||||
});
|
||||
}
|
||||
doActions(ic, action, token = null) {
|
||||
RestAPI.post(this.makeURL(this.url + '/' + ic.id + '/action'), action, token).then(response => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ics/action-started',
|
||||
data: response
|
||||
});
|
||||
}).catch(error => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ics/action-error',
|
||||
error
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getStatus(url,token,ic){
|
||||
RestAPI.get(url, null).then(response => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ics/status-received',
|
||||
data: response,
|
||||
token: token,
|
||||
ic: ic
|
||||
});
|
||||
}).catch(error => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ics/status-error',
|
||||
error: error
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
restart(url,token){
|
||||
RestAPI.post(url, null).then(response => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ics/restart-successful',
|
||||
data: response,
|
||||
token: token,
|
||||
});
|
||||
}).catch(error => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ics/restart-error',
|
||||
error: error
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
shutdown(url,token){
|
||||
RestAPI.post(url, null).then(response => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ics/shutdown-successful',
|
||||
data: response,
|
||||
token: token,
|
||||
});
|
||||
}).catch(error => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ics/shutdown-error',
|
||||
error: error
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default new IcsDataManager();
|
||||
|
|
|
@ -24,7 +24,6 @@ import moment from 'moment'
|
|||
|
||||
import AppDispatcher from '../common/app-dispatcher';
|
||||
import InfrastructureComponentStore from './ic-store';
|
||||
import ICStatusStore from './ic-status-store';
|
||||
|
||||
import Icon from '../common/icon';
|
||||
import Table from '../common/table';
|
||||
|
@ -39,7 +38,7 @@ import DeleteDialog from '../common/dialogs/delete-dialog';
|
|||
|
||||
class InfrastructureComponents extends Component {
|
||||
static getStores() {
|
||||
return [ InfrastructureComponentStore, ICStatusStore];
|
||||
return [ InfrastructureComponentStore];
|
||||
}
|
||||
|
||||
static statePrio(state) {
|
||||
|
@ -78,9 +77,7 @@ class InfrastructureComponents extends Component {
|
|||
return {
|
||||
sessionToken: localStorage.getItem("token"),
|
||||
ics: ics,
|
||||
icStatus: ICStatusStore.getState(),
|
||||
modalIC: {},
|
||||
modalICStatus: {},
|
||||
deleteModal: false,
|
||||
icModal: false,
|
||||
selectedICs: [],
|
||||
|
@ -117,13 +114,10 @@ class InfrastructureComponents extends Component {
|
|||
this.state.ics.forEach(ic => {
|
||||
if ((ic.type === "villas-node" || ic.type === "villas-relay")
|
||||
&& ic.apiurl !== '' && ic.apiurl !== undefined && ic.apiurl !== null) {
|
||||
let splitWebsocketURL = ic.websocketurl.split("/");
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ic-status/get-status',
|
||||
type: 'ics/get-status',
|
||||
url: ic.apiurl + "/status",
|
||||
socketname: splitWebsocketURL[splitWebsocketURL.length - 1],
|
||||
token: this.state.sessionToken,
|
||||
icid: ic.id,
|
||||
ic: ic
|
||||
});
|
||||
}
|
||||
|
@ -349,26 +343,22 @@ class InfrastructureComponents extends Component {
|
|||
openICStatus(ic){
|
||||
|
||||
let index = this.state.ics.indexOf(ic);
|
||||
let icStatus = this.state.icStatus.find(status => status.icID === ic.id);
|
||||
|
||||
this.setState({ icModal: true, modalIC: ic, modalICStatus: icStatus, modalIndex: index })
|
||||
this.setState({ icModal: true, modalIC: ic, modalIndex: index })
|
||||
}
|
||||
|
||||
sendControlCommand(command,ic){
|
||||
let splitWebsocketURL = ic.websocketurl.split("/");
|
||||
|
||||
if(command === "restart"){
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ic-status/restart',
|
||||
type: 'ics/restart',
|
||||
url: ic.apiurl + "/restart",
|
||||
socketname: splitWebsocketURL[splitWebsocketURL.length - 1],
|
||||
token: this.state.sessionToken,
|
||||
});
|
||||
}else if(command === "shutdown"){
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ic-status/shutdown',
|
||||
type: 'ics/shutdown',
|
||||
url: ic.apiurl + "/shutdown",
|
||||
socketname: splitWebsocketURL[splitWebsocketURL.length - 1],
|
||||
token: this.state.sessionToken,
|
||||
});
|
||||
}
|
||||
|
@ -451,7 +441,6 @@ class InfrastructureComponents extends Component {
|
|||
ic={this.state.modalIC}
|
||||
token={this.state.sessionToken}
|
||||
userRole={this.state.currentUser.role}
|
||||
icStatus={this.state.modalICStatus}
|
||||
sendControlCommand={(command, ic) => this.sendControlCommand(command, ic)}/>
|
||||
|
||||
<DeleteDialog title="infrastructure-component" name={this.state.modalIC.name || 'Unknown'} show={this.state.deleteModal} onClose={(e) => this.closeDeleteModal(e)} />
|
||||
|
|
Loading…
Add table
Reference in a new issue