Skip to content

Commit

Permalink
Merge pull request #1086 from seokho-son/main
Browse files Browse the repository at this point in the history
Temporal removal of GCP from RegisterCspResAll and hotfix
  • Loading branch information
jihoon-seo authored May 3, 2022
2 parents 3b9124a + 5fd10d9 commit 2d40715
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
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

}

0 comments on commit 2d40715

Please sign in to comment.