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 MaxRequestAmplification int
86 RailsSessionSecretToken string
87 RequestTimeout Duration
89 WebsocketClientEventQueue int
90 WebsocketServerEventQueue int
95 UnloggedAttributes StringSet
100 BlobSigningTTL Duration
101 CollectionVersioning bool
102 DefaultTrashLifetime Duration
103 DefaultReplication int
104 ManagedProperties map[string]struct {
109 PreserveVersionIfIdle Duration
110 TrashSweepInterval Duration
113 WebDAVCache WebDAVCacheConfig
119 ProviderAppSecret string
122 RemoteTokenRefresh Duration
125 MailchimpAPIKey string
126 MailchimpListID string
127 SendUserSetupNotificationEmail bool
128 IssueReporterEmailFrom string
129 IssueReporterEmailTo string
130 SupportEmailAddress string
136 MaxRequestLogParamsSize int
144 AnonymousUserToken string
145 AdminNotifierEmailFrom string
146 AutoAdminFirstUser bool
147 AutoAdminUserWithEmail string
148 AutoSetupNewUsers bool
149 AutoSetupNewUsersWithRepository bool
150 AutoSetupNewUsersWithVmUUID string
151 AutoSetupUsernameBlacklist StringSet
152 EmailSubjectPrefix string
153 NewInactiveUserNotificationRecipients StringSet
154 NewUserNotificationRecipients StringSet
155 NewUsersAreActive bool
156 UserNotifierEmailFrom string
157 UserProfileNotificationAddress string
160 ActivationContactLink string
161 APIClientConnectTimeout Duration
162 APIClientReceiveTimeout Duration
163 APIResponseCompression bool
164 ApplicationMimetypesWithViewIcon StringSet
165 ArvadosDocsite string
166 ArvadosPublicDataDocURL string
167 DefaultOpenIdPrefix string
168 EnableGettingStartedPopup bool
169 EnablePublicProjectsPage bool
170 FileViewersConfigURL string
171 LogViewerMaxBytes ByteSize
172 MultiSiteSearch string
173 ProfilingEnabled bool
175 RepositoryCache string
176 RunningJobLogRecordsToFetch int
178 ShowRecentCollectionsOnDashboard bool
179 ShowUserAgreementInline bool
180 ShowUserNotifications bool
183 UserProfileFormFields map[string]struct {
185 FormFieldTitle string
186 FormFieldDescription string
189 Options map[string]struct{}
191 UserProfileFormMessage string
195 EnableBetaController14287 bool
198 type Services struct {
201 DispatchCloud Service
211 WebDAVDownload Service
219 type Service struct {
220 InternalURLs map[URL]ServiceInstance
224 // URL is a url.URL that is also usable as a JSON key/value.
227 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
228 // used as a JSON key/value.
229 func (su *URL) UnmarshalText(text []byte) error {
230 u, err := url.Parse(string(text))
237 func (su URL) MarshalText() ([]byte, error) {
238 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
241 type ServiceInstance struct{}
243 type PostgreSQL struct {
244 Connection PostgreSQLConnection
248 type PostgreSQLConnection map[string]string
250 type RemoteCluster struct {
258 type InstanceType struct {
264 IncludedScratch ByteSize
265 AddedScratch ByteSize
270 type ContainersConfig struct {
271 CloudVMs CloudVMsConfig
272 CrunchRunCommand string
273 CrunchRunArgumentsList []string
274 DefaultKeepCacheRAM ByteSize
275 DispatchPrivateKey string
276 LogReuseDecisions bool
278 MaxDispatchAttempts int
280 MinRetryPeriod Duration
281 ReserveExtraRAM ByteSize
282 StaleLockTimeout Duration
283 SupportedDockerImageFormats StringSet
284 UsePreemptibleInstances bool
288 GitInternalDir string
293 LogSecondsBetweenEvents int
294 LogThrottlePeriod Duration
297 LimitLogBytesPerJob int
298 LogPartialLineThrottlePeriod Duration
299 LogUpdatePeriod Duration
300 LogUpdateSize ByteSize
304 SbatchArgumentsList []string
305 SbatchEnvironmentVariables map[string]string
307 DNSServerConfDir string
308 DNSServerConfTemplate string
309 DNSServerReloadCommand string
310 DNSServerUpdateCommand string
311 ComputeNodeDomain string
312 ComputeNodeNameservers StringSet
313 AssignNodeHostname string
318 type CloudVMsConfig struct {
321 BootProbeCommand string
323 MaxCloudOpsPerSecond int
324 MaxProbesPerSecond int
325 PollInterval Duration
326 ProbeInterval Duration
328 SyncInterval Duration
329 TimeoutBooting Duration
331 TimeoutProbe Duration
332 TimeoutShutdown Duration
333 TimeoutSignal Duration
335 ResourceTags map[string]string
339 DriverParameters json.RawMessage
342 type InstanceTypeMap map[string]InstanceType
344 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
346 // UnmarshalJSON handles old config files that provide an array of
347 // instance types instead of a hash.
348 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
349 if len(data) > 0 && data[0] == '[' {
350 var arr []InstanceType
351 err := json.Unmarshal(data, &arr)
359 *it = make(map[string]InstanceType, len(arr))
360 for _, t := range arr {
361 if _, ok := (*it)[t.Name]; ok {
362 return errDuplicateInstanceTypeName
364 if t.ProviderType == "" {
365 t.ProviderType = t.Name
368 t.Scratch = t.IncludedScratch + t.AddedScratch
369 } else if t.AddedScratch == 0 {
370 t.AddedScratch = t.Scratch - t.IncludedScratch
371 } else if t.IncludedScratch == 0 {
372 t.IncludedScratch = t.Scratch - t.AddedScratch
375 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
376 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
382 var hash map[string]InstanceType
383 err := json.Unmarshal(data, &hash)
387 // Fill in Name field (and ProviderType field, if not
388 // specified) using hash key.
389 *it = InstanceTypeMap(hash)
390 for name, t := range *it {
392 if t.ProviderType == "" {
393 t.ProviderType = name
400 type StringSet map[string]struct{}
402 // UnmarshalJSON handles old config files that provide an array of
403 // instance types instead of a hash.
404 func (ss *StringSet) UnmarshalJSON(data []byte) error {
405 if len(data) > 0 && data[0] == '[' {
407 err := json.Unmarshal(data, &arr)
415 *ss = make(map[string]struct{}, len(arr))
416 for _, t := range arr {
417 (*ss)[t] = struct{}{}
421 var hash map[string]struct{}
422 err := json.Unmarshal(data, &hash)
426 *ss = make(map[string]struct{}, len(hash))
427 for t, _ := range hash {
428 (*ss)[t] = struct{}{}
434 type ServiceName string
437 ServiceNameRailsAPI ServiceName = "arvados-api-server"
438 ServiceNameController ServiceName = "arvados-controller"
439 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
440 ServiceNameHealth ServiceName = "arvados-health"
441 ServiceNameNodemanager ServiceName = "arvados-node-manager"
442 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
443 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
444 ServiceNameWebsocket ServiceName = "arvados-ws"
445 ServiceNameKeepbalance ServiceName = "keep-balance"
446 ServiceNameKeepweb ServiceName = "keep-web"
447 ServiceNameKeepproxy ServiceName = "keepproxy"
448 ServiceNameKeepstore ServiceName = "keepstore"
451 // Map returns all services as a map, suitable for iterating over all
452 // services or looking up a service by name.
453 func (svcs Services) Map() map[ServiceName]Service {
454 return map[ServiceName]Service{
455 ServiceNameRailsAPI: svcs.RailsAPI,
456 ServiceNameController: svcs.Controller,
457 ServiceNameDispatchCloud: svcs.DispatchCloud,
458 ServiceNameHealth: svcs.Health,
459 ServiceNameNodemanager: svcs.Nodemanager,
460 ServiceNameWorkbench1: svcs.Workbench1,
461 ServiceNameWorkbench2: svcs.Workbench2,
462 ServiceNameWebsocket: svcs.Websocket,
463 ServiceNameKeepbalance: svcs.Keepbalance,
464 ServiceNameKeepweb: svcs.WebDAV,
465 ServiceNameKeepproxy: svcs.Keepproxy,
466 ServiceNameKeepstore: svcs.Keepstore,