mirror of
https://github.com/postmannen/ctrl.git
synced 2024-12-14 12:37:31 +00:00
renamed REQnCliCommandCont to REQCliCommandCont
This commit is contained in:
parent
855275d19f
commit
054455b857
8 changed files with 86 additions and 89 deletions
|
@ -46,11 +46,10 @@ ENV START_SUB_REQ_TO_FILE ""
|
|||
ENV START_SUB_REQ_PING ""
|
||||
ENV START_SUB_REQ_PONG ""
|
||||
ENV START_SUB_REQ_CLI_COMMAND ""
|
||||
ENV START_SUB_REQN_CLI_COMMAND ""
|
||||
ENV START_SUB_REQ_TO_CONSOLE ""
|
||||
ENV START_SUB_REQ_HTTP_GET ""
|
||||
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\
|
||||
-socketFolder=$SOCKET_FOLDER\
|
||||
|
@ -79,9 +78,8 @@ CMD ["ash","-c","env CONFIGFOLDER=./etc/ /app/steward\
|
|||
-startSubREQPing=$START_SUB_REQ_PING\
|
||||
-startSubREQPong=$START_SUB_REQ_PONG\
|
||||
-startSubREQCliCommand=$START_SUB_REQ_CLI_COMMAND\
|
||||
-startSubREQnCliCommand=$START_SUB_REQN_CLI_COMMAND\
|
||||
-startSubREQToConsole=$START_SUB_REQ_TO_CONSOLE\
|
||||
-startSubREQHttpGet=$START_SUB_REQ_HTTP_GET\
|
||||
-startSubREQTailFile=$START_SUB_REQ_TAIL_FILE\
|
||||
-startSubREQnCliCommandCont=$START_SUB_REQ_N_CLI_COMMAND_CONT\
|
||||
-startSubREQCliCommandCont=$START_SUB_REQ_CLI_COMMAND_CONT\
|
||||
"]
|
||||
|
|
|
@ -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)
|
||||
- [Request Methods](#request-methods)
|
||||
- [REQCliCommand](#reqclicommand)
|
||||
- [REQnCliCommandCont](#reqnclicommandcont)
|
||||
- [REQCliCommandCont](#reqclicommandcont)
|
||||
- [REQTailFile](#reqtailfile)
|
||||
- [REQHttpGet](#reqhttpget)
|
||||
- [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.
|
||||
|
||||
#### REQnCliCommandCont
|
||||
#### REQCliCommandCont
|
||||
|
||||
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
|
||||
StartSubREQTailFile bool
|
||||
// Subscriber for continously delivery of output from cli commands.
|
||||
StartSubREQnCliCommandCont bool
|
||||
StartSubREQCliCommandCont bool
|
||||
```
|
||||
|
||||
### How to Run
|
||||
|
@ -554,7 +554,7 @@ and another example
|
|||
"operation":{
|
||||
"opCmd":"startProc",
|
||||
"opArg": {
|
||||
"method": "REQnCliCommandCont",
|
||||
"method": "REQCliCommandCont",
|
||||
"allowedNodes": ["central"]
|
||||
}
|
||||
},
|
||||
|
|
|
@ -79,7 +79,7 @@ type Configuration struct {
|
|||
// Subscriber for tailing log files
|
||||
StartSubREQTailFile bool
|
||||
// Subscriber for continously delivery of output from cli commands.
|
||||
StartSubREQnCliCommandCont bool
|
||||
StartSubREQCliCommandCont bool
|
||||
}
|
||||
|
||||
// ConfigurationFromFile should have the same structure as
|
||||
|
@ -87,38 +87,37 @@ type Configuration struct {
|
|||
// configuration values from file, so we are able to detect
|
||||
// if a value were given or not when parsing.
|
||||
type ConfigurationFromFile struct {
|
||||
ConfigFolder *string
|
||||
SocketFolder *string
|
||||
TCPListener *string
|
||||
HTTPListener *string
|
||||
DatabaseFolder *string
|
||||
NodeName *string
|
||||
BrokerAddress *string
|
||||
NatsConnectRetryInterval *int
|
||||
ProfilingPort *string
|
||||
PromHostAndPort *string
|
||||
DefaultMessageTimeout *int
|
||||
DefaultMessageRetries *int
|
||||
SubscribersDataFolder *string
|
||||
CentralNodeName *string
|
||||
RootCAPath *string
|
||||
NkeySeedFile *string
|
||||
ExposeDataFolder *string
|
||||
ErrorMessageTimeout *int
|
||||
ErrorMessageRetries *int
|
||||
StartPubREQHello *int
|
||||
StartSubREQErrorLog *bool
|
||||
StartSubREQHello *bool
|
||||
StartSubREQToFileAppend *bool
|
||||
StartSubREQToFile *bool
|
||||
StartSubREQPing *bool
|
||||
StartSubREQPong *bool
|
||||
StartSubREQCliCommand *bool
|
||||
StartSubREQnCliCommand *bool
|
||||
StartSubREQToConsole *bool
|
||||
StartSubREQHttpGet *bool
|
||||
StartSubREQTailFile *bool
|
||||
StartSubREQnCliCommandCont *bool
|
||||
ConfigFolder *string
|
||||
SocketFolder *string
|
||||
TCPListener *string
|
||||
HTTPListener *string
|
||||
DatabaseFolder *string
|
||||
NodeName *string
|
||||
BrokerAddress *string
|
||||
NatsConnectRetryInterval *int
|
||||
ProfilingPort *string
|
||||
PromHostAndPort *string
|
||||
DefaultMessageTimeout *int
|
||||
DefaultMessageRetries *int
|
||||
SubscribersDataFolder *string
|
||||
CentralNodeName *string
|
||||
RootCAPath *string
|
||||
NkeySeedFile *string
|
||||
ExposeDataFolder *string
|
||||
ErrorMessageTimeout *int
|
||||
ErrorMessageRetries *int
|
||||
StartPubREQHello *int
|
||||
StartSubREQErrorLog *bool
|
||||
StartSubREQHello *bool
|
||||
StartSubREQToFileAppend *bool
|
||||
StartSubREQToFile *bool
|
||||
StartSubREQPing *bool
|
||||
StartSubREQPong *bool
|
||||
StartSubREQCliCommand *bool
|
||||
StartSubREQToConsole *bool
|
||||
StartSubREQHttpGet *bool
|
||||
StartSubREQTailFile *bool
|
||||
StartSubREQCliCommandCont *bool
|
||||
}
|
||||
|
||||
// NewConfiguration will return a *Configuration.
|
||||
|
@ -150,17 +149,17 @@ func newConfigurationDefaults() Configuration {
|
|||
ErrorMessageTimeout: 60,
|
||||
ErrorMessageRetries: 10,
|
||||
|
||||
StartSubREQErrorLog: true,
|
||||
StartSubREQHello: true,
|
||||
StartSubREQToFileAppend: true,
|
||||
StartSubREQToFile: true,
|
||||
StartSubREQPing: true,
|
||||
StartSubREQPong: true,
|
||||
StartSubREQCliCommand: true,
|
||||
StartSubREQToConsole: true,
|
||||
StartSubREQHttpGet: true,
|
||||
StartSubREQTailFile: true,
|
||||
StartSubREQnCliCommandCont: true,
|
||||
StartSubREQErrorLog: true,
|
||||
StartSubREQHello: true,
|
||||
StartSubREQToFileAppend: true,
|
||||
StartSubREQToFile: true,
|
||||
StartSubREQPing: true,
|
||||
StartSubREQPong: true,
|
||||
StartSubREQCliCommand: true,
|
||||
StartSubREQToConsole: true,
|
||||
StartSubREQHttpGet: true,
|
||||
StartSubREQTailFile: true,
|
||||
StartSubREQCliCommandCont: true,
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
@ -321,10 +320,10 @@ func checkConfigValues(cf ConfigurationFromFile) Configuration {
|
|||
} else {
|
||||
conf.StartSubREQTailFile = *cf.StartSubREQTailFile
|
||||
}
|
||||
if cf.StartSubREQnCliCommandCont == nil {
|
||||
conf.StartSubREQnCliCommandCont = cd.StartSubREQnCliCommandCont
|
||||
if cf.StartSubREQCliCommandCont == nil {
|
||||
conf.StartSubREQCliCommandCont = cd.StartSubREQCliCommandCont
|
||||
} else {
|
||||
conf.StartSubREQnCliCommandCont = *cf.StartSubREQnCliCommandCont
|
||||
conf.StartSubREQCliCommandCont = *cf.StartSubREQCliCommandCont
|
||||
}
|
||||
|
||||
return conf
|
||||
|
@ -390,7 +389,7 @@ func (c *Configuration) CheckFlags() error {
|
|||
flag.BoolVar(&c.StartSubREQToConsole, "startSubREQToConsole", fc.StartSubREQToConsole, "true/false")
|
||||
flag.BoolVar(&c.StartSubREQHttpGet, "startSubREQHttpGet", fc.StartSubREQHttpGet, "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()
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
"toNode": "ship1",
|
||||
"data": ["bash","-c","tree ../"],
|
||||
"replyMethod":"REQToFileAppend",
|
||||
"method":"REQnCliCommand",
|
||||
"method":"REQCliCommand",
|
||||
"ACKTimeout":3,
|
||||
"retries":3,
|
||||
"methodTimeout": 10
|
||||
|
|
|
@ -116,8 +116,8 @@ func (p *processes) Start(proc process) {
|
|||
proc.startup.subREQTailFile(proc)
|
||||
}
|
||||
|
||||
if proc.configuration.StartSubREQnCliCommandCont {
|
||||
proc.startup.subREQnCliCommandCont(proc)
|
||||
if proc.configuration.StartSubREQCliCommandCont {
|
||||
proc.startup.subREQCliCommandCont(proc)
|
||||
}
|
||||
|
||||
proc.startup.subREQToSocket(proc)
|
||||
|
@ -299,9 +299,9 @@ func (s startup) subREQTailFile(p process) {
|
|||
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)
|
||||
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)
|
||||
// fmt.Printf("*** %#v\n", proc)
|
||||
go proc.spawnWorker(p.processes, p.natsConn)
|
||||
|
|
|
@ -296,7 +296,7 @@ func newSubjectAndMessage(m Message) (subjectAndMessage, error) {
|
|||
|
||||
tmpH := mt.getHandler(m.Method)
|
||||
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{
|
||||
|
|
26
requests.go
26
requests.go
|
@ -73,11 +73,11 @@ const (
|
|||
// The data field is a slice of strings where the first string
|
||||
// value should be the command, and the following the arguments.
|
||||
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
|
||||
// to send the output of the command continually back as it is
|
||||
// generated, and not just when the command is finished.
|
||||
REQnCliCommandCont Method = "REQnCliCommandCont"
|
||||
// generated, and not wait until the command is finished.
|
||||
REQCliCommandCont Method = "REQCliCommandCont"
|
||||
// Send text to be logged to the console.
|
||||
// The data field is a slice of strings where the first string
|
||||
// value should be the command, and the following the arguments.
|
||||
|
@ -137,7 +137,7 @@ func (m Method) GetMethodsAvailable() MethodsAvailable {
|
|||
REQCliCommand: methodREQCliCommand{
|
||||
commandOrEvent: CommandACK,
|
||||
},
|
||||
REQnCliCommandCont: methodREQnCliCommandCont{
|
||||
REQCliCommandCont: methodREQCliCommandCont{
|
||||
commandOrEvent: CommandACK,
|
||||
},
|
||||
REQToConsole: methodREQToConsole{
|
||||
|
@ -1089,19 +1089,19 @@ func (m methodREQTailFile) handler(proc process, message Message, node string) (
|
|||
}
|
||||
|
||||
// ---
|
||||
type methodREQnCliCommandCont struct {
|
||||
type methodREQCliCommandCont struct {
|
||||
commandOrEvent CommandOrEvent
|
||||
}
|
||||
|
||||
func (m methodREQnCliCommandCont) getKind() CommandOrEvent {
|
||||
func (m methodREQCliCommandCont) getKind() 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
|
||||
// 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.
|
||||
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)
|
||||
|
||||
// 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.
|
||||
outReader, err := cmd.StdoutPipe()
|
||||
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)
|
||||
log.Printf("%v\n", er)
|
||||
|
||||
|
@ -1138,7 +1138,7 @@ func (m methodREQnCliCommandCont) handler(proc process, message Message, node st
|
|||
|
||||
ErrorReader, err := cmd.StderrPipe()
|
||||
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)
|
||||
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 {
|
||||
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)
|
||||
log.Printf("%v\n", er)
|
||||
|
||||
|
@ -1163,7 +1163,7 @@ func (m methodREQnCliCommandCont) handler(proc process, message Message, node st
|
|||
for scanner.Scan() {
|
||||
select {
|
||||
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)
|
||||
log.Printf("%v\n", er)
|
||||
case <-ctx.Done():
|
||||
|
@ -1189,7 +1189,7 @@ func (m methodREQnCliCommandCont) handler(proc process, message Message, node st
|
|||
select {
|
||||
case <-ctx.Done():
|
||||
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)
|
||||
return
|
||||
case out := <-outCh:
|
||||
|
|
|
@ -55,15 +55,15 @@ func TestStewardServer(t *testing.T) {
|
|||
DefaultMessageRetries: 1,
|
||||
DefaultMessageTimeout: 3,
|
||||
|
||||
StartSubREQCliCommand: true,
|
||||
StartSubREQnCliCommandCont: true,
|
||||
StartSubREQToConsole: true,
|
||||
StartSubREQToFileAppend: true,
|
||||
StartSubREQToFile: true,
|
||||
StartSubREQHello: true,
|
||||
StartSubREQErrorLog: true,
|
||||
StartSubREQHttpGet: true,
|
||||
StartSubREQTailFile: true,
|
||||
StartSubREQCliCommand: true,
|
||||
StartSubREQCliCommandCont: true,
|
||||
StartSubREQToConsole: true,
|
||||
StartSubREQToFileAppend: true,
|
||||
StartSubREQToFile: true,
|
||||
StartSubREQHello: true,
|
||||
StartSubREQErrorLog: true,
|
||||
StartSubREQHttpGet: true,
|
||||
StartSubREQTailFile: true,
|
||||
// StartSubREQToSocket: flagNodeSlice{OK: true, Values: []Node{"*"}},
|
||||
}
|
||||
stewardServer, err := NewServer(conf, "test")
|
||||
|
@ -82,7 +82,7 @@ func TestStewardServer(t *testing.T) {
|
|||
funcs := []testFunc{
|
||||
checkREQOpCommandTest,
|
||||
checkREQCliCommandTest,
|
||||
checkREQnCliCommandContTest,
|
||||
checkREQCliCommandContTest,
|
||||
// checkREQToConsoleTest(conf, t), NB: No tests will be made for console ouput.
|
||||
// checkREQToFileAppendTest(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.
|
||||
func checkREQnCliCommandContTest(stewardServer *server, conf *Configuration, t *testing.T) error {
|
||||
func checkREQCliCommandContTest(stewardServer *server, conf *Configuration, t *testing.T) error {
|
||||
m := `[
|
||||
{
|
||||
"directory":"commands-executed",
|
||||
|
@ -184,7 +184,7 @@ func checkREQnCliCommandContTest(stewardServer *server, conf *Configuration, t *
|
|||
"toNode": "central",
|
||||
"data": ["bash","-c","echo apekatt && sleep 5 && echo gris"],
|
||||
"replyMethod":"REQToFileAppend",
|
||||
"method":"REQnCliCommandCont",
|
||||
"method":"REQCliCommandCont",
|
||||
"ACKTimeout":3,
|
||||
"retries":3,
|
||||
"methodTimeout": 5
|
||||
|
@ -196,10 +196,10 @@ func checkREQnCliCommandContTest(stewardServer *server, conf *Configuration, t *
|
|||
resultFile := filepath.Join(conf.SubscribersDataFolder, "commands-executed", "central", "fileName.result")
|
||||
_, err := findStringInFileTest("apekatt", resultFile, conf, t)
|
||||
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue