From a50a173f546aabae8ba878681489e43553d4e168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 16 Feb 2018 12:07:16 +0100 Subject: [PATCH 01/13] Implement ProcessManagingEventHandler --- .../components/process_managing_event_handler.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/tfw/components/process_managing_event_handler.py diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py new file mode 100644 index 0000000..8fd1bea --- /dev/null +++ b/lib/tfw/components/process_managing_event_handler.py @@ -0,0 +1,15 @@ +from tfw.event_handler_base import EventHandlerBase +from tfw.components.mixins import SupervisorMixin + + +class ProcessManagingEventHandler(EventHandlerBase, SupervisorMixin): + def __init__(self, anchor, supervisor_process_name): + super().__init__(anchor) + self.process = supervisor_process_name + self.commands = {'start': self.start_process, + 'stop': self.stop_process, + 'restart': self.restart_process} + + def handle_event(self, anchor, data_json): + data = data_json['data'] + self.commands[data['command']]() From 8d8b60d143c31008919ab8e425f6ba67f28e8637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 20 Feb 2018 14:45:16 +0100 Subject: [PATCH 02/13] Refactor ProcessManagingEventHandler --- .../process_managing_event_handler.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index 8fd1bea..7b387a5 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -2,14 +2,21 @@ from tfw.event_handler_base import EventHandlerBase from tfw.components.mixins import SupervisorMixin +class ProcessManager(SupervisorMixin): + def __init__(self, process_name): + self.process = process_name + self.commands = {'start': self.start_process, + 'stop': self.stop_process, + 'restart': self.restart_process} + + def __call__(self, command): + self.commands[command]() + + class ProcessManagingEventHandler(EventHandlerBase, SupervisorMixin): def __init__(self, anchor, supervisor_process_name): super().__init__(anchor) - self.process = supervisor_process_name - self.commands = {'start': self.start_process, - 'stop': self.stop_process, - 'restart': self.restart_process} + self.processmanager = ProcessManager(supervisor_process_name) def handle_event(self, anchor, data_json): - data = data_json['data'] - self.commands[data['command']]() + self.processmanager(data_json['data']['command']) From 69c998bfde82e16ebeca984a557bf9105ff2942c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 20 Feb 2018 16:29:19 +0100 Subject: [PATCH 03/13] Rename ProcessManager.__init__() arguments to be more specific --- lib/tfw/components/process_managing_event_handler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index 7b387a5..6eeba43 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -3,8 +3,8 @@ from tfw.components.mixins import SupervisorMixin class ProcessManager(SupervisorMixin): - def __init__(self, process_name): - self.process = process_name + def __init__(self, supervisor_process_name): + self.process = supervisor_process_name self.commands = {'start': self.start_process, 'stop': self.stop_process, 'restart': self.restart_process} From 3506f5abb44586bcf100ab007f123bfb8e7f081a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 20 Feb 2018 16:38:51 +0100 Subject: [PATCH 04/13] Fix ProcessMonitor not being compatible with SupervisorMixin --- lib/tfw/components/process_managing_event_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index 6eeba43..c05416c 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -4,7 +4,7 @@ from tfw.components.mixins import SupervisorMixin class ProcessManager(SupervisorMixin): def __init__(self, supervisor_process_name): - self.process = supervisor_process_name + self.process_name = supervisor_process_name self.commands = {'start': self.start_process, 'stop': self.stop_process, 'restart': self.restart_process} From 387d07bc4afc7eff9909e4cf2029a7f637783463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 21 Feb 2018 14:43:48 +0100 Subject: [PATCH 05/13] Remove SupervisorMixin from ProcessManagingEventHandler --- lib/tfw/components/process_managing_event_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index c05416c..d23fe5b 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -13,7 +13,7 @@ class ProcessManager(SupervisorMixin): self.commands[command]() -class ProcessManagingEventHandler(EventHandlerBase, SupervisorMixin): +class ProcessManagingEventHandler(EventHandlerBase): def __init__(self, anchor, supervisor_process_name): super().__init__(anchor) self.processmanager = ProcessManager(supervisor_process_name) From c96f50711d62e0f33245b0c8557627f614e00dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 21 Feb 2018 14:44:49 +0100 Subject: [PATCH 06/13] Add ProcessManagingEventHandler to event_handler_main --- src/demo/event_handler_main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/demo/event_handler_main.py b/src/demo/event_handler_main.py index 4dce5f6..42a01cf 100644 --- a/src/demo/event_handler_main.py +++ b/src/demo/event_handler_main.py @@ -1,5 +1,6 @@ from tfw.components.source_code_event_handler import SourceCodeEventHandler from tfw.components.terminado_event_handler import TerminadoEventHandler +from tfw.components.process_managing_event_handler import ProcessManagingEventHandler from tornado.ioloop import IOLoop from tfw.config import tfwenv @@ -7,7 +8,8 @@ from tfw.config import tfwenv if __name__ == '__main__': eventhandlers = {SourceCodeEventHandler('anchor_webide', tfwenv.WEBIDE_WD), - TerminadoEventHandler('anchor_terminado', 'terminado')} + TerminadoEventHandler('anchor_terminado', 'terminado'), + ProcessManagingEventHandler('anchor_processmanager', 'login')} try: IOLoop.instance().start() finally: From 3341e97ef6dc9b4c2f63f2abdcaf2d417af16cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 27 Feb 2018 14:11:13 +0100 Subject: [PATCH 07/13] Fix anchor->key refactor conflicts after rebase --- lib/tfw/components/process_managing_event_handler.py | 8 +++++--- src/demo/event_handler_main.py | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index d23fe5b..ebe0629 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -1,5 +1,7 @@ from tfw.event_handler_base import EventHandlerBase from tfw.components.mixins import SupervisorMixin +from tfw.config.logs import logging +log = logging.getLogger(__name__) class ProcessManager(SupervisorMixin): @@ -14,9 +16,9 @@ class ProcessManager(SupervisorMixin): class ProcessManagingEventHandler(EventHandlerBase): - def __init__(self, anchor, supervisor_process_name): - super().__init__(anchor) + def __init__(self, key, supervisor_process_name): + super().__init__(key) self.processmanager = ProcessManager(supervisor_process_name) - def handle_event(self, anchor, data_json): + def handle_event(self, key, data_json): self.processmanager(data_json['data']['command']) diff --git a/src/demo/event_handler_main.py b/src/demo/event_handler_main.py index 42a01cf..ff6f362 100644 --- a/src/demo/event_handler_main.py +++ b/src/demo/event_handler_main.py @@ -7,9 +7,9 @@ from tfw.config import tfwenv if __name__ == '__main__': - eventhandlers = {SourceCodeEventHandler('anchor_webide', tfwenv.WEBIDE_WD), - TerminadoEventHandler('anchor_terminado', 'terminado'), - ProcessManagingEventHandler('anchor_processmanager', 'login')} + eventhandlers = {SourceCodeEventHandler('webide', tfwenv.WEBIDE_WD), + TerminadoEventHandler('terminado', 'terminado'), + ProcessManagingEventHandler('processmanager', 'login')} try: IOLoop.instance().start() finally: From b50a2e401f458970994abca8266e13aa13a651a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 27 Feb 2018 14:39:54 +0100 Subject: [PATCH 08/13] Update ProcessManagingEventHandler to support new architecture --- lib/tfw/components/process_managing_event_handler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index ebe0629..eae199a 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -1,4 +1,4 @@ -from tfw.event_handler_base import EventHandlerBase +from tfw.event_handler_base import TriggerlessEventHandler from tfw.components.mixins import SupervisorMixin from tfw.config.logs import logging log = logging.getLogger(__name__) @@ -15,7 +15,7 @@ class ProcessManager(SupervisorMixin): self.commands[command]() -class ProcessManagingEventHandler(EventHandlerBase): +class ProcessManagingEventHandler(TriggerlessEventHandler): def __init__(self, key, supervisor_process_name): super().__init__(key) self.processmanager = ProcessManager(supervisor_process_name) From 57bd2aec45b74249d20bd92200fc8dc2265055ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 27 Feb 2018 15:26:16 +0100 Subject: [PATCH 09/13] Implement uplink notifications in ProcessManagingEventHandler --- lib/tfw/components/process_managing_event_handler.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index eae199a..e8e0ccd 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -1,5 +1,6 @@ from tfw.event_handler_base import TriggerlessEventHandler from tfw.components.mixins import SupervisorMixin +from tfw.networking.event_handlers.server_connector import ServerUplinkConnector from tfw.config.logs import logging log = logging.getLogger(__name__) @@ -18,7 +19,10 @@ class ProcessManager(SupervisorMixin): class ProcessManagingEventHandler(TriggerlessEventHandler): def __init__(self, key, supervisor_process_name): super().__init__(key) + self.key = key self.processmanager = ProcessManager(supervisor_process_name) + self.uplink = ServerUplinkConnector() def handle_event(self, key, data_json): self.processmanager(data_json['data']['command']) + self.uplink.send(self.key, {'key': self.key}) From 789db7416de1e984c001d902eabdb0353e79bf47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 27 Feb 2018 15:54:10 +0100 Subject: [PATCH 10/13] Refactor SupervisorMixin to be stateless --- lib/tfw/components/mixins/supervisor_mixin.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/tfw/components/mixins/supervisor_mixin.py b/lib/tfw/components/mixins/supervisor_mixin.py index 968063e..ab483ff 100644 --- a/lib/tfw/components/mixins/supervisor_mixin.py +++ b/lib/tfw/components/mixins/supervisor_mixin.py @@ -8,13 +8,13 @@ from tfw.config import tfwenv class SupervisorMixin: supervisor = xmlrpc.client.ServerProxy(tfwenv.SUPERVISOR_HTTP_URI).supervisor - def stop_process(self): + def stop_process(self, process_name): with suppress(SupervisorFault): - self.supervisor.stopProcess(self.process_name) + self.supervisor.stopProcess(process_name) - def start_process(self): - self.supervisor.startProcess(self.process_name) + def start_process(self, process_name): + self.supervisor.startProcess(process_name) - def restart_process(self): - self.stop_process() - self.start_process() + def restart_process(self, process_name): + self.stop_process(process_name) + self.start_process(process_name) From a6bbe6df55417c53fbb5547805f4f213518d4b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 27 Feb 2018 15:54:31 +0100 Subject: [PATCH 11/13] Update SupervisorMixin users to support stateless API --- lib/tfw/components/process_managing_event_handler.py | 10 ++++++---- lib/tfw/components/terminado_event_handler.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index e8e0ccd..3962a2b 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -12,8 +12,8 @@ class ProcessManager(SupervisorMixin): 'stop': self.stop_process, 'restart': self.restart_process} - def __call__(self, command): - self.commands[command]() + def __call__(self, command, process_name): + self.commands[command](process_name) class ProcessManagingEventHandler(TriggerlessEventHandler): @@ -24,5 +24,7 @@ class ProcessManagingEventHandler(TriggerlessEventHandler): self.uplink = ServerUplinkConnector() def handle_event(self, key, data_json): - self.processmanager(data_json['data']['command']) - self.uplink.send(self.key, {'key': self.key}) + data = data_json['data'] + self.processmanager(data['command'], data['process_name']) + self.uplink.send(self.key, {'key': self.key, + 'data': {'process_name': data['process_name']}}) diff --git a/lib/tfw/components/terminado_event_handler.py b/lib/tfw/components/terminado_event_handler.py index 42b09d2..5329e3c 100644 --- a/lib/tfw/components/terminado_event_handler.py +++ b/lib/tfw/components/terminado_event_handler.py @@ -10,7 +10,7 @@ class TerminadoEventHandler(TriggerlessEventHandler, SupervisorMixin): super().__init__(key) self.working_directory = tfwenv.TERMINADO_DIR self.process_name = process_name - self.start_process() + self.start_process(self.process_name) def handle_event(self, key, data_json): log.debug('TerminadoEventHandler received event for key {}'.format(key)) From 9eaced9f02a3553125968411e54757fcab3ad3bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 27 Feb 2018 16:51:10 +0100 Subject: [PATCH 12/13] Remove unused __init__ attributes from pmgeh related classes --- lib/tfw/components/process_managing_event_handler.py | 7 +++---- src/demo/event_handler_main.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index 3962a2b..8084382 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -6,8 +6,7 @@ log = logging.getLogger(__name__) class ProcessManager(SupervisorMixin): - def __init__(self, supervisor_process_name): - self.process_name = supervisor_process_name + def __init__(self): self.commands = {'start': self.start_process, 'stop': self.stop_process, 'restart': self.restart_process} @@ -17,10 +16,10 @@ class ProcessManager(SupervisorMixin): class ProcessManagingEventHandler(TriggerlessEventHandler): - def __init__(self, key, supervisor_process_name): + def __init__(self, key): super().__init__(key) self.key = key - self.processmanager = ProcessManager(supervisor_process_name) + self.processmanager = ProcessManager() self.uplink = ServerUplinkConnector() def handle_event(self, key, data_json): diff --git a/src/demo/event_handler_main.py b/src/demo/event_handler_main.py index ff6f362..35a8f09 100644 --- a/src/demo/event_handler_main.py +++ b/src/demo/event_handler_main.py @@ -9,7 +9,7 @@ from tfw.config import tfwenv if __name__ == '__main__': eventhandlers = {SourceCodeEventHandler('webide', tfwenv.WEBIDE_WD), TerminadoEventHandler('terminado', 'terminado'), - ProcessManagingEventHandler('processmanager', 'login')} + ProcessManagingEventHandler('processmanager')} try: IOLoop.instance().start() finally: From e29b3009256648119fd61d74024514c0fce4d220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 28 Feb 2018 15:57:44 +0100 Subject: [PATCH 13/13] Refactor ServerUplinkConnector to avoid passing redundant data --- lib/tfw/components/directory_monitor.py | 3 +-- lib/tfw/components/process_managing_event_handler.py | 3 +-- lib/tfw/message_sender.py | 5 +---- lib/tfw/networking/event_handlers/server_connector.py | 1 + lib/tfw/networking/server/tfw_server.py | 3 +-- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/tfw/components/directory_monitor.py b/lib/tfw/components/directory_monitor.py index 5234367..6d2d264 100644 --- a/lib/tfw/components/directory_monitor.py +++ b/lib/tfw/components/directory_monitor.py @@ -25,8 +25,7 @@ class WebideReloadEventHandler(FileSystemEventHandler): if self._paused: return log.debug(event) key = 'webide' - self.uplink.send(key, {'key': key, - 'data': {'command': 'reload'}}) + self.uplink.send(key, {'data': {'command': 'reload'}}) class DirectoryMonitor: diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index 8084382..ec20fce 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -25,5 +25,4 @@ class ProcessManagingEventHandler(TriggerlessEventHandler): def handle_event(self, key, data_json): data = data_json['data'] self.processmanager(data['command'], data['process_name']) - self.uplink.send(self.key, {'key': self.key, - 'data': {'process_name': data['process_name']}}) + self.uplink.send(self.key, {'data': {'process_name': data['process_name']}}) diff --git a/lib/tfw/message_sender.py b/lib/tfw/message_sender.py index 6d57aa6..fbd52fb 100644 --- a/lib/tfw/message_sender.py +++ b/lib/tfw/message_sender.py @@ -14,8 +14,5 @@ class MessageSender: 'timestamp': datetime.now().isoformat(), 'message': message } - response = { - 'key': self.key, - 'data': data - } + response = {'data': data} self.server_connector.send(self.key, response) diff --git a/lib/tfw/networking/event_handlers/server_connector.py b/lib/tfw/networking/event_handlers/server_connector.py index 99fe058..7c3fcb3 100644 --- a/lib/tfw/networking/event_handlers/server_connector.py +++ b/lib/tfw/networking/event_handlers/server_connector.py @@ -26,6 +26,7 @@ class ServerUplinkConnector(ZMQConnectorBase): self._zmq_push_socket.connect('tcp://localhost:{}'.format(tfwenv.RECEIVER_PORT)) def send(self, key, response): + response['key'] = key self._zmq_push_socket.send_multipart(serialize_all(key, response)) diff --git a/lib/tfw/networking/server/tfw_server.py b/lib/tfw/networking/server/tfw_server.py index 8411bd4..39cd498 100644 --- a/lib/tfw/networking/server/tfw_server.py +++ b/lib/tfw/networking/server/tfw_server.py @@ -46,8 +46,7 @@ class FSMUpdater: def generate_fsm_update(self): key = 'FSMUpdate' - response = {'key': key, - 'data': {'current_state': self.fsm.state, + response = {'data': {'current_state': self.fsm.state, 'valid_transitions': [{'trigger': trigger} for trigger in self.fsm.machine.get_triggers(self.fsm.state)]}} return key, response