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 BlobMissingReport string
123 BalancePeriod Duration
124 BalanceCollectionBatch int
125 BalanceCollectionBuffers int
127 WebDAVCache WebDAVCacheConfig
135 GoogleClientID string
136 GoogleClientSecret string
138 ProviderAppSecret string
140 RemoteTokenRefresh Duration
143 MailchimpAPIKey string
144 MailchimpListID string
145 SendUserSetupNotificationEmail bool
146 IssueReporterEmailFrom string
147 IssueReporterEmailTo string
148 SupportEmailAddress string
154 MaxRequestLogParamsSize int
162 AnonymousUserToken string
163 AdminNotifierEmailFrom string
164 AutoAdminFirstUser bool
165 AutoAdminUserWithEmail string
166 AutoSetupNewUsers bool
167 AutoSetupNewUsersWithRepository bool
168 AutoSetupNewUsersWithVmUUID string
169 AutoSetupUsernameBlacklist StringSet
170 EmailSubjectPrefix string
171 NewInactiveUserNotificationRecipients StringSet
172 NewUserNotificationRecipients StringSet
173 NewUsersAreActive bool
174 UserNotifierEmailFrom string
175 UserProfileNotificationAddress string
177 Volumes map[string]Volume
179 ActivationContactLink string
180 APIClientConnectTimeout Duration
181 APIClientReceiveTimeout Duration
182 APIResponseCompression bool
183 ApplicationMimetypesWithViewIcon StringSet
184 ArvadosDocsite string
185 ArvadosPublicDataDocURL string
186 DefaultOpenIdPrefix string
187 EnableGettingStartedPopup bool
188 EnablePublicProjectsPage bool
189 FileViewersConfigURL string
190 LogViewerMaxBytes ByteSize
191 MultiSiteSearch string
192 ProfilingEnabled bool
194 RepositoryCache string
195 RunningJobLogRecordsToFetch int
197 ShowRecentCollectionsOnDashboard bool
198 ShowUserAgreementInline bool
199 ShowUserNotifications bool
202 UserProfileFormFields map[string]struct {
204 FormFieldTitle string
205 FormFieldDescription string
208 Options map[string]struct{}
210 UserProfileFormMessage string
212 WelcomePageHTML string
213 InactivePageHTML string
216 EnableBetaController14287 bool
220 AccessViaHosts map[URL]VolumeAccess
223 StorageClasses map[string]bool
225 DriverParameters json.RawMessage
228 type S3VolumeDriverParameters struct {
234 LocationConstraint bool
236 ConnectTimeout Duration
242 type AzureVolumeDriverParameters struct {
243 StorageAccountName string
244 StorageAccountKey string
245 StorageBaseURL string
247 RequestTimeout Duration
248 ListBlobsRetryDelay Duration
249 ListBlobsMaxAttempts int
252 type DirectoryVolumeDriverParameters struct {
257 type VolumeAccess struct {
261 type Services struct {
264 DispatchCloud Service
274 WebDAVDownload Service
282 type Service struct {
283 InternalURLs map[URL]ServiceInstance
287 // URL is a url.URL that is also usable as a JSON key/value.
290 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
291 // used as a JSON key/value.
292 func (su *URL) UnmarshalText(text []byte) error {
293 u, err := url.Parse(string(text))
300 func (su URL) MarshalText() ([]byte, error) {
301 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
304 func (su URL) String() string {
305 return (*url.URL)(&su).String()
308 type ServiceInstance struct {
309 Rendezvous string `json:",omitempty"`
312 type PostgreSQL struct {
313 Connection PostgreSQLConnection
317 type PostgreSQLConnection map[string]string
319 type RemoteCluster struct {
327 type InstanceType struct {
333 IncludedScratch ByteSize
334 AddedScratch ByteSize
339 type ContainersConfig struct {
340 CloudVMs CloudVMsConfig
341 CrunchRunCommand string
342 CrunchRunArgumentsList []string
343 DefaultKeepCacheRAM ByteSize
344 DispatchPrivateKey string
345 LogReuseDecisions bool
347 MaxDispatchAttempts int
349 MinRetryPeriod Duration
350 ReserveExtraRAM ByteSize
351 StaleLockTimeout Duration
352 SupportedDockerImageFormats StringSet
353 UsePreemptibleInstances bool
357 GitInternalDir string
362 LogSecondsBetweenEvents int
363 LogThrottlePeriod Duration
366 LimitLogBytesPerJob int
367 LogPartialLineThrottlePeriod Duration
368 LogUpdatePeriod Duration
369 LogUpdateSize ByteSize
373 SbatchArgumentsList []string
374 SbatchEnvironmentVariables map[string]string
376 DNSServerConfDir string
377 DNSServerConfTemplate string
378 DNSServerReloadCommand string
379 DNSServerUpdateCommand string
380 ComputeNodeDomain string
381 ComputeNodeNameservers StringSet
382 AssignNodeHostname string
387 type CloudVMsConfig struct {
390 BootProbeCommand string
392 MaxCloudOpsPerSecond int
393 MaxProbesPerSecond int
394 PollInterval Duration
395 ProbeInterval Duration
397 SyncInterval Duration
398 TimeoutBooting Duration
400 TimeoutProbe Duration
401 TimeoutShutdown Duration
402 TimeoutSignal Duration
404 ResourceTags map[string]string
408 DriverParameters json.RawMessage
411 type InstanceTypeMap map[string]InstanceType
413 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
415 // UnmarshalJSON handles old config files that provide an array of
416 // instance types instead of a hash.
417 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
418 if len(data) > 0 && data[0] == '[' {
419 var arr []InstanceType
420 err := json.Unmarshal(data, &arr)
428 *it = make(map[string]InstanceType, len(arr))
429 for _, t := range arr {
430 if _, ok := (*it)[t.Name]; ok {
431 return errDuplicateInstanceTypeName
433 if t.ProviderType == "" {
434 t.ProviderType = t.Name
437 t.Scratch = t.IncludedScratch + t.AddedScratch
438 } else if t.AddedScratch == 0 {
439 t.AddedScratch = t.Scratch - t.IncludedScratch
440 } else if t.IncludedScratch == 0 {
441 t.IncludedScratch = t.Scratch - t.AddedScratch
444 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
445 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
451 var hash map[string]InstanceType
452 err := json.Unmarshal(data, &hash)
456 // Fill in Name field (and ProviderType field, if not
457 // specified) using hash key.
458 *it = InstanceTypeMap(hash)
459 for name, t := range *it {
461 if t.ProviderType == "" {
462 t.ProviderType = name
469 type StringSet map[string]struct{}
471 // UnmarshalJSON handles old config files that provide an array of
472 // instance types instead of a hash.
473 func (ss *StringSet) UnmarshalJSON(data []byte) error {
474 if len(data) > 0 && data[0] == '[' {
476 err := json.Unmarshal(data, &arr)
484 *ss = make(map[string]struct{}, len(arr))
485 for _, t := range arr {
486 (*ss)[t] = struct{}{}
490 var hash map[string]struct{}
491 err := json.Unmarshal(data, &hash)
495 *ss = make(map[string]struct{}, len(hash))
496 for t, _ := range hash {
497 (*ss)[t] = struct{}{}
503 type ServiceName string
506 ServiceNameRailsAPI ServiceName = "arvados-api-server"
507 ServiceNameController ServiceName = "arvados-controller"
508 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
509 ServiceNameHealth ServiceName = "arvados-health"
510 ServiceNameNodemanager ServiceName = "arvados-node-manager"
511 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
512 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
513 ServiceNameWebsocket ServiceName = "arvados-ws"
514 ServiceNameKeepbalance ServiceName = "keep-balance"
515 ServiceNameKeepweb ServiceName = "keep-web"
516 ServiceNameKeepproxy ServiceName = "keepproxy"
517 ServiceNameKeepstore ServiceName = "keepstore"
520 // Map returns all services as a map, suitable for iterating over all
521 // services or looking up a service by name.
522 func (svcs Services) Map() map[ServiceName]Service {
523 return map[ServiceName]Service{
524 ServiceNameRailsAPI: svcs.RailsAPI,
525 ServiceNameController: svcs.Controller,
526 ServiceNameDispatchCloud: svcs.DispatchCloud,
527 ServiceNameHealth: svcs.Health,
528 ServiceNameNodemanager: svcs.Nodemanager,
529 ServiceNameWorkbench1: svcs.Workbench1,
530 ServiceNameWorkbench2: svcs.Workbench2,
531 ServiceNameWebsocket: svcs.Websocket,
532 ServiceNameKeepbalance: svcs.Keepbalance,
533 ServiceNameKeepweb: svcs.WebDAV,
534 ServiceNameKeepproxy: svcs.Keepproxy,
535 ServiceNameKeepstore: svcs.Keepstore,