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
30 // GetConfig returns the current system config, loading it from
31 // configFile if needed.
32 func GetConfig(configFile string) (*Config, error) {
34 err := config.LoadFile(&cfg, configFile)
38 // GetCluster returns the cluster ID and config for the given
39 // cluster, or the default/only configured cluster if clusterID is "".
40 func (sc *Config) GetCluster(clusterID string) (*Cluster, error) {
42 if len(sc.Clusters) == 0 {
43 return nil, fmt.Errorf("no clusters configured")
44 } else if len(sc.Clusters) > 1 {
45 return nil, fmt.Errorf("multiple clusters configured, cannot choose")
47 for id, cc := range sc.Clusters {
53 if cc, ok := sc.Clusters[clusterID]; !ok {
54 return nil, fmt.Errorf("cluster %q is not configured", clusterID)
56 cc.ClusterID = clusterID
61 type WebDAVCacheConfig struct {
65 MaxCollectionEntries int
66 MaxCollectionBytes int64
67 MaxPermissionEntries int
72 ClusterID string `json:"-"`
73 ManagementToken string
74 SystemRootToken string
76 InstanceTypes InstanceTypeMap
77 Containers ContainersConfig
78 RemoteClusters map[string]RemoteCluster
82 AsyncPermissionsUpdateInterval Duration
83 DisabledAPIs StringSet
84 MaxIndexDatabaseRead int
85 MaxItemsPerResponse int
86 MaxConcurrentRequests int
87 MaxKeepBlobBuffers int
88 MaxRequestAmplification int
90 RailsSessionSecretToken string
91 RequestTimeout Duration
93 WebsocketClientEventQueue int
94 WebsocketServerEventQueue int
95 KeepServiceRequestTimeout Duration
100 UnloggedAttributes StringSet
104 BlobSigningKey string
105 BlobSigningTTL Duration
107 BlobTrashLifetime Duration
108 BlobTrashCheckInterval Duration
109 BlobTrashConcurrency int
110 BlobDeleteConcurrency int
111 BlobReplicateConcurrency int
112 CollectionVersioning bool
113 DefaultTrashLifetime Duration
114 DefaultReplication int
115 ManagedProperties map[string]struct {
120 PreserveVersionIfIdle Duration
121 TrashSweepInterval Duration
123 ForwardSlashNameSubstitution string
125 BlobMissingReport string
126 BalancePeriod Duration
127 BalanceCollectionBatch int
128 BalanceCollectionBuffers int
130 WebDAVCache WebDAVCacheConfig
145 SearchAttribute string
146 SearchBindUser string
147 SearchBindPassword string
150 EmailAttribute string
151 UsernameAttribute string
157 AlternateEmailAddresses bool
162 DefaultEmailDomain string
167 ProviderAppSecret string
170 RemoteTokenRefresh Duration
173 MailchimpAPIKey string
174 MailchimpListID string
175 SendUserSetupNotificationEmail bool
176 IssueReporterEmailFrom string
177 IssueReporterEmailTo string
178 SupportEmailAddress string
184 MaxRequestLogParamsSize int
192 AnonymousUserToken string
193 AdminNotifierEmailFrom string
194 AutoAdminFirstUser bool
195 AutoAdminUserWithEmail string
196 AutoSetupNewUsers bool
197 AutoSetupNewUsersWithRepository bool
198 AutoSetupNewUsersWithVmUUID string
199 AutoSetupUsernameBlacklist StringSet
200 EmailSubjectPrefix string
201 NewInactiveUserNotificationRecipients StringSet
202 NewUserNotificationRecipients StringSet
203 NewUsersAreActive bool
204 UserNotifierEmailFrom string
205 UserProfileNotificationAddress string
206 PreferDomainForUsername string
208 Volumes map[string]Volume
210 ActivationContactLink string
211 APIClientConnectTimeout Duration
212 APIClientReceiveTimeout Duration
213 APIResponseCompression bool
214 ApplicationMimetypesWithViewIcon StringSet
215 ArvadosDocsite string
216 ArvadosPublicDataDocURL string
217 DefaultOpenIdPrefix string
218 EnableGettingStartedPopup bool
219 EnablePublicProjectsPage bool
220 FileViewersConfigURL string
221 LogViewerMaxBytes ByteSize
222 MultiSiteSearch string
223 ProfilingEnabled bool
225 RepositoryCache string
226 RunningJobLogRecordsToFetch int
228 ShowRecentCollectionsOnDashboard bool
229 ShowUserAgreementInline bool
230 ShowUserNotifications bool
233 UserProfileFormFields map[string]struct {
235 FormFieldTitle string
236 FormFieldDescription string
239 Options map[string]struct{}
241 UserProfileFormMessage string
243 WelcomePageHTML string
244 InactivePageHTML string
245 SSHHelpPageHTML string
246 SSHHelpHostSuffix string
249 ForceLegacyAPI14 bool
253 AccessViaHosts map[URL]VolumeAccess
256 StorageClasses map[string]bool
258 DriverParameters json.RawMessage
261 type S3VolumeDriverParameters struct {
267 LocationConstraint bool
269 ConnectTimeout Duration
275 type AzureVolumeDriverParameters struct {
276 StorageAccountName string
277 StorageAccountKey string
278 StorageBaseURL string
280 RequestTimeout Duration
281 ListBlobsRetryDelay Duration
282 ListBlobsMaxAttempts int
285 type DirectoryVolumeDriverParameters struct {
290 type VolumeAccess struct {
294 type Services struct {
297 DispatchCloud Service
307 WebDAVDownload Service
315 type Service struct {
316 InternalURLs map[URL]ServiceInstance
320 // URL is a url.URL that is also usable as a JSON key/value.
323 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
324 // used as a JSON key/value.
325 func (su *URL) UnmarshalText(text []byte) error {
326 u, err := url.Parse(string(text))
329 if su.Path == "" && su.Host != "" {
330 // http://example really means http://example/
337 func (su URL) MarshalText() ([]byte, error) {
338 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
341 func (su URL) String() string {
342 return (*url.URL)(&su).String()
345 type ServiceInstance struct {
346 Rendezvous string `json:",omitempty"`
349 type PostgreSQL struct {
350 Connection PostgreSQLConnection
354 type PostgreSQLConnection map[string]string
356 type RemoteCluster struct {
364 type InstanceType struct {
370 IncludedScratch ByteSize
371 AddedScratch ByteSize
376 type ContainersConfig struct {
377 CloudVMs CloudVMsConfig
378 CrunchRunCommand string
379 CrunchRunArgumentsList []string
380 DefaultKeepCacheRAM ByteSize
381 DispatchPrivateKey string
382 LogReuseDecisions bool
384 MaxDispatchAttempts int
386 MinRetryPeriod Duration
387 ReserveExtraRAM ByteSize
388 StaleLockTimeout Duration
389 SupportedDockerImageFormats StringSet
390 UsePreemptibleInstances bool
394 GitInternalDir string
399 LogSecondsBetweenEvents Duration
400 LogThrottlePeriod Duration
403 LimitLogBytesPerJob int
404 LogPartialLineThrottlePeriod Duration
405 LogUpdatePeriod Duration
406 LogUpdateSize ByteSize
410 SbatchArgumentsList []string
411 SbatchEnvironmentVariables map[string]string
413 DNSServerConfDir string
414 DNSServerConfTemplate string
415 DNSServerReloadCommand string
416 DNSServerUpdateCommand string
417 ComputeNodeDomain string
418 ComputeNodeNameservers StringSet
419 AssignNodeHostname string
424 type CloudVMsConfig struct {
427 BootProbeCommand string
428 DeployRunnerBinary string
430 MaxCloudOpsPerSecond int
431 MaxProbesPerSecond int
432 PollInterval Duration
433 ProbeInterval Duration
435 SyncInterval Duration
436 TimeoutBooting Duration
438 TimeoutProbe Duration
439 TimeoutShutdown Duration
440 TimeoutSignal Duration
442 ResourceTags map[string]string
446 DriverParameters json.RawMessage
449 type InstanceTypeMap map[string]InstanceType
451 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
453 // UnmarshalJSON handles old config files that provide an array of
454 // instance types instead of a hash.
455 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
456 fixup := func(t InstanceType) (InstanceType, error) {
457 if t.ProviderType == "" {
458 t.ProviderType = t.Name
461 t.Scratch = t.IncludedScratch + t.AddedScratch
462 } else if t.AddedScratch == 0 {
463 t.AddedScratch = t.Scratch - t.IncludedScratch
464 } else if t.IncludedScratch == 0 {
465 t.IncludedScratch = t.Scratch - t.AddedScratch
468 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
469 return t, fmt.Errorf("InstanceType %q: Scratch != (IncludedScratch + AddedScratch)", t.Name)
474 if len(data) > 0 && data[0] == '[' {
475 var arr []InstanceType
476 err := json.Unmarshal(data, &arr)
484 *it = make(map[string]InstanceType, len(arr))
485 for _, t := range arr {
486 if _, ok := (*it)[t.Name]; ok {
487 return errDuplicateInstanceTypeName
497 var hash map[string]InstanceType
498 err := json.Unmarshal(data, &hash)
502 // Fill in Name field (and ProviderType field, if not
503 // specified) using hash key.
504 *it = InstanceTypeMap(hash)
505 for name, t := range *it {
516 type StringSet map[string]struct{}
518 // UnmarshalJSON handles old config files that provide an array of
519 // instance types instead of a hash.
520 func (ss *StringSet) UnmarshalJSON(data []byte) error {
521 if len(data) > 0 && data[0] == '[' {
523 err := json.Unmarshal(data, &arr)
531 *ss = make(map[string]struct{}, len(arr))
532 for _, t := range arr {
533 (*ss)[t] = struct{}{}
537 var hash map[string]struct{}
538 err := json.Unmarshal(data, &hash)
542 *ss = make(map[string]struct{}, len(hash))
543 for t, _ := range hash {
544 (*ss)[t] = struct{}{}
550 type ServiceName string
553 ServiceNameRailsAPI ServiceName = "arvados-api-server"
554 ServiceNameController ServiceName = "arvados-controller"
555 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
556 ServiceNameHealth ServiceName = "arvados-health"
557 ServiceNameNodemanager ServiceName = "arvados-node-manager"
558 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
559 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
560 ServiceNameWebsocket ServiceName = "arvados-ws"
561 ServiceNameKeepbalance ServiceName = "keep-balance"
562 ServiceNameKeepweb ServiceName = "keep-web"
563 ServiceNameKeepproxy ServiceName = "keepproxy"
564 ServiceNameKeepstore ServiceName = "keepstore"
567 // Map returns all services as a map, suitable for iterating over all
568 // services or looking up a service by name.
569 func (svcs Services) Map() map[ServiceName]Service {
570 return map[ServiceName]Service{
571 ServiceNameRailsAPI: svcs.RailsAPI,
572 ServiceNameController: svcs.Controller,
573 ServiceNameDispatchCloud: svcs.DispatchCloud,
574 ServiceNameHealth: svcs.Health,
575 ServiceNameNodemanager: svcs.Nodemanager,
576 ServiceNameWorkbench1: svcs.Workbench1,
577 ServiceNameWorkbench2: svcs.Workbench2,
578 ServiceNameWebsocket: svcs.Websocket,
579 ServiceNameKeepbalance: svcs.Keepbalance,
580 ServiceNameKeepweb: svcs.WebDAV,
581 ServiceNameKeepproxy: svcs.Keepproxy,
582 ServiceNameKeepstore: svcs.Keepstore,