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

Support spec selection and custom request ID #1454

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion scripts/runSpider.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

CONTAINER_NAME_READ="CB-Spider"
CONTAINER_VERSION="0.8.4"
CONTAINER_VERSION="0.8.7"
CONTAINER_PORT="-p 1024:1024 -p 2048:2048"
CONTAINER_DATA_PATH="/root/go/src/github.com/cloud-barista/cb-spider/meta_db"

Expand Down
6 changes: 6 additions & 0 deletions src/api/rest/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1826,6 +1826,12 @@ const docTemplate = `{
"description": "vmId to apply the command only for a VM in MCIS",
"name": "vmId",
"in": "query"
},
{
"type": "string",
"description": "Custom request ID",
"name": "x-request-id",
"in": "header"
}
],
"responses": {
Expand Down
6 changes: 6 additions & 0 deletions src/api/rest/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,12 @@
"description": "vmId to apply the command only for a VM in MCIS",
"name": "vmId",
"in": "query"
},
{
"type": "string",
"description": "Custom request ID",
"name": "x-request-id",
"in": "header"
}
],
"responses": {
Expand Down
4 changes: 4 additions & 0 deletions src/api/rest/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4029,6 +4029,10 @@ paths:
in: query
name: vmId
type: string
- description: Custom request ID
in: header
name: x-request-id
type: string
produces:
- application/json
responses:
Expand Down
25 changes: 20 additions & 5 deletions src/api/rest/server/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ import (
// @Failure 500 {object} common.SimpleMsg
// @Router /config/{configId} [delete]
func RestInitConfig(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
if err := Validate(c, []string{"configId"}); err != nil {
common.CBLog.Error(err)
return common.EndRequestWithLog(c, reqID, err, nil)
Expand Down Expand Up @@ -70,7 +73,10 @@ func RestInitConfig(c echo.Context) error {
// @Failure 500 {object} common.SimpleMsg
// @Router /config/{configId} [get]
func RestGetConfig(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
if err := Validate(c, []string{"configId"}); err != nil {
common.CBLog.Error(err)
return SendMessage(c, http.StatusBadRequest, err.Error())
Expand Down Expand Up @@ -102,7 +108,10 @@ type RestGetAllConfigResponse struct {
// @Failure 500 {object} common.SimpleMsg
// @Router /config [get]
func RestGetAllConfig(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
var content RestGetAllConfigResponse

configList, err := common.ListConfig()
Expand All @@ -122,7 +131,10 @@ func RestGetAllConfig(c echo.Context) error {
// @Failure 500 {object} common.SimpleMsg
// @Router /config [post]
func RestPostConfig(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
u := &common.ConfigReq{}
if err := c.Bind(u); err != nil {
return common.EndRequestWithLog(c, reqID, err, nil)
Expand All @@ -144,7 +156,10 @@ func RestPostConfig(c echo.Context) error {
// @Failure 404 {object} common.SimpleMsg
// @Router /config [delete]
func RestInitAllConfig(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
err := common.InitAllConfig()
content := map[string]string{
"message": "All configs has been initialized"}
Expand Down
38 changes: 31 additions & 7 deletions src/api/rest/server/common/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ limitations under the License.
package common

import (
"net/http"

"github.com/labstack/echo/v4"

"github.com/cloud-barista/cb-tumblebug/src/core/common"
)

func RestCheckNs(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
if err := Validate(c, []string{"nsId"}); err != nil {
return common.EndRequestWithLog(c, reqID, err, nil)
}
Expand All @@ -45,7 +50,10 @@ func RestCheckNs(c echo.Context) error {
// @Failure 404 {object} common.SimpleMsg
// @Router /ns [delete]
func RestDelAllNs(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
err := common.DelAllNs()
content := map[string]string{"message": "All namespaces has been deleted"}
return common.EndRequestWithLog(c, reqID, err, content)
Expand All @@ -62,7 +70,10 @@ func RestDelAllNs(c echo.Context) error {
// @Failure 404 {object} common.SimpleMsg
// @Router /ns/{nsId} [delete]
func RestDelNs(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
if err := Validate(c, []string{"nsId"}); err != nil {
return common.EndRequestWithLog(c, reqID, err, nil)
}
Expand Down Expand Up @@ -97,7 +108,10 @@ type RestGetAllNsResponse struct {
// @Failure 500 {object} common.SimpleMsg
// @Router /ns [get]
func RestGetAllNs(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
optionFlag := c.QueryParam("option")

var content RestGetAllNsResponse
Expand Down Expand Up @@ -125,7 +139,11 @@ func RestGetAllNs(c echo.Context) error {
// @Failure 500 {object} common.SimpleMsg
// @Router /ns/{nsId} [get]
func RestGetNs(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}

if err := Validate(c, []string{"nsId"}); err != nil {
return common.EndRequestWithLog(c, reqID, err, nil)
}
Expand All @@ -146,7 +164,10 @@ func RestGetNs(c echo.Context) error {
// @Failure 500 {object} common.SimpleMsg
// @Router /ns [post]
func RestPostNs(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
u := &common.NsReq{}
if err := c.Bind(u); err != nil {
return common.EndRequestWithLog(c, reqID, err, nil)
Expand All @@ -170,7 +191,10 @@ func RestPostNs(c echo.Context) error {
// @Failure 500 {object} common.SimpleMsg
// @Router /ns/{nsId} [put]
func RestPutNs(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
u := &common.NsReq{}
if err := c.Bind(u); err != nil {
return common.EndRequestWithLog(c, reqID, err, nil)
Expand Down
45 changes: 36 additions & 9 deletions src/api/rest/server/common/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ func RestGetSwagger(c echo.Context) error {
// @Failure 500 {object} common.SimpleMsg
// @Router /connConfig/{connConfigName} [get]
func RestGetConnConfig(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
connConfigName := c.Param("connConfigName")

content, err := common.GetConnConfig(connConfigName)
Expand All @@ -172,7 +175,10 @@ func RestGetConnConfig(c echo.Context) error {
// @Failure 500 {object} common.SimpleMsg
// @Router /connConfig [get]
func RestGetConnConfigList(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
content, err := common.GetConnConfigList()
return common.EndRequestWithLog(c, reqID, err, content)
}
Expand All @@ -190,7 +196,10 @@ func RestGetConnConfigList(c echo.Context) error {
// @Failure 500 {object} common.SimpleMsg
// @Router /region/{regionName} [get]
func RestGetRegion(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
regionName := c.Param("regionName")

content, err := common.GetRegion(regionName)
Expand All @@ -210,7 +219,10 @@ func RestGetRegion(c echo.Context) error {
// @Failure 500 {object} common.SimpleMsg
// @Router /region [get]
func RestGetRegionList(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
content, err := common.GetRegionList()
return common.EndRequestWithLog(c, reqID, err, content)

Expand Down Expand Up @@ -345,7 +357,10 @@ type RestInspectResourcesRequest struct {
// @Failure 500 {object} common.SimpleMsg
// @Router /inspectResources [post]
func RestInspectResources(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
u := &RestInspectResourcesRequest{}
if err := c.Bind(u); err != nil {
return err
Expand Down Expand Up @@ -375,7 +390,10 @@ func RestInspectResources(c echo.Context) error {
// @Failure 500 {object} common.SimpleMsg
// @Router /inspectResourcesOverview [get]
func RestInspectResourcesOverview(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
content, err := mcis.InspectResourcesOverview()
return common.EndRequestWithLog(c, reqID, err, content)
}
Expand All @@ -401,7 +419,10 @@ type RestRegisterCspNativeResourcesRequest struct {
// @Failure 500 {object} common.SimpleMsg
// @Router /registerCspResources [post]
func RestRegisterCspNativeResources(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
u := &RestRegisterCspNativeResourcesRequest{}
if err := c.Bind(u); err != nil {
return common.EndRequestWithLog(c, reqID, err, nil)
Expand Down Expand Up @@ -434,7 +455,10 @@ type RestRegisterCspNativeResourcesRequestAll struct {
// @Failure 500 {object} common.SimpleMsg
// @Router /registerCspResourcesAll [post]
func RestRegisterCspNativeResourcesAll(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
u := &RestRegisterCspNativeResourcesRequest{}
if err := c.Bind(u); err != nil {
return common.EndRequestWithLog(c, reqID, err, nil)
Expand All @@ -457,7 +481,10 @@ func RestRegisterCspNativeResourcesAll(c echo.Context) error {
// @Success 200 {object} map[string]interface{}
// @Router /forward/{path} [post]
func RestForwardAnyReqToAny(c echo.Context) error {
reqID := common.StartRequestWithLog(c)
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
reqPath := c.Param("*")
reqPath, err := url.PathUnescape(reqPath)
if err != nil {
Expand Down
Loading