Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance RegisterCspNativeResourcesAll mechanism #1092

Merged
merged 6 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/runMapUI.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

CONTAINER_NAME_READ="CB-MapUI"
CONTAINER_VERSION="0.5.1"
CONTAINER_VERSION="0.5.2"
CONTAINER_PORT="-p 1324:1324"
CONTAINER_DATA_PATH=""

Expand Down
20 changes: 15 additions & 5 deletions src/api/rest/server/common/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func RestInspectResources(c echo.Context) error {
type RestRegisterCspNativeResourcesRequest struct {
ConnectionName string `json:"connectionName" example:"aws-ap-southeast-1"`
NsId string `json:"nsId" example:"ns01"`
McisName string `json:"mcisName" example:"mcis-csp-native"`
McisName string `json:"mcisName" example:"csp"`
}

// RestRegisterCspNativeResources godoc
Expand All @@ -385,7 +385,8 @@ type RestRegisterCspNativeResourcesRequest struct {
// @Tags [Admin] System management
// @Accept json
// @Produce json
// @Param Request body RestRegisterCspNativeResourcesRequest true "Specify connectionName and NS Id"
// @Param Request body RestRegisterCspNativeResourcesRequest true "Specify connectionName, NS Id, and MCIS Name""
// @Param option query string false "Option to specify resourceType" Enums(onlyVm, exceptVm)
// @Success 200 {object} mcis.RegisterResourceResult
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
Expand All @@ -396,8 +397,9 @@ func RestRegisterCspNativeResources(c echo.Context) error {
if err := c.Bind(u); err != nil {
return err
}
option := c.QueryParam("option")

content, err := mcis.RegisterCspNativeResources(u.NsId, u.ConnectionName, u.McisName)
content, err := mcis.RegisterCspNativeResources(u.NsId, u.ConnectionName, u.McisName, option)

if err != nil {
common.CBLog.Error(err)
Expand All @@ -409,13 +411,20 @@ func RestRegisterCspNativeResources(c echo.Context) error {

}

// Request struct for RestRegisterCspNativeResources
type RestRegisterCspNativeResourcesRequestAll struct {
NsId string `json:"nsId" example:"ns01"`
McisName string `json:"mcisName" example:"csp"`
}

// RestRegisterCspNativeResourcesAll godoc
// @Summary Register CSP Native Resources (vNet, securityGroup, sshKey, vm) from all Clouds to CB-Tumblebug
// @Description Register CSP Native Resources (vNet, securityGroup, sshKey, vm) from all Clouds to CB-Tumblebug
// @Tags [Admin] System management
// @Accept json
// @Produce json
// @Param Request body RestRegisterCspNativeResourcesRequest true "Specify NS Id and MCIS Name"
// @Param Request body RestRegisterCspNativeResourcesRequestAll true "Specify NS Id and MCIS Name"
// @Param option query string false "Option to specify resourceType" Enums(onlyVm, exceptVm)
// @Success 200 {object} mcis.RegisterResourceAllResult
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
Expand All @@ -426,8 +435,9 @@ func RestRegisterCspNativeResourcesAll(c echo.Context) error {
if err := c.Bind(u); err != nil {
return err
}
option := c.QueryParam("option")

content, err := mcis.RegisterCspNativeResourcesAll(u.NsId, u.McisName)
content, err := mcis.RegisterCspNativeResourcesAll(u.NsId, u.McisName, option)

if err != nil {
common.CBLog.Error(err)
Expand Down
10 changes: 8 additions & 2 deletions src/core/common/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ func GenUid() string {
return uid.New().String()
}

// RandomSleep is func to make a caller waits for during random time seconds
func RandomSleep(t int) {
// RandomSleep is func to make a caller waits for during random time seconds (random value within x~y)
func RandomSleep(from int, to int) {
if from > to {
tmp := from
from = to
to = tmp
}
t := to - from
rand.Seed(time.Now().UnixNano())
n := rand.Intn(t * 1000)
time.Sleep(time.Duration(n) * time.Millisecond)
Expand Down
6 changes: 3 additions & 3 deletions src/core/mcir/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ func ListResource(nsId string, resourceType string) (interface{}, error) {
return nil, err
}

fmt.Println("[Get " + resourceType + " list")
fmt.Println("[Get] " + resourceType + " list")
key := "/ns/" + nsId + "/resources/" + resourceType
fmt.Println(key)

Expand Down Expand Up @@ -1365,7 +1365,7 @@ func LoadCommonResource() (common.IdList, error) {
go func(i int, row []string) {
defer wait.Done()
// RandomSleep for safe parallel executions
common.RandomSleep(20)
common.RandomSleep(0, 20)
specReqTmp := TbSpecReq{}
// [0]connectionName, [1]cspSpecName, [2]CostPerHour, [3]evaluationScore01, ..., [12]evaluationScore10
specReqTmp.ConnectionName = row[2]
Expand Down Expand Up @@ -1470,7 +1470,7 @@ func LoadCommonResource() (common.IdList, error) {
go func(i int, row []string) {
defer wait.Done()
// RandomSleep for safe parallel executions
common.RandomSleep(20)
common.RandomSleep(0, 20)
imageReqTmp := TbImageReq{}
// row0: ProviderName
// row1: connectionName
Expand Down
24 changes: 13 additions & 11 deletions src/core/mcir/securitygroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,21 @@ func CreateSecurityGroup(nsId string, u *TbSecurityGroupReq, option string) (TbS
tempReq.ReqInfo.CSPId = u.CspSecurityGroupId

// tempReq.ReqInfo.SecurityRules = u.FirewallRules
for _, v := range *u.FirewallRules {
jsonBody, err := json.Marshal(v)
if err != nil {
common.CBLog.Error(err)
}
if u.FirewallRules != nil {
for _, v := range *u.FirewallRules {
jsonBody, err := json.Marshal(v)
if err != nil {
common.CBLog.Error(err)
}

spiderSecurityRuleInfo := SpiderSecurityRuleInfo{}
err = json.Unmarshal(jsonBody, &spiderSecurityRuleInfo)
if err != nil {
common.CBLog.Error(err)
}
spiderSecurityRuleInfo := SpiderSecurityRuleInfo{}
err = json.Unmarshal(jsonBody, &spiderSecurityRuleInfo)
if err != nil {
common.CBLog.Error(err)
}

tempReq.ReqInfo.SecurityRules = append(tempReq.ReqInfo.SecurityRules, spiderSecurityRuleInfo)
tempReq.ReqInfo.SecurityRules = append(tempReq.ReqInfo.SecurityRules, spiderSecurityRuleInfo)
}
}

var tempSpiderSecurityInfo *SpiderSecurityInfo
Expand Down
2 changes: 1 addition & 1 deletion src/core/mcis/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ func CreateVm(nsId string, mcisId string, vmInfoData *TbVmInfo, option string) e
payload, _ := json.Marshal(tempReq)

// Randomly sleep within 30 Secs to avoid rateLimit from CSP
common.RandomSleep(30)
common.RandomSleep(0, 30)

// Call cb-spider API by REST or gRPC
if os.Getenv("SPIDER_CALL_METHOD") == "REST" {
Expand Down
Loading