Commit 71fa94d0 authored by Stefan Dähling's avatar Stefan Dähling
Browse files

new api endpoint for agency info

parent 79889b7c
Pipeline #262290 passed with stages
in 1 minute and 46 seconds
...@@ -192,6 +192,12 @@ func (ams *AMS) getAgencyInfoFull(masID int, agencyID int) (ret schemas.AgencyIn ...@@ -192,6 +192,12 @@ func (ams *AMS) getAgencyInfoFull(masID int, agencyID int) (ret schemas.AgencyIn
return return
} }
func (ams *AMS) getContainerAgencyInfoFull(masID int, imID int,
agencyID int) (ret schemas.AgencyInfoFull, err error) {
ret, err = ams.stor.getContainerAgencyInfoFull(masID, imID, agencyID)
return
}
// createMAS creates a new mas according to masconfig // createMAS creates a new mas according to masconfig
func (ams *AMS) createMAS(masSpec schemas.MASSpec) (err error) { func (ams *AMS) createMAS(masSpec schemas.MASSpec) (err error) {
// fill masInfo // fill masInfo
......
...@@ -208,6 +208,24 @@ func GetAgencyInfoFull(masID int, agencyID int) (agency schemas.AgencyInfoFull, ...@@ -208,6 +208,24 @@ func GetAgencyInfoFull(masID int, agencyID int) (agency schemas.AgencyInfoFull,
return return
} }
// GetContainerAgencyInfoFull requests agency information
func GetContainerAgencyInfoFull(masID int, imID int, agencyID int) (agency schemas.AgencyInfoFull,
httpStatus int, err error) {
var body []byte
body, httpStatus, err = httpretry.Get(httpClient, "http://"+Host+":"+strconv.Itoa(Port)+
"/api/clonemap/mas/"+strconv.Itoa(masID)+"/container/"+strconv.Itoa(imID)+"/"+
strconv.Itoa(agencyID), time.Second*2, 2)
if err != nil {
return
}
//fmt.Println(string(body))
err = json.Unmarshal(body, &agency)
if err != nil {
agency = schemas.AgencyInfoFull{}
}
return
}
// Init initializes the client // Init initializes the client
func Init(timeout time.Duration, del time.Duration, numRet int) { func Init(timeout time.Duration, del time.Duration, numRet int) {
httpClient.Timeout = timeout httpClient.Timeout = timeout
......
...@@ -137,20 +137,17 @@ func (ams *AMS) handleAPI(w http.ResponseWriter, r *http.Request) { ...@@ -137,20 +137,17 @@ func (ams *AMS) handleAPI(w http.ResponseWriter, r *http.Request) {
cmapErr, httpErr = ams.handleAgentAddress(masID, agentID, w, r) cmapErr, httpErr = ams.handleAgentAddress(masID, agentID, w, r)
resvalid = true resvalid = true
} }
} else if respath[5] == "container" {
var imid, agencyID int
imid, cmapErr = strconv.Atoi(respath[6])
if cmapErr != nil {
agencyID, cmapErr = strconv.Atoi(respath[6])
if cmapErr == nil {
cmapErr, httpErr = ams.handleContainer(masID, imid, 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: default:
...@@ -320,7 +317,7 @@ func (ams *AMS) handleAgentAddress(masID int, agentid int, w http.ResponseWriter ...@@ -320,7 +317,7 @@ func (ams *AMS) handleAgentAddress(masID int, agentid int, w http.ResponseWriter
return return
} }
// handleAgent 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) {
if r.Method == "GET" { if r.Method == "GET" {
...@@ -336,7 +333,7 @@ func (ams *AMS) handleAgency(masID int, w http.ResponseWriter, r *http.Request) ...@@ -336,7 +333,7 @@ func (ams *AMS) handleAgency(masID int, w http.ResponseWriter, r *http.Request)
return return
} }
// handleAgentID is the handler for requests to path /api/cloumap/mas/{mas-id}/agencies/{agency-id} // handleAgencyID is the handler for requests to path /api/cloumap/mas/{mas-id}/agencies/{agency-id}
func (ams *AMS) handleAgencyID(masID int, agencyid int, w http.ResponseWriter, func (ams *AMS) handleAgencyID(masID int, agencyid int, w http.ResponseWriter,
r *http.Request) (cmapErr, httpErr error) { r *http.Request) (cmapErr, httpErr error) {
if r.Method == "GET" { if r.Method == "GET" {
...@@ -351,22 +348,21 @@ func (ams *AMS) handleAgencyID(masID int, agencyid int, w http.ResponseWriter, ...@@ -351,22 +348,21 @@ func (ams *AMS) handleAgencyID(masID int, agencyid int, w http.ResponseWriter,
return return
} }
// // handleAgencyConfig is the handler for requests to path // handleContainer is the handler for requests to path /api/cloumap/mas/{mas-id}/container/{imid}/
// // /api/clonemap/mas/{mas-id}/agencies/{agency-id}/config // {agency-id}
// func (ams *AMS) handleAgencyConfig(masID int, agencyid int, w http.ResponseWriter, func (ams *AMS) handleContainer(masID int, imID int, agencyid int, w http.ResponseWriter,
// r *http.Request) (cmapErr, httpErr error) { r *http.Request) (cmapErr, httpErr error) {
// if r.Method == "GET" { if r.Method == "GET" {
// // return config of specified agency var agencySpec schemas.AgencyInfoFull
// var agencyConfig schemas.AgencyConfig agencySpec, cmapErr = ams.getContainerAgencyInfoFull(masID, imID, agencyid)
// agencyConfig, cmapErr = ams.getAgencyConfig(masID, agencyid) httpErr = httpreply.Resource(w, agencySpec, cmapErr)
// httpErr = httpreply.Resource(w, agencyConfig, cmapErr) } else {
// } else { httpErr = httpreply.MethodNotAllowed(w)
// httpErr = httpreply.MethodNotAllowed(w) cmapErr = errors.New("Error: Method not allowed on path /api/clonemap/mas/{mas-id}/" +
// cmapErr = errors.New("Error: Method not allowed on path /api/clonemap/mas/{mas-id}/" + "agencies/{agency-id}")
// "agencies/{agency-id}/config") }
// } return
// return }
// }
// listen opens a http server listening and serving request // listen opens a http server listening and serving request
func (ams *AMS) listen() (err error) { func (ams *AMS) listen() (err error) {
......
...@@ -89,6 +89,10 @@ type storage interface { ...@@ -89,6 +89,10 @@ type storage interface {
// getAgencyInfoFull returns status of one agency // getAgencyInfoFull returns status of one agency
getAgencyInfoFull(masID int, agencyID int) (ret schemas.AgencyInfoFull, err error) getAgencyInfoFull(masID int, agencyID int) (ret schemas.AgencyInfoFull, err error)
// getContainerAgencyInfoFull returns the agency info for an image id and an agency id
getContainerAgencyInfoFull(masID int, imID int, agencyID int) (ret schemas.AgencyInfoFull,
err error)
// registerMAS registers a new MAS with the storage and returns its ID // registerMAS registers a new MAS with the storage and returns its ID
registerMAS() (masID int, err error) registerMAS() (masID int, err error)
...@@ -283,6 +287,44 @@ func (stor *localStorage) getAgencyInfoFull(masID int, ...@@ -283,6 +287,44 @@ func (stor *localStorage) getAgencyInfoFull(masID int,
return return
} }
// getContainerAgencyInfoFull returns info of one agency for imid and agencyID
func (stor *localStorage) getContainerAgencyInfoFull(masID int, imID int,
agencyID int) (ret schemas.AgencyInfoFull, err error) {
agencyName := "mas-" + strconv.Itoa(masID) + "-im-" + strconv.Itoa(imID) + "-agency-" +
strconv.Itoa(agencyID) + ".mas" + strconv.Itoa(masID) + "agencies"
realID := -1
stor.mutex.Lock()
if len(stor.mas)-1 < masID {
stor.mutex.Unlock()
err = errors.New("Agency does not exist")
return
}
if len(stor.mas[masID].ImageGroups)-1 < imID {
stor.mutex.Unlock()
err = errors.New("Agency does not exist")
return
}
for i := range stor.mas[masID].ImageGroups[imID].Agencies {
tempID := stor.mas[masID].ImageGroups[imID].Agencies[i]
if len(stor.mas[masID].Agencies.Instances)-1 < tempID {
stor.mutex.Unlock()
err = errors.New("Agency does not exist")
return
}
if stor.mas[masID].Agencies.Instances[tempID].Name == agencyName {
realID = tempID
break
}
}
stor.mutex.Unlock()
if realID == -1 {
err = errors.New("Agency does not exist")
return
}
ret, err = stor.getAgencyInfoFull(masID, realID)
return
}
// registerMAS registers a new MAS with the storage and returns its ID // registerMAS registers a new MAS with the storage and returns its ID
func (stor *localStorage) registerMAS() (masID int, err error) { func (stor *localStorage) registerMAS() (masID int, err error) {
stor.mutex.Lock() stor.mutex.Lock()
......
Supports Markdown
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