diff --git a/scripts/runSpider.sh b/scripts/runSpider.sh index b18c3cca9..177b0c7c5 100755 --- a/scripts/runSpider.sh +++ b/scripts/runSpider.sh @@ -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" diff --git a/src/api/rest/docs/docs.go b/src/api/rest/docs/docs.go index faf54e723..d2f27a39c 100644 --- a/src/api/rest/docs/docs.go +++ b/src/api/rest/docs/docs.go @@ -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": { diff --git a/src/api/rest/docs/swagger.json b/src/api/rest/docs/swagger.json index 988244171..76f483be1 100644 --- a/src/api/rest/docs/swagger.json +++ b/src/api/rest/docs/swagger.json @@ -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": { diff --git a/src/api/rest/docs/swagger.yaml b/src/api/rest/docs/swagger.yaml index 3488e7028..70b74cf65 100644 --- a/src/api/rest/docs/swagger.yaml +++ b/src/api/rest/docs/swagger.yaml @@ -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: diff --git a/src/api/rest/server/common/config.go b/src/api/rest/server/common/config.go index efb911ae8..ee00a884c 100644 --- a/src/api/rest/server/common/config.go +++ b/src/api/rest/server/common/config.go @@ -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) @@ -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()) @@ -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() @@ -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) @@ -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"} diff --git a/src/api/rest/server/common/namespace.go b/src/api/rest/server/common/namespace.go index c71522119..c1f5cf7da 100644 --- a/src/api/rest/server/common/namespace.go +++ b/src/api/rest/server/common/namespace.go @@ -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) } @@ -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) @@ -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) } @@ -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 @@ -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) } @@ -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) @@ -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) diff --git a/src/api/rest/server/common/utility.go b/src/api/rest/server/common/utility.go index 36cb40b3b..bc2fce18c 100644 --- a/src/api/rest/server/common/utility.go +++ b/src/api/rest/server/common/utility.go @@ -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) @@ -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) } @@ -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) @@ -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) @@ -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 @@ -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) } @@ -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) @@ -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) @@ -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 { diff --git a/src/api/rest/server/mcir/common.go b/src/api/rest/server/mcir/common.go index 878028b0a..5612d4019 100644 --- a/src/api/rest/server/mcir/common.go +++ b/src/api/rest/server/mcir/common.go @@ -16,6 +16,7 @@ package mcir import ( "fmt" + "net/http" "strings" "github.com/labstack/echo/v4" @@ -34,7 +35,10 @@ type JSONResult struct { // RestDelAllResources is a common function to handle 'DelAllResources' REST API requests. // Dummy functions for Swagger exist in [mcir/*.go] func RestDelAllResources(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()}) + } nsId := c.Param("nsId") resourceType := strings.Split(c.Path(), "/")[5] // c.Path(): /tumblebug/ns/:nsId/resources/spec/:specId @@ -49,7 +53,10 @@ func RestDelAllResources(c echo.Context) error { // RestDelResource is a common function to handle 'DelResource' REST API requests. // Dummy functions for Swagger exist in [mcir/*.go] func RestDelResource(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()}) + } nsId := c.Param("nsId") resourceType := strings.Split(c.Path(), "/")[5] @@ -67,7 +74,10 @@ func RestDelResource(c echo.Context) error { // RestDelChildResource is a common function to handle 'DelChildResource' REST API requests. // Dummy functions for Swagger exist in [mcir/*.go] func RestDelChildResource(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()}) + } nsId := c.Param("nsId") childResourceType := strings.Split(c.Path(), "/")[7] @@ -86,7 +96,10 @@ func RestDelChildResource(c echo.Context) error { // RestGetAllResources is a common function to handle 'GetAllResources' REST API requests. // Dummy functions for Swagger exist in [mcir/*.go] func RestGetAllResources(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()}) + } nsId := c.Param("nsId") optionFlag := c.QueryParam("option") @@ -170,7 +183,10 @@ func RestGetAllResources(c echo.Context) error { // RestGetResource is a common function to handle 'GetResource' REST API requests. // Dummy functions for Swagger exist in [mcir/*.go] func RestGetResource(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()}) + } nsId := c.Param("nsId") resourceType := strings.Split(c.Path(), "/")[5] @@ -199,7 +215,10 @@ func RestGetResource(c echo.Context) error { // @Failure 404 {object} common.SimpleMsg // @Router /{nsId}/checkResource/{resourceType}/{resourceId} [get] func RestCheckResource(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()}) + } nsId := c.Param("nsId") resourceType := c.Param("resourceType") resourceId := c.Param("resourceId") @@ -218,7 +237,10 @@ func RestCheckResource(c echo.Context) error { // RestTestAddObjectAssociation is a REST API call handling function // to test "mcir.UpdateAssociatedObjectList" function with "add" argument. func RestTestAddObjectAssociation(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()}) + } nsId := c.Param("nsId") //resourceType := strings.Split(c.Path(), "/")[5] // c.Path(): /tumblebug/ns/:nsId/testAddObjectAssociation/:resourceType/:resourceId @@ -233,7 +255,10 @@ func RestTestAddObjectAssociation(c echo.Context) error { // RestTestDeleteObjectAssociation is a REST API call handling function // to test "mcir.UpdateAssociatedObjectList" function with "delete" argument. func RestTestDeleteObjectAssociation(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()}) + } nsId := c.Param("nsId") //resourceType := strings.Split(c.Path(), "/")[5] // c.Path(): /tumblebug/ns/:nsId/testDeleteObjectAssociation/:resourceType/:resourceId @@ -247,7 +272,10 @@ func RestTestDeleteObjectAssociation(c echo.Context) error { // RestTestGetAssociatedObjectCount is a REST API call handling function // to test "mcir.GetAssociatedObjectCount" function. func RestTestGetAssociatedObjectCount(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()}) + } nsId := c.Param("nsId") //resourceType := strings.Split(c.Path(), "/")[5] // c.Path(): /tumblebug/ns/:nsId/testGetAssociatedObjectCount/:resourceType/:resourceId @@ -270,7 +298,10 @@ func RestTestGetAssociatedObjectCount(c echo.Context) error { // @Failure 404 {object} common.SimpleMsg // @Router /loadCommonResource [get] func RestLoadCommonResource(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 := mcir.LoadCommonResource() return common.EndRequestWithLog(c, reqID, err, content) } @@ -288,7 +319,10 @@ func RestLoadCommonResource(c echo.Context) error { // @Failure 404 {object} common.SimpleMsg // @Router /ns/{nsId}/loadDefaultResource [get] func RestLoadDefaultResource(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()}) + } nsId := c.Param("nsId") resType := c.QueryParam("option") @@ -311,7 +345,10 @@ func RestLoadDefaultResource(c echo.Context) error { // @Failure 404 {object} common.SimpleMsg // @Router /ns/{nsId}/defaultResources [delete] func RestDelAllDefaultResources(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()}) + } nsId := c.Param("nsId") content, err := mcir.DelAllDefaultResources(nsId) diff --git a/src/api/rest/server/mcir/customimage.go b/src/api/rest/server/mcir/customimage.go index 2cd7814c7..8d5638b03 100644 --- a/src/api/rest/server/mcir/customimage.go +++ b/src/api/rest/server/mcir/customimage.go @@ -16,6 +16,7 @@ package mcir import ( "fmt" + "net/http" "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcir" @@ -36,7 +37,10 @@ import ( // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/customImage [post] func RestPostCustomImage(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()}) + } nsId := c.Param("nsId") optionFlag := c.QueryParam("option") diff --git a/src/api/rest/server/mcir/dataDisk.go b/src/api/rest/server/mcir/dataDisk.go index 39a91527c..0fa69c12d 100644 --- a/src/api/rest/server/mcir/dataDisk.go +++ b/src/api/rest/server/mcir/dataDisk.go @@ -16,6 +16,7 @@ package mcir import ( "fmt" + "net/http" "strconv" "github.com/cloud-barista/cb-tumblebug/src/core/common" @@ -38,7 +39,10 @@ import ( // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/dataDisk [post] func RestPostDataDisk(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()}) + } nsId := c.Param("nsId") @@ -67,7 +71,10 @@ func RestPostDataDisk(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/dataDisk/{dataDiskId} [put] func RestPutDataDisk(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()}) + } nsId := c.Param("nsId") dataDiskId := c.Param("resourceId") @@ -171,7 +178,10 @@ func RestDelAllDataDisk(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/vm/{vmId}/dataDisk [put] func RestPutVmDataDisk(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") vmId := c.Param("vmId") @@ -219,7 +229,10 @@ func RestPutVmDataDisk(c echo.Context) error { // @Failure 404 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/vm/{vmId}/dataDisk [post] func RestPostVmDataDisk(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") vmId := c.Param("vmId") @@ -251,7 +264,10 @@ func RestPostVmDataDisk(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/vm/{vmId}/dataDisk [get] func RestGetVmDataDisk(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") vmId := c.Param("vmId") diff --git a/src/api/rest/server/mcir/firewallrule.go b/src/api/rest/server/mcir/firewallrule.go index fd8825581..414014a6f 100644 --- a/src/api/rest/server/mcir/firewallrule.go +++ b/src/api/rest/server/mcir/firewallrule.go @@ -15,6 +15,8 @@ limitations under the License. package mcir import ( + "net/http" + "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcir" "github.com/labstack/echo/v4" @@ -37,7 +39,10 @@ type TbFirewallRulesWrapper struct { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/securityGroup/{securityGroupId}/rules [post] func RestPostFirewallRules(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()}) + } nsId := c.Param("nsId") securityGroupId := c.Param("securityGroupId") @@ -106,7 +111,10 @@ type RestGetAllFirewallRulesResponse struct { // @Failure 404 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/securityGroup/{securityGroupId}/rules [delete] func RestDelFirewallRules(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()}) + } nsId := c.Param("nsId") securityGroupId := c.Param("securityGroupId") diff --git a/src/api/rest/server/mcir/image.go b/src/api/rest/server/mcir/image.go index e8866e870..4e973d575 100644 --- a/src/api/rest/server/mcir/image.go +++ b/src/api/rest/server/mcir/image.go @@ -16,6 +16,7 @@ package mcir import ( "fmt" + "net/http" "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcir" @@ -37,7 +38,10 @@ import ( // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/image [post] func RestPostImage(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()}) + } nsId := c.Param("nsId") action := c.QueryParam("action") @@ -86,7 +90,10 @@ func RestPostImage(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/image/{imageId} [put] func RestPutImage(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()}) + } nsId := c.Param("nsId") imageId := c.Param("resourceId") @@ -117,7 +124,10 @@ type RestLookupImageRequest struct { // @Failure 500 {object} common.SimpleMsg // @Router /lookupImage [post] func RestLookupImage(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 := &RestLookupImageRequest{} if err := c.Bind(u); err != nil { return common.EndRequestWithLog(c, reqID, err, nil) @@ -141,7 +151,10 @@ func RestLookupImage(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /lookupImages [post] func RestLookupImageList(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 := &RestLookupImageRequest{} if err := c.Bind(u); err != nil { return common.EndRequestWithLog(c, reqID, err, nil) @@ -165,7 +178,10 @@ func RestLookupImageList(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/fetchImages [post] func RestFetchImages(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()}) + } nsId := c.Param("nsId") u := &RestLookupImageRequest{} @@ -285,7 +301,10 @@ type RestSearchImageRequest struct { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/searchImage [post] func RestSearchImage(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()}) + } nsId := c.Param("nsId") u := &RestSearchImageRequest{} diff --git a/src/api/rest/server/mcir/securitygroup.go b/src/api/rest/server/mcir/securitygroup.go index a3a9a0dd9..c7130d497 100644 --- a/src/api/rest/server/mcir/securitygroup.go +++ b/src/api/rest/server/mcir/securitygroup.go @@ -15,6 +15,8 @@ limitations under the License. package mcir import ( + "net/http" + "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcir" "github.com/labstack/echo/v4" @@ -34,7 +36,10 @@ import ( // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/securityGroup [post] func RestPostSecurityGroup(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()}) + } nsId := c.Param("nsId") optionFlag := c.QueryParam("option") diff --git a/src/api/rest/server/mcir/spec.go b/src/api/rest/server/mcir/spec.go index cd6ae147c..1887b7ee2 100644 --- a/src/api/rest/server/mcir/spec.go +++ b/src/api/rest/server/mcir/spec.go @@ -16,6 +16,7 @@ package mcir import ( "fmt" + "net/http" "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcir" @@ -37,7 +38,10 @@ import ( // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/spec [post] func RestPostSpec(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()}) + } nsId := c.Param("nsId") action := c.QueryParam("action") @@ -82,7 +86,10 @@ func RestPostSpec(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/spec/{specId} [put] func RestPutSpec(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()}) + } nsId := c.Param("nsId") specId := c.Param("resourceId") @@ -113,7 +120,10 @@ type RestLookupSpecRequest struct { // @Failure 500 {object} common.SimpleMsg // @Router /lookupSpec [post] func RestLookupSpec(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 := &RestLookupSpecRequest{} if err := c.Bind(u); err != nil { return common.EndRequestWithLog(c, reqID, err, nil) @@ -137,7 +147,10 @@ func RestLookupSpec(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /lookupSpecs [post] func RestLookupSpecList(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 := &RestLookupSpecRequest{} if err := c.Bind(u); err != nil { return common.EndRequestWithLog(c, reqID, err, nil) @@ -161,7 +174,10 @@ func RestLookupSpecList(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/fetchSpecs [post] func RestFetchSpecs(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()}) + } nsId := c.Param("nsId") u := &RestLookupSpecRequest{} @@ -208,7 +224,10 @@ type RestFilterSpecsResponse struct { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/filterSpecs [post] func RestFilterSpecs(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()}) + } nsId := c.Param("nsId") u := &mcir.TbSpecInfo{} @@ -236,7 +255,10 @@ func RestFilterSpecs(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/filterSpecsByRange [post] func RestFilterSpecsByRange(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()}) + } nsId := c.Param("nsId") u := &mcir.FilterSpecsByRangeRequest{} @@ -252,7 +274,10 @@ func RestFilterSpecsByRange(c echo.Context) error { } func RestTestSortSpecs(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()}) + } nsId := c.Param("nsId") u := &mcir.TbSpecInfo{} diff --git a/src/api/rest/server/mcir/sshkey.go b/src/api/rest/server/mcir/sshkey.go index e5b0bd276..ffd862ff3 100644 --- a/src/api/rest/server/mcir/sshkey.go +++ b/src/api/rest/server/mcir/sshkey.go @@ -15,6 +15,8 @@ limitations under the License. package mcir import ( + "net/http" + "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcir" "github.com/labstack/echo/v4" @@ -34,7 +36,10 @@ import ( // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/sshKey [post] func RestPostSshKey(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()}) + } nsId := c.Param("nsId") @@ -63,7 +68,10 @@ func RestPostSshKey(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/sshKey/{sshKeyId} [put] func RestPutSshKey(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()}) + } nsId := c.Param("nsId") sshKeyId := c.Param("resourceId") diff --git a/src/api/rest/server/mcir/subnet.go b/src/api/rest/server/mcir/subnet.go index 7782129f5..38073946b 100644 --- a/src/api/rest/server/mcir/subnet.go +++ b/src/api/rest/server/mcir/subnet.go @@ -15,6 +15,8 @@ limitations under the License. package mcir import ( + "net/http" + "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcir" "github.com/labstack/echo/v4" @@ -34,7 +36,10 @@ import ( // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/vNet/{vNetId}/subnet [post] func RestPostSubnet(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()}) + } nsId := c.Param("nsId") vNetId := c.Param("vNetId") diff --git a/src/api/rest/server/mcir/vnet.go b/src/api/rest/server/mcir/vnet.go index e1d0983aa..ab7ea84de 100644 --- a/src/api/rest/server/mcir/vnet.go +++ b/src/api/rest/server/mcir/vnet.go @@ -15,6 +15,8 @@ limitations under the License. package mcir import ( + "net/http" + "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcir" "github.com/labstack/echo/v4" @@ -34,7 +36,10 @@ import ( // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/resources/vNet [post] func RestPostVNet(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()}) + } nsId := c.Param("nsId") optionFlag := c.QueryParam("option") u := &mcir.TbVNetReq{} diff --git a/src/api/rest/server/mcis/benchmark.go b/src/api/rest/server/mcis/benchmark.go index e3bf17dae..d04bc7f00 100644 --- a/src/api/rest/server/mcis/benchmark.go +++ b/src/api/rest/server/mcis/benchmark.go @@ -15,6 +15,8 @@ limitations under the License. package mcis import ( + "net/http" + "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcis" "github.com/labstack/echo/v4" @@ -35,7 +37,10 @@ import ( // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/installBenchmarkAgent/mcis/{mcisId} [post] func RestPostInstallBenchmarkAgentToMcis(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") @@ -79,7 +84,10 @@ type RestGetAllBenchmarkRequest struct { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/benchmarkAll/mcis/{mcisId} [post] func RestGetAllBenchmark(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") @@ -106,7 +114,10 @@ func RestGetAllBenchmark(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/benchmarkLatency/mcis/{mcisId} [get] func RestGetBenchmarkLatency(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") @@ -133,7 +144,10 @@ type RestGetBenchmarkRequest struct { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/benchmark/mcis/{mcisId} [post] func RestGetBenchmark(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") action := c.QueryParam("action") diff --git a/src/api/rest/server/mcis/control.go b/src/api/rest/server/mcis/control.go index 808882ec8..bddb1e395 100644 --- a/src/api/rest/server/mcis/control.go +++ b/src/api/rest/server/mcis/control.go @@ -16,6 +16,7 @@ package mcis import ( "fmt" + "net/http" "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcis" @@ -37,7 +38,10 @@ import ( // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/control/mcis/{mcisId} [get] func RestGetControlMcis(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") @@ -75,7 +79,10 @@ func RestGetControlMcis(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/control/mcis/{mcisId}/vm/{vmId} [get] func RestGetControlMcisVm(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") vmId := c.Param("vmId") @@ -113,7 +120,10 @@ func RestGetControlMcisVm(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/vm/{vmId}/snapshot [post] func RestPostMcisVmSnapshot(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") vmId := c.Param("vmId") diff --git a/src/api/rest/server/mcis/manageInfo.go b/src/api/rest/server/mcis/manageInfo.go index 44615e405..8d1776b46 100644 --- a/src/api/rest/server/mcis/manageInfo.go +++ b/src/api/rest/server/mcis/manageInfo.go @@ -16,6 +16,7 @@ package mcis import ( "fmt" + "net/http" "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcis" @@ -49,7 +50,10 @@ type JSONResult struct { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId} [get] func RestGetMcis(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") @@ -114,7 +118,10 @@ type RestGetAllMcisStatusResponse struct { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis [get] func RestGetAllMcis(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()}) + } nsId := c.Param("nsId") option := c.QueryParam("option") @@ -186,7 +193,10 @@ func RestPutMcis(c echo.Context) error { // @Failure 404 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId} [delete] func RestDelMcis(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") option := c.QueryParam("option") @@ -207,7 +217,10 @@ func RestDelMcis(c echo.Context) error { // @Failure 404 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis [delete] func RestDelAllMcis(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()}) + } nsId := c.Param("nsId") option := c.QueryParam("option") @@ -233,7 +246,10 @@ func RestDelAllMcis(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/vm/{vmId} [get] func RestGetMcisVm(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") vmId := c.Param("vmId") @@ -289,7 +305,10 @@ func RestPutMcisVm(c echo.Context) error { // @Failure 404 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/vm/{vmId} [delete] func RestDelMcisVm(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") vmId := c.Param("vmId") @@ -321,7 +340,10 @@ func RestDelMcisVm(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/subgroup/{subgroupId} [get] func RestGetMcisGroupVms(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") subgroupId := c.Param("subgroupId") @@ -346,7 +368,10 @@ func RestGetMcisGroupVms(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/subgroup [get] func RestGetMcisGroupIds(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") //option := c.QueryParam("option") diff --git a/src/api/rest/server/mcis/monitoring.go b/src/api/rest/server/mcis/monitoring.go index 2f279f373..ae854a024 100644 --- a/src/api/rest/server/mcis/monitoring.go +++ b/src/api/rest/server/mcis/monitoring.go @@ -15,6 +15,8 @@ limitations under the License. package mcis import ( + "net/http" + "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcis" "github.com/labstack/echo/v4" @@ -34,7 +36,10 @@ import ( // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/monitoring/install/mcis/{mcisId} [post] func RestPostInstallMonitorAgentToMcis(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") @@ -61,7 +66,10 @@ func RestPostInstallMonitorAgentToMcis(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/monitoring/status/mcis/{mcisId}/vm/{vmId} [put] func RestPutMonitorAgentStatusInstalled(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") vmId := c.Param("vmId") @@ -90,7 +98,10 @@ func RestPutMonitorAgentStatusInstalled(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/monitoring/mcis/{mcisId}/metric/{metric} [get] func RestGetMonitorData(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") metric := c.Param("metric") diff --git a/src/api/rest/server/mcis/network.go b/src/api/rest/server/mcis/network.go index f0730ee18..3d7c7611b 100644 --- a/src/api/rest/server/mcis/network.go +++ b/src/api/rest/server/mcis/network.go @@ -15,6 +15,8 @@ limitations under the License. package mcis import ( + "net/http" + "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcis" "github.com/labstack/echo/v4" @@ -34,7 +36,10 @@ import ( // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/network/mcis/{mcisId} [post] func RestPostConfigureCloudAdaptiveNetworkToMcis(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") @@ -61,7 +66,10 @@ func RestPostConfigureCloudAdaptiveNetworkToMcis(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/network/mcis/{mcisId} [put] func RestPutInjectCloudInformationForCloudAdaptiveNetwork(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") diff --git a/src/api/rest/server/mcis/nlb.go b/src/api/rest/server/mcis/nlb.go index 6f7431133..aeee19c7c 100644 --- a/src/api/rest/server/mcis/nlb.go +++ b/src/api/rest/server/mcis/nlb.go @@ -15,6 +15,8 @@ limitations under the License. package mcis import ( + "net/http" + "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcis" "github.com/labstack/echo/v4" @@ -35,7 +37,10 @@ import ( // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/nlb [post] func RestPostNLB(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") @@ -64,7 +69,10 @@ func RestPostNLB(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/mcSwNlb [post] func RestPostMcNLB(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") @@ -116,7 +124,10 @@ func RestPutNLB(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId} [get] func RestGetNLB(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") resourceId := c.Param("resourceId") @@ -146,7 +157,10 @@ type RestGetAllNLBResponse struct { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/nlb [get] func RestGetAllNLB(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") @@ -188,7 +202,10 @@ func RestGetAllNLB(c echo.Context) error { // @Failure 404 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId} [delete] func RestDelNLB(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") resourceId := c.Param("resourceId") @@ -213,7 +230,10 @@ func RestDelNLB(c echo.Context) error { // @Failure 404 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/nlb [delete] func RestDelAllNLB(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") @@ -238,7 +258,10 @@ func RestDelAllNLB(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}/healthz [get] func RestGetNLBHealth(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") resourceId := c.Param("resourceId") @@ -264,7 +287,10 @@ func RestGetNLBHealth(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}/vm [post] func RestAddNLBVMs(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") resourceId := c.Param("resourceId") @@ -291,7 +317,10 @@ func RestAddNLBVMs(c echo.Context) error { // @Failure 404 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}/vm [delete] func RestRemoveNLBVMs(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") resourceId := c.Param("resourceId") diff --git a/src/api/rest/server/mcis/orchestration.go b/src/api/rest/server/mcis/orchestration.go index 69a1ddd86..634996407 100644 --- a/src/api/rest/server/mcis/orchestration.go +++ b/src/api/rest/server/mcis/orchestration.go @@ -16,6 +16,7 @@ package mcis import ( "fmt" + "net/http" "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcis" @@ -36,7 +37,10 @@ import ( // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/policy/mcis/{mcisId} [post] func RestPostMcisPolicy(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") @@ -62,7 +66,10 @@ func RestPostMcisPolicy(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/policy/mcis/{mcisId} [get] func RestGetMcisPolicy(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") @@ -97,7 +104,10 @@ type RestGetAllMcisPolicyResponse struct { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/policy/mcis [get] func RestGetAllMcisPolicy(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()}) + } nsId := c.Param("nsId") fmt.Println("[Get MCIS Policy List]") @@ -142,7 +152,10 @@ func RestPutMcisPolicy(c echo.Context) error { // @Failure 404 {object} common.SimpleMsg // @Router /ns/{nsId}/policy/mcis/{mcisId} [delete] func RestDelMcisPolicy(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") @@ -162,7 +175,10 @@ func RestDelMcisPolicy(c echo.Context) error { // @Failure 404 {object} common.SimpleMsg // @Router /ns/{nsId}/policy/mcis [delete] func RestDelAllMcisPolicy(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()}) + } nsId := c.Param("nsId") result, err := mcis.DelAllMcisPolicy(nsId) return common.EndRequestWithLog(c, reqID, err, result) diff --git a/src/api/rest/server/mcis/provisioning.go b/src/api/rest/server/mcis/provisioning.go index 6307a720a..880f78605 100644 --- a/src/api/rest/server/mcis/provisioning.go +++ b/src/api/rest/server/mcis/provisioning.go @@ -15,6 +15,8 @@ limitations under the License. package mcis import ( + "net/http" + "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcis" "github.com/labstack/echo/v4" @@ -33,7 +35,10 @@ import ( // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis [post] func RestPostMcis(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()}) + } nsId := c.Param("nsId") req := &mcis.TbMcisReq{} @@ -59,7 +64,10 @@ func RestPostMcis(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/registerCspVm [post] func RestPostRegisterCSPNativeVM(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()}) + } nsId := c.Param("nsId") req := &mcis.TbMcisReq{} @@ -84,7 +92,10 @@ func RestPostRegisterCSPNativeVM(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /systemMcis [post] func RestPostSystemMcis(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()}) + } option := c.QueryParam("option") req := &mcis.TbMcisDynamicReq{} @@ -109,7 +120,10 @@ func RestPostSystemMcis(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcisDynamic [post] func RestPostMcisDynamic(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()}) + } nsId := c.Param("nsId") req := &mcis.TbMcisDynamicReq{} @@ -135,7 +149,10 @@ func RestPostMcisDynamic(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/vmDynamic [post] func RestPostMcisVmDynamic(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") @@ -160,7 +177,10 @@ func RestPostMcisVmDynamic(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /mcisDynamicCheckRequest [post] func RestPostMcisDynamicCheckRequest(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()}) + } req := &mcis.McisConnectionConfigCandidatesReq{} if err := c.Bind(req); err != nil { return common.EndRequestWithLog(c, reqID, err, nil) @@ -184,7 +204,10 @@ func RestPostMcisDynamicCheckRequest(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/vm [post] func RestPostMcisVm(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") @@ -211,7 +234,10 @@ func RestPostMcisVm(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/subgroup/{subgroupId} [post] func RestPostMcisSubGroupScaleOut(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") subgroupId := c.Param("subgroupId") diff --git a/src/api/rest/server/mcis/recommendation.go b/src/api/rest/server/mcis/recommendation.go index 6095ee8d5..7a1d43107 100644 --- a/src/api/rest/server/mcis/recommendation.go +++ b/src/api/rest/server/mcis/recommendation.go @@ -15,6 +15,8 @@ limitations under the License. package mcis import ( + "net/http" + "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcis" "github.com/labstack/echo/v4" @@ -32,7 +34,10 @@ import ( // @Failure 500 {object} common.SimpleMsg // @Router /mcisRecommendVm [post] func RestRecommendVm(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()}) + } nsId := common.SystemCommonNs u := &mcis.DeploymentPlan{} diff --git a/src/api/rest/server/mcis/remoteCommand.go b/src/api/rest/server/mcis/remoteCommand.go index 8715ed643..caa921453 100644 --- a/src/api/rest/server/mcis/remoteCommand.go +++ b/src/api/rest/server/mcis/remoteCommand.go @@ -15,6 +15,8 @@ limitations under the License. package mcis import ( + "net/http" + "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcis" "github.com/labstack/echo/v4" @@ -31,12 +33,16 @@ import ( // @Param mcisCmdReq body mcis.McisCmdReq true "MCIS Command Request" // @Param subGroupId query string false "subGroupId to apply the command only for VMs in subGroup of MCIS" default(g1) // @Param vmId query string false "vmId to apply the command only for a VM in MCIS" default(g1-1) +// @Param x-request-id header string false "Custom request ID" // @Success 200 {object} mcis.McisSshCmdResult // @Failure 404 {object} common.SimpleMsg // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/cmd/mcis/{mcisId} [post] func RestPostCmdMcis(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") @@ -45,23 +51,23 @@ func RestPostCmdMcis(c echo.Context) error { req := &mcis.McisCmdReq{} if err := c.Bind(req); err != nil { - return err + return common.EndRequestWithLog(c, reqID, err, nil) } - resultArray, err := mcis.RemoteCommandToMcis(nsId, mcisId, subGroupId, vmId, req) + output, err := mcis.RemoteCommandToMcis(nsId, mcisId, subGroupId, vmId, req) if err != nil { return common.EndRequestWithLog(c, reqID, err, nil) } - content := mcis.McisSshCmdResult{} + result := mcis.McisSshCmdResult{} - for _, v := range resultArray { - content.Results = append(content.Results, v) + for _, v := range output { + result.Results = append(result.Results, v) } - common.PrintJsonPretty(content) + common.PrintJsonPretty(result) - return common.EndRequestWithLog(c, reqID, nil, content) + return common.EndRequestWithLog(c, reqID, err, result) } @@ -80,7 +86,10 @@ func RestPostCmdMcis(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/vm/{targetVmId}/bastion/{bastionVmId} [put] func RestSetBastionNodes(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") targetVmId := c.Param("targetVmId") @@ -104,7 +113,10 @@ func RestSetBastionNodes(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/vm/{targetVmId}/bastion [get] func RestGetBastionNodes(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") targetVmId := c.Param("targetVmId") @@ -127,7 +139,10 @@ func RestGetBastionNodes(c echo.Context) error { // @Failure 500 {object} common.SimpleMsg // @Router /ns/{nsId}/mcis/{mcisId}/bastion/{bastionVmId} [delete] func RestRemoveBastionNodes(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") bastionVmId := c.Param("bastionVmId") diff --git a/src/api/rest/server/mcis/utility.go b/src/api/rest/server/mcis/utility.go index 701717ab3..fdf206dbb 100644 --- a/src/api/rest/server/mcis/utility.go +++ b/src/api/rest/server/mcis/utility.go @@ -15,13 +15,18 @@ limitations under the License. package mcis import ( + "net/http" + "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcis" "github.com/labstack/echo/v4" ) func RestCheckMcis(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") @@ -36,7 +41,10 @@ func RestCheckMcis(c echo.Context) error { } func RestCheckVm(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()}) + } nsId := c.Param("nsId") mcisId := c.Param("mcisId") vmId := c.Param("vmId") diff --git a/src/api/rest/server/util/netuil.go b/src/api/rest/server/util/netuil.go index bd8d8ba78..b52becbcf 100644 --- a/src/api/rest/server/util/netuil.go +++ b/src/api/rest/server/util/netuil.go @@ -1,6 +1,8 @@ package netutil import ( + "net/http" + "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/common/netutil" "github.com/labstack/echo/v4" @@ -28,7 +30,10 @@ type RestPostUtilToDesignNetworkReponse struct { func RestPostUtilToDesignNetwork(c echo.Context) error { // ID for API request tracing - reqID := common.StartRequestWithLog(c) + reqID, idErr := common.StartRequestWithLog(c) + if idErr != nil { + return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()}) + } // Bind the request body to SubnettingRequest struct subnettingReq := new(netutil.SubnettingRequest) @@ -63,7 +68,10 @@ type RestPostUtilToValidateNetworkRequest struct { func RestPostUtilToValidateNetwork(c echo.Context) error { // ID for API request tracing - reqID := common.StartRequestWithLog(c) + reqID, idErr := common.StartRequestWithLog(c) + if idErr != nil { + return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()}) + } // Bind the request body to SubnettingRequest struct req := new(netutil.NetworkConfig) diff --git a/src/core/common/client.go b/src/core/common/client.go index f8be2932c..081ec2699 100644 --- a/src/core/common/client.go +++ b/src/core/common/client.go @@ -209,15 +209,22 @@ func ExtractRequestInfo(r *http.Request) RequestInfo { } // StartRequestWithLog initializes request tracking details -func StartRequestWithLog(c echo.Context) string { - reqID := fmt.Sprintf("%d", time.Now().UnixNano()) +func StartRequestWithLog(c echo.Context) (string, error) { + reqID := c.Request().Header.Get("x-request-id") + if reqID == "" { + reqID = fmt.Sprintf("%d", time.Now().UnixNano()) + } + if _, ok := RequestMap.Load(reqID); ok { + return reqID, fmt.Errorf("The x-request-id is already in use") + } + details := RequestDetails{ StartTime: time.Now(), Status: "Handling", RequestInfo: ExtractRequestInfo(c.Request()), } RequestMap.Store(reqID, details) - return reqID + return reqID, nil } // EndRequestWithLog updates the request details and sends the final response. diff --git a/src/core/mcir/spec.go b/src/core/mcir/spec.go index fc42899bc..4e19dece4 100644 --- a/src/core/mcir/spec.go +++ b/src/core/mcir/spec.go @@ -21,7 +21,8 @@ import ( "strconv" "time" - //"strings" + "strings" + "unicode" "github.com/cloud-barista/cb-tumblebug/src/core/common" validator "github.com/go-playground/validator/v10" @@ -706,9 +707,13 @@ func FilterSpecsByRange(nsId string, filter FilterSpecsByRangeRequest) ([]TbSpec sqlQuery = sqlQuery.And("ProviderName LIKE ?", "%"+filter.ProviderName+"%") } if filter.CspSpecName != "" { - //sqlQuery += " AND `cspSpecName` LIKE '%" + filter.CspSpecName + "%'" - filter.CspSpecName = ToNamingRuleCompatible(filter.CspSpecName) - sqlQuery = sqlQuery.And("CspSpecName LIKE ?", "%"+filter.CspSpecName+"%") + keywords := strings.FieldsFunc(filter.CspSpecName, func(r rune) bool { + return !unicode.IsLetter(r) && !unicode.IsNumber(r) + }) + + for _, keyword := range keywords { + sqlQuery = sqlQuery.And("CspSpecName LIKE ?", "%"+keyword+"%") + } } if filter.OsType != "" { //sqlQuery += " AND `osType` LIKE '%" + filter.OsType + "%'"