def process(udp_clients): hash_codes = set() # PUT all users. for u in USERS: data_bytes, key = serialize_PUT(u) ring = NodeRing(NODES) server_index = NODES.index(ring.get_node(key)) response = udp_clients[server_index].put(key, data_bytes) hash_codes.add(response.decode()) print(response) print( f"Number of Users={len(USERS)}\nNumber of Users Cached={len(hash_codes)}" ) # GET all users. for hc in hash_codes: print(hc) data_bytes, key = serialize_GET(hc) ring = NodeRing(NODES) server_index = NODES.index(ring.get_node(key)) response = udp_clients[server_index].get_request(hc, data_bytes) print(response) # Delete all Users for hc in hash_codes: print(hc) data_bytes, key = serialize_DELETE(hc) ring = NodeRing(NODES) server_index = NODES.index(ring.get_node(key)) response = udp_clients[server_index].delete(key, data_bytes) print(response)
def process(udp_clients): udp_client = udp_clients hash_codes = set() client_ring = NodeRing(udp_client) # PUT all users. for u in USERS: data_bytes, key = serialize_PUT(u) response = put(key, data_bytes, client_ring) hash_codes.add(response) print(hash_codes) print( f"Number of Users={len(USERS)}\nNumber of Users Cached={len(hash_codes)}" ) for hc in hash_codes: # print(hc) data_bytes, key = serialize_GET(hc) response = get(key, data_bytes, client_ring) # print(response) for hc in hash_codes: data_bytes, key = serialize_DELETE(hc) print("keys from DELETE OPERATAIONS:", data_bytes, key) response = delete(key, data_bytes, client_ring) print(response)
def process(udp_clients): client_ring = NodeRing(NODES) hash_codes = set() # PUT all users. for u in USERS: data_bytes, key = serialize_PUT(u) put(key, u) server = client_ring.get_node(key) response = udp_clients.send(data_bytes, server) print(response) hash_codes.add(str(response.decode())) print( f"Number of Users={len(USERS)}\nNumber of Users Cached={len(hash_codes)}" ) # GET all users. for hc in hash_codes: print(hc) data_bytes, key = serialize_GET(hc) response = get(key) if not (response): server = client_ring.get_node(key) response = udp_clients.send(data_bytes, server) print(response)
def process(udp_clients): client_ring = NodeRing(udp_clients) hash_codes = set() # PUT all users. for u in USERS: data_bytes, key = serialize_PUT(u) response = put([key, data_bytes, client_ring]) print(response) hash_codes.add(str(response.decode())) print(f"Number of Users={len(USERS)}\nNumber of Users Cached={len(hash_codes)}") # GET all users for u in USERS: data_bytes, key = serialize_GET(u) response = get([key, data_bytes, client_ring]) print(response) # DELETE all users. for u in USERS: data_bytes, key = serialize_DELETE(u) response = delete([key, data_bytes, client_ring]) print(response)
def process(udp_clients): ring = NodeRing(nodes=NODES) hash_codes = set() # PUT all users. for u in USERS: data_bytes, key = serialize_PUT(u) # TODO: PART II - Instead of going to server 0, use Naive hashing to split data into multiple servers #fix_me_server_id = 0 fix_me_server_id = NODES.index(ring.get_node(key)) print(f"Server id: {fix_me_server_id}") response = udp_clients[fix_me_server_id].send(data_bytes) hash_codes.add(response) print(response) print( f"Number of Users={len(USERS)}\nNumber of Users Cached={len(hash_codes)}" ) # TODO: PART I # GET all users. for hc in hash_codes: print(f"GET:{hc}") data_bytes, key = serialize_GET(hc) fix_me_server_id = NODES.index(ring.get_node(key)) response = udp_clients[fix_me_server_id].send(data_bytes) #print(deserialize(response)) print(response) # DELETE all users for hc in hash_codes: # print(hc) data_bytes, key = serialize_DELETE(hc) fix_me_server_id = NODES.index(ring.get_node(key)) response = udp_clients[fix_me_server_id].send(data_bytes) print(response)
def process(udp_clients): client_ring = NodeRing(udp_clients) hash_codes = set() # PUT all users. for u in USERS: data_bytes, key = serialize_PUT(u) response = client_ring.get_node(key).send(data_bytes) print(response) hash_codes.add(str(response.decode())) print( f"Number of Users={len(USERS)}\nNumber of Users Cached={len(hash_codes)}" ) # GET all users. for hc in hash_codes: print(hc) data_bytes, key = serialize_GET(hc) response = client_ring.get_node(key).send(data_bytes) print(response) #DELETE for hc in hash_codes: data_bytes, key = serialize_DELETE(hc) response = client_ring.get_node(key).send(data_bytes) print(response) print("success")
def put(udp_clients,obj): client_ring = NodeRing(udp_clients) global bloomfilter data_bytes, key = serialize_PUT(obj) bloomfilter.add(key) response = client_ring.get_node(key).send(data_bytes) return str(response.decode())
def process(udp_clients): client_ring = NodeRing(udp_clients) hash_codes = set() # PUT all users. for u in USERS: data_bytes, key = serialize_PUT(u) get_ch_node = client_ring.get_ch_node(key) response = get_ch_node.send(data_bytes) replica = replica_map[get_ch_node] print("Replicating in next node") replica.send(data_bytes) print(response) hash_codes.add(str(response.decode())) print( f"Number of Users={len(USERS)}\nNumber of Users Cached={len(hash_codes)}" ) # GET all users. for hc in hash_codes: print(hc) data_bytes, key = serialize_GET(hc) get_ch_node = client_ring.get_ch_node(key) response = get_ch_node.send(data_bytes) replica = replica_map[get_ch_node] print("Response from corresponding node") print(response) print("Getting response from replica node") rep_response = replica.send(data_bytes) print(rep_response)
def process(udp_clients): client_ring = NodeRing(udp_clients) # weightList = [500,501,502,503] # seedList = [100, 200, 300, 400] # client_ring = NodeRing(udp_clients,mode='Rendezvous Hashing',weights=weightList, seeds=seedList) hash_codes = set() # PUT all users. for u in USERS: response = put(u, client_ring) print(response) hash_codes.add(str(response.decode())) print( f"Number of Users={len(USERS)}\nNumber of Users Cached={len(hash_codes)}" ) # GET all users. for i in range(0, 3): for hc in hash_codes: print(hc) response = get(hc, client_ring) print(response) for hc in hash_codes: out = delete(hc, client_ring) print(out) for hc in hash_codes: print(hc) response = get(hc, client_ring) print(response)
def process(udp_clients): # create client ring of the udp client, actually the server sockets they connect to client_ring = NodeRing(udp_clients) hash_codes = set() # PUT all users. for u in USERS: # serialize the user data data_bytes, key = serialize_PUT(u) # first find out the nodes by the key, then send the data by that client response = client_ring.get_node(key).send(data_bytes) print(response) # add the response, hash_codes.add(str(response.decode())) print( f"Number of Users={len(USERS)}\nNumber of Users Cached={len(hash_codes)}" ) # GET all users. for hc in hash_codes: data_bytes, key = serialize_GET(hc) response = client_ring.get_node(key).send(data_bytes) print(response) # delete for hc in hash_codes: data_bytes, key = serialize_DELETE(hc) response = client_ring.get_node(key).send(data_bytes) print(response)
def process(udp_clients): client_ring = NodeRing(udp_clients) hash_codes = set() # PUT all users. for u in USERS: data_bytes, key = serialize_PUT(u) bloomfilter.add(key) response = client_ring.get_node(key).send(data_bytes) print(response) hash_codes.add(str(response.decode())) print(f"Number of Users={len(USERS)}\nNumber of Users Cached={len(hash_codes)}") # GET all users. for hc in hash_codes: print(hc) data_bytes, key = serialize_GET(hc) if bloomfilter.is_member(key): response = client_ring.get_node(key).send(data_bytes) else: return None print(response) # DELETE all users. for hc in hash_codes: print(hc) data_bytes, key = serialize_DELETE(hc) if bloomfilter.is_member(key): response = client_ring.get_node(key).send(data_bytes) else: return None print(response)
def process(udp_clients, seed, weight): client_ring = NodeRing(udp_clients, seed, weight) client_ring = ConsistentHashing(udp_clients) hash_codes = set() # PUT all users. for u in USERS: data_bytes, key = serialize_PUT(u) response = client_ring.get_node(key).send(data_bytes) print(response) hash_codes.add(str(response.decode())) print( f"Number of Users={len(USERS)}\nNumber of Users Cached={len(hash_codes)}" ) # # GET all users # for u in USERS: # data_bytes, key = serialize_GET(u) # response = client_ring.get_node(key).send(data_bytes) # print(response) # # DELETE all users. # for u in USERS: # data_bytes, key = serialize_DELETE(u) # response = client_ring.get_node(key).send(data_bytes) # print(response) LB = client_ring.load_balanced() for index in LB: print(LB[index])
def process(udp_clients): client_ring = NodeRing(udp_clients) hash_codes = set() # PUT all users. for u in USERS: data_bytes, key = serialize_PUT(u) put(key, data_bytes) response = client_ring.get_node(key).send(data_bytes) print(response) hash_codes.add(str(response.decode())) print( f"Number of Users={len(USERS)}\nNumber of Users Cached={len(hash_codes)}" ) # GET all users. for hc in hash_codes: data_bytes, key = get(hc) if key is None: if data_bytes is None: response = None else: response = data_bytes else: response = client_ring.get_node(key).send(data_bytes) lru_cache_put(key, data_bytes) print(response) for hc in hash_codes: data_bytes, key = delete(hc) if data_bytes is not None: response = client_ring.get_node(key).send(data_bytes) else: response = "Key not Present" print(response)
def process(udp_clients): client_ring = NodeRing(udp_clients) hash_codes = set() # PUT all users. for u in USERS: response = put(u, client_ring) print(response) hash_codes.add(str(response.decode())) print( f"Number of Users={len(USERS)}\nNumber of Users Cached={len(hash_codes)}" ) # GET all users. for hc in hash_codes: print(hc) response = get(hc, client_ring) print(response) # DELETE all users for hc in hash_codes: print(hc) response = delete(hc, client_ring) print(response)
def put(self, udp_clients, key, data_bytes): # PUT all users. ring = NodeRing(NODES) fix_me_server_id = NODES.index(ring.get_node(key)) response = udp_clients[fix_me_server_id].send(data_bytes) hash_codes.add(response) print(f"Server--->Number of Users Cached={len(hash_codes)}") return "hi"
def delete(self, key): client_ring = NodeRing(NODES) data_bytes, key = serialize_DELETE(key) server = client_ring.get_node(key) udp_client.host = server['host'] udp_client.port = server['port'] response = udp_client.send(data_bytes) return response
def put(key, value): bloomfilter.add(key) client_ring = NodeRing(clients) data_bytes, key1 = serialize_PUT(value) response = client_ring.get_node(key1).send(data_bytes) print(response) hash_codes.add(str(response.decode())) return response
def delete(udp_clients,id): client_ring = NodeRing(udp_clients) data_bytes, key = serialize_DELETE(id) global bloomfilter if not bloomfilter.is_member(key): print("Not found in bloom filter") return None response = client_ring.get_node(key).send(data_bytes) return response
def process_cons_hash(udp_clients): cons_hash('client-06', ["s1", "s2", "s3", "s4", "s5", "s6"]) print("parameter: ", udp_clients) client_ring = NodeRing(udp_clients) servers = ["s1", "s2", "s3", "s4"] cons_hash("client-01", ["s1", "s2", "s3", "s4"]) cons_hash("client-02", ["s1", "s2", "s3", "s4"]) cons_hash("client-03", ["s1", "s2", "s3", "s4"]) cons_hash("client-04", ["s1", "s2", "s3", "s4"])
def getAll(self, udp_clients): for hc in hash_codes: data_bytes, key = serialize_GET(hc) ring = NodeRing(NODES) fix_me_server_id = NODES.index(ring.get_node(key)) print(data_bytes) response = udp_clients[fix_me_server_id].send(data_bytes) print(f"Server GETALL--->{response}") return response
def put(key, value): global globalclient ring = NodeRing(nodes=NODES) node = ring.get_node(key) fix_me_server_id = node['port'] - 4000 #fix_me_server_id=0 response = globalclient[fix_me_server_id].send(value) bloomfilter.add(response) return response
def put(self, value): client_ring = NodeRing(NODES) data_bytes, key = serialize_PUT(value) server = client_ring.get_node(key) udp_client.host = server['host'] udp_client.port = server['port'] response = udp_client.send(data_bytes) return key
def get_users(hc): myOb = NodeRing(NODES) data_bytes, key = serialize_GET(hc) print(f'In GET {data_bytes},{key}') if bf.is_member(key): node = myOb.get_node(key) response = UDPClient(node['host'], node['port']).send(data_bytes) else: print("Data not in bloom filter and probably not in server") return response
def delete(key): if (bloomfilter.is_member(key)): data_bytes, key1 = serialize_DELETE(key) client_ring = NodeRing(clients) server_details = client_ring.get_node(key1) response = server_details.send(data_bytes) print(response) return response else: return None
def get(key): if (bloomfilter.is_member(key)): print("Found in bloom filter, fetching from server") data_bytes, key1 = serialize_GET(key) client_ring = NodeRing(clients) response = client_ring.get_node(key1).send(data_bytes) #print(response) return response else: return None
def get(self, udp_clients, key): k = key.encode() for hc in hash_codes: if (hc == k): data_bytes, key = serialize_GET(hc) ring = NodeRing(NODES) fix_me_server_id = NODES.index(ring.get_node(key)) response = udp_clients[fix_me_server_id].send(data_bytes) print(f"Server GET--->{response}") return response return None
def delete_users(hc): myOb = NodeRing(NODES) data_bytes, key = serialize_DELETE(hc) node = myOb.get_node(key) if bf.is_member(key): response = UDPClient(node['host'], node['port']).send(data_bytes) if (response.decode() == 'Success'): print('Deleted Succesfully') # bf.delete(key) else: print("Data not in bloom filter and probably not in server")
def delete(hc): global globalclient if bloomfilter.is_member(hc): data_bytes, key = serialize_DELETE(hc) ring = NodeRing(nodes=NODES) node = ring.get_node(key) fix_me_server_id = node['port'] - 4000 #fix_me_server_id=0 response = globalclient[fix_me_server_id].send(data_bytes) return response else: return None
def post_users(): hash_codes = set() myOb = NodeRing(NODES) # PUT all users. for u in USERS: data_bytes, key = serialize_PUT(u) # TODO: PART II - Instead of going to server 0, use Naive hashing to split data into multiple servers node = myOb.get_node(key) response = UDPClient(node['host'], node['port']).send(data_bytes) hash_codes.add(response) bf.add(response) return hash_codes
def delete(self, udp_clients, key): k = key.encode() for hc in hash_codes: print(hash_codes) if (hc == k): data_bytes, key = serialize_DELETE(hc) ring = NodeRing(NODES) fix_me_server_id = NODES.index(ring.get_node(key)) response = udp_clients[fix_me_server_id].send(data_bytes) hash_codes.remove(hc) #print(hash_codes) break print(f"Server DELETE--->Number of Users Cached={len(hash_codes)}")