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 MaxKeepBlockBuffers 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 WebDAVCache WebDAVCacheConfig
130 ProviderAppSecret string
134 MailchimpAPIKey string
135 MailchimpListID string
136 SendUserSetupNotificationEmail bool
137 IssueReporterEmailFrom string
138 IssueReporterEmailTo string
139 SupportEmailAddress string
145 MaxRequestLogParamsSize int
153 AnonymousUserToken string
154 AdminNotifierEmailFrom string
155 AutoAdminFirstUser bool
156 AutoAdminUserWithEmail string
157 AutoSetupNewUsers bool
158 AutoSetupNewUsersWithRepository bool
159 AutoSetupNewUsersWithVmUUID string
160 AutoSetupUsernameBlacklist StringSet
161 EmailSubjectPrefix string
162 NewInactiveUserNotificationRecipients StringSet
163 NewUserNotificationRecipients StringSet
164 NewUsersAreActive bool
165 UserNotifierEmailFrom string
166 UserProfileNotificationAddress string
168 Volumes map[string]Volume
170 ActivationContactLink string
171 APIClientConnectTimeout Duration
172 APIClientReceiveTimeout Duration
173 APIResponseCompression bool
174 ApplicationMimetypesWithViewIcon StringSet
175 ArvadosDocsite string
176 ArvadosPublicDataDocURL string
177 DefaultOpenIdPrefix string
178 EnableGettingStartedPopup bool
179 EnablePublicProjectsPage bool
180 FileViewersConfigURL string
181 LogViewerMaxBytes ByteSize
182 MultiSiteSearch string
183 ProfilingEnabled bool
185 RepositoryCache string
186 RunningJobLogRecordsToFetch int
188 ShowRecentCollectionsOnDashboard bool
189 ShowUserAgreementInline bool
190 ShowUserNotifications bool
193 UserProfileFormFields map[string]struct {
195 FormFieldTitle string
196 FormFieldDescription string
199 Options map[string]struct{}
201 UserProfileFormMessage string
205 EnableBetaController14287 bool
209 AccessViaHosts map[URL]VolumeAccess
212 StorageClasses map[string]bool
214 DriverParameters json.RawMessage
217 type S3VolumeDriverParameters struct {
223 LocationConstraint bool
225 ConnectTimeout Duration
231 type AzureVolumeDriverParameters struct {
232 StorageAccountName string
233 StorageAccountKey string
234 StorageBaseURL string
236 RequestTimeout Duration
237 ListBlobsRetryDelay Duration
238 ListBlobsMaxAttempts int
241 type DirectoryVolumeDriverParameters struct {
246 type VolumeAccess struct {
250 type Services struct {
253 DispatchCloud Service
263 WebDAVDownload Service
271 type Service struct {
272 InternalURLs map[URL]ServiceInstance
276 // URL is a url.URL that is also usable as a JSON key/value.
279 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
280 // used as a JSON key/value.
281 func (su *URL) UnmarshalText(text []byte) error {
282 u, err := url.Parse(string(text))
289 func (su URL) MarshalText() ([]byte, error) {
290 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
293 func (su URL) String() string {
294 return (*url.URL)(&su).String()
297 type ServiceInstance struct {
298 // Rendezvous is normally empty; when changing the URL of a
299 // Keepstore service, Rendezvous can be set to the old URL to
300 // preserve rendezvous ordering.
301 Rendezvous string `json:",omitempty"`
304 type PostgreSQL struct {
305 Connection PostgreSQLConnection
309 type PostgreSQLConnection map[string]string
311 type RemoteCluster struct {
319 type InstanceType struct {
325 IncludedScratch ByteSize
326 AddedScratch ByteSize
331 type ContainersConfig struct {
332 CloudVMs CloudVMsConfig
333 CrunchRunCommand string
334 CrunchRunArgumentsList []string
335 DefaultKeepCacheRAM ByteSize
336 DispatchPrivateKey string
337 LogReuseDecisions bool
339 MaxDispatchAttempts int
341 MinRetryPeriod Duration
342 ReserveExtraRAM ByteSize
343 StaleLockTimeout Duration
344 SupportedDockerImageFormats StringSet
345 UsePreemptibleInstances bool
349 GitInternalDir string
354 LogSecondsBetweenEvents int
355 LogThrottlePeriod Duration
358 LimitLogBytesPerJob int
359 LogPartialLineThrottlePeriod Duration
360 LogUpdatePeriod Duration
361 LogUpdateSize ByteSize
365 SbatchArgumentsList []string
366 SbatchEnvironmentVariables map[string]string
368 DNSServerConfDir string
369 DNSServerConfTemplate string
370 DNSServerReloadCommand string
371 DNSServerUpdateCommand string
372 ComputeNodeDomain string
373 ComputeNodeNameservers StringSet
374 AssignNodeHostname string
379 type CloudVMsConfig struct {
382 BootProbeCommand string
384 MaxCloudOpsPerSecond int
385 MaxProbesPerSecond int
386 PollInterval Duration
387 ProbeInterval Duration
389 SyncInterval Duration
390 TimeoutBooting Duration
392 TimeoutProbe Duration
393 TimeoutShutdown Duration
394 TimeoutSignal Duration
396 ResourceTags map[string]string
400 DriverParameters json.RawMessage
403 type InstanceTypeMap map[string]InstanceType
405 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
407 // UnmarshalJSON handles old config files that provide an array of
408 // instance types instead of a hash.
409 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
410 if len(data) > 0 && data[0] == '[' {
411 var arr []InstanceType
412 err := json.Unmarshal(data, &arr)
420 *it = make(map[string]InstanceType, len(arr))
421 for _, t := range arr {
422 if _, ok := (*it)[t.Name]; ok {
423 return errDuplicateInstanceTypeName
425 if t.ProviderType == "" {
426 t.ProviderType = t.Name
429 t.Scratch = t.IncludedScratch + t.AddedScratch
430 } else if t.AddedScratch == 0 {
431 t.AddedScratch = t.Scratch - t.IncludedScratch
432 } else if t.IncludedScratch == 0 {
433 t.IncludedScratch = t.Scratch - t.AddedScratch
436 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
437 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
443 var hash map[string]InstanceType
444 err := json.Unmarshal(data, &hash)
448 // Fill in Name field (and ProviderType field, if not
449 // specified) using hash key.
450 *it = InstanceTypeMap(hash)
451 for name, t := range *it {
453 if t.ProviderType == "" {
454 t.ProviderType = name
461 type StringSet map[string]struct{}
463 // UnmarshalJSON handles old config files that provide an array of
464 // instance types instead of a hash.
465 func (ss *StringSet) UnmarshalJSON(data []byte) error {
466 if len(data) > 0 && data[0] == '[' {
468 err := json.Unmarshal(data, &arr)
476 *ss = make(map[string]struct{}, len(arr))
477 for _, t := range arr {
478 (*ss)[t] = struct{}{}
482 var hash map[string]struct{}
483 err := json.Unmarshal(data, &hash)
487 *ss = make(map[string]struct{}, len(hash))
488 for t, _ := range hash {
489 (*ss)[t] = struct{}{}
495 type ServiceName string
498 ServiceNameRailsAPI ServiceName = "arvados-api-server"
499 ServiceNameController ServiceName = "arvados-controller"
500 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
501 ServiceNameHealth ServiceName = "arvados-health"
502 ServiceNameNodemanager ServiceName = "arvados-node-manager"
503 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
504 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
505 ServiceNameWebsocket ServiceName = "arvados-ws"
506 ServiceNameKeepbalance ServiceName = "keep-balance"
507 ServiceNameKeepweb ServiceName = "keep-web"
508 ServiceNameKeepproxy ServiceName = "keepproxy"
509 ServiceNameKeepstore ServiceName = "keepstore"
512 // Map returns all services as a map, suitable for iterating over all
513 // services or looking up a service by name.
514 func (svcs Services) Map() map[ServiceName]Service {
515 return map[ServiceName]Service{
516 ServiceNameRailsAPI: svcs.RailsAPI,
517 ServiceNameController: svcs.Controller,
518 ServiceNameDispatchCloud: svcs.DispatchCloud,
519 ServiceNameHealth: svcs.Health,
520 ServiceNameNodemanager: svcs.Nodemanager,
521 ServiceNameWorkbench1: svcs.Workbench1,
522 ServiceNameWorkbench2: svcs.Workbench2,
523 ServiceNameWebsocket: svcs.Websocket,
524 ServiceNameKeepbalance: svcs.Keepbalance,
525 ServiceNameKeepweb: svcs.WebDAV,
526 ServiceNameKeepproxy: svcs.Keepproxy,
527 ServiceNameKeepstore: svcs.Keepstore,