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

added missing event publishing to routing table

parent fd7c7a12
No related branches found
No related tags found
1 merge request!363Resolve "Improve security by enabling and enforcing more linting rules"
Pipeline #110729 failed
This commit is part of merge request !363. Comments created here will be created in the context of that merge request.
package routingtables package routingtables
import ( import (
"code.fbi.h-da.de/danet/gosdn/controller/event"
eventInterfaces "code.fbi.h-da.de/danet/gosdn/controller/interfaces/event"
query "code.fbi.h-da.de/danet/gosdn/controller/store" query "code.fbi.h-da.de/danet/gosdn/controller/store"
"code.fbi.h-da.de/danet/gosdn/controller/topology/nodes" "code.fbi.h-da.de/danet/gosdn/controller/topology/nodes"
"code.fbi.h-da.de/danet/gosdn/controller/topology/ports" "code.fbi.h-da.de/danet/gosdn/controller/topology/ports"
"github.com/google/uuid" "github.com/google/uuid"
log "github.com/sirupsen/logrus"
)
const (
// RoutingTableEventTopic is the used topic for routing table related entity changes
RoutingTableEventTopic = "routingTable"
) )
// Service defines a interface for a RoutingTableService // Service defines a interface for a RoutingTableService
...@@ -18,9 +26,10 @@ type Service interface { ...@@ -18,9 +26,10 @@ type Service interface {
// RoutingTableService is a RoutingTableService // RoutingTableService is a RoutingTableService
type RoutingTableService struct { type RoutingTableService struct {
store Store store Store
nodeService nodes.Service nodeService nodes.Service
portService ports.Service portService ports.Service
eventService eventInterfaces.Service
} }
// NewRoutingTableService creates a RoutingTableService // NewRoutingTableService creates a RoutingTableService
...@@ -28,11 +37,13 @@ func NewRoutingTableService( ...@@ -28,11 +37,13 @@ func NewRoutingTableService(
store Store, store Store,
nodeService nodes.Service, nodeService nodes.Service,
portService ports.Service, portService ports.Service,
eventService eventInterfaces.Service,
) Service { ) Service {
return &RoutingTableService{ return &RoutingTableService{
store: store, store: store,
nodeService: nodeService, nodeService: nodeService,
portService: portService, portService: portService,
eventService: eventService,
} }
} }
...@@ -57,7 +68,12 @@ func (r *RoutingTableService) createRoutingTable(routingTable RoutingTable) (Rou ...@@ -57,7 +68,12 @@ func (r *RoutingTableService) createRoutingTable(routingTable RoutingTable) (Rou
return routingTable, err return routingTable, err
} }
return routingTable, err if err := r.eventService.PublishEvent(RoutingTableEventTopic, event.NewAddEvent(routingTable.ID)); err != nil {
//TODO: improve error handling, maybe to sth like reconnect
log.Error(err)
}
return routingTable, nil
} }
// Update updates an existing routingTable // Update updates an existing routingTable
...@@ -67,6 +83,11 @@ func (r *RoutingTableService) Update(routingTable RoutingTable) error { ...@@ -67,6 +83,11 @@ func (r *RoutingTableService) Update(routingTable RoutingTable) error {
return err return err
} }
if err := r.eventService.PublishEvent(RoutingTableEventTopic, event.NewUpdateEvent(routingTable.ID)); err != nil {
//TODO: improve error handling, maybe to sth like reconnect
log.Error(err)
}
return nil return nil
} }
...@@ -77,6 +98,11 @@ func (r *RoutingTableService) Delete(routingTable RoutingTable) error { ...@@ -77,6 +98,11 @@ func (r *RoutingTableService) Delete(routingTable RoutingTable) error {
return err return err
} }
if err := r.eventService.PublishEvent(RoutingTableEventTopic, event.NewDeleteEvent(routingTable.ID)); err != nil {
//TODO: improve error handling, maybe to sth like reconnect
log.Error(err)
}
return nil return nil
} }
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"testing" "testing"
eventservice "code.fbi.h-da.de/danet/gosdn/controller/eventService" eventservice "code.fbi.h-da.de/danet/gosdn/controller/eventService"
eventInterfaces "code.fbi.h-da.de/danet/gosdn/controller/interfaces/event"
query "code.fbi.h-da.de/danet/gosdn/controller/store" query "code.fbi.h-da.de/danet/gosdn/controller/store"
"code.fbi.h-da.de/danet/gosdn/controller/topology/nodes" "code.fbi.h-da.de/danet/gosdn/controller/topology/nodes"
"code.fbi.h-da.de/danet/gosdn/controller/topology/ports" "code.fbi.h-da.de/danet/gosdn/controller/topology/ports"
...@@ -85,9 +86,10 @@ func getTestStoreWithPorts(t *testing.T, portsToAdd []ports.Port) ports.Store { ...@@ -85,9 +86,10 @@ func getTestStoreWithPorts(t *testing.T, portsToAdd []ports.Port) ports.Store {
func TestNewRoutingTableService(t *testing.T) { func TestNewRoutingTableService(t *testing.T) {
type args struct { type args struct {
store Store store Store
nodeService nodes.Service nodeService nodes.Service
portService ports.Service portService ports.Service
eventService eventInterfaces.Service
} }
tests := []struct { tests := []struct {
name string name string
...@@ -97,20 +99,22 @@ func TestNewRoutingTableService(t *testing.T) { ...@@ -97,20 +99,22 @@ func TestNewRoutingTableService(t *testing.T) {
{ {
name: "should create a new topology service", name: "should create a new topology service",
args: args{ args: args{
store: getTestStoreWithRoutingTables(t, []RoutingTable{}), store: getTestStoreWithRoutingTables(t, []RoutingTable{}),
nodeService: nodes.NewNodeService(getTestStoreWithNodes(t, []nodes.Node{}), eventservice.NewMockEventService()), nodeService: nodes.NewNodeService(getTestStoreWithNodes(t, []nodes.Node{}), eventservice.NewMockEventService()),
portService: ports.NewPortService(getTestStoreWithPorts(t, []ports.Port{}), eventservice.NewMockEventService()), portService: ports.NewPortService(getTestStoreWithPorts(t, []ports.Port{}), eventservice.NewMockEventService()),
eventService: eventservice.NewMockEventService(),
}, },
want: NewRoutingTableService( want: NewRoutingTableService(
getTestStoreWithRoutingTables(t, []RoutingTable{}), getTestStoreWithRoutingTables(t, []RoutingTable{}),
nodes.NewNodeService(getTestStoreWithNodes(t, []nodes.Node{}), eventservice.NewMockEventService()), nodes.NewNodeService(getTestStoreWithNodes(t, []nodes.Node{}), eventservice.NewMockEventService()),
ports.NewPortService(getTestStoreWithPorts(t, []ports.Port{}), eventservice.NewMockEventService()), ports.NewPortService(getTestStoreWithPorts(t, []ports.Port{}), eventservice.NewMockEventService()),
eventservice.NewMockEventService(),
), ),
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if got := NewRoutingTableService(tt.args.store, tt.args.nodeService, tt.args.portService); !reflect.DeepEqual(got, tt.want) { if got := NewRoutingTableService(tt.args.store, tt.args.nodeService, tt.args.portService, tt.args.eventService); !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewNodeService() = %v, want %v", got, tt.want) t.Errorf("NewNodeService() = %v, want %v", got, tt.want)
} }
}) })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment