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

fixes

parent 931119dc
Pipeline #439703 passed with stages
in 16 minutes and 9 seconds
......@@ -71,6 +71,9 @@ func task(ag *agency.Agent) (err error) {
svc := schemas.Service{
Desc: "agent" + strconv.Itoa(id),
}
ag.DF.RegisterService(svc)
_, err = ag.DF.RegisterService(svc)
if err != nil {
fmt.Println(err)
}
return
}
......@@ -109,7 +109,7 @@ func (agency *Agency) aclLookup(agentID int) (acl *ACL, err error) {
// check if remote agency is already known
if ok {
agency.logInfo.Println("New remote agent ", agentID, " in known agency ", address.Agency)
ag = newAgent(agentInfo, remAgency.msgIn, nil, nil, schemas.LoggerConfig{}, nil, nil,
ag = newAgent(agentInfo, remAgency.msgIn, nil, nil, schemas.LoggerConfig{}, nil, false, nil,
agency.logError, agency.logInfo)
} else {
agency.logInfo.Println("New remote agent ", agentID, " in unknown agency ", address.Agency)
......@@ -131,7 +131,7 @@ func (agency *Agency) aclLookup(agentID int) (acl *ACL, err error) {
numRemAgencies < numLocalAgs {
go agency.receiveMsgs()
}
ag = newAgent(agentInfo, remAgency.msgIn, nil, nil, schemas.LoggerConfig{}, nil, nil,
ag = newAgent(agentInfo, remAgency.msgIn, nil, nil, schemas.LoggerConfig{}, nil, false, nil,
agency.logError, agency.logInfo)
}
agency.mutex.Lock()
......
......@@ -172,8 +172,8 @@ func (agency *Agency) init() (err error) {
agency.mutex.Lock()
agency.info.ID = agencyInfoFull.ID
agency.info.Logger = agencyInfoFull.Logger
agency.info.Logger.Host = "logger"
agency.info.Logger.Port = 11000
agency.info.DF = agencyInfoFull.DF
agency.info.MQTT = agencyInfoFull.MQTT
agency.mutex.Unlock()
if err != nil {
agency.info.Status = schemas.Status{
......@@ -249,7 +249,7 @@ func (agency *Agency) createAgent(agentInfo schemas.AgentInfo) (err error) {
msgIn := make(chan schemas.ACLMessage, 1000)
agency.mutex.Lock()
ag := newAgent(agentInfo, msgIn, agency.aclLookup, agency.logCollector, agency.info.Logger,
agency.mqttClient, agency.dfClient, agency.logError, agency.logInfo)
agency.mqttClient, agency.info.DF.Active, agency.dfClient, agency.logError, agency.logInfo)
agency.localAgents[agentInfo.ID] = ag
agency.mutex.Unlock()
ag.startAgent(agency.agentTask)
......
......@@ -81,7 +81,8 @@ type Agent struct {
// newAgent creates a new agent
func newAgent(info schemas.AgentInfo, msgIn chan schemas.ACLMessage,
aclLookup func(int) (*ACL, error), logCol *client.LogCollector, logConfig schemas.LoggerConfig,
mqtt *mqttClient, dfClient *client.DFClient, logErr *log.Logger, logInf *log.Logger) (ag *Agent) {
mqtt *mqttClient, dfActive bool, dfClient *client.DFClient, logErr *log.Logger,
logInf *log.Logger) (ag *Agent) {
ag = &Agent{
id: info.ID,
nodeID: info.Spec.NodeID,
......@@ -102,7 +103,8 @@ func newAgent(info schemas.AgentInfo, msgIn chan schemas.ACLMessage,
}
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 = client.NewAgentDF(ag.masID, ag.id, ag.nodeID, dfClient, ag.logError, ag.logInfo)
ag.DF = client.NewAgentDF(ag.masID, ag.id, ag.nodeID, dfActive, dfClient, ag.logError,
ag.logInfo)
return
}
......
......@@ -388,6 +388,8 @@ func (stor *localStorage) getAgencyInfoFull(masID int, imID int,
ret.ID = agencyID
ret.ImageGroupID = imID
ret.Logger = stor.mas[masID].ImageGroups.Inst[imID].Agencies.Inst[agencyID].Logger
ret.DF = stor.mas[masID].ImageGroups.Inst[imID].Agencies.Inst[agencyID].DF
ret.MQTT = stor.mas[masID].ImageGroups.Inst[imID].Agencies.Inst[agencyID].MQTT
ret.Status = stor.mas[masID].ImageGroups.Inst[imID].Agencies.Inst[agencyID].Status
ret.Agents = make([]schemas.AgentInfo,
len(stor.mas[masID].ImageGroups.Inst[imID].Agencies.Inst[agencyID].Agents))
......
......@@ -53,7 +53,6 @@ import (
"log"
"net"
"net/http"
"os"
"strconv"
"sync"
"time"
......@@ -307,21 +306,22 @@ func (df *AgentDF) DeregisterService(svcID string) (err error) {
}
// NewAgentDF creates a new DF object
func NewAgentDF(masID int, agentID int, nodeID int, dfCli *DFClient, logErr *log.Logger,
func NewAgentDF(masID int, agentID int, nodeID int, active bool, dfCli *DFClient, logErr *log.Logger,
logInf *log.Logger) (df *AgentDF) {
df = &AgentDF{
agentID: agentID,
masID: masID,
nodeID: nodeID,
mutex: &sync.Mutex{},
active: false,
active: active,
logError: logErr,
logInfo: logInf,
dfClient: dfCli,
}
act := os.Getenv("CLONEMAP_DF")
if act == "ON" {
df.active = true
}
// act := os.Getenv("CLONEMAP_DF")
// if act == "ON" {
// df.active = true
// }
df.registeredServices = make(map[string]schemas.Service)
return
}
......
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