From a8bed90f021837fa41dd57b9da7dd78fe7a1639b Mon Sep 17 00:00:00 2001 From: PawelPlesniak Date: Fri, 25 Oct 2024 15:39:43 +0200 Subject: [PATCH 1/3] Removing ProcessQuery dependency for terminate --- src/drunc/process_manager/interface/commands.py | 7 ++----- src/drunc/process_manager/process_manager.py | 8 ++++---- src/drunc/process_manager/process_manager_driver.py | 5 ++--- src/drunc/process_manager/ssh_process_manager.py | 2 +- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/drunc/process_manager/interface/commands.py b/src/drunc/process_manager/interface/commands.py index 1bbe82c3..ed446779 100644 --- a/src/drunc/process_manager/interface/commands.py +++ b/src/drunc/process_manager/interface/commands.py @@ -76,13 +76,10 @@ async def dummy_boot(obj:ProcessManagerContext, user:str, n_processes:int, sleep @click.command('terminate') -@add_query_options(at_least_one=False) @click.pass_obj @run_coroutine -async def terminate(obj:ProcessManagerContext, query:ProcessQuery) -> None: - result = await obj.get_driver('process_manager').terminate( - query = query, - ) +async def terminate(obj:ProcessManagerContext) -> None: + result = await obj.get_driver('process_manager').terminate() if not result: return from drunc.process_manager.utils import tabulate_process_instance_list diff --git a/src/drunc/process_manager/process_manager.py b/src/drunc/process_manager/process_manager.py index fbbf8ac4..c9946aa3 100644 --- a/src/drunc/process_manager/process_manager.py +++ b/src/drunc/process_manager/process_manager.py @@ -192,7 +192,7 @@ def boot(self, br:BootRequest) -> Response: @abc.abstractmethod - def _terminate_impl(self, q:ProcessQuery) -> ProcessInstanceList: + def _terminate_impl(self) -> ProcessInstanceList: raise NotImplementedError # ORDER MATTERS! @@ -201,10 +201,10 @@ def _terminate_impl(self, q:ProcessQuery) -> ProcessInstanceList: action=ActionType.DELETE, system=SystemType.PROCESS_MANAGER ) # 2nd step - @unpack_request_data_to(ProcessQuery) # 3rd step - def terminate(self, q:ProcessQuery) -> Response: + @unpack_request_data_to(None) # 3rd step + def terminate(self) -> Response: try: - resp = self._terminate_impl(q) + resp = self._terminate_impl() return Response( name = self.name, token = None, diff --git a/src/drunc/process_manager/process_manager_driver.py b/src/drunc/process_manager/process_manager_driver.py index 667aa28d..9ae705bc 100644 --- a/src/drunc/process_manager/process_manager_driver.py +++ b/src/drunc/process_manager/process_manager_driver.py @@ -281,11 +281,10 @@ async def dummy_boot(self, user:str, session_name:str, n_processes:int, sleep:in outformat = ProcessInstance, ) - async def terminate(self, query:ProcessQuery) -> ProcessInstanceList: + async def terminate(self, ) -> ProcessInstanceList: return await self.send_command_aio( 'terminate', - data = query, - outformat = ProcessInstanceList, + outformat = ProcessInstanceList ) async def kill(self, query:ProcessQuery) -> ProcessInstance: diff --git a/src/drunc/process_manager/ssh_process_manager.py b/src/drunc/process_manager/ssh_process_manager.py index e7d16d04..46d182d3 100644 --- a/src/drunc/process_manager/ssh_process_manager.py +++ b/src/drunc/process_manager/ssh_process_manager.py @@ -128,7 +128,7 @@ def kill_processes(self, uuids:list) -> ProcessInstanceList: return pil - def _terminate_impl(self, query:ProcessQuery) -> ProcessInstanceList: + def _terminate_impl(self) -> ProcessInstanceList: self._log.info('Terminating') if self.process_store: self._log.warning('Killing all the known processes before exiting') From 64635857a7864cea66a685e1d2bc41a81c1f6f24 Mon Sep 17 00:00:00 2001 From: PawelPlesniak Date: Fri, 25 Oct 2024 15:57:54 +0200 Subject: [PATCH 2/3] Clearing kill output, making it more informative --- src/drunc/process_manager/interface/commands.py | 2 +- src/drunc/process_manager/utils.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/drunc/process_manager/interface/commands.py b/src/drunc/process_manager/interface/commands.py index ed446779..70f03399 100644 --- a/src/drunc/process_manager/interface/commands.py +++ b/src/drunc/process_manager/interface/commands.py @@ -86,7 +86,7 @@ async def terminate(obj:ProcessManagerContext) -> None: obj.print(tabulate_process_instance_list(result.data, 'Terminated process', False)) @click.command('kill') -@add_query_options(at_least_one=False) +@add_query_options(at_least_one=True) @click.pass_obj @run_coroutine async def kill(obj:ProcessManagerContext, query:ProcessQuery) -> None: diff --git a/src/drunc/process_manager/utils.py b/src/drunc/process_manager/utils.py index 065c3b4d..aff727a6 100644 --- a/src/drunc/process_manager/utils.py +++ b/src/drunc/process_manager/utils.py @@ -5,10 +5,9 @@ def generate_process_query(f, at_least_one:bool, all_processes_by_default:bool=F @click.pass_context def new_func(ctx, session, name, user, uuid, **kwargs): is_trivial_query = bool((len(uuid) == 0) and (session is None) and (len(name) == 0) and (user is None)) - # print(f'is_trivial_query={is_trivial_query} ({type(is_trivial_query)}): uuid={uuid} ({type(uuid)}), session={session} ({type(session)}), name={name} ({type(name)}), user={user} ({type(user)})') if is_trivial_query and at_least_one: - raise click.BadParameter('You need to provide at least a \'--uuid\', \'--session\', \'--user\' or \'--name\'!') + raise click.BadParameter('You need to provide at least a \'--uuid\', \'--session\', \'--user\' or \'--name\'!\nAll these values are presented with \'ps\'.\nIf you want to kill everything, use \'terminate\'.') if all_processes_by_default and is_trivial_query: name = ['.*'] From 03fab3768e386a7c353ad361b137a474eed7c5f4 Mon Sep 17 00:00:00 2001 From: PawelPlesniak Date: Tue, 29 Oct 2024 10:05:43 +0100 Subject: [PATCH 3/3] RRequested change --- src/drunc/process_manager/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drunc/process_manager/utils.py b/src/drunc/process_manager/utils.py index aff727a6..6ae8312b 100644 --- a/src/drunc/process_manager/utils.py +++ b/src/drunc/process_manager/utils.py @@ -7,7 +7,7 @@ def new_func(ctx, session, name, user, uuid, **kwargs): is_trivial_query = bool((len(uuid) == 0) and (session is None) and (len(name) == 0) and (user is None)) if is_trivial_query and at_least_one: - raise click.BadParameter('You need to provide at least a \'--uuid\', \'--session\', \'--user\' or \'--name\'!\nAll these values are presented with \'ps\'.\nIf you want to kill everything, use \'terminate\'.') + raise click.BadParameter('You need to provide at least a \'--uuid\', \'--session\', \'--user\' or \'--name\'!\nAll these values are presented with \'ps\'.\nIf you want to kill everything, use \'ps\' and \'kill\'.') if all_processes_by_default and is_trivial_query: name = ['.*']