Skip to content

Commit

Permalink
List: generate NextPageToken
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <[email protected]>
  • Loading branch information
glimchb committed Apr 10, 2023
1 parent 5b62856 commit 01088b5
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.19

require (
github.com/digitalocean/go-qemu v0.0.0-20221209210016-f035778c97f7
github.com/google/uuid v1.3.0
github.com/opiproject/opi-api v0.0.0-20230404182329-b6f178ec8cfa
github.com/ulule/deepcopier v0.0.0-20200430083143-45decc6639b6
google.golang.org/grpc v1.54.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/opiproject/opi-api v0.0.0-20230111150933-e4b3480e8ee9 h1:Y/0Ku5yIfnLEnLa9jzYCK/7l85CHQVefs0PnaXFX+v0=
github.com/opiproject/opi-api v0.0.0-20230111150933-e4b3480e8ee9/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY=
github.com/opiproject/opi-api v0.0.0-20230123165122-10e47bafd42b h1:Ho6qkBoU1vfqERZbih+Hmn7Y1lsx14YtOiqMl4lzdF4=
Expand Down
5 changes: 4 additions & 1 deletion pkg/backend/aio.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
pb "github.com/opiproject/opi-api/storage/v1alpha1/gen/go"
"github.com/opiproject/opi-spdk-bridge/pkg/models"

"github.com/google/uuid"
"github.com/ulule/deepcopier"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -148,16 +149,18 @@ func (s *Server) ListAioControllers(_ context.Context, in *pb.ListAioControllers
return nil, err
}
log.Printf("Received from SPDK: %v", result)
var token string
if in.PageSize > 0 && int(in.PageSize) < len(result) {
log.Printf("Limiting result to: %d", in.PageSize)
result = result[:in.PageSize]
token = uuid.New().String()
}
Blobarray := make([]*pb.AioController, len(result))
for i := range result {
r := &result[i]
Blobarray[i] = &pb.AioController{Handle: &pc.ObjectKey{Value: r.Name}, BlockSize: r.BlockSize, BlocksCount: r.NumBlocks}
}
return &pb.ListAioControllersResponse{AioControllers: Blobarray}, nil
return &pb.ListAioControllersResponse{AioControllers: Blobarray, NextPageToken: token}, nil
}

// GetAioController gets an Aio controller
Expand Down
5 changes: 4 additions & 1 deletion pkg/backend/null.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
pb "github.com/opiproject/opi-api/storage/v1alpha1/gen/go"
"github.com/opiproject/opi-spdk-bridge/pkg/models"

"github.com/google/uuid"
"github.com/ulule/deepcopier"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -148,16 +149,18 @@ func (s *Server) ListNullDebugs(_ context.Context, in *pb.ListNullDebugsRequest)
return nil, err
}
log.Printf("Received from SPDK: %v", result)
var token string
if in.PageSize > 0 && int(in.PageSize) < len(result) {
log.Printf("Limiting result to: %d", in.PageSize)
result = result[:in.PageSize]
token = uuid.New().String()
}
Blobarray := make([]*pb.NullDebug, len(result))
for i := range result {
r := &result[i]
Blobarray[i] = &pb.NullDebug{Handle: &pc.ObjectKey{Value: r.Name}, Uuid: &pc.Uuid{Value: r.UUID}, BlockSize: r.BlockSize, BlocksCount: r.NumBlocks}
}
return &pb.ListNullDebugsResponse{NullDebugs: Blobarray}, nil
return &pb.ListNullDebugsResponse{NullDebugs: Blobarray, NextPageToken: token}, nil
}

// GetNullDebug gets a a Null Debug instance
Expand Down
5 changes: 4 additions & 1 deletion pkg/backend/nvme.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
pb "github.com/opiproject/opi-api/storage/v1alpha1/gen/go"
"github.com/opiproject/opi-spdk-bridge/pkg/models"

