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

cleanup of core schemas

parent d9f03c54
Pipeline #259911 passed with stages
in 2 minutes and 52 seconds
......@@ -104,10 +104,10 @@ func (agency *Agency) aclLookup(agentID int) (acl *ACL, err error) {
agency.mutex.Unlock()
// check if remote agency is already known
if ok {
agency.logInfo.Println("New remote agent ", agentInfo.Spec.ID, " in known agency ", address.Agency)
agency.logInfo.Println("New remote agent ", agentInfo.ID, " in known agency ", address.Agency)
ag = newAgent(agentInfo, remAgency.msgIn, nil, nil, schemas.LogConfig{}, nil, agency.logError, agency.logInfo)
} else {
agency.logInfo.Println("New remote agent ", agentInfo.Spec.ID, " in unknown agency ", address.Agency)
agency.logInfo.Println("New remote agent ", agentInfo.ID, " in unknown agency ", address.Agency)
// create new remote agency
remAgency = &remoteAgency{
msgIn: make(chan schemas.ACLMessage, 1000),
......
......@@ -166,9 +166,9 @@ func (agency *Agency) terminate(gracefulStop chan os.Signal) {
// startAgents starts all the agents
func (agency *Agency) startAgents() (err error) {
// request configuration
var agencyConfig schemas.AgencyConfig
agencyConfig, _, err = amsclient.GetAgencyConfig(agency.info.Spec.MASID, agency.info.Spec.ID)
agency.info.Spec.Logger = agencyConfig.Spec.Logger
var agencySpec schemas.AgencySpec
agencySpec, _, err = amsclient.GetAgencySpec(agency.info.Spec.MASID, agency.info.Spec.ID)
agency.info.Spec.Logger = agencySpec.Logger
if err != nil {
agency.info.Status = schemas.Status{
Code: status.Error,
......@@ -177,8 +177,8 @@ func (agency *Agency) startAgents() (err error) {
return
}
agency.logInfo.Println("Starting agents")
for i := 0; i < len(agencyConfig.Agents); i++ {
err = agency.createAgent(agencyConfig.Agents[i])
for i := 0; i < len(agencySpec.Agents); i++ {
err = agency.createAgent(agencySpec.Agents[i])
if err != nil {
agency.mutex.Lock()
agency.info.Status = schemas.Status{
......@@ -196,7 +196,7 @@ func (agency *Agency) startAgents() (err error) {
func (agency *Agency) createAgent(agentInfo schemas.AgentInfo) (err error) {
// check if agent does not exist
agency.mutex.Lock()
_, agExist := agency.localAgents[agentInfo.Spec.ID]
_, agExist := agency.localAgents[agentInfo.ID]
agency.mutex.Unlock()
if agExist {
err = errors.New("NotAllowedError")
......@@ -208,7 +208,7 @@ func (agency *Agency) createAgent(agentInfo schemas.AgentInfo) (err error) {
agency.mutex.Lock()
ag := newAgent(agentInfo, msgIn, agency.aclLookup, agency.logger, agency.info.Spec.Logger,
agency.mqtt, agency.logError, agency.logInfo)
agency.localAgents[agentInfo.Spec.ID] = ag
agency.localAgents[agentInfo.ID] = ag
agency.mutex.Unlock()
ag.startAgent(agency.agentTask)
return
......
......@@ -79,15 +79,15 @@ func newAgent(info schemas.AgentInfo, msgIn chan schemas.ACLMessage,
aclLookup func(int) (*ACL, error), log *loggerClient, logConfig schemas.LogConfig,
mqtt *mqttClient, logErr *log.Logger, logInf *log.Logger) (ag *Agent) {
ag = &Agent{
id: info.Spec.ID,
id: info.ID,
nodeID: info.Spec.NodeID,
name: info.Spec.Name,
aType: info.Spec.AType,
aSubtype: info.Spec.ASubtype,
masID: info.Spec.MASID,
masID: info.MASID,
custom: info.Spec.Custom,
mutex: &sync.Mutex{},
ACL: newACL(info.Spec.ID, msgIn, aclLookup, logErr, logInf),
ACL: newACL(info.ID, msgIn, aclLookup, logErr, logInf),
logError: logErr,
logInfo: logInf,
}
......
......@@ -185,16 +185,16 @@ func (ams *AMS) getAgencies(masID int) (ret schemas.Agencies, err error) {
return
}
// getAgencyConfig returns status of one agency
func (ams *AMS) getAgencyConfig(masID int, agencyID int) (ret schemas.AgencyConfig, err error) {
ret, err = ams.stor.getAgencyConfig(masID, agencyID)
// getAgencySpec returns status of one agency
func (ams *AMS) getAgencySpec(masID int, agencyID int) (ret schemas.AgencySpec, err error) {
ret, err = ams.stor.getAgencySpec(masID, agencyID)
return
}
// createMAS creates a new mas according to masconfig
func (ams *AMS) createMAS(masConf schemas.MASConfig) (err error) {
func (ams *AMS) createMAS(masSpec schemas.MASSpec) (err error) {
// fill masInfo
masInfo, numAgencies := ams.configureMAS(masConf)
masInfo, numAgencies := ams.configureMAS(masSpec)
// safe mas in storage and get ID
var masID int
......@@ -229,8 +229,8 @@ func (ams *AMS) startMAS(masID int, masInfo schemas.MASInfo, numAgencies int) (e
image := ""
pullSecret := ""
if len(masInfo.Agents.Instances) > 0 {
image = masInfo.Agents.Instances[0].AgencyImage
pullSecret = masInfo.Agents.Instances[0].ImagePullSecret
image = masInfo.Agents.Instances[0].Spec.AgencyImage
pullSecret = masInfo.Agents.Instances[0].Spec.ImagePullSecret
}
err = ams.depl.newMAS(masID, image, pullSecret, numAgencies, masInfo.Spec.Logging,
masInfo.Spec.MQTT, masInfo.Spec.DF)
......@@ -244,30 +244,30 @@ func (ams *AMS) startMAS(masID int, masInfo schemas.MASInfo, numAgencies int) (e
}
// configureMAS fills the missing configuration as agencies, agent ids and addresses
func (ams *AMS) configureMAS(masConf schemas.MASConfig) (masInfo schemas.MASInfo, numAgencies int) {
func (ams *AMS) configureMAS(masSpec schemas.MASSpec) (masInfo schemas.MASInfo, numAgencies int) {
// MAS configuration
masInfo.Spec = masConf.Spec
masInfo.Agents.Counter = len(masConf.Agents)
masInfo.Agents.Instances = make([]schemas.AgentSpec, masInfo.Agents.Counter,
masInfo.Spec = masSpec
masInfo.Agents.Counter = len(masSpec.Agents)
masInfo.Agents.Instances = make([]schemas.AgentInfo, masInfo.Agents.Counter,
masInfo.Agents.Counter)
numAgencies = len(masConf.Agents) / masConf.Spec.NumAgentsPerAgency
if len(masConf.Agents)%masConf.Spec.NumAgentsPerAgency > 0 {
numAgencies = len(masSpec.Agents) / masSpec.NumAgentsPerAgency
if len(masSpec.Agents)%masSpec.NumAgentsPerAgency > 0 {
numAgencies++
}
masInfo.Agencies.Counter = numAgencies
masInfo.Agencies.Instances = make([]schemas.AgencySpec, numAgencies, numAgencies)
masInfo.Graph = masConf.Graph
masInfo.Agencies.Instances = make([]schemas.AgencyInfo, numAgencies, numAgencies)
masInfo.Graph = masSpec.Graph
if len(masInfo.Graph.Node) == 0 {
masInfo.Graph.Node = append(masInfo.Graph.Node, schemas.Node{ID: 0})
}
// agent configuration
for i := 0; i < masInfo.Agents.Counter; i++ {
masInfo.Agents.Instances[i] = masConf.Agents[i]
masInfo.Agents.Instances[i].Spec = masSpec.Agents[i]
masInfo.Agents.Instances[i].ID = i
masInfo.Agents.Instances[i].AgencyID = i / masConf.Spec.NumAgentsPerAgency
masInfo.Agents.Instances[i].AgencyID = i / masSpec.NumAgentsPerAgency
for j := range masInfo.Graph.Node {
if masInfo.Graph.Node[j].ID == masInfo.Agents.Instances[i].NodeID {
if masInfo.Graph.Node[j].ID == masInfo.Agents.Instances[i].Spec.NodeID {
masInfo.Graph.Node[j].Agent = append(masInfo.Graph.Node[j].Agent,
masInfo.Agents.Instances[i].ID)
break
......@@ -280,16 +280,16 @@ func (ams *AMS) configureMAS(masConf schemas.MASConfig) (masInfo schemas.MASInfo
for i := 0; i < numAgencies; i++ {
agencySpec := schemas.AgencySpec{
ID: i,
Logger: masConf.Spec.Logger,
Logger: masSpec.Logger,
}
for j := 0; j < masConf.Spec.NumAgentsPerAgency; j++ {
for j := 0; j < masSpec.NumAgentsPerAgency; j++ {
if agentCounter >= masInfo.Agents.Counter {
break
}
agencySpec.Agents = append(agencySpec.Agents, agentCounter)
agencySpec.Agents = append(agencySpec.Agents, masInfo.Agents.Instances[agentCounter])
agentCounter++
}
masInfo.Agencies.Instances[i] = agencySpec
masInfo.Agencies.Instances[i].Spec = agencySpec
}
return
}
......
......@@ -126,14 +126,12 @@ func dummyClient(s *http.Server, t *testing.T) {
if httpStatus != http.StatusOK {
t.Error("Error GetCloneMAP " + strconv.Itoa(httpStatus))
}
mas := schemas.MASConfig{
Spec: schemas.MASSpec{
Name: "test",
NumAgentsPerAgency: 10,
Logging: false,
MQTT: false,
DF: false,
},
mas := schemas.MASSpec{
Name: "test",
NumAgentsPerAgency: 10,
Logging: false,
MQTT: false,
DF: false,
Agents: []schemas.AgentSpec{
schemas.AgentSpec{
AgencyImage: "agent",
......@@ -205,7 +203,7 @@ func dummyClient(s *http.Server, t *testing.T) {
t.Error("Error GetAgencies " + strconv.Itoa(httpStatus))
}
_, httpStatus, err = amsclient.GetAgencyConfig(0, 0)
_, httpStatus, err = amsclient.GetAgencySpec(0, 0)
if err != nil {
t.Error(err)
}
......
......@@ -98,7 +98,7 @@ func GetMASs() (mass schemas.MASs, httpStatus int, err error) {
}
// PostMAS post an mas
func PostMAS(mas schemas.MASConfig) (httpStatus int, err error) {
func PostMAS(mas schemas.MASSpec) (httpStatus int, err error) {
js, _ := json.Marshal(mas)
_, httpStatus, err = httpretry.Post(httpClient, "http://"+Host+":"+strconv.Itoa(Port)+
"/api/clonemap/mas", "application/json", js, time.Second*2, 2)
......@@ -190,8 +190,8 @@ func GetAgencies(masID int) (agencies schemas.Agencies, httpStatus int, err erro
return
}
// GetAgencyConfig requests agency information
func GetAgencyConfig(masID int, agencyID int) (agency schemas.AgencyConfig, httpStatus int,
// GetAgencySpec requests agency information
func GetAgencySpec(masID int, agencyID int) (agency schemas.AgencySpec, httpStatus int,
err error) {
var body []byte
body, httpStatus, err = httpretry.Get(httpClient, "http://"+Host+":"+strconv.Itoa(Port)+
......@@ -203,7 +203,7 @@ func GetAgencyConfig(masID int, agencyID int) (agency schemas.AgencyConfig, http
//fmt.Println(string(body))
err = json.Unmarshal(body, &agency)
if err != nil {
agency = schemas.AgencyConfig{}
agency = schemas.AgencySpec{}
}
return
}
......
......@@ -203,12 +203,12 @@ func (stor *etcdStorage) uploadAgentInfo(newMAS masStorage) (err error) {
if err != nil {
return
}
Ops[i] = clientv3.OpPut("ams/mas/"+strconv.Itoa(newMAS.spec.ID)+"/agent/"+
Ops[i] = clientv3.OpPut("ams/mas/"+strconv.Itoa(newMAS.id)+"/agent/"+
strconv.Itoa(agentIndex), string(res))
agentIndex++
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
cond := clientv3.Compare(clientv3.Version("ams/mas/"+strconv.Itoa(newMAS.spec.ID)+
cond := clientv3.Compare(clientv3.Version("ams/mas/"+strconv.Itoa(newMAS.id)+
"/agentcounter"), ">", 0)
_, err = stor.client.Txn(ctx).If(cond).Then(Ops...).Commit()
cancel()
......@@ -239,12 +239,12 @@ func (stor *etcdStorage) uploadAgencyInfo(newMAS masStorage) (err error) {
if err != nil {
return
}
Ops[i] = clientv3.OpPut("ams/mas/"+strconv.Itoa(newMAS.spec.ID)+"/agency/"+
Ops[i] = clientv3.OpPut("ams/mas/"+strconv.Itoa(newMAS.id)+"/agency/"+
strconv.Itoa(agencyIndex), string(res))
agencyIndex++
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
cond := clientv3.Compare(clientv3.Version("ams/mas/"+strconv.Itoa(newMAS.spec.ID)+
cond := clientv3.Compare(clientv3.Version("ams/mas/"+strconv.Itoa(newMAS.id)+
"/agencycounter"), ">", 0)
_, err = stor.client.Txn(ctx).If(cond).Then(Ops...).Commit()
cancel()
......
......@@ -138,19 +138,19 @@ func (ams *AMS) handleAPI(w http.ResponseWriter, r *http.Request) {
resvalid = true
}
}
} else if respath[5] == "agencies" {
var agencyID int
agencyID, cmapErr = strconv.Atoi(respath[6])
if cmapErr == nil {
// if respath[7] == "status" {
// cmapErr, httpErr = ams.handleAgencyStatus(masID, agencyID, w, r)
// resvalid = true
// } else
if respath[7] == "config" {
cmapErr, httpErr = ams.handleAgencyConfig(masID, agencyID, w, r)
resvalid = true
}
}
// } else if respath[5] == "agencies" {
// var agencyID int
// agencyID, cmapErr = strconv.Atoi(respath[6])
// if cmapErr == nil {
// // if respath[7] == "status" {
// // cmapErr, httpErr = ams.handleAgencyStatus(masID, agencyID, w, r)
// // resvalid = true
// // } else
// if respath[7] == "config" {
// cmapErr, httpErr = ams.handleAgencyConfig(masID, agencyID, w, r)
// resvalid = true
// }
// }
}
}
default:
......@@ -195,10 +195,10 @@ func (ams *AMS) handleMAS(w http.ResponseWriter, r *http.Request) (cmapErr, http
var body []byte
body, cmapErr = ioutil.ReadAll(r.Body)
if cmapErr == nil {
var masConfig schemas.MASConfig
cmapErr = json.Unmarshal(body, &masConfig)
var masSpec schemas.MASSpec
cmapErr = json.Unmarshal(body, &masSpec)
if cmapErr == nil {
cmapErr = ams.createMAS(masConfig)
cmapErr = ams.createMAS(masSpec)
if cmapErr == nil {
httpErr = httpreply.Created(w, cmapErr, "text/plain", []byte("Ressource Created"))
} else {
......@@ -340,9 +340,9 @@ func (ams *AMS) handleAgency(masID int, w http.ResponseWriter, r *http.Request)
func (ams *AMS) handleAgencyID(masID int, agencyid int, w http.ResponseWriter,
r *http.Request) (cmapErr, httpErr error) {
if r.Method == "GET" {
var agencyConfig schemas.AgencyConfig
agencyConfig, cmapErr = ams.getAgencyConfig(masID, agencyid)
httpErr = httpreply.Resource(w, agencyConfig, cmapErr)
var agencySpec schemas.AgencySpec
agencySpec, cmapErr = ams.getAgencySpec(masID, agencyid)
httpErr = httpreply.Resource(w, agencySpec, cmapErr)
} else {
httpErr = httpreply.MethodNotAllowed(w)
cmapErr = errors.New("Error: Method not allowed on path /api/clonemap/mas/{mas-id}/" +
......@@ -351,22 +351,22 @@ func (ams *AMS) handleAgencyID(masID int, agencyid int, w http.ResponseWriter,
return
}
// handleAgencyConfig is the handler for requests to path
// /api/clonemap/mas/{mas-id}/agencies/{agency-id}/config
func (ams *AMS) handleAgencyConfig(masID int, agencyid int, w http.ResponseWriter,
r *http.Request) (cmapErr, httpErr error) {
if r.Method == "GET" {
// return config of specified agency
var agencyConfig schemas.AgencyConfig
agencyConfig, cmapErr = ams.getAgencyConfig(masID, agencyid)
httpErr = httpreply.Resource(w, agencyConfig, cmapErr)
} else {
httpErr = httpreply.MethodNotAllowed(w)
cmapErr = errors.New("Error: Method not allowed on path /api/clonemap/mas/{mas-id}/" +
"agencies/{agency-id}/config")
}
return
}
// // handleAgencyConfig is the handler for requests to path
// // /api/clonemap/mas/{mas-id}/agencies/{agency-id}/config
// func (ams *AMS) handleAgencyConfig(masID int, agencyid int, w http.ResponseWriter,
// r *http.Request) (cmapErr, httpErr error) {
// if r.Method == "GET" {
// // return config of specified agency
// var agencyConfig schemas.AgencyConfig
// agencyConfig, cmapErr = ams.getAgencyConfig(masID, agencyid)
// httpErr = httpreply.Resource(w, agencyConfig, cmapErr)
// } else {
// httpErr = httpreply.MethodNotAllowed(w)
// cmapErr = errors.New("Error: Method not allowed on path /api/clonemap/mas/{mas-id}/" +
// "agencies/{agency-id}/config")
// }
// return
// }
// listen opens a http server listening and serving request
func (ams *AMS) listen() (err error) {
......
......@@ -86,8 +86,8 @@ type storage interface {
// getAgencies returns specs of all agencies in MAS
getAgencies(masID int) (ret schemas.Agencies, err error)
// getAgencyConfig returns status of one agency
getAgencyConfig(masID int, agencyID int) (ret schemas.AgencyConfig, err error)
// getAgencySpec returns status of one agency
getAgencySpec(masID int, agencyID int) (ret schemas.AgencySpec, err error)
// registerMAS registers a new MAS with the storage and returns its ID
registerMAS() (masID int, err error)
......@@ -122,6 +122,7 @@ type localStorage struct {
// mas storage
type masStorage struct {
id int // mas id
spec schemas.MASSpec
status schemas.Status
agentCounter int // counter for agents
......@@ -170,16 +171,16 @@ func (stor *localStorage) getMASInfo(masID int) (ret schemas.MASInfo, err error)
ret.Spec = stor.mas[masID].spec
ret.Status = stor.mas[masID].status
ret.Graph = stor.mas[masID].graph
ret.Agencies.Instances = make([]schemas.AgencySpec, len(stor.mas[masID].agencies),
ret.Agencies.Instances = make([]schemas.AgencyInfo, len(stor.mas[masID].agencies),
len(stor.mas[masID].agencies))
for i := 0; i < len(stor.mas[masID].agencies); i++ {
ret.Agencies.Instances[i] = stor.mas[masID].agencies[i].Spec
ret.Agencies.Instances[i].Spec = stor.mas[masID].agencies[i].Spec
}
ret.Agencies.Counter = stor.mas[masID].agencyCounter
ret.Agents.Instances = make([]schemas.AgentSpec, len(stor.mas[masID].agents),
ret.Agents.Instances = make([]schemas.AgentInfo, len(stor.mas[masID].agents),
len(stor.mas[masID].agents))
for i := 0; i < len(stor.mas[masID].agents); i++ {
ret.Agents.Instances[i] = stor.mas[masID].agents[i].Spec
ret.Agents.Instances[i].Spec = stor.mas[masID].agents[i].Spec
}
ret.Agents.Counter = stor.mas[masID].agentCounter
stor.mutex.Unlock()
......@@ -194,10 +195,10 @@ func (stor *localStorage) getAgents(masID int) (ret schemas.Agents, err error) {
err = errors.New("MAS does not exist")
return
}
ret.Instances = make([]schemas.AgentSpec, len(stor.mas[masID].agents),
ret.Instances = make([]schemas.AgentInfo, len(stor.mas[masID].agents),
len(stor.mas[masID].agents))
for i := 0; i < len(stor.mas[masID].agents); i++ {
ret.Instances[i] = stor.mas[masID].agents[i].Spec
ret.Instances[i].Spec = stor.mas[masID].agents[i].Spec
}
ret.Counter = stor.mas[masID].agentCounter
stor.mutex.Unlock()
......@@ -272,19 +273,19 @@ func (stor *localStorage) getAgencies(masID int) (ret schemas.Agencies, err erro
err = errors.New("Agency does not exist")
return
}
ret.Instances = make([]schemas.AgencySpec, len(stor.mas[masID].agencies),
ret.Instances = make([]schemas.AgencyInfo, len(stor.mas[masID].agencies),
len(stor.mas[masID].agencies))
for i := 0; i < len(stor.mas[masID].agencies); i++ {
ret.Instances[i] = stor.mas[masID].agencies[i].Spec
ret.Instances[i].Spec = stor.mas[masID].agencies[i].Spec
}
ret.Counter = stor.mas[masID].agencyCounter
stor.mutex.Unlock()
return
}
// getAgencyConfig returns status of one agency
func (stor *localStorage) getAgencyConfig(masID int,
agencyID int) (ret schemas.AgencyConfig, err error) {
// getAgencySpec returns status of one agency
func (stor *localStorage) getAgencySpec(masID int,
agencyID int) (ret schemas.AgencySpec, err error) {
stor.mutex.Lock()
if len(stor.mas)-1 < masID {
stor.mutex.Unlock()
......@@ -296,17 +297,17 @@ func (stor *localStorage) getAgencyConfig(masID int,
err = errors.New("Agency does not exist")
return
}
ret.Spec = stor.mas[masID].agencies[agencyID].Spec
ret.Agents = make([]schemas.AgentInfo, len(ret.Spec.Agents), len(ret.Spec.Agents))
for i := 0; i < len(ret.Spec.Agents); i++ {
var temp schemas.AgentInfo
temp, err = stor.getAgentInfoNolock(masID, ret.Spec.Agents[i])
if err != nil {
stor.mutex.Unlock()
return
}
ret.Agents[i] = temp
}
ret = stor.mas[masID].agencies[agencyID].Spec
// ret.Agents = make([]schemas.AgentInfo, len(ret.Spec.Agents), len(ret.Spec.Agents))
// for i := 0; i < len(ret.Spec.Agents); i++ {
// var temp schemas.AgentInfo
// temp, err = stor.getAgentInfoNolock(masID, ret.Spec.Agents[i].ID)
// if err != nil {
// stor.mutex.Unlock()
// return
// }
// ret.Agents[i] = temp
// }
stor.mutex.Unlock()
return
}
......@@ -331,7 +332,7 @@ func (stor *localStorage) storeMAS(masID int, masInfo schemas.MASInfo) (err erro
}
} else {
// check if mas stor is already populated
if stor.mas[masID].spec.ID == masID {
if stor.mas[masID].id == masID {
err = errors.New("MAS already exists")
return
}
......@@ -350,17 +351,17 @@ func createMASStorage(masID int, masInfo schemas.MASInfo) (ret masStorage) {
ret.agencyCounter = masInfo.Agencies.Counter
ret.graph = masInfo.Graph
ret.spec.ID = masID
ret.id = masID
ret.agents = make([]schemas.AgentInfo, ret.agentCounter, ret.agentCounter)
for i := 0; i < ret.agentCounter; i++ {
ret.agents[i].Spec = masInfo.Agents.Instances[i]
ret.agents[i].Spec.MASID = masID
ret.agents[i].Spec = masInfo.Agents.Instances[i].Spec
ret.agents[i].MASID = masID
ret.agents[i].Address.Agency = "mas-" + strconv.Itoa(masID) + "-agency-" +
strconv.Itoa(ret.agents[i].Spec.AgencyID) + ".mas" + strconv.Itoa(masID) + "agencies"
strconv.Itoa(ret.agents[i].AgencyID) + ".mas" + strconv.Itoa(masID) + "agencies"
}
ret.agencies = make([]schemas.AgencyInfo, ret.agencyCounter, ret.agencyCounter)
for i := 0; i < ret.agencyCounter; i++ {
ret.agencies[i].Spec = masInfo.Agencies.Instances[i]
ret.agencies[i].Spec = masInfo.Agencies.Instances[i].Spec
ret.agencies[i].Spec.MASID = masID
ret.agencies[i].Spec.Name = "mas-" + strconv.Itoa(masID) + "-agency-" + strconv.Itoa(i) +
".mas" + strconv.Itoa(masID) + "agencies"
......
......@@ -56,25 +56,48 @@ type CloneMAP struct {
Uptime time.Time `json:"uptime,omitempty"` // uptime of clonemap instance
}
// MASInfo contains info about MAS spec, agents and agencies in MAS
type MASInfo struct {
Spec MASSpec `json:"spec"`
ID int `json:"id"`
Agents Agents `json:"agents"`
Agencies Agencies `json:"agencies"`
Status Status `json:"status"`
Graph Graph `json:"graph"`
}
// MASSpec contains information about a MAS running in clonemap
type MASSpec struct {
ID int `json:"id"` // unique ID of MAS
// ID int `json:"id"` // unique ID of MAS
Name string `json:"name,omitempty"` // name/description of MAS
NumAgentsPerAgency int `json:"agentsperagency,omitempty"` // number of agents per agency
Logging bool `json:"logging"` // switch for logging module
// Analysis bool `json:"analysis"` // switch for analysis logging
MQTT bool `json:"mqtt"` //switch for mqtt
DF bool `json:"df"` //switch for df
Logger LogConfig `json:"log"` // logger configuration
Uptime time.Time `json:"uptime"`
MQTT bool `json:"mqtt"` //switch for mqtt
DF bool `json:"df"` //switch for df
Logger LogConfig `json:"log"` // logger configuration
Uptime time.Time `json:"uptime"`
Agents []AgentSpec `json:"agents"`
Graph Graph `json:"graph"`
}
// AgentInfo contains information about agent spec, address, communication, mqtt and status
type AgentInfo struct {
Spec AgentSpec `json:"spec"`
MASID int `json:"masid"` // ID of MAS
AgencyID int `json:"agencyid"` // name of the agency
ImageID int `json:"imid"` // ID of agency image
ID int `json:"id"` // ID of agent
Address Address `json:"address"`
Status Status `json:"status"`
}
// AgentSpec contains information about a agent running in a MAS
type AgentSpec struct {
MASID int `json:"masid"` // ID of MAS
AgencyID int `json:"agencyid"` // name of the agency
NodeID int `json:"nodeid"` // id of the node the agent is attached to
ID int `json:"id"` // unique ID of agent
// MASID int `json:"masid"` // ID of MAS
// AgencyID int `json:"agencyid"` // name of the agency
NodeID int `json:"nodeid"` // id of the node the agent is attached to
// ID int `json:"id"` // unique ID of agent
AgencyImage string `json:"image"` // docker image to be used for agencies
ImagePullSecret string `json:"secret,omitempty"` // image pull secret
Name string `json:"name,omitempty"` // name/description of agent
......@@ -88,25 +111,66 @@ type Address struct {
Agency string `json:"agency"`
}
// // MQTT contains information regarding MQTT topics of agents
// type MQTT struct {
// SubTopics []string // list of topics the agent has/should subscribed to
// PubTopics []string // list of topics the agent can publish
// }
// Status contains information about an agent's or agency's status
type Status struct {
Code int `json:"code"` // status code
LastUpdate time.Time `json:"lastupdate"` // time of last update
}
// AgencyInfo contains information about agency spec and status
type AgencyInfo struct {
Spec AgencySpec `json:"spec"`
Status Status `json:"status"`
}
// AgencySpec contains information about agency
type AgencySpec 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"` // unique ID (contained in name)
Logger LogConfig `json:"log"` // logger configuration
Agents []int `json:"agents"`
MASID int `json:"masid"` // ID of MAS
Name string `json:"name"` // name of agency (hostname of pod given by kubernetes)
ID int `json:"id"` // unique ID (contained in name)
Logger LogConfig `json:"log"` // logger configuration
Agents []AgentInfo `json:"agents"`
}