Skip to content

Commit 5b2aa82

Browse files
updating
1 parent 59b0b17 commit 5b2aa82

File tree

7 files changed

+127
-57
lines changed

7 files changed

+127
-57
lines changed

client/client.py

+35-8
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,12 @@ def update_handler(self):
8080
self.processing = tree["processing"]
8181
# update on GUI
8282

83+
# self._update_canvas()
8384
for filename in file_written: #populate listbox again
8485
self.listbox.insert(END, filename)
85-
tk.mainloop()
86+
# listbox.insert(END, percent)
87+
self.listbox.update_idletasks()
88+
# tk.mainloop()
8689
# self.window.mainloop()
8790
elif response["status"] == "NO_UPD":
8891
print(response["msg"])
@@ -91,13 +94,13 @@ def update_handler(self):
9194

9295
except Exception as e:
9396
s.close()
94-
print("Update failed")
97+
print("Update (write) from MDS failed")
9598
print(e)
9699
time.sleep(self.update_interval)
97100

98101

99102
finally:
100-
print("Exiting login..")
103+
101104
time.sleep(self.update_interval)
102105

103106

@@ -111,7 +114,7 @@ def upload(self, file_path):
111114

112115
if file_id < 0:
113116
return
114-
117+
115118
filename = os.path.basename(file_path)
116119
## send to OSD using sockets ; ask IP to monitor
117120
## using _write function
@@ -219,8 +222,16 @@ def _write(self, pg, pg_data):
219222

220223
_send_msg(s, msg)
221224
#s.send(d_msg)
222-
osd_dict = _wait_recv_msg(s, MSG_SIZE)
223-
print(osd_dict)
225+
res = _wait_recv_msg(s, MSG_SIZE)
226+
osd_dict = {}
227+
228+
if res["status"] == "SUCCESS":
229+
osd_dict = res["osd_dict"]
230+
231+
else:
232+
print(res["msg"])
233+
s.close()
234+
return -2
224235
# osd_dict = response["osd_dict"]
225236

226237
# print(osd_ips)
@@ -266,8 +277,10 @@ def _chunker(self, file_path):
266277
for d in self.dir_tree.keys():
267278
for file_id in self.dir_tree[d].keys():
268279
file_ids.append(file_id)
280+
file_id = 0
281+
if len(file_ids) > 0:
282+
file_id = max(file_ids)+1
269283

270-
file_id = max(file_ids)+1
271284
object_id = self.client_id+"_"+str(file_id)+"_OBJ"+str(0)
272285
object_index = 0
273286

@@ -353,6 +366,7 @@ def gui(self):
353366

354367
self.window.mainloop()
355368

