112 lines
2.8 KiB
Lua
112 lines
2.8 KiB
Lua
--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.."/persistmods/start?nodetype=".."\""..nodetype.."\"".."&nodename=".."\""..nodename.."\""
|
|
|
|
if (args ~= nil) then
|
|
msg = msg .."&args=\""..args.."\""
|
|
end
|
|
|
|
|
|
local response, code, headers = easyhttp.request(msg)
|
|
|
|
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.."/persistmods/execute?nodename=".."\""..nodename.."\"")
|
|
local response, code, headers = easyhttp.request("https://"..host.."/persistmods/execute?nodename=".."\""..nodename.."\"")
|
|
|
|
end
|
|
|
|
|
|
function node_get_logs(child)
|
|
for a, b in pairs(live_nodes) do
|
|
msg="https://"..b.."//persistmods/get_logs?nodename=".."\""..a.."\""
|
|
local response, code, headers = easyhttp.request(msg)
|
|
print)msg)
|
|
end
|
|
local file = io.open("logfil.txt", "w") -- "w" means write (overwrite)
|
|
file:write(response)
|
|
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.."/persistsmods/stop?nodename=".."\""..nodename.."\"")
|
|
local response, code, headers = easyhttp.request("https://"..host.."/persistsmods/stop?nodename=".."\""..nodename.."\"")
|
|
|
|
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("<root>"..xml_string.."</root>")
|
|
--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
|