Skip to content

Commit

Permalink
Added Restore action
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseflorig committed Mar 16, 2023
1 parent 0c9dc07 commit 194bc36
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
15 changes: 11 additions & 4 deletions dashboard/src/msnActions.js
Original file line number Diff line number Diff line change
@@ -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
},
]
9 changes: 9 additions & 0 deletions dashboard/src/mxActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ function handleResetMission(send){
send('reset')
}

function handleRestoreMission(send){
send('restore')
}

export default [
{
label: "Build MX Data",
Expand All @@ -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
}
]
12 changes: 9 additions & 3 deletions msn-api-server/msn-api-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
21 changes: 15 additions & 6 deletions mx-api-server/mx-api-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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}")
Expand All @@ -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
Expand Down

0 comments on commit 194bc36

Please sign in to comment.