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

make mas id, name andcustom accessible in agent

parent fcf5291f
Pipeline #568361 passed with stages
in 9 minutes and 43 seconds
......@@ -68,6 +68,7 @@ func task(ag *agency.Agent) (err error) {
msg, _ := ag.ACL.NewMessage(recv, 0, 0, "test message")
ag.ACL.SendMessage(msg)
ag.Logger.NewLog("app", "This is agent "+strconv.Itoa(id), "")
ag.Logger.NewLog("app", ag.GetMASName()+", "+ag.GetMASCustomData(), "")
svc := schemas.Service{
Desc: "agent" + strconv.Itoa(id),
}
......
......@@ -109,8 +109,8 @@ 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, false, nil,
agency.logError, agency.logInfo)
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)
// create new remote agency
......@@ -131,8 +131,8 @@ 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, false, nil,
agency.logError, agency.logInfo)
ag = newAgent(agentInfo, "", "", remAgency.msgIn, nil, nil, schemas.LoggerConfig{}, nil,
false, nil, agency.logError, agency.logInfo)
}
agency.mutex.Lock()
agency.remoteAgents[agentID] = ag
......
......@@ -65,7 +65,12 @@ import (
// Agency contains information about agents located in agency
type Agency struct {
info schemas.AgencyInfo // configuration of agency
info schemas.AgencyInfo // configuration of agency
loggerConfig schemas.LoggerConfig
dfConfig schemas.DFConfig
mqttConfig schemas.MQTTConfig
masName string
masCustom string
// agents []schemas.AgentInfo // list of agents in agency
localAgents map[int]*Agent
remoteAgents map[int]*Agent
......@@ -171,9 +176,11 @@ func (agency *Agency) init() (err error) {
agency.info.ImageGroupID, agency.info.ID)
agency.mutex.Lock()
agency.info.ID = agencyInfoFull.ID
agency.info.Logger = agencyInfoFull.Logger
agency.info.DF = agencyInfoFull.DF
agency.info.MQTT = agencyInfoFull.MQTT
agency.loggerConfig = agencyInfoFull.Logger
agency.dfConfig = agencyInfoFull.DF
agency.mqttConfig = agencyInfoFull.MQTT
agency.masName = agencyInfoFull.MASName
agency.masCustom = agencyInfoFull.MASCustom
agency.mutex.Unlock()
if err != nil {
agency.info.Status = schemas.Status{
......@@ -184,11 +191,11 @@ func (agency *Agency) init() (err error) {
}
agency.mutex.Lock()
agency.logCollector = client.NewLogCollector(agency.info.MASID, agency.info.Logger,
agency.logCollector = client.NewLogCollector(agency.info.MASID, agency.loggerConfig,
agency.logError, agency.logInfo)
agency.dfClient = client.NewDFClient(agency.info.DF.Host, agency.info.DF.Port,
agency.dfClient = client.NewDFClient(agency.dfConfig.Host, agency.dfConfig.Port,
time.Second*60, time.Second*1, 4)
agency.mqttCollector = newMQTTCollector(agency.info.MQTT, agency.info.Name, agency.logError,
agency.mqttCollector = newMQTTCollector(agency.mqttConfig, agency.info.Name, agency.logError,
agency.logInfo)
agency.mutex.Unlock()
......@@ -244,9 +251,9 @@ func (agency *Agency) createAgent(agentInfo schemas.AgentInfo) (err error) {
agentInfo.Status.Code = status.Starting
msgIn := make(chan schemas.ACLMessage, 1000)
agency.mutex.Lock()
ag := newAgent(agentInfo, msgIn, agency.aclLookup, agency.logCollector, agency.info.Logger,
agency.mqttCollector, agency.info.DF.Active, agency.dfClient, agency.logError,
agency.logInfo)
ag := newAgent(agentInfo, agency.masName, agency.masCustom, msgIn, agency.aclLookup,
agency.logCollector, agency.loggerConfig, agency.mqttCollector, agency.dfConfig.Active,
agency.dfClient, agency.logError, agency.logInfo)
agency.localAgents[agentInfo.ID] = ag
agency.mutex.Unlock()
ag.startAgent(agency.agentTask)
......
......@@ -62,12 +62,14 @@ type Agent struct {
mutex *sync.Mutex
id int // unique id of agent
nodeID int
name string // Name of agent
aType string // Type of agent
aSubtype string // Subtype of agent
custom string // custom data
customChan chan string // channel for custom update behavior
masID int // ID of MAS agent is belongs to
name string // Name of agent
aType string // Type of agent
aSubtype string // Subtype of agent
custom string // custom data
customChan chan string // channel for custom update behavior
masID int // ID of MAS agent is belongs to
masName string
masCustom string
status int // Status of agent
ACL *ACL // agent communication
Logger *client.AgentLogger // logger object
......@@ -79,10 +81,10 @@ 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,
mqttCol *mqttCollector, dfActive bool, dfClient *client.DFClient, logErr *log.Logger,
logInf *log.Logger) (ag *Agent) {
func newAgent(info schemas.AgentInfo, masName string, masCustom string,
msgIn chan schemas.ACLMessage, aclLookup func(int) (*ACL, error), logCol *client.LogCollector,
logConfig schemas.LoggerConfig, mqttCol *mqttCollector, dfActive bool,
dfClient *client.DFClient, logErr *log.Logger, logInf *log.Logger) (ag *Agent) {
ag = &Agent{
id: info.ID,
nodeID: info.Spec.NodeID,
......@@ -90,6 +92,8 @@ func newAgent(info schemas.AgentInfo, msgIn chan schemas.ACLMessage,
aType: info.Spec.AType,
aSubtype: info.Spec.ASubtype,
masID: info.MASID,
masName: masName,
masCustom: masCustom,
custom: info.Spec.Custom,
customChan: nil,
mutex: &sync.Mutex{},
......@@ -153,6 +157,30 @@ func (agent *Agent) GetCustomData() (ret string) {
return
}
// GetMASID returns mas id
func (agent *Agent) GetMASID() (ret int) {
agent.mutex.Lock()
ret = agent.masID
agent.mutex.Unlock()
return
}
// GetMASName returns mas name
func (agent *Agent) GetMASName() (ret string) {
agent.mutex.Lock()
ret = agent.masName
agent.mutex.Unlock()
return
}
// GetMASVustom returns mas custom config
func (agent *Agent) GetMASCustomData() (ret string) {
agent.mutex.Lock()
ret = agent.masCustom
agent.mutex.Unlock()
return
}
// registerCustomUpdateChannel sets the channel for a custom config update behavior if not already
// set
func (agent *Agent) registerCustomUpdateChannel(custChan chan string) (err error) {
......
......@@ -388,10 +388,10 @@ func (ams *AMS) configureMAS(masSpec schemas.MASSpec) (masInfo schemas.MASInfo,
agencyInfo := schemas.AgencyInfo{
ImageGroupID: i,
ID: j,
Logger: masInfo.Config.Logger,
DF: masInfo.Config.DF,
MQTT: masInfo.Config.MQTT,
Name: "-im-" + strconv.Itoa(i) + "-agency-" + strconv.Itoa(j),
// Logger: masInfo.Config.Logger,
// DF: masInfo.Config.DF,
// MQTT: masInfo.Config.MQTT,
Name: "-im-" + strconv.Itoa(i) + "-agency-" + strconv.Itoa(j),
}
for k := 0; k < masSpec.Config.NumAgentsPerAgency; k++ {
if agentCounter >= len(masSpec.ImageGroups[i].Agents) {
......
......@@ -454,7 +454,7 @@ func (stor *etcdStorage) addAgent(masID int, imID int,
ID: agencyID,
Name: "mas-" + strconv.Itoa(masID) + "-im-" + strconv.Itoa(imID) +
"-agency-" + strconv.Itoa(agencyID) + ".mas" + strconv.Itoa(masID) + "agencies",
Logger: stor.mas[masID].Config.Logger,
// Logger: stor.mas[masID].Config.Logger,
Agents: []int{agentID},
}
......
......@@ -497,7 +497,7 @@ func (stor *fiwareStorage) getAgencyInfoFull(masID int, imID int,
ret.Name = agencyInfo.Name
ret.ID = agencyID
ret.ImageGroupID = imID
ret.Logger = agencyInfo.Logger
// ret.Logger = agencyInfo.Logger
ret.Status = agencyInfo.Status
ret.Agents = make([]schemas.AgentInfo, len(agencyInfo.Agents), len(agencyInfo.Agents))
for i := 0; i < len(ret.Agents); i++ {
......@@ -776,7 +776,7 @@ func (stor *fiwareStorage) addAgent(masID int, imID int,
ID: agencyID,
Name: "mas-" + strconv.Itoa(masID) + "-im-" + strconv.Itoa(imID) +
"-agency-" + strconv.Itoa(agencyID) + ".mas" + strconv.Itoa(masID) + "agencies",
Logger: masConfig.Logger,
// Logger: masConfig.Logger,
Agents: []int{agentID},
}
agencyEntity := orion.Entity{
......
......@@ -426,7 +426,7 @@ func (ams *AMS) handleGetAgencies(w http.ResponseWriter, r *http.Request) {
}
// handleGetAgencyID is the handler for get requests to path
// /api/clonemap/mas/{masid}/imgroup/{imid}/agencies/{agencyid}
// /api/clonemap/mas/{masid}/imgroup/{imid}/agency/{agencyid}
func (ams *AMS) handleGetAgencyID(w http.ResponseWriter, r *http.Request) {
var cmapErr, httpErr error
vars := mux.Vars(r)
......
......@@ -98,7 +98,7 @@ type storage interface {
// getAgencies returns specs of all agencies in MAS
getAgencies(masID int) (ret schemas.Agencies, err error)
// getAgencyInfoFull returns status of one agency
// getAgencyInfoFull returns complete info of one agency
getAgencyInfoFull(masID int, imID int, agencyID int) (ret schemas.AgencyInfoFull, err error)
// registerMAS registers a new MAS with the storage and returns its ID
......@@ -387,9 +387,12 @@ func (stor *localStorage) getAgencyInfoFull(masID int, imID int,
ret.Name = stor.mas[masID].ImageGroups.Inst[imID].Agencies.Inst[agencyID].Name
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.Logger = stor.mas[masID].ImageGroups.Inst[imID].Agencies.Inst[agencyID].Logger
ret.Logger = stor.mas[masID].Config.Logger
ret.DF = stor.mas[masID].Config.DF
ret.MQTT = stor.mas[masID].Config.MQTT
ret.MASName = stor.mas[masID].Config.Name
ret.MASCustom = stor.mas[masID].Config.Custom
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))
......@@ -557,7 +560,7 @@ func (stor *localStorage) addAgent(masID int, imID int,
ID: agencyID,
Name: "mas-" + strconv.Itoa(masID) + "-im-" + strconv.Itoa(imID) +
"-agency-" + strconv.Itoa(agencyID) + ".mas" + strconv.Itoa(masID) + "agencies",
Logger: stor.mas[masID].Config.Logger,
// Logger: stor.mas[masID].Config.Logger,
Agents: []int{agentID},
}
stor.mas[masID].ImageGroups.Inst[imID].Agencies.Inst =
......
......@@ -107,11 +107,12 @@ type MASSpec struct {
// MASConfig contains configuration of MAS
type MASConfig struct {
Name string `json:"name,omitempty"` // name/description of MAS
NumAgentsPerAgency int `json:"agentsperagency"` // number of agents per agency
MQTT MQTTConfig `json:"mqtt"` //switch for mqtt
DF DFConfig `json:"df"` //switch for df
Logger LoggerConfig `json:"logger"` // logger configuration
Name string `json:"name,omitempty"` // name/description of MAS
NumAgentsPerAgency int `json:"agentsperagency"` // number of agents per agency
MQTT MQTTConfig `json:"mqtt"` //switch for mqtt
DF DFConfig `json:"df"` //switch for df
Logger LoggerConfig `json:"logger"` // logger configuration
Custom string `json:"custom,omitempty"` // custom configuration data
}
// ImageGroupInfo contains information about all agents that have the same image
......@@ -166,26 +167,30 @@ type Status struct {
// AgencyInfo contains information about agency spec and status (for storage)
type AgencyInfo struct {
MASID int `json:"masid"` // ID of MAS
Name string `json:"name"` // name of agency (hostname of pod given by kubernetes)
ID int `json:"id"` // within image group unique ID (contained in name)
ImageGroupID int `json:"imid"` // ID of agency image group
Logger LoggerConfig `json:"logger"` // logger configuration
MQTT MQTTConfig `json:"mqtt"` // MQTT configuration
DF DFConfig `json:"df"` // DF configuration
Agents []int `json:"agents"`
Status Status `json:"status"`
MASID int `json:"masid"` // ID of MAS
Name string `json:"name"` // name of agency (hostname of pod given by kubernetes)
ID int `json:"id"` // within image group unique ID (contained in name)
ImageGroupID int `json:"imid"` // ID of agency image group
// Logger LoggerConfig `json:"logger"` // logger configuration
// MQTT MQTTConfig `json:"mqtt"` // MQTT configuration
// DF DFConfig `json:"df"` // DF configuration
// MASName string `json:"masname"` // name of MAS as specified by user in MASConfig
// MASCustom string `json:"custom,omitempty"` // custom global configuration data from MASConfig
Agents []int `json:"agents"`
Status Status `json:"status"`
}
// AgencyInfoFull contains information about agency and full info about agents it conatins (for api)
type AgencyInfoFull struct {
MASID int `json:"masid"` // ID of MAS
Name string `json:"name"` // name of agency (hostname of pod given by kubernetes)
ID int `json:"id"` // within image group unique ID (contained in name)
ImageGroupID int `json:"imid"` // ID of agency image group
Logger LoggerConfig `json:"logger"` // logger configuration
MQTT MQTTConfig `json:"mqtt"` // MQTT configuration
DF DFConfig `json:"df"` // DF configuration
MASID int `json:"masid"` // ID of MAS
Name string `json:"name"` // name of agency (hostname of pod given by kubernetes)
ID int `json:"id"` // within image group unique ID (contained in name)
ImageGroupID int `json:"imid"` // ID of agency image group
Logger LoggerConfig `json:"logger"` // logger configuration
MQTT MQTTConfig `json:"mqtt"` // MQTT configuration
DF DFConfig `json:"df"` // DF configuration
MASName string `json:"masname"` // name of MAS as specified by user in MASConfig
MASCustom string `json:"custom,omitempty"` // custom global configuration data from MASConfig
Agents []AgentInfo `json:"agents"`
Status Status `json:"status"`
}
......
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