Skip to content
Snippets Groups Projects
Commit 98eb6d5a authored by André Sterba's avatar André Sterba
Browse files

Implement app NBI

parent 90ba7258
No related branches found
No related tags found
2 merge requests!376Add additional example application hostname-checker,!343Add basic application framework and example application to show interaction between events an NBI
This commit is part of merge request !343. Comments created here will be created in the context of that merge request.
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd" ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac" apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac"
tpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/transport" tpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/transport"
"code.fbi.h-da.de/danet/gosdn/controller/app"
"code.fbi.h-da.de/danet/gosdn/controller/config" "code.fbi.h-da.de/danet/gosdn/controller/config"
eventservice "code.fbi.h-da.de/danet/gosdn/controller/eventService" eventservice "code.fbi.h-da.de/danet/gosdn/controller/eventService"
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/device" "code.fbi.h-da.de/danet/gosdn/controller/interfaces/device"
...@@ -144,8 +145,9 @@ func bootstrapUnitTest() { ...@@ -144,8 +145,9 @@ func bootstrapUnitTest() {
} }
jwtManager := rbacImpl.NewJWTManager("", (10000 * time.Hour)) jwtManager := rbacImpl.NewJWTManager("", (10000 * time.Hour))
appService := app.NewMockAppService()
northbound := nbi.NewNBI(pndStore, userService, roleService, *jwtManager) northbound := nbi.NewNBI(pndStore, userService, roleService, *jwtManager, appService)
cpb.RegisterCoreServiceServer(s, northbound.Core) cpb.RegisterCoreServiceServer(s, northbound.Core)
ppb.RegisterPndServiceServer(s, northbound.Pnd) ppb.RegisterPndServiceServer(s, northbound.Pnd)
......
...@@ -19,11 +19,15 @@ import ( ...@@ -19,11 +19,15 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/credentials/insecure"
apppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/app"
pb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/core" pb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/core"
cpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/csbi" cpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/csbi"
ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd" ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac" apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac"
spb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/southbound" spb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/southbound"
"code.fbi.h-da.de/danet/gosdn/controller/app"
apps "code.fbi.h-da.de/danet/gosdn/controller/app"
"code.fbi.h-da.de/danet/gosdn/controller/config" "code.fbi.h-da.de/danet/gosdn/controller/config"
eventservice "code.fbi.h-da.de/danet/gosdn/controller/eventService" eventservice "code.fbi.h-da.de/danet/gosdn/controller/eventService"
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/device" "code.fbi.h-da.de/danet/gosdn/controller/interfaces/device"
...@@ -51,6 +55,7 @@ type Core struct { ...@@ -51,6 +55,7 @@ type Core struct {
grpcServer *grpc.Server grpcServer *grpc.Server
nbi *nbi.NorthboundInterface nbi *nbi.NorthboundInterface
eventService eventInterfaces.Service eventService eventInterfaces.Service
appService app.IService
stopChan chan os.Signal stopChan chan os.Signal
csbiClient cpb.CsbiServiceClient csbiClient cpb.CsbiServiceClient
...@@ -75,6 +80,7 @@ func initialize() error { ...@@ -75,6 +80,7 @@ func initialize() error {
userService: rbacImpl.NewUserService(rbacImpl.NewUserStore(), eventService), userService: rbacImpl.NewUserService(rbacImpl.NewUserStore(), eventService),
roleService: rbacImpl.NewRoleService(rbacImpl.NewRoleStore(), eventService), roleService: rbacImpl.NewRoleService(rbacImpl.NewRoleStore(), eventService),
eventService: eventService, eventService: eventService,
appService: apps.NewAppService(apps.NewAppStore()),
stopChan: make(chan os.Signal, 1), stopChan: make(chan os.Signal, 1),
} }
...@@ -118,7 +124,7 @@ func startGrpc() error { ...@@ -118,7 +124,7 @@ func startGrpc() error {
jwtManager := rbacImpl.NewJWTManager(config.JWTSecret, config.JWTDuration) jwtManager := rbacImpl.NewJWTManager(config.JWTSecret, config.JWTDuration)
setupGRPCServerWithCorrectSecurityLevel(jwtManager, c.userService, c.roleService) setupGRPCServerWithCorrectSecurityLevel(jwtManager, c.userService, c.roleService)
c.nbi = nbi.NewNBI(c.pndStore, c.userService, c.roleService, *jwtManager) c.nbi = nbi.NewNBI(c.pndStore, c.userService, c.roleService, *jwtManager, c.appService)
pb.RegisterCoreServiceServer(c.grpcServer, c.nbi.Core) pb.RegisterCoreServiceServer(c.grpcServer, c.nbi.Core)
ppb.RegisterPndServiceServer(c.grpcServer, c.nbi.Pnd) ppb.RegisterPndServiceServer(c.grpcServer, c.nbi.Pnd)
...@@ -127,6 +133,8 @@ func startGrpc() error { ...@@ -127,6 +133,8 @@ func startGrpc() error {
apb.RegisterAuthServiceServer(c.grpcServer, c.nbi.Auth) apb.RegisterAuthServiceServer(c.grpcServer, c.nbi.Auth)
apb.RegisterUserServiceServer(c.grpcServer, c.nbi.User) apb.RegisterUserServiceServer(c.grpcServer, c.nbi.User)
apb.RegisterRoleServiceServer(c.grpcServer, c.nbi.Role) apb.RegisterRoleServiceServer(c.grpcServer, c.nbi.Role)
apppb.RegisterAppServiceServer(c.grpcServer, c.nbi.App)
go func() { go func() {
if err := c.grpcServer.Serve(lislisten); err != nil { if err := c.grpcServer.Serve(lislisten); err != nil {
log.Fatal(err) log.Fatal(err)
......
package server
import (
"context"
"time"
apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/app"
"code.fbi.h-da.de/danet/gosdn/controller/app"
)
// App represents a AppServiceServer.
type App struct {
apb.UnimplementedAppServiceServer
appService app.IService
}
// NewAppServer creates a new AppServiceServer.
func NewAppServer(appService app.IService) *App {
return &App{
appService: appService,
}
}
// Register checks if the app already exists and if not creates a new one.
func (a *App) Register(ctx context.Context, request *apb.AppRegisterRequest) (*apb.AppRegisterResponse, error) {
app, err := a.appService.Register(request.Appname, request.Token)
if err != nil {
return &apb.AppRegisterResponse{
Timestamp: time.Now().UnixNano(),
Status: apb.Status_STATUS_ERROR,
}, err
}
return &apb.AppRegisterResponse{
Timestamp: time.Now().UnixNano(),
Status: apb.Status_STATUS_OK,
Queueconnection: app.GetCredentials(),
}, nil
}
// Deregister deregisters an app.
func (a *App) Deregister(ctx context.Context, request *apb.AppDeregisterRequest) (*apb.AppDeregisterResponse, error) {
err := a.appService.Deregister(request.Appname)
if err != nil {
return &apb.AppDeregisterResponse{
Timestamp: time.Now().UnixNano(),
Status: apb.Status_STATUS_ERROR,
}, err
}
return &apb.AppDeregisterResponse{
Timestamp: time.Now().UnixNano(),
Status: apb.Status_STATUS_OK,
}, nil
}
package server package server
import ( import (
"code.fbi.h-da.de/danet/gosdn/controller/app"
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/networkdomain" "code.fbi.h-da.de/danet/gosdn/controller/interfaces/networkdomain"
rbacInterfaces "code.fbi.h-da.de/danet/gosdn/controller/interfaces/rbac" rbacInterfaces "code.fbi.h-da.de/danet/gosdn/controller/interfaces/rbac"
"code.fbi.h-da.de/danet/gosdn/controller/rbac" "code.fbi.h-da.de/danet/gosdn/controller/rbac"
...@@ -22,10 +23,17 @@ type NorthboundInterface struct { ...@@ -22,10 +23,17 @@ type NorthboundInterface struct {
Auth *Auth Auth *Auth
User *User User *User
Role *Role Role *Role
App *App
} }
// NewNBI receives a PndStore and returns a new gRPC *NorthboundInterface // NewNBI receives a PndStore and returns a new gRPC *NorthboundInterface
func NewNBI(pnds networkdomain.PndStore, users rbacInterfaces.UserService, roles rbacInterfaces.RoleService, jwt rbac.JWTManager) *NorthboundInterface { func NewNBI(
pnds networkdomain.PndStore,
users rbacInterfaces.UserService,
roles rbacInterfaces.RoleService,
jwt rbac.JWTManager,
apps app.IService,
) *NorthboundInterface {
return &NorthboundInterface{ return &NorthboundInterface{
Pnd: NewPndServer(pnds), Pnd: NewPndServer(pnds),
Core: NewCoreServer(pnds), Core: NewCoreServer(pnds),
...@@ -34,6 +42,7 @@ func NewNBI(pnds networkdomain.PndStore, users rbacInterfaces.UserService, roles ...@@ -34,6 +42,7 @@ func NewNBI(pnds networkdomain.PndStore, users rbacInterfaces.UserService, roles
Auth: NewAuthServer(&jwt, users), Auth: NewAuthServer(&jwt, users),
User: NewUserServer(&jwt, users), User: NewUserServer(&jwt, users),
Role: NewRoleServer(&jwt, roles), Role: NewRoleServer(&jwt, roles),
App: NewAppServer(apps),
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment