1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2025-03-15 10:57:42 +00:00

removed sams from channels

This commit is contained in:
postmannen 2024-12-01 03:08:40 +01:00
parent 9fca6d0b7f
commit 49be8947fa
9 changed files with 76 additions and 204 deletions

View file

@ -68,7 +68,7 @@ const logNone logLevel = "none"
// process if it should continue or not based not based on how severe // process if it should continue or not based not based on how severe
// the error where. This should be right after sending the error // the error where. This should be right after sending the error
// sending in the process. // sending in the process.
func (e *errorKernel) start(ringBufferBulkInCh chan<- subjectAndMessage) error { func (e *errorKernel) start(ringBufferBulkInCh chan<- Message) error {
// Initiate the slog logger. // Initiate the slog logger.
var replaceFunc func(groups []string, a slog.Attr) slog.Attr var replaceFunc func(groups []string, a slog.Attr) slog.Attr
if !e.configuration.LogConsoleTimestamps { if !e.configuration.LogConsoleTimestamps {
@ -131,13 +131,8 @@ func (e *errorKernel) start(ringBufferBulkInCh chan<- subjectAndMessage) error {
Retries: errEvent.process.configuration.ErrorMessageRetries, Retries: errEvent.process.configuration.ErrorMessageRetries,
} }
sam := subjectAndMessage{
Subject: newSubject(ErrorLog, "errorCentral"),
Message: m,
}
// Put the message on the channel to the ringbuffer. // Put the message on the channel to the ringbuffer.
ringBufferBulkInCh <- sam ringBufferBulkInCh <- m
// if errEvent.process.configuration.EnableDebug { // if errEvent.process.configuration.EnableDebug {
// log.Printf("%v\n", er) // log.Printf("%v\n", er)

View file

@ -77,7 +77,7 @@ func (s *server) readStartupFolder() {
readBytes = bytes.Trim(readBytes, "\x00") readBytes = bytes.Trim(readBytes, "\x00")
// unmarshal the JSON into a struct // unmarshal the JSON into a struct
sams, err := s.convertBytesToSAMs(readBytes) messages, err := s.convertBytesToMessages(readBytes)
if err != nil { if err != nil {
er := fmt.Errorf("error: startup folder: malformed json read: %v", err) er := fmt.Errorf("error: startup folder: malformed json read: %v", err)
s.errorKernel.errSend(s.processInitial, Message{}, er, logWarning) s.errorKernel.errSend(s.processInitial, Message{}, er, logWarning)
@ -85,38 +85,35 @@ func (s *server) readStartupFolder() {
} }
// Check if fromNode field is specified, and remove the message if blank. // Check if fromNode field is specified, and remove the message if blank.
for i := range sams { for i := range messages {
// We want to allow the use of nodeName local only in startup folder, and // We want to allow the use of nodeName local only in startup folder, and
// if used we substite it for the local node name. // if used we substite it for the local node name.
if sams[i].Message.ToNode == "local" { if messages[i].ToNode == "local" {
sams[i].Message.ToNode = Node(s.nodeName) messages[i].ToNode = Node(s.nodeName)
sams[i].Subject.ToNode = s.nodeName
} }
switch { switch {
case sams[i].Message.FromNode == "": case messages[i].FromNode == "":
// Remove the first message from the slice.
sams = append(sams[:i], sams[i+1:]...)
er := fmt.Errorf(" error: missing value in fromNode field in startup message, discarding message") er := fmt.Errorf(" error: missing value in fromNode field in startup message, discarding message")
s.errorKernel.errSend(s.processInitial, Message{}, er, logWarning) s.errorKernel.errSend(s.processInitial, Message{}, er, logWarning)
continue
case sams[i].Message.ToNode == "" && len(sams[i].Message.ToNodes) == 0: case messages[i].ToNode == "" && len(messages[i].ToNodes) == 0:
// Remove the first message from the slice.
sams = append(sams[:i], sams[i+1:]...)
er := fmt.Errorf(" error: missing value in both toNode and toNodes fields in startup message, discarding message") er := fmt.Errorf(" error: missing value in both toNode and toNodes fields in startup message, discarding message")
s.errorKernel.errSend(s.processInitial, Message{}, er, logWarning) s.errorKernel.errSend(s.processInitial, Message{}, er, logWarning)
continue
} }
} }
j, err := json.MarshalIndent(sams, "", " ") j, err := json.MarshalIndent(messages, "", " ")
if err != nil { if err != nil {
log.Printf("test error: %v\n", err) log.Printf("test error: %v\n", err)
} }
er = fmt.Errorf("%v", string(j)) er = fmt.Errorf("%v", string(j))
s.errorKernel.errSend(s.processInitial, Message{}, er, logInfo) s.errorKernel.errSend(s.processInitial, Message{}, er, logInfo)
s.messageDeliverLocalCh <- sams s.messageDeliverLocalCh <- messages
} }
@ -212,15 +209,7 @@ func (s *server) jetstreamConsume() {
// nodeName of the consumer in the ctrl Message, so we are sure it is handled locally. // nodeName of the consumer in the ctrl Message, so we are sure it is handled locally.
m.ToNode = Node(s.nodeName) m.ToNode = Node(s.nodeName)
sam, err := newSubjectAndMessage(m) s.messageDeliverLocalCh <- []Message{m}
if err != nil {
er := fmt.Errorf("error: jetstreamConsume: newSubjectAndMessage failed: %v", err)
s.errorKernel.errSend(s.processInitial, Message{}, er, logError)
return
}
// If a message is received via
s.messageDeliverLocalCh <- []subjectAndMessage{sam}
}) })
defer consumeContext.Stop() defer consumeContext.Stop()
@ -300,30 +289,30 @@ func (s *server) readSocket() {
readBytes = bytes.Trim(readBytes, "\x00") readBytes = bytes.Trim(readBytes, "\x00")
// unmarshal the JSON into a struct // unmarshal the JSON into a struct
sams, err := s.convertBytesToSAMs(readBytes) messages, err := s.convertBytesToMessages(readBytes)
if err != nil { if err != nil {
er := fmt.Errorf("error: malformed json received on socket: %s\n %v", readBytes, err) er := fmt.Errorf("error: malformed json received on socket: %s\n %v", readBytes, err)
s.errorKernel.errSend(s.processInitial, Message{}, er, logWarning) s.errorKernel.errSend(s.processInitial, Message{}, er, logWarning)
return return
} }
for i := range sams { for i := range messages {
// Fill in the value for the FromNode field, so the receiver // Fill in the value for the FromNode field, so the receiver
// can check this field to know where it came from. // can check this field to know where it came from.
sams[i].Message.FromNode = Node(s.nodeName) messages[i].FromNode = Node(s.nodeName)
// Send an info message to the central about the message picked // Send an info message to the central about the message picked
// for auditing. // for auditing.
er := fmt.Errorf("info: message read from socket on %v: %v", s.nodeName, sams[i].Message) er := fmt.Errorf("info: message read from socket on %v: %v", s.nodeName, messages[i])
s.errorKernel.errSend(s.processInitial, Message{}, er, logInfo) s.errorKernel.errSend(s.processInitial, Message{}, er, logInfo)
s.newMessagesCh <- sams[i] s.newMessagesCh <- messages[i]
} }
// Send the SAM struct to be picked up by the ring buffer. // Send the SAM struct to be picked up by the ring buffer.
s.auditLogCh <- sams s.auditLogCh <- messages
}(conn) }(conn)
} }
@ -384,42 +373,42 @@ func (s *server) readFolder() {
b = bytes.Trim(b, "\x00") b = bytes.Trim(b, "\x00")
// unmarshal the JSON into a struct // unmarshal the JSON into a struct
sams, err := s.convertBytesToSAMs(b) messages, err := s.convertBytesToMessages(b)
if err != nil { if err != nil {
er := fmt.Errorf("error: readFolder: malformed json received: %s\n %v", b, err) er := fmt.Errorf("error: readFolder: malformed json received: %s\n %v", b, err)
s.errorKernel.errSend(s.processInitial, Message{}, er, logWarning) s.errorKernel.errSend(s.processInitial, Message{}, er, logWarning)
return return
} }
for i := range sams { for i := range messages {
// Fill in the value for the FromNode field, so the receiver // Fill in the value for the FromNode field, so the receiver
// can check this field to know where it came from. // can check this field to know where it came from.
sams[i].Message.FromNode = Node(s.nodeName) messages[i].FromNode = Node(s.nodeName)
// Send an info message to the central about the message picked // Send an info message to the central about the message picked
// for auditing. // for auditing.
er := fmt.Errorf("info: readFolder: message read from readFolder on %v: %v", s.nodeName, sams[i].Message) er := fmt.Errorf("info: readFolder: message read from readFolder on %v: %v", s.nodeName, messages[i])
s.errorKernel.errSend(s.processInitial, Message{}, er, logWarning) s.errorKernel.errSend(s.processInitial, Message{}, er, logWarning)
// Check if it is a message to publish with Jetstream. // Check if it is a message to publish with Jetstream.
if sams[i].Message.JetstreamToNode != "" { if messages[i].JetstreamToNode != "" {
s.jetstreamPublishCh <- sams[i].Message s.jetstreamPublishCh <- messages[i]
er = fmt.Errorf("readFolder: read new JETSTREAM message in readfolder and putting it on s.jetstreamPublishCh: %#v", sams) er = fmt.Errorf("readFolder: read new JETSTREAM message in readfolder and putting it on s.jetstreamPublishCh: %#v", messages)
s.errorKernel.logDebug(er) s.errorKernel.logDebug(er)
continue continue
} }
s.newMessagesCh <- sams[i] s.newMessagesCh <- messages[i]
er = fmt.Errorf("readFolder: read new message in readfolder and putting it on s.samToSendCh: %#v", sams) er = fmt.Errorf("readFolder: read new message in readfolder and putting it on s.samToSendCh: %#v", messages)
s.errorKernel.logDebug(er) s.errorKernel.logDebug(er)
} }
// Send the SAM struct to be picked up by the ring buffer. // Send the SAM struct to be picked up by the ring buffer.
s.auditLogCh <- sams s.auditLogCh <- messages
// Delete the file. // Delete the file.
err = os.Remove(event.Name) err = os.Remove(event.Name)
@ -496,23 +485,23 @@ func (s *server) readTCPListener() {
readBytes = bytes.Trim(readBytes, "\x00") readBytes = bytes.Trim(readBytes, "\x00")
// unmarshal the JSON into a struct // unmarshal the JSON into a struct
sams, err := s.convertBytesToSAMs(readBytes) messages, err := s.convertBytesToMessages(readBytes)
if err != nil { if err != nil {
er := fmt.Errorf("error: malformed json received on tcp listener: %v", err) er := fmt.Errorf("error: malformed json received on tcp listener: %v", err)
s.errorKernel.errSend(s.processInitial, Message{}, er, logWarning) s.errorKernel.errSend(s.processInitial, Message{}, er, logWarning)
return return
} }
for i := range sams { for i := range messages {
// Fill in the value for the FromNode field, so the receiver // Fill in the value for the FromNode field, so the receiver
// can check this field to know where it came from. // can check this field to know where it came from.
sams[i].Message.FromNode = Node(s.nodeName) messages[i].FromNode = Node(s.nodeName)
s.newMessagesCh <- sams[i] s.newMessagesCh <- messages[i]
} }
// Send the SAM struct to be picked up by the ring buffer. // Send the SAM struct to be picked up by the ring buffer.
s.auditLogCh <- sams s.auditLogCh <- messages
}(conn) }(conn)
} }
@ -541,23 +530,23 @@ func (s *server) readHTTPlistenerHandler(w http.ResponseWriter, r *http.Request)
readBytes = bytes.Trim(readBytes, "\x00") readBytes = bytes.Trim(readBytes, "\x00")
// unmarshal the JSON into a struct // unmarshal the JSON into a struct
sams, err := s.convertBytesToSAMs(readBytes) messages, err := s.convertBytesToMessages(readBytes)
if err != nil { if err != nil {
er := fmt.Errorf("error: malformed json received on HTTPListener: %v", err) er := fmt.Errorf("error: malformed json received on HTTPListener: %v", err)
s.errorKernel.errSend(s.processInitial, Message{}, er, logWarning) s.errorKernel.errSend(s.processInitial, Message{}, er, logWarning)
return return
} }
for i := range sams { for i := range messages {
// Fill in the value for the FromNode field, so the receiver // Fill in the value for the FromNode field, so the receiver
// can check this field to know where it came from. // can check this field to know where it came from.
sams[i].Message.FromNode = Node(s.nodeName) messages[i].FromNode = Node(s.nodeName)
s.newMessagesCh <- sams[i] s.newMessagesCh <- messages[i]
} }
// Send the SAM struct to be picked up by the ring buffer. // Send the SAM struct to be picked up by the ring buffer.
s.auditLogCh <- sams s.auditLogCh <- messages
} }
@ -595,7 +584,7 @@ type subjectAndMessage struct {
// json format. For each element found the Message type will be converted into // json format. For each element found the Message type will be converted into
// a SubjectAndMessage type value and appended to a slice, and the slice is // a SubjectAndMessage type value and appended to a slice, and the slice is
// returned to the caller. // returned to the caller.
func (s *server) convertBytesToSAMs(b []byte) ([]subjectAndMessage, error) { func (s *server) convertBytesToMessages(b []byte) ([]Message, error) {
MsgSlice := []Message{} MsgSlice := []Message{}
err := yaml.Unmarshal(b, &MsgSlice) err := yaml.Unmarshal(b, &MsgSlice)
@ -607,22 +596,7 @@ func (s *server) convertBytesToSAMs(b []byte) ([]subjectAndMessage, error) {
MsgSlice = s.checkMessageToNodes(MsgSlice) MsgSlice = s.checkMessageToNodes(MsgSlice)
s.metrics.promUserMessagesTotal.Add(float64(len(MsgSlice))) s.metrics.promUserMessagesTotal.Add(float64(len(MsgSlice)))
sam := []subjectAndMessage{} return MsgSlice, nil
// Range over all the messages parsed from json, and create a subject for
// each message.
for _, m := range MsgSlice {
sm, err := newSubjectAndMessage(m)
if err != nil {
er := fmt.Errorf("error: newSubjectAndMessage: %v", err)
s.errorKernel.errSend(s.processInitial, m, er, logWarning)
continue
}
sam = append(sam, sm)
}
return sam, nil
} }
// checkMessageToNodes will check that either toHost or toHosts are // checkMessageToNodes will check that either toHost or toHosts are

View file

@ -81,7 +81,7 @@ type process struct {
// copy of the configuration from server // copy of the configuration from server
configuration *Configuration configuration *Configuration
// The new messages channel copied from *Server // The new messages channel copied from *Server
newMessagesCh chan<- subjectAndMessage newMessagesCh chan<- Message
// The structure who holds all processes information // The structure who holds all processes information
processes *processes processes *processes
// nats connection // nats connection

View file

@ -185,13 +185,7 @@ func (p *processes) Start(proc process) {
Retries: 1, Retries: 1,
} }
sam, err := newSubjectAndMessage(m) proc.newMessagesCh <- m
if err != nil {
// In theory the system should drop the message before it reaches here.
er := fmt.Errorf("error: ProcessesStart: %v", err)
p.errorKernel.errSend(proc, m, er, logError)
}
proc.newMessagesCh <- sam
select { select {
case <-ticker.C: case <-ticker.C:
@ -236,12 +230,7 @@ func (p *processes) Start(proc process) {
} }
proc.nodeAuth.publicKeys.mu.Unlock() proc.nodeAuth.publicKeys.mu.Unlock()
sam, err := newSubjectAndMessage(m) proc.newMessagesCh <- m
if err != nil {
// In theory the system should drop the message before it reaches here.
p.errorKernel.errSend(proc, m, err, logError)
}
proc.newMessagesCh <- sam
select { select {
case <-ticker.C: case <-ticker.C:
@ -284,13 +273,7 @@ func (p *processes) Start(proc process) {
} }
proc.nodeAuth.nodeAcl.mu.Unlock() proc.nodeAuth.nodeAcl.mu.Unlock()
sam, err := newSubjectAndMessage(m) proc.newMessagesCh <- m
if err != nil {
// In theory the system should drop the message before it reaches here.
p.errorKernel.errSend(proc, m, err, logError)
log.Printf("error: ProcessesStart: %v\n", err)
}
proc.newMessagesCh <- sam
select { select {
case <-ticker.C: case <-ticker.C:

View file

@ -352,14 +352,7 @@ func newReplyMessage(proc process, message Message, outData []byte) {
PreviousMessage: &thisMsg, PreviousMessage: &thisMsg,
} }
sam, err := newSubjectAndMessage(newMsg) proc.newMessagesCh <- newMsg
if err != nil {
// In theory the system should drop the message before it reaches here.
er := fmt.Errorf("error: newSubjectAndMessage : %v, message: %v", err, message)
proc.errorKernel.errSend(proc, message, er, logError)
}
proc.newMessagesCh <- sam
} }
// selectFileNaming will figure out the correct naming of the file // selectFileNaming will figure out the correct naming of the file

View file

@ -86,13 +86,8 @@ func methodCopySrc(proc process, message Message, node string) ([]byte, error) {
// we should forward the message to that specified toNode. This will allow // we should forward the message to that specified toNode. This will allow
// us to initiate a file copy from another node to this node. // us to initiate a file copy from another node to this node.
if message.ToNode != proc.node { if message.ToNode != proc.node {
sam, err := newSubjectAndMessage(message)
if err != nil {
er := fmt.Errorf("error: newSubjectAndMessage failed: %v, message=%v", err, message)
proc.errorKernel.errSend(proc, message, er, logWarning)
}
proc.newMessagesCh <- sam proc.newMessagesCh <- message
return nil, fmt.Errorf("info: the copy message was forwarded to %v message, %v", message.ToNode, message) return nil, fmt.Errorf("info: the copy message was forwarded to %v message, %v", message.ToNode, message)
} }
@ -260,14 +255,7 @@ func methodCopySrc(proc process, message Message, node string) ([]byte, error) {
// msg.Directory = dstDir // msg.Directory = dstDir
// msg.FileName = dstFile // msg.FileName = dstFile
sam, err := newSubjectAndMessage(msg) proc.newMessagesCh <- msg
if err != nil {
er := fmt.Errorf("error: newSubjectAndMessage failed: %v, message=%v", err, message)
proc.errorKernel.errSend(proc, message, er, logWarning)
cancel()
}
proc.newMessagesCh <- sam
replyData := fmt.Sprintf("info: succesfully initiated copy source process: procName=%v, srcNode=%v, srcPath=%v, dstNode=%v, dstPath=%v, starting sub process=%v for the actual copying", copySrcSubProc.processName, node, SrcFilePath, DstNode, DstFilePath, subProcessName) replyData := fmt.Sprintf("info: succesfully initiated copy source process: procName=%v, srcNode=%v, srcPath=%v, dstNode=%v, dstPath=%v, starting sub process=%v for the actual copying", copySrcSubProc.processName, node, SrcFilePath, DstNode, DstFilePath, subProcessName)
@ -558,15 +546,7 @@ func copySrcSubProcFunc(proc process, cia copyInitialData, cancel context.Cancel
ReplyRetries: initialMessage.ReplyRetries, ReplyRetries: initialMessage.ReplyRetries,
} }
sam, err := newSubjectAndMessage(msg) proc.newMessagesCh <- msg
if err != nil {
er := fmt.Errorf("copySrcProcSubFunc: newSubjectAndMessage failed: %v", err)
proc.errorKernel.errSend(proc, message, er, logWarning)
newReplyMessage(proc, msgForSubErrors, []byte(er.Error()))
return er
}
proc.newMessagesCh <- sam
resendRetries = 0 resendRetries = 0
@ -628,15 +608,7 @@ func copySrcSubProcFunc(proc process, cia copyInitialData, cancel context.Cancel
ReplyRetries: initialMessage.ReplyRetries, ReplyRetries: initialMessage.ReplyRetries,
} }
sam, err := newSubjectAndMessage(msg) proc.newMessagesCh <- msg
if err != nil {
er := fmt.Errorf("copyDstProcSubFunc: newSubjectAndMessage failed: %v", err)
proc.errorKernel.errSend(proc, message, er, logWarning)
newReplyMessage(proc, msgForSubErrors, []byte(er.Error()))
return er
}
proc.newMessagesCh <- sam
resendRetries++ resendRetries++
@ -692,14 +664,7 @@ func copyDstSubProcFunc(proc process, cia copyInitialData, message Message, canc
ReplyRetries: message.ReplyRetries, ReplyRetries: message.ReplyRetries,
} }
sam, err := newSubjectAndMessage(msg) proc.newMessagesCh <- msg
if err != nil {
er := fmt.Errorf("copyDstProcSubFunc: newSubjectAndMessage failed: %v", err)
proc.errorKernel.errSend(proc, message, er, logWarning)
return er
}
proc.newMessagesCh <- sam
} }
// Open a tmp folder for where to write the received chunks // Open a tmp folder for where to write the received chunks
@ -794,14 +759,7 @@ func copyDstSubProcFunc(proc process, cia copyInitialData, message Message, canc
ReplyRetries: message.ReplyRetries, ReplyRetries: message.ReplyRetries,
} }
sam, err := newSubjectAndMessage(msg) proc.newMessagesCh <- msg
if err != nil {
er := fmt.Errorf("copyDstProcSubFunc: newSubjectAndMessage failed: %v", err)
proc.errorKernel.errSend(proc, message, er, logWarning)
return er
}
proc.newMessagesCh <- sam
case copyResendLast: case copyResendLast:
// The csa already contains copyStatus copyResendLast when reached here, // The csa already contains copyStatus copyResendLast when reached here,
@ -827,14 +785,7 @@ func copyDstSubProcFunc(proc process, cia copyInitialData, message Message, canc
ReplyRetries: message.ReplyRetries, ReplyRetries: message.ReplyRetries,
} }
sam, err := newSubjectAndMessage(msg) proc.newMessagesCh <- msg
if err != nil {
er := fmt.Errorf("copyDstProcSubFunc: newSubjectAndMessage failed: %v", err)
proc.errorKernel.errSend(proc, message, er, logWarning)
return er
}
proc.newMessagesCh <- sam
case copySrcDone: case copySrcDone:
err := func() error { err := func() error {
@ -980,14 +931,7 @@ func copyDstSubProcFunc(proc process, cia copyInitialData, message Message, canc
ReplyRetries: message.ReplyRetries, ReplyRetries: message.ReplyRetries,
} }
sam, err := newSubjectAndMessage(msg) proc.newMessagesCh <- msg
if err != nil {
er := fmt.Errorf("copyDstProcSubFunc: newSubjectAndMessage failed: %v", err)
proc.errorKernel.errSend(proc, message, er, logWarning)
return er
}
proc.newMessagesCh <- sam
} }
cancel() cancel()

View file

@ -323,14 +323,7 @@ func pushKeys(proc process, message Message, nodes []Node) error {
ACKTimeout: 0, ACKTimeout: 0,
} }
sam, err := newSubjectAndMessage(msg) proc.newMessagesCh <- msg
if err != nil {
// In theory the system should drop the message before it reaches here.
er := fmt.Errorf("error: newSubjectAndMessage : %v, message: %v", err, message)
proc.errorKernel.errSend(proc, message, er, logWarning)
}
proc.newMessagesCh <- sam
er = fmt.Errorf("----> methodKeysAllow: SENDING KEYS TO NODE=%v", message.FromNode) er = fmt.Errorf("----> methodKeysAllow: SENDING KEYS TO NODE=%v", message.FromNode)
proc.errorKernel.logDebug(er) proc.errorKernel.logDebug(er)
@ -370,14 +363,7 @@ func pushKeys(proc process, message Message, nodes []Node) error {
ACKTimeout: 0, ACKTimeout: 0,
} }
sam, err := newSubjectAndMessage(msg) proc.newMessagesCh <- msg
if err != nil {
// In theory the system should drop the message before it reaches here.
er := fmt.Errorf("error: newSubjectAndMessage : %v, message: %v", err, message)
proc.errorKernel.errSend(proc, message, er, logWarning)
}
proc.newMessagesCh <- sam
er = fmt.Errorf("----> methodKeysAllow: sending keys update to node=%v", message.FromNode) er = fmt.Errorf("----> methodKeysAllow: sending keys update to node=%v", message.FromNode)
proc.errorKernel.logDebug(er) proc.errorKernel.logDebug(er)

View file

@ -285,12 +285,7 @@ func TestRequest(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
switch tt.viaSocketOrCh { switch tt.viaSocketOrCh {
case viaCh: case viaCh:
sam, err := newSubjectAndMessage(tt.message) tstSrv.newMessagesCh <- tt.message
if err != nil {
t.Fatalf("newSubjectAndMessage failed: %v\n", err)
}
tstSrv.newMessagesCh <- sam
case viaSocket: case viaSocket:
msgs := []Message{tt.message} msgs := []Message{tt.message}
@ -339,6 +334,7 @@ func TestRequest(t *testing.T) {
checkREQTailFileTest(tstConf, t, tstTempDir) checkREQTailFileTest(tstConf, t, tstTempDir)
checkMetricValuesTest(tstSrv, t) checkMetricValuesTest(tstSrv, t)
checkErrorKernelMalformedJSONtest(tstConf, t) checkErrorKernelMalformedJSONtest(tstConf, t)
t.Log("*******starting with checkREQCopySrc\n")
checkREQCopySrc(tstConf, t, tstTempDir) checkREQCopySrc(tstConf, t, tstTempDir)
} }

View file

@ -50,9 +50,9 @@ type server struct {
// //
// In general the ringbuffer will read this // In general the ringbuffer will read this
// channel, unfold each slice, and put single messages on the buffer. // channel, unfold each slice, and put single messages on the buffer.
newMessagesCh chan subjectAndMessage newMessagesCh chan Message
// messageDeliverLocalCh // messageDeliverLocalCh
messageDeliverLocalCh chan []subjectAndMessage messageDeliverLocalCh chan []Message
// Channel for messages to publish with Jetstream. // Channel for messages to publish with Jetstream.
jetstreamPublishCh chan Message jetstreamPublishCh chan Message
// errorKernel is doing all the error handling like what to do if // errorKernel is doing all the error handling like what to do if
@ -76,7 +76,7 @@ type server struct {
// message ID // message ID
messageID messageID messageID messageID
// audit logging // audit logging
auditLogCh chan []subjectAndMessage auditLogCh chan []Message
zstdEncoder *zstd.Encoder zstdEncoder *zstd.Encoder
} }
@ -234,8 +234,8 @@ func NewServer(configuration *Configuration, version string) (*server, error) {
nodeName: configuration.NodeName, nodeName: configuration.NodeName,
natsConn: conn, natsConn: conn,
ctrlSocket: ctrlSocket, ctrlSocket: ctrlSocket,
newMessagesCh: make(chan subjectAndMessage), newMessagesCh: make(chan Message),
messageDeliverLocalCh: make(chan []subjectAndMessage), messageDeliverLocalCh: make(chan []Message),
jetstreamPublishCh: make(chan Message), jetstreamPublishCh: make(chan Message),
metrics: metrics, metrics: metrics,
version: version, version: version,
@ -243,7 +243,7 @@ func NewServer(configuration *Configuration, version string) (*server, error) {
nodeAuth: nodeAuth, nodeAuth: nodeAuth,
helloRegister: newHelloRegister(), helloRegister: newHelloRegister(),
centralAuth: centralAuth, centralAuth: centralAuth,
auditLogCh: make(chan []subjectAndMessage), auditLogCh: make(chan []Message),
zstdEncoder: zstdEncoder, zstdEncoder: zstdEncoder,
} }
@ -397,11 +397,11 @@ func (s *server) startAuditLog(ctx context.Context) {
for { for {
select { select {
case sams := <-s.auditLogCh: case messages := <-s.auditLogCh:
for _, sam := range sams { for _, message := range messages {
msgForPermStore := Message{} msgForPermStore := Message{}
copier.Copy(&msgForPermStore, sam.Message) copier.Copy(&msgForPermStore, message)
// Remove the content of the data field. // Remove the content of the data field.
msgForPermStore.Data = nil msgForPermStore.Data = nil
@ -433,27 +433,29 @@ func (s *server) directSAMSChRead() {
case <-s.ctx.Done(): case <-s.ctx.Done():
log.Printf("info: stopped the directSAMSCh reader\n\n") log.Printf("info: stopped the directSAMSCh reader\n\n")
return return
case sams := <-s.messageDeliverLocalCh: case messages := <-s.messageDeliverLocalCh:
// fmt.Printf(" * DEBUG: directSAMSChRead: <- sams = %v\n", sams) // fmt.Printf(" * DEBUG: directSAMSChRead: <- sams = %v\n", sams)
// Range over all the sams, find the process, check if the method exists, and // Range over all the sams, find the process, check if the method exists, and
// handle the message by starting the correct method handler. // handle the message by starting the correct method handler.
for i := range sams { for i := range messages {
processName := processNameGet(sams[i].Subject.name(), processKindSubscriber) // TODO: !!!!!! Shoud the node here be the fromNode ???????
subject := newSubject(messages[i].Method, string(messages[i].ToNode))
processName := processNameGet(subject.name(), processKindSubscriber)
s.processes.active.mu.Lock() s.processes.active.mu.Lock()
p := s.processes.active.procNames[processName] p := s.processes.active.procNames[processName]
s.processes.active.mu.Unlock() s.processes.active.mu.Unlock()
mh, ok := p.methodsAvailable.CheckIfExists(sams[i].Message.Method) mh, ok := p.methodsAvailable.CheckIfExists(messages[i].Method)
if !ok { if !ok {
er := fmt.Errorf("error: subscriberHandler: method type not available: %v", p.subject.Method) er := fmt.Errorf("error: subscriberHandler: method type not available: %v", p.subject.Method)
p.errorKernel.errSend(p, sams[i].Message, er, logError) p.errorKernel.errSend(p, messages[i], er, logError)
continue continue
} }
p.handler = mh p.handler = mh
go executeHandler(p, sams[i].Message, s.nodeName) go executeHandler(p, messages[i], s.nodeName)
} }
} }
} }
@ -508,8 +510,7 @@ func (s *server) routeMessagesToPublisherProcess() {
methodsAvailable := method.GetMethodsAvailable() methodsAvailable := method.GetMethodsAvailable()
go func() { go func() {
for sam1 := range s.newMessagesCh { for message := range s.newMessagesCh {
message := sam1.Message
go func(message Message) { go func(message Message) {