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 string `json:",omitempty"`
303 type PostgreSQL struct {
304 Connection PostgreSQLConnection
308 type PostgreSQLConnection map[string]string
310 type RemoteCluster struct {
318 type InstanceType struct {
324 IncludedScratch ByteSize
325 AddedScratch ByteSize
330 type ContainersConfig struct {
331 CloudVMs CloudVMsConfig
332 CrunchRunCommand string
333 CrunchRunArgumentsList []string
334 DefaultKeepCacheRAM ByteSize
335 DispatchPrivateKey string
336 LogReuseDecisions bool
338 MaxDispatchAttempts int
340 MinRetryPeriod Duration
341 ReserveExtraRAM ByteSize
342 StaleLockTimeout Duration
343 SupportedDockerImageFormats StringSet
344 UsePreemptibleInstances bool
348 GitInternalDir string
353 LogSecondsBetweenEvents int
354 LogThrottlePeriod Duration
357 LimitLogBytesPerJob int
358 LogPartialLineThrottlePeriod Duration
359 LogUpdatePeriod Duration
360 LogUpdateSize ByteSize
364 SbatchArgumentsList []string
365 SbatchEnvironmentVariables map[string]string
367 DNSServerConfDir string
368 DNSServerConfTemplate string
369 DNSServerReloadCommand string
370 DNSServerUpdateCommand string
371 ComputeNodeDomain string
372 ComputeNodeNameservers StringSet
373 AssignNodeHostname string
378 type CloudVMsConfig struct {
381 BootProbeCommand string
383 MaxCloudOpsPerSecond int
384 MaxProbesPerSecond int
385 PollInterval Duration
386 ProbeInterval Duration
388 SyncInterval Duration
389 TimeoutBooting Duration
391 TimeoutProbe Duration
392 TimeoutShutdown Duration
393 TimeoutSignal Duration
395 ResourceTags map[string]string
399 DriverParameters json.RawMessage
402 type InstanceTypeMap map[string]InstanceType
404 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
406 // UnmarshalJSON handles old config files that provide an array of
407 // instance types instead of a hash.
408 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
409 if len(data) > 0 && data[0] == '[' {
410 var arr []InstanceType
411 err := json.Unmarshal(data, &arr)
419 *it = make(map[string]InstanceType, len(arr))
420 for _, t := range arr {
421 if _, ok := (*it)[t.Name]; ok {
422 return errDuplicateInstanceTypeName
424 if t.ProviderType == "" {
425 t.ProviderType = t.Name
428 t.Scratch = t.IncludedScratch + t.AddedScratch
429 } else if t.AddedScratch == 0 {
430 t.AddedScratch = t.Scratch - t.IncludedScratch
431 } else if t.IncludedScratch == 0 {
432 t.IncludedScratch = t.Scratch - t.AddedScratch
435 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
436 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
442 var hash map[string]InstanceType
443 err := json.Unmarshal(data, &hash)
447 // Fill in Name field (and ProviderType field, if not
448 // specified) using hash key.
449 *it = InstanceTypeMap(hash)
450 for name, t := range *it {
452 if t.ProviderType == "" {
453 t.ProviderType = name
460 type StringSet map[string]struct{}
462 // UnmarshalJSON handles old config files that provide an array of
463 // instance types instead of a hash.
464 func (ss *StringSet) UnmarshalJSON(data []byte) error {
465 if len(data) > 0 && data[0] == '[' {
467 err := json.Unmarshal(data, &arr)
475 *ss = make(map[string]struct{}, len(arr))
476 for _, t := range arr {
477 (*ss)[t] = struct{}{}
481 var hash map[string]struct{}
482 err := json.Unmarshal(data, &hash)
486 *ss = make(map[string]struct{}, len(hash))
487 for t, _ := range hash {
488 (*ss)[t] = struct{}{}
494 type ServiceName string
497 ServiceNameRailsAPI ServiceName = "arvados-api-server"
498 ServiceNameController ServiceName = "arvados-controller"
499 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
500 ServiceNameHealth ServiceName = "arvados-health"
501 ServiceNameNodemanager ServiceName = "arvados-node-manager"
502 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
503 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
504 ServiceNameWebsocket ServiceName = "arvados-ws"
505 ServiceNameKeepbalance ServiceName = "keep-balance"
506 ServiceNameKeepweb ServiceName = "keep-web"
507 ServiceNameKeepproxy ServiceName = "keepproxy"
508 ServiceNameKeepstore ServiceName = "keepstore"
511 // Map returns all services as a map, suitable for iterating over all
512 // services or looking up a service by name.
513 func (svcs Services) Map() map[ServiceName]Service {
514 return map[ServiceName]Service{
515 ServiceNameRailsAPI: svcs.RailsAPI,
516 ServiceNameController: svcs.Controller,
517 ServiceNameDispatchCloud: svcs.DispatchCloud,
518 ServiceNameHealth: svcs.Health,
519 ServiceNameNodemanager: svcs.Nodemanager,
520 ServiceNameWorkbench1: svcs.Workbench1,
521 ServiceNameWorkbench2: svcs.Workbench2,
522 ServiceNameWebsocket: svcs.Websocket,
523 ServiceNameKeepbalance: svcs.Keepbalance,
524 ServiceNameKeepweb: svcs.WebDAV,
525 ServiceNameKeepproxy: svcs.Keepproxy,
526 ServiceNameKeepstore: svcs.Keepstore,