Skip to content
Snippets Groups Projects
nbi.go 3.73 KiB
Newer Older
  • Learn to ignore specific revisions
  • Manuel Kieweg's avatar
    Manuel Kieweg committed
    package server
    
    import (
    
    	cpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/csbi"
    	rpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/plugin-registry"
    
    	"code.fbi.h-da.de/danet/gosdn/controller/interfaces/networkdomain"
    
    	"code.fbi.h-da.de/danet/gosdn/controller/interfaces/networkelement"
    	"code.fbi.h-da.de/danet/gosdn/controller/interfaces/plugin"
    
    	rbacInterfaces "code.fbi.h-da.de/danet/gosdn/controller/interfaces/rbac"
    
    	"code.fbi.h-da.de/danet/gosdn/controller/nucleus"
    
    	"code.fbi.h-da.de/danet/gosdn/controller/rbac"
    
    	"code.fbi.h-da.de/danet/gosdn/controller/store"
    
    	"code.fbi.h-da.de/danet/gosdn/controller/topology"
    	"code.fbi.h-da.de/danet/gosdn/controller/topology/nodes"
    	"code.fbi.h-da.de/danet/gosdn/controller/topology/ports"
    
    	routingtables "code.fbi.h-da.de/danet/gosdn/controller/topology/routing-tables"
    
    	"code.fbi.h-da.de/danet/gosdn/controller/metrics"
    
    	"github.com/bufbuild/protovalidate-go"
    
    Malte Bauch's avatar
    Malte Bauch committed
    	"github.com/prometheus/client_golang/prometheus"
    	log "github.com/sirupsen/logrus"
    	"google.golang.org/grpc/codes"
    	"google.golang.org/grpc/status"
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    // NorthboundInterface is the representation of the
    // gRPC services used provided.
    type NorthboundInterface struct {
    
    	Pnd                     *PndServer
    	Csbi                    *CsbiServer
    
    	Auth                    *AuthServer
    	User                    *UserServer
    	Role                    *RoleServer
    	Topology                *TopologyServer
    	App                     *AppServer
    	NetworkElement          *NetworkElementServer
    	Routes                  *RoutingTableServiceServer
    	ConfigurationManagement *ConfigurationManagementServer
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    }
    
    
    // NewNBI receives a PndStore and returns a new gRPC *NorthboundInterface.
    
    func NewNBI(
    	pnds networkdomain.PndStore,
    
    	pndService networkdomain.Service,
    	mneService networkelement.Service,
    	changeStore store.ChangeStore,
    
    	users rbacInterfaces.UserService,
    	roles rbacInterfaces.RoleService,
    	jwt rbac.JWTManager,
    	topologyService topology.Service,
    	nodeService nodes.Service,
    	portService ports.Service,
    
    	routeService routingtables.Service,
    	apps app.ManagementService,
    
    	pluginService plugin.Service,
    	pluginRegistryClient rpb.PluginRegistryServiceClient,
    	csbiClient cpb.CsbiServiceClient,
    	pndCallbackFn func(uuid.UUID, chan networkelement.Details),
    
    	networkElementWatchter *nucleus.NetworkElementWatcher,
    
    ) *NorthboundInterface {
    
    	protoValidator, err := protovalidate.New()
    	if err != nil {
    		panic(err)
    	}
    
    
    Manuel Kieweg's avatar
    Manuel Kieweg committed
    	return &NorthboundInterface{
    
    		Pnd:                     NewPndServer(pndService, pluginService, pndCallbackFn, csbiClient, protoValidator),
    		Csbi:                    NewCsbiServer(pnds, protoValidator),
    		Plugin:                  NewPluginInternalServer(pluginRegistryClient, pluginService, protoValidator),
    		Auth:                    NewAuthServer(&jwt, users, protoValidator),
    		User:                    NewUserServer(&jwt, users, protoValidator),
    		Role:                    NewRoleServer(&jwt, roles, protoValidator),
    		Topology:                NewTopologyServer(topologyService, nodeService, portService, protoValidator),
    		App:                     NewAppServer(apps, protoValidator),
    
    		NetworkElement:          NewNetworkElementServer(mneService, pndService, pluginService, changeStore, protoValidator, networkElementWatchter),
    
    		Routes:                  NewRoutingTableServiceServer(routeService, nodeService, portService, protoValidator),
    		ConfigurationManagement: NewConfigurationManagementServer(pndService, mneService, topologyService, nodeService, portService, pluginService, protoValidator),
    
    Malte Bauch's avatar
    Malte Bauch committed
    
    func handleRPCError(labels prometheus.Labels, err error) error {
    	log.Error(err)
    	return status.Errorf(codes.Aborted, "%v", metrics.HandleError(labels, err, grpcAPIErrorsTotal))
    }