Skip to content
This repository was archived by the owner on Nov 29, 2017. It is now read-only.

Commit 442b18d

Browse files
committed
Merge pull request #12 from jojimt/I6
Fix contiv/modelgen#6
2 parents e96dfaf + 3eab39a commit 442b18d

File tree

1 file changed

+84
-24
lines changed

1 file changed

+84
-24
lines changed

contivModel.go

+84-24
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@ func CreateAppProfile(obj *AppProfile) error {
718718
return errors.New("Invalid object type")
719719
}
720720

721+
saveObj := obj
722+
721723
// Check if object already exists
722724
if collections.appProfiles[obj.Key] != nil {
723725
// Perform Update callback
@@ -726,6 +728,9 @@ func CreateAppProfile(obj *AppProfile) error {
726728
log.Errorf("AppProfileUpdate retruned error for: %+v. Err: %v", obj, err)
727729
return err
728730
}
731+
732+
// save the original object after update
733+
saveObj = collections.appProfiles[obj.Key]
729734
} else {
730735
// save it in cache
731736
collections.appProfiles[obj.Key] = obj
@@ -740,9 +745,9 @@ func CreateAppProfile(obj *AppProfile) error {
740745
}
741746

742747
// Write it to modeldb
743-
err = obj.Write()
748+
err = saveObj.Write()
744749
if err != nil {
745-
log.Errorf("Error saving appProfile %s to db. Err: %v", obj.Key, err)
750+
log.Errorf("Error saving appProfile %s to db. Err: %v", saveObj.Key, err)
746751
return err
747752
}
748753

@@ -952,6 +957,8 @@ func CreateEndpointGroup(obj *EndpointGroup) error {
952957
return errors.New("Invalid object type")
953958
}
954959

960+
saveObj := obj
961+
955962
// Check if object already exists
956963
if collections.endpointGroups[obj.Key] != nil {
957964
// Perform Update callback
@@ -960,6 +967,9 @@ func CreateEndpointGroup(obj *EndpointGroup) error {
960967
log.Errorf("EndpointGroupUpdate retruned error for: %+v. Err: %v", obj, err)
961968
return err
962969
}
970+
971+
// save the original object after update
972+
saveObj = collections.endpointGroups[obj.Key]
963973
} else {
964974
// save it in cache
965975
collections.endpointGroups[obj.Key] = obj
@@ -974,9 +984,9 @@ func CreateEndpointGroup(obj *EndpointGroup) error {
974984
}
975985

976986
// Write it to modeldb
977-
err = obj.Write()
987+
err = saveObj.Write()
978988
if err != nil {
979-
log.Errorf("Error saving endpointGroup %s to db. Err: %v", obj.Key, err)
989+
log.Errorf("Error saving endpointGroup %s to db. Err: %v", saveObj.Key, err)
980990
return err
981991
}
982992

@@ -1186,6 +1196,8 @@ func CreateGlobal(obj *Global) error {
11861196
return errors.New("Invalid object type")
11871197
}
11881198

1199+
saveObj := obj
1200+
11891201
// Check if object already exists
11901202
if collections.globals[obj.Key] != nil {
11911203
// Perform Update callback
@@ -1194,6 +1206,9 @@ func CreateGlobal(obj *Global) error {
11941206
log.Errorf("GlobalUpdate retruned error for: %+v. Err: %v", obj, err)
11951207
return err
11961208
}
1209+
1210+
// save the original object after update
1211+
saveObj = collections.globals[obj.Key]
11971212
} else {
11981213
// save it in cache
11991214
collections.globals[obj.Key] = obj
@@ -1208,9 +1223,9 @@ func CreateGlobal(obj *Global) error {
12081223
}
12091224

12101225
// Write it to modeldb
1211-
err = obj.Write()
1226+
err = saveObj.Write()
12121227
if err != nil {
1213-
log.Errorf("Error saving global %s to db. Err: %v", obj.Key, err)
1228+
log.Errorf("Error saving global %s to db. Err: %v", saveObj.Key, err)
12141229
return err
12151230
}
12161231

@@ -1438,6 +1453,8 @@ func CreateBgp(obj *Bgp) error {
14381453
return errors.New("Invalid object type")
14391454
}
14401455

1456+
saveObj := obj
1457+
14411458
// Check if object already exists
14421459
if collections.Bgps[obj.Key] != nil {
14431460
// Perform Update callback
@@ -1446,6 +1463,9 @@ func CreateBgp(obj *Bgp) error {
14461463
log.Errorf("BgpUpdate retruned error for: %+v. Err: %v", obj, err)
14471464
return err
14481465
}
1466+
1467+
// save the original object after update
1468+
saveObj = collections.Bgps[obj.Key]
14491469
} else {
14501470
// save it in cache
14511471
collections.Bgps[obj.Key] = obj
@@ -1460,9 +1480,9 @@ func CreateBgp(obj *Bgp) error {
14601480
}
14611481

14621482
// Write it to modeldb
1463-
err = obj.Write()
1483+
err = saveObj.Write()
14641484
if err != nil {
1465-
log.Errorf("Error saving Bgp %s to db. Err: %v", obj.Key, err)
1485+
log.Errorf("Error saving Bgp %s to db. Err: %v", saveObj.Key, err)
14661486
return err
14671487
}
14681488

@@ -1692,6 +1712,8 @@ func CreateNetwork(obj *Network) error {
16921712
return errors.New("Invalid object type")
16931713
}
16941714

1715+
saveObj := obj
1716+
16951717
// Check if object already exists
16961718
if collections.networks[obj.Key] != nil {
16971719
// Perform Update callback
@@ -1700,6 +1722,9 @@ func CreateNetwork(obj *Network) error {
17001722
log.Errorf("NetworkUpdate retruned error for: %+v. Err: %v", obj, err)
17011723
return err
17021724
}
1725+
1726+
// save the original object after update
1727+
saveObj = collections.networks[obj.Key]
17031728
} else {
17041729
// save it in cache
17051730
collections.networks[obj.Key] = obj
@@ -1714,9 +1739,9 @@ func CreateNetwork(obj *Network) error {
17141739
}
17151740

17161741
// Write it to modeldb
1717-
err = obj.Write()
1742+
err = saveObj.Write()
17181743
if err != nil {
1719-
log.Errorf("Error saving network %s to db. Err: %v", obj.Key, err)
1744+
log.Errorf("Error saving network %s to db. Err: %v", saveObj.Key, err)
17201745
return err
17211746
}
17221747

@@ -1944,6 +1969,8 @@ func CreatePolicy(obj *Policy) error {
19441969
return errors.New("Invalid object type")
19451970
}
19461971

1972+
saveObj := obj
1973+
19471974
// Check if object already exists
19481975
if collections.policys[obj.Key] != nil {
19491976
// Perform Update callback
@@ -1952,6 +1979,9 @@ func CreatePolicy(obj *Policy) error {
19521979
log.Errorf("PolicyUpdate retruned error for: %+v. Err: %v", obj, err)
19531980
return err
19541981
}
1982+
1983+
// save the original object after update
1984+
saveObj = collections.policys[obj.Key]
19551985
} else {
19561986
// save it in cache
19571987
collections.policys[obj.Key] = obj
@@ -1966,9 +1996,9 @@ func CreatePolicy(obj *Policy) error {
19661996
}
19671997

19681998
// Write it to modeldb
1969-
err = obj.Write()
1999+
err = saveObj.Write()
19702000
if err != nil {
1971-
log.Errorf("Error saving policy %s to db. Err: %v", obj.Key, err)
2001+
log.Errorf("Error saving policy %s to db. Err: %v", saveObj.Key, err)
19722002
return err
19732003
}
19742004

@@ -2178,6 +2208,8 @@ func CreateRule(obj *Rule) error {
21782208
return errors.New("Invalid object type")
21792209
}
21802210

2211+
saveObj := obj
2212+
21812213
// Check if object already exists
21822214
if collections.rules[obj.Key] != nil {
21832215
// Perform Update callback
@@ -2186,6 +2218,9 @@ func CreateRule(obj *Rule) error {
21862218
log.Errorf("RuleUpdate retruned error for: %+v. Err: %v", obj, err)
21872219
return err
21882220
}
2221+
2222+
// save the original object after update
2223+
saveObj = collections.rules[obj.Key]
21892224
} else {
21902225
// save it in cache
21912226
collections.rules[obj.Key] = obj
@@ -2200,9 +2235,9 @@ func CreateRule(obj *Rule) error {
22002235
}
22012236

22022237
// Write it to modeldb
2203-
err = obj.Write()
2238+
err = saveObj.Write()
22042239
if err != nil {
2205-
log.Errorf("Error saving rule %s to db. Err: %v", obj.Key, err)
2240+
log.Errorf("Error saving rule %s to db. Err: %v", saveObj.Key, err)
22062241
return err
22072242
}
22082243

@@ -2471,6 +2506,8 @@ func CreateService(obj *Service) error {
24712506
return errors.New("Invalid object type")
24722507
}
24732508

2509+
saveObj := obj
2510+
24742511
// Check if object already exists
24752512
if collections.services[obj.Key] != nil {
24762513
// Perform Update callback
@@ -2479,6 +2516,9 @@ func CreateService(obj *Service) error {
24792516
log.Errorf("ServiceUpdate retruned error for: %+v. Err: %v", obj, err)
24802517
return err
24812518
}
2519+
2520+
// save the original object after update
2521+
saveObj = collections.services[obj.Key]
24822522
} else {
24832523
// save it in cache
24842524
collections.services[obj.Key] = obj
@@ -2493,9 +2533,9 @@ func CreateService(obj *Service) error {
24932533
}
24942534

24952535
// Write it to modeldb
2496-
err = obj.Write()
2536+
err = saveObj.Write()
24972537
if err != nil {
2498-
log.Errorf("Error saving service %s to db. Err: %v", obj.Key, err)
2538+
log.Errorf("Error saving service %s to db. Err: %v", saveObj.Key, err)
24992539
return err
25002540
}
25012541

@@ -2705,6 +2745,8 @@ func CreateServiceInstance(obj *ServiceInstance) error {
27052745
return errors.New("Invalid object type")
27062746
}
27072747

2748+
saveObj := obj
2749+
27082750
// Check if object already exists
27092751
if collections.serviceInstances[obj.Key] != nil {
27102752
// Perform Update callback
@@ -2713,6 +2755,9 @@ func CreateServiceInstance(obj *ServiceInstance) error {
27132755
log.Errorf("ServiceInstanceUpdate retruned error for: %+v. Err: %v", obj, err)
27142756
return err
27152757
}
2758+
2759+
// save the original object after update
2760+
saveObj = collections.serviceInstances[obj.Key]
27162761
} else {
27172762
// save it in cache
27182763
collections.serviceInstances[obj.Key] = obj
@@ -2727,9 +2772,9 @@ func CreateServiceInstance(obj *ServiceInstance) error {
27272772
}
27282773

27292774
// Write it to modeldb
2730-
err = obj.Write()
2775+
err = saveObj.Write()
27312776
if err != nil {
2732-
log.Errorf("Error saving serviceInstance %s to db. Err: %v", obj.Key, err)
2777+
log.Errorf("Error saving serviceInstance %s to db. Err: %v", saveObj.Key, err)
27332778
return err
27342779
}
27352780

@@ -2939,6 +2984,8 @@ func CreateTenant(obj *Tenant) error {
29392984
return errors.New("Invalid object type")
29402985
}
29412986

2987+
saveObj := obj
2988+
29422989
// Check if object already exists
29432990
if collections.tenants[obj.Key] != nil {
29442991
// Perform Update callback
@@ -2947,6 +2994,9 @@ func CreateTenant(obj *Tenant) error {
29472994
log.Errorf("TenantUpdate retruned error for: %+v. Err: %v", obj, err)
29482995
return err
29492996
}
2997+
2998+
// save the original object after update
2999+
saveObj = collections.tenants[obj.Key]
29503000
} else {
29513001
// save it in cache
29523002
collections.tenants[obj.Key] = obj
@@ -2961,9 +3011,9 @@ func CreateTenant(obj *Tenant) error {
29613011
}
29623012

29633013
// Write it to modeldb
2964-
err = obj.Write()
3014+
err = saveObj.Write()
29653015
if err != nil {
2966-
log.Errorf("Error saving tenant %s to db. Err: %v", obj.Key, err)
3016+
log.Errorf("Error saving tenant %s to db. Err: %v", saveObj.Key, err)
29673017
return err
29683018
}
29693019

@@ -3181,6 +3231,8 @@ func CreateVolume(obj *Volume) error {
31813231
return errors.New("Invalid object type")
31823232
}
31833233

3234+
saveObj := obj
3235+
31843236
// Check if object already exists
31853237
if collections.volumes[obj.Key] != nil {
31863238
// Perform Update callback
@@ -3189,6 +3241,9 @@ func CreateVolume(obj *Volume) error {
31893241
log.Errorf("VolumeUpdate retruned error for: %+v. Err: %v", obj, err)
31903242
return err
31913243
}
3244+
3245+
// save the original object after update
3246+
saveObj = collections.volumes[obj.Key]
31923247
} else {
31933248
// save it in cache
31943249
collections.volumes[obj.Key] = obj
@@ -3203,9 +3258,9 @@ func CreateVolume(obj *Volume) error {
32033258
}
32043259

32053260
// Write it to modeldb
3206-
err = obj.Write()
3261+
err = saveObj.Write()
32073262
if err != nil {
3208-
log.Errorf("Error saving volume %s to db. Err: %v", obj.Key, err)
3263+
log.Errorf("Error saving volume %s to db. Err: %v", saveObj.Key, err)
32093264
return err
32103265
}
32113266

@@ -3415,6 +3470,8 @@ func CreateVolumeProfile(obj *VolumeProfile) error {
34153470
return errors.New("Invalid object type")
34163471
}
34173472

3473+
saveObj := obj
3474+
34183475
// Check if object already exists
34193476
if collections.volumeProfiles[obj.Key] != nil {
34203477
// Perform Update callback
@@ -3423,6 +3480,9 @@ func CreateVolumeProfile(obj *VolumeProfile) error {
34233480
log.Errorf("VolumeProfileUpdate retruned error for: %+v. Err: %v", obj, err)
34243481
return err
34253482
}
3483+
3484+
// save the original object after update
3485+
saveObj = collections.volumeProfiles[obj.Key]
34263486
} else {
34273487
// save it in cache
34283488
collections.volumeProfiles[obj.Key] = obj
@@ -3437,9 +3497,9 @@ func CreateVolumeProfile(obj *VolumeProfile) error {
34373497
}
34383498

34393499
// Write it to modeldb
3440-
err = obj.Write()
3500+
err = saveObj.Write()
34413501
if err != nil {
3442-
log.Errorf("Error saving volumeProfile %s to db. Err: %v", obj.Key, err)
3502+
log.Errorf("Error saving volumeProfile %s to db. Err: %v", saveObj.Key, err)
34433503
return err
34443504
}
34453505

0 commit comments

Comments
 (0)