forked from pachyderm/pachyderm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
94 lines (84 loc) · 2.92 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package server
import (
pfsclient "github.com/pachyderm/pachyderm/src/client/pfs"
"github.com/pachyderm/pachyderm/src/server/pkg/obj"
)
// Valid object storage backends
const (
MinioBackendEnvVar = "MINIO"
AmazonBackendEnvVar = "AMAZON"
GoogleBackendEnvVar = "GOOGLE"
MicrosoftBackendEnvVar = "MICROSOFT"
)
var (
blockSize = 8 * 1024 * 1024 // 8 Megabytes
// maxBlockSize specifies the maximum block size for any data type
maxBlockSize = 100 * 1024 * 1024 // 100 MB
)
// APIServer represents and api server.
type APIServer interface {
pfsclient.APIServer
}
// BlockAPIServer combines BlockAPIServer and ObjectAPIServer.
type BlockAPIServer interface {
pfsclient.ObjectAPIServer
}
// NewAPIServer creates an APIServer.
// cacheSize is the number of commit trees which will be cached in the server.
func NewAPIServer(address string, etcdAddresses []string, etcdPrefix string, cacheSize int64) (APIServer, error) {
return newAPIServer(address, etcdAddresses, etcdPrefix, cacheSize)
}
// NewHTTPServer creates an APIServer.
// cacheSize is the number of commit trees which will be cached in the server.
func NewHTTPServer(address string, etcdAddresses []string, etcdPrefix string, cacheSize int64) (*HTTPServer, error) {
return newHTTPServer(address, etcdAddresses, etcdPrefix, cacheSize)
}
// NewLocalBlockAPIServer creates a BlockAPIServer.
func NewLocalBlockAPIServer(dir string) (BlockAPIServer, error) {
return newLocalBlockAPIServer(dir)
}
// NewObjBlockAPIServer create a BlockAPIServer from an obj.Client.
func NewObjBlockAPIServer(dir string, cacheBytes int64, etcdAddress string, objClient obj.Client) (BlockAPIServer, error) {
return newObjBlockAPIServer(dir, cacheBytes, etcdAddress, objClient)
}
// NewBlockAPIServer creates a BlockAPIServer using the credentials it finds in
// the environment
func NewBlockAPIServer(dir string, cacheBytes int64, backend string, etcdAddress string) (BlockAPIServer, error) {
switch backend {
case MinioBackendEnvVar:
// S3 compatible doesn't like leading slashes
if len(dir) > 0 && dir[0] == '/' {
dir = dir[1:]
}
blockAPIServer, err := newMinioBlockAPIServer(dir, cacheBytes, etcdAddress)
if err != nil {
return nil, err
}
return blockAPIServer, nil
case AmazonBackendEnvVar:
// amazon doesn't like leading slashes
if len(dir) > 0 && dir[0] == '/' {
dir = dir[1:]
}
blockAPIServer, err := newAmazonBlockAPIServer(dir, cacheBytes, etcdAddress)
if err != nil {
return nil, err
}
return blockAPIServer, nil
case GoogleBackendEnvVar:
// TODO figure out if google likes leading slashses
blockAPIServer, err := newGoogleBlockAPIServer(dir, cacheBytes, etcdAddress)
if err != nil {
return nil, err
}
return blockAPIServer, nil
case MicrosoftBackendEnvVar:
blockAPIServer, err := newMicrosoftBlockAPIServer(dir, cacheBytes, etcdAddress)
if err != nil {
return nil, err
}
return blockAPIServer, nil
default:
return NewLocalBlockAPIServer(dir)
}
}