def starting():
    check_master = print_children()
    if (check_master == []):
        master = True
        print("I am the master server!")
        replicate("server3")
        keys_in_server = select_all_keys("server3")  #list
        d = {}
        d[connected_port] = keys_in_server
        d = collections.OrderedDict(d)
        register_server(d, "server3")
        time.sleep(10)
        #put_watch()
        register_server_in_others(d)
    else:
        print("I am the child server!")
        print("Registering with master!")
        replicate("server3")
        keys_in_server = select_all_keys("server3")  #list
        d = {}
        d[connected_port] = keys_in_server
        d = collections.OrderedDict(d)
        register_server(d, "server3")
        time.sleep(10)
        #put_watch()
        register_server_in_others(d)
Exemplo n.º 2
0
def modify_mappings():
    zk = KazooClient("localhost:2181")
    zk.start()
    children = zk.get_children("/big_data_assign")
    for each in children:
        path = "/big_data_assign/" + each
        print(path)
        c = zk.get(path)
        c = c[0]
        c = c.decode()
        c = eval(c, {'OrderedDict': OrderedDict})
        #print("here4",c,type(c))
        #for key, value in c.items():
        key = list(c.items())[0]
        key = key[0]
        print(key)
        d = {}
        d[key] = select_all_keys(each)
        d = OrderedDict(d)
        modify_server(d, each)
        #print(d)
    for each in children:
        path = "/big_data_assign/" + each
        print(path)
        c = zk.get(path)
        c = c[0]
        c = c.decode()
        c = eval(c, {'OrderedDict': OrderedDict})
        #print("here4",c,type(c))
        #for key, value in c.items():
        key = list(c.items())[0]
        key = key[0]
        print(key)
        d = {}
        d[key] = select_all_keys(each)
        d = OrderedDict(d)
        register_server_in_others(d)