369+
356370
def browseFiles(self):
357371
filename = filedialog.askopenfilename(initialdir = "/",
358372
title = "Select a File",
@@ -433,6 +447,16 @@ def _popup(self, title, msg):
433447
user = None
434448
passwd = None
435449

450+
def _popup(title, msg):
451+
print(title, msg)
452+
popup = tk.Toplevel()
453+
popup.wm_title(title)
454+
label = tk.Label(popup, text=msg)
455+
label.pack(fill='x', padx=50, pady=5)
456+
B1 = tk.Button(popup, text="Okay", command = popup.destroy)
457+
B1.pack()
458+
popup.mainloop()
459+
436460
def LoginPage():
437461
global user, passwd, login_screen
438462
login_screen=tk.Tk()
@@ -493,12 +517,15 @@ def login():
493517

494518

495519
elif response["status"] == "ERROR":
496-
print(response["msg"])
520+
# print(response["msg"])
521+
_popup("Login Failed", response["msg"])
497522

498523
except Exception as e:
499524
s.close()
525+
500526
print("[ERROR] login failed")
501527
print(e)
528+
_popup("Login Failed", response["msg"])
502529

503530
finally:
504531
print("Exiting login..")

monitor/cluster_topology

-222 Bytes
Binary file not shown.

monitor/hashtable

-1
This file was deleted.

monitor/init.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def main():
3030
1:
3131
{
3232
"ip":OSD_IPs[1],
33-
"port":1207,#READ_WRITE_PORT,
33+
"port":READ_WRITE_PORT,
3434
"free_space":1000,
3535
"status":0,
3636
"friends_update":False,
@@ -40,7 +40,7 @@ def main():
4040
2:
4141
{
4242
"ip":OSD_IPs[2],
43-
"port":1208,#READ_WRITE_PORT,
43+
"port":READ_WRITE_PORT,
4444
"free_space":1000,
4545
"status":0,
4646
"friends_update":False,
@@ -50,7 +50,7 @@ def main():
5050
3:
5151
{
5252
"ip":OSD_IPs[3],
53-
"port":1209,#READ_WRITE_PORT,
53+
"port":READ_WRITE_PORT,
5454
"free_space":1000,
5555
"status":0,
5656
"friends_update":False,
@@ -60,7 +60,7 @@ def main():
6060
4:
6161
{
6262
"ip":OSD_IPs[4],
63-
"port":1210,#READ_WRITE_PORT,
63+
"port":READ_WRITE_PORT,
6464
"free_space":1000,
6565
"status":0,
6666
"friends_update":False,

monitor/main.py

+83-40
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from transfer import _send_msg, _recv_msg, _wait_recv_msg
1717
from monitor_gossip import heartbeat_protocol
1818
from info import MDS_IPs, MDS_PORT, WRITE_ACK_PORT, OSD_INACTIVE_STATUS_PORT, CLIENT_REQ_PORT, \
19-
RECV_PRIMARY_UPDATE
19+
RECV_PRIMARY_UPDATE_PORT, MSG_SIZE
2020

2121
hashtable = {}
2222
MDS_flags = {}
@@ -28,42 +28,77 @@
2828
# osd_list = osd_ids list corresponding to pg_id, if update_type == "hashtable"
2929
# osd_data, else
3030
def update_backup_monitor(update_type, pg_or_osd_ids_list, osd_list):
31-
# if update_type == "hash_table":
32-
# for i in range(len(pg_or_osd_ids_list)):
33-
# hashtable[pg_or_osd_ids_list[i]] = osd_list[i]
34-
# else:
35-
# for i in range(len(pg_or_osd_ids_list)):
36-
# cluster_topology[pg_or_osd_ids_list[i]] = osd_list[i]
37-
pass
31+
primary_update_socket = socket.socket()
32+
print ("primary update socket successfully created")
33+
34+
try:
35+
primary_update_socket.connect((MDS_IPs["backup"], RECV_PRIMARY_UPDATE_PORT))
36+
msg = {"update_type": update_type, "pg_or_osd_ids_list": pg_or_osd_ids_list, \
37+
"osd_list": osd_list}
38+
_send_msg(primary_update_socket, msg)
39+
response = _wait_recv_msg(primary_update_socket, MSG_SIZE)
40+
primary_update_socket.close()
41+
if response["status"] == "SUCCESS":
42+
print("written to monitor backup successfully")
43+
else:
44+
print("write to monitor backup failed")
45+
except Exception as e:
46+
print(e)
47+
primary_update_socket.close()
3848

3949
def recv_primary_update():
40-
# recv_primary_update_socket = socket.socket()
41-
# print ("primary update socket successfully created")
42-
# recv_primary_update_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
43-
44-
# # reserve a port on your computer
45-
# port = RECV_PRIMARY_UPDATE
46-
47-
# # Next bind to the port
48-
# # we have not entered any ip in the ip field
49-
# # instead we have inputted an empty string
50-
# # this makes the server listen to requests
51-
# # coming from other computers on the network
52-
# recv_primary_update_socket.bind(('', port))
53-
# print ("primary update socket bound to %s" %(port))
54-
55-
# # put the socket into listening mode
56-
# recv_primary_update_socket.listen(5)
57-
# print ("socket is listening")
58-
59-
# # a forever loop until we interrupt it or
60-
# # an error occurs
61-
# while True:
62-
63-
# # Establish connection with osd
64-
# c, addr = recv_primary_update_socket.accept()
65-
# print ('Got connection from', addr)
66-
pass
50+
recv_primary_update_socket = socket.socket()
51+
print ("recv primary update socket successfully created")
52+
recv_primary_update_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
53+
54+
# reserve a port on your computer
55+
port = RECV_PRIMARY_UPDATE_PORT
56+
57+
# Next bind to the port
58+
# we have not entered any ip in the ip field
59+
# instead we have inputted an empty string
60+
# this makes the server listen to requests
61+
# coming from other computers on the network
62+
recv_primary_update_socket.bind(('', port))
63+
print ("primary update socket bound to %s" %(port))
64+
65+
# put the socket into listening mode
66+
recv_primary_update_socket.listen(5)
67+
print ("primary update socket is listening")
68+
69+
# a forever loop until we interrupt it or
70+
# an error occurs
71+
while True:
72+
73+
# Establish connection with osd
74+
c, addr = recv_primary_update_socket.accept()
75+
print ('Got connection from', addr)
76+
77+
# recv the update
78+
update = _recv_msg(c, 1024)
79+
print(update)
80+
81+
if update["update_type"] == "hash_table":
82+
for i in range(len(update["pg_or_osd_ids_list"])):
83+
hashtable[update["pg_or_osd_ids_list"][i]] = update["osd_list"][i]
84+
else:
85+
for i in range(len(update["pg_or_osd_ids_list"])):
86+
cluster_topology[update["pg_or_osd_ids_list"][i]] = update["osd_list"][i]
87+
88+
hashtable_file = open('hashtable', 'wb')
89+
hashtable_dump = pickle.dumps(hashtable)
90+
hashtable_file.write(hashtable_dump)
91+
hashtable_file.close()
92+
93+
cluster_topology_file = open('cluster_topology', 'wb')
94+
cluster_topology_dump = pickle.dumps(cluster_topology)
95+
cluster_topology_file.write(cluster_topology_dump)
96+
cluster_topology_file.close()
97+
98+
# send the acknowledgement
99+
c.close()
100+
101+
recv_primary_update_socket.close()
67102

68103
def recv_write_acks():
69104
global hashtable, cluster_topology, MDS_IP, MDS_flags
@@ -272,20 +307,28 @@ def recv_client_reqs():
272307

273308
i = 0
274309
for osd_id in cluster_topology:
275-
if cluster_topology[osd_id]["free_space"] > size:
310+
if cluster_topology[osd_id]["free_space"] > size and cluster_topology[osd_id]["status"] == 0:
276311
hashtable[pg_id].append([osd_id, 0])
277312
i = i+1
278313

279314
if(i>2):
280315
break
281-
316+
317+
if i < 3:
318+
print("less than two osds are free/alive")
319+
response = {"status":"ERROR", "msg": "sufficent storage not available"}
320+
_send_msg(c, response)
321+
c.close()
322+
continue
323+
324+
282325
osd_ids = [osd[0] for osd in hashtable[pg_id]]
283326

284327
addrs = {}
285328
for osd_id in osd_ids:
286329
addrs[osd_id] = (cluster_topology[osd_id]["ip"], cluster_topology[osd_id]["port"])
287-
osds_dict = {"osd_ids": osd_ids, "addrs": addrs}
288-
330+
osd_dict = {"osd_ids": osd_ids, "addrs": addrs}
331+
response = {"osd_dict": osd_dict, "status":"SUCCESS", "msg": "written succefully"}
289332
# updating the backup(only hash_table)
290333
# update_backup_monitor("hash_table", [pg_id], [hashtable[pg_id]])
291334

@@ -294,7 +337,7 @@ def recv_client_reqs():
294337
hashtable_file.write(hashtable_dump)
295338
hashtable_file.close()
296339

297-
_send_msg(c, osds_dict)
340+
_send_msg(c, response)
298341

299342
elif req["type"] == "READ":
300343
pg_id = req["pg_id"]

osd/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ def heartbeat_protocol():
2727

2828
def recv_client_reqs():
2929
global MY_OSD_ID
30+
3031
recv_client_reqs_socket = socket.socket()
3132
print("client reqs socket successfully created")
3233
recv_client_reqs_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
3334

3435
# reserve a port on your computer
35-
port = 1207#READ_WRITE_PORT
36+
port = READ_WRITE_PORT
3637

3738
# Next bind to the port
3839
# we have not entered any ip in the ip field

utils/info.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"""
99
# MDS
1010
MDS_PORT = 1201
11-
MDS_IPs = {"primary":{"ip":"127.0.0.1", "port":MDS_PORT}, "backup":{"ip":"127.0.0.1", "port":MDS_PORT+1}}
11+
MDS_IPs = {"primary":{"ip":"52.15.197.75", "port":MDS_PORT}, "backup":{"ip":"3.143.216.252", "port":MDS_PORT+1}}
1212

1313
num_objects_per_file = 1
1414

@@ -42,14 +42,14 @@
4242

4343
# OSD
4444

45-
OSD_IPs = {1:"127.0.0.1", 2:"127.0.0.1", 3:"127.0.0.1", 4:"1.5.6.8"}
45+
OSD_IPs = {1:"52.15.197.75", 2:"3.143.216.252", 3:"54.90.61.223", 4:"34.224.4.5"}
4646

4747
READ_WRITE_PORT = 1207
4848
HEARTBEAT_PORT = 1213
4949

5050

5151
# MONITOR
52-
MONITOR_IPs = {"primary": "127.0.0.1", "backup": "1.2.3.4"}
52+
MONITOR_IPs = {"primary": "34.224.4.5", "backup": "54.90.61.223"}
5353

5454
CLIENT_REQ_PORT = 1217
5555
WRITE_ACK_PORT = 1223

0 commit comments

Comments
 (0)