-
Notifications
You must be signed in to change notification settings - Fork 0
/
startServer.py
executable file
·71 lines (63 loc) · 2.3 KB
/
startServer.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
from mencius.server import Server as MenciusServer
from multipaxos.server import Server as MultipaxosServer
from simple.server import Server as SimpleServer
from mencius_physical_time.server import Server as RobustMenciusServer
from config import Configs
import argparse
import logging
import os
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"-n", "--name", type=str, required=True, help="The name of the server"
)
parser.add_argument(
"-t", "--type", type=str, required=True, help="The type of the server"
)
parser.add_argument(
"-c", "--config", type=str, required=False, help="The config"
)
parser.add_argument(
"-g", "--debug", type=str, required=False, help="The name of the server"
)
parser.add_argument(
"-l", "--log", type=str, required=False, help="The name of the file to log to"
)
args = parser.parse_args()
match args.debug:
case "DEBUG":
logging.basicConfig(level=logging.DEBUG)
case "INFO":
logging.basicConfig(level=logging.INFO)
case "WARNING":
logging.basicConfig(level=logging.WARNING)
case "ERROR":
logging.basicConfig(level=logging.ERROR)
case "CRITICAL":
logging.basicConfig(level=logging.CRITICAL)
case _:
raise ValueError("Invalid debug level")
logger = logging.getLogger()
if args.log:
os.makedirs(os.path.dirname(args.log), exist_ok=True)
fh = logging.FileHandler(args.log)
logger.addHandler(fh)
config = getattr(Configs(), args.config)()
servers = []
for k in config:
if k.startswith("server"):
servers.append(k)
match args.type:
case "mencius":
server = MenciusServer(args.name, config=config, logger=logger, servers=servers)
case "simple":
server = SimpleServer(args.name, config=config, logger=logger)
case "multipaxos":
server = MultipaxosServer(args.name, config=config, logger=logger, servers=servers)
case "robust_mencius":
server = RobustMenciusServer(args.name, config=config, logger=logger, servers=servers)
case _:
raise ValueError("Invalid type")
server.start_node()
if __name__ == "__main__":
main()