diff --git a/dashboard/src/msnActions.js b/dashboard/src/msnActions.js index de800d9..1d2c482 100644 --- a/dashboard/src/msnActions.js +++ b/dashboard/src/msnActions.js @@ -1,23 +1,30 @@ function handleBuildATO(send){ - // Send post fetch to mission server send('build') } function handlePublishATO(send){ - // Fetch mission server from dashboard send('publish') } +function handleRestoreMsnData(send){ + send('restore') +} + export default [ { label: "Build ATO", - desc: "", + desc: "MSN API Server will build the ATO", handler: handleBuildATO }, { label: "Publish ATO", - desc: "", + desc: "MSN API Server will publish the ATO to the MSN Dashboard", handler: handlePublishATO }, + { + label: "Restore ATO Data", + desc: "MSN Data Servers will overwrite MSN Data with backup data", + handler: handleRestoreMsnData + }, ] diff --git a/dashboard/src/mxActions.js b/dashboard/src/mxActions.js index ad02f2f..ca5f02b 100644 --- a/dashboard/src/mxActions.js +++ b/dashboard/src/mxActions.js @@ -15,6 +15,10 @@ function handleResetMission(send){ send('reset') } +function handleRestoreMission(send){ + send('restore') +} + export default [ { label: "Build MX Data", @@ -35,5 +39,10 @@ export default [ label: "Reset MX Data", desc: "MX API Server will clear the msn data file", handler: handleResetMission + }, + { + label: "Restore MX Data", + desc: "MX Data Server will overwrite msn data with backup data", + handler: handleRestoreMission } ] diff --git a/msn-api-server/msn-api-server.py b/msn-api-server/msn-api-server.py index c070372..3018e9a 100644 --- a/msn-api-server/msn-api-server.py +++ b/msn-api-server/msn-api-server.py @@ -39,8 +39,12 @@ def build_msn_data(path='/'): msn_data_file.write(json.dumps(data)) msn_data_file.close() - websockets.broadcast(connections['/msn-controller'], "{'build': true}") + websockets.broadcast(connections['/msn-controller'], "Built mission data on MSN API Server") +def restore_msn_data(): + for idx, data_server in enumerate(DATA_SERVERS): + urlopen(f"{data_server}/restore") + websockets.broadcast(connections['/msn-controller'], "Restored MSN Data on MSN Data Servers") async def socket_handler(websocket, path): # Register connection @@ -54,17 +58,19 @@ async def socket_handler(websocket, path): with open(MSN_DATA_FILE) as file: data = json.load(file) websockets.broadcast(connections['/msn-dashboard'], json.dumps(data)) - websockets.broadcast(connections['/msn-controller'], "{'publish': true}") + websockets.broadcast(connections['/msn-controller'], "Published mission data to MSN Dashboard") file.close() elif message == "build": build_msn_data() elif message == "return": build_msn_data('/return') + elif message == "restore": + restore_msn_data() elif message == "reset": with open(MSN_DATA_FILE, 'w') as msn_data_file: msn_data_file.write(f"[]") msn_data_file.close() - websockets.broadcast(connections['/msn-controller'], "{'reset': true}") + websockets.broadcast(connections['/msn-controller'], "Reset mission data on MSN API Server") finally: # Unregister connection diff --git a/mx-api-server/mx-api-server.py b/mx-api-server/mx-api-server.py index 0b885fb..21624b3 100644 --- a/mx-api-server/mx-api-server.py +++ b/mx-api-server/mx-api-server.py @@ -20,7 +20,8 @@ '/mx-dashboard': set() } -def build_msn_data(path='/'): +# Build MX data from data servers; Path determines source file to build from +def build_mx_data(path='/'): with open(MSN_DATA_FILE, 'w') as msn_data_file: msn_data_file.write(f"[\n") for idx, data_server in enumerate(DATA_SERVERS): @@ -31,13 +32,19 @@ def build_msn_data(path='/'): msn_data_file.write(f"{content},\n") msn_data_file.write(f"]\n") msn_data_file.close() - websockets.broadcast(connections['/mx-controller'], "{'build': true}") + websockets.broadcast(connections['/mx-controller'], "Built MX Data on MX API Server") +# Send GET to all data servers on the restore path +def restore_mx_data(): + for idx, data_server in enumerate(DATA_SERVERS): + content = urlopen(f"{data_server}/restore") + websockets.broadcast(connections['/mx-controller'], "Restored MX Data on MX Data Servers") async def socket_handler(websocket, path): # Register connection connections[path].add(websocket) + # Handle websocket messages try: async for message in websocket: print(f"Received message: {message}") @@ -46,17 +53,19 @@ async def socket_handler(websocket, path): with open(MSN_DATA_FILE) as file: data = json.load(file) websockets.broadcast(connections['/mx-dashboard'], json.dumps(data)) - websockets.broadcast(connections['/mx-controller'], "{'publish': true}") + websockets.broadcast(connections['/mx-controller'], "Published MX Data to MX Dashboard") file.close() elif message == "build": - build_msn_data() + build_mx_data() elif message == "return": - build_msn_data('/return') + build_mx_data("/return") + elif message == "restore": + restore_mx_data() elif message == "reset": with open(MSN_DATA_FILE, 'w') as msn_data_file: msn_data_file.write(f"[]") msn_data_file.close() - websockets.broadcast(connections['/mx-controller'], "{'reset': true}") + websockets.broadcast(connections['/mx-controller'], "Reset MX Data on MX API Server") finally: # Unregister connection