1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2025-01-18 13:49:29 +00:00

renamed REQnCliCommandCont to REQCliCommandCont

This commit is contained in:
postmannen 2021-09-17 10:17:10 +02:00
parent 855275d19f
commit 054455b857
8 changed files with 86 additions and 89 deletions

View file

@ -46,11 +46,10 @@ ENV START_SUB_REQ_TO_FILE ""
ENV START_SUB_REQ_PING "" ENV START_SUB_REQ_PING ""
ENV START_SUB_REQ_PONG "" ENV START_SUB_REQ_PONG ""
ENV START_SUB_REQ_CLI_COMMAND "" ENV START_SUB_REQ_CLI_COMMAND ""
ENV START_SUB_REQN_CLI_COMMAND ""
ENV START_SUB_REQ_TO_CONSOLE "" ENV START_SUB_REQ_TO_CONSOLE ""
ENV START_SUB_REQ_HTTP_GET "" ENV START_SUB_REQ_HTTP_GET ""
ENV START_SUB_REQ_TAIL_FILE "" ENV START_SUB_REQ_TAIL_FILE ""
ENV START_SUB_REQ_N_CLI_COMMAND_CONT "" ENV START_SUB_REQ_CLI_COMMAND_CONT ""
CMD ["ash","-c","env CONFIGFOLDER=./etc/ /app/steward\ CMD ["ash","-c","env CONFIGFOLDER=./etc/ /app/steward\
-socketFolder=$SOCKET_FOLDER\ -socketFolder=$SOCKET_FOLDER\
@ -79,9 +78,8 @@ CMD ["ash","-c","env CONFIGFOLDER=./etc/ /app/steward\
-startSubREQPing=$START_SUB_REQ_PING\ -startSubREQPing=$START_SUB_REQ_PING\
-startSubREQPong=$START_SUB_REQ_PONG\ -startSubREQPong=$START_SUB_REQ_PONG\
-startSubREQCliCommand=$START_SUB_REQ_CLI_COMMAND\ -startSubREQCliCommand=$START_SUB_REQ_CLI_COMMAND\
-startSubREQnCliCommand=$START_SUB_REQN_CLI_COMMAND\
-startSubREQToConsole=$START_SUB_REQ_TO_CONSOLE\ -startSubREQToConsole=$START_SUB_REQ_TO_CONSOLE\
-startSubREQHttpGet=$START_SUB_REQ_HTTP_GET\ -startSubREQHttpGet=$START_SUB_REQ_HTTP_GET\
-startSubREQTailFile=$START_SUB_REQ_TAIL_FILE\ -startSubREQTailFile=$START_SUB_REQ_TAIL_FILE\
-startSubREQnCliCommandCont=$START_SUB_REQ_N_CLI_COMMAND_CONT\ -startSubREQCliCommandCont=$START_SUB_REQ_CLI_COMMAND_CONT\
"] "]

View file

@ -21,7 +21,7 @@ The idea behind Steward is to help out with exactly that, and let you handle the
- [Flags and configuration file](#flags-and-configuration-file) - [Flags and configuration file](#flags-and-configuration-file)
- [Request Methods](#request-methods) - [Request Methods](#request-methods)
- [REQCliCommand](#reqclicommand) - [REQCliCommand](#reqclicommand)
- [REQnCliCommandCont](#reqnclicommandcont) - [REQCliCommandCont](#reqclicommandcont)
- [REQTailFile](#reqtailfile) - [REQTailFile](#reqtailfile)
- [REQHttpGet](#reqhttpget) - [REQHttpGet](#reqhttpget)
- [REQHello](#reqhello) - [REQHello](#reqhello)
@ -200,7 +200,7 @@ Run CLI command on a node. Linux/Windows/Mac/Docker-container or other.
Will run the command given, and return the stdout output of the command when the command is done. Will run the command given, and return the stdout output of the command when the command is done.
#### REQnCliCommandCont #### REQCliCommandCont
Run CLI command on a node. Linux/Windows/Mac/Docker-container or other. Run CLI command on a node. Linux/Windows/Mac/Docker-container or other.
@ -329,7 +329,7 @@ The location of the config file are given via an env variable at startup (defaul
// Subscriber for tailing log files // Subscriber for tailing log files
StartSubREQTailFile bool StartSubREQTailFile bool
// Subscriber for continously delivery of output from cli commands. // Subscriber for continously delivery of output from cli commands.
StartSubREQnCliCommandCont bool StartSubREQCliCommandCont bool
``` ```
### How to Run ### How to Run
@ -554,7 +554,7 @@ and another example
"operation":{ "operation":{
"opCmd":"startProc", "opCmd":"startProc",
"opArg": { "opArg": {
"method": "REQnCliCommandCont", "method": "REQCliCommandCont",
"allowedNodes": ["central"] "allowedNodes": ["central"]
} }
}, },

View file

@ -79,7 +79,7 @@ type Configuration struct {
// Subscriber for tailing log files // Subscriber for tailing log files
StartSubREQTailFile bool StartSubREQTailFile bool
// Subscriber for continously delivery of output from cli commands. // Subscriber for continously delivery of output from cli commands.
StartSubREQnCliCommandCont bool StartSubREQCliCommandCont bool
} }
// ConfigurationFromFile should have the same structure as // ConfigurationFromFile should have the same structure as
@ -114,11 +114,10 @@ type ConfigurationFromFile struct {
StartSubREQPing *bool StartSubREQPing *bool
StartSubREQPong *bool StartSubREQPong *bool
StartSubREQCliCommand *bool StartSubREQCliCommand *bool
StartSubREQnCliCommand *bool
StartSubREQToConsole *bool StartSubREQToConsole *bool
StartSubREQHttpGet *bool StartSubREQHttpGet *bool
StartSubREQTailFile *bool StartSubREQTailFile *bool
StartSubREQnCliCommandCont *bool StartSubREQCliCommandCont *bool
} }
// NewConfiguration will return a *Configuration. // NewConfiguration will return a *Configuration.
@ -160,7 +159,7 @@ func newConfigurationDefaults() Configuration {
StartSubREQToConsole: true, StartSubREQToConsole: true,
StartSubREQHttpGet: true, StartSubREQHttpGet: true,
StartSubREQTailFile: true, StartSubREQTailFile: true,
StartSubREQnCliCommandCont: true, StartSubREQCliCommandCont: true,
} }
return c return c
} }
@ -321,10 +320,10 @@ func checkConfigValues(cf ConfigurationFromFile) Configuration {
} else { } else {
conf.StartSubREQTailFile = *cf.StartSubREQTailFile conf.StartSubREQTailFile = *cf.StartSubREQTailFile
} }
if cf.StartSubREQnCliCommandCont == nil { if cf.StartSubREQCliCommandCont == nil {
conf.StartSubREQnCliCommandCont = cd.StartSubREQnCliCommandCont conf.StartSubREQCliCommandCont = cd.StartSubREQCliCommandCont
} else { } else {
conf.StartSubREQnCliCommandCont = *cf.StartSubREQnCliCommandCont conf.StartSubREQCliCommandCont = *cf.StartSubREQCliCommandCont
} }
return conf return conf
@ -390,7 +389,7 @@ func (c *Configuration) CheckFlags() error {
flag.BoolVar(&c.StartSubREQToConsole, "startSubREQToConsole", fc.StartSubREQToConsole, "true/false") flag.BoolVar(&c.StartSubREQToConsole, "startSubREQToConsole", fc.StartSubREQToConsole, "true/false")
flag.BoolVar(&c.StartSubREQHttpGet, "startSubREQHttpGet", fc.StartSubREQHttpGet, "true/false") flag.BoolVar(&c.StartSubREQHttpGet, "startSubREQHttpGet", fc.StartSubREQHttpGet, "true/false")
flag.BoolVar(&c.StartSubREQTailFile, "startSubREQTailFile", fc.StartSubREQTailFile, "true/false") flag.BoolVar(&c.StartSubREQTailFile, "startSubREQTailFile", fc.StartSubREQTailFile, "true/false")
flag.BoolVar(&c.StartSubREQnCliCommandCont, "startSubREQnCliCommandCont", fc.StartSubREQnCliCommandCont, "true/false") flag.BoolVar(&c.StartSubREQCliCommandCont, "startSubREQCliCommandCont", fc.StartSubREQCliCommandCont, "true/false")
flag.Parse() flag.Parse()

View file

@ -5,7 +5,7 @@
"toNode": "ship1", "toNode": "ship1",
"data": ["bash","-c","tree ../"], "data": ["bash","-c","tree ../"],
"replyMethod":"REQToFileAppend", "replyMethod":"REQToFileAppend",
"method":"REQnCliCommand", "method":"REQCliCommand",
"ACKTimeout":3, "ACKTimeout":3,
"retries":3, "retries":3,
"methodTimeout": 10 "methodTimeout": 10

View file

@ -116,8 +116,8 @@ func (p *processes) Start(proc process) {
proc.startup.subREQTailFile(proc) proc.startup.subREQTailFile(proc)
} }
if proc.configuration.StartSubREQnCliCommandCont { if proc.configuration.StartSubREQCliCommandCont {
proc.startup.subREQnCliCommandCont(proc) proc.startup.subREQCliCommandCont(proc)
} }
proc.startup.subREQToSocket(proc) proc.startup.subREQToSocket(proc)
@ -299,9 +299,9 @@ func (s startup) subREQTailFile(p process) {
go proc.spawnWorker(p.processes, p.natsConn) go proc.spawnWorker(p.processes, p.natsConn)
} }
func (s startup) subREQnCliCommandCont(p process) { func (s startup) subREQCliCommandCont(p process) {
log.Printf("Starting cli command with continous delivery: %#v\n", p.node) log.Printf("Starting cli command with continous delivery: %#v\n", p.node)
sub := newSubject(REQnCliCommandCont, string(p.node)) sub := newSubject(REQCliCommandCont, string(p.node))
proc := newProcess(p.ctx, s.metrics, p.natsConn, p.processes, p.toRingbufferCh, p.configuration, sub, p.errorCh, processKindSubscriber, nil) proc := newProcess(p.ctx, s.metrics, p.natsConn, p.processes, p.toRingbufferCh, p.configuration, sub, p.errorCh, processKindSubscriber, nil)
// fmt.Printf("*** %#v\n", proc) // fmt.Printf("*** %#v\n", proc)
go proc.spawnWorker(p.processes, p.natsConn) go proc.spawnWorker(p.processes, p.natsConn)

View file

@ -296,7 +296,7 @@ func newSubjectAndMessage(m Message) (subjectAndMessage, error) {
tmpH := mt.getHandler(m.Method) tmpH := mt.getHandler(m.Method)
if tmpH == nil { if tmpH == nil {
return subjectAndMessage{}, fmt.Errorf("error: method value did not exist in map") return subjectAndMessage{}, fmt.Errorf("error: no such request type defined: %v", tmpH)
} }
sub := Subject{ sub := Subject{

View file

@ -73,11 +73,11 @@ const (
// The data field is a slice of strings where the first string // The data field is a slice of strings where the first string
// value should be the command, and the following the arguments. // value should be the command, and the following the arguments.
REQCliCommand Method = "REQCliCommand" REQCliCommand Method = "REQCliCommand"
// REQnCliCommandCont same as normal Cli command, but can be used // REQCliCommandCont same as normal Cli command, but can be used
// when running a command that will take longer time and you want // when running a command that will take longer time and you want
// to send the output of the command continually back as it is // to send the output of the command continually back as it is
// generated, and not just when the command is finished. // generated, and not wait until the command is finished.
REQnCliCommandCont Method = "REQnCliCommandCont" REQCliCommandCont Method = "REQCliCommandCont"
// Send text to be logged to the console. // Send text to be logged to the console.
// The data field is a slice of strings where the first string // The data field is a slice of strings where the first string
// value should be the command, and the following the arguments. // value should be the command, and the following the arguments.
@ -137,7 +137,7 @@ func (m Method) GetMethodsAvailable() MethodsAvailable {
REQCliCommand: methodREQCliCommand{ REQCliCommand: methodREQCliCommand{
commandOrEvent: CommandACK, commandOrEvent: CommandACK,
}, },
REQnCliCommandCont: methodREQnCliCommandCont{ REQCliCommandCont: methodREQCliCommandCont{
commandOrEvent: CommandACK, commandOrEvent: CommandACK,
}, },
REQToConsole: methodREQToConsole{ REQToConsole: methodREQToConsole{
@ -1089,19 +1089,19 @@ func (m methodREQTailFile) handler(proc process, message Message, node string) (
} }
// --- // ---
type methodREQnCliCommandCont struct { type methodREQCliCommandCont struct {
commandOrEvent CommandOrEvent commandOrEvent CommandOrEvent
} }
func (m methodREQnCliCommandCont) getKind() CommandOrEvent { func (m methodREQCliCommandCont) getKind() CommandOrEvent {
return m.commandOrEvent return m.commandOrEvent
} }
// Handler to run REQnCliCommandCont, which is the same as normal // Handler to run REQCliCommandCont, which is the same as normal
// Cli command, but can be used when running a command that will take // Cli command, but can be used when running a command that will take
// longer time and you want to send the output of the command continually // longer time and you want to send the output of the command continually
// back as it is generated, and not just when the command is finished. // back as it is generated, and not just when the command is finished.
func (m methodREQnCliCommandCont) handler(proc process, message Message, node string) ([]byte, error) { func (m methodREQCliCommandCont) handler(proc process, message Message, node string) ([]byte, error) {
log.Printf("<--- CLInCommandCont REQUEST received from: %v, containing: %v", message.FromNode, message.Data) log.Printf("<--- CLInCommandCont REQUEST received from: %v, containing: %v", message.FromNode, message.Data)
// Execute the CLI command in it's own go routine, so we are able // Execute the CLI command in it's own go routine, so we are able
@ -1129,7 +1129,7 @@ func (m methodREQnCliCommandCont) handler(proc process, message Message, node st
// able to read the out put of the command. // able to read the out put of the command.
outReader, err := cmd.StdoutPipe() outReader, err := cmd.StdoutPipe()
if err != nil { if err != nil {
er := fmt.Errorf("error: methodREQnCliCommandCont: cmd.StdoutPipe failed : %v, message: %v", err, message) er := fmt.Errorf("error: methodREQCliCommandCont: cmd.StdoutPipe failed : %v, message: %v", err, message)
sendErrorLogMessage(proc.configuration, proc.processes.metrics, proc.toRingbufferCh, proc.node, er) sendErrorLogMessage(proc.configuration, proc.processes.metrics, proc.toRingbufferCh, proc.node, er)
log.Printf("%v\n", er) log.Printf("%v\n", er)
@ -1138,7 +1138,7 @@ func (m methodREQnCliCommandCont) handler(proc process, message Message, node st
ErrorReader, err := cmd.StderrPipe() ErrorReader, err := cmd.StderrPipe()
if err != nil { if err != nil {
er := fmt.Errorf("error: methodREQnCliCommandCont: cmd.StderrPipe failed : %v, message: %v", err, message) er := fmt.Errorf("error: methodREQCliCommandCont: cmd.StderrPipe failed : %v, message: %v", err, message)
sendErrorLogMessage(proc.configuration, proc.processes.metrics, proc.toRingbufferCh, proc.node, er) sendErrorLogMessage(proc.configuration, proc.processes.metrics, proc.toRingbufferCh, proc.node, er)
log.Printf("%v\n", er) log.Printf("%v\n", er)
@ -1146,7 +1146,7 @@ func (m methodREQnCliCommandCont) handler(proc process, message Message, node st
} }
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
er := fmt.Errorf("error: methodREQnCliCommandCont: cmd.Start failed : %v, message: %v", err, message) er := fmt.Errorf("error: methodREQCliCommandCont: cmd.Start failed : %v, message: %v", err, message)
sendErrorLogMessage(proc.configuration, proc.processes.metrics, proc.toRingbufferCh, proc.node, er) sendErrorLogMessage(proc.configuration, proc.processes.metrics, proc.toRingbufferCh, proc.node, er)
log.Printf("%v\n", er) log.Printf("%v\n", er)
@ -1163,7 +1163,7 @@ func (m methodREQnCliCommandCont) handler(proc process, message Message, node st
for scanner.Scan() { for scanner.Scan() {
select { select {
case errCh <- scanner.Text(): case errCh <- scanner.Text():
er := fmt.Errorf("error: methodREQnCliCommandCont: cmd.Start failed : %v, message: %v, error_output: %v", err, message, <-errCh) er := fmt.Errorf("error: methodREQCliCommandCont: cmd.Start failed : %v, message: %v, error_output: %v", err, message, <-errCh)
sendErrorLogMessage(proc.configuration, proc.processes.metrics, proc.toRingbufferCh, proc.node, er) sendErrorLogMessage(proc.configuration, proc.processes.metrics, proc.toRingbufferCh, proc.node, er)
log.Printf("%v\n", er) log.Printf("%v\n", er)
case <-ctx.Done(): case <-ctx.Done():
@ -1189,7 +1189,7 @@ func (m methodREQnCliCommandCont) handler(proc process, message Message, node st
select { select {
case <-ctx.Done(): case <-ctx.Done():
cancel() cancel()
er := fmt.Errorf("info: methodREQnCliCommandCont: method timeout reached, canceling: %v", message) er := fmt.Errorf("info: methodREQCliCommandCont: method timeout reached, canceling: %v", message)
sendErrorLogMessage(proc.configuration, proc.processes.metrics, proc.toRingbufferCh, proc.node, er) sendErrorLogMessage(proc.configuration, proc.processes.metrics, proc.toRingbufferCh, proc.node, er)
return return
case out := <-outCh: case out := <-outCh:

View file

@ -56,7 +56,7 @@ func TestStewardServer(t *testing.T) {
DefaultMessageTimeout: 3, DefaultMessageTimeout: 3,
StartSubREQCliCommand: true, StartSubREQCliCommand: true,
StartSubREQnCliCommandCont: true, StartSubREQCliCommandCont: true,
StartSubREQToConsole: true, StartSubREQToConsole: true,
StartSubREQToFileAppend: true, StartSubREQToFileAppend: true,
StartSubREQToFile: true, StartSubREQToFile: true,
@ -82,7 +82,7 @@ func TestStewardServer(t *testing.T) {
funcs := []testFunc{ funcs := []testFunc{
checkREQOpCommandTest, checkREQOpCommandTest,
checkREQCliCommandTest, checkREQCliCommandTest,
checkREQnCliCommandContTest, checkREQCliCommandContTest,
// checkREQToConsoleTest(conf, t), NB: No tests will be made for console ouput. // checkREQToConsoleTest(conf, t), NB: No tests will be made for console ouput.
// checkREQToFileAppendTest(conf, t), NB: Already tested via others // checkREQToFileAppendTest(conf, t), NB: Already tested via others
// checkREQToFileTest(conf, t), NB: Already tested via others // checkREQToFileTest(conf, t), NB: Already tested via others
@ -176,7 +176,7 @@ func checkREQCliCommandTest(stewardServer *server, conf *Configuration, t *testi
} }
// The continous non-sequential sending of CLI Commands. // The continous non-sequential sending of CLI Commands.
func checkREQnCliCommandContTest(stewardServer *server, conf *Configuration, t *testing.T) error { func checkREQCliCommandContTest(stewardServer *server, conf *Configuration, t *testing.T) error {
m := `[ m := `[
{ {
"directory":"commands-executed", "directory":"commands-executed",
@ -184,7 +184,7 @@ func checkREQnCliCommandContTest(stewardServer *server, conf *Configuration, t *
"toNode": "central", "toNode": "central",
"data": ["bash","-c","echo apekatt && sleep 5 && echo gris"], "data": ["bash","-c","echo apekatt && sleep 5 && echo gris"],
"replyMethod":"REQToFileAppend", "replyMethod":"REQToFileAppend",
"method":"REQnCliCommandCont", "method":"REQCliCommandCont",
"ACKTimeout":3, "ACKTimeout":3,
"retries":3, "retries":3,
"methodTimeout": 5 "methodTimeout": 5
@ -196,10 +196,10 @@ func checkREQnCliCommandContTest(stewardServer *server, conf *Configuration, t *
resultFile := filepath.Join(conf.SubscribersDataFolder, "commands-executed", "central", "fileName.result") resultFile := filepath.Join(conf.SubscribersDataFolder, "commands-executed", "central", "fileName.result")
_, err := findStringInFileTest("apekatt", resultFile, conf, t) _, err := findStringInFileTest("apekatt", resultFile, conf, t)
if err != nil { if err != nil {
return fmt.Errorf(" [FAILED] : checkREQnCliCommandContTest: %v", err) return fmt.Errorf(" [FAILED] : checkREQCliCommandContTest: %v", err)
} }
t.Logf(" \U0001f600 [SUCCESS] : checkREQnCliCommandContTest\n") t.Logf(" \U0001f600 [SUCCESS] : checkREQCliCommandContTest\n")
return nil return nil
} }