pygui: adjust service configuration to not use grpc calls, data is saved and provided in start session call

This commit is contained in:
Blake Harnden 2021-04-23 22:51:35 -07:00
parent 4830538053
commit 3d356272f1
4 changed files with 43 additions and 66 deletions

View file

@ -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:

View file

@ -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":

View file

@ -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

View file

@ -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()