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 {
268 LocationConstraint bool
271 ConnectTimeout Duration
277 type AzureVolumeDriverParameters struct {
278 StorageAccountName string
279 StorageAccountKey string
280 StorageBaseURL string
282 RequestTimeout Duration
283 ListBlobsRetryDelay Duration
284 ListBlobsMaxAttempts int
287 type DirectoryVolumeDriverParameters struct {
292 type VolumeAccess struct {
296 type Services struct {
299 DispatchCloud Service
309 WebDAVDownload Service
317 type Service struct {
318 InternalURLs map[URL]ServiceInstance
322 // URL is a url.URL that is also usable as a JSON key/value.
325 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
326 // used as a JSON key/value.
327 func (su *URL) UnmarshalText(text []byte) error {
328 u, err := url.Parse(string(text))
331 if su.Path == "" && su.Host != "" {
332 // http://example really means http://example/
339 func (su URL) MarshalText() ([]byte, error) {
340 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
343 func (su URL) String() string {
344 return (*url.URL)(&su).String()
347 type ServiceInstance struct {
348 Rendezvous string `json:",omitempty"`
351 type PostgreSQL struct {
352 Connection PostgreSQLConnection
356 type PostgreSQLConnection map[string]string
358 type RemoteCluster struct {
366 type InstanceType struct {
372 IncludedScratch ByteSize
373 AddedScratch ByteSize
378 type ContainersConfig struct {
379 CloudVMs CloudVMsConfig
380 CrunchRunCommand string
381 CrunchRunArgumentsList []string
382 DefaultKeepCacheRAM ByteSize
383 DispatchPrivateKey string
384 LogReuseDecisions bool
386 MaxDispatchAttempts int
388 MinRetryPeriod Duration
389 ReserveExtraRAM ByteSize
390 StaleLockTimeout Duration
391 SupportedDockerImageFormats StringSet
392 UsePreemptibleInstances bool
396 GitInternalDir string
401 LogSecondsBetweenEvents Duration
402 LogThrottlePeriod Duration
405 LimitLogBytesPerJob int
406 LogPartialLineThrottlePeriod Duration
407 LogUpdatePeriod Duration
408 LogUpdateSize ByteSize
412 SbatchArgumentsList []string
413 SbatchEnvironmentVariables map[string]string
415 DNSServerConfDir string
416 DNSServerConfTemplate string
417 DNSServerReloadCommand string
418 DNSServerUpdateCommand string
419 ComputeNodeDomain string
420 ComputeNodeNameservers StringSet
421 AssignNodeHostname string
426 type CloudVMsConfig struct {
429 BootProbeCommand string
430 DeployRunnerBinary string
432 MaxCloudOpsPerSecond int
433 MaxProbesPerSecond int
434 PollInterval Duration
435 ProbeInterval Duration
437 SyncInterval Duration
438 TimeoutBooting Duration
440 TimeoutProbe Duration
441 TimeoutShutdown Duration
442 TimeoutSignal Duration
444 ResourceTags map[string]string
448 DriverParameters json.RawMessage
451 type InstanceTypeMap map[string]InstanceType
453 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
455 // UnmarshalJSON handles old config files that provide an array of
456 // instance types instead of a hash.
457 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
458 fixup := func(t InstanceType) (InstanceType, error) {
459 if t.ProviderType == "" {
460 t.ProviderType = t.Name
463 t.Scratch = t.IncludedScratch + t.AddedScratch
464 } else if t.AddedScratch == 0 {
465 t.AddedScratch = t.Scratch - t.IncludedScratch
466 } else if t.IncludedScratch == 0 {
467 t.IncludedScratch = t.Scratch - t.AddedScratch
470 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
471 return t, fmt.Errorf("InstanceType %q: Scratch != (IncludedScratch + AddedScratch)", t.Name)
476 if len(data) > 0 && data[0] == '[' {
477 var arr []InstanceType
478 err := json.Unmarshal(data, &arr)
486 *it = make(map[string]InstanceType, len(arr))
487 for _, t := range arr {
488 if _, ok := (*it)[t.Name]; ok {
489 return errDuplicateInstanceTypeName
499 var hash map[string]InstanceType
500 err := json.Unmarshal(data, &hash)
504 // Fill in Name field (and ProviderType field, if not
505 // specified) using hash key.
506 *it = InstanceTypeMap(hash)
507 for name, t := range *it {
518 type StringSet map[string]struct{}
520 // UnmarshalJSON handles old config files that provide an array of
521 // instance types instead of a hash.
522 func (ss *StringSet) UnmarshalJSON(data []byte) error {
523 if len(data) > 0 && data[0] == '[' {
525 err := json.Unmarshal(data, &arr)
533 *ss = make(map[string]struct{}, len(arr))
534 for _, t := range arr {
535 (*ss)[t] = struct{}{}
539 var hash map[string]struct{}
540 err := json.Unmarshal(data, &hash)
544 *ss = make(map[string]struct{}, len(hash))
545 for t, _ := range hash {
546 (*ss)[t] = struct{}{}
552 type ServiceName string
555 ServiceNameRailsAPI ServiceName = "arvados-api-server"
556 ServiceNameController ServiceName = "arvados-controller"
557 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
558 ServiceNameHealth ServiceName = "arvados-health"
559 ServiceNameNodemanager ServiceName = "arvados-node-manager"
560 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
561 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
562 ServiceNameWebsocket ServiceName = "arvados-ws"
563 ServiceNameKeepbalance ServiceName = "keep-balance"
564 ServiceNameKeepweb ServiceName = "keep-web"
565 ServiceNameKeepproxy ServiceName = "keepproxy"
566 ServiceNameKeepstore ServiceName = "keepstore"
569 // Map returns all services as a map, suitable for iterating over all
570 // services or looking up a service by name.
571 func (svcs Services) Map() map[ServiceName]Service {
572 return map[ServiceName]Service{
573 ServiceNameRailsAPI: svcs.RailsAPI,
574 ServiceNameController: svcs.Controller,
575 ServiceNameDispatchCloud: svcs.DispatchCloud,
576 ServiceNameHealth: svcs.Health,
577 ServiceNameNodemanager: svcs.Nodemanager,
578 ServiceNameWorkbench1: svcs.Workbench1,
579 ServiceNameWorkbench2: svcs.Workbench2,
580 ServiceNameWebsocket: svcs.Websocket,
581 ServiceNameKeepbalance: svcs.Keepbalance,
582 ServiceNameKeepweb: svcs.WebDAV,
583 ServiceNameKeepproxy: svcs.Keepproxy,
584 ServiceNameKeepstore: svcs.Keepstore,