merged latest from coretk

This commit is contained in:
Blake Harnden 2019-11-13 10:49:14 -08:00
commit 1e642b6302
3 changed files with 131 additions and 12 deletions

View file

@ -416,6 +416,35 @@ class CoreClient:
logging.debug("open xml: %s", response) logging.debug("open xml: %s", response)
self.join_session(response.session_id) self.join_session(response.session_id)
def get_node_service(self, node_id, service_name):
response = self.client.get_node_service(self.session_id, node_id, service_name)
logging.debug("get node service %s", response)
return response.service
def set_node_service(self, node_id, service_name, startups, validations, shutdowns):
response = self.client.set_node_service(
self.session_id, node_id, service_name, startups, validations, shutdowns
)
logging.debug("set node service %s", response)
def create_nodes_and_links(self):
node_protos = self.get_nodes_proto()
link_protos = self.get_links_proto()
self.client.set_session_state(self.session_id, core_pb2.SessionState.DEFINITION)
for node_proto in node_protos:
response = self.client.add_node(self.session_id, node_proto)
logging.debug("create node: %s", response)
for link_proto in link_protos:
response = self.client.add_link(
self.session_id,
link_proto.node_one_id,
link_proto.node_two_id,
link_proto.interface_one,
link_proto.interface_two,
link_proto.options,
)
logging.debug("create link: %s", response)
def close(self): def close(self):
""" """
Clean ups when done using grpc Clean ups when done using grpc

View file

