Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance NLB mgmt feature (2) #1178

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
683 changes: 399 additions & 284 deletions src/api/rest/docs/docs.go

Large diffs are not rendered by default.

683 changes: 399 additions & 284 deletions src/api/rest/docs/swagger.json

Large diffs are not rendered by default.

532 changes: 307 additions & 225 deletions src/api/rest/docs/swagger.yaml

Large diffs are not rendered by default.

89 changes: 66 additions & 23 deletions src/api/rest/server/mcis/nlb.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ import (
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param option query string false "Option: [required params for register] connectionName, name, cspNLBId" Enums(register)
// @Param nlbReq body mcis.TbNLBReq true "Details of the NLB object"
// @Success 200 {object} mcis.TbNLBInfo
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /ns/{nsId}/nlb [post]
// @Router /ns/{nsId}/mcis/{mcisId}/nlb [post]
func RestPostNLB(c echo.Context) error {

nsId := c.Param("nsId")
mcisId := c.Param("mcisId")

optionFlag := c.QueryParam("option")

Expand All @@ -49,7 +51,7 @@ func RestPostNLB(c echo.Context) error {

fmt.Println("[POST NLB]")

content, err := mcis.CreateNLB(nsId, u, optionFlag)
content, err := mcis.CreateNLB(nsId, mcisId, u, optionFlag)

if err != nil {
common.CBLog.Error(err)
Expand All @@ -68,14 +70,17 @@ func RestPostNLB(c echo.Context) error {
// @Tags [Infra resource] NLB management
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param nlbInfo body mcis.TbNLBInfo true "Details of the NLB object"
// @Success 200 {object} mcis.TbNLBInfo
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /ns/{nsId}/nlb/{nlbId} [put]
// @Router /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId} [put]
*/
func RestPutNLB(c echo.Context) error {
//nsId := c.Param("nsId")
// nsId := c.Param("nsId")
// mcisId := c.Param("mcisId")

return nil
}
Expand All @@ -87,18 +92,19 @@ func RestPutNLB(c echo.Context) error {
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param nlbId path string true "NLB ID"
// @Success 200 {object} mcis.TbNLBInfo
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /ns/{nsId}/nlb/{nlbId} [get]
// @Router /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId} [get]
func RestGetNLB(c echo.Context) error {

nsId := c.Param("nsId")

mcisId := c.Param("mcisId")
resourceId := c.Param("resourceId")

res, err := mcis.GetNLB(nsId, resourceId)
res, err := mcis.GetNLB(nsId, mcisId, resourceId)
if err != nil {
mapA := map[string]string{"message": "Failed to find the NLB " + resourceId}
return c.JSON(http.StatusNotFound, &mapA)
Expand All @@ -119,16 +125,18 @@ type RestGetAllNLBResponse struct {
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param option query string false "Option" Enums(id)
// @Param filterKey query string false "Field key for filtering (ex: cspNLBName)"
// @Param filterVal query string false "Field value for filtering (ex: ns01-alibaba-ap-northeast-1-vpc)"
// @Success 200 {object} JSONResult{[DEFAULT]=RestGetAllNLBResponse,[ID]=common.IdList} "Different return structures by the given option param"
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /ns/{nsId}/nlb [get]
// @Router /ns/{nsId}/mcis/{mcisId}/nlb [get]
func RestGetAllNLB(c echo.Context) error {

nsId := c.Param("nsId")
mcisId := c.Param("mcisId")

optionFlag := c.QueryParam("option")
filterKey := c.QueryParam("filterKey")
Expand All @@ -137,7 +145,7 @@ func RestGetAllNLB(c echo.Context) error {
if optionFlag == "id" {
content := common.IdList{}
var err error
content.IdList, err = mcis.ListNLBId(nsId)
content.IdList, err = mcis.ListNLBId(nsId, mcisId)
if err != nil {
mapA := map[string]string{"message": "Failed to list NLBs' ID; " + err.Error()}
return c.JSON(http.StatusNotFound, &mapA)
Expand All @@ -146,7 +154,7 @@ func RestGetAllNLB(c echo.Context) error {
return c.JSON(http.StatusOK, &content)
} else {

resourceList, err := mcis.ListNLB(nsId, filterKey, filterVal)
resourceList, err := mcis.ListNLB(nsId, mcisId, filterKey, filterVal)
if err != nil {
mapA := map[string]string{"message": "Failed to list NLBs; " + err.Error()}
return c.JSON(http.StatusNotFound, &mapA)
Expand All @@ -169,19 +177,20 @@ func RestGetAllNLB(c echo.Context) error {
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param nlbId path string true "NLB ID"
// @Success 200 {object} common.SimpleMsg
// @Failure 404 {object} common.SimpleMsg
// @Router /ns/{nsId}/nlb/{nlbId} [delete]
// @Router /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId} [delete]
func RestDelNLB(c echo.Context) error {

nsId := c.Param("nsId")

mcisId := c.Param("mcisId")
resourceId := c.Param("resourceId")

forceFlag := c.QueryParam("force")

err := mcis.DelNLB(nsId, resourceId, forceFlag)
err := mcis.DelNLB(nsId, mcisId, resourceId, forceFlag)
if err != nil {
common.CBLog.Error(err)
mapA := map[string]string{"message": err.Error()}
Expand All @@ -199,18 +208,20 @@ func RestDelNLB(c echo.Context) error {
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param match query string false "Delete resources containing matched ID-substring only" default()
// @Success 200 {object} common.IdList
// @Failure 404 {object} common.SimpleMsg
// @Router /ns/{nsId}/nlb [delete]
// @Router /ns/{nsId}/mcis/{mcisId}/nlb [delete]
func RestDelAllNLB(c echo.Context) error {

nsId := c.Param("nsId")
mcisId := c.Param("mcisId")

forceFlag := c.QueryParam("force")
subString := c.QueryParam("match")

output, err := mcis.DelAllNLB(nsId, subString, forceFlag)
output, err := mcis.DelAllNLB(nsId, mcisId, subString, forceFlag)
if err != nil {
common.CBLog.Error(err)
mapA := map[string]string{"message": err.Error()}
Expand All @@ -220,23 +231,54 @@ func RestDelAllNLB(c echo.Context) error {
return c.JSON(http.StatusOK, output)
}

// RestGetNLBHealth godoc
// @Summary Get NLB Health
// @Description Get NLB Health
// @Tags [Infra resource] NLB management
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param nlbId path string true "NLB ID"
// @Success 200 {object} mcis.TbNLBInfo
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}/healthz [get]
func RestGetNLBHealth(c echo.Context) error {

nsId := c.Param("nsId")
mcisId := c.Param("mcisId")
resourceId := c.Param("resourceId")

res, err := mcis.GetNLBHealth(nsId, mcisId, resourceId)
if err != nil {
mapA := map[string]string{"message": "Failed to get the health info of NLB " + resourceId}
return c.JSON(http.StatusNotFound, &mapA)
} else {
return c.JSON(http.StatusOK, &res)
}
}

// The REST APIs below are for dev/test only

// RestAddNLBVMs godoc
// @Summary Add VMs to NLB
// @Description Add VMs to NLB
// @Tags [Infra resource] NLB management
// @Tags [Infra resource] NLB management (for developer)
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param nlbId path string true "NLB ID"
// @Param nlbAddRemoveVMReq body mcis.TbNLBAddRemoveVMReq true "VMs to add to NLB"
// @Success 200 {object} mcis.TbNLBInfo
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /ns/{nsId}/nlb/{nlbId}/vm [post]
// @Router /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}/vm [post]
func RestAddNLBVMs(c echo.Context) error {

nsId := c.Param("nsId")

mcisId := c.Param("mcisId")
resourceId := c.Param("resourceId")

u := &mcis.TbNLBAddRemoveVMReq{}
Expand All @@ -246,7 +288,7 @@ func RestAddNLBVMs(c echo.Context) error {

fmt.Println("[Add NLB VMs]")

content, err := mcis.AddNLBVMs(nsId, resourceId, u)
content, err := mcis.AddNLBVMs(nsId, mcisId, resourceId, u)

if err != nil {
common.CBLog.Error(err)
Expand All @@ -259,27 +301,28 @@ func RestAddNLBVMs(c echo.Context) error {
// RestRemoveNLBVMs godoc
// @Summary Delete VMs from NLB
// @Description Delete VMs from NLB
// @Tags [Infra resource] NLB management
// @Tags [Infra resource] NLB management (for developer)
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param nlbId path string true "NLB ID"
// @Param nlbAddRemoveVMReq body mcis.TbNLBAddRemoveVMReq true "VMs to add to NLB"
// @Success 200 {object} common.SimpleMsg
// @Failure 404 {object} common.SimpleMsg
// @Router /ns/{nsId}/nlb/{nlbId}/vm [delete]
// @Router /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}/vm [delete]
func RestRemoveNLBVMs(c echo.Context) error {

nsId := c.Param("nsId")

mcisId := c.Param("mcisId")
resourceId := c.Param("resourceId")

u := &mcis.TbNLBAddRemoveVMReq{}
if err := c.Bind(u); err != nil {
return err
}

err := mcis.RemoveNLBVMs(nsId, resourceId, u)
err := mcis.RemoveNLBVMs(nsId, mcisId, resourceId, u)
if err != nil {
common.CBLog.Error(err)
mapA := map[string]string{"message": err.Error()}
Expand Down
20 changes: 11 additions & 9 deletions src/api/rest/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,17 @@ func RunServer(port string) {
g.PUT("/:nsId/network/mcis/:mcisId", rest_mcis.RestPutInjectCloudInformationForCloudAdaptiveNetwork)

// Network Load Balancer
g.POST("/:nsId/nlb", rest_mcis.RestPostNLB)
g.GET("/:nsId/nlb/:resourceId", rest_mcis.RestGetNLB)
g.GET("/:nsId/nlb", rest_mcis.RestGetAllNLB)
// g.PUT("/:nsId/nlb/:resourceId", rest_mcis.RestPutNLB)
g.DELETE("/:nsId/nlb/:resourceId", rest_mcis.RestDelNLB)
g.DELETE("/:nsId/nlb", rest_mcis.RestDelAllNLB)

g.POST("/:nsId/nlb/:resourceId/vm", rest_mcis.RestAddNLBVMs)
g.DELETE("/:nsId/nlb/:resourceId/vm", rest_mcis.RestRemoveNLBVMs)
g.POST("/:nsId/mcis/:mcisId/nlb", rest_mcis.RestPostNLB)
g.GET("/:nsId/mcis/:mcisId/nlb/:resourceId", rest_mcis.RestGetNLB)
g.GET("/:nsId/mcis/:mcisId/nlb", rest_mcis.RestGetAllNLB)
// g.PUT("/:nsId/mcis/:mcisId/nlb/:resourceId", rest_mcis.RestPutNLB)
g.DELETE("/:nsId/mcis/:mcisId/nlb/:resourceId", rest_mcis.RestDelNLB)
g.DELETE("/:nsId/mcis/:mcisId/nlb", rest_mcis.RestDelAllNLB)
g.GET("/:nsId/mcis/:mcisId/nlb/:resourceId/healthz", rest_mcis.RestGetNLBHealth)

// These REST APIs are for dev/test only
g.POST("/:nsId/mcis/:mcisId/nlb/:resourceId/vm", rest_mcis.RestAddNLBVMs)
g.DELETE("/:nsId/mcis/:mcisId/nlb/:resourceId/vm", rest_mcis.RestRemoveNLBVMs)

//MCIR Management
g.POST("/:nsId/resources/image", rest_mcir.RestPostImage)
Expand Down
Loading