-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_infra.py
44 lines (34 loc) · 1.25 KB
/
setup_infra.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
import logging
import subprocess
from lvcloud.gateway.gateway import Gateway
logging.basicConfig(format='%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s',
datefmt='%Y-%m-%d:%H:%M:%S', level=logging.INFO)
def generate_local_clusters(n, k=3):
'''
n: Number of Raft clusters to utilize in database
k: Number of nodes per raft cluster
'''
clusters = []
port = 5001
host = 'localhost'
for _ in range(n):
cluster = []
for _ in range(k):
node = host + ':' + str(port)
cluster.append(node)
port += 1
clusters.append(cluster)
return clusters
clusters = generate_local_clusters(2, k=3)
procs = []
for cluster in clusters:
for node in cluster:
process = subprocess.Popen(['python3', 'launch_db_node.py', 'http://localhost:8000', node] + [j for j in cluster if j != node],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, bufsize=0)
logging.info(f'Starting up node: {node} with process id: {process.pid}')
procs.append(process)
gateway = Gateway(clusters, port = 8000)
gateway.run()
for process in procs:
logging.info(f"terminating process: {process}")
process.terminate()