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)
Ejemplo n.º 2
0
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")
Ejemplo n.º 3
0
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 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())
Ejemplo n.º 5
0
 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
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
 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(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
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
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
Ejemplo n.º 14
0
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
Ejemplo n.º 15
0
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")
Ejemplo n.º 16
0
 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
Ejemplo n.º 17
0
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
Ejemplo n.º 18
0
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
Ejemplo n.º 19
0
def process():
    client_ring = NodeRing()
    hash_codes = set()
    # PUT all users.
    for u in USERS:
        data_bytes, key = serialize_PUT(u)
        server = client_ring.get_node(key)
        response = UDPClient().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)
        server = client_ring.get_node(key)
        response = UDPClient().send(data_bytes, server)
        print(response)
Ejemplo n.º 20
0
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)

    def delete(upd_clients, hc):
        client_ring = NodeRing(udp_clients)
        data_bytes, key = serialize_DELETE(hc)
        response = client_ring.get_node(key).send(data_bytes)
        print(response)

    def put(upd_clients, obj):
        client_ring = NodeRing(upd_clients)
        data_bytes, key = serialize_PUT(obj)
        response = client_ring.get_node(key).send(data_bytes)
        print(response)

    @lru_cache(5)
    def get(udp_clients, hc):
        client_ring = NodeRing(udp_clients)
        data_bytes, key = serialize_GET(hc)
        response = client_ring.get_node(key).send(data_bytes)
        print(response)
Ejemplo n.º 21
0
def process(udp_clients):
    print("parameter: ", udp_clients)

    client_ring = NodeRing(udp_clients)  # ???????
    #hrw = rendezvous_hashing(client_ring, [100,200,300,400])

    #hrw= RHW_hashing.Ring()

    print("client_ring", client_ring)
    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)
        # response = hrw.get_responsible_node(key).send(data_bytes)
        #lcu.cash add(response)
        hash_codes.add(str(response.decode()))
        # print("users",u)
        # print("hashcode:",hash_codes)
        print(
            "user numbers:"
            f"Number of Users={len(USERS)}\nNumber of Users Cached={len(hash_codes)}"
        )

    # GET all users.
    for hc in hash_codes:
        print("hashcode:", hc)
        data_bytes, key = serialize_GET(hc)
        print("data_bytes: ", data_bytes)
        print("key", key)
        #cash
        #bloomingfilter
        response = client_ring.get_node(key).send(data_bytes)
        print("response:", response)
    #delete
    for hc in hash_codes:
        data_bytes, key = serialize_DELETE(hc)
        response = client_ring.get_node(key).send(data_bytes)
        print("success")
Ejemplo n.º 22
0
 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)}")
Ejemplo n.º 23
0
 def get(udp_clients, hc):
     client_ring = NodeRing(udp_clients)
     data_bytes, key = serialize_GET(hc)
     response = client_ring.get_node(key).send(data_bytes)
     print(response)
Ejemplo n.º 24
0
 def put(upd_clients, obj):
     client_ring = NodeRing(upd_clients)
     data_bytes, key = serialize_PUT(obj)
     response = client_ring.get_node(key).send(data_bytes)
     print(response)
Ejemplo n.º 25
0
 def delete(upd_clients, hc):
     client_ring = NodeRing(udp_clients)
     data_bytes, key = serialize_DELETE(hc)
     response = client_ring.get_node(key).send(data_bytes)
     print(response)