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
178 Volumes map[string]Volume
180 ActivationContactLink string
181 APIClientConnectTimeout Duration
182 APIClientReceiveTimeout Duration
183 APIResponseCompression bool
184 ApplicationMimetypesWithViewIcon StringSet
185 ArvadosDocsite string
186 ArvadosPublicDataDocURL string
187 DefaultOpenIdPrefix string
188 EnableGettingStartedPopup bool
189 EnablePublicProjectsPage bool
190 FileViewersConfigURL string
191 LogViewerMaxBytes ByteSize
192 MultiSiteSearch string
193 ProfilingEnabled bool
195 RepositoryCache string
196 RunningJobLogRecordsToFetch int
198 ShowRecentCollectionsOnDashboard bool
199 ShowUserAgreementInline bool
200 ShowUserNotifications bool
203 UserProfileFormFields map[string]struct {
205 FormFieldTitle string
206 FormFieldDescription string
209 Options map[string]struct{}
211 UserProfileFormMessage string
213 WelcomePageHTML string
214 InactivePageHTML string
217 EnableBetaController14287 bool
221 AccessViaHosts map[URL]VolumeAccess
224 StorageClasses map[string]bool
226 DriverParameters json.RawMessage
229 type S3VolumeDriverParameters struct {
235 LocationConstraint bool
237 ConnectTimeout Duration
243 type AzureVolumeDriverParameters struct {
244 StorageAccountName string
245 StorageAccountKey string
246 StorageBaseURL string
248 RequestTimeout Duration
249 ListBlobsRetryDelay Duration
250 ListBlobsMaxAttempts int
253 type DirectoryVolumeDriverParameters struct {
258 type VolumeAccess struct {
262 type Services struct {
265 DispatchCloud Service
275 WebDAVDownload Service
283 type Service struct {
284 InternalURLs map[URL]ServiceInstance
288 // URL is a url.URL that is also usable as a JSON key/value.
291 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
292 // used as a JSON key/value.
293 func (su *URL) UnmarshalText(text []byte) error {
294 u, err := url.Parse(string(text))
301 func (su URL) MarshalText() ([]byte, error) {
302 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
305 func (su URL) String() string {
306 return (*url.URL)(&su).String()
309 type ServiceInstance struct {
310 Rendezvous string `json:",omitempty"`
313 type PostgreSQL struct {
314 Connection PostgreSQLConnection
318 type PostgreSQLConnection map[string]string
320 type RemoteCluster struct {
328 type InstanceType struct {
334 IncludedScratch ByteSize
335 AddedScratch ByteSize
340 type ContainersConfig struct {
341 CloudVMs CloudVMsConfig
342 CrunchRunCommand string
343 CrunchRunArgumentsList []string
344 DefaultKeepCacheRAM ByteSize
345 DispatchPrivateKey string
346 LogReuseDecisions bool
348 MaxDispatchAttempts int
350 MinRetryPeriod Duration
351 ReserveExtraRAM ByteSize
352 StaleLockTimeout Duration
353 SupportedDockerImageFormats StringSet
354 UsePreemptibleInstances bool
358 GitInternalDir string
363 LogSecondsBetweenEvents int
364 LogThrottlePeriod Duration
367 LimitLogBytesPerJob int
368 LogPartialLineThrottlePeriod Duration
369 LogUpdatePeriod Duration
370 LogUpdateSize ByteSize
374 SbatchArgumentsList []string
375 SbatchEnvironmentVariables map[string]string
377 DNSServerConfDir string
378 DNSServerConfTemplate string
379 DNSServerReloadCommand string
380 DNSServerUpdateCommand string
381 ComputeNodeDomain string
382 ComputeNodeNameservers StringSet
383 AssignNodeHostname string
388 type CloudVMsConfig struct {
391 BootProbeCommand string
393 MaxCloudOpsPerSecond int
394 MaxProbesPerSecond int
395 PollInterval Duration
396 ProbeInterval Duration
398 SyncInterval Duration
399 TimeoutBooting Duration
401 TimeoutProbe Duration
402 TimeoutShutdown Duration
403 TimeoutSignal Duration
405 ResourceTags map[string]string
409 DriverParameters json.RawMessage
412 type InstanceTypeMap map[string]InstanceType
414 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
416 // UnmarshalJSON handles old config files that provide an array of
417 // instance types instead of a hash.
418 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
419 if len(data) > 0 && data[0] == '[' {
420 var arr []InstanceType
421 err := json.Unmarshal(data, &arr)
429 *it = make(map[string]InstanceType, len(arr))
430 for _, t := range arr {
431 if _, ok := (*it)[t.Name]; ok {
432 return errDuplicateInstanceTypeName
434 if t.ProviderType == "" {
435 t.ProviderType = t.Name
438 t.Scratch = t.IncludedScratch + t.AddedScratch
439 } else if t.AddedScratch == 0 {
440 t.AddedScratch = t.Scratch - t.IncludedScratch
441 } else if t.IncludedScratch == 0 {
442 t.IncludedScratch = t.Scratch - t.AddedScratch
445 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
446 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
452 var hash map[string]InstanceType
453 err := json.Unmarshal(data, &hash)
457 // Fill in Name field (and ProviderType field, if not
458 // specified) using hash key.
459 *it = InstanceTypeMap(hash)
460 for name, t := range *it {
462 if t.ProviderType == "" {
463 t.ProviderType = name
470 type StringSet map[string]struct{}
472 // UnmarshalJSON handles old config files that provide an array of
473 // instance types instead of a hash.
474 func (ss *StringSet) UnmarshalJSON(data []byte) error {
475 if len(data) > 0 && data[0] == '[' {
477 err := json.Unmarshal(data, &arr)
485 *ss = make(map[string]struct{}, len(arr))
486 for _, t := range arr {
487 (*ss)[t] = struct{}{}
491 var hash map[string]struct{}
492 err := json.Unmarshal(data, &hash)
496 *ss = make(map[string]struct{}, len(hash))
497 for t, _ := range hash {
498 (*ss)[t] = struct{}{}
504 type ServiceName string
507 ServiceNameRailsAPI ServiceName = "arvados-api-server"
508 ServiceNameController ServiceName = "arvados-controller"
509 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
510 ServiceNameHealth ServiceName = "arvados-health"
511 ServiceNameNodemanager ServiceName = "arvados-node-manager"
512 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
513 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
514 ServiceNameWebsocket ServiceName = "arvados-ws"
515 ServiceNameKeepbalance ServiceName = "keep-balance"
516 ServiceNameKeepweb ServiceName = "keep-web"
517 ServiceNameKeepproxy ServiceName = "keepproxy"
518 ServiceNameKeepstore ServiceName = "keepstore"
521 // Map returns all services as a map, suitable for iterating over all
522 // services or looking up a service by name.
523 func (svcs Services) Map() map[ServiceName]Service {
524 return map[ServiceName]Service{
525 ServiceNameRailsAPI: svcs.RailsAPI,
526 ServiceNameController: svcs.Controller,
527 ServiceNameDispatchCloud: svcs.DispatchCloud,
528 ServiceNameHealth: svcs.Health,
529 ServiceNameNodemanager: svcs.Nodemanager,
530 ServiceNameWorkbench1: svcs.Workbench1,
531 ServiceNameWorkbench2: svcs.Workbench2,
532 ServiceNameWebsocket: svcs.Websocket,
533 ServiceNameKeepbalance: svcs.Keepbalance,
534 ServiceNameKeepweb: svcs.WebDAV,
535 ServiceNameKeepproxy: svcs.Keepproxy,
536 ServiceNameKeepstore: svcs.Keepstore,