From 2583be9e32364d68ba06a64e0d4689d46bf29da0 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Fri, 9 Nov 2018 11:17:55 +0200 Subject: [PATCH] Removed Context parameter for RemoveAttributeProfile API --- apier/v1/attributes.go | 9 ++++----- apier/v1/attributes_it_test.go | 9 +++++++-- apier/v1/filter_indexes_it_test.go | 10 ++++------ apier/v1/filterindexecache_it_test.go | 4 ++-- engine/datamanager.go | 7 +++---- engine/filterindexer_it_test.go | 2 +- engine/onstor_it_test.go | 2 +- engine/tp_reader.go | 3 ++- migrator/attributes.go | 2 +- 9 files changed, 25 insertions(+), 23 deletions(-) diff --git a/apier/v1/attributes.go b/apier/v1/attributes.go index e845e9f75..45c8659f3 100644 --- a/apier/v1/attributes.go +++ b/apier/v1/attributes.go @@ -80,17 +80,16 @@ func (apierV1 *ApierV1) SetAttributeProfile(alsPrf *engine.AttributeProfile, rep } type ArgRemoveAttrProfile struct { - Tenant string - ID string - Contexts []string + Tenant string + ID string } //RemoveAttributeProfile remove a specific Attribute Profile func (apierV1 *ApierV1) RemoveAttributeProfile(arg *ArgRemoveAttrProfile, reply *string) error { - if missing := utils.MissingStructFields(arg, []string{"Tenant", "ID", "Contexts"}); len(missing) != 0 { //Params missing + if missing := utils.MissingStructFields(arg, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := apierV1.DataManager.RemoveAttributeProfile(arg.Tenant, arg.ID, arg.Contexts, utils.NonTransactional, true); err != nil { + if err := apierV1.DataManager.RemoveAttributeProfile(arg.Tenant, arg.ID, utils.NonTransactional, true); err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } diff --git a/apier/v1/attributes_it_test.go b/apier/v1/attributes_it_test.go index d1d2343da..c85086f99 100644 --- a/apier/v1/attributes_it_test.go +++ b/apier/v1/attributes_it_test.go @@ -704,8 +704,7 @@ func testAttributeSUpdateAlsPrf(t *testing.T) { func testAttributeSRemAlsPrf(t *testing.T) { var resp string if err := attrSRPC.Call("ApierV1.RemoveAttributeProfile", - &ArgRemoveAttrProfile{Tenant: alsPrf.Tenant, ID: alsPrf.ID, - Contexts: alsPrf.Contexts}, &resp); err != nil { + &ArgRemoveAttrProfile{Tenant: alsPrf.Tenant, ID: alsPrf.ID}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) @@ -716,6 +715,12 @@ func testAttributeSRemAlsPrf(t *testing.T) { &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } + // remove twice shoud return not found + resp = "" + if err := attrSRPC.Call("ApierV1.RemoveAttributeProfile", + &ArgRemoveAttrProfile{Tenant: alsPrf.Tenant, ID: alsPrf.ID}, &resp); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } } func testAttributeSSetAlsPrf2(t *testing.T) { diff --git a/apier/v1/filter_indexes_it_test.go b/apier/v1/filter_indexes_it_test.go index 3f29d5ec7..d1c20b79c 100644 --- a/apier/v1/filter_indexes_it_test.go +++ b/apier/v1/filter_indexes_it_test.go @@ -1396,17 +1396,15 @@ func testV1FIdxRemoveAttributeProfile(t *testing.T) { t.Error("Unexpected reply returned", result) } if err := tFIdxRpc.Call("ApierV1.RemoveAttributeProfile", &ArgRemoveAttrProfile{ - Tenant: tenant, - ID: "ApierTest", - Contexts: []string{utils.MetaSessionS}}, &result); err != nil { + Tenant: tenant, + ID: "ApierTest"}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } if err := tFIdxRpc.Call("ApierV1.RemoveAttributeProfile", &ArgRemoveAttrProfile{ - Tenant: tenant, - ID: "ApierTest2", - Contexts: []string{utils.MetaSessionS}}, &result); err != nil { + Tenant: tenant, + ID: "ApierTest2"}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) diff --git a/apier/v1/filterindexecache_it_test.go b/apier/v1/filterindexecache_it_test.go index 6acfa4ac3..73cf59d61 100644 --- a/apier/v1/filterindexecache_it_test.go +++ b/apier/v1/filterindexecache_it_test.go @@ -1063,7 +1063,7 @@ func testV1FIdxCaRemoveAttributeProfile(t *testing.T) { } //Remove threshold profile that was set form api if err := tFIdxCaRpc.Call("ApierV1.RemoveAttributeProfile", &ArgRemoveAttrProfile{Tenant: "cgrates.org", - ID: "TEST_PROFILE1", Contexts: []string{utils.MetaSessionS}}, &resp); err != nil { + ID: "TEST_PROFILE1"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) @@ -1077,7 +1077,7 @@ func testV1FIdxCaRemoveAttributeProfile(t *testing.T) { } //Remove threshold profile that was set form tariffplan if err := tFIdxCaRpc.Call("ApierV1.RemoveAttributeProfile", &ArgRemoveAttrProfile{Tenant: "cgrates.org", - ID: "ATTR_1", Contexts: []string{utils.MetaSessionS}}, &resp); err != nil { + ID: "ATTR_1"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) diff --git a/engine/datamanager.go b/engine/datamanager.go index e79ffd3dc..3648f3439 100644 --- a/engine/datamanager.go +++ b/engine/datamanager.go @@ -1228,10 +1228,9 @@ func (dm *DataManager) SetAttributeProfile(ap *AttributeProfile, withIndex bool) return } -func (dm *DataManager) RemoveAttributeProfile(tenant, id string, contexts []string, - transactionID string, withIndex bool) (err error) { +func (dm *DataManager) RemoveAttributeProfile(tenant, id string, transactionID string, withIndex bool) (err error) { oldAttr, err := dm.GetAttributeProfile(tenant, id, true, false, utils.NonTransactional) - if err != nil && err != utils.ErrNotFound { + if err != nil { return err } if err = dm.DataDB().RemoveAttributeProfileDrv(tenant, id); err != nil { @@ -1240,7 +1239,7 @@ func (dm *DataManager) RemoveAttributeProfile(tenant, id string, contexts []stri Cache.Remove(utils.CacheAttributeProfiles, utils.ConcatenatedKey(tenant, id), cacheCommit(transactionID), transactionID) if withIndex { - for _, context := range contexts { + for _, context := range oldAttr.Contexts { if err = NewFilterIndexer(dm, utils.AttributeProfilePrefix, utils.ConcatenatedKey(tenant, context)).RemoveItemFromIndex(tenant, id, oldAttr.FilterIDs); err != nil { return diff --git a/engine/filterindexer_it_test.go b/engine/filterindexer_it_test.go index 47a7e644e..d47f2d2cd 100644 --- a/engine/filterindexer_it_test.go +++ b/engine/filterindexer_it_test.go @@ -485,7 +485,7 @@ func testITTestAttributeProfileFilterIndexes(t *testing.T) { } if err := dataManager.RemoveAttributeProfile(attrProfile.Tenant, - attrProfile.ID, attrProfile.Contexts, utils.NonTransactional, true); err != nil { + attrProfile.ID, utils.NonTransactional, true); err != nil { t.Error(err) } //check if index is removed diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index a278d8027..eb88ce2c5 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -2539,7 +2539,7 @@ func testOnStorITAttributeProfile(t *testing.T) { t.Errorf("Expecting: %v, received: %v", attrProfile, rcv) } if err := onStor.RemoveAttributeProfile(attrProfile.Tenant, - attrProfile.ID, attrProfile.Contexts, utils.NonTransactional, false); err != nil { + attrProfile.ID, utils.NonTransactional, false); err != nil { t.Error(err) } //check cache if removed diff --git a/engine/tp_reader.go b/engine/tp_reader.go index ac418ba58..249c37cc9 100644 --- a/engine/tp_reader.go +++ b/engine/tp_reader.go @@ -2786,7 +2786,8 @@ func (tpr *TpReader) RemoveFromDatabase(verbose, disable_reverse bool) (err erro log.Print("AttributeProfiles:") } for _, tpTH := range tpr.attributeProfiles { - if err = tpr.dm.RemoveAttributeProfile(tpTH.Tenant, tpTH.ID, tpTH.Contexts, utils.NonTransactional, false); err != nil { + if err = tpr.dm.RemoveAttributeProfile(tpTH.Tenant, tpTH.ID, + utils.NonTransactional, false); err != nil && err.Error() != utils.ErrNotFound.Error() { return err } if verbose { diff --git a/migrator/attributes.go b/migrator/attributes.go index 70cb14ae0..224b80fd5 100644 --- a/migrator/attributes.go +++ b/migrator/attributes.go @@ -63,7 +63,7 @@ func (m *Migrator) migrateCurrentAttributeProfile() (err error) { return err } if err := m.dmIN.DataManager().RemoveAttributeProfile(tenant, - idg, attrPrf.Contexts, utils.NonTransactional, false); err != nil { + idg, utils.NonTransactional, false); err != nil { return err } m.stats[utils.Attributes] += 1