1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
13 "git.curoverse.com/arvados.git/sdk/go/config"
16 const DefaultConfigFile = "/etc/arvados/config.yml"
19 Clusters map[string]Cluster
22 // GetConfig returns the current system config, loading it from
23 // configFile if needed.
24 func GetConfig(configFile string) (*Config, error) {
26 err := config.LoadFile(&cfg, configFile)
30 // GetCluster returns the cluster ID and config for the given
31 // cluster, or the default/only configured cluster if clusterID is "".
32 func (sc *Config) GetCluster(clusterID string) (*Cluster, error) {
34 if len(sc.Clusters) == 0 {
35 return nil, fmt.Errorf("no clusters configured")
36 } else if len(sc.Clusters) > 1 {
37 return nil, fmt.Errorf("multiple clusters configured, cannot choose")
39 for id, cc := range sc.Clusters {
45 if cc, ok := sc.Clusters[clusterID]; !ok {
46 return nil, fmt.Errorf("cluster %q is not configured", clusterID)
48 cc.ClusterID = clusterID
54 MaxItemsPerResponse int
55 MaxRequestAmplification int
56 RequestTimeout Duration
60 ClusterID string `json:"-"`
61 ManagementToken string
62 SystemRootToken string
64 InstanceTypes InstanceTypeMap
65 Containers ContainersConfig
66 RemoteClusters map[string]RemoteCluster
73 type Services struct {
89 InternalURLs map[URL]ServiceInstance `json:",omitempty"`
93 // URL is a url.URL that is also usable as a JSON key/value.
96 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
97 // used as a JSON key/value.
98 func (su *URL) UnmarshalText(text []byte) error {
99 u, err := url.Parse(string(text))
106 func (su URL) MarshalText() ([]byte, error) {
107 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
110 type ServiceInstance struct{}
112 type SystemLogs struct {
115 MaxRequestLogParamsSize int
118 type PostgreSQL struct {
119 Connection PostgreSQLConnection
123 type PostgreSQLConnection map[string]string
125 type RemoteCluster struct {
126 // API endpoint host or host:port; default is {id}.arvadosapi.com
128 // Perform a proxy request when a local client requests an
129 // object belonging to this remote.
131 // Scheme, default "https". Can be set to "http" for testing.
133 // Disable TLS verify. Can be set to true for testing.
137 type InstanceType struct {
143 IncludedScratch ByteSize
144 AddedScratch ByteSize
149 type ContainersConfig struct {
150 CloudVMs CloudVMsConfig
151 DispatchPrivateKey string
152 StaleLockTimeout Duration
155 type CloudVMsConfig struct {
158 BootProbeCommand string
160 MaxCloudOpsPerSecond int
161 MaxProbesPerSecond int
162 PollInterval Duration
163 ProbeInterval Duration
165 SyncInterval Duration
166 TimeoutBooting Duration
168 TimeoutProbe Duration
169 TimeoutShutdown Duration
170 TimeoutSignal Duration
172 ResourceTags map[string]string
175 DriverParameters json.RawMessage
178 type InstanceTypeMap map[string]InstanceType
180 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
182 // UnmarshalJSON handles old config files that provide an array of
183 // instance types instead of a hash.
184 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
185 if len(data) > 0 && data[0] == '[' {
186 var arr []InstanceType
187 err := json.Unmarshal(data, &arr)
195 *it = make(map[string]InstanceType, len(arr))
196 for _, t := range arr {
197 if _, ok := (*it)[t.Name]; ok {
198 return errDuplicateInstanceTypeName
200 if t.ProviderType == "" {
201 t.ProviderType = t.Name
204 t.Scratch = t.IncludedScratch + t.AddedScratch
205 } else if t.AddedScratch == 0 {
206 t.AddedScratch = t.Scratch - t.IncludedScratch
207 } else if t.IncludedScratch == 0 {
208 t.IncludedScratch = t.Scratch - t.AddedScratch
211 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
212 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
218 var hash map[string]InstanceType
219 err := json.Unmarshal(data, &hash)
223 // Fill in Name field (and ProviderType field, if not
224 // specified) using hash key.
225 *it = InstanceTypeMap(hash)
226 for name, t := range *it {
228 if t.ProviderType == "" {
229 t.ProviderType = name
236 type ServiceName string
239 ServiceNameRailsAPI ServiceName = "arvados-api-server"
240 ServiceNameController ServiceName = "arvados-controller"
241 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
242 ServiceNameHealth ServiceName = "arvados-health"
243 ServiceNameNodemanager ServiceName = "arvados-node-manager"
244 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
245 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
246 ServiceNameWebsocket ServiceName = "arvados-ws"
247 ServiceNameKeepbalance ServiceName = "keep-balance"
248 ServiceNameKeepweb ServiceName = "keep-web"
249 ServiceNameKeepproxy ServiceName = "keepproxy"
250 ServiceNameKeepstore ServiceName = "keepstore"
253 // Map returns all services as a map, suitable for iterating over all
254 // services or looking up a service by name.
255 func (svcs Services) Map() map[ServiceName]Service {
256 return map[ServiceName]Service{
257 ServiceNameRailsAPI: svcs.RailsAPI,
258 ServiceNameController: svcs.Controller,
259 ServiceNameDispatchCloud: svcs.DispatchCloud,
260 ServiceNameHealth: svcs.Health,
261 ServiceNameNodemanager: svcs.Nodemanager,
262 ServiceNameWorkbench1: svcs.Workbench1,
263 ServiceNameWorkbench2: svcs.Workbench2,
264 ServiceNameWebsocket: svcs.Websocket,
265 ServiceNameKeepbalance: svcs.Keepbalance,
266 ServiceNameKeepweb: svcs.WebDAV,
267 ServiceNameKeepproxy: svcs.Keepproxy,
268 ServiceNameKeepstore: svcs.Keepstore,