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
137 GoogleAlternateEmailAddresses bool
139 ProviderAppSecret string
141 RemoteTokenRefresh Duration
144 MailchimpAPIKey string
145 MailchimpListID string
146 SendUserSetupNotificationEmail bool
147 IssueReporterEmailFrom string
148 IssueReporterEmailTo string
149 SupportEmailAddress string
155 MaxRequestLogParamsSize int
163 AnonymousUserToken string
164 AdminNotifierEmailFrom string
165 AutoAdminFirstUser bool
166 AutoAdminUserWithEmail string
167 AutoSetupNewUsers bool
168 AutoSetupNewUsersWithRepository bool
169 AutoSetupNewUsersWithVmUUID string
170 AutoSetupUsernameBlacklist StringSet
171 EmailSubjectPrefix string
172 NewInactiveUserNotificationRecipients StringSet
173 NewUserNotificationRecipients StringSet
174 NewUsersAreActive bool
175 UserNotifierEmailFrom string
176 UserProfileNotificationAddress string
177 PreferDomainForUsername string
179 Volumes map[string]Volume
181 ActivationContactLink string
182 APIClientConnectTimeout Duration
183 APIClientReceiveTimeout Duration
184 APIResponseCompression bool
185 ApplicationMimetypesWithViewIcon StringSet
186 ArvadosDocsite string
187 ArvadosPublicDataDocURL string
188 DefaultOpenIdPrefix string
189 EnableGettingStartedPopup bool
190 EnablePublicProjectsPage bool
191 FileViewersConfigURL string
192 LogViewerMaxBytes ByteSize
193 MultiSiteSearch string
194 ProfilingEnabled bool
196 RepositoryCache string
197 RunningJobLogRecordsToFetch int
199 ShowRecentCollectionsOnDashboard bool
200 ShowUserAgreementInline bool
201 ShowUserNotifications bool
204 UserProfileFormFields map[string]struct {
206 FormFieldTitle string
207 FormFieldDescription string
210 Options map[string]struct{}
212 UserProfileFormMessage string
214 WelcomePageHTML string
215 InactivePageHTML string
218 EnableBetaController14287 bool
222 AccessViaHosts map[URL]VolumeAccess
225 StorageClasses map[string]bool
227 DriverParameters json.RawMessage
230 type S3VolumeDriverParameters struct {
236 LocationConstraint bool
238 ConnectTimeout Duration
244 type AzureVolumeDriverParameters struct {
245 StorageAccountName string
246 StorageAccountKey string
247 StorageBaseURL string
249 RequestTimeout Duration
250 ListBlobsRetryDelay Duration
251 ListBlobsMaxAttempts int
254 type DirectoryVolumeDriverParameters struct {
259 type VolumeAccess struct {
263 type Services struct {
266 DispatchCloud Service
276 WebDAVDownload Service
284 type Service struct {
285 InternalURLs map[URL]ServiceInstance
289 // URL is a url.URL that is also usable as a JSON key/value.
292 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
293 // used as a JSON key/value.
294 func (su *URL) UnmarshalText(text []byte) error {
295 u, err := url.Parse(string(text))
302 func (su URL) MarshalText() ([]byte, error) {
303 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
306 func (su URL) String() string {
307 return (*url.URL)(&su).String()
310 type ServiceInstance struct {
311 Rendezvous string `json:",omitempty"`
314 type PostgreSQL struct {
315 Connection PostgreSQLConnection
319 type PostgreSQLConnection map[string]string
321 type RemoteCluster struct {
329 type InstanceType struct {
335 IncludedScratch ByteSize
336 AddedScratch ByteSize
341 type ContainersConfig struct {
342 CloudVMs CloudVMsConfig
343 CrunchRunCommand string
344 CrunchRunArgumentsList []string
345 DefaultKeepCacheRAM ByteSize
346 DispatchPrivateKey string
347 LogReuseDecisions bool
349 MaxDispatchAttempts int
351 MinRetryPeriod Duration
352 ReserveExtraRAM ByteSize
353 StaleLockTimeout Duration
354 SupportedDockerImageFormats StringSet
355 UsePreemptibleInstances bool
359 GitInternalDir string
364 LogSecondsBetweenEvents int
365 LogThrottlePeriod Duration
368 LimitLogBytesPerJob int
369 LogPartialLineThrottlePeriod Duration
370 LogUpdatePeriod Duration
371 LogUpdateSize ByteSize
375 SbatchArgumentsList []string
376 SbatchEnvironmentVariables map[string]string
378 DNSServerConfDir string
379 DNSServerConfTemplate string
380 DNSServerReloadCommand string
381 DNSServerUpdateCommand string
382 ComputeNodeDomain string
383 ComputeNodeNameservers StringSet
384 AssignNodeHostname string
389 type CloudVMsConfig struct {
392 BootProbeCommand string
394 MaxCloudOpsPerSecond int
395 MaxProbesPerSecond int
396 PollInterval Duration
397 ProbeInterval Duration
399 SyncInterval Duration
400 TimeoutBooting Duration
402 TimeoutProbe Duration
403 TimeoutShutdown Duration
404 TimeoutSignal Duration
406 ResourceTags map[string]string
410 DriverParameters json.RawMessage
413 type InstanceTypeMap map[string]InstanceType
415 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
417 // UnmarshalJSON handles old config files that provide an array of
418 // instance types instead of a hash.
419 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
420 if len(data) > 0 && data[0] == '[' {
421 var arr []InstanceType
422 err := json.Unmarshal(data, &arr)
430 *it = make(map[string]InstanceType, len(arr))
431 for _, t := range arr {
432 if _, ok := (*it)[t.Name]; ok {
433 return errDuplicateInstanceTypeName
435 if t.ProviderType == "" {
436 t.ProviderType = t.Name
439 t.Scratch = t.IncludedScratch + t.AddedScratch
440 } else if t.AddedScratch == 0 {
441 t.AddedScratch = t.Scratch - t.IncludedScratch
442 } else if t.IncludedScratch == 0 {
443 t.IncludedScratch = t.Scratch - t.AddedScratch
446 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
447 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
453 var hash map[string]InstanceType
454 err := json.Unmarshal(data, &hash)
458 // Fill in Name field (and ProviderType field, if not
459 // specified) using hash key.
460 *it = InstanceTypeMap(hash)
461 for name, t := range *it {
463 if t.ProviderType == "" {
464 t.ProviderType = name
471 type StringSet map[string]struct{}
473 // UnmarshalJSON handles old config files that provide an array of
474 // instance types instead of a hash.
475 func (ss *StringSet) UnmarshalJSON(data []byte) error {
476 if len(data) > 0 && data[0] == '[' {
478 err := json.Unmarshal(data, &arr)
486 *ss = make(map[string]struct{}, len(arr))
487 for _, t := range arr {
488 (*ss)[t] = struct{}{}
492 var hash map[string]struct{}
493 err := json.Unmarshal(data, &hash)
497 *ss = make(map[string]struct{}, len(hash))
498 for t, _ := range hash {
499 (*ss)[t] = struct{}{}
505 type ServiceName string
508 ServiceNameRailsAPI ServiceName = "arvados-api-server"
509 ServiceNameController ServiceName = "arvados-controller"
510 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
511 ServiceNameHealth ServiceName = "arvados-health"
512 ServiceNameNodemanager ServiceName = "arvados-node-manager"
513 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
514 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
515 ServiceNameWebsocket ServiceName = "arvados-ws"
516 ServiceNameKeepbalance ServiceName = "keep-balance"
517 ServiceNameKeepweb ServiceName = "keep-web"
518 ServiceNameKeepproxy ServiceName = "keepproxy"
519 ServiceNameKeepstore ServiceName = "keepstore"
522 // Map returns all services as a map, suitable for iterating over all
523 // services or looking up a service by name.
524 func (svcs Services) Map() map[ServiceName]Service {
525 return map[ServiceName]Service{
526 ServiceNameRailsAPI: svcs.RailsAPI,
527 ServiceNameController: svcs.Controller,
528 ServiceNameDispatchCloud: svcs.DispatchCloud,
529 ServiceNameHealth: svcs.Health,
530 ServiceNameNodemanager: svcs.Nodemanager,
531 ServiceNameWorkbench1: svcs.Workbench1,
532 ServiceNameWorkbench2: svcs.Workbench2,
533 ServiceNameWebsocket: svcs.Websocket,
534 ServiceNameKeepbalance: svcs.Keepbalance,
535 ServiceNameKeepweb: svcs.WebDAV,
536 ServiceNameKeepproxy: svcs.Keepproxy,
537 ServiceNameKeepstore: svcs.Keepstore,