diff --git a/controller/event/event.go b/controller/event/event.go index 8eb6cf8d558e580f58a59b31f9d448891380e548..df39d2b9a8c17b6074825fb05b079ee8d6096dae 100644 --- a/controller/event/event.go +++ b/controller/event/event.go @@ -4,10 +4,10 @@ import "github.com/google/uuid" // Event is a event that can be published via the event service as payload. type Event struct { - ID uuid.UUID `json:"id,omitempty"` - EntityID uuid.UUID `json:"entity_id,omitempty"` - Type string `json:"type,omitempty"` - Paths []string `json:"paths,omitempty"` + ID uuid.UUID `json:"id,omitempty"` + EntityID uuid.UUID `json:"entity_id,omitempty"` + Type string `json:"type,omitempty"` + PathsAndValuesMap map[string]string `json:"paths_and_values,omitempty"` } const ( @@ -49,11 +49,11 @@ func NewUpdateEvent(entityID uuid.UUID) Event { } // NewMneUpdateEvent creates a new update event for managed network elements. -func NewMneUpdateEvent(entityID uuid.UUID, paths []string) Event { +func NewMneUpdateEvent(entityID uuid.UUID, pathsAndValues map[string]string) Event { return Event{ - ID: uuid.New(), - EntityID: entityID, - Type: TypeUpdate, - Paths: paths, + ID: uuid.New(), + EntityID: entityID, + Type: TypeUpdate, + PathsAndValuesMap: pathsAndValues, } } diff --git a/controller/event/event_test.go b/controller/event/event_test.go index 96f4a32a8d437dd6d055f1e967880384845492f4..9150bf0a23965618e9823d828ae72b5564eb2155 100644 --- a/controller/event/event_test.go +++ b/controller/event/event_test.go @@ -123,8 +123,8 @@ func TestNewUpdateEvent(t *testing.T) { func TestNewMneUpdateEvent(t *testing.T) { type args struct { - entityID uuid.UUID - paths []string + entityID uuid.UUID + pathsAndValuesMap map[string]string } tests := []struct { name string @@ -134,20 +134,20 @@ func TestNewMneUpdateEvent(t *testing.T) { { name: "should create a new update event", args: args{ - entityID: getTestEntityUUID(), - paths: []string{"some/random/path"}, + entityID: getTestEntityUUID(), + pathsAndValuesMap: map[string]string{"some/random/path": "val"}, }, want: Event{ - ID: uuid.New(), - EntityID: getTestEntityUUID(), - Type: TypeUpdate, - Paths: []string{"some/random/path"}, + ID: uuid.New(), + EntityID: getTestEntityUUID(), + Type: TypeUpdate, + PathsAndValuesMap: map[string]string{"some/random/path": "val"}, }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got := NewMneUpdateEvent(tt.args.entityID, tt.args.paths) + got := NewMneUpdateEvent(tt.args.entityID, tt.args.pathsAndValuesMap) if !reflect.DeepEqual(got.EntityID, tt.want.EntityID) { t.Errorf("NewMneUpdateEvent().EntityID = %v, want %v", got, tt.want) @@ -157,7 +157,7 @@ func TestNewMneUpdateEvent(t *testing.T) { t.Errorf("NewMneUpdateEvent().Type = %v, want %v", got, tt.want) } - if !reflect.DeepEqual(got.Paths, tt.want.Paths) { + if !reflect.DeepEqual(got.PathsAndValuesMap, tt.want.PathsAndValuesMap) { t.Errorf("NewMneUpdateEvent().Type = %v, want %v", got, tt.want) } }) diff --git a/controller/nucleus/networkElementService.go b/controller/nucleus/networkElementService.go index b6c0979b3410d82b4821824d6564e2ca14e0abff..a41cdc3514a4ebf4be5ac429f00643e934c36e83 100644 --- a/controller/nucleus/networkElementService.go +++ b/controller/nucleus/networkElementService.go @@ -137,8 +137,8 @@ func (s *NetworkElementService) UpdateModel(networkElementToUpdate networkelemen return err } - // TODO (faseid): check if we want to add the paths here instead of empty string array! - pubEvent := event.NewMneUpdateEvent(networkElementToUpdate.ID(), []string{}) + // TODO (faseid): check if we want to add the paths here instead of empty map! + pubEvent := event.NewMneUpdateEvent(networkElementToUpdate.ID(), map[string]string{}) if err := s.eventService.PublishEvent(NetworkElementEventTopic, pubEvent); err != nil { go func() { s.eventService.Reconnect() @@ -160,8 +160,8 @@ func (s *NetworkElementService) Update(networkElementToUpdate networkelement.Net return err } - // TODO (faseid): check if we want to add the paths here instead of empty string array! - pubEvent := event.NewMneUpdateEvent(networkElementToUpdate.ID(), []string{}) + // TODO (faseid): check if we want to add the paths here instead of empty map! + pubEvent := event.NewMneUpdateEvent(networkElementToUpdate.ID(), map[string]string{}) if err := s.eventService.PublishEvent(NetworkElementEventTopic, pubEvent); err != nil { go func() { s.eventService.Reconnect() diff --git a/controller/nucleus/networkElementWatcher.go b/controller/nucleus/networkElementWatcher.go index 5cb76b0a822fe766cc999b3b80d72e091e2f79ca..af72cb62531e7895873422d136ab9b6fbdb7af50 100644 --- a/controller/nucleus/networkElementWatcher.go +++ b/controller/nucleus/networkElementWatcher.go @@ -3,6 +3,7 @@ package nucleus import ( "context" "fmt" + "strings" "code.fbi.h-da.de/danet/gosdn/controller/customerrs" "code.fbi.h-da.de/danet/gosdn/controller/event" @@ -164,19 +165,24 @@ func (n *NetworkElementWatcher) handleSubscribeResponseUpdate(resp *gpb.Subscrib err = mne.Transport().ProcessControlPlaneSubscribeResponse(resp, mne.GetModel(), mne.SBI().Schema()) if err != nil { log.Error(err) - } // else { - // if err := pnd.UpdateNetworkElementAfterSubscribeResponse(mne); err != nil { - // log.Error(err) - // } - // } + } - paths := []string{} + pathsAndValues := make(map[string]string, 0) for _, update := range resp.Update.Update { - paths = append(paths, update.String()) + pathString := "" + + // go through elem to build full path + for _, elem := range update.Path.Elem { + // remove unwanted parts of path string example: "name:\"system\"" -> "system" + filteredElem := elem.String()[strings.Index(elem.String(), ":\"")+2 : len(elem.String())-1] + pathString += filteredElem + "/" + } + + pathsAndValues[pathString] = update.Val.GetStringVal() } - pubEvent := event.NewMneUpdateEvent(mne.ID(), paths) + pubEvent := event.NewMneUpdateEvent(mne.ID(), pathsAndValues) if err := n.eventService.PublishEvent(NetworkElementEventTopic, pubEvent); err != nil { go func() { n.eventService.Reconnect()