mirror of
https://github.com/postmannen/ctrl.git
synced 2025-01-05 20:09:16 +00:00
implemented newReplyMessage for all request types
This commit is contained in:
parent
66f89cd731
commit
1b17f8e345
5 changed files with 44 additions and 73 deletions
|
@ -6,6 +6,6 @@
|
||||||
"method":"OpCommand",
|
"method":"OpCommand",
|
||||||
"timeout":3,
|
"timeout":3,
|
||||||
"retries":3,
|
"retries":3,
|
||||||
"MethodTimeout": 7
|
"methodTimeout": 7
|
||||||
}
|
}
|
||||||
]
|
]
|
|
@ -2,10 +2,12 @@
|
||||||
{
|
{
|
||||||
|
|
||||||
"toNode": "ship1",
|
"toNode": "ship1",
|
||||||
"data": ["psa"],
|
"data": ["ps"],
|
||||||
"method":"OpCommandRequest",
|
"method":"OpCommandRequest",
|
||||||
"timeout":3,
|
"timeout":3,
|
||||||
"retries":3,
|
"retries":3,
|
||||||
|
"requestTimeout":3,
|
||||||
|
"requestRetries":3,
|
||||||
"MethodTimeout": 7
|
"MethodTimeout": 7
|
||||||
}
|
}
|
||||||
]
|
]
|
|
@ -6,6 +6,6 @@
|
||||||
"method":"CLICommandRequest",
|
"method":"CLICommandRequest",
|
||||||
"timeout":10,
|
"timeout":10,
|
||||||
"retries":3,
|
"retries":3,
|
||||||
"MethodTimeout": 7
|
"methodTimeout": 4
|
||||||
}
|
}
|
||||||
]
|
]
|
|
@ -6,6 +6,6 @@
|
||||||
"method":"CLICommandRequestNOSEQ",
|
"method":"CLICommandRequestNOSEQ",
|
||||||
"timeout":10,
|
"timeout":10,
|
||||||
"retries":3,
|
"retries":3,
|
||||||
"MethodTimeout": 0
|
"methodTimeout": 0
|
||||||
}
|
}
|
||||||
]
|
]
|
|
@ -270,31 +270,41 @@ func (m methodOpCommandRequest) handler(proc process, message Message, node stri
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//--
|
// Prepare and queue for sending a new message with the output
|
||||||
// Create a new message for the reply, and put it on the
|
// of the action executed.
|
||||||
// ringbuffer to be published.
|
newReplyMessage(proc, message, OpCommandReply, out)
|
||||||
newMsg := Message{
|
|
||||||
ToNode: message.FromNode,
|
|
||||||
Data: []string{string(out)},
|
|
||||||
Method: OpCommandReply,
|
|
||||||
Timeout: 3,
|
|
||||||
Retries: 3,
|
|
||||||
}
|
|
||||||
fmt.Printf("** %#v\n", newMsg)
|
|
||||||
|
|
||||||
nSAM, err := newSAM(newMsg)
|
|
||||||
if err != nil {
|
|
||||||
// In theory the system should drop the message before it reaches here.
|
|
||||||
log.Printf("error: methodCLICommandRequest: %v\n", err)
|
|
||||||
}
|
|
||||||
proc.toRingbufferCh <- []subjectAndMessage{nSAM}
|
|
||||||
//--
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ackMsg := []byte(fmt.Sprintf("confirmed from node: %v: messageID: %v\n---\n", node, message.ID))
|
ackMsg := []byte(fmt.Sprintf("confirmed from node: %v: messageID: %v\n---\n", node, message.ID))
|
||||||
return ackMsg, nil
|
return ackMsg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--
|
||||||
|
// Create a new message for the reply containing the output of the
|
||||||
|
// action executed put in outData, and put it on the ringbuffer to
|
||||||
|
// be published.
|
||||||
|
func newReplyMessage(proc process, message Message, method Method, outData []byte) {
|
||||||
|
//--
|
||||||
|
// Create a new message for the reply, and put it on the
|
||||||
|
// ringbuffer to be published.
|
||||||
|
newMsg := Message{
|
||||||
|
ToNode: message.FromNode,
|
||||||
|
Data: []string{string(outData)},
|
||||||
|
Method: method,
|
||||||
|
Timeout: message.RequestTimeout,
|
||||||
|
Retries: message.RequestRetries,
|
||||||
|
}
|
||||||
|
fmt.Printf("** %#v\n", newMsg)
|
||||||
|
|
||||||
|
nSAM, err := newSAM(newMsg)
|
||||||
|
if err != nil {
|
||||||
|
// In theory the system should drop the message before it reaches here.
|
||||||
|
log.Printf("error: %v: %v\n", message.Method, err)
|
||||||
|
}
|
||||||
|
proc.toRingbufferCh <- []subjectAndMessage{nSAM}
|
||||||
|
//--
|
||||||
|
}
|
||||||
|
|
||||||
// -----
|
// -----
|
||||||
|
|
||||||
type methodOpCommandReply struct {
|
type methodOpCommandReply struct {
|
||||||
|
@ -442,22 +452,9 @@ func (m methodEchoRequest) getKind() CommandOrEvent {
|
||||||
func (m methodEchoRequest) handler(proc process, message Message, node string) ([]byte, error) {
|
func (m methodEchoRequest) handler(proc process, message Message, node string) ([]byte, error) {
|
||||||
log.Printf("<--- ECHO REQUEST received from: %v, containing: %v", message.FromNode, message.Data)
|
log.Printf("<--- ECHO REQUEST received from: %v, containing: %v", message.FromNode, message.Data)
|
||||||
|
|
||||||
// Create a new message for the reply, and put it on the
|
// Prepare and queue for sending a new message with the output
|
||||||
// ringbuffer to be published.
|
// of the action executed.
|
||||||
newMsg := Message{
|
newReplyMessage(proc, message, ECHOReply, []byte{})
|
||||||
ToNode: message.FromNode,
|
|
||||||
Data: []string{""},
|
|
||||||
Method: ECHOReply,
|
|
||||||
Timeout: 3,
|
|
||||||
Retries: 3,
|
|
||||||
}
|
|
||||||
|
|
||||||
nSAM, err := newSAM(newMsg)
|
|
||||||
if err != nil {
|
|
||||||
// In theory the system should drop the message before it reaches here.
|
|
||||||
log.Printf("error: methodEchoRequest: %v\n", err)
|
|
||||||
}
|
|
||||||
proc.toRingbufferCh <- []subjectAndMessage{nSAM}
|
|
||||||
|
|
||||||
ackMsg := []byte("confirmed from: " + node + ": " + fmt.Sprint(message.ID))
|
ackMsg := []byte("confirmed from: " + node + ": " + fmt.Sprint(message.ID))
|
||||||
return ackMsg, nil
|
return ackMsg, nil
|
||||||
|
@ -525,23 +522,9 @@ func (m methodCLICommandRequest) handler(proc process, message Message, node str
|
||||||
case out := <-outCh:
|
case out := <-outCh:
|
||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
// Create a new message for the reply, and put it on the
|
// Prepare and queue for sending a new message with the output
|
||||||
// ringbuffer to be published.
|
// of the action executed.
|
||||||
newMsg := Message{
|
newReplyMessage(proc, message, CLICommandReply, out)
|
||||||
ToNode: message.FromNode,
|
|
||||||
Data: []string{string(out)},
|
|
||||||
Method: CLICommandReply,
|
|
||||||
Timeout: 3,
|
|
||||||
Retries: 3,
|
|
||||||
}
|
|
||||||
fmt.Printf("** %#v\n", newMsg)
|
|
||||||
|
|
||||||
nSAM, err := newSAM(newMsg)
|
|
||||||
if err != nil {
|
|
||||||
// In theory the system should drop the message before it reaches here.
|
|
||||||
log.Printf("error: methodCLICommandRequest: %v\n", err)
|
|
||||||
}
|
|
||||||
proc.toRingbufferCh <- []subjectAndMessage{nSAM}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}()
|
}()
|
||||||
|
@ -598,23 +581,9 @@ func (m methodCLICommandRequestNOSEQ) handler(proc process, message Message, nod
|
||||||
case out := <-outCh:
|
case out := <-outCh:
|
||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
// Create a new message for the reply, and put it on the
|
// Prepare and queue for sending a new message with the output
|
||||||
// ringbuffer to be published.
|
// of the action executed.
|
||||||
newMsg := Message{
|
newReplyMessage(proc, message, CLICommandReply, out)
|
||||||
ToNode: message.FromNode,
|
|
||||||
Data: []string{string(out)},
|
|
||||||
Method: CLICommandReply,
|
|
||||||
Timeout: 3,
|
|
||||||
Retries: 3,
|
|
||||||
}
|
|
||||||
fmt.Printf("** %#v\n", newMsg)
|
|
||||||
|
|
||||||
nSAM, err := newSAM(newMsg)
|
|
||||||
if err != nil {
|
|
||||||
// In theory the system should drop the message before it reaches here.
|
|
||||||
log.Printf("error: methodCLICommandRequest: %v\n", err)
|
|
||||||
}
|
|
||||||
proc.toRingbufferCh <- []subjectAndMessage{nSAM}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in a new issue