@ -3,6 +3,7 @@ import logging
import tkinter as tk import tkinter as tk
from tkinter import ttk from tkinter import ttk
from core.api.grpc import core_pb2
from coretk.dialogs.dialog import Dialog from coretk.dialogs.dialog import Dialog
from coretk.images import ImageEnum, Images from coretk.images import ImageEnum, Images
from coretk.widgets import ListboxScroll from coretk.widgets import ListboxScroll
@ -12,26 +13,51 @@ class ServiceConfiguration(Dialog):
def __init__(self, master, app, service_name, canvas_node): def __init__(self, master, app, service_name, canvas_node):
super().__init__(master, app, f"{service_name} service", modal=True) super().__init__(master, app, f"{service_name} service", modal=True)
self.app = app self.app = app
self.canvas_node = canvas_node
self.service_name = service_name self.service_name = service_name
self.metadata = tk.StringVar()
self.filename = tk.StringVar()
self.radiovar = tk.IntVar() self.radiovar = tk.IntVar()
self.radiovar.set(2) self.radiovar.set(2)
self.startup_index = tk.IntVar() self.metadata = ""
self.start_time = tk.IntVar() self.filenames = []
self.dependencies = []
self.executables = []
self.startup_commands = []
self.validation_commands = []
self.shutdown_commands = []
self.validation_mode = None
self.validation_time = None
self.validation_period = None
self.documentnew_img = Images.get(ImageEnum.DOCUMENTNEW, 16) self.documentnew_img = Images.get(ImageEnum.DOCUMENTNEW, 16)
self.editdelete_img = Images.get(ImageEnum.EDITDELETE, 16) self.editdelete_img = Images.get(ImageEnum.EDITDELETE, 16)
self.tab_parent = None
self.filenames = ["test1", "test2", "test3"]
self.tab_parent = None
self.metadata_entry = None self.metadata_entry = None
self.filename_combobox = None self.filename_combobox = None
self.startup_commands_listbox = None self.startup_commands_listbox = None
self.shutdown_commands_listbox = None self.shutdown_commands_listbox = None
self.validate_commands_listbox = None self.validate_commands_listbox = None
self.validation_time_entry = None
self.validation_mode_entry = None
self.load()
self.draw() self.draw()
def load(self):
# create nodes and links in definition state for getting and setting service file
self.app.core.create_nodes_and_links()
# load data from local memory
service_config = self.app.core.serviceconfig_manager.configurations[
self.canvas_node.core_id
][self.service_name]
self.dependencies = [x for x in service_config.dependencies]
self.executables = [x for x in service_config.executables]
self.metadata = service_config.meta
self.filenames = [x for x in service_config.configs]
self.startup_commands = [x for x in service_config.startup]
self.validation_commands = [x for x in service_config.validate]
self.shutdown_commands = [x for x in service_config.shutdown]
self.validation_mode = service_config.validation_mode
self.validation_time = service_config.validation_timer
def draw(self): def draw(self):
# self.columnconfigure(1, weight=1) # self.columnconfigure(1, weight=1)
frame = ttk.Frame(self.top) frame = ttk.Frame(self.top)
@ -44,6 +70,7 @@ class ServiceConfiguration(Dialog):
# frame2.columnconfigure(1, weight=4) # frame2.columnconfigure(1, weight=4)
label = ttk.Label(frame2, text="Meta-data") label = ttk.Label(frame2, text="Meta-data")
label.grid(row=0, column=0) label.grid(row=0, column=0)
self.metadata_entry = ttk.Entry(frame2, textvariable=self.metadata) self.metadata_entry = ttk.Entry(frame2, textvariable=self.metadata)
self.metadata_entry.grid(row=0, column=1) self.metadata_entry.grid(row=0, column=1)
frame2.grid(row=1, column=0) frame2.grid(row=1, column=0)
@ -78,7 +105,11 @@ class ServiceConfiguration(Dialog):
label.grid(row=0, column=0) label.grid(row=0, column=0)
self.filename_combobox = ttk.Combobox(frame, values=self.filenames) self.filename_combobox = ttk.Combobox(frame, values=self.filenames)
self.filename_combobox.grid(row=0, column=1) self.filename_combobox.grid(row=0, column=1)
if len(self.filenames) > 0:
self.filename_combobox.current(0) self.filename_combobox.current(0)
self.filename_combobox.bind(
"<<ComboboxSelected>>", self.display_service_file_data
)
button = ttk.Button(frame, image=self.documentnew_img) button = ttk.Button(frame, image=self.documentnew_img)
button.bind("<Button-1>", self.add_filename) button.bind("<Button-1>", self.add_filename)
button.grid(row=0, column=2) button.grid(row=0, column=2)
@ -134,10 +165,14 @@ class ServiceConfiguration(Dialog):
label_frame = None label_frame = None
if i == 0: if i == 0:
label_frame = ttk.LabelFrame(tab3, text="Startup commands") label_frame = ttk.LabelFrame(tab3, text="Startup commands")
commands = self.startup_commands
elif i == 1: elif i == 1:
label_frame = ttk.LabelFrame(tab3, text="Shutdown commands") label_frame = ttk.LabelFrame(tab3, text="Shutdown commands")
commands = self.shutdown_commands
elif i == 2: elif i == 2:
label_frame = ttk.LabelFrame(tab3, text="Validation commands") label_frame = ttk.LabelFrame(tab3, text="Validation commands")
commands = self.validation_commands
label_frame.columnconfigure(0, weight=1) label_frame.columnconfigure(0, weight=1)
frame = ttk.Frame(label_frame) frame = ttk.Frame(label_frame)
frame.columnconfigure(0, weight=1) frame.columnconfigure(0, weight=1)
@ -152,6 +187,8 @@ class ServiceConfiguration(Dialog):
frame.grid(row=0, column=0, sticky="nsew") frame.grid(row=0, column=0, sticky="nsew")
listbox_scroll = ListboxScroll(label_frame) listbox_scroll = ListboxScroll(label_frame)
listbox_scroll.listbox.bind("<<ListboxSelect>>", self.update_entry) listbox_scroll.listbox.bind("<<ListboxSelect>>", self.update_entry)
for command in commands:
listbox_scroll.listbox.insert("end", command)
listbox_scroll.listbox.config(height=4) listbox_scroll.listbox.config(height=4)
listbox_scroll.grid(row=1, column=0, sticky="nsew") listbox_scroll.grid(row=1, column=0, sticky="nsew")
if i == 0: if i == 0:
@ -164,29 +201,56 @@ class ServiceConfiguration(Dialog):
# tab 4 # tab 4
for i in range(2): for i in range(2):
label_frame = None
if i == 0: if i == 0:
label_frame = ttk.LabelFrame(tab4, text="Executables") label_frame = ttk.LabelFrame(tab4, text="Executables")
elif i == 1: elif i == 1:
label_frame = ttk.LabelFrame(tab4, text="Dependencies") label_frame = ttk.LabelFrame(tab4, text="Dependencies")
label_frame.columnconfigure(0, weight=1) label_frame.columnconfigure(0, weight=1)
listbox_scroll = ListboxScroll(label_frame) listbox_scroll = ListboxScroll(label_frame)
listbox_scroll.listbox.config(height=4, state="disabled") listbox_scroll.listbox.config(height=4)
listbox_scroll.grid(row=0, column=0, sticky="nsew") listbox_scroll.grid(row=0, column=0, sticky="nsew")
label_frame.grid(row=i, column=0, sticky="nsew") label_frame.grid(row=i, column=0, sticky="nsew")
if i == 0:
for executable in self.executables:
print(executable)
listbox_scroll.listbox.insert("end", executable)
if i == 1:
for dependency in self.dependencies:
listbox_scroll.listbox.insert("end", dependency)
for i in range(3): for i in range(3):
frame = ttk.Frame(tab4) frame = ttk.Frame(tab4)
frame.columnconfigure(0, weight=1) frame.columnconfigure(0, weight=1)
if i == 0: if i == 0:
label = ttk.Label(frame, text="Validation time:") label = ttk.Label(frame, text="Validation time:")
self.validation_time_entry = ttk.Entry(
frame,
state="disabled",
textvariable=tk.StringVar(value=self.validation_time),
)
self.validation_time_entry.grid(row=i, column=1)
elif i == 1: elif i == 1:
label = ttk.Label(frame, text="Validation mode:") label = ttk.Label(frame, text="Validation mode:")
if self.validation_mode == core_pb2.ServiceValidationMode.BLOCKING:
mode = "BLOCKING"
elif (
self.validation_mode == core_pb2.ServiceValidationMode.NON_BLOCKING
):
mode = "NON_BLOCKING"
elif self.validation_mode == core_pb2.ServiceValidationMode.TIMER:
mode = "TIMER"
self.validation_mode_entry = ttk.Entry(
frame, state="disabled", textvariable=tk.StringVar(value=mode)
)
self.validation_mode_entry.grid(row=i, column=1)
elif i == 2: elif i == 2:
label = ttk.Label(frame, text="Validation period:") label = ttk.Label(frame, text="Validation period:")
self.validation_period_entry = ttk.Entry(
frame, state="disabled", textvariable=tk.StringVar()
)
self.validation_period_entry.grid(row=i, column=1)
label.grid(row=i, column=0) label.grid(row=i, column=0)
entry = ttk.Entry(frame, state="disabled", textvariable=tk.StringVar())
entry.grid(row=i, column=1)
frame.grid(row=2 + i, column=0, sticky="nsew") frame.grid(row=2 + i, column=0, sticky="nsew")
button = ttk.Button( button = ttk.Button(
@ -262,6 +326,13 @@ class ServiceConfiguration(Dialog):
startup_commands = self.startup_commands_listbox.get(0, "end") startup_commands = self.startup_commands_listbox.get(0, "end")
shutdown_commands = self.shutdown_commands_listbox.get(0, "end") shutdown_commands = self.shutdown_commands_listbox.get(0, "end")
validate_commands = self.validate_commands_listbox.get(0, "end") validate_commands = self.validate_commands_listbox.get(0, "end")
self.app.core.serviceconfig_manager.node_service_custom_configuration(
self.canvas_node.core_id,
self.service_name,
startup_commands,
validate_commands,
shutdown_commands,
)
logging.info( logging.info(
"%s, %s, %s, %s, %s", "%s, %s, %s, %s, %s",
metadata, metadata,
@ -270,6 +341,13 @@ class ServiceConfiguration(Dialog):
shutdown_commands, shutdown_commands,
validate_commands, validate_commands,
) )
# wipe nodes and links when finished by setting to DEFINITION state
self.app.core.client.set_session_state(
self.app.core.session_id, core_pb2.SessionState.DEFINITION
)
def display_service_file_data(self, event):
print("not implemented")
def click_defaults(self): def click_defaults(self):
logging.info("not implemented") logging.info("not implemented")

View file

@ -35,3 +35,15 @@ class ServiceNodeConfig:
response, response,
) )
self.configurations[node_id][default] = response.service self.configurations[node_id][default] = response.service
def node_custom_service_configuration(self, node_id, service_name):
return
def node_service_custom_configuration(
self, node_id, service_name, startups, validates, shutdowns
):
self.app.core.set_node_service(
node_id, service_name, startups, validates, shutdowns
)
config = self.app.core.get_node_service(node_id, service_name)
self.configurations[node_id][service_name] = config