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 MaxKeepBlockBuffers 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
134 MailchimpAPIKey string
135 MailchimpListID string
136 SendUserSetupNotificationEmail bool
137 IssueReporterEmailFrom string
138 IssueReporterEmailTo string
139 SupportEmailAddress string
145 MaxRequestLogParamsSize int
153 AnonymousUserToken string
154 AdminNotifierEmailFrom string
155 AutoAdminFirstUser bool
156 AutoAdminUserWithEmail string
157 AutoSetupNewUsers bool
158 AutoSetupNewUsersWithRepository bool
159 AutoSetupNewUsersWithVmUUID string
160 AutoSetupUsernameBlacklist StringSet
161 EmailSubjectPrefix string
162 NewInactiveUserNotificationRecipients StringSet
163 NewUserNotificationRecipients StringSet
164 NewUsersAreActive bool
165 UserNotifierEmailFrom string
166 UserProfileNotificationAddress string
168 Volumes map[string]Volume
170 ActivationContactLink string
171 APIClientConnectTimeout Duration
172 APIClientReceiveTimeout Duration
173 APIResponseCompression bool
174 ApplicationMimetypesWithViewIcon StringSet
175 ArvadosDocsite string
176 ArvadosPublicDataDocURL string
177 DefaultOpenIdPrefix string
178 EnableGettingStartedPopup bool
179 EnablePublicProjectsPage bool
180 FileViewersConfigURL string
181 LogViewerMaxBytes ByteSize
182 MultiSiteSearch string
183 ProfilingEnabled bool
185 RepositoryCache string
186 RunningJobLogRecordsToFetch int
188 ShowRecentCollectionsOnDashboard bool
189 ShowUserAgreementInline bool
190 ShowUserNotifications bool
193 UserProfileFormFields map[string]struct {
195 FormFieldTitle string
196 FormFieldDescription string
199 Options map[string]struct{}
201 UserProfileFormMessage string
205 EnableBetaController14287 bool
209 AccessViaHosts map[URL]VolumeAccess
212 StorageClasses map[string]bool
214 DriverParameters json.RawMessage
217 type S3VolumeDriverParameters struct {
223 LocationConstraint bool
225 ConnectTimeout Duration
231 type AzureVolumeDriverParameters struct {
232 StorageAccountName string
233 StorageAccountKey string
234 StorageBaseURL string
236 RequestTimeout Duration
237 ListBlobsRetryDelay Duration
238 ListBlobsMaxAttempts int
241 type DirectoryVolumeDriverParameters struct {
246 type VolumeAccess struct {
250 type Services struct {
253 DispatchCloud Service
263 WebDAVDownload Service
271 type Service struct {
272 InternalURLs map[URL]ServiceInstance
276 // URL is a url.URL that is also usable as a JSON key/value.
279 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
280 // used as a JSON key/value.
281 func (su *URL) UnmarshalText(text []byte) error {
282 u, err := url.Parse(string(text))
289 func (su URL) MarshalText() ([]byte, error) {
290 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
293 func (su URL) String() string {
294 return (*url.URL)(&su).String()
297 type ServiceInstance struct{}
299 type PostgreSQL struct {
300 Connection PostgreSQLConnection
304 type PostgreSQLConnection map[string]string
306 type RemoteCluster struct {
314 type InstanceType struct {
320 IncludedScratch ByteSize
321 AddedScratch ByteSize
326 type ContainersConfig struct {
327 CloudVMs CloudVMsConfig
328 CrunchRunCommand string
329 CrunchRunArgumentsList []string
330 DefaultKeepCacheRAM ByteSize
331 DispatchPrivateKey string
332 LogReuseDecisions bool
334 MaxDispatchAttempts int
336 MinRetryPeriod Duration
337 ReserveExtraRAM ByteSize
338 StaleLockTimeout Duration
339 SupportedDockerImageFormats StringSet
340 UsePreemptibleInstances bool
344 GitInternalDir string
349 LogSecondsBetweenEvents int
350 LogThrottlePeriod Duration
353 LimitLogBytesPerJob int
354 LogPartialLineThrottlePeriod Duration
355 LogUpdatePeriod Duration
356 LogUpdateSize ByteSize
360 SbatchArgumentsList []string
361 SbatchEnvironmentVariables map[string]string
363 DNSServerConfDir string
364 DNSServerConfTemplate string
365 DNSServerReloadCommand string
366 DNSServerUpdateCommand string
367 ComputeNodeDomain string
368 ComputeNodeNameservers StringSet
369 AssignNodeHostname string
374 type CloudVMsConfig struct {
377 BootProbeCommand string
379 MaxCloudOpsPerSecond int
380 MaxProbesPerSecond int
381 PollInterval Duration
382 ProbeInterval Duration
384 SyncInterval Duration
385 TimeoutBooting Duration
387 TimeoutProbe Duration
388 TimeoutShutdown Duration
389 TimeoutSignal Duration
391 ResourceTags map[string]string
395 DriverParameters json.RawMessage
398 type InstanceTypeMap map[string]InstanceType
400 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
402 // UnmarshalJSON handles old config files that provide an array of
403 // instance types instead of a hash.
404 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
405 if len(data) > 0 && data[0] == '[' {
406 var arr []InstanceType
407 err := json.Unmarshal(data, &arr)
415 *it = make(map[string]InstanceType, len(arr))
416 for _, t := range arr {
417 if _, ok := (*it)[t.Name]; ok {
418 return errDuplicateInstanceTypeName
420 if t.ProviderType == "" {
421 t.ProviderType = t.Name
424 t.Scratch = t.IncludedScratch + t.AddedScratch
425 } else if t.AddedScratch == 0 {
426 t.AddedScratch = t.Scratch - t.IncludedScratch
427 } else if t.IncludedScratch == 0 {
428 t.IncludedScratch = t.Scratch - t.AddedScratch
431 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
432 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
438 var hash map[string]InstanceType
439 err := json.Unmarshal(data, &hash)
443 // Fill in Name field (and ProviderType field, if not
444 // specified) using hash key.
445 *it = InstanceTypeMap(hash)
446 for name, t := range *it {
448 if t.ProviderType == "" {
449 t.ProviderType = name
456 type StringSet map[string]struct{}
458 // UnmarshalJSON handles old config files that provide an array of
459 // instance types instead of a hash.
460 func (ss *StringSet) UnmarshalJSON(data []byte) error {
461 if len(data) > 0 && data[0] == '[' {
463 err := json.Unmarshal(data, &arr)
471 *ss = make(map[string]struct{}, len(arr))
472 for _, t := range arr {
473 (*ss)[t] = struct{}{}
477 var hash map[string]struct{}
478 err := json.Unmarshal(data, &hash)
482 *ss = make(map[string]struct{}, len(hash))
483 for t, _ := range hash {
484 (*ss)[t] = struct{}{}
490 type ServiceName string
493 ServiceNameRailsAPI ServiceName = "arvados-api-server"
494 ServiceNameController ServiceName = "arvados-controller"
495 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
496 ServiceNameHealth ServiceName = "arvados-health"
497 ServiceNameNodemanager ServiceName = "arvados-node-manager"
498 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
499 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
500 ServiceNameWebsocket ServiceName = "arvados-ws"
501 ServiceNameKeepbalance ServiceName = "keep-balance"
502 ServiceNameKeepweb ServiceName = "keep-web"
503 ServiceNameKeepproxy ServiceName = "keepproxy"
504 ServiceNameKeepstore ServiceName = "keepstore"
507 // Map returns all services as a map, suitable for iterating over all
508 // services or looking up a service by name.
509 func (svcs Services) Map() map[ServiceName]Service {
510 return map[ServiceName]Service{
511 ServiceNameRailsAPI: svcs.RailsAPI,
512 ServiceNameController: svcs.Controller,
513 ServiceNameDispatchCloud: svcs.DispatchCloud,
514 ServiceNameHealth: svcs.Health,
515 ServiceNameNodemanager: svcs.Nodemanager,
516 ServiceNameWorkbench1: svcs.Workbench1,
517 ServiceNameWorkbench2: svcs.Workbench2,
518 ServiceNameWebsocket: svcs.Websocket,
519 ServiceNameKeepbalance: svcs.Keepbalance,
520 ServiceNameKeepweb: svcs.WebDAV,
521 ServiceNameKeepproxy: svcs.Keepproxy,
522 ServiceNameKeepstore: svcs.Keepstore,