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

endpoint to remove all mas

parent 6bd21675
Pipeline #530838 passed with stages
in 9 minutes and 21 seconds
......@@ -89,6 +89,11 @@ paths:
responses:
'201':
description: Created
delete:
description: delete all MASs
responses:
'200':
description: succesful deletion of all MASs
/api/clonemap/mas/{masid}:
parameters:
- $ref: '#/components/parameters/masID'
......
......@@ -58,6 +58,7 @@ import (
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/status"
)
// AMS contains storage and deployment object
......@@ -442,6 +443,18 @@ func (ams *AMS) checkModules(configIn schemas.MASConfig) (configOut schemas.MASC
return
}
// removeAllMAS removes all mas
func (ams *AMS) removeAllMAS() (err error) {
var mass []schemas.MASInfoShort
mass, err = ams.getMASsShort()
for i := range mass {
if mass[i].Status.Code != status.Terminated {
ams.removeMAS(mass[i].ID)
}
}
return
}
// removeMAS removes specified mas if it exists
func (ams *AMS) removeMAS(masID int) (err error) {
err = ams.depl.deleteMAS(masID)
......
......@@ -93,6 +93,19 @@ func (ams *AMS) handleGetMAS(w http.ResponseWriter, r *http.Request) {
ams.logErrors(r.URL.Path, cmapErr, httpErr)
}
// handleDeleteMAS is the handler for delete requests to path /api/clonemap/mas
func (ams *AMS) handleDeleteMAS(w http.ResponseWriter, r *http.Request) {
var cmapErr, httpErr error
cmapErr = ams.removeAllMAS()
if cmapErr != nil {
httpErr = httpreply.CMAPError(w, cmapErr.Error())
ams.logErrors(r.URL.Path, cmapErr, httpErr)
return
}
httpErr = httpreply.Deleted(w, cmapErr)
ams.logErrors(r.URL.Path, cmapErr, httpErr)
}
// handlePostMAS is the handler for post requests to path /api/clonemap/mas
func (ams *AMS) handlePostMAS(w http.ResponseWriter, r *http.Request) {
var cmapErr, httpErr error
......@@ -503,7 +516,8 @@ func (ams *AMS) server(port int) (serv *http.Server) {
s.Path("/clonemap").Methods("POST", "PUT", "DELETE").HandlerFunc(ams.methodNotAllowed)
s.Path("/clonemap/mas").Methods("GET").HandlerFunc(ams.handleGetMAS)
s.Path("/clonemap/mas").Methods("POST").HandlerFunc(ams.handlePostMAS)
s.Path("/clonemap/mas").Methods("PUT", "DELETE").HandlerFunc(ams.methodNotAllowed)
s.Path("/clonemap/mas").Methods("DELETE").HandlerFunc(ams.handleDeleteMAS)
s.Path("/clonemap/mas").Methods("PUT").HandlerFunc(ams.methodNotAllowed)
s.Path("/clonemap/mas/{masid}").Methods("GET").HandlerFunc(ams.handleGetMASID)
s.Path("/clonemap/mas/{masid}").Methods("DELETE").HandlerFunc(ams.handleDeleteMASID)
s.Path("/clonemap/mas/{masid}").Methods("PUT", "POST").HandlerFunc(ams.methodNotAllowed)
......
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