Skip to content
Snippets Groups Projects
Commit 2e560e9d authored by Malte Bauch's avatar Malte Bauch
Browse files

NewChange() starts a Goroutine acting as a Change's reciever for errors

This allows to log Errors thrown within a rollback.

Addresses: #152
parent 7dc82f18
No related branches found
No related tags found
1 merge request!218Resolve "Internal Changes representation is not working as expected"
This commit is part of merge request !218. Comments created here will be created in the context of that merge request.
...@@ -46,6 +46,13 @@ func NewChange(device uuid.UUID, currentState ygot.GoStruct, change ygot.GoStruc ...@@ -46,6 +46,13 @@ func NewChange(device uuid.UUID, currentState ygot.GoStruct, change ygot.GoStruc
c.stateOut = stateOut c.stateOut = stateOut
c.requestState = requestState c.requestState = requestState
c.errChan = errChan c.errChan = errChan
// recieve the errors from a Change and log them
go func() {
errChan := <-c.errChan
log.Error(errChan)
}()
return c return c
} }
...@@ -116,6 +123,9 @@ func stateManager(ch *Change, timeout time.Duration) (chan<- ppb.Change_State, < ...@@ -116,6 +123,9 @@ func stateManager(ch *Change, timeout time.Duration) (chan<- ppb.Change_State, <
stateIn := make(chan ppb.Change_State) stateIn := make(chan ppb.Change_State)
stateOut := make(chan ppb.Change_State) stateOut := make(chan ppb.Change_State)
stateRequest := make(chan bool) stateRequest := make(chan bool)
//A Goroutine, which is called from
//principalNetworkDomain.ChangeOND is now the reciever
//for errorChan
errChan := make(chan error) errChan := make(chan error)
// create ticker and make it wait for 1 week // create ticker and make it wait for 1 week
// workaround for delayed ticker start and ugly housekeeping // workaround for delayed ticker start and ugly housekeeping
...@@ -126,17 +136,13 @@ func stateManager(ch *Change, timeout time.Duration) (chan<- ppb.Change_State, < ...@@ -126,17 +136,13 @@ func stateManager(ch *Change, timeout time.Duration) (chan<- ppb.Change_State, <
for { for {
select { select {
case <-ticker.C: case <-ticker.C:
//TODO: errorChan seems problematic here, since there is no real
// reciever available. therefore currently there will be
// only simple logging.
err := ch.callback(ch.intendedState, ch.previousState) err := ch.callback(ch.intendedState, ch.previousState)
if err != nil { if err != nil {
state = ppb.Change_INCONSISTENT state = ppb.Change_INCONSISTENT
log.Errorf("change %v timed out", ch.cuid) log.Errorf("change %v timed out", ch.cuid)
//errChan <- err errChan <- err
} }
log.Errorf("change %v timed out", ch.cuid) errChan <- fmt.Errorf("change %v timed out", ch.cuid)
//errChan <- fmt.Errorf("change %v timed out", ch.cuid)
case s := <-stateIn: case s := <-stateIn:
switch s { switch s {
case ppb.Change_COMMITTED: case ppb.Change_COMMITTED:
...@@ -151,8 +157,8 @@ func stateManager(ch *Change, timeout time.Duration) (chan<- ppb.Change_State, < ...@@ -151,8 +157,8 @@ func stateManager(ch *Change, timeout time.Duration) (chan<- ppb.Change_State, <
state = ppb.Change_COMMITTED state = ppb.Change_COMMITTED
stateOut <- state stateOut <- state
case ppb.Change_CONFIRMED: case ppb.Change_CONFIRMED:
// stop the timer, since the changes are now confirmed and a // The change has been confirmed and the timer is stopped,
// rollback is not needed anymore // since a rollback is not necessary anymore.
ticker.Stop() ticker.Stop()
state = ppb.Change_CONFIRMED state = ppb.Change_CONFIRMED
stateOut <- state stateOut <- state
......
...@@ -317,6 +317,13 @@ func (pnd *pndImplementation) ChangeOND(duid uuid.UUID, operation ppb.ApiOperati ...@@ -317,6 +317,13 @@ func (pnd *pndImplementation) ChangeOND(duid uuid.UUID, operation ppb.ApiOperati
if err := pnd.changes.Add(ch); err != nil { if err := pnd.changes.Add(ch); err != nil {
return uuid.Nil, err return uuid.Nil, err
} }
//TODO:
// recieve the errors from a Change and log them
go func() {
errChan := <-ch.errChan
log.Error(errChan)
}()
return ch.cuid, nil return ch.cuid, nil
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment