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

Temporal removal of GCP from RegisterCspResAll and hotfix #1086

Merged
merged 2 commits into from
May 3, 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
9 changes: 5 additions & 4 deletions src/core/mcir/securitygroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,18 @@ func CreateSecurityGroup(nsId string, u *TbSecurityGroupReq, option string) (TbS
// Assign random temporal ID to u.VNetId
if option == "register" && u.VNetId == "not defined" {
resourceList, err := ListResource(nsId, common.StrVNet)
var content struct {
VNet []TbVNetInfo `json:"vNet"`
}
content.VNet = resourceList.([]TbVNetInfo) // type assertion (interface{} -> array)

if err != nil {
common.CBLog.Error(err)
err := fmt.Errorf("Cannot ListResourceId securityGroup")
return TbSecurityGroupInfo{}, err
}

var content struct {
VNet []TbVNetInfo `json:"vNet"`
}
content.VNet = resourceList.([]TbVNetInfo) // type assertion (interface{} -> array)

if len(content.VNet) == 0 {
errString := "There is no " + common.StrVNet + " resource in " + nsId
err := fmt.Errorf(errString)
Expand Down
26 changes: 24 additions & 2 deletions src/core/mcis/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,16 +592,23 @@ func RegisterCspNativeResourcesAll(nsId string, mcisId string) (RegisterResource
common.CBLog.Error(err)
return RegisterResourceAllResult{}, err
}
refinedConnectionConfigList := common.ConnConfigList{}
for _, k := range connectionConfigList.Connectionconfig {
if !strings.Contains(k.ConfigName, "gcp") {
refinedConnectionConfigList.Connectionconfig = append(refinedConnectionConfigList.Connectionconfig, k)
}
}

output := RegisterResourceAllResult{}

var wait sync.WaitGroup
for _, k := range connectionConfigList.Connectionconfig {
for _, k := range refinedConnectionConfigList.Connectionconfig {
wait.Add(1)
go func(k common.ConnConfig) {
defer wait.Done()

mcisNameForRegister := mcisId + "-" + k.ConfigName

//common.RandomSleep(300)
registerResult, err := RegisterCspNativeResources(nsId, k.ConfigName, mcisNameForRegister)
if err != nil {
common.CBLog.Error(err)
Expand All @@ -624,6 +631,8 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string) (
registeredStatus := ""
result := RegisterResourceResult{}

startTime01 := time.Now() //tmp

// bring vNet list and register all
inspectedResources, err := InspectResources(connConfig, common.StrVNet)
if err != nil {
Expand Down Expand Up @@ -651,6 +660,9 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string) (
result.RegisterationOverview.VNet++
}

fmt.Printf("\n\n%s [Elapsed]%s %d \n\n", connConfig, common.StrVNet, int(math.Round(time.Now().Sub(startTime01).Seconds()))) //tmp
startTime02 := time.Now() //tmp

// bring SecurityGroup list and register all
inspectedResources, err = InspectResources(connConfig, common.StrSecurityGroup)
if err != nil {
Expand Down Expand Up @@ -679,6 +691,9 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string) (
result.RegisterationOverview.SecurityGroup++
}

fmt.Printf("\n\n%s [Elapsed]%s %d \n\n", connConfig, common.StrSecurityGroup, int(math.Round(time.Now().Sub(startTime02).Seconds()))) //tmp
startTime03 := time.Now() //tmp

// bring SSHKey list and register all
inspectedResources, err = InspectResources(connConfig, common.StrSSHKey)
if err != nil {
Expand Down Expand Up @@ -711,6 +726,9 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string) (
result.RegisterationOverview.SshKey++
}

fmt.Printf("\n\n%s [Elapsed]%s %d \n\n", connConfig, common.StrSSHKey, int(math.Round(time.Now().Sub(startTime03).Seconds()))) //tmp
startTime04 := time.Now() //tmp

// bring VM list and register all
inspectedResources, err = InspectResources(connConfig, common.StrVM)
if err != nil {
Expand Down Expand Up @@ -756,6 +774,10 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string) (
result.ConnectionName = connConfig
result.ElapsedTime = int(math.Round(time.Now().Sub(startTime).Seconds()))

fmt.Printf("\n\n%s [Elapsed]%s %d \n\n", connConfig, common.StrVM, int(math.Round(time.Now().Sub(startTime04).Seconds()))) //tmp

fmt.Printf("\n\n%s [Elapsed]Total %d \n\n", connConfig, int(math.Round(time.Now().Sub(startTime).Seconds())))

return result, err

}