コード例 #1
0
 def on_connect_button_clicked(self, *args):
     """
     Triggered when connect button clicked
     Connects to selected server
     :param args:
     :return:
     """
     path = self.view["connection_tree_view1"].get_cursor()[0]
     if path is not None:
         for index in path:
             address = self.network_manager_model.connected_ip_port[index]
             logger.info("Connecting to: {0}".format(address))
             if self.network_manager_model.get_connected_status(
                     address) == "connected":
                 logger.info("Already connected to server!")
             else:
                 global_monitoring_manager.reconnect(address)
     else:
         address = ((
             global_network_config.get_config_value("SERVER_IP"),
             global_network_config.get_config_value("SERVER_UDP_PORT")))
         global_monitoring_manager.reconnect(address)
コード例 #2
0
def client_interaction(main_window_controller, global_monitoring_manager,
                       queue_dict, state_machine_id):
    import rafcon.core.singleton as core_singletons  # be careful, could be replaced before
    import rafcon.gui.singleton as gui_singletons
    from monitoring.monitoring_execution_engine import MonitoringExecutionEngine
    from rafcon.core.execution.execution_status import StateMachineExecutionStatus
    from rafcon.core.execution.execution_engine import ExecutionEngine
    from monitoring.model.network_model import network_manager_model
    from monitoring.monitoring_manager import MonitoringManager
    from rafcon.utils import log

    client_controller = gui_singletons.main_window_controller.get_controller(
        'monitoring_manager_ctrl')

    assert isinstance(global_monitoring_manager, MonitoringManager)
    remote_execution_engine = core_singletons.state_machine_execution_engine
    assert isinstance(remote_execution_engine, MonitoringExecutionEngine)

    logger = log.get_logger("Interacting client1")
    sleep_time = 0.01
    logger.info("Start interacting with server\n\n")

    for id, queue in queue_dict.items():
        assert isinstance(queue, multiprocessing.queues.Queue)

    while not global_monitoring_manager.endpoint_initialized:
        logger.warning("global_monitoring_manager not initialized yet!")
        time.sleep(sleep_time)

    while len(network_manager_model.connected_ip_port) < 1:
        time.sleep(sleep_time)

    while not global_monitoring_manager.endpoint.registered_to_server:
        time.sleep(sleep_time)

    #######################################################
    print("\n\n\nTEST1 stop - start - wait_for_stop")
    #######################################################

    queue_dict[CLIENT_TO_SERVER].put("start_test_1")

    # step 1: stop sm and synchronize
    queue_element = queue_dict[SERVER_TO_CLIENT].get(
    )  # synchronize, when to start stepping
    assert queue_element == "started"
    print("received: ", queue_element)
    # test stop start
    remote_execution_engine.stop()
    queue_element = queue_dict[SERVER_TO_CLIENT].get()
    assert queue_element == "stop_received"
    print("received: ", queue_element)

    # step 2: start sm and synchronize
    remote_execution_engine.start(state_machine_id)
    queue_element = queue_dict[SERVER_TO_CLIENT].get(
    )  # synchronize, when to start stepping
    assert queue_element == "restarted"
    print("received: ", queue_element)

    # step 3: synchronize with stopping of execution engine
    queue_element = queue_dict[SERVER_TO_CLIENT].get()
    assert queue_element == "successfully stopped the state machine"
    print("received: ", queue_element)
    queue_dict[MAIN_QUEUE].put(STOP_START_SUCCESSFUL)

    # queue_dict[KILL_CLIENT1_QUEUE].get()
    # os._exit(0)
    # return

    #######################################################
    print("\n\n\nTEST2 disconnect -> run sm -> connect -> run sm")
    #######################################################

    queue_dict[CLIENT_TO_SERVER].put("start_test_2")

    # step 1
    queue_element = queue_dict[SERVER_TO_CLIENT].get()
    assert queue_element == "disconnect_me_and_run"
    print("received: ", queue_element)

    address = None
    for addr in network_manager_model.connected_ip_port:
        global_monitoring_manager.disconnect(addr)
        address = addr

    while global_monitoring_manager.endpoint.registered_to_server:
        time.sleep(sleep_time)

    # TODO: why is this in a while loop here?
    while not isinstance(remote_execution_engine, ExecutionEngine):
        remote_execution_engine = core_singletons.state_machine_execution_engine
        time.sleep(sleep_time)

    # the start command won't do anything
    remote_execution_engine.start(state_machine_id)
    while remote_execution_engine.status.execution_mode is not StateMachineExecutionStatus.STARTED:
        time.sleep(sleep_time)

    queue_dict[CLIENT_TO_SERVER].put("disconnected_and_executed")

    # joining and stopping the execution engine won't do anything
    remote_execution_engine.join()
    remote_execution_engine.stop()

    # step 2
    queue_element = queue_dict[SERVER_TO_CLIENT].get()
    assert queue_element == "reconnect_me_and_run"
    print("received: ", queue_element)

    global_monitoring_manager.reconnect(address)
    while not global_monitoring_manager.endpoint.registered_to_server:
        time.sleep(sleep_time)
    while not network_manager_model.get_connected_status(
            address) == "connected":
        time.sleep(sleep_time)
    print("status connected")

    while not isinstance(remote_execution_engine, MonitoringExecutionEngine):
        remote_execution_engine = core_singletons.state_machine_execution_engine
        time.sleep(sleep_time)

    print("sm monitoring")
    remote_execution_engine.start(state_machine_id)
    while remote_execution_engine.status.execution_mode is not StateMachineExecutionStatus.STARTED:
        time.sleep(sleep_time)
    print("sm started")

    queue_dict[CLIENT_TO_SERVER].put("reconnected_and_executed")
    queue_element = queue_dict[SERVER_TO_CLIENT].get()
    assert queue_element == "succeeded"
    print("received: ", queue_element)

    # stop is executed by the server itself, but it is not forwarded to the remote server!
    # TODO: forward it

    queue_dict[MAIN_QUEUE].put(DISCONNECTED_RUN_SUCCESSFUL)
    print("client disconnection test succeeded")

    # queue_dict[KILL_CLIENT1_QUEUE].get()
    # os._exit(0)
    # return

    #######################################################
    print("\n\n\nclient TEST3 disable -> run sm -> enable -> run sm")
    #######################################################

    queue_dict[CLIENT_TO_SERVER].put("start_test_3")

    queue_element = queue_dict[SERVER_TO_CLIENT].get()
    assert queue_element == "you_are_disabled"
    print("client received: ", queue_element)

    for address in network_manager_model.connected_ip_port:
        while not network_manager_model.get_connected_status(
                address) == "disabled":
            time.sleep(sleep_time)

    print("start remote_execution_engine 1")

    # since the engine changed to local after disabling, we need to import it again
    remote_execution_engine = core_singletons.state_machine_execution_engine
    while not isinstance(remote_execution_engine, ExecutionEngine):
        time.sleep(sleep_time)

    print("start remote_execution_engine 2")
    remote_execution_engine.start(state_machine_id)

    print("wait for started")
    while remote_execution_engine.status.execution_mode is not StateMachineExecutionStatus.STARTED:
        time.sleep(sleep_time)

    print("wait for stopped")
    while not remote_execution_engine.finished_or_stopped():
        time.sleep(sleep_time)

    print("stop engine")
    remote_execution_engine.stop()
    if not remote_execution_engine.finished_or_stopped():
        remote_execution_engine.join()

    print("disabled run stopped")
    queue_dict[CLIENT_TO_SERVER].put("reached end")

    global_monitoring_manager.reinitialize(
        network_manager_model.connected_ip_port)

    for address in network_manager_model.connected_ip_port:
        # TODO: reconnect does not work
        # global_monitoring_manager.reconnect(address)
        while not network_manager_model.get_connected_status(
                address) == "connected":
            print("network_manager_model.get_connected_status(address)",
                  network_manager_model.get_connected_status(address))
            time.sleep(0.5)

    queue_dict[CLIENT_TO_SERVER].put("enabled_again")

    while not isinstance(remote_execution_engine, MonitoringExecutionEngine):
        remote_execution_engine = core_singletons.state_machine_execution_engine
        time.sleep(sleep_time)

    remote_execution_engine.start(state_machine_id)
    print("started enabled sm")
    while remote_execution_engine.status.execution_mode is not StateMachineExecutionStatus.STARTED:
        time.sleep(sleep_time)
    print("start enabled run")
    queue_dict[CLIENT_TO_SERVER].put("started_execution")

    queue_element = queue_dict[SERVER_TO_CLIENT].get()
    assert queue_element == "succeeded"
    print("client received: ", queue_element)

    remote_execution_engine.stop()
    remote_execution_engine.join()

    queue_dict[MAIN_QUEUE].put(DISABLED_RUN_SUCCESSFUL)

    # queue_dict[KILL_CLIENT1_QUEUE].get()
    # os._exit(0)
    # return

    #######################################################
    print(
        "client TEST4 change client ID in config -> apply -> check connected client ID"
    )
    #######################################################

    queue_dict[CLIENT_TO_SERVER].put("start_test_4")

    queue_element = queue_dict[SERVER_TO_CLIENT].get()
    assert queue_element == "ready_to_change_config"
    print("client received: ", queue_element)

    network_manager_model.set_config_value('CLIENT_ID', 'apply_test_client_id')
    while not client_controller.global_network_config.get_config_value(
            'CLIENT_ID') == 'apply_test_client_id':
        time.sleep(sleep_time)
    global_monitoring_manager.endpoint.registered_to_server = False
    global_monitoring_manager.reinitialize(
        network_manager_model.connected_ip_port)

    while not global_monitoring_manager.endpoint_initialized:
        logger.warning("global_monitoring_manager not initialized yet!")
        time.sleep(sleep_time)

    logger.info("Wait until registered to server")
    while not global_monitoring_manager.endpoint:
        time.sleep(sleep_time)
    while not global_monitoring_manager.endpoint.registered_to_server:
        time.sleep(sleep_time)
    # here is a function needed which ensures that the client is disconnected and reconnected again
    queue_dict[CLIENT_TO_SERVER].put("on_apply_button_clicked")

    queue_element = queue_dict[SERVER_TO_CLIENT].get()
    assert queue_element == "succeeded"
    print("client received: ", queue_element)

    while not isinstance(remote_execution_engine, MonitoringExecutionEngine):
        # import rafcon.core.singleton as core_singletons
        remote_execution_engine = core_singletons.state_machine_execution_engine
        time.sleep(sleep_time)
    queue_dict[MAIN_QUEUE].put(APPLY_CONFIG_SUCCESSFUL)

    queue_dict[KILL_CLIENT1_QUEUE].get()  # synchronize to main process
    os._exit(0)
