2021-02-24 09:58:02 +00:00
|
|
|
package steward
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-03-09 10:58:50 +00:00
|
|
|
"time"
|
2021-03-04 15:27:55 +00:00
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2021-02-24 09:58:02 +00:00
|
|
|
)
|
|
|
|
|
2021-03-10 06:11:14 +00:00
|
|
|
func (s *server) ProcessesStart() {
|
2021-03-01 11:16:36 +00:00
|
|
|
// Start a subscriber for CLICommand messages
|
2021-02-24 09:58:02 +00:00
|
|
|
{
|
2021-03-01 11:16:36 +00:00
|
|
|
fmt.Printf("Starting CLICommand subscriber: %#v\n", s.nodeName)
|
|
|
|
sub := newSubject(CLICommand, CommandACK, s.nodeName)
|
2021-03-09 03:55:51 +00:00
|
|
|
proc := newProcess(s.processes, s.newMessagesCh, s.configuration, sub, s.errorKernel.errorCh, processKindSubscriber, []node{"central", "ship2"}, nil)
|
2021-02-24 09:58:02 +00:00
|
|
|
// fmt.Printf("*** %#v\n", proc)
|
2021-03-03 13:14:32 +00:00
|
|
|
go proc.spawnWorker(s)
|
2021-02-24 09:58:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start a subscriber for textLogging messages
|
|
|
|
{
|
|
|
|
fmt.Printf("Starting textlogging subscriber: %#v\n", s.nodeName)
|
|
|
|
sub := newSubject(TextLogging, EventACK, s.nodeName)
|
2021-03-09 03:55:51 +00:00
|
|
|
proc := newProcess(s.processes, s.newMessagesCh, s.configuration, sub, s.errorKernel.errorCh, processKindSubscriber, []node{"*"}, nil)
|
2021-02-24 09:58:02 +00:00
|
|
|
// fmt.Printf("*** %#v\n", proc)
|
2021-03-03 13:14:32 +00:00
|
|
|
go proc.spawnWorker(s)
|
2021-02-24 09:58:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start a subscriber for SayHello messages
|
|
|
|
{
|
|
|
|
fmt.Printf("Starting SayHello subscriber: %#v\n", s.nodeName)
|
|
|
|
sub := newSubject(SayHello, EventNACK, s.nodeName)
|
2021-03-09 03:55:51 +00:00
|
|
|
proc := newProcess(s.processes, s.newMessagesCh, s.configuration, sub, s.errorKernel.errorCh, processKindSubscriber, []node{"*"}, nil)
|
2021-03-05 12:10:46 +00:00
|
|
|
proc.procFuncCh = make(chan Message)
|
2021-03-10 06:11:14 +00:00
|
|
|
|
2021-03-05 12:10:46 +00:00
|
|
|
proc.procFunc = func() error {
|
|
|
|
sayHelloNodes := make(map[node]struct{})
|
|
|
|
for {
|
2021-03-10 13:14:09 +00:00
|
|
|
// Receive a copy of the message sent from the method handler.
|
2021-03-05 12:10:46 +00:00
|
|
|
m := <-proc.procFuncCh
|
2021-03-09 10:58:50 +00:00
|
|
|
fmt.Printf("--- DEBUG : procFunc call:kind=%v, Subject=%v, toNode=%v\n", proc.processKind, proc.subject, proc.subject.ToNode)
|
2021-03-10 13:14:09 +00:00
|
|
|
|
2021-03-05 12:10:46 +00:00
|
|
|
sayHelloNodes[m.FromNode] = struct{}{}
|
|
|
|
|
|
|
|
// update the prometheus metrics
|
|
|
|
s.metrics.metricsCh <- metricType{
|
|
|
|
metric: prometheus.NewGauge(prometheus.GaugeOpts{
|
|
|
|
Name: "hello_nodes",
|
|
|
|
Help: "The current number of total nodes who have said hello",
|
|
|
|
}),
|
|
|
|
value: float64(len(sayHelloNodes)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-03 13:14:32 +00:00
|
|
|
go proc.spawnWorker(s)
|
2021-02-24 09:58:02 +00:00
|
|
|
}
|
2021-02-24 14:43:31 +00:00
|
|
|
|
|
|
|
if s.centralErrorLogger {
|
|
|
|
// Start a subscriber for ErrorLog messages
|
|
|
|
{
|
|
|
|
fmt.Printf("Starting ErrorLog subscriber: %#v\n", s.nodeName)
|
|
|
|
sub := newSubject(ErrorLog, EventNACK, "errorCentral")
|
2021-03-09 03:55:51 +00:00
|
|
|
proc := newProcess(s.processes, s.newMessagesCh, s.configuration, sub, s.errorKernel.errorCh, processKindSubscriber, []node{"*"}, nil)
|
2021-03-03 13:14:32 +00:00
|
|
|
go proc.spawnWorker(s)
|
2021-02-24 14:43:31 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-09 10:58:50 +00:00
|
|
|
|
|
|
|
// --------- Testing with publisher ------------
|
|
|
|
// Define a process of kind publisher with subject for SayHello to central,
|
|
|
|
// and register a procFunc with the process that will handle the actual
|
|
|
|
// sending of say hello.
|
|
|
|
if s.configuration.PublisherServiceSayhello != 0 {
|
|
|
|
fmt.Printf("Starting SayHello Publisher: %#v\n", s.nodeName)
|
2021-03-10 13:14:09 +00:00
|
|
|
|
2021-03-09 10:58:50 +00:00
|
|
|
// TODO: Replace "central" name with variable below.
|
|
|
|
sub := newSubject(SayHello, EventNACK, "central")
|
|
|
|
proc := newProcess(s.processes, s.newMessagesCh, s.configuration, sub, s.errorKernel.errorCh, processKindPublisher, []node{}, nil)
|
|
|
|
|
2021-03-10 13:14:09 +00:00
|
|
|
// Define the procFun to be used for the process.
|
|
|
|
proc.procFunc = procFunc(
|
|
|
|
func() error {
|
|
|
|
for {
|
|
|
|
fmt.Printf("--- DEBUG : procFunc call:kind=%v, Subject=%v, toNode=%v\n", proc.processKind, proc.subject, proc.subject.ToNode)
|
2021-03-09 10:58:50 +00:00
|
|
|
|
2021-03-10 13:14:09 +00:00
|
|
|
d := fmt.Sprintf("Hello from %v\n", s.nodeName)
|
2021-03-09 10:58:50 +00:00
|
|
|
|
2021-03-10 13:14:09 +00:00
|
|
|
m := Message{
|
|
|
|
ToNode: "central",
|
|
|
|
FromNode: node(s.nodeName),
|
|
|
|
Data: []string{d},
|
|
|
|
Method: SayHello,
|
|
|
|
}
|
2021-03-10 06:11:14 +00:00
|
|
|
|
2021-03-10 13:14:09 +00:00
|
|
|
sam := createSAMfromMessage(m)
|
|
|
|
proc.newMessagesCh <- []subjectAndMessage{sam}
|
|
|
|
time.Sleep(time.Second * time.Duration(s.configuration.PublisherServiceSayhello))
|
|
|
|
}
|
|
|
|
})
|
2021-03-09 10:58:50 +00:00
|
|
|
go proc.spawnWorker(s)
|
|
|
|
}
|
2021-02-24 09:58:02 +00:00
|
|
|
}
|