Skip to content
Snippets Groups Projects
Commit 17211eb2 authored by Fabian Seidl's avatar Fabian Seidl
Browse files

Resolve "Improve the event system by adding an extra Event for gNMI-Subscribe...

Resolve "Improve the event system by adding an extra Event for gNMI-Subscribe to replace the currently used Update Event"

See merge request !568
parent 25cf7a73
No related branches found
No related tags found
1 merge request!568Resolve "Improve the event system by adding an extra Event for gNMI-Subscribe to replace the currently used Update Event"
Pipeline #164086 passed
...@@ -12,6 +12,8 @@ const ( ...@@ -12,6 +12,8 @@ const (
Update Update
// Delete is a delete event. // Delete is a delete event.
Delete Delete
// Subscribe is a gNMI subscribe event.
Subscribe
) )
// String implements the stringer interface for types. // String implements the stringer interface for types.
...@@ -23,6 +25,8 @@ func (t Type) String() string { ...@@ -23,6 +25,8 @@ func (t Type) String() string {
return "update" return "update"
case Delete: case Delete:
return "delete" return "delete"
case Subscribe:
return "subscribe"
} }
return "unknown" return "unknown"
...@@ -30,9 +34,10 @@ func (t Type) String() string { ...@@ -30,9 +34,10 @@ func (t Type) String() string {
var ( var (
typeLookup = map[string]Type{ typeLookup = map[string]Type{
"add": Add, "add": Add,
"update": Update, "update": Update,
"delete": Delete, "delete": Delete,
"subscribe": Subscribe,
} }
) )
......
...@@ -19,6 +19,9 @@ const ( ...@@ -19,6 +19,9 @@ const (
// TypeDelete is a delete event. // TypeDelete is a delete event.
TypeDelete = "delete" TypeDelete = "delete"
// TypeSubscribe is a gNMI subscribe event.
TypeSubscribe = "subscribe"
) )
// NewAddEvent creates a new add event. // NewAddEvent creates a new add event.
...@@ -48,12 +51,12 @@ func NewUpdateEvent(entityID uuid.UUID) Event { ...@@ -48,12 +51,12 @@ func NewUpdateEvent(entityID uuid.UUID) Event {
} }
} }
// NewMneUpdateEvent creates a new update event for managed network elements. // NewGnmiSubscribeEvent creates a new gNMI subscribe event for managed network elements.
func NewMneUpdateEvent(entityID uuid.UUID, pathsAndValues map[string]string) Event { func NewGnmiSubscribeEvent(entityID uuid.UUID, pathsAndValues map[string]string) Event {
return Event{ return Event{
ID: uuid.New(), ID: uuid.New(),
EntityID: entityID, EntityID: entityID,
Type: TypeUpdate, Type: TypeSubscribe,
PathsAndValuesMap: pathsAndValues, PathsAndValuesMap: pathsAndValues,
} }
} }
...@@ -121,7 +121,7 @@ func TestNewUpdateEvent(t *testing.T) { ...@@ -121,7 +121,7 @@ func TestNewUpdateEvent(t *testing.T) {
} }
} }
func TestNewMneUpdateEvent(t *testing.T) { func TestNewGnmiSubscribeEvent(t *testing.T) {
type args struct { type args struct {
entityID uuid.UUID entityID uuid.UUID
pathsAndValuesMap map[string]string pathsAndValuesMap map[string]string
...@@ -132,7 +132,7 @@ func TestNewMneUpdateEvent(t *testing.T) { ...@@ -132,7 +132,7 @@ func TestNewMneUpdateEvent(t *testing.T) {
want Event want Event
}{ }{
{ {
name: "should create a new update event", name: "should create a new subscribe event",
args: args{ args: args{
entityID: getTestEntityUUID(), entityID: getTestEntityUUID(),
pathsAndValuesMap: map[string]string{"some/random/path": "val"}, pathsAndValuesMap: map[string]string{"some/random/path": "val"},
...@@ -140,25 +140,25 @@ func TestNewMneUpdateEvent(t *testing.T) { ...@@ -140,25 +140,25 @@ func TestNewMneUpdateEvent(t *testing.T) {
want: Event{ want: Event{
ID: uuid.New(), ID: uuid.New(),
EntityID: getTestEntityUUID(), EntityID: getTestEntityUUID(),
Type: TypeUpdate, Type: TypeSubscribe,
PathsAndValuesMap: map[string]string{"some/random/path": "val"}, PathsAndValuesMap: map[string]string{"some/random/path": "val"},
}, },
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got := NewMneUpdateEvent(tt.args.entityID, tt.args.pathsAndValuesMap) got := NewGnmiSubscribeEvent(tt.args.entityID, tt.args.pathsAndValuesMap)
if !reflect.DeepEqual(got.EntityID, tt.want.EntityID) { if !reflect.DeepEqual(got.EntityID, tt.want.EntityID) {
t.Errorf("NewMneUpdateEvent().EntityID = %v, want %v", got, tt.want) t.Errorf("NewGnmiSubscribeEvent().EntityID = %v, want %v", got, tt.want)
} }
if !reflect.DeepEqual(got.Type, tt.want.Type) { if !reflect.DeepEqual(got.Type, tt.want.Type) {
t.Errorf("NewMneUpdateEvent().Type = %v, want %v", got, tt.want) t.Errorf("NewGnmiSubscribeEvent().Type = %v, want %v", got, tt.want)
} }
if !reflect.DeepEqual(got.PathsAndValuesMap, tt.want.PathsAndValuesMap) { if !reflect.DeepEqual(got.PathsAndValuesMap, tt.want.PathsAndValuesMap) {
t.Errorf("NewMneUpdateEvent().PathsAndValuesMap = %v, want %v", got, tt.want) t.Errorf("NewGnmiSubscribeEvent().PathsAndValuesMap = %v, want %v", got, tt.want)
} }
}) })
} }
......
...@@ -146,7 +146,7 @@ func (s *NetworkElementService) UpdateModel(networkElementID uuid.UUID, modelAsS ...@@ -146,7 +146,7 @@ func (s *NetworkElementService) UpdateModel(networkElementID uuid.UUID, modelAsS
} }
// TODO (faseid): check if we want to add the paths with values here instead of empty map! // TODO (faseid): check if we want to add the paths with values here instead of empty map!
pubEvent := event.NewMneUpdateEvent(networkElementID, map[string]string{}) pubEvent := event.NewUpdateEvent(networkElementID)
if err := s.eventService.PublishEvent(NetworkElementEventTopic, pubEvent); err != nil { if err := s.eventService.PublishEvent(NetworkElementEventTopic, pubEvent); err != nil {
go func() { go func() {
s.eventService.Reconnect() s.eventService.Reconnect()
...@@ -169,7 +169,7 @@ func (s *NetworkElementService) Update(networkElementToUpdate networkelement.Net ...@@ -169,7 +169,7 @@ func (s *NetworkElementService) Update(networkElementToUpdate networkelement.Net
} }
// TODO (faseid): check if we want to add the paths with values here instead of empty map! // TODO (faseid): check if we want to add the paths with values here instead of empty map!
pubEvent := event.NewMneUpdateEvent(networkElementToUpdate.ID(), map[string]string{}) pubEvent := event.NewUpdateEvent(networkElementToUpdate.ID())
if err := s.eventService.PublishEvent(NetworkElementEventTopic, pubEvent); err != nil { if err := s.eventService.PublishEvent(NetworkElementEventTopic, pubEvent); err != nil {
go func() { go func() {
s.eventService.Reconnect() s.eventService.Reconnect()
......
...@@ -201,7 +201,7 @@ func (n *NetworkElementWatcher) handleSubscribeResponseUpdate(resp *gpb.Subscrib ...@@ -201,7 +201,7 @@ func (n *NetworkElementWatcher) handleSubscribeResponseUpdate(resp *gpb.Subscrib
log.Errorf("Error trying to parse uuid, could not handle subscription response: %v", err) log.Errorf("Error trying to parse uuid, could not handle subscription response: %v", err)
} }
pubEvent := event.NewMneUpdateEvent(mneID, pathsAndValues) pubEvent := event.NewGnmiSubscribeEvent(mneID, pathsAndValues)
if err := n.eventService.PublishEvent(NetworkElementEventTopic, pubEvent); err != nil { if err := n.eventService.PublishEvent(NetworkElementEventTopic, pubEvent); err != nil {
go func() { go func() {
n.eventService.Reconnect() n.eventService.Reconnect()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment