commit 09d2c141f3442bafbca1718705fdcd19c0da765e Author: Morten V. Christiansen Date: Mon Sep 8 23:20:23 2025 -0400 initial diff --git a/Controller.lua b/Controller.lua new file mode 100644 index 0000000..66a616f --- /dev/null +++ b/Controller.lua @@ -0,0 +1,111 @@ +--controller +local lxp = require("lxp") +local lom = require("lxp.lom") +local inspect = require "inspect" +local easyhttp = require("easyhttp") +local urlencode = require("urlencode") + +local _ENV=require "std.strict" (_G) + +local live_nodes = {} + +function node_start(child) + local host = child.attr.host + local nodetype = child.attr.nodetype + local nodename = child.attr.nodename + local args = child.attr.args --may be nil + + local msg = "https://"..host.."/_django_App_start?nodetype=".."\""..nodetype.."\"".."?nodename=".."\""..nodename.."\"" + + if (args ~= nil) then + msg = msg .."?args=\""..args.."\"" + end + + +local response, code, headers = easyhttp.request(msg) +#print(response) +#print(code) +#print(headers) + + print( msg) + --send & handle resp + live_nodes[nodename]=host +end + + +function node_execute(child) + local nodename=child.attr.nodename + local host=live_nodes[nodename] + + print ("https://"..host.."/_django_App_execute?nodename=".."\""..nodename.."\"") + local response, code, headers = easyhttp.request(msg) +end + + +function node_get_logs(child) + for a, b in pairs(live_nodes) do + print ("https://"..b.."/_django_App_get_logs?nodename=".."\""..a.."\"") + end + local file = io.open("logfil.txt", "w") -- "w" means write (overwrite) + file:write("Test OK") + file:close() +end + + +function node_check_test(child) + local file = io.open("logfil.txt", "r") + print(file:read("*a")) +end + + +function node_close(child) + local nodename=child.attr.nodename + local host=live_nodes[nodename] + print ("https://"..host.."/_django_App_close?nodename=".."\""..nodename.."\"") + local response, code, headers = easyhttp.request(msg) + +end + + + + function exec_child(child) + if (child.tag == "notetool-node-start") then + node_start(child) + elseif (child.tag == "notetool-node-execute") then + node_execute(child) + elseif (child.tag == "notetool-get-logs") then + node_get_logs(child) + elseif (child.tag == "nodetool-check-test") then + node_check_test(child) + elseif (child.tag == "nodetool-close-node") then + node_close(child) + end +end + +--start +local filename +if (#arg<1) then + filename="commands.xml" +else + filename=arg[1] +end + +--load data from filename +local xml_file = io.open(filename,"r") +local xml_string = xml_file:read("*a") +xml_file:close() +local xml_string = xml_string:gsub("[\r\n]", "") + +local xml_tree = lom.parse(""..xml_string.."") +--print (inspect(xml_tree)) + +--now we have the xml iń an object. work through it +for i, child in ipairs(xml_tree) do + if type(child) == "table" then + --print("Child tag:", child.tag) + exec_child(child) + --for k, v in pairs(child.attr) do + --print(" -", k, v) + --end + end +end diff --git a/commands.xml b/commands.xml new file mode 100644 index 0000000..8e5b9e4 --- /dev/null +++ b/commands.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/logfil.txt b/logfil.txt new file mode 100644 index 0000000..d58f86d --- /dev/null +++ b/logfil.txt @@ -0,0 +1 @@ +Test OK \ No newline at end of file