seaweedfs-csi-driver/pkg/driver/utils.go
2020-06-12 00:57:01 -07:00

61 lines
1.4 KiB
Go

package driver
import (
"fmt"
"strings"
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/chrislusf/seaweedfs/weed/glog"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
func NewNodeServer(n *SeaweedFsDriver) *NodeServer {
return &NodeServer{
Driver: n,
}
}
func NewIdentityServer(d *SeaweedFsDriver) *IdentityServer {
return &IdentityServer{
Driver: d,
}
}
func NewControllerServer(d *SeaweedFsDriver) *ControllerServer {
return &ControllerServer{
Driver: d,
}
}
func NewControllerServiceCapability(cap csi.ControllerServiceCapability_RPC_Type) *csi.ControllerServiceCapability {
return &csi.ControllerServiceCapability{
Type: &csi.ControllerServiceCapability_Rpc{
Rpc: &csi.ControllerServiceCapability_RPC{
Type: cap,
},
},
}
}
func ParseEndpoint(ep string) (string, string, error) {
if strings.HasPrefix(strings.ToLower(ep), "unix://") || strings.HasPrefix(strings.ToLower(ep), "tcp://") {
s := strings.SplitN(ep, "://", 2)
if s[1] != "" {
return s[0], s[1], nil
}
}
return "", "", fmt.Errorf("Invalid endpoint: %v", ep)
}
func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
glog.V(3).Infof("GRPC %s request %+v", info.FullMethod, req)
resp, err := handler(ctx, req)
if err != nil {
glog.Errorf("GRPC error: %v", err)
}
glog.V(3).Infof("GRPC %s response %+v", info.FullMethod, resp)
return resp, err
}