Skip to content

Commit

Permalink
feat: run http bridge for storage
Browse files Browse the repository at this point in the history
Signed-off-by: Artsiom Koltun <artsiom.koltun@intel.com>
  • Loading branch information
artek-koltun committed Feb 6, 2024
1 parent b03c522 commit 249638d
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,19 @@ func runGatewayServer(grpcPort int, httpPort int) {
// Note: Make sure the gRPC server is running properly and accessible
mux := runtime.NewServeMux()
opts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
err := pc.RegisterInventoryServiceHandlerFromEndpoint(ctx, mux, fmt.Sprintf(":%d", grpcPort), opts)
if err != nil {
log.Panic("cannot register handler server")
}
endpoint := fmt.Sprintf("localhost:%d", grpcPort)
registerGatewayHandler(ctx, mux, endpoint, opts, pc.RegisterInventoryServiceHandlerFromEndpoint, "inventory")

registerGatewayHandler(ctx, mux, endpoint, opts, pb.RegisterAioVolumeServiceHandlerFromEndpoint, "backend aio")
registerGatewayHandler(ctx, mux, endpoint, opts, pb.RegisterNullVolumeServiceHandlerFromEndpoint, "backend null")
registerGatewayHandler(ctx, mux, endpoint, opts, pb.RegisterNvmeRemoteControllerServiceHandlerFromEndpoint, "backend nvme")

registerGatewayHandler(ctx, mux, endpoint, opts, pb.RegisterMiddleendEncryptionServiceHandlerFromEndpoint, "middleend encryption")
registerGatewayHandler(ctx, mux, endpoint, opts, pb.RegisterMiddleendQosVolumeServiceHandlerFromEndpoint, "middleend qos")

registerGatewayHandler(ctx, mux, endpoint, opts, pb.RegisterFrontendVirtioBlkServiceHandlerFromEndpoint, "frontend virtio-blk")
registerGatewayHandler(ctx, mux, endpoint, opts, pb.RegisterFrontendVirtioScsiServiceHandlerFromEndpoint, "frontend virtio-scsi")
registerGatewayHandler(ctx, mux, endpoint, opts, pb.RegisterFrontendNvmeServiceHandlerFromEndpoint, "frontend nvme")

// Start HTTP server (and proxy calls to gRPC server endpoint)
log.Printf("HTTP Server listening at %v", httpPort)
Expand All @@ -168,8 +177,17 @@ func runGatewayServer(grpcPort int, httpPort int) {
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
}
err = server.ListenAndServe()
err := server.ListenAndServe()
if err != nil {
log.Panic("cannot start HTTP gateway server")
}
}

type registerHandlerFunc func(context.Context, *runtime.ServeMux, string, []grpc.DialOption) error

func registerGatewayHandler(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption, registerFunc registerHandlerFunc, serviceName string) {
err := registerFunc(ctx, mux, endpoint, opts)
if err != nil {
log.Panicf("cannot register %s handler server: %v", serviceName, err)
}
}

0 comments on commit 249638d

Please sign in to comment.