Skip to content
Snippets Groups Projects
Commit 9b6443a8 authored by Viktor Vorobev's avatar Viktor Vorobev
Browse files

Merged in NRRPLT-8926-mqtt-prefix (pull request #49)

[NRRPLT-8926] MQTT prefix

* [NRRPLT-8926] Add MQTTPrefix alongside with simulationID

* [NRRPLT-8926] Fix MQTTPrefix order

* [NRRPLT-8926] Do not add an empty prefix

* [NRRPLT-8931] Add ws/wss parameter to config

* Merge branch 'NRRPLT-8931-wss' into NRRPLT-8926-mqtt-prefix

* Merge remote-tracking branch 'origin/development' into NRRPLT-8926-mqtt-prefix


Approved-by: Sandro Weber
parent 06d75336
No related branches found
No related tags found
No related merge requests found
...@@ -53,7 +53,10 @@ class SimulationDetails extends React.Component { ...@@ -53,7 +53,10 @@ class SimulationDetails extends React.Component {
* Opens experiment workbench and sets the running simulation ID in ExperimentWorkbenchService * Opens experiment workbench and sets the running simulation ID in ExperimentWorkbenchService
*/ */
joinSimulation(simulationInfo) { joinSimulation(simulationInfo) {
ExperimentWorkbenchService.instance.simulationID = simulationInfo.runningSimulation.simulationID; ExperimentWorkbenchService.instance.simulationInfo = {
ID: simulationInfo.runningSimulation.simulationID,
MQTTPrefix: simulationInfo.runningSimulation.MQTTPrefix
};
ServerResourcesService.instance.getServerConfig(simulationInfo.server).then((serverConfig) => { ServerResourcesService.instance.getServerConfig(simulationInfo.server).then((serverConfig) => {
ExperimentWorkbenchService.instance.serverURL = serverConfig['nrp-services']; ExperimentWorkbenchService.instance.serverURL = serverConfig['nrp-services'];
this.props.history.push({ this.props.history.push({
......
...@@ -32,7 +32,6 @@ export default class ExperimentTimeBox extends React.Component { ...@@ -32,7 +32,6 @@ export default class ExperimentTimeBox extends React.Component {
break; break;
} }
this.state = { this.state = {
simulationID: undefined,
timeToken: null, timeToken: null,
simulationTime: undefined simulationTime: undefined
}; };
......
...@@ -15,7 +15,7 @@ class ExperimentWorkbenchService extends EventEmitter { ...@@ -15,7 +15,7 @@ class ExperimentWorkbenchService extends EventEmitter {
if (enforcer !== SINGLETON_ENFORCER) { if (enforcer !== SINGLETON_ENFORCER) {
throw new Error('Use ' + this.constructor.name + '.instance'); throw new Error('Use ' + this.constructor.name + '.instance');
} }
this._simulationID = undefined; this._simulationInfo = undefined;
this._serverURL = undefined; this._serverURL = undefined;
this._errorToken = undefined; this._errorToken = undefined;
this._statusToken = undefined; this._statusToken = undefined;
...@@ -53,17 +53,23 @@ class ExperimentWorkbenchService extends EventEmitter { ...@@ -53,17 +53,23 @@ class ExperimentWorkbenchService extends EventEmitter {
console.info(['ExperimentWorkbenchService - serverURL', this._serverURL]); console.info(['ExperimentWorkbenchService - serverURL', this._serverURL]);
} }
get simulationID() { /**
return this._simulationID; * Returns the simulation MQTT description
* @returns {object} the simulation info
* @returns {string} simulationInfo.ID the simulation ID
* @returns {string} simulationInfo.MQTTPrefix the simulation MQTT Prefix
*/
get simulationInfo() {
return this._simulationInfo;
} }
set simulationID(simulationID) { set simulationInfo(simulationInfo) {
this._simulationID = simulationID; this._simulationInfo = simulationInfo;
console.info(['ExperimentWorkbenchService - simulationID', this._simulationID]); console.info(['ExperimentWorkbenchService - simulationInfo', this._simulationInfo]);
ExperimentWorkbenchService.instance.emit( ExperimentWorkbenchService.instance.emit(
ExperimentWorkbenchService.EVENTS.SIMULATION_SET, ExperimentWorkbenchService.EVENTS.SIMULATION_SET,
this._simulationID this._simulationInfo
); );
this.setTopics(this._simulationID); this.setTopics(this._simulationInfo);
} }
/** /**
...@@ -74,7 +80,7 @@ class ExperimentWorkbenchService extends EventEmitter { ...@@ -74,7 +80,7 @@ class ExperimentWorkbenchService extends EventEmitter {
return MqttClientService.instance.isConnected(); return MqttClientService.instance.isConnected();
} }
setTopics = (simulationID) => { setTopics = (simulationInfo) => {
if (this._errorToken) { if (this._errorToken) {
MqttClientService.instance.unsubscribe(this._errorToken); MqttClientService.instance.unsubscribe(this._errorToken);
this._errorToken = undefined; this._errorToken = undefined;
...@@ -83,9 +89,11 @@ class ExperimentWorkbenchService extends EventEmitter { ...@@ -83,9 +89,11 @@ class ExperimentWorkbenchService extends EventEmitter {
MqttClientService.instance.unsubscribe(this._statusToken); MqttClientService.instance.unsubscribe(this._statusToken);
this._statusToken = undefined; this._statusToken = undefined;
} }
if (simulationID !== undefined) { if (simulationInfo !== undefined) {
const topicBase = MqttClientService.instance.getConfig().mqtt.topics.base + '/' const mqttTopics = MqttClientService.instance.getConfig().mqtt.topics;
+ simulationID + '/'; const topicBase = simulationInfo.MQTTPrefix ?
simulationInfo.MQTTPrefix + '/' + mqttTopics.base + '/' + simulationInfo.ID + '/' :
mqttTopics.base + '/' + simulationInfo.ID + '/';
// assign error MQTT topic // assign error MQTT topic
const errorTopic = topicBase + MqttClientService.instance.getConfig().mqtt.topics.errors; const errorTopic = topicBase + MqttClientService.instance.getConfig().mqtt.topics.errors;
const errorToken = MqttClientService.instance.subscribeToTopic(errorTopic, this.errorMsgHandler); const errorToken = MqttClientService.instance.subscribeToTopic(errorTopic, this.errorMsgHandler);
......
...@@ -212,7 +212,9 @@ class ExperimentWorkbench extends React.Component { ...@@ -212,7 +212,9 @@ class ExperimentWorkbench extends React.Component {
async componentDidMount() { async componentDidMount() {
// Get the simulation ID from ExperimentWorkbenchService, if is defined (for joining the simulation) // Get the simulation ID from ExperimentWorkbenchService, if is defined (for joining the simulation)
this.state.runningSimulationID = ExperimentWorkbenchService.instance.simulationID; if (ExperimentWorkbenchService.instance.simulationInfo !== undefined) {
this.state.runningSimulationID = ExperimentWorkbenchService.instance.simulationInfo.ID;
}
// Update simulation state, if it is defined // Update simulation state, if it is defined
if (this.state.runningSimulationID !== undefined) { if (this.state.runningSimulationID !== undefined) {
...@@ -255,7 +257,7 @@ class ExperimentWorkbench extends React.Component { ...@@ -255,7 +257,7 @@ class ExperimentWorkbench extends React.Component {
this.onUpdateServerAvailability this.onUpdateServerAvailability
); );
// Remove the simulation when we leave the workbench // Remove the simulation when we leave the workbench
ExperimentWorkbenchService.instance.simulationID = undefined; ExperimentWorkbenchService.instance.simulationInfo = undefined;
} }
/** /**
...@@ -283,9 +285,9 @@ class ExperimentWorkbench extends React.Component { ...@@ -283,9 +285,9 @@ class ExperimentWorkbench extends React.Component {
DialogService.instance.progressNotification({ DialogService.instance.progressNotification({
message: 'The experiment is ' + this.state.simulationState message: 'The experiment is ' + this.state.simulationState
}); });
// clear simulationID for the finilized experiments // clear simulationInfo for the finilized experiments
if (EXPERIMENT_FINAL_STATE.includes(this.state.simulationState)) { if (EXPERIMENT_FINAL_STATE.includes(this.state.simulationState)) {
ExperimentWorkbenchService.instance.simulationID = undefined; ExperimentWorkbenchService.instance.simulationInfo = undefined;
this.setState({ runningSimulationID: undefined }); this.setState({ runningSimulationID: undefined });
} }
} }
...@@ -320,7 +322,10 @@ class ExperimentWorkbench extends React.Component { ...@@ -320,7 +322,10 @@ class ExperimentWorkbench extends React.Component {
const simInfo = await simRespose['simulation'].json(); const simInfo = await simRespose['simulation'].json();
// TODO: get proper simulation information // TODO: get proper simulation information
if (simInfo) { if (simInfo) {
ExperimentWorkbenchService.instance.simulationID = simInfo.simulationID; ExperimentWorkbenchService.instance.simulationInfo = {
ID: simInfo.simulationID,
MQTTPrefix: simInfo.MQTTPrefix
};
this.setState({ runningSimulationID: simInfo.simulationID }); this.setState({ runningSimulationID: simInfo.simulationID });
// get the simulationState from MQTT only // get the simulationState from MQTT only
this.setState({ simStateLoading: true }); this.setState({ simStateLoading: true });
...@@ -361,7 +366,7 @@ class ExperimentWorkbench extends React.Component { ...@@ -361,7 +366,7 @@ class ExperimentWorkbench extends React.Component {
await this.setSimulationState(newState).then(() => { await this.setSimulationState(newState).then(() => {
if (this.state.simulationState === EXPERIMENT_STATE.STOPPED) { if (this.state.simulationState === EXPERIMENT_STATE.STOPPED) {
this.setState({ runningSimulationID: undefined }); this.setState({ runningSimulationID: undefined });
ExperimentWorkbenchService.instance.simulationID = undefined; ExperimentWorkbenchService.instance.simulationInfo = undefined;
} }
}); });
} }
...@@ -379,8 +384,8 @@ class ExperimentWorkbench extends React.Component { ...@@ -379,8 +384,8 @@ class ExperimentWorkbench extends React.Component {
if (simInfo.state === EXPERIMENT_STATE.STOPPED) { if (simInfo.state === EXPERIMENT_STATE.STOPPED) {
this.setState({ simulationState: simInfo.state }); this.setState({ simulationState: simInfo.state });
this.setState({ simStateLoading: false }); this.setState({ simStateLoading: false });
// clear simulationID for the finilized experiments // clear simulationInfo for the finilized experiments
ExperimentWorkbenchService.instance.simulationID = undefined; ExperimentWorkbenchService.instance.simulationInfo = undefined;
this.setState({ runningSimulationID: undefined }); this.setState({ runningSimulationID: undefined });
} }
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment