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

more changes to schemas

parent cea49038
Pipeline #260629 passed with stages
in 2 minutes and 45 seconds
......@@ -92,7 +92,7 @@ func (agency *Agency) aclLookup(agentID int) (acl *ACL, err error) {
agency.logInfo.Println("Request address of unknown agent")
agentInfo := schemas.AgentInfo{}
agency.mutex.Lock()
agencyName := agency.info.Spec.Name
agencyName := agency.info.Name
agency.mutex.Unlock()
if address.Agency == agencyName {
err = errors.New("MassiveError")
......@@ -138,7 +138,7 @@ func (agency *Agency) aclLookup(agentID int) (acl *ACL, err error) {
// requestAgentAddress requests the address of an agent from ams
func (agency *Agency) requestAgentAddress(agentID int) (address schemas.Address, err error) {
agency.mutex.Lock()
masID := agency.info.Spec.MASID
masID := agency.info.MASID
agency.mutex.Unlock()
address, _, err = amsclient.GetAgentAddress(masID, agentID)
return
......
......@@ -137,11 +137,11 @@ func (agency *Agency) init() (err error) {
err = errors.New("incorrect hostname")
return
}
agency.info.Spec.MASID, err = strconv.Atoi(hostname[1])
agency.info.Spec.ID, err = strconv.Atoi(hostname[3])
agency.info.Spec.Name = temp + ".mas" + hostname[1] + "agencies"
agency.logger = newLoggerClient(agency.info.Spec.MASID, agency.logError, agency.logInfo)
agency.mqtt = newMQTTClient("mqtt", 1883, agency.info.Spec.Name, agency.logError, agency.logInfo)
agency.info.MASID, err = strconv.Atoi(hostname[1])
agency.info.ID, err = strconv.Atoi(hostname[3])
agency.info.Name = temp + ".mas" + hostname[1] + "agencies"
agency.logger = newLoggerClient(agency.info.MASID, agency.logError, agency.logInfo)
agency.mqtt = newMQTTClient("mqtt", 1883, agency.info.Name, agency.logError, agency.logInfo)
agency.mqtt.init()
agency.mutex.Unlock()
return
......@@ -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 agencySpec schemas.AgencySpec
agencySpec, _, err = amsclient.GetAgencySpec(agency.info.Spec.MASID, agency.info.Spec.ID)
agency.info.Spec.Logger = agencySpec.Logger
var agencyInfoFull schemas.AgencyInfoFull
agencyInfoFull, _, err = amsclient.GetAgencyInfoFull(agency.info.MASID, agency.info.ID)
agency.info.Logger = agencyInfoFull.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(agencySpec.Agents); i++ {
err = agency.createAgent(agencySpec.Agents[i])
for i := 0; i < len(agencyInfoFull.Agents); i++ {
err = agency.createAgent(agencyInfoFull.Agents[i])
if err != nil {
agency.mutex.Lock()
agency.info.Status = schemas.Status{
......@@ -206,7 +206,7 @@ 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.logger, agency.info.Spec.Logger,
ag := newAgent(agentInfo, msgIn, agency.aclLookup, agency.logger, agency.info.Logger,
agency.mqtt, agency.logError, agency.logInfo)
agency.localAgents[agentInfo.ID] = ag
agency.mutex.Unlock()
......
......@@ -185,9 +185,9 @@ func (ams *AMS) getAgencies(masID int) (ret schemas.Agencies, err error) {
return
}
// 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)
// getAgencyInfoFull returns status of one agency
func (ams *AMS) getAgencyInfoFull(masID int, agencyID int) (ret schemas.AgencyInfoFull, err error) {
ret, err = ams.stor.getAgencyInfoFull(masID, agencyID)
return
}
......@@ -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].Spec.AgencyImage
pullSecret = masInfo.Agents.Instances[0].Spec.ImagePullSecret
image = masInfo.ImageGroups[0].Image
pullSecret = masInfo.ImageGroups[0].PullSecret
}
err = ams.depl.newMAS(masID, image, pullSecret, numAgencies, masInfo.Spec.Logging,
masInfo.Spec.MQTT, masInfo.Spec.DF)
......@@ -245,13 +245,22 @@ 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(masSpec schemas.MASSpec) (masInfo schemas.MASInfo, numAgencies int) {
// extract all image groups
groupID := 0
imGroupInfo := schemas.ImageGroupInfo{
Image: masSpec.ImageGroups.Image,
PullSecret: masSpec.ImageGroups.PullSecret,
ID: groupID,
}
masInfo.ImageGroups = append(masInfo.ImageGroups, imGroupInfo)
// MAS configuration
masInfo.Spec = masSpec
masInfo.Agents.Counter = len(masSpec.Agents)
masInfo.Agents.Counter = len(masSpec.ImageGroups.Agents)
masInfo.Agents.Instances = make([]schemas.AgentInfo, masInfo.Agents.Counter,
masInfo.Agents.Counter)
numAgencies = len(masSpec.Agents) / masSpec.NumAgentsPerAgency
if len(masSpec.Agents)%masSpec.NumAgentsPerAgency > 0 {
numAgencies = len(masSpec.ImageGroups.Agents) / masSpec.NumAgentsPerAgency
if len(masSpec.ImageGroups.Agents)%masSpec.NumAgentsPerAgency > 0 {
numAgencies++
}
masInfo.Agencies.Counter = numAgencies
......@@ -262,7 +271,7 @@ func (ams *AMS) configureMAS(masSpec schemas.MASSpec) (masInfo schemas.MASInfo,
// agent configuration
for i := 0; i < masInfo.Agents.Counter; i++ {
masInfo.Agents.Instances[i].Spec = masSpec.Agents[i]
masInfo.Agents.Instances[i].Spec = masSpec.ImageGroups.Agents[i]
masInfo.Agents.Instances[i].ID = i
masInfo.Agents.Instances[i].AgencyID = i / masSpec.NumAgentsPerAgency
for j := range masInfo.Spec.Graph.Node {
......@@ -277,7 +286,7 @@ func (ams *AMS) configureMAS(masSpec schemas.MASSpec) (masInfo schemas.MASInfo,
// agency configuration
agentCounter := 0
for i := 0; i < numAgencies; i++ {
agencySpec := schemas.AgencySpec{
agencyInfo := schemas.AgencyInfo{
ID: i,
Logger: masSpec.Logger,
}
......@@ -285,10 +294,10 @@ func (ams *AMS) configureMAS(masSpec schemas.MASSpec) (masInfo schemas.MASInfo,
if agentCounter >= masInfo.Agents.Counter {
break
}
agencySpec.Agents = append(agencySpec.Agents, masInfo.Agents.Instances[agentCounter])
agencyInfo.Agents = append(agencyInfo.Agents, agentCounter)
agentCounter++
}
masInfo.Agencies.Instances[i].Spec = agencySpec
masInfo.Agencies.Instances[i] = agencyInfo
}
return
}
......
......@@ -132,18 +132,18 @@ func dummyClient(s *http.Server, t *testing.T) {
Logging: false,
MQTT: false,
DF: false,
Agents: []schemas.AgentSpec{
schemas.AgentSpec{
AgencyImage: "agent",
ImagePullSecret: "",
Name: "test1",
AType: "test",
},
schemas.AgentSpec{
AgencyImage: "agent",
ImagePullSecret: "",
Name: "test2",
AType: "test",
ImageGroups: schemas.ImageGroupSpec{
Image: "agent",
PullSecret: "",
Agents: []schemas.AgentSpec{
schemas.AgentSpec{
Name: "test1",
AType: "test",
},
schemas.AgentSpec{
Name: "test2",
AType: "test",
},
},
},
}
......@@ -203,7 +203,7 @@ func dummyClient(s *http.Server, t *testing.T) {
t.Error("Error GetAgencies " + strconv.Itoa(httpStatus))
}
_, httpStatus, err = amsclient.GetAgencySpec(0, 0)
_, httpStatus, err = amsclient.GetAgencyInfoFull(0, 0)
if err != nil {
t.Error(err)
}
......
......@@ -190,8 +190,8 @@ func GetAgencies(masID int) (agencies schemas.Agencies, httpStatus int, err erro
return
}
// GetAgencySpec requests agency information
func GetAgencySpec(masID int, agencyID int) (agency schemas.AgencySpec, httpStatus int,
// GetAgencyInfoFull requests agency information
func GetAgencyInfoFull(masID int, agencyID int) (agency schemas.AgencyInfoFull, httpStatus int,
err error) {
var body []byte
body, httpStatus, err = httpretry.Get(httpClient, "http://"+Host+":"+strconv.Itoa(Port)+
......@@ -203,7 +203,7 @@ func GetAgencySpec(masID int, agencyID int) (agency schemas.AgencySpec, httpStat
//fmt.Println(string(body))
err = json.Unmarshal(body, &agency)
if err != nil {
agency = schemas.AgencySpec{}
agency = schemas.AgencyInfoFull{}
}
return
}
......
......@@ -340,8 +340,8 @@ 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 agencySpec schemas.AgencySpec
agencySpec, cmapErr = ams.getAgencySpec(masID, agencyid)
var agencySpec schemas.AgencyInfoFull
agencySpec, cmapErr = ams.getAgencyInfoFull(masID, agencyid)
httpErr = httpreply.Resource(w, agencySpec, cmapErr)
} else {
httpErr = httpreply.MethodNotAllowed(w)
......
......@@ -86,8 +86,8 @@ type storage interface {
// getAgencies returns specs of all agencies in MAS
getAgencies(masID int) (ret schemas.Agencies, err error)
// getAgencySpec returns status of one agency
getAgencySpec(masID int, agencyID int) (ret schemas.AgencySpec, err error)
// getAgencyInfoFull returns status of one agency
getAgencyInfoFull(masID int, agencyID int) (ret schemas.AgencyInfoFull, err error)
// registerMAS registers a new MAS with the storage and returns its ID
registerMAS() (masID int, err error)
......@@ -281,9 +281,9 @@ func (stor *localStorage) getAgencies(masID int) (ret schemas.Agencies, err erro
return
}
// getAgencySpec returns status of one agency
func (stor *localStorage) getAgencySpec(masID int,
agencyID int) (ret schemas.AgencySpec, err error) {
// getAgencyInfoFull returns status of one agency
func (stor *localStorage) getAgencyInfoFull(masID int,
agencyID int) (ret schemas.AgencyInfoFull, err error) {
stor.mutex.Lock()
if len(stor.mas)-1 < masID {
stor.mutex.Unlock()
......@@ -295,7 +295,23 @@ func (stor *localStorage) getAgencySpec(masID int,
err = errors.New("Agency does not exist")
return
}
ret = stor.mas[masID].agencies[agencyID].Spec
ret.MASID = stor.mas[masID].agencies[agencyID].MASID
ret.Name = stor.mas[masID].agencies[agencyID].Name
ret.ID = stor.mas[masID].agencies[agencyID].ID
ret.ImageGroupID = stor.mas[masID].agencies[agencyID].ImageGroupID
ret.Logger = stor.mas[masID].agencies[agencyID].Logger
ret.Status = stor.mas[masID].agencies[agencyID].Status
ret.Agents = make([]schemas.AgentInfo, len(stor.mas[masID].agencies[agencyID].Agents),
len(stor.mas[masID].agencies[agencyID].Agents))
for i := 0; i < len(ret.Agents); i++ {
var temp schemas.AgentInfo
temp, err = stor.getAgentInfoNolock(masID, stor.mas[masID].agencies[agencyID].Agents[i])
if err != nil {
stor.mutex.Unlock()
return
}
ret.Agents[i] = temp
}
stor.mutex.Unlock()
return
}
......@@ -349,8 +365,8 @@ func createMASStorage(masID int, masInfo schemas.MASInfo) (ret masStorage) {
ret.agencies = make([]schemas.AgencyInfo, ret.agencyCounter, ret.agencyCounter)
for i := 0; i < ret.agencyCounter; i++ {
ret.agencies[i] = masInfo.Agencies.Instances[i]
ret.agencies[i].Spec.MASID = masID
ret.agencies[i].Spec.Name = "mas-" + strconv.Itoa(masID) + "-agency-" + strconv.Itoa(i) +
ret.agencies[i].MASID = masID
ret.agencies[i].Name = "mas-" + strconv.Itoa(masID) + "-agency-" + strconv.Itoa(i) +
".mas" + strconv.Itoa(masID) + "agencies"
}
return
......
......@@ -58,46 +58,59 @@ type CloneMAP struct {
// 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"`
Spec MASSpec `json:"spec"`
ID int `json:"id"`
ImageGroups []ImageGroupInfo `json:"groups"`
Agents Agents `json:"agents"`
Agencies Agencies `json:"agencies"`
Uptime time.Time `json:"uptime"`
Status Status `json:"status"`
}
// MASSpec contains information about a MAS running in clonemap
type MASSpec struct {
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
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"`
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
MQTT bool `json:"mqtt"` //switch for mqtt
DF bool `json:"df"` //switch for df
Logger LogConfig `json:"log"` // logger configuration
ImageGroups ImageGroupSpec `json:"groups"`
Graph Graph `json:"graph"`
}
// ImageGroupInfo contains information about all agents that have the same image
type ImageGroupInfo struct {
Image string `json:"image"` // docker image to be used for agencies
PullSecret string `json:"secret,omitempty"` // image pull secret
ID int `json:"id"`
}
// ImageGroupSpec contains information about all agents that have the same image
type ImageGroupSpec struct {
Image string `json:"image"` // docker image to be used for agencies
PullSecret string `json:"secret,omitempty"` // image pull secret
Agents []AgentSpec `json:"agents"`
}
// 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"`
Spec AgentSpec `json:"spec"`
MASID int `json:"masid"` // ID of MAS
AgencyID int `json:"agencyid"` // name of the agency
ImageGroupID 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 {
NodeID int `json:"nodeid"` // id of the node the agent is attached to
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
AType string `json:"type,omitempty"` // type of agent (application dependent)
ASubtype string `json:"subtype,omitempty"` // subtype of agent (application dependent)
Custom string `json:"custom,omitempty"` // custom configuration data
NodeID int `json:"nodeid"` // id of the node the agent is attached to
Name string `json:"name,omitempty"` // name/description of agent
AType string `json:"type,omitempty"` // type of agent (application dependent)
ASubtype string `json:"subtype,omitempty"` // subtype of agent (application dependent)
Custom string `json:"custom,omitempty"` // custom configuration data
}
// Address holds the address information of an agent
......@@ -111,19 +124,26 @@ type Status struct {
LastUpdate time.Time `json:"lastupdate"` // time of last update
}
// AgencyInfo contains information about agency spec and status
// AgencyInfo contains information about agency spec and status (for storage)
type AgencyInfo struct {
Spec AgencySpec `json:"spec"`
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"` // unique ID (contained in name)
ImageGroupID int `json:"imid"` // ID of agency image
Logger LogConfig `json:"log"` // logger configuration
Agents []int `json:"agents"`
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 []AgentInfo `json:"agents"`
// 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"` // unique ID (contained in name)
ImageGroupID int `json:"imid"` // ID of agency image
Logger LogConfig `json:"log"` // logger configuration
Agents []AgentInfo `json:"agents"`
Status Status `json:"status"`
}
// MASs contains informaton about how many MASs are running
......@@ -142,6 +162,7 @@ type Agents struct {
type Agencies struct {
Counter int `json:"counter"` // counter for agents
Instances []AgencyInfo `json:"instances"` // agencies
}
// AgentStatus contains status of agency
......
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