diff --git a/controller/api/initialise_test.go b/controller/api/initialise_test.go index 46726014e7acdd5493f6de98a6caea0e3b71f714..94299cd84a7c3a338567b4e3a52b1752ff93c569 100644 --- a/controller/api/initialise_test.go +++ b/controller/api/initialise_test.go @@ -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) diff --git a/controller/controller.go b/controller/controller.go index a1a8333c6a01fc30d5709ca918d05114423cbe0b..96031a6f81f5ba533b5f8225152f8b618d2e8ef5 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -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) diff --git a/controller/northbound/server/app.go b/controller/northbound/server/app.go new file mode 100644 index 0000000000000000000000000000000000000000..dfde32c3aabaa4d4dc01f4b614dc766576ddd061 --- /dev/null +++ b/controller/northbound/server/app.go @@ -0,0 +1,55 @@ +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 +} diff --git a/controller/northbound/server/nbi.go b/controller/northbound/server/nbi.go index cd4e983516f8ef4d498ebdf7fb956333e796a0be..5b8262d010cd590d48d1c1cef97014e7b4cb1063 100644 --- a/controller/northbound/server/nbi.go +++ b/controller/northbound/server/nbi.go @@ -1,6 +1,7 @@ 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), } }