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

implement new endpoints

parent 30fd5a21
Pipeline #405412 passed with stages
in 2 minutes and 27 seconds
......@@ -171,6 +171,21 @@ func (ams *AMS) getMASInfo(masID int) (ret schemas.MASInfo, err error) {
return
}
// getMASByName returns IDs of all MAS with mathcing name
func (ams *AMS) getMASByName(name string) (masIDs []int, err error) {
var mass schemas.MASs
mass, err = ams.stor.getMASs()
if err != nil {
return
}
for i := range mass.Inst {
if mass.Inst[i].Config.Name == name {
masIDs = append(masIDs, i)
}
}
return
}
// getAgents returns specs of all agents in MAS
func (ams *AMS) getAgents(masID int) (ret schemas.Agents, err error) {
ret, err = ams.stor.getAgents(masID)
......@@ -214,6 +229,17 @@ func (ams *AMS) updateAgentCustom(masID int, agentID int, custom string) (err er
return
}
// getAgentsByName returns IDs of all agents with matching name
func (ams *AMS) getAgentsByName(masID int, name string) (agentIDs []int, err error) {
var agents schemas.Agents
for i := range agents.Inst {
if agents.Inst[i].Spec.Name == name {
agentIDs = append(agentIDs, i)
}
}
return
}
// getAgencies returns specs of all agencies in MAS
func (ams *AMS) getAgencies(masID int) (ret schemas.Agencies, err error) {
ret, err = ams.stor.getAgencies(masID)
......
......@@ -262,7 +262,9 @@ func (ams *AMS) handleMASName(name string, w http.ResponseWriter, r *http.Reques
httpErr error) {
if r.Method == "GET" {
// search for MAS with matching name
// ToDo
var ids []int
ids, cmapErr = ams.getMASByName(name)
httpErr = httpreply.Resource(w, ids, cmapErr)
} else {
httpErr = httpreply.MethodNotAllowed(w)
cmapErr = errors.New("Error: Method not allowed on path /api/clonemap/name/{name}")
......@@ -383,7 +385,9 @@ func (ams *AMS) handleAgentName(masID int, name string, w http.ResponseWriter,
r *http.Request) (cmapErr, httpErr error) {
if r.Method == "GET" {
// search for agents with matching name
// ToDo
var ids []int
ids, cmapErr = ams.getAgentsByName(masID, name)
httpErr = httpreply.Resource(w, ids, cmapErr)
} else {
httpErr = httpreply.MethodNotAllowed(w)
cmapErr = errors.New("Error: Method not allowed on path /api/clonemap/mas/{masid}/agents/" +
......
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