Skip to content
Snippets Groups Projects

Develop

Closed Ghost User requested to merge develop into master
8 files
+ 47
48
Compare changes
  • Side-by-side
  • Inline
Files
8
+ 9
0
@@ -30,6 +30,10 @@ func init() {
log.Debugf("change timeout set to %v", changeTimeout)
}
// NewChange takes a Device UUID, a pair GoStructs (current and intended state)
// a callback function and a channel for errors and returns a *Change
// The callback function is used by the Commit() and Confirm() functions. It
// must define how the change is carried out.
func NewChange(device uuid.UUID, currentState ygot.GoStruct, change ygot.GoStruct, callback func(ygot.GoStruct, ygot.GoStruct) error, errChan chan error) *Change {
return &Change{
cuid: uuid.New(),
@@ -66,10 +70,14 @@ type Change struct {
Done chan int
}
// ID returns the Change's UUID
func (c *Change) ID() uuid.UUID {
return c.cuid
}
// Commit pushes the cange to the OND using the callback() function
// and starts the timeout-timer for the Change. If the timer expires
// the change is rolled back.
func (c *Change) Commit() error {
if err := c.callback(c.intendedState, c.previousState); err != nil {
return err
@@ -102,6 +110,7 @@ func (c *Change) rollbackHandler(ctx context.Context) {
}
}
// Confirm confirms a committed Change and stops the rollback timer.
func (c *Change) Confirm() error {
c.lock.RLock()
if !c.committed {
Loading