-
Notifications
You must be signed in to change notification settings - Fork 1
/
auto_client.py
74 lines (61 loc) · 3.02 KB
/
auto_client.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
import time, requests, pickle
from datetime import datetime
from repcl import RepCl
from veccl import VecCl
import numpy as np
masterURL = "http://localhost:5000"
replicaURL = "http://localhost:5001"
file = open("requests.txt", 'r')
req_num = 0
setNum = 1
repcl_time = RepCl(2, np.uint64(1), np.uint64(1))
veccl_time = VecCl(2, 3, 64)
for line in file.readlines() :
req_num += 1
print(f"Request #{req_num} : ", end = "")
# alternating receiver node every 4 requests
if (req_num % 2 == 0) :
setNum += 1
# Extracting parameters from the read/write request
vals = line.split()
method = vals[0]
if method == "POST" :
print("post\n")
send_data = vals[1]
# checking whether to send to master/replica
if (setNum % 2 == 1) :
repcl_time.send_local()
veccl_time.advance()
requests.post(masterURL, params = {"data" : send_data},
files = {"repcl_time" : pickle.dumps(repcl_time),
"veccl_time" : pickle.dumps(veccl_time)})
else :
requests.post(replicaURL, params = {"data" : send_data},
files = {"repcl_time" : pickle.dumps(repcl_time),
"veccl_time" : pickle.dumps(veccl_time)})
elif method == 'GET' :
type = vals[1]
key = vals[2]
print(f"{type}\n")
if type == 'get' :
if (setNum % 2 == 1) :
requests.get(masterURL, params = {"uuid_key" : key, "type" : type}, files = {"repcl_time" : pickle.dumps(repcl_time), "veccl_time" : pickle.dumps(veccl_time)})
else :
requests.get(replicaURL, params = {"uuid_key" : key, "type" : type}, files = {"repcl_time" : pickle.dumps(repcl_time), "veccl_time" : pickle.dumps(veccl_time)})
elif type == 'put' :
new_val = vals[3]
if (setNum % 2 == 1) :
requests.get(masterURL, params = {"uuid_key" : key, "type" : type, "new_val" : new_val}, files = {"repcl_time" : pickle.dumps(repcl_time), "veccl_time" : pickle.dumps(veccl_time)})
else :
requests.get(replicaURL, params = {"uuid_key" : key, "type" : type, "new_val" : new_val}, files = {"repcl_time" : pickle.dumps(repcl_time), "veccl_time" : pickle.dumps(veccl_time)})
elif type == 'delete' :
if (setNum % 2 == 1) :
requests.get(masterURL, params ={'type' : type, 'uuid_key': key}, files = {"repcl_time" : pickle.dumps(repcl_time), "veccl_time" : pickle.dumps(veccl_time)})
else :
requests.get(replicaURL, params ={'type' : type, 'uuid_key': key}, files = {"repcl_time" : pickle.dumps(repcl_time), "veccl_time" : pickle.dumps(veccl_time)})
# syncing every 2 requests
if (req_num % 2 == 0) :
print("Syncing now....")
response = requests.get(masterURL, params = {'uuid_key' : None, 'type' : 'sync'})
print(f"Sync response : {response}")
print("Executed all requests!")