Skip to content

Commit

Permalink
Register all specs and update asset spec
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-github-robot committed Aug 7, 2024
2 parents c030ae3 + 9ad0c2f commit 0e12098
Show file tree
Hide file tree
Showing 5 changed files with 290 additions and 312 deletions.
17 changes: 14 additions & 3 deletions src/api/rest/server/mcir/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func RestPutSpec(c echo.Context) error {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
nsId := c.Param("nsId")
specId := c.Param("specId")
specId := c.Param("resourceId")
specId = strings.ReplaceAll(specId, " ", "+")
specId = strings.ReplaceAll(specId, "%2B", "+")

Expand Down Expand Up @@ -273,8 +273,19 @@ func RestFilterSpecsByRange(c echo.Context) error {
// @Failure 500 {object} common.SimpleMsg
// @Router /ns/{nsId}/resources/spec/{specId} [get]
func RestGetSpec(c echo.Context) error {
// This is a dummy function for Swagger.
return nil
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")
// make " " and "+" to be "+" (web utilizes "+" for " " in URL)
specId = strings.ReplaceAll(specId, " ", "+")
specId = strings.ReplaceAll(specId, "%2B", "+")

log.Debug().Msg("[Get spec]" + specId)
result, err := mcir.GetSpec(nsId, specId)
return common.EndRequestWithLog(c, reqID, err, result)
}

// Response structure for RestGetAllSpec
Expand Down
2 changes: 1 addition & 1 deletion src/api/rest/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ func RunServer(port string) {
g.DELETE("/:nsId/resources/sshKey", rest_mcir.RestDelAllResources)

g.POST("/:nsId/resources/spec", rest_mcir.RestPostSpec)
g.GET("/:nsId/resources/spec/:resourceId", rest_mcir.RestGetResource)
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)
Expand Down
62 changes: 45 additions & 17 deletions src/core/mcir/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1452,10 +1452,26 @@ func LoadCommonResource() (common.IdList, error) {
log.Info().Msgf("[%s] #Spec: %d", connConfig.ConfigName, len(specsInConnection.Vmspec))
validRepresentativeConnectionMap.Store(connConfig.ProviderName+"-"+connConfig.RegionDetail.RegionName, connConfig)
for _, spec := range specsInConnection.Vmspec {
key := GetProviderRegionZoneResourceKey(connConfig.ProviderName, connConfig.RegionDetail.RegionName, "", spec.Name)
// instead of connConfig.RegionName, spec.Region will be used in the future
//log.Info().Msgf("specMap.Store(%s, spec)", key)
specMap.Store(key, spec)
spiderSpec := spec
//log.Info().Msgf("Found spec in the map: %s", spiderSpec.Name)
tumblebugSpec, errConvert := ConvertSpiderSpecToTumblebugSpec(spiderSpec)
if errConvert != nil {
log.Error().Err(errConvert).Msg("Cannot ConvertSpiderSpecToTumblebugSpec")
} else {
key := GetProviderRegionZoneResourceKey(connConfig.ProviderName, connConfig.RegionDetail.RegionName, "", spec.Name)
tumblebugSpec.Name = key
tumblebugSpec.ConnectionName = connConfig.ConfigName
tumblebugSpec.ProviderName = strings.ToLower(connConfig.ProviderName)
tumblebugSpec.RegionName = connConfig.RegionDetail.RegionName
tumblebugSpec.InfraType = "vm" // default value
tumblebugSpec.SystemLabel = "auto-gen"
tumblebugSpec.CostPerHour = 99999999.9
tumblebugSpec.EvaluationScore01 = -99.9

// instead of connConfig.RegionName, spec.Region will be used in the future
//log.Info().Msgf("specMap.Store(%s, spec)", key)
specMap.Store(key, tumblebugSpec)
}
}
}(connConfig)
}
Expand All @@ -1482,6 +1498,17 @@ func LoadCommonResource() (common.IdList, error) {

log.Info().Msgf("LookupSpecList in parallel: %s", totalDuration)

specMap.Range(func(key, value interface{}) bool {
specInfo := value.(TbSpecInfo)
//log.Info().Msgf("specMap.Range: %s value: %v", key, specInfo)

_, errRegisterSpec := RegisterSpecWithInfo(common.SystemCommonNs, &specInfo, true)
if errRegisterSpec != nil {
log.Info().Err(errRegisterSpec).Msg("RegisterSpec WithInfo failed")
}
return true
})

// Read common specs and register spec objects
file, fileErr := os.Open("../assets/cloudspec.csv")
defer file.Close()
Expand Down Expand Up @@ -1622,21 +1649,21 @@ func LoadCommonResource() (common.IdList, error) {

// Register Spec object
searchKey := GetProviderRegionZoneResourceKey(providerName, regionName, "", specReqTmp.CspSpecName)
value, ok := specMap.Load(searchKey)
_, ok := specMap.Load(searchKey)
if ok {
spiderSpec := value.(SpiderSpecInfo)
//log.Info().Msgf("Found spec in the map: %s", spiderSpec.Name)
tumblebugSpec, errConvert := ConvertSpiderSpecToTumblebugSpec(spiderSpec)
if errConvert != nil {
log.Error().Err(errConvert).Msg("Cannot ConvertSpiderSpecToTumblebugSpec")
}
// spiderSpec := value.(SpiderSpecInfo)
// //log.Info().Msgf("Found spec in the map: %s", spiderSpec.Name)
// tumblebugSpec, errConvert := ConvertSpiderSpecToTumblebugSpec(spiderSpec)
// if errConvert != nil {
// log.Error().Err(errConvert).Msg("Cannot ConvertSpiderSpecToTumblebugSpec")
// }

tumblebugSpec.Name = specInfoId
tumblebugSpec.ConnectionName = specReqTmp.ConnectionName
_, errRegisterSpec = RegisterSpecWithInfo(common.SystemCommonNs, &tumblebugSpec, true)
if errRegisterSpec != nil {
log.Info().Err(errRegisterSpec).Msg("RegisterSpec WithInfo failed")
}
// tumblebugSpec.Name = specInfoId
// tumblebugSpec.ConnectionName = specReqTmp.ConnectionName
// // _, errRegisterSpec = RegisterSpecWithInfo(common.SystemCommonNs, &tumblebugSpec, true)
// // if errRegisterSpec != nil {
// // log.Info().Err(errRegisterSpec).Msg("RegisterSpec WithInfo failed")
// // }

} else {
errRegisterSpec = fmt.Errorf("Not Found spec from the fetched spec list: %s", searchKey)
Expand Down Expand Up @@ -1676,6 +1703,7 @@ func LoadCommonResource() (common.IdList, error) {
AcceleratorMemoryGB: float32(acceleratorMemoryGB),
Description: description,
EvaluationScore01: float32(evaluationScore01),
SystemLabel: "from-assets",
InfraType: expandedInfraType,
}

Expand Down
Loading

0 comments on commit 0e12098

Please sign in to comment.