1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
14 "git.curoverse.com/arvados.git/sdk/go/config"
17 var DefaultConfigFile = func() string {
18 if path := os.Getenv("ARVADOS_CONFIG"); path != "" {
21 return "/etc/arvados/config.yml"
26 Clusters map[string]Cluster
29 // GetConfig returns the current system config, loading it from
30 // configFile if needed.
31 func GetConfig(configFile string) (*Config, error) {
33 err := config.LoadFile(&cfg, configFile)
37 // GetCluster returns the cluster ID and config for the given
38 // cluster, or the default/only configured cluster if clusterID is "".
39 func (sc *Config) GetCluster(clusterID string) (*Cluster, error) {
41 if len(sc.Clusters) == 0 {
42 return nil, fmt.Errorf("no clusters configured")
43 } else if len(sc.Clusters) > 1 {
44 return nil, fmt.Errorf("multiple clusters configured, cannot choose")
46 for id, cc := range sc.Clusters {
52 if cc, ok := sc.Clusters[clusterID]; !ok {
53 return nil, fmt.Errorf("cluster %q is not configured", clusterID)
55 cc.ClusterID = clusterID
60 type WebDAVCacheConfig struct {
64 MaxCollectionEntries int
65 MaxCollectionBytes int64
66 MaxPermissionEntries int
70 ClusterID string `json:"-"`
71 ManagementToken string
72 SystemRootToken string
74 InstanceTypes InstanceTypeMap
75 Containers ContainersConfig
76 RemoteClusters map[string]RemoteCluster
80 AsyncPermissionsUpdateInterval Duration
81 DisabledAPIs StringSet
82 MaxIndexDatabaseRead int
83 MaxItemsPerResponse int
84 MaxConcurrentRequests int
85 MaxKeepBlobBuffers int
86 MaxRequestAmplification int
88 RailsSessionSecretToken string
89 RequestTimeout Duration
91 WebsocketClientEventQueue int
92 WebsocketServerEventQueue int
93 KeepServiceRequestTimeout Duration
98 UnloggedAttributes StringSet
102 BlobSigningKey string
103 BlobSigningTTL Duration
105 BlobTrashLifetime Duration
106 BlobTrashCheckInterval Duration
107 BlobTrashConcurrency int
108 BlobDeleteConcurrency int
109 BlobReplicateConcurrency int
110 CollectionVersioning bool
111 DefaultTrashLifetime Duration
112 DefaultReplication int
113 ManagedProperties map[string]struct {
118 PreserveVersionIfIdle Duration
119 TrashSweepInterval Duration
122 WebDAVCache WebDAVCacheConfig
130 ProviderAppSecret string
133 RemoteTokenRefresh Duration
136 MailchimpAPIKey string
137 MailchimpListID string
138 SendUserSetupNotificationEmail bool
139 IssueReporterEmailFrom string
140 IssueReporterEmailTo string
141 SupportEmailAddress string
147 MaxRequestLogParamsSize int
155 AnonymousUserToken string
156 AdminNotifierEmailFrom string
157 AutoAdminFirstUser bool
158 AutoAdminUserWithEmail string
159 AutoSetupNewUsers bool
160 AutoSetupNewUsersWithRepository bool
161 AutoSetupNewUsersWithVmUUID string
162 AutoSetupUsernameBlacklist StringSet
163 EmailSubjectPrefix string
164 NewInactiveUserNotificationRecipients StringSet
165 NewUserNotificationRecipients StringSet
166 NewUsersAreActive bool
167 UserNotifierEmailFrom string
168 UserProfileNotificationAddress string
170 Volumes map[string]Volume
172 ActivationContactLink string
173 APIClientConnectTimeout Duration
174 APIClientReceiveTimeout Duration
175 APIResponseCompression bool
176 ApplicationMimetypesWithViewIcon StringSet
177 ArvadosDocsite string
178 ArvadosPublicDataDocURL string
179 DefaultOpenIdPrefix string
180 EnableGettingStartedPopup bool
181 EnablePublicProjectsPage bool
182 FileViewersConfigURL string
183 LogViewerMaxBytes ByteSize
184 MultiSiteSearch string
185 ProfilingEnabled bool
187 RepositoryCache string
188 RunningJobLogRecordsToFetch int
190 ShowRecentCollectionsOnDashboard bool
191 ShowUserAgreementInline bool
192 ShowUserNotifications bool
195 UserProfileFormFields map[string]struct {
197 FormFieldTitle string
198 FormFieldDescription string
201 Options map[string]struct{}
203 UserProfileFormMessage string
207 EnableBetaController14287 bool
211 AccessViaHosts map[URL]VolumeAccess
214 StorageClasses map[string]bool
216 DriverParameters json.RawMessage
219 type S3VolumeDriverParameters struct {
225 LocationConstraint bool
227 ConnectTimeout Duration
233 type AzureVolumeDriverParameters struct {
234 StorageAccountName string
235 StorageAccountKey string
236 StorageBaseURL string
238 RequestTimeout Duration
239 ListBlobsRetryDelay Duration
240 ListBlobsMaxAttempts int
243 type DirectoryVolumeDriverParameters struct {
248 type VolumeAccess struct {
252 type Services struct {
255 DispatchCloud Service
265 WebDAVDownload Service
273 type Service struct {
274 InternalURLs map[URL]ServiceInstance
278 // URL is a url.URL that is also usable as a JSON key/value.
281 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
282 // used as a JSON key/value.
283 func (su *URL) UnmarshalText(text []byte) error {
284 u, err := url.Parse(string(text))
291 func (su URL) MarshalText() ([]byte, error) {
292 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
295 func (su URL) String() string {
296 return (*url.URL)(&su).String()
299 type ServiceInstance struct {
300 // Rendezvous is normally empty; when changing the URL of a
301 // Keepstore service, Rendezvous can be set to the old URL to
302 // preserve rendezvous ordering.
303 Rendezvous string `json:",omitempty"`
306 type PostgreSQL struct {
307 Connection PostgreSQLConnection
311 type PostgreSQLConnection map[string]string
313 type RemoteCluster struct {
321 type InstanceType struct {
327 IncludedScratch ByteSize
328 AddedScratch ByteSize
333 type ContainersConfig struct {
334 CloudVMs CloudVMsConfig
335 CrunchRunCommand string
336 CrunchRunArgumentsList []string
337 DefaultKeepCacheRAM ByteSize
338 DispatchPrivateKey string
339 LogReuseDecisions bool
341 MaxDispatchAttempts int
343 MinRetryPeriod Duration
344 ReserveExtraRAM ByteSize
345 StaleLockTimeout Duration
346 SupportedDockerImageFormats StringSet
347 UsePreemptibleInstances bool
351 GitInternalDir string
356 LogSecondsBetweenEvents int
357 LogThrottlePeriod Duration
360 LimitLogBytesPerJob int
361 LogPartialLineThrottlePeriod Duration
362 LogUpdatePeriod Duration
363 LogUpdateSize ByteSize
367 SbatchArgumentsList []string
368 SbatchEnvironmentVariables map[string]string
370 DNSServerConfDir string
371 DNSServerConfTemplate string
372 DNSServerReloadCommand string
373 DNSServerUpdateCommand string
374 ComputeNodeDomain string
375 ComputeNodeNameservers StringSet
376 AssignNodeHostname string
381 type CloudVMsConfig struct {
384 BootProbeCommand string
386 MaxCloudOpsPerSecond int
387 MaxProbesPerSecond int
388 PollInterval Duration
389 ProbeInterval Duration
391 SyncInterval Duration
392 TimeoutBooting Duration
394 TimeoutProbe Duration
395 TimeoutShutdown Duration
396 TimeoutSignal Duration
398 ResourceTags map[string]string
402 DriverParameters json.RawMessage
405 type InstanceTypeMap map[string]InstanceType
407 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
409 // UnmarshalJSON handles old config files that provide an array of
410 // instance types instead of a hash.
411 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
412 if len(data) > 0 && data[0] == '[' {
413 var arr []InstanceType
414 err := json.Unmarshal(data, &arr)
422 *it = make(map[string]InstanceType, len(arr))
423 for _, t := range arr {
424 if _, ok := (*it)[t.Name]; ok {
425 return errDuplicateInstanceTypeName
427 if t.ProviderType == "" {
428 t.ProviderType = t.Name
431 t.Scratch = t.IncludedScratch + t.AddedScratch
432 } else if t.AddedScratch == 0 {
433 t.AddedScratch = t.Scratch - t.IncludedScratch
434 } else if t.IncludedScratch == 0 {
435 t.IncludedScratch = t.Scratch - t.AddedScratch
438 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
439 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
445 var hash map[string]InstanceType
446 err := json.Unmarshal(data, &hash)
450 // Fill in Name field (and ProviderType field, if not
451 // specified) using hash key.
452 *it = InstanceTypeMap(hash)
453 for name, t := range *it {
455 if t.ProviderType == "" {
456 t.ProviderType = name
463 type StringSet map[string]struct{}
465 // UnmarshalJSON handles old config files that provide an array of
466 // instance types instead of a hash.
467 func (ss *StringSet) UnmarshalJSON(data []byte) error {
468 if len(data) > 0 && data[0] == '[' {
470 err := json.Unmarshal(data, &arr)
478 *ss = make(map[string]struct{}, len(arr))
479 for _, t := range arr {
480 (*ss)[t] = struct{}{}
484 var hash map[string]struct{}
485 err := json.Unmarshal(data, &hash)
489 *ss = make(map[string]struct{}, len(hash))
490 for t, _ := range hash {
491 (*ss)[t] = struct{}{}
497 type ServiceName string
500 ServiceNameRailsAPI ServiceName = "arvados-api-server"
501 ServiceNameController ServiceName = "arvados-controller"
502 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
503 ServiceNameHealth ServiceName = "arvados-health"
504 ServiceNameNodemanager ServiceName = "arvados-node-manager"
505 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
506 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
507 ServiceNameWebsocket ServiceName = "arvados-ws"
508 ServiceNameKeepbalance ServiceName = "keep-balance"
509 ServiceNameKeepweb ServiceName = "keep-web"
510 ServiceNameKeepproxy ServiceName = "keepproxy"
511 ServiceNameKeepstore ServiceName = "keepstore"
514 // Map returns all services as a map, suitable for iterating over all
515 // services or looking up a service by name.
516 func (svcs Services) Map() map[ServiceName]Service {
517 return map[ServiceName]Service{
518 ServiceNameRailsAPI: svcs.RailsAPI,
519 ServiceNameController: svcs.Controller,
520 ServiceNameDispatchCloud: svcs.DispatchCloud,
521 ServiceNameHealth: svcs.Health,
522 ServiceNameNodemanager: svcs.Nodemanager,
523 ServiceNameWorkbench1: svcs.Workbench1,
524 ServiceNameWorkbench2: svcs.Workbench2,
525 ServiceNameWebsocket: svcs.Websocket,
526 ServiceNameKeepbalance: svcs.Keepbalance,
527 ServiceNameKeepweb: svcs.WebDAV,
528 ServiceNameKeepproxy: svcs.Keepproxy,
529 ServiceNameKeepstore: svcs.Keepstore,