From 3d356272f1d0997f38c5f112a38c26869d6e02f7 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Fri, 23 Apr 2021 22:51:35 -0700 Subject: [PATCH] pygui: adjust service configuration to not use grpc calls, data is saved and provided in start session call --- daemon/core/api/grpc/server.py | 12 ++--- daemon/core/api/grpc/wrappers.py | 20 ++++---- daemon/core/gui/coreclient.py | 12 ----- daemon/core/gui/dialogs/serviceconfig.py | 65 ++++++++++-------------- 4 files changed, 43 insertions(+), 66 deletions(-) diff --git a/daemon/core/api/grpc/server.py b/daemon/core/api/grpc/server.py index 592cb871..3c4966ac 100644 --- a/daemon/core/api/grpc/server.py +++ b/daemon/core/api/grpc/server.py @@ -269,6 +269,12 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer): for config in request.service_configs: grpcutils.service_configuration(session, config) + # service file configs + for config in request.service_file_configs: + session.services.set_service_file( + config.node_id, config.service, config.file, config.data + ) + # config service configs for config in request.config_service_configs: node = self.get_node(session, config.node_id, context, CoreNode) @@ -278,12 +284,6 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer): for name, template in config.templates.items(): service.set_template(name, template) - # service file configs - for config in request.service_file_configs: - session.services.set_service_file( - config.node_id, config.service, config.file, config.data - ) - # create links _, exceptions = grpcutils.create_links(session, request.links) if exceptions: diff --git a/daemon/core/api/grpc/wrappers.py b/daemon/core/api/grpc/wrappers.py index b32e7b8f..cda54ef2 100644 --- a/daemon/core/api/grpc/wrappers.py +++ b/daemon/core/api/grpc/wrappers.py @@ -206,16 +206,16 @@ class ServiceDefault: @dataclass class NodeServiceData: - executables: List[str] - dependencies: List[str] - dirs: List[str] - configs: List[str] - startup: List[str] - validate: List[str] - validation_mode: ServiceValidationMode - validation_timer: int - shutdown: List[str] - meta: str + executables: List[str] = field(default_factory=list) + dependencies: List[str] = field(default_factory=list) + dirs: List[str] = field(default_factory=list) + configs: List[str] = field(default_factory=list) + startup: List[str] = field(default_factory=list) + validate: List[str] = field(default_factory=list) + validation_mode: ServiceValidationMode = ServiceValidationMode.NON_BLOCKING + validation_timer: int = 5 + shutdown: List[str] = field(default_factory=list) + meta: str = None @classmethod def from_proto(cls, proto: services_pb2.NodeServiceData) -> "NodeServiceData": diff --git a/daemon/core/gui/coreclient.py b/daemon/core/gui/coreclient.py index 3559f669..c612cb8d 100644 --- a/daemon/core/gui/coreclient.py +++ b/daemon/core/gui/coreclient.py @@ -580,11 +580,6 @@ class CoreClient: ) return node_service - def set_node_service(self, node_id: int, config: ServiceConfig) -> NodeServiceData: - result = self.client.set_node_service(self.session.id, config) - logger.info("set node service result(%s): %s", result, config) - return self.client.get_node_service(self.session.id, node_id, config.service) - def get_node_service_file( self, node_id: int, service_name: str, file_name: str ) -> str: @@ -600,13 +595,6 @@ class CoreClient: ) return data - def set_node_service_file( - self, node_id: int, service_name: str, file_name: str, data: str - ) -> None: - config = ServiceFileConfig(node_id, service_name, file_name, data) - result = self.client.set_node_service_file(self.session.id, config) - logger.info("set service file config %s: %s", config, result) - def create_nodes_and_links(self) -> None: """ create nodes and links that have not been created yet diff --git a/daemon/core/gui/dialogs/serviceconfig.py b/daemon/core/gui/dialogs/serviceconfig.py index 1d6881df..56514479 100644 --- a/daemon/core/gui/dialogs/serviceconfig.py +++ b/daemon/core/gui/dialogs/serviceconfig.py @@ -7,12 +7,7 @@ from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple import grpc from PIL.ImageTk import PhotoImage -from core.api.grpc.wrappers import ( - Node, - NodeServiceData, - ServiceConfig, - ServiceValidationMode, -) +from core.api.grpc.wrappers import Node, NodeServiceData, ServiceValidationMode from core.gui import images from core.gui.dialogs.copyserviceconfig import CopyServiceConfigDialog from core.gui.dialogs.dialog import Dialog @@ -454,37 +449,31 @@ class ServiceConfigDialog(Dialog): self.current_service_color("") self.destroy() return - - try: - if ( - self.is_custom_command() - or self.has_new_files() - or self.is_custom_directory() - ): - startup, validate, shutdown = self.get_commands() - config = ServiceConfig( - node_id=self.node.id, - service=self.service_name, - files=list(self.filename_combobox["values"]), - directories=self.temp_directories, - startup=startup, - validate=validate, - shutdown=shutdown, - ) - service_data = self.core.set_node_service(self.node.id, config) - self.node.service_configs[self.service_name] = service_data - for file in self.modified_files: - file_configs = self.node.service_file_configs.setdefault( - self.service_name, {} - ) - file_configs[file] = self.temp_service_files[file] - # TODO: check if this is really needed - self.app.core.set_node_service_file( - self.node.id, self.service_name, file, self.temp_service_files[file] - ) - self.current_service_color("green") - except grpc.RpcError as e: - self.app.show_grpc_exception("Save Service Config Error", e) + files = set(self.filenames) + if ( + self.is_custom_command() + or self.has_new_files() + or self.is_custom_directory() + ): + startup, validate, shutdown = self.get_commands() + files = set(self.filename_combobox["values"]) + service_data = NodeServiceData( + configs=list(files), + dirs=self.temp_directories, + startup=startup, + validate=validate, + shutdown=shutdown, + ) + logger.info("setting service data: %s", service_data) + self.node.service_configs[self.service_name] = service_data + for file in self.modified_files: + if file not in files: + continue + file_configs = self.node.service_file_configs.setdefault( + self.service_name, {} + ) + file_configs[file] = self.temp_service_files[file] + self.current_service_color("green") self.destroy() def display_service_file_data(self, event: tk.Event) -> None: @@ -592,7 +581,7 @@ class ServiceConfigDialog(Dialog): if directory.is_dir(): if str(directory) not in self.temp_directories: self.dir_list.listbox.insert("end", directory) - self.temp_directories.append(directory) + self.temp_directories.append(str(directory)) def remove_directory(self) -> None: d = self.directory_entry.get()