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
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"
"code.fbi.h-da.de/danet/gosdn/controller/topology/nodes"
"code.fbi.h-da.de/danet/gosdn/controller/topology/ports"
"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
......@@ -18,9 +26,10 @@ type Service interface {
// RoutingTableService is a RoutingTableService
type RoutingTableService struct {
store Store
nodeService nodes.Service
portService ports.Service
store Store
nodeService nodes.Service
portService ports.Service
eventService eventInterfaces.Service
}
// NewRoutingTableService creates a RoutingTableService
......@@ -28,11 +37,13 @@ func NewRoutingTableService(
store Store,
nodeService nodes.Service,
portService ports.Service,
eventService eventInterfaces.Service,
) Service {
return &RoutingTableService{
store: store,
nodeService: nodeService,
portService: portService,
store: store,
nodeService: nodeService,
portService: portService,
eventService: eventService,
}
}
......@@ -57,7 +68,12 @@ func (r *RoutingTableService) createRoutingTable(routingTable RoutingTable) (Rou
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
......@@ -67,6 +83,11 @@ func (r *RoutingTableService) Update(routingTable RoutingTable) error {
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
}
......@@ -77,6 +98,11 @@ func (r *RoutingTableService) Delete(routingTable RoutingTable) error {
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
}
......
......@@ -5,6 +5,7 @@ import (
"testing"
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"
"code.fbi.h-da.de/danet/gosdn/controller/topology/nodes"
"code.fbi.h-da.de/danet/gosdn/controller/topology/ports"
......@@ -85,9 +86,10 @@ func getTestStoreWithPorts(t *testing.T, portsToAdd []ports.Port) ports.Store {
func TestNewRoutingTableService(t *testing.T) {
type args struct {
store Store
nodeService nodes.Service
portService ports.Service
store Store
nodeService nodes.Service
portService ports.Service
eventService eventInterfaces.Service
}
tests := []struct {
name string
......@@ -97,20 +99,22 @@ func TestNewRoutingTableService(t *testing.T) {
{
name: "should create a new topology service",
args: args{
store: getTestStoreWithRoutingTables(t, []RoutingTable{}),
nodeService: nodes.NewNodeService(getTestStoreWithNodes(t, []nodes.Node{}), eventservice.NewMockEventService()),
portService: ports.NewPortService(getTestStoreWithPorts(t, []ports.Port{}), eventservice.NewMockEventService()),
store: getTestStoreWithRoutingTables(t, []RoutingTable{}),
nodeService: nodes.NewNodeService(getTestStoreWithNodes(t, []nodes.Node{}), eventservice.NewMockEventService()),
portService: ports.NewPortService(getTestStoreWithPorts(t, []ports.Port{}), eventservice.NewMockEventService()),
eventService: eventservice.NewMockEventService(),
},
want: NewRoutingTableService(
getTestStoreWithRoutingTables(t, []RoutingTable{}),
nodes.NewNodeService(getTestStoreWithNodes(t, []nodes.Node{}), eventservice.NewMockEventService()),
ports.NewPortService(getTestStoreWithPorts(t, []ports.Port{}), eventservice.NewMockEventService()),
eventservice.NewMockEventService(),
),
},
}
for _, tt := range tests {
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)
}
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment