-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
73 lines (51 loc) · 1.84 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import sys
import os
LOCAL_DIRECTORY = os.getcwd()
WEB_SERVICE = os.path.join(LOCAL_DIRECTORY, "webService")
sys.path.append(os.path.join(WEB_SERVICE, "pathsMethods"))
sys.path.append(os.path.join(WEB_SERVICE, "apiTypes"))
sys.path.append(os.path.join(LOCAL_DIRECTORY, "networking"))
###
import uvicorn
import argparse
from fastapi import FastAPI
from webService.apiReqInterpreter import ApiReqInterpret
from router import Router
from putRequests import SetEntry,SetEntries, DelGetEntry
from localAgent import LocalAgent
app = FastAPI()
@app.get("/")
async def read_root():
return Router.main()
@app.post("/putEntry")
async def putEntry(req: SetEntry):
resp = Router.setEntry(ApiReqInterpret.processPutEntry(req))
return resp
@app.post("/putEntries")
async def putEntries(req: SetEntries):
resp = Router.setEntries(ApiReqInterpret.processPutEntries(req))
return resp
@app.post("/getEntry")
async def getEntry(req: DelGetEntry):
return Router.getEntry(ApiReqInterpret.processDelGetEntry(req))
@app.delete("/delEntry")
async def delEntry(req: DelGetEntry):
return Router.delEntry(ApiReqInterpret.processDelGetEntry(req))
@app.on_event('shutdown')
def shutdown_event():
LocalAgent.closeServers()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--aport', type=int, required=True)
parser.add_argument('--gport', type=str, required=True)
parser.add_argument('--join', type=str, required=False)
args = parser.parse_args()
if args.join:
LocalAgent.joinNetwork(args.join)
# print(LocalAgent.__agent)
else:
LocalAgent.initNetwork(args.gport)
LocalAgent.showMe()
host = "localhost:{}".format(args.gport)
LocalAgent.serveGRPC(host)
uvicorn.run("main:app", host="0.0.0.0", port=args.aport, reload=True)