-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.sh
99 lines (94 loc) · 3.58 KB
/
client.sh
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
89
90
91
92
93
94
95
96
97
98
99
while true; do
# Take input from user, for add or remove servers
echo -n "Enter home/rep/add/rm/init/status/exit/: "
read action
# Check if action is add or rm (case insensitive)
if [ "${action,,}" == "add" ]; then
echo -n "Enter number of servers to add: "
read n
echo -n "Enter hostnames of servers to add (seperated by spaces): "
read -a hostnames
# Check if hostnames are valid
for hostname in "${hostnames[@]}"
do
if [[ ! $hostname =~ ^[a-zA-Z0-9_@-]+$ ]]; then
echo "Invalid hostname"
fi
done
# Check if number of servers is valid
if [ $n -lt 0 ]; then
echo "Invalid number of servers"
fi
# hostname_string="[\"$(IFS='","'; echo "${hostnames[*]}")\"]"
hostname_string=""
for element in "${hostnames[@]}"; do
hostname_string+="\"$element\","
done
hostname_string="${hostname_string%,}" # Remove trailing comma
# hostname_string+="]"
# echo $hostname_string
# echo $n
# Send request to server with hostnames and number of servers
curl -X POST \
-H "Content-type: application/json" \
-d "{\"n\":$n, \"hostnames\": [$hostname_string]}" \
"http://0.0.0.0:5000/add"
echo ""
elif [ "${action,,}" == "rm" ]; then
echo -n "Enter number of servers to remove: "
read n
echo -n "Enter hostnames of servers to remove (seperated by spaces): "
read -a hostnames
# Check if hostnames are valid
for hostname in "${hostnames[@]}"
do
if [[ ! $hostname =~ ^[a-zA-Z0-9_@-]+$ ]]; then
echo "Invalid hostname"
fi
done
# Check if number of servers is valid
if [ $n -lt 0 ]; then
echo "Invalid number of servers"
fi
hostname_string=""
for element in "${hostnames[@]}"; do
hostname_string+="\"$element\","
done
hostname_string="${hostname_string%,}" # Remove trailing comma
# hostname_string+="]"
# echo $hostname_string
# Send request to server
curl -X DELETE \
-H "Content-type: application/json" \
-d "{\"n\":$n, \"hostnames\": [$hostname_string]}" \
"http://0.0.0.0:5000/rm"
echo ""
elif [ "${action,,}" == "init" ]; then
# -d "{\"N\":3,
# \"schema\":{\"columns\":[\"Stud_id\",\"Stud_name\",\"Stud_marks\"],
# \"dtypes\":[\"Number\",\"String\",\"String\"]}
# \"shards\":[{\"Stud_id_low\":0, \"Shard_id\": \"sh1\", \"Shard_size\":4096},
# {\"Stud_id_low\":4096, \"Shard_id\": \"sh2\", \"Shard_size\":4096},
# {\"Stud_id_low\":8192, \"Shard_id\": \"sh3\", \"Shard_size\":4096},]
# \"servers\":{\"Server0\":[\"sh1\",\"sh2\"],
# \"Server1\":[\"sh2\",\"sh3\"],
# \"Server2\":[\"sh1\",\"sh3\"]}
# }" \
curl -X POST \
-H "Content-type: application/json" \
-d '{ "N":3, "schema":{"columns":["Stud_id","Stud_name","Stud_marks"],"dtypes":["Number","String","String"]}, "shards":[{"Stud_id_low":0, "Shard_id": "sh1", "Shard_size":4096}, {"Stud_id_low":4096, "Shard_id": "sh2", "Shard_size":4096}, {"Stud_id_low":8192, "Shard_id": "sh3", "Shard_size":4096}], "servers":{"Server0":["sh1","sh2"],"Server1":["sh2","sh3"],"Server2":["sh1","sh3"]}}' \
"http://0.0.0.0:5000/init"
echo ""
elif [ "${action,,}" == "status" ]; then
curl -X GET "http://0.0.0.0:5000/status"
echo ""
elif [ "${action,,}" == "rep" ]; then
curl -X GET "http://0.0.0.0:5000/rep"
echo ""
elif [ "${action,,}" == "exit" ]; then
break
else
echo "Invalid action"
fi
done
exit 0