From 670b055efc81ab2fd0194a42aff0b9489f559536 Mon Sep 17 00:00:00 2001 From: ioito Date: Tue, 23 Jul 2019 21:02:52 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=AE=89=E5=85=A8=E7=BB=84=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/compute/models/cloudsync.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/compute/models/cloudsync.go b/pkg/compute/models/cloudsync.go index cf038c8cc0..f1b629d12f 100644 --- a/pkg/compute/models/cloudsync.go +++ b/pkg/compute/models/cloudsync.go @@ -213,6 +213,13 @@ func syncVpcSecGroup(ctx context.Context, userCred mcclient.TokenCredential, syn _, _, result := SecurityGroupCacheManager.SyncSecurityGroupCaches(ctx, userCred, provider, secgroups, localVpc) syncResults.Add(SecurityGroupCacheManager, result) + + msg := result.Result() + notes := fmt.Sprintf("SyncSecurityGroupCaches for VPC %s result: %s", localVpc.Name, msg) + log.Infof(notes) + if result.IsError() { + return + } } func syncVpcRouteTables(ctx context.Context, userCred mcclient.TokenCredential, syncResults SSyncResultSet, provider *SCloudprovider, localVpc *SVpc, remoteVpc cloudprovider.ICloudVpc, syncRange *SSyncRange) { From 81e94b11a4bfa5c42b6877eacedc2f7a20fbaddf Mon Sep 17 00:00:00 2001 From: ioito Date: Tue, 23 Jul 2019 21:43:01 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=81=BF=E5=85=8D=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=90=8C=E4=B8=80vpc=E5=BA=95=E4=B8=8B?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E5=AE=89=E5=85=A8=E7=BB=84externalId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/compute/models/secgroupcache.go | 32 +++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/pkg/compute/models/secgroupcache.go b/pkg/compute/models/secgroupcache.go index 690bb27f41..2e978975df 100644 --- a/pkg/compute/models/secgroupcache.go +++ b/pkg/compute/models/secgroupcache.go @@ -145,9 +145,6 @@ func (manager *SSecurityGroupCacheManager) GetSecgroupCache(ctx context.Context, if err != nil { return nil, err } - if count > 1 { - return nil, fmt.Errorf("duplicate secgroupcache for secgroup: %s vpcId: %s regionId: %s", secgroupId, vpcId, regionId) - } if count == 0 { return nil, nil } @@ -156,19 +153,11 @@ func (manager *SSecurityGroupCacheManager) GetSecgroupCache(ctx context.Context, return &secgroupCache, nil } -func (manager *SSecurityGroupCacheManager) Register(ctx context.Context, userCred mcclient.TokenCredential, secgroupId, vpcId, regionId string, providerId string) (*SSecurityGroupCache, error) { +func (manager *SSecurityGroupCacheManager) NewCache(ctx context.Context, userCred mcclient.TokenCredential, secgroupId, vpcId, regionId string, providerId string) (*SSecurityGroupCache, error) { lockman.LockClass(ctx, manager, userCred.GetProjectId()) defer lockman.ReleaseClass(ctx, manager, userCred.GetProjectId()) - secgroupCache, err := manager.GetSecgroupCache(ctx, userCred, secgroupId, vpcId, regionId, providerId) - if err != nil { - return nil, err - } - if secgroupCache != nil { - return secgroupCache, nil - } - - secgroupCache = &SSecurityGroupCache{ + secgroupCache := &SSecurityGroupCache{ SecgroupId: secgroupId, VpcId: vpcId, CloudregionId: regionId, @@ -182,6 +171,19 @@ func (manager *SSecurityGroupCacheManager) Register(ctx context.Context, userCre return secgroupCache, nil } +func (manager *SSecurityGroupCacheManager) Register(ctx context.Context, userCred mcclient.TokenCredential, secgroupId, vpcId, regionId string, providerId string) (*SSecurityGroupCache, error) { + secgroupCache, err := manager.GetSecgroupCache(ctx, userCred, secgroupId, vpcId, regionId, providerId) + if err != nil { + return nil, err + } + + if secgroupCache != nil { + return secgroupCache, nil + } + + return manager.NewCache(ctx, userCred, secgroupId, vpcId, regionId, providerId) +} + func (manager *SSecurityGroupCacheManager) getSecgroupcachesByProvider(provider *SCloudprovider) ([]SSecurityGroupCache, error) { q := manager.Query().Equals("manager_id", provider.Id) caches := []SSecurityGroupCache{} @@ -232,9 +234,9 @@ func (manager *SSecurityGroupCacheManager) SyncSecurityGroupCaches(ctx context.C syncResult.AddError(err) continue } - cache, err := manager.Register(ctx, userCred, secgroup.Id, added[i].GetVpcId(), vpc.CloudregionId, provider.Id) + cache, err := manager.NewCache(ctx, userCred, secgroup.Id, added[i].GetVpcId(), vpc.CloudregionId, provider.Id) if err != nil { - syncResult.AddError(fmt.Errorf("failed to registor secgroup cache for secgroup %s(%s) provider: %s: %s", secgroup.Name, secgroup.Name, provider.Name, err)) + syncResult.AddError(fmt.Errorf("failed to create secgroup cache for secgroup %s(%s) provider: %s: %s", secgroup.Name, secgroup.Name, provider.Name, err)) continue } if err = cache.SetExternalId(userCred, added[i].GetGlobalId()); err != nil {