diff --git a/src/api/rest/server/mci/benchmark.go b/src/api/rest/server/mci/benchmark.go index 20dae7c01..f3065f841 100644 --- a/src/api/rest/server/mci/benchmark.go +++ b/src/api/rest/server/mci/benchmark.go @@ -26,7 +26,7 @@ import ( // @ID PostInstallBenchmarkAgentToMci // @Summary Install the benchmark agent to specified MCI // @Description Install the benchmark agent to specified MCI -// @Tags [Infra service] MCI Performance benchmarking (WIP) +// @Tags [MC-Infra] MCI Performance benchmarking (WIP) // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -75,7 +75,7 @@ type RestGetAllBenchmarkRequest struct { // @ID GetAllBenchmark // @Summary Run MCI benchmark for all performance metrics and return results // @Description Run MCI benchmark for all performance metrics and return results -// @Tags [Infra service] MCI Performance benchmarking (WIP) +// @Tags [MC-Infra] MCI Performance benchmarking (WIP) // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -107,7 +107,7 @@ func RestGetAllBenchmark(c echo.Context) error { // @ID GetLatencyBenchmark // @Summary Run MCI benchmark for network latency // @Description Run MCI benchmark for network latency -// @Tags [Infra service] MCI Performance benchmarking (WIP) +// @Tags [MC-Infra] MCI Performance benchmarking (WIP) // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(system-purpose-common-ns) @@ -136,7 +136,7 @@ type RestGetBenchmarkRequest struct { // @ID GetBenchmark // @Summary Run MCI benchmark for a single performance metric and return results // @Description Run MCI benchmark for a single performance metric and return results -// @Tags [Infra service] MCI Performance benchmarking (WIP) +// @Tags [MC-Infra] MCI Performance benchmarking (WIP) // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) diff --git a/src/api/rest/server/mci/control.go b/src/api/rest/server/mci/control.go index 75acd615c..5cc47e8ef 100644 --- a/src/api/rest/server/mci/control.go +++ b/src/api/rest/server/mci/control.go @@ -27,7 +27,7 @@ import ( // @ID GetControlMci // @Summary Control the lifecycle of MCI (refine, suspend, resume, reboot, terminate) // @Description Control the lifecycle of MCI (refine, suspend, resume, reboot, terminate) -// @Tags [Infra service] MCI Control lifecycle +// @Tags [MC-Infra] MCI Control lifecycle // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -73,7 +73,7 @@ func RestGetControlMci(c echo.Context) error { // @ID GetControlMciVm // @Summary Control the lifecycle of VM (suspend, resume, reboot, terminate) // @Description Control the lifecycle of VM (suspend, resume, reboot, terminate) -// @Tags [Infra service] MCI Control lifecycle +// @Tags [MC-Infra] MCI Control lifecycle // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) diff --git a/src/api/rest/server/mci/manageInfo.go b/src/api/rest/server/mci/manageInfo.go index e6414f0b5..33ad3a109 100644 --- a/src/api/rest/server/mci/manageInfo.go +++ b/src/api/rest/server/mci/manageInfo.go @@ -38,7 +38,7 @@ type JSONResult struct { // @ID GetMci // @Summary Get MCI object (option: status, accessInfo, vmId) // @Description Get MCI object (option: status, accessInfo, vmId) -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -111,7 +111,7 @@ type RestGetAllMciStatusResponse struct { // @ID GetAllMci // @Summary List all MCIs or MCIs' ID // @Description List all MCIs or MCIs' ID -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -171,7 +171,7 @@ func RestGetAllMci(c echo.Context) error { // @ID PutMci // @Summary Update MCI // @Description Update MCI -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param mciInfo body TbMciInfo true "Details for an MCI object" @@ -188,7 +188,7 @@ func RestPutMci(c echo.Context) error { // @ID DelMci // @Summary Delete MCI // @Description Delete MCI -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -214,7 +214,7 @@ func RestDelMci(c echo.Context) error { // @ID DelAllMci // @Summary Delete all MCIs // @Description Delete all MCIs -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -241,7 +241,7 @@ func RestDelAllMci(c echo.Context) error { // @ID GetMciVm // @Summary Get VM in specified MCI // @Description Get VM in specified MCI -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -283,7 +283,7 @@ func RestGetMciVm(c echo.Context) error { // @ID PutSshKey // @Summary Update MCI // @Description Update MCI -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -303,7 +303,7 @@ func RestPutMciVm(c echo.Context) error { // @ID DelMciVm // @Summary Delete VM in specified MCI // @Description Delete VM in specified MCI -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -338,7 +338,7 @@ func RestDelMciVm(c echo.Context) error { // @ID GetMciGroupVms // @Summary List VMs with a SubGroup label in a specified MCI // @Description List VMs with a SubGroup label in a specified MCI -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -369,7 +369,7 @@ func RestGetMciGroupVms(c echo.Context) error { // @ID GetMciGroupIds // @Summary List SubGroup IDs in a specified MCI // @Description List SubGroup IDs in a specified MCI -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) diff --git a/src/api/rest/server/mci/monitoring.go b/src/api/rest/server/mci/monitoring.go index 8ccdafcb9..6b0f86b8a 100644 --- a/src/api/rest/server/mci/monitoring.go +++ b/src/api/rest/server/mci/monitoring.go @@ -26,7 +26,7 @@ import ( // @ID PostInstallMonitorAgentToMci // @Summary Install monitoring agent (CB-Dragonfly agent) to MCI // @Description Install monitoring agent (CB-Dragonfly agent) to MCI -// @Tags [Infra service] MCI Resource monitor (for developer) +// @Tags [MC-Infra] MCI Resource monitor (for developer) // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -57,7 +57,7 @@ func RestPostInstallMonitorAgentToMci(c echo.Context) error { // @ID PutMonitorAgentStatusInstalled // @Summary Set monitoring agent (CB-Dragonfly agent) installation status installed (for Windows VM only) // @Description Set monitoring agent (CB-Dragonfly agent) installation status installed (for Windows VM only) -// @Tags [Infra service] MCI Resource monitor (for developer) +// @Tags [MC-Infra] MCI Resource monitor (for developer) // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -90,7 +90,7 @@ func RestPutMonitorAgentStatusInstalled(c echo.Context) error { // @ID GetMonitorData // @Summary Get monitoring data of specified MCI for specified monitoring metric (cpu, memory, disk, network) // @Description Get monitoring data of specified MCI for specified monitoring metric (cpu, memory, disk, network) -// @Tags [Infra service] MCI Resource monitor (for developer) +// @Tags [MC-Infra] MCI Resource monitor (for developer) // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) diff --git a/src/api/rest/server/mci/orchestration.go b/src/api/rest/server/mci/orchestration.go index 1e00ffa60..0efc6d577 100644 --- a/src/api/rest/server/mci/orchestration.go +++ b/src/api/rest/server/mci/orchestration.go @@ -28,7 +28,7 @@ import ( // @ID PostMciPolicy // @Summary Create MCI Automation policy // @Description Create MCI Automation policy -// @Tags [Infra service] MCI Auto control policy management (WIP) +// @Tags [MC-Infra] MCI Auto control policy management (WIP) // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -59,7 +59,7 @@ func RestPostMciPolicy(c echo.Context) error { // @ID GetMciPolicy // @Summary Get MCI Policy // @Description Get MCI Policy -// @Tags [Infra service] MCI Auto control policy management (WIP) +// @Tags [MC-Infra] MCI Auto control policy management (WIP) // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -99,7 +99,7 @@ type RestGetAllMciPolicyResponse struct { // @ID GetAllMciPolicy // @Summary List all MCI policies // @Description List all MCI policies -// @Tags [Infra service] MCI Auto control policy management (WIP) +// @Tags [MC-Infra] MCI Auto control policy management (WIP) // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -132,7 +132,7 @@ func RestGetAllMciPolicy(c echo.Context) error { // @ID PutMciPolicy // @Summary Update MCI Policy // @Description Update MCI Policy -// @Tags [Infra service] MCI Auto control policy management (WIP) +// @Tags [MC-Infra] MCI Auto control policy management (WIP) // @Accept json // @Produce json // @Param mciInfo body MciPolicyInfo true "Details for an MCI Policy object" @@ -149,7 +149,7 @@ func RestPutMciPolicy(c echo.Context) error { // @ID DelMciPolicy // @Summary Delete MCI Policy // @Description Delete MCI Policy -// @Tags [Infra service] MCI Auto control policy management (WIP) +// @Tags [MC-Infra] MCI Auto control policy management (WIP) // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -174,7 +174,7 @@ func RestDelMciPolicy(c echo.Context) error { // @ID DelAllMciPolicy // @Summary Delete all MCI policies // @Description Delete all MCI policies -// @Tags [Infra service] MCI Auto control policy management (WIP) +// @Tags [MC-Infra] MCI Auto control policy management (WIP) // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) diff --git a/src/api/rest/server/mci/provisioning.go b/src/api/rest/server/mci/provisioning.go index a8bb901f8..854ecbd12 100644 --- a/src/api/rest/server/mci/provisioning.go +++ b/src/api/rest/server/mci/provisioning.go @@ -26,7 +26,7 @@ import ( // @ID PostMci // @Summary Create MCI // @Description Create MCI -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -56,7 +56,7 @@ func RestPostMci(c echo.Context) error { // @ID PostRegisterCSPNativeVM // @Summary Register existing VM in a CSP to Cloud-Barista MCI // @Description Register existing VM in a CSP to Cloud-Barista MCI -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -86,7 +86,7 @@ func RestPostRegisterCSPNativeVM(c echo.Context) error { // @ID PostSystemMci // @Summary Create System MCI Dynamically for Special Purpose in NS:system-purpose-common-ns // @Description Create System MCI Dynamically for Special Purpose -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param option query string false "Option for the purpose of system MCI" Enums(probe) @@ -114,7 +114,7 @@ func RestPostSystemMci(c echo.Context) error { // @ID PostMciDynamic // @Summary Create MCI Dynamically // @Description Create MCI Dynamically from common spec and image -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -147,7 +147,7 @@ func RestPostMciDynamic(c echo.Context) error { // @ID PostMciVmDynamic // @Summary Create VM Dynamically and add it to MCI // @Description Create VM Dynamically and add it to MCI -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -178,7 +178,7 @@ func RestPostMciVmDynamic(c echo.Context) error { // @ID PostMciDynamicCheckRequest // @Summary Check available ConnectionConfig list for creating MCI Dynamically // @Description Check available ConnectionConfig list before create MCI Dynamically from common spec and image -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param mciReq body MciConnectionConfigCandidatesReq true "Details for MCI dynamic request information" @@ -204,7 +204,7 @@ func RestPostMciDynamicCheckRequest(c echo.Context) error { // @ID PostMciVm // @Summary Create and add homogeneous VMs(subGroup) to a specified MCI (Set subGroupSize for multiple VMs) // @Description Create and add homogeneous VMs(subGroup) to a specified MCI (Set subGroupSize for multiple VMs) -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -234,7 +234,7 @@ func RestPostMciVm(c echo.Context) error { // @ID PostMciSubGroupScaleOut // @Summary ScaleOut subGroup in specified MCI // @Description ScaleOut subGroup in specified MCI -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) diff --git a/src/api/rest/server/mci/recommendation.go b/src/api/rest/server/mci/recommendation.go index ecbe19fe5..f9614060d 100644 --- a/src/api/rest/server/mci/recommendation.go +++ b/src/api/rest/server/mci/recommendation.go @@ -26,7 +26,7 @@ import ( // @ID RecommendVm // @Summary Recommend MCI plan (filter and priority) // @Description Recommend MCI plan (filter and priority) Find details from https://github.com/cloud-barista/cb-tumblebug/discussions/1234 -// @Tags [Infra service] MCI Provisioning management +// @Tags [MC-Infra] MCI Provisioning management // @Accept json // @Produce json // @Param deploymentPlan body mci.DeploymentPlan false "Recommend MCI plan (filter and priority)" @@ -62,7 +62,7 @@ type RestPostMciRecommendResponse struct { // func RestPostMciRecommend(c echo.Context) error { // // @Summary Get MCI recommendation // // @Description Get MCI recommendation -// // @Tags [Infra service] MCI Provisioning management +// // @Tags [MC-Infra] MCI Provisioning management // // @Accept json // // @Produce json // // @Param nsId path string true "Namespace ID" default(ns01) diff --git a/src/api/rest/server/mci/remoteCommand.go b/src/api/rest/server/mci/remoteCommand.go index c718c045c..2208247d5 100644 --- a/src/api/rest/server/mci/remoteCommand.go +++ b/src/api/rest/server/mci/remoteCommand.go @@ -26,7 +26,7 @@ import ( // @ID PostCmdMci // @Summary Send a command to specified MCI // @Description Send a command to specified MCI -// @Tags [Infra service] MCI Remote command +// @Tags [MC-Infra] MCI Remote command // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -79,7 +79,7 @@ func RestPostCmdMci(c echo.Context) error { // @ID SetBastionNodes // @Summary Set bastion nodes for a VM // @Description Set bastion nodes for a VM -// @Tags [Infra service] MCI Remote command +// @Tags [MC-Infra] MCI Remote command // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -108,7 +108,7 @@ func RestSetBastionNodes(c echo.Context) error { // @ID GetBastionNodes // @Summary Get bastion nodes for a VM // @Description Get bastion nodes for a VM -// @Tags [Infra service] MCI Remote command +// @Tags [MC-Infra] MCI Remote command // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -135,7 +135,7 @@ func RestGetBastionNodes(c echo.Context) error { // @ID RemoveBastionNodes // @Summary Remove a bastion VM from all vNets // @Description Remove a bastion VM from all vNets -// @Tags [Infra service] MCI Remote command +// @Tags [MC-Infra] MCI Remote command // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) diff --git a/src/api/rest/server/mcir/spec.go b/src/api/rest/server/mcir/spec.go index 4e3c6f156..4a5691e04 100644 --- a/src/api/rest/server/mcir/spec.go +++ b/src/api/rest/server/mcir/spec.go @@ -288,31 +288,6 @@ func RestGetSpec(c echo.Context) error { return common.EndRequestWithLog(c, reqID, err, result) } -// Response structure for RestGetAllSpec -type RestGetAllSpecResponse struct { - Spec []mcir.TbSpecInfo `json:"spec"` -} - -// RestGetAllSpec godoc -// @ID GetAllSpec -// @Summary List all specs or specs' ID -// @Description List all specs or specs' ID -// @Tags [Infra resource] MCIR Spec management -// @Accept json -// @Produce json -// @Param nsId path string true "Namespace ID" default(system-purpose-common-ns) -// @Param option query string false "Option" Enums(id) -// @Param filterKey query string false "Field key for filtering (ex: providerName)" -// @Param filterVal query string false "Field value for filtering (ex: aws)" -// @Success 200 {object} JSONResult{[DEFAULT]=RestGetAllSpecResponse,[ID]=common.IdList} "Different return structures by the given option param" -// @Failure 404 {object} common.SimpleMsg -// @Failure 500 {object} common.SimpleMsg -// @Router /ns/{nsId}/resources/spec [get] -func RestGetAllSpec(c echo.Context) error { - // This is a dummy function for Swagger. - return nil -} - // RestDelSpec godoc // @ID DelSpec // @Summary Delete spec @@ -329,20 +304,3 @@ func RestDelSpec(c echo.Context) error { // This is a dummy function for Swagger. return nil } - -// RestDelAllSpec godoc -// @ID DelAllSpec -// @Summary Delete all specs -// @Description Delete all specs -// @Tags [Infra resource] MCIR Spec management -// @Accept json -// @Produce json -// @Param nsId path string true "Namespace ID" default(ns01) -// @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}/resources/spec [delete] -func RestDelAllSpec(c echo.Context) error { - // This is a dummy function for Swagger. - return nil -} diff --git a/src/api/rest/server/server.go b/src/api/rest/server/server.go index 2605c93fe..06e43938c 100644 --- a/src/api/rest/server/server.go +++ b/src/api/rest/server/server.go @@ -420,10 +420,8 @@ func RunServer(port string) { g.POST("/:nsId/resources/spec", rest_mcir.RestPostSpec) g.GET("/:nsId/resources/spec/:resourceId", rest_mcir.RestGetSpec) - g.GET("/:nsId/resources/spec", rest_mcir.RestGetAllResources) g.PUT("/:nsId/resources/spec/:resourceId", rest_mcir.RestPutSpec) g.DELETE("/:nsId/resources/spec/:resourceId", rest_mcir.RestDelResource) - g.DELETE("/:nsId/resources/spec", rest_mcir.RestDelAllResources) g.POST("/:nsId/resources/fetchSpecs", rest_mcir.RestFetchSpecs) g.POST("/:nsId/resources/filterSpecsByRange", rest_mcir.RestFilterSpecsByRange) diff --git a/src/core/mcir/image.go b/src/core/mcir/image.go index 76dbbdd98..ad7894cab 100644 --- a/src/core/mcir/image.go +++ b/src/core/mcir/image.go @@ -19,6 +19,7 @@ import ( "fmt" "net/url" "strconv" + "strings" "time" "github.com/go-resty/resty/v2" @@ -519,7 +520,7 @@ func UpdateImage(nsId string, imageId string, fieldsToUpdate TbImageInfo, RDBonl return fieldsToUpdate, nil } -// GetImage accepts namespace ID and imageKey(id,name,type,...), and returns the TB image object +// GetImage accepts namespace Id and imageKey(Id,CspImageId,GuestOS,...), and returns the TB image object func GetImage(nsId string, imageKey string) (TbImageInfo, error) { if err := common.CheckString(nsId); err != nil { log.Error().Err(err).Msg("Invalid namespace ID") @@ -528,9 +529,13 @@ func GetImage(nsId string, imageKey string) (TbImageInfo, error) { log.Debug().Msg("[Get image] " + imageKey) + // make comparison case-insensitive + nsId = strings.ToLower(nsId) + imageKey = strings.ToLower(imageKey) + // ex: tencent+ap-jakarta+ubuntu22.04 image := TbImageInfo{Namespace: nsId, Id: imageKey} - has, err := common.ORM.Where("Namespace = ? AND Id = ?", nsId, imageKey).Get(&image) + has, err := common.ORM.Where("LOWER(Namespace) = ? AND LOWER(Id) = ?", nsId, imageKey).Get(&image) if err != nil { log.Info().Err(err).Msgf("Failed to get image %s by ID", imageKey) } @@ -540,7 +545,7 @@ func GetImage(nsId string, imageKey string) (TbImageInfo, error) { // ex: img-487zeit5 image = TbImageInfo{Namespace: nsId, CspImageId: imageKey} - has, err = common.ORM.Where("Namespace = ? AND CspImageId = ?", nsId, imageKey).Get(&image) + has, err = common.ORM.Where("LOWER(Namespace) = ? AND LOWER(CspImageId) = ?", nsId, imageKey).Get(&image) if err != nil { log.Info().Err(err).Msgf("Failed to get image %s by CspImageId", imageKey) } @@ -550,7 +555,7 @@ func GetImage(nsId string, imageKey string) (TbImageInfo, error) { // ex: Ubuntu22.04 image = TbImageInfo{Namespace: nsId, GuestOS: imageKey} - has, err = common.ORM.Where("Namespace = ? AND GuestOS = ?", nsId, imageKey).Get(&image) + has, err = common.ORM.Where("LOWER(Namespace) = ? AND LOWER(GuestOS) LIKE ?", nsId, imageKey).Get(&image) if err != nil { log.Info().Err(err).Msgf("Failed to get image %s by GuestOS type", imageKey) } diff --git a/src/core/mcir/spec.go b/src/core/mcir/spec.go index 3bca459f8..e56bf93f0 100644 --- a/src/core/mcir/spec.go +++ b/src/core/mcir/spec.go @@ -429,27 +429,40 @@ type Range struct { Max float32 `json:"max"` } -// GetSpec accepts namespace ID and spec ID, and returns the TB spec object -func GetSpec(nsId string, specId string) (TbSpecInfo, error) { +// GetSpec accepts namespace Id and specKey(Id,CspImageId,...), and returns the TB spec object +func GetSpec(nsId string, specKey string) (TbSpecInfo, error) { if err := common.CheckString(nsId); err != nil { log.Error().Err(err).Msg("Invalid namespace ID") return TbSpecInfo{}, err } - log.Debug().Msg("[Get spec]" + specId) + log.Debug().Msg("[Get spec] " + specKey) - spec := TbSpecInfo{Namespace: nsId, Id: specId} - has, err := common.ORM.Where("Namespace = ? AND Id = ?", nsId, specId).Get(&spec) + // make comparison case-insensitive + nsId = strings.ToLower(nsId) + specKey = strings.ToLower(specKey) + + // ex: tencent+ap-jakarta+ubuntu22.04 + spec := TbSpecInfo{Namespace: nsId, Id: specKey} + has, err := common.ORM.Where("LOWER(Namespace) = ? AND LOWER(Id) = ?", nsId, specKey).Get(&spec) if err != nil { - log.Error().Err(err).Msgf("Failed to get spec %s", specId) - return TbSpecInfo{}, err + log.Info().Err(err).Msgf("Failed to get spec %s by ID", specKey) + } + if has { + return spec, nil } - if !has { - return TbSpecInfo{}, fmt.Errorf("spec with ID %s not found", specId) + // ex: img-487zeit5 + spec = TbSpecInfo{Namespace: nsId, CspSpecName: specKey} + has, err = common.ORM.Where("LOWER(Namespace) = ? AND LOWER(CspSpecName) = ?", nsId, specKey).Get(&spec) + if err != nil { + log.Info().Err(err).Msgf("Failed to get spec %s by CspSpecName", specKey) + } + if has { + return spec, nil } - return spec, nil + return TbSpecInfo{}, fmt.Errorf("The specKey %s not found by any of ID, CspSpecName", specKey) } // FilterSpecsByRange accepts criteria ranges for filtering, and returns the list of filtered TB spec objects