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

Merge branch 'develop' of git.rwth-aachen.de:acs/public/cloud/mas/clonemap into develop

parents f9438392 87411bcd
Pipeline #405915 passed with stages
in 3 minutes and 6 seconds
...@@ -169,6 +169,21 @@ func (ams *AMS) getMASInfo(masID int) (ret schemas.MASInfo, err error) { ...@@ -169,6 +169,21 @@ func (ams *AMS) getMASInfo(masID int) (ret schemas.MASInfo, err error) {
return 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 // getAgents returns specs of all agents in MAS
func (ams *AMS) getAgents(masID int) (ret schemas.Agents, err error) { func (ams *AMS) getAgents(masID int) (ret schemas.Agents, err error) {
ret, err = ams.stor.getAgents(masID) ret, err = ams.stor.getAgents(masID)
...@@ -212,6 +227,17 @@ func (ams *AMS) updateAgentCustom(masID int, agentID int, custom string) (err er ...@@ -212,6 +227,17 @@ func (ams *AMS) updateAgentCustom(masID int, agentID int, custom string) (err er
return 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 // getAgencies returns specs of all agencies in MAS
func (ams *AMS) getAgencies(masID int) (ret schemas.Agencies, err error) { func (ams *AMS) getAgencies(masID int) (ret schemas.Agencies, err error) {
ret, err = ams.stor.getAgencies(masID) ret, err = ams.stor.getAgencies(masID)
......
...@@ -88,15 +88,22 @@ func (ams *AMS) handleAPI(w http.ResponseWriter, r *http.Request) { ...@@ -88,15 +88,22 @@ func (ams *AMS) handleAPI(w http.ResponseWriter, r *http.Request) {
resvalid = true resvalid = true
} }
case 6: case 6:
var masID int
masID, cmapErr = strconv.Atoi(respath[4])
if respath[2] == "clonemap" && respath[3] == "mas" && cmapErr == nil { if respath[2] == "clonemap" && respath[3] == "mas" && cmapErr == nil {
if respath[5] == "agents" { if respath[4] == "name" {
cmapErr, httpErr = ams.handleAgent(masID, w, r) cmapErr, httpErr = ams.handleMASName(respath[5], w, r)
resvalid = true
} else if respath[5] == "agencies" {
cmapErr, httpErr = ams.handleAgency(masID, w, r)
resvalid = true resvalid = true
} else {
var masID int
masID, cmapErr = strconv.Atoi(respath[4])
if cmapErr == nil {
if respath[5] == "agents" {
cmapErr, httpErr = ams.handleAgent(masID, w, r)
resvalid = true
} else if respath[5] == "agencies" {
cmapErr, httpErr = ams.handleAgency(masID, w, r)
resvalid = true
}
}
} }
} }
case 7: case 7:
...@@ -117,19 +124,24 @@ func (ams *AMS) handleAPI(w http.ResponseWriter, r *http.Request) { ...@@ -117,19 +124,24 @@ func (ams *AMS) handleAPI(w http.ResponseWriter, r *http.Request) {
masID, cmapErr = strconv.Atoi(respath[4]) masID, cmapErr = strconv.Atoi(respath[4])
if respath[2] == "clonemap" && respath[3] == "mas" && cmapErr == nil { if respath[2] == "clonemap" && respath[3] == "mas" && cmapErr == nil {
if respath[5] == "agents" { if respath[5] == "agents" {
var agentID int if respath[6] == "name" {
agentID, cmapErr = strconv.Atoi(respath[6]) cmapErr, httpErr = ams.handleAgentName(masID, respath[7], w, r)
if cmapErr == nil { resvalid = true
// if respath[7] == "status" { } else {
// cmapErr, httpErr = ams.handleAgentStatus(masID, agentID, w, r) var agentID int
// resvalid = true agentID, cmapErr = strconv.Atoi(respath[6])
// } else if cmapErr == nil {
if respath[7] == "address" { // if respath[7] == "status" {
cmapErr, httpErr = ams.handleAgentAddress(masID, agentID, w, r) // cmapErr, httpErr = ams.handleAgentStatus(masID, agentID, w, r)
resvalid = true // resvalid = true
} else if respath[7] == "custom" { // } else
cmapErr, httpErr = ams.handleAgentCustom(masID, agentID, w, r) if respath[7] == "address" {
resvalid = true cmapErr, httpErr = ams.handleAgentAddress(masID, agentID, w, r)
resvalid = true
} else if respath[7] == "custom" {
cmapErr, httpErr = ams.handleAgentCustom(masID, agentID, w, r)
resvalid = true
}
} }
} }
} }
...@@ -245,6 +257,21 @@ func (ams *AMS) handlemasID(masID int, w http.ResponseWriter, r *http.Request) ( ...@@ -245,6 +257,21 @@ func (ams *AMS) handlemasID(masID int, w http.ResponseWriter, r *http.Request) (
return return
} }
// handleMASName is the handler for requests to path /api/clonemap/mas/name/{name}
func (ams *AMS) handleMASName(name string, w http.ResponseWriter, r *http.Request) (cmapErr,
httpErr error) {
if r.Method == "GET" {
// search for MAS with matching name
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}")
}
return
}
// handleAgent is the handler for requests to path /api/clonemap/mas/{mas-id}/agents // handleAgent is the handler for requests to path /api/clonemap/mas/{mas-id}/agents
func (ams *AMS) handleAgent(masID int, w http.ResponseWriter, r *http.Request) (cmapErr, func (ams *AMS) handleAgent(masID int, w http.ResponseWriter, r *http.Request) (cmapErr,
httpErr error) { httpErr error) {
...@@ -353,6 +380,22 @@ func (ams *AMS) handleAgentCustom(masID int, agentid int, w http.ResponseWriter, ...@@ -353,6 +380,22 @@ func (ams *AMS) handleAgentCustom(masID int, agentid int, w http.ResponseWriter,
return return
} }
// handleAgentName is the handler for requests to path /api/clonemap/mas/{masid}/agents/name/{name}
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
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/" +
"name/{name}")
}
return
}
// handleAgency is the handler for requests to path /api/cloumap/mas/{mas-id}/agencies // handleAgency is the handler for requests to path /api/cloumap/mas/{mas-id}/agencies
func (ams *AMS) handleAgency(masID int, w http.ResponseWriter, r *http.Request) (cmapErr, func (ams *AMS) handleAgency(masID int, w http.ResponseWriter, r *http.Request) (cmapErr,
httpErr error) { httpErr error) {
......
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