-
Notifications
You must be signed in to change notification settings - Fork 0
/
startClient.py
executable file
·88 lines (78 loc) · 2.67 KB
/
startClient.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from mencius.client import Client as MenciusClient
from simple.client import Client as SimpleClient
from multipaxos.client import Client as MultipaxosClient
from mencius_physical_time.client import Client as RobustMenciusClient
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 client"
)
parser.add_argument(
"-t", "--type", type=str, required=True, help="The type of the client"
)
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 client"
)
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, mode="w")
fh.setLevel(args.debug)
logger.addHandler(fh)
config = getattr(Configs(), args.config)()
match args.type:
case "mencius":
client = MenciusClient(args.name, config=config, logger=logger)
case "simple":
client = SimpleClient(args.name, config=config, logger=logger)
case "multipaxos":
client = MultipaxosClient(args.name, config=config, logger=logger)
case "robust_mencius":
client = RobustMenciusClient(args.name, config=config, logger=logger)
case _:
raise ValueError("Invalid type")
client.start_node()
server = config[args.name]["publish"][0][0]
for i in range(Configs.WORKLOAD_SIZE):
client.send_request(
{
"type": "PUT",
"key": f"{args.name}",
"value": i,
},
server,
)
client.send_request(
{
"type": "GET",
"key": f"{args.name}",
},
server,
)
logger.info("Client %s has finished", args.name)
if __name__ == "__main__":
main()