コード例 #3
0
ファイル: _test_network_gui.py プロジェクト: uservinu/RAFCON
def interacting_function_client1(main_window_controller,
                                 global_monitoring_manager, queue_dict):
    import rafcon.core.singleton as core_singletons  # be careful, could be replaced before
    remote_execution_engine = core_singletons.state_machine_execution_engine
    from rafcon.utils import log
    logger = log.get_logger("Interacting client1")
    sleep_time = 0.01
    logger.info("Start interacting with server\n\n")

    for id, queue in queue_dict.iteritems():
        assert isinstance(queue, multiprocessing.queues.Queue)

    while not global_monitoring_manager.endpoint_initialized:
        logger.warn("global_monitoring_manager not initialized yet!")
        time.sleep(sleep_time)
    """
    TEST1 disconnect -> run sm -> connect -> run sm
    """
    queue_dict[SERVER_TO_CLIENT].get()  # synchronize, when to start stepping
    # test stop start
    remote_execution_engine.stop()
    queue_dict[SERVER_TO_CLIENT].get()
    remote_execution_engine.start()
    queue_dict[SERVER_TO_CLIENT].get()
    queue_dict[MAIN_QUEUE].put(STOP_START_SUCCESSFUL)

    from monitoring.controllers import client_controller
    from rafcon.core.execution.execution_status import StateMachineExecutionStatus
    from rafcon.core.execution.execution_engine import ExecutionEngine
    from monitoring.monitoring_execution_engine import MonitoringExecutionEngine
    from monitoring.model.network_model import network_manager_model
    """
    TEST2 disconnect -> run sm -> connect -> run sm
    """
    queue_dict[SERVER_TO_CLIENT].get()

    for address in network_manager_model.connected_ip_port:
        global_monitoring_manager.disconnect(address)

    while global_monitoring_manager.endpoint.registered_to_server:
        time.sleep(sleep_time)

    # import rafcon.core.singleton as core_singletons
    # remote_execution_engine = core_singletons.state_machine_execution_engine
    while not isinstance(remote_execution_engine, ExecutionEngine):
        remote_execution_engine = core_singletons.state_machine_execution_engine
        time.sleep(sleep_time)

    remote_execution_engine.start()
    while remote_execution_engine.status.execution_mode is not StateMachineExecutionStatus.STARTED:
        time.sleep(sleep_time)

    remote_execution_engine.join()
    # while remote_execution_engine.status.execution_mode is not StateMachineExecutionStatus.STOPPED:
    #     time.sleep(0.01)
    queue_dict[CLIENT_TO_SERVER].put("disconnected_and_executed")

    remote_execution_engine.stop()
    if not remote_execution_engine.finished_or_stopped():
        remote_execution_engine.join()

    queue_dict[SERVER_TO_CLIENT].get()
    global_monitoring_manager.reconnect(address)

    while not global_monitoring_manager.endpoint.registered_to_server:
        time.sleep(sleep_time)

    while not network_manager_model.get_connected_status(
            address) == "connected":
        time.sleep(sleep_time)
    print "status connected"

    # import rafcon.core.singleton as core_singletons
    while not isinstance(remote_execution_engine, MonitoringExecutionEngine):
        remote_execution_engine = core_singletons.state_machine_execution_engine
        time.sleep(sleep_time)

    print "sm monitoring"
    remote_execution_engine.start()
    while remote_execution_engine.status.execution_mode is not StateMachineExecutionStatus.STARTED:
        time.sleep(sleep_time)
    print "sm started"

    queue_dict[CLIENT_TO_SERVER].put("reconnected_and_executed")
    queue_dict[SERVER_TO_CLIENT].get()

    remote_execution_engine.stop()
    if not remote_execution_engine.finished_or_stopped():
        remote_execution_engine.join()

    queue_dict[MAIN_QUEUE].put(DISCONNECTED_RUN_SUCCESSFUL)
    print "client disconnection test succeeded"
    """
    TEST3 disable -> run sm -> enable -> run sm
    """
    queue_dict[SERVER_TO_CLIENT].get()
    print "client disabled test begin"
    for address in network_manager_model.connected_ip_port:
        while not network_manager_model.get_connected_status(
                address) == "disabled":
            time.sleep(sleep_time)

    # since the engine changed to local after disabling, we need to import it again
    # import rafcon.core.singleton as core_singletons
    remote_execution_engine = core_singletons.state_machine_execution_engine
    while not isinstance(remote_execution_engine, ExecutionEngine):
        time.sleep(sleep_time)

    remote_execution_engine.start()

    while remote_execution_engine.status.execution_mode is not StateMachineExecutionStatus.STARTED:
        time.sleep(sleep_time)

    while not remote_execution_engine.finished_or_stopped():
        time.sleep(sleep_time)

    remote_execution_engine.stop()
    if not remote_execution_engine.finished_or_stopped():
        remote_execution_engine.join()

    print "disabled run stopped"
    queue_dict[CLIENT_TO_SERVER].put("reached end")
    queue_dict[SERVER_TO_CLIENT].get()
    print "ended disabled run"
    # for address in network_manager_model.connected_ip_port:
    #     while not network_manager_model.get_connected_status(address) == "connected":
    #         time.sleep(0.01)

    # since the engine changed to remote after enabling, we need to import it again

    while not isinstance(remote_execution_engine, MonitoringExecutionEngine):
        remote_execution_engine = core_singletons.state_machine_execution_engine
        time.sleep(sleep_time)

    remote_execution_engine.start()
    print "started enabled sm"
    while remote_execution_engine.status.execution_mode is not StateMachineExecutionStatus.STARTED:
        time.sleep(sleep_time)
    print "start enabled run"
    queue_dict[CLIENT_TO_SERVER].put("started execution")
    queue_dict[SERVER_TO_CLIENT].get()

    remote_execution_engine.stop()
    if not remote_execution_engine.finished_or_stopped():
        remote_execution_engine.join()

    queue_dict[MAIN_QUEUE].put(DISABLED_RUN_SUCCESSFUL)
    """
    TEST4 change client ID in config -> apply -> check connected client ID
    """
    queue_dict[SERVER_TO_CLIENT].get()
    network_manager_model.set_config_value('CLIENT_ID', 'apply_test_client_id')
    while not client_controller.global_network_config.get_config_value(
            'CLIENT_ID') == 'apply_test_client_id':
        time.sleep(sleep_time)
    global_monitoring_manager.endpoint.registered_to_server = False
    global_monitoring_manager.reinitialize(
        network_manager_model.connected_ip_port)

    while not global_monitoring_manager.endpoint_initialized:
        logger.warn("global_monitoring_manager not initialized yet!")
        time.sleep(sleep_time)

    logger.info("Wait until registered to server")
    while not global_monitoring_manager.endpoint:
        time.sleep(sleep_time)
    while not global_monitoring_manager.endpoint.registered_to_server:
        time.sleep(sleep_time)
    # here is a function needed which ensures that the client is disconnected and reconnected again
    queue_dict[CLIENT_TO_SERVER].put("on_apply_button clicked")
    queue_dict[SERVER_TO_CLIENT].get()

    while not isinstance(remote_execution_engine, MonitoringExecutionEngine):
        # import rafcon.core.singleton as core_singletons
        remote_execution_engine = core_singletons.state_machine_execution_engine
        time.sleep(sleep_time)
    queue_dict[MAIN_QUEUE].put(APPLY_CONFIG_SUCCESSFUL)

    queue_dict[KILL_CLIENT1_QUEUE].get()  # synchronize to main process
    os._exit(0)