Skip to content

Commit

Permalink
Simplify ID system using GenUid and no Transform
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-github-robot authored Aug 19, 2024
2 parents da7bbfe + 64429a4 commit aef942b
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 201 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ services:
# - API_PASSWORD=
- SPIDER_LOG_LEVEL=error
- SPIDER_HISCALL_LOG_LEVEL=error
- ID_TRANSFORM_MODE=ON
- ID_TRANSFORM_MODE=OFF
healthcheck: # for CB-Spider
test: [ "CMD", "curl", "-f", "http://localhost:1024/spider/readyz" ]
interval: 1m
Expand Down
48 changes: 25 additions & 23 deletions src/api/rest/server/mcir/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,33 @@ func RestDelResource(c echo.Context) error {
return common.EndRequestWithLog(c, reqID, err, content)
}

// Todo: need to reimplment the following invalid function

// 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, 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]
// c.Path(): /tumblebug/ns/:nsId/resources/vNet/:vNetId/subnet/:subnetId

parentResourceId := c.Param("parentResourceId")
childResourceId := c.Param("childResourceId")
parentResourceId = strings.ReplaceAll(parentResourceId, " ", "+")
parentResourceId = strings.ReplaceAll(parentResourceId, "%2B", "+")
childResourceId = strings.ReplaceAll(childResourceId, " ", "+")
childResourceId = strings.ReplaceAll(childResourceId, "%2B", "+")

forceFlag := c.QueryParam("force")

err := mcir.DelChildResource(nsId, childResourceType, parentResourceId, childResourceId, forceFlag)
content := map[string]string{"message": "The " + childResourceType + " " + childResourceId + " has been deleted"}
return common.EndRequestWithLog(c, reqID, err, content)
}
// func RestDelChildResource(c echo.Context) error {
// 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]
// // c.Path(): /tumblebug/ns/:nsId/resources/vNet/:vNetId/subnet/:subnetId

// parentResourceId := c.Param("parentResourceId")
// childResourceId := c.Param("childResourceId")
// parentResourceId = strings.ReplaceAll(parentResourceId, " ", "+")
// parentResourceId = strings.ReplaceAll(parentResourceId, "%2B", "+")
// childResourceId = strings.ReplaceAll(childResourceId, " ", "+")
// childResourceId = strings.ReplaceAll(childResourceId, "%2B", "+")

// forceFlag := c.QueryParam("force")

// err := mcir.DelChildResource(nsId, childResourceType, parentResourceId, childResourceId, forceFlag)
// content := map[string]string{"message": "The " + childResourceType + " " + childResourceId + " has been deleted"}
// return common.EndRequestWithLog(c, reqID, err, content)
// }

// RestGetAllResources is a common function to handle 'GetAllResources' REST API requests.
// Dummy functions for Swagger exist in [mcir/*.go]
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 @@ -450,7 +450,7 @@ func RunServer(port string) {
// g.GET("/:nsId/resources/vNet/:vNetId/subnet/:subnetId", rest_mcir.RestGetSubnet)
// g.GET("/:nsId/resources/vNet/:vNetId/subnet", rest_mcir.RestGetAllSubnet)
// g.PUT("/:nsId/resources/vNet/:vNetId/subnet/:subnetId", rest_mcir.RestPutSubnet)
g.DELETE("/:nsId/resources/vNet/:parentResourceId/subnet/:childResourceId", rest_mcir.RestDelChildResource)
// g.DELETE("/:nsId/resources/vNet/:parentResourceId/subnet/:childResourceId", rest_mcir.RestDelChildResource)
// g.DELETE("/:nsId/resources/vNet/:vNetId/subnet", rest_mcir.RestDelAllSubnet)

/*
Expand Down
8 changes: 3 additions & 5 deletions src/core/mci/k8scluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,6 @@ func CreateK8sCluster(nsId string, u *TbK8sClusterReq, option string) (TbK8sClus
* Build RequestBody for SpiderClusterReq{}
*/

spName := fmt.Sprintf("%s-%s", nsId, u.Id)

// Validate
err = validateAtCreateK8sCluster(u)
if err != nil {
Expand Down Expand Up @@ -605,7 +603,7 @@ func CreateK8sCluster(nsId string, u *TbK8sClusterReq, option string) (TbK8sClus
}

spNodeGroupList = append(spNodeGroupList, SpiderNodeGroupReqInfo{
Name: v.Name,
Name: common.GenUid(),
ImageName: spImgName,
VMSpecName: spSpecName,
RootDiskType: v.RootDiskType,
Expand All @@ -622,7 +620,7 @@ func CreateK8sCluster(nsId string, u *TbK8sClusterReq, option string) (TbK8sClus
NameSpace: "", // should be empty string from Tumblebug
ConnectionName: u.ConnectionName,
ReqInfo: SpiderClusterReqInfo{
Name: spName,
Name: common.GenUid(),
Version: spVersion,
VPCName: spVPCName,
SubnetNames: spSubnetNames,
Expand Down Expand Up @@ -1210,7 +1208,7 @@ func GetK8sCluster(nsId string, k8sClusterId string) (TbK8sClusterInfo, error) {

client := resty.New()
client.SetTimeout(10 * time.Minute)
url := common.SpiderRestUrl + "/cluster/" + nsId + "-" + k8sClusterId
url := common.SpiderRestUrl + "/cluster/" + storedTbK8sCInfo.CspK8sClusterName
method := "GET"

// Create Request body for GetK8sCluster of CB-Spider
Expand Down
6 changes: 4 additions & 2 deletions src/core/mci/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -1657,8 +1657,7 @@ func CreateVm(nsId string, mciId string, vmInfoData *TbVmInfo, option string) er
requestBody.ConnectionName = vmInfoData.ConnectionName

//generate VM ID(Name) to request to CSP(Spider)
//combination of nsId, mcidId, and vmName reqested from user
requestBody.ReqInfo.Name = fmt.Sprintf("%s-%s-%s", nsId, mciId, vmInfoData.Name)
requestBody.ReqInfo.Name = common.GenUid()

customImageFlag := false

Expand Down Expand Up @@ -1771,6 +1770,9 @@ func CreateVm(nsId string, mciId string, vmInfoData *TbVmInfo, option string) er
}
}

log.Info().Msg("VM request body to CB-Spider")
common.PrintJsonPretty(requestBody)

// Randomly sleep within 20 Secs to avoid rateLimit from CSP
common.RandomSleep(0, 20)
client := resty.New()
Expand Down
2 changes: 1 addition & 1 deletion src/core/mci/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func CreateVmSnapshot(nsId string, mciId string, vmId string, snapshotName strin
json.Unmarshal([]byte(keyValue.Value), &vm)

if snapshotName == "" {
snapshotName = fmt.Sprintf("%s-%s", vm.Name, common.GenerateNewRandomString(5))
snapshotName = common.GenUid()
}

requestBody := mcir.SpiderMyImageReq{
Expand Down
Loading

0 comments on commit aef942b

Please sign in to comment.