Commit ee1087f6 authored by Stefan Dähling's avatar Stefan Dähling
Browse files

fixes

parent 2d55b528
Pipeline #439407 passed with stages
in 5 minutes and 15 seconds
......@@ -105,7 +105,6 @@ func StartAgency(task func(*Agent) error) (err error) {
return
}
go agency.receiveMsgs()
go agency.startAgents()
// catch kill signal in order to terminate agency and agents before exiting
var gracefulStop = make(chan os.Signal, 10)
......@@ -149,26 +148,57 @@ func (agency *Agency) init() (err error) {
agency.mutex.Lock()
if len(hostname) < 6 {
err = errors.New("incorrect hostname")
agency.mutex.Unlock()
return
}
agency.info.MASID, err = strconv.Atoi(hostname[1])
if err != nil {
agency.mutex.Unlock()
return
}
agency.info.ImageGroupID, err = strconv.Atoi(hostname[3])
if err != nil {
agency.mutex.Unlock()
return
}
agency.info.ID, err = strconv.Atoi(hostname[5])
if err != nil {
agency.mutex.Unlock()
return
}
agency.info.Name = temp + ".mas" + hostname[1] + "agencies"
agency.mutex.Unlock()
// request configuration
var agencyInfoFull schemas.AgencyInfoFull
agencyInfoFull, _, err = agency.amsClient.GetAgencyInfo(agency.info.MASID,
agency.info.ImageGroupID, agency.info.ID)
agency.mutex.Lock()
agency.info.ID = agencyInfoFull.ID
agency.info.Logger = agencyInfoFull.Logger
agency.info.Logger.Host = "logger"
agency.info.Logger.Port = 11000
agency.mutex.Unlock()
if err != nil {
agency.info.Status = schemas.Status{
Code: status.Error,
LastUpdate: time.Now(),
}
return
}
agency.mutex.Lock()
agency.logCollector, err = client.NewLogCollector(agency.info.MASID, agency.info.Logger,
agency.logError, agency.logInfo)
if err != nil {
agency.mutex.Unlock()
return
}
agency.mqttClient = newMQTTClient("mqtt", 1883, agency.info.Name, agency.logError,
agency.logInfo)
agency.mutex.Unlock()
go agency.startAgents(agencyInfoFull)
return
}
......@@ -189,22 +219,7 @@ func (agency *Agency) terminate(gracefulStop chan os.Signal) {
}
// startAgents starts all the agents
func (agency *Agency) startAgents() (err error) {
// request configuration
var agencyInfoFull schemas.AgencyInfoFull
agencyInfoFull, _, err = agency.amsClient.GetAgencyInfo(agency.info.MASID,
agency.info.ImageGroupID, agency.info.ID)
agency.mutex.Lock()
agency.info.ID = agencyInfoFull.ID
agency.info.Logger = agencyInfoFull.Logger
agency.mutex.Unlock()
if err != nil {
agency.info.Status = schemas.Status{
Code: status.Error,
LastUpdate: time.Now(),
}
return
}
func (agency *Agency) startAgents(agencyInfoFull schemas.AgencyInfoFull) (err error) {
agency.logInfo.Println("Starting agents")
for i := 0; i < len(agencyInfoFull.Agents); i++ {
err = agency.createAgent(agencyInfoFull.Agents[i])
......
......@@ -98,7 +98,9 @@ func newAgent(info schemas.AgentInfo, msgIn chan schemas.ACLMessage,
active: true,
}
// in, out := ag.ACL.getCommDataChannels()
ag.Logger = logCol.NewAgentLogger(ag.id, logConfig, ag.logError, ag.logInfo)
if logCol != nil {
ag.Logger = logCol.NewAgentLogger(ag.id, logConfig, ag.logError, ag.logInfo)
}
ag.ACL = newACL(info.ID, msgIn, aclLookup, ag.Logger, logErr, logInf)
ag.MQTT = newMQTT(ag.id, mqtt, ag.Logger, ag.logError, ag.logInfo)
ag.DF = newDF(ag.masID, ag.id, ag.nodeID, dfClient, ag.logError, ag.logInfo)
......
......@@ -264,6 +264,7 @@ func NewLogCollector(masID int, config schemas.LoggerConfig, logErr *log.Logger,
time.Second*1, 4)
if err != nil {
logCol.config.Active = false
return
}
}
logCol.logIn = make(chan schemas.LogMessage, 10000)
......@@ -289,6 +290,9 @@ type AgentLogger struct {
// NewLog sends a new logging message to the logging service
func (agLog *AgentLogger) NewLog(topic string, message string, data string) (err error) {
if agLog == nil {
return
}
agLog.mutex.Lock()
if !agLog.active {
agLog.mutex.Unlock()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment