Skip to content

Commit

Permalink
osdconfig lib update
Browse files Browse the repository at this point in the history
code refactoring and simplification.

Signed-off-by: Saurabh Deoras <[email protected]>
  • Loading branch information
sdeoras committed Feb 15, 2018
1 parent a0d4d02 commit ec088b7
Show file tree
Hide file tree
Showing 18 changed files with 361 additions and 1,160 deletions.
59 changes: 59 additions & 0 deletions osdconfig/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# osdconfig
osdconfig is a library to work with distributed configuration parameters. It defines an interface and provides an
implementation against KVDB backend.

General purpose of this package is as follows:
* Allow users to register their callback functions on updates to backend
* Allow users to set/get config parameters

# installation
osdconfig is written in go (golang). It can be installed using go get
```bash
$ go get github.com/libopenstorage/openstorage/osdconfig/...
```

# example
Create an instance of kvdb
```go
kv, err := kvdb.New(mem.Name, "", []string{}, nil, nil)
if err != nil {
logrus.Fatal(err)
}
```

Create an instance of osdconfig manager
```go
manager, err := osdconfig.NewManager(kv)
if err != nil {
// do something
}
defer manager.Close()
```

Define a function literal that can be registered to watch for changes
```go
f := func(config *osdconfig.Config) error {
// do something with config (say print)
fmt.Println(config)
return nil
}
```

Register this function literal to watch on kvdb changes
```go
if err := manager.WatchCluster("watcher", f); err != nil {
// do something
}
```

Update cluster config on kvdb
```go
conf := new(osdconfig.ClusterConfig)
conf.ClusterID = "myID"
if err := manager.SetClusterConf(conf); err != nil {
// do something
return
}
```

once updates are pushed to backend (kvdb in this implementation), callback function is called
Loading

0 comments on commit ec088b7

Please sign in to comment.