Skip to content

Commit aba0eba

Browse files
committed
hotfix: Reorder topology loading in scenario data to prevent overwrites by event handlers.
1 parent 3e2e310 commit aba0eba

1 file changed

Lines changed: 29 additions & 26 deletions

File tree

nebula/frontend/static/js/deployment/scenario.js

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Scenario Management Module
2-
const ScenarioManager = (function() {
2+
const ScenarioManager = (function () {
33
let scenariosList = [];
44
let actual_scenario = 0;
5-
let physical_ips = [];
5+
let physical_ips = [];
66

77
// Initialize scenarios from session storage
88
function initializeScenarios() {
@@ -151,28 +151,7 @@ const ScenarioManager = (function() {
151151
document.getElementById("rounds").value = scenario.rounds;
152152

153153
// Load topology
154-
if (scenario.nodes && scenario.nodes_graph) {
155-
const topologyData = {
156-
nodes: Object.values(scenario.nodes),
157-
links: []
158-
};
159-
160-
// Reconstruct links from the nodes' neighbors
161-
topologyData.nodes.forEach(node => {
162-
if (node.neighbors) {
163-
node.neighbors.forEach(neighborId => {
164-
topologyData.links.push({
165-
source: node.id,
166-
target: neighborId
167-
});
168-
});
169-
}
170-
});
171154

172-
window.TopologyManager.setData(topologyData);
173-
} else {
174-
window.TopologyManager.generatePredefinedTopology();
175-
}
176155

177156
/* if "physical" assign the IPs again*/
178157
if (scenario.physical_ips) {
@@ -247,6 +226,30 @@ const ScenarioManager = (function() {
247226
document.getElementById("federationArchitecture").dispatchEvent(new Event('change'));
248227
document.getElementById("datasetSelect").dispatchEvent(new Event('change'));
249228
document.getElementById("iidSelect").dispatchEvent(new Event('change'));
229+
230+
// Load topology last to avoid overwrites by event handlers
231+
if (scenario.nodes && scenario.nodes_graph) {
232+
const topologyData = {
233+
nodes: Object.values(scenario.nodes),
234+
links: []
235+
};
236+
237+
// Reconstruct links from the nodes' neighbors
238+
topologyData.nodes.forEach(node => {
239+
if (node.neighbors) {
240+
node.neighbors.forEach(neighborId => {
241+
topologyData.links.push({
242+
source: node.id,
243+
target: neighborId
244+
});
245+
});
246+
}
247+
});
248+
249+
window.TopologyManager.setData(topologyData);
250+
} else {
251+
window.TopologyManager.generatePredefinedTopology();
252+
}
250253
}
251254

252255
function saveScenario() {
@@ -353,16 +356,16 @@ const ScenarioManager = (function() {
353356
function setPhysicalIPs(ipList = []) {
354357
physical_ips = [...ipList];
355358
}
356-
359+
357360
function setActualScenario(index) {
358361
actual_scenario = index;
359362
if (scenariosList[index]) {
360363
// Clear the current graph
361364
window.TopologyManager.clearGraph();
362-
365+
363366
// Load new scenario data
364367
loadScenarioData(scenariosList[index]);
365-
368+
366369
// If physical deployment, set physical IPs
367370
if (scenariosList[index].deployment === 'physical' && scenariosList[index].physical_ips) {
368371
window.TopologyManager.setPhysicalIPs(scenariosList[index].physical_ips);

0 commit comments

Comments
 (0)