[VOL-3731] added DeleteWithPrefix method from KV
Provides deleting multiple keys in one shot
Change-Id: I71e3089adcdc90a8307b9503197d220d1405f030
diff --git a/pkg/ponresourcemanager/ponresourcemanager.go b/pkg/ponresourcemanager/ponresourcemanager.go
index 0e1ae8f..415ce21 100755
--- a/pkg/ponresourcemanager/ponresourcemanager.go
+++ b/pkg/ponresourcemanager/ponresourcemanager.go
@@ -112,8 +112,11 @@
FLOW_ID_RESOURCE_MAP_PATH = "{%s}/{%s}/flow_ids"
//Flow Id info: Use to store more metadata associated with the flow_id
- //Format: <device_id>/<(pon_intf_id, onu_id)>/flow_id_info/<flow_id>
- FLOW_ID_INFO_PATH = "{%s}/{%s}/flow_id_info/{%d}"
+ FLOW_ID_INFO_PATH_PREFIX = "{%s}/flow_id_info"
+ //Format: <device_id>/flow_id_info/<(pon_intf_id, onu_id)>
+ FLOW_ID_INFO_PATH_INTF_ONU_PREFIX = "{%s}/flow_id_info/{%s}"
+ //Format: <device_id>/flow_id_info/<(pon_intf_id, onu_id)><flow_id>
+ FLOW_ID_INFO_PATH = FLOW_ID_INFO_PATH_PREFIX + "/{%s}/{%d}"
//path on the kvstore to store onugem info map
//format: <device-id>/onu_gem_info/<intfid>
@@ -1034,6 +1037,20 @@
return true
}
+func (PONRMgr *PONResourceManager) RemoveAllFlowIDInfo(ctx context.Context, IntfONUID string) bool {
+ /*
+ Remove flow_id_info details configured for the ONU.
+ :param pon_intf_onu_id: reference of PON interface id and onu id
+ */
+ Path := fmt.Sprintf(FLOW_ID_INFO_PATH_INTF_ONU_PREFIX, PONRMgr.DeviceID, IntfONUID)
+
+ if err := PONRMgr.KVStore.DeleteWithPrefix(ctx, Path); err != nil {
+ logger.Errorf(ctx, "Falied to remove resource %s", Path)
+ return false
+ }
+ return true
+}
+
func (PONRMgr *PONResourceManager) UpdateAllocIdsForOnu(ctx context.Context, IntfONUID string, AllocIDs []uint32) error {
/*
Update currently configured alloc ids for given pon_intf_onu_id
diff --git a/pkg/ponresourcemanager/ponresourcemanager_test.go b/pkg/ponresourcemanager/ponresourcemanager_test.go
index ecdccc7..1bc908e 100644
--- a/pkg/ponresourcemanager/ponresourcemanager_test.go
+++ b/pkg/ponresourcemanager/ponresourcemanager_test.go
@@ -88,6 +88,10 @@
return nil
}
+func (c *MockResKVClient) DeleteWithPrefix(ctx context.Context, prefixKey string) error {
+ return nil
+}
+
// Reserve mock function implementation for KVClient
func (kvclient *MockResKVClient) Reserve(ctx context.Context, key string, value interface{}, ttl time.Duration) (interface{}, error) {
return nil, errors.New("key didn't find")