61 lines
1.4 KiB
Go
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/util/log"
|
|
"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) {
|
|
log.Tracef("GRPC %s request %+v", info.FullMethod, req)
|
|
resp, err := handler(ctx, req)
|
|
if err != nil {
|
|
log.Errorf("GRPC error: %v", err)
|
|
}
|
|
log.Tracef("GRPC %s response %+v", info.FullMethod, resp)
|
|
return resp, err
|
|
}
|