"github.com/google/uuid"
"github.com/ulule/deepcopier"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -110,9 +111,11 @@ func (s *Server) ListNVMfRemoteControllers(_ context.Context, in *pb.ListNVMfRem
return nil, err
}
log.Printf("Received from SPDK: %v", result)
var token string
if in.PageSize > 0 && int(in.PageSize) < len(result) {
log.Printf("Limiting result to: %d", in.PageSize)
result = result[:in.PageSize]
token = uuid.New().String()
}
Blobarray := make([]*pb.NVMfRemoteController, len(result))
for i := range result {
Expand All @@ -128,7 +131,7 @@ func (s *Server) ListNVMfRemoteControllers(_ context.Context, in *pb.ListNVMfRem
Trsvcid: port,
}
}
return &pb.ListNVMfRemoteControllersResponse{NvMfRemoteControllers: Blobarray}, nil
return &pb.ListNVMfRemoteControllersResponse{NvMfRemoteControllers: Blobarray, NextPageToken: token}, nil
}

// GetNVMfRemoteController gets an NVMf remote controller
Expand Down
5 changes: 4 additions & 1 deletion pkg/frontend/blk.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"log"

"github.com/google/uuid"
pc "github.com/opiproject/opi-api/common/v1/gen/go"
pb "github.com/opiproject/opi-api/storage/v1alpha1/gen/go"
"github.com/opiproject/opi-spdk-bridge/pkg/models"
Expand Down Expand Up @@ -107,9 +108,11 @@ func (s *Server) ListVirtioBlks(_ context.Context, in *pb.ListVirtioBlksRequest)
return nil, err
}
log.Printf("Received from SPDK: %v", result)
var token string
if in.PageSize > 0 && int(in.PageSize) < len(result) {
log.Printf("Limiting result to: %d", in.PageSize)
result = result[:in.PageSize]
token = uuid.New().String()
}
Blobarray := make([]*pb.VirtioBlk, len(result))
for i := range result {
Expand All @@ -119,7 +122,7 @@ func (s *Server) ListVirtioBlks(_ context.Context, in *pb.ListVirtioBlksRequest)
PcieId: &pb.PciEndpoint{PhysicalFunction: 1},
VolumeId: &pc.ObjectKey{Value: "TBD"}}
}
return &pb.ListVirtioBlksResponse{VirtioBlks: Blobarray}, nil
return &pb.ListVirtioBlksResponse{VirtioBlks: Blobarray, NextPageToken: token}, nil
}

// GetVirtioBlk gets a Virtio block device
Expand Down
12 changes: 9 additions & 3 deletions pkg/frontend/nvme.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
pb "github.com/opiproject/opi-api/storage/v1alpha1/gen/go"
"github.com/opiproject/opi-spdk-bridge/pkg/models"

"github.com/google/uuid"
"github.com/ulule/deepcopier"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -172,16 +173,18 @@ func (s *Server) ListNVMeSubsystems(_ context.Context, in *pb.ListNVMeSubsystems
return nil, err
}
log.Printf("Received from SPDK: %v", result)
var token string
if in.PageSize > 0 && int(in.PageSize) < len(result) {
log.Printf("Limiting result to: %d", in.PageSize)
result = result[:in.PageSize]
token = uuid.New().String()
}
Blobarray := make([]*pb.NVMeSubsystem, len(result))
for i := range result {
r := &result[i]
Blobarray[i] = &pb.NVMeSubsystem{Spec: &pb.NVMeSubsystemSpec{Nqn: r.Nqn, SerialNumber: r.SerialNumber, ModelNumber: r.ModelNumber}}
}
return &pb.ListNVMeSubsystemsResponse{NvMeSubsystems: Blobarray}, nil
return &pb.ListNVMeSubsystemsResponse{NvMeSubsystems: Blobarray, NextPageToken: token}, nil
}

// GetNVMeSubsystem gets NVMe Subsystems
Expand Down Expand Up @@ -325,7 +328,8 @@ func (s *Server) ListNVMeControllers(_ context.Context, in *pb.ListNVMeControlle
for _, controller := range s.Nvme.Controllers {
Blobarray = append(Blobarray, controller)
}
return &pb.ListNVMeControllersResponse{NvMeControllers: Blobarray}, nil
token := uuid.New().String()
return &pb.ListNVMeControllersResponse{NvMeControllers: Blobarray, NextPageToken: token}, nil
}

// GetNVMeController gets an NVMe controller
Expand Down Expand Up @@ -474,6 +478,7 @@ func (s *Server) ListNVMeNamespaces(_ context.Context, in *pb.ListNVMeNamespaces
return nil, err
}
log.Printf("Received from SPDK: %v", result)
var token string
Blobarray := []*pb.NVMeNamespace{}
for i := range result {
rr := &result[i]
Expand All @@ -489,7 +494,8 @@ func (s *Server) ListNVMeNamespaces(_ context.Context, in *pb.ListNVMeNamespaces
}
}
if len(Blobarray) > 0 {
return &pb.ListNVMeNamespacesResponse{NvMeNamespaces: Blobarray}, nil
token = uuid.New().String()
return &pb.ListNVMeNamespacesResponse{NvMeNamespaces: Blobarray, NextPageToken: token}, nil
}

msg := fmt.Sprintf("Could not find any namespaces for NQN: %s", nqn)
Expand Down
9 changes: 7 additions & 2 deletions pkg/frontend/scsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
pb "github.com/opiproject/opi-api/storage/v1alpha1/gen/go"
"github.com/opiproject/opi-spdk-bridge/pkg/models"

"github.com/google/uuid"
"github.com/ulule/deepcopier"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -85,16 +86,18 @@ func (s *Server) ListVirtioScsiControllers(_ context.Context, in *pb.ListVirtioS
return nil, err
}
log.Printf("Received from SPDK: %v", result)
var token string
if in.PageSize > 0 && int(in.PageSize) < len(result) {
log.Printf("Limiting result to: %d", in.PageSize)
result = result[:in.PageSize]
token = uuid.New().String()
}
Blobarray := make([]*pb.VirtioScsiController, len(result))
for i := range result {
r := &result[i]
Blobarray[i] = &pb.VirtioScsiController{Id: &pc.ObjectKey{Value: r.Ctrlr}}
}
return &pb.ListVirtioScsiControllersResponse{VirtioScsiControllers: Blobarray}, nil
return &pb.ListVirtioScsiControllersResponse{VirtioScsiControllers: Blobarray, NextPageToken: token}, nil
}

// GetVirtioScsiController gets a Virtio SCSI controller
Expand Down Expand Up @@ -190,16 +193,18 @@ func (s *Server) ListVirtioScsiLuns(_ context.Context, in *pb.ListVirtioScsiLuns
return nil, err
}
log.Printf("Received from SPDK: %v", result)
var token string
if in.PageSize > 0 && int(in.PageSize) < len(result) {
log.Printf("Limiting result to: %d", in.PageSize)
result = result[:in.PageSize]
token = uuid.New().String()
}
Blobarray := make([]*pb.VirtioScsiLun, len(result))
for i := range result {
r := &result[i]
Blobarray[i] = &pb.VirtioScsiLun{VolumeId: &pc.ObjectKey{Value: r.Ctrlr}}
}
return &pb.ListVirtioScsiLunsResponse{VirtioScsiLuns: Blobarray}, nil
return &pb.ListVirtioScsiLunsResponse{VirtioScsiLuns: Blobarray, NextPageToken: token}, nil
}

// GetVirtioScsiLun gets a Virtio SCSI LUN
Expand Down
5 changes: 4 additions & 1 deletion pkg/middleend/middleend.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/opiproject/opi-spdk-bridge/pkg/models"
"github.com/opiproject/opi-spdk-bridge/pkg/server"

"github.com/google/uuid"
"github.com/ulule/deepcopier"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -219,16 +220,18 @@ func (s *Server) ListEncryptedVolumes(_ context.Context, in *pb.ListEncryptedVol
return nil, err
}
log.Printf("Received from SPDK: %v", result)
var token string
if in.PageSize > 0 && int(in.PageSize) < len(result) {
log.Printf("Limiting result to: %d", in.PageSize)
result = result[:in.PageSize]
token = uuid.New().String()
}
Blobarray := make([]*pb.EncryptedVolume, len(result))
for i := range result {
r := &result[i]
Blobarray[i] = &pb.EncryptedVolume{EncryptedVolumeId: &pc.ObjectKey{Value: r.Name}}
}
return &pb.ListEncryptedVolumesResponse{EncryptedVolumes: Blobarray}, nil
return &pb.ListEncryptedVolumesResponse{EncryptedVolumes: Blobarray, NextPageToken: token}, nil
}

// GetEncryptedVolume gets an encrypted volume
Expand Down

0 comments on commit 01088b5

Please sign in to comment.