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) {
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)
......@@ -212,6 +227,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)
......
......@@ -88,15 +88,22 @@ func (ams *AMS) handleAPI(w http.ResponseWriter, r *http.Request) {
resvalid = true
}
case 6:
var masID int
masID, cmapErr = strconv.Atoi(respath[4])
if respath[2] == "clonemap" && respath[3] == "mas" && 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)
if respath[4] == "name" {
cmapErr, httpErr = ams.handleMASName(respath[5], w, r)
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:
......@@ -117,19 +124,24 @@ func (ams *AMS) handleAPI(w http.ResponseWriter, r *http.Request) {
masID, cmapErr = strconv.Atoi(respath[4])
if respath[2] == "clonemap" && respath[3] == "mas" && cmapErr == nil {
if respath[5] == "agents" {
var agentID int
agentID, cmapErr = strconv.Atoi(respath[6])
if cmapErr == nil {
// if respath[7] == "status" {
// cmapErr, httpErr = ams.handleAgentStatus(masID, agentID, w, r)
// resvalid = true
// } else
if respath[7] == "address" {
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
if respath[6] == "name" {
cmapErr, httpErr = ams.handleAgentName(masID, respath[7], w, r)
resvalid = true
} else {
var agentID int
agentID, cmapErr = strconv.Atoi(respath[6])
if cmapErr == nil {
// if respath[7] == "status" {
// cmapErr, httpErr = ams.handleAgentStatus(masID, agentID, w, r)
// resvalid = true
// } else
if respath[7] == "address" {
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) (
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
func (ams *AMS) handleAgent(masID int, w http.ResponseWriter, r *http.Request) (cmapErr,
httpErr error) {
......@@ -353,6 +380,22 @@ func (ams *AMS) handleAgentCustom(masID int, agentid int, w http.ResponseWriter,
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
func (ams *AMS) handleAgency(masID int, w http.ResponseWriter, r *http.Request) (cmapErr,
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