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

Implement app NBI

parent 90ba7258
Branches
Tags
2 merge requests!376Add additional example application hostname-checker,!343Add basic application framework and example application to show interaction between events an NBI
......@@ -12,6 +12,7 @@ import (
ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac"
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"
eventservice "code.fbi.h-da.de/danet/gosdn/controller/eventService"
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/device"
......@@ -144,8 +145,9 @@ func bootstrapUnitTest() {
}
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)
ppb.RegisterPndServiceServer(s, northbound.Pnd)
......
......@@ -19,11 +19,15 @@ import (
"google.golang.org/grpc"
"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"
cpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/csbi"
ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac"
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"
eventservice "code.fbi.h-da.de/danet/gosdn/controller/eventService"
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/device"
......@@ -51,6 +55,7 @@ type Core struct {
grpcServer *grpc.Server
nbi *nbi.NorthboundInterface
eventService eventInterfaces.Service
appService app.IService
stopChan chan os.Signal
csbiClient cpb.CsbiServiceClient
......@@ -75,6 +80,7 @@ func initialize() error {
userService: rbacImpl.NewUserService(rbacImpl.NewUserStore(), eventService),
roleService: rbacImpl.NewRoleService(rbacImpl.NewRoleStore(), eventService),
eventService: eventService,
appService: apps.NewAppService(apps.NewAppStore()),
stopChan: make(chan os.Signal, 1),
}
......@@ -118,7 +124,7 @@ func startGrpc() error {
jwtManager := rbacImpl.NewJWTManager(config.JWTSecret, config.JWTDuration)
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)
ppb.RegisterPndServiceServer(c.grpcServer, c.nbi.Pnd)
......@@ -127,6 +133,8 @@ func startGrpc() error {
apb.RegisterAuthServiceServer(c.grpcServer, c.nbi.Auth)
apb.RegisterUserServiceServer(c.grpcServer, c.nbi.User)
apb.RegisterRoleServiceServer(c.grpcServer, c.nbi.Role)
apppb.RegisterAppServiceServer(c.grpcServer, c.nbi.App)
go func() {
if err := c.grpcServer.Serve(lislisten); err != nil {
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
import (
"code.fbi.h-da.de/danet/gosdn/controller/app"
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/networkdomain"
rbacInterfaces "code.fbi.h-da.de/danet/gosdn/controller/interfaces/rbac"
"code.fbi.h-da.de/danet/gosdn/controller/rbac"
......@@ -22,10 +23,17 @@ type NorthboundInterface struct {
Auth *Auth
User *User
Role *Role
App *App
}
// 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{
Pnd: NewPndServer(pnds),
Core: NewCoreServer(pnds),
......@@ -34,6 +42,7 @@ func NewNBI(pnds networkdomain.PndStore, users rbacInterfaces.UserService, roles
Auth: NewAuthServer(&jwt, users),
User: NewUserServer(&jwt, users),
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