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
121 ForwardSlashNameSubstitution string
123 BlobMissingReport string
124 BalancePeriod Duration
125 BalanceCollectionBatch int
126 BalanceCollectionBuffers int
128 WebDAVCache WebDAVCacheConfig
136 GoogleClientID string
137 GoogleClientSecret string
138 GoogleAlternateEmailAddresses bool
140 ProviderAppSecret string
142 RemoteTokenRefresh Duration
145 MailchimpAPIKey string
146 MailchimpListID string
147 SendUserSetupNotificationEmail bool
148 IssueReporterEmailFrom string
149 IssueReporterEmailTo string
150 SupportEmailAddress string
156 MaxRequestLogParamsSize int
164 AnonymousUserToken string
165 AdminNotifierEmailFrom string
166 AutoAdminFirstUser bool
167 AutoAdminUserWithEmail string
168 AutoSetupNewUsers bool
169 AutoSetupNewUsersWithRepository bool
170 AutoSetupNewUsersWithVmUUID string
171 AutoSetupUsernameBlacklist StringSet
172 EmailSubjectPrefix string
173 NewInactiveUserNotificationRecipients StringSet
174 NewUserNotificationRecipients StringSet
175 NewUsersAreActive bool
176 UserNotifierEmailFrom string
177 UserProfileNotificationAddress string
178 PreferDomainForUsername string
180 Volumes map[string]Volume
182 ActivationContactLink string
183 APIClientConnectTimeout Duration
184 APIClientReceiveTimeout Duration
185 APIResponseCompression bool
186 ApplicationMimetypesWithViewIcon StringSet
187 ArvadosDocsite string
188 ArvadosPublicDataDocURL string
189 DefaultOpenIdPrefix string
190 EnableGettingStartedPopup bool
191 EnablePublicProjectsPage bool
192 FileViewersConfigURL string
193 LogViewerMaxBytes ByteSize
194 MultiSiteSearch string
195 ProfilingEnabled bool
197 RepositoryCache string
198 RunningJobLogRecordsToFetch int
200 ShowRecentCollectionsOnDashboard bool
201 ShowUserAgreementInline bool
202 ShowUserNotifications bool
205 UserProfileFormFields map[string]struct {
207 FormFieldTitle string
208 FormFieldDescription string
211 Options map[string]struct{}
213 UserProfileFormMessage string
215 WelcomePageHTML string
216 InactivePageHTML string
217 SSHHelpPageHTML string
218 SSHHelpHostSuffix string
221 ForceLegacyAPI14 bool
225 AccessViaHosts map[URL]VolumeAccess
228 StorageClasses map[string]bool
230 DriverParameters json.RawMessage
233 type S3VolumeDriverParameters struct {
239 LocationConstraint bool
241 ConnectTimeout Duration
247 type AzureVolumeDriverParameters struct {
248 StorageAccountName string
249 StorageAccountKey string
250 StorageBaseURL string
252 RequestTimeout Duration
253 ListBlobsRetryDelay Duration
254 ListBlobsMaxAttempts int
257 type DirectoryVolumeDriverParameters struct {
262 type VolumeAccess struct {
266 type Services struct {
269 DispatchCloud Service
279 WebDAVDownload Service
287 type Service struct {
288 InternalURLs map[URL]ServiceInstance
292 // URL is a url.URL that is also usable as a JSON key/value.
295 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
296 // used as a JSON key/value.
297 func (su *URL) UnmarshalText(text []byte) error {
298 u, err := url.Parse(string(text))
305 func (su URL) MarshalText() ([]byte, error) {
306 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
309 func (su URL) String() string {
310 return (*url.URL)(&su).String()
313 type ServiceInstance struct {
314 Rendezvous string `json:",omitempty"`
317 type PostgreSQL struct {
318 Connection PostgreSQLConnection
322 type PostgreSQLConnection map[string]string
324 type RemoteCluster struct {
332 type InstanceType struct {
338 IncludedScratch ByteSize
339 AddedScratch ByteSize
344 type ContainersConfig struct {
345 CloudVMs CloudVMsConfig
346 CrunchRunCommand string
347 CrunchRunArgumentsList []string
348 DefaultKeepCacheRAM ByteSize
349 DispatchPrivateKey string
350 LogReuseDecisions bool
352 MaxDispatchAttempts int
354 MinRetryPeriod Duration
355 ReserveExtraRAM ByteSize
356 StaleLockTimeout Duration
357 SupportedDockerImageFormats StringSet
358 UsePreemptibleInstances bool
362 GitInternalDir string
367 LogSecondsBetweenEvents Duration
368 LogThrottlePeriod Duration
371 LimitLogBytesPerJob int
372 LogPartialLineThrottlePeriod Duration
373 LogUpdatePeriod Duration
374 LogUpdateSize ByteSize
378 SbatchArgumentsList []string
379 SbatchEnvironmentVariables map[string]string
381 DNSServerConfDir string
382 DNSServerConfTemplate string
383 DNSServerReloadCommand string
384 DNSServerUpdateCommand string
385 ComputeNodeDomain string
386 ComputeNodeNameservers StringSet
387 AssignNodeHostname string
392 type CloudVMsConfig struct {
395 BootProbeCommand string
396 DeployRunnerBinary string
398 MaxCloudOpsPerSecond int
399 MaxProbesPerSecond int
400 PollInterval Duration
401 ProbeInterval Duration
403 SyncInterval Duration
404 TimeoutBooting Duration
406 TimeoutProbe Duration
407 TimeoutShutdown Duration
408 TimeoutSignal Duration
410 ResourceTags map[string]string
414 DriverParameters json.RawMessage
417 type InstanceTypeMap map[string]InstanceType
419 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
421 // UnmarshalJSON handles old config files that provide an array of
422 // instance types instead of a hash.
423 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
424 if len(data) > 0 && data[0] == '[' {
425 var arr []InstanceType
426 err := json.Unmarshal(data, &arr)
434 *it = make(map[string]InstanceType, len(arr))
435 for _, t := range arr {
436 if _, ok := (*it)[t.Name]; ok {
437 return errDuplicateInstanceTypeName
439 if t.ProviderType == "" {
440 t.ProviderType = t.Name
443 t.Scratch = t.IncludedScratch + t.AddedScratch
444 } else if t.AddedScratch == 0 {
445 t.AddedScratch = t.Scratch - t.IncludedScratch
446 } else if t.IncludedScratch == 0 {
447 t.IncludedScratch = t.Scratch - t.AddedScratch
450 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
451 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
457 var hash map[string]InstanceType
458 err := json.Unmarshal(data, &hash)
462 // Fill in Name field (and ProviderType field, if not
463 // specified) using hash key.
464 *it = InstanceTypeMap(hash)
465 for name, t := range *it {
467 if t.ProviderType == "" {
468 t.ProviderType = name
475 type StringSet map[string]struct{}
477 // UnmarshalJSON handles old config files that provide an array of
478 // instance types instead of a hash.
479 func (ss *StringSet) UnmarshalJSON(data []byte) error {
480 if len(data) > 0 && data[0] == '[' {
482 err := json.Unmarshal(data, &arr)
490 *ss = make(map[string]struct{}, len(arr))
491 for _, t := range arr {
492 (*ss)[t] = struct{}{}
496 var hash map[string]struct{}
497 err := json.Unmarshal(data, &hash)
501 *ss = make(map[string]struct{}, len(hash))
502 for t, _ := range hash {
503 (*ss)[t] = struct{}{}
509 type ServiceName string
512 ServiceNameRailsAPI ServiceName = "arvados-api-server"
513 ServiceNameController ServiceName = "arvados-controller"
514 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
515 ServiceNameHealth ServiceName = "arvados-health"
516 ServiceNameNodemanager ServiceName = "arvados-node-manager"
517 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
518 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
519 ServiceNameWebsocket ServiceName = "arvados-ws"
520 ServiceNameKeepbalance ServiceName = "keep-balance"
521 ServiceNameKeepweb ServiceName = "keep-web"
522 ServiceNameKeepproxy ServiceName = "keepproxy"
523 ServiceNameKeepstore ServiceName = "keepstore"
526 // Map returns all services as a map, suitable for iterating over all
527 // services or looking up a service by name.
528 func (svcs Services) Map() map[ServiceName]Service {
529 return map[ServiceName]Service{
530 ServiceNameRailsAPI: svcs.RailsAPI,
531 ServiceNameController: svcs.Controller,
532 ServiceNameDispatchCloud: svcs.DispatchCloud,
533 ServiceNameHealth: svcs.Health,
534 ServiceNameNodemanager: svcs.Nodemanager,
535 ServiceNameWorkbench1: svcs.Workbench1,
536 ServiceNameWorkbench2: svcs.Workbench2,
537 ServiceNameWebsocket: svcs.Websocket,
538 ServiceNameKeepbalance: svcs.Keepbalance,
539 ServiceNameKeepweb: svcs.WebDAV,
540 ServiceNameKeepproxy: svcs.Keepproxy,
541 ServiceNameKeepstore: svcs.Keepstore,