-
Notifications
You must be signed in to change notification settings - Fork 0
/
single_node_server.py
64 lines (45 loc) · 1.69 KB
/
single_node_server.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
import os
from argparse import ArgumentParser
from thunderdb import thunderdb
def get_argument_parser():
"""Configures a parser for command-line arguments
Returns:
ArgumentParser: Built-in parser for command-line options, arguments
"""
parser = ArgumentParser(description='The CLI for our key-value server for immutable data')
parser.add_argument('-d', '--data',
required=True,
help="Path to the file which contains the key-value pairs you want to load")
return parser
def parse_arguments():
"""Parses command line arguments, returning options and a list of tasks
Returns:
Namespace: Simple class used by default by parse_args() to create an
object holding attributes and return it
"""
parser = get_argument_parser()
arguments = parser.parse_args()
for error in validate_arguments(arguments):
parser.error(error)
return arguments
def validate_arguments(arguments):
"""Validates that all the arguments are valid
Yields:
Errors, if any
"""
if not os.path.exists(arguments.data) or not os.path.isfile(arguments.data):
yield "The data file you provided does not exist..."
return
def local_mode(data_file):
"""Run the key-value store on a single node in local mode (on your local machine, not in docker)
"""
os.environ['NODE_ID'] = "0"
os.environ['NODE_IP'] = "localhost"
os.environ['NEXT_NODE_ID'] = "0"
os.environ['NEXT_NODE_IP'] = "localhost"
os.environ['DATA_FILE'] = data_file
thunderdb.main()
def main(arguments):
local_mode(arguments.data)
if __name__ == "__main__":
main(parse_arguments())