예제 #1
0
def main():
    ip = sys.argv[1]
    port = sys.argv[2]
    platform = lib_agent.PlatformWrapper(ip, port)
    while True:
        functions = platform.get_all_functions()
        print(functions)
        time.sleep(10)
예제 #2
0
def main():
    ip = sys.argv[1]
    port = sys.argv[2]
    platform = lib_agent.PlatformWrapper(ip, port)
    while True:
        try:
            functions = platform.get_all_functions()
            if len(functions) == 0:
                print("There are not registered functions")
                continue
            index = randint(0, len(functions)-1)
            print("Getting agents of function "+ functions[index])
            agents = platform.get_agent_by_function(functions[index])
            print(agents)
        except Exception as e:
            print("Error " + str(e))
        time.sleep(10)
예제 #3
0
def main():
    name = 'Adder'
    function = 'Add'
    host = sys.argv[1]
    port = int(sys.argv[2])
    myIp = sys.argv[3]
    myPort = int(sys.argv[4])

    platform = lib_agent.PlatformWrapper(host, port)

    test_case = [
        lib_agent.TestCase('1 2', '3'),
        lib_agent.TestCase('2 3', '5'),
    ]
    endpoint_service = [
        lib_agent.Addr(f'{myIp}', myPort),
    ]

    is_alive_service = dict()
    is_alive_service[f'{myIp}:{myPort}'] = lib_agent.Addr(
        f'{myIp}', (myPort + 1))

    documentation = dict()
    documentation[f'{myIp}:{myPort}'] = lib_agent.Addr(f'{myIp}', (myPort + 2))

    # Agent | Agent to register
    agent = lib_agent.Agent(name=name,
                            function=function,
                            endpoint_service=endpoint_service,
                            documentation=documentation,
                            is_alive_service=is_alive_service,
                            test_cases=test_case)

    sum_server = threading.Thread(target=handle_sum, args=(f'{myIp}', myPort))
    sum_server.start()

    is_alive_server = threading.Thread(target=handle_is_alive,
                                       args=(f'{myIp}', myPort + 1))
    is_alive_server.start()

    doc_server = threading.Thread(target=handle_documentation,
                                  args=(f'{myIp}', myPort + 2))
    doc_server.start()

    # Register Agent
    try:
        print("Registering")
        platform.register_agent(agent)
        print("Registered")
    except:
        print("Failing register, trying add endpoint")
        try:
            platform.add_endpoint(agent.name, agent.password,
                                  agent._endpoint_service,
                                  agent.is_alive_service, agent.documentation)
        except Exception as e:
            print(e)
            print("Couldn\'t add agent")
            return

    sum_server.join()
    is_alive_server.join()
    doc_server.join()