1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
14 "git.arvados.org/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 ForceLegacyAPI14 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
393 DeployRunnerBinary string
395 MaxCloudOpsPerSecond int
396 MaxProbesPerSecond int
397 PollInterval Duration
398 ProbeInterval Duration
400 SyncInterval Duration
401 TimeoutBooting Duration
403 TimeoutProbe Duration
404 TimeoutShutdown Duration
405 TimeoutSignal Duration
407 ResourceTags map[string]string
411 DriverParameters json.RawMessage
414 type InstanceTypeMap map[string]InstanceType
416 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
418 // UnmarshalJSON handles old config files that provide an array of
419 // instance types instead of a hash.
420 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
421 if len(data) > 0 && data[0] == '[' {
422 var arr []InstanceType
423 err := json.Unmarshal(data, &arr)
431 *it = make(map[string]InstanceType, len(arr))
432 for _, t := range arr {
433 if _, ok := (*it)[t.Name]; ok {
434 return errDuplicateInstanceTypeName
436 if t.ProviderType == "" {
437 t.ProviderType = t.Name
440 t.Scratch = t.IncludedScratch + t.AddedScratch
441 } else if t.AddedScratch == 0 {
442 t.AddedScratch = t.Scratch - t.IncludedScratch
443 } else if t.IncludedScratch == 0 {
444 t.IncludedScratch = t.Scratch - t.AddedScratch
447 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
448 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
454 var hash map[string]InstanceType
455 err := json.Unmarshal(data, &hash)
459 // Fill in Name field (and ProviderType field, if not
460 // specified) using hash key.
461 *it = InstanceTypeMap(hash)
462 for name, t := range *it {
464 if t.ProviderType == "" {
465 t.ProviderType = name
472 type StringSet map[string]struct{}
474 // UnmarshalJSON handles old config files that provide an array of
475 // instance types instead of a hash.
476 func (ss *StringSet) UnmarshalJSON(data []byte) error {
477 if len(data) > 0 && data[0] == '[' {
479 err := json.Unmarshal(data, &arr)
487 *ss = make(map[string]struct{}, len(arr))
488 for _, t := range arr {
489 (*ss)[t] = struct{}{}
493 var hash map[string]struct{}
494 err := json.Unmarshal(data, &hash)
498 *ss = make(map[string]struct{}, len(hash))
499 for t, _ := range hash {
500 (*ss)[t] = struct{}{}
506 type ServiceName string
509 ServiceNameRailsAPI ServiceName = "arvados-api-server"
510 ServiceNameController ServiceName = "arvados-controller"
511 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
512 ServiceNameHealth ServiceName = "arvados-health"
513 ServiceNameNodemanager ServiceName = "arvados-node-manager"
514 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
515 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
516 ServiceNameWebsocket ServiceName = "arvados-ws"
517 ServiceNameKeepbalance ServiceName = "keep-balance"
518 ServiceNameKeepweb ServiceName = "keep-web"
519 ServiceNameKeepproxy ServiceName = "keepproxy"
520 ServiceNameKeepstore ServiceName = "keepstore"
523 // Map returns all services as a map, suitable for iterating over all
524 // services or looking up a service by name.
525 func (svcs Services) Map() map[ServiceName]Service {
526 return map[ServiceName]Service{
527 ServiceNameRailsAPI: svcs.RailsAPI,
528 ServiceNameController: svcs.Controller,
529 ServiceNameDispatchCloud: svcs.DispatchCloud,
530 ServiceNameHealth: svcs.Health,
531 ServiceNameNodemanager: svcs.Nodemanager,
532 ServiceNameWorkbench1: svcs.Workbench1,
533 ServiceNameWorkbench2: svcs.Workbench2,
534 ServiceNameWebsocket: svcs.Websocket,
535 ServiceNameKeepbalance: svcs.Keepbalance,
536 ServiceNameKeepweb: svcs.WebDAV,
537 ServiceNameKeepproxy: svcs.Keepproxy,
538 ServiceNameKeepstore: svcs.Keepstore,