[VOL-2782] Update go.mod of voltha-go,open-olt-adapter,ofagent-go and voltctl to be compatible with latest version of voltha-lig-go
Change-Id: Idd1a36b6059927af9a4f3c12581663d587a19176
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/config/configmanager.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/config/configmanager.go
index 8f96b22..441c488 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/config/configmanager.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/config/configmanager.go
@@ -24,9 +24,16 @@
"strings"
)
+func init() {
+ _, err := log.AddPackage(log.JSON, log.FatalLevel, nil)
+ if err != nil {
+ log.Errorw("unable-to-register-package-to-the-log-map", log.Fields{"error": err})
+ }
+}
+
const (
defaultkvStoreConfigPath = "config"
- kvStoreDataPathPrefix = "/service/voltha"
+ kvStoreDataPathPrefix = "service/voltha"
kvStorePathSeparator = "/"
)
@@ -52,6 +59,10 @@
Delete
)
+func (ce ChangeEvent) String() string {
+ return [...]string{"Put", "Delete"}[ce]
+}
+
// ConfigChangeEvent represents config for the events recieved from watch
// For example,ChangeType is Put ,ConfigAttribute default
type ConfigChangeEvent struct {
@@ -102,6 +113,35 @@
}
}
+// RetrieveComponentList list the component Names for which loglevel is stored in kvstore
+func (c *ConfigManager) RetrieveComponentList(ctx context.Context, configType ConfigType) ([]string, error) {
+ data, err := c.backend.List(ctx, c.KvStoreConfigPrefix)
+ if err != nil {
+ return nil, err
+ }
+
+ // Looping through the data recieved from the backend for config
+ // Trimming and Splitting the required key and value from data and storing as componentName,PackageName and Level
+ // For Example, recieved key would be <Backend Prefix Path>/<Config Prefix>/<Component Name>/<Config Type>/default and value \"DEBUG\"
+ // Then in default will be stored as PackageName,componentName as <Component Name> and DEBUG will be stored as value in List struct
+ ccPathPrefix := kvStorePathSeparator + configType.String() + kvStorePathSeparator
+ pathPrefix := kvStoreDataPathPrefix + kvStorePathSeparator + c.KvStoreConfigPrefix + kvStorePathSeparator
+ var list []string
+ keys := make(map[string]interface{})
+ for attr := range data {
+ cname := strings.TrimPrefix(attr, pathPrefix)
+ cName := strings.SplitN(cname, ccPathPrefix, 2)
+ if len(cName) != 2 {
+ continue
+ }
+ if _, exist := keys[cName[0]]; !exist {
+ keys[cName[0]] = nil
+ list = append(list, cName[0])
+ }
+ }
+ return list, nil
+}
+
// Initialize the component config
func (cm *ConfigManager) InitComponentConfig(componentLabel string, configType ConfigType) *ComponentConfig {
@@ -147,8 +187,11 @@
func (c *ComponentConfig) processKVStoreWatchEvents() {
ccKeyPrefix := c.makeConfigPath()
+
log.Debugw("processing-kvstore-event-change", log.Fields{"key-prefix": ccKeyPrefix})
+
ccPathPrefix := c.cManager.backend.PathPrefix + ccKeyPrefix + kvStorePathSeparator
+
for watchResp := range c.kvStoreEventChan {
if watchResp.EventType == kvstore.CONNECTIONDOWN || watchResp.EventType == kvstore.UNKNOWN {
@@ -168,10 +211,30 @@
}
}
+// Retrieves value of a specific config key. Value of key is returned in String format
+func (c *ComponentConfig) Retrieve(ctx context.Context, configKey string) (string, error) {
+ key := c.makeConfigPath() + "/" + configKey
+
+ log.Debugw("retrieving-config", log.Fields{"key": key})
+
+ if kvpair, err := c.cManager.backend.Get(ctx, key); err != nil {
+ return "", err
+ } else {
+ if kvpair == nil {
+ return "", fmt.Errorf("config-key-does-not-exist : %s", key)
+ }
+
+ value := strings.Trim(fmt.Sprintf("%s", kvpair.Value), "\"")
+ log.Debugw("retrieved-config", log.Fields{"key": key, "value": value})
+ return value, nil
+ }
+}
+
func (c *ComponentConfig) RetrieveAll(ctx context.Context) (map[string]string, error) {
key := c.makeConfigPath()
log.Debugw("retreiving-list", log.Fields{"key": key})
+
data, err := c.cManager.backend.List(ctx, key)
if err != nil {
return nil, err
@@ -190,10 +253,10 @@
return res, nil
}
-func (c *ComponentConfig) Save(configKey string, configValue string, ctx context.Context) error {
+func (c *ComponentConfig) Save(ctx context.Context, configKey string, configValue string) error {
key := c.makeConfigPath() + "/" + configKey
- log.Debugw("saving-key", log.Fields{"key": key, "value": configValue})
+ log.Debugw("saving-config", log.Fields{"key": key, "value": configValue})
//save the data for update config
if err := c.cManager.backend.Put(ctx, key, configValue); err != nil {
@@ -202,11 +265,11 @@
return nil
}
-func (c *ComponentConfig) Delete(configKey string, ctx context.Context) error {
+func (c *ComponentConfig) Delete(ctx context.Context, configKey string) error {
//construct key using makeConfigPath
key := c.makeConfigPath() + "/" + configKey
- log.Debugw("deleting-key", log.Fields{"key": key})
+ log.Debugw("deleting-config", log.Fields{"key": key})
//delete the config
if err := c.cManager.backend.Delete(ctx, key); err != nil {
return err