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 const DefaultConfigFile = "/etc/arvados/config.yml"
20 Clusters map[string]Cluster
23 // GetConfig returns the current system config, loading it from
24 // configFile if needed.
25 func GetConfig(configFile string) (*Config, error) {
27 err := config.LoadFile(&cfg, configFile)
31 // GetCluster returns the cluster ID and config for the given
32 // cluster, or the default/only configured cluster if clusterID is "".
33 func (sc *Config) GetCluster(clusterID string) (*Cluster, error) {
35 if len(sc.Clusters) == 0 {
36 return nil, fmt.Errorf("no clusters configured")
37 } else if len(sc.Clusters) > 1 {
38 return nil, fmt.Errorf("multiple clusters configured, cannot choose")
40 for id, cc := range sc.Clusters {
46 if cc, ok := sc.Clusters[clusterID]; !ok {
47 return nil, fmt.Errorf("cluster %q is not configured", clusterID)
49 cc.ClusterID = clusterID
55 MaxItemsPerResponse int
56 MaxRequestAmplification int
60 ClusterID string `json:"-"`
61 ManagementToken string
62 SystemRootToken string
64 NodeProfiles map[string]NodeProfile
65 InstanceTypes InstanceTypeMap
68 HTTPRequestTimeout Duration
69 RemoteClusters map[string]RemoteCluster
76 type Services struct {
92 InternalURLs map[URL]ServiceInstance
96 // URL is a url.URL that is also usable as a JSON key/value.
99 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
100 // used as a JSON key/value.
101 func (su *URL) UnmarshalText(text []byte) error {
102 u, err := url.Parse(string(text))
109 func (su URL) MarshalText() ([]byte, error) {
110 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
113 type ServiceInstance struct{}
115 type Logging struct {
120 type PostgreSQL struct {
121 Connection PostgreSQLConnection
125 type PostgreSQLConnection map[string]string
127 type RemoteCluster struct {
128 // API endpoint host or host:port; default is {id}.arvadosapi.com
130 // Perform a proxy request when a local client requests an
131 // object belonging to this remote.
133 // Scheme, default "https". Can be set to "http" for testing.
135 // Disable TLS verify. Can be set to true for testing.
139 type InstanceType struct {
145 IncludedScratch ByteSize
146 AddedScratch ByteSize
151 type Dispatch struct {
152 // PEM encoded SSH key (RSA, DSA, or ECDSA) able to log in to
156 // Max time for workers to come up before abandoning stale
157 // locks from previous run
158 StaleLockTimeout Duration
160 // Interval between queue polls
161 PollInterval Duration
163 // Interval between probes to each worker
164 ProbeInterval Duration
166 // Maximum total worker probes per second
167 MaxProbesPerSecond int
169 // Time before repeating SIGTERM when killing a container
170 TimeoutSignal Duration
172 // Time to give up on SIGTERM and write off the worker
176 type CloudVMs struct {
177 // Shell command that exits zero IFF the VM is fully booted
178 // and ready to run containers, e.g., "mount | grep
180 BootProbeCommand string
182 // Listening port (name or number) of SSH servers on worker
186 SyncInterval Duration
188 // Maximum idle time before automatic shutdown
191 // Maximum booting time before automatic shutdown
192 TimeoutBooting Duration
194 // Maximum time with no successful probes before automatic shutdown
195 TimeoutProbe Duration
197 // Time after shutdown to retry shutdown
198 TimeoutShutdown Duration
200 // Maximum create/destroy-instance operations per second
201 MaxCloudOpsPerSecond int
206 DriverParameters json.RawMessage
209 type InstanceTypeMap map[string]InstanceType
211 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
213 // UnmarshalJSON handles old config files that provide an array of
214 // instance types instead of a hash.
215 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
216 if len(data) > 0 && data[0] == '[' {
217 var arr []InstanceType
218 err := json.Unmarshal(data, &arr)
226 *it = make(map[string]InstanceType, len(arr))
227 for _, t := range arr {
228 if _, ok := (*it)[t.Name]; ok {
229 return errDuplicateInstanceTypeName
231 if t.ProviderType == "" {
232 t.ProviderType = t.Name
235 t.Scratch = t.IncludedScratch + t.AddedScratch
236 } else if t.AddedScratch == 0 {
237 t.AddedScratch = t.Scratch - t.IncludedScratch
238 } else if t.IncludedScratch == 0 {
239 t.IncludedScratch = t.Scratch - t.AddedScratch
242 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
243 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
249 var hash map[string]InstanceType
250 err := json.Unmarshal(data, &hash)
254 // Fill in Name field (and ProviderType field, if not
255 // specified) using hash key.
256 *it = InstanceTypeMap(hash)
257 for name, t := range *it {
259 if t.ProviderType == "" {
260 t.ProviderType = name
267 // GetNodeProfile returns a NodeProfile for the given hostname. An
268 // error is returned if the appropriate configuration can't be
269 // determined (e.g., this does not appear to be a system node). If
270 // node is empty, use the OS-reported hostname.
271 func (cc *Cluster) GetNodeProfile(node string) (*NodeProfile, error) {
273 hostname, err := os.Hostname()
279 if cfg, ok := cc.NodeProfiles[node]; ok {
282 // If node is not listed, but "*" gives a default system node
283 // config, use the default config.
284 if cfg, ok := cc.NodeProfiles["*"]; ok {
287 return nil, fmt.Errorf("config does not provision host %q as a system node", node)
290 type NodeProfile struct {
291 Controller SystemServiceInstance `json:"arvados-controller"`
292 Health SystemServiceInstance `json:"arvados-health"`
293 Keepbalance SystemServiceInstance `json:"keep-balance"`
294 Keepproxy SystemServiceInstance `json:"keepproxy"`
295 Keepstore SystemServiceInstance `json:"keepstore"`
296 Keepweb SystemServiceInstance `json:"keep-web"`
297 Nodemanager SystemServiceInstance `json:"arvados-node-manager"`
298 DispatchCloud SystemServiceInstance `json:"arvados-dispatch-cloud"`
299 RailsAPI SystemServiceInstance `json:"arvados-api-server"`
300 Websocket SystemServiceInstance `json:"arvados-ws"`
301 Workbench SystemServiceInstance `json:"arvados-workbench"`
304 type ServiceName string
307 ServiceNameRailsAPI ServiceName = "arvados-api-server"
308 ServiceNameController ServiceName = "arvados-controller"
309 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
310 ServiceNameNodemanager ServiceName = "arvados-node-manager"
311 ServiceNameWorkbench ServiceName = "arvados-workbench"
312 ServiceNameWebsocket ServiceName = "arvados-ws"
313 ServiceNameKeepbalance ServiceName = "keep-balance"
314 ServiceNameKeepweb ServiceName = "keep-web"
315 ServiceNameKeepproxy ServiceName = "keepproxy"
316 ServiceNameKeepstore ServiceName = "keepstore"
319 // ServicePorts returns the configured listening address (or "" if
320 // disabled) for each service on the node.
321 func (np *NodeProfile) ServicePorts() map[ServiceName]string {
322 return map[ServiceName]string{
323 ServiceNameRailsAPI: np.RailsAPI.Listen,
324 ServiceNameController: np.Controller.Listen,
325 ServiceNameDispatchCloud: np.DispatchCloud.Listen,
326 ServiceNameNodemanager: np.Nodemanager.Listen,
327 ServiceNameWorkbench: np.Workbench.Listen,
328 ServiceNameWebsocket: np.Websocket.Listen,
329 ServiceNameKeepbalance: np.Keepbalance.Listen,
330 ServiceNameKeepweb: np.Keepweb.Listen,
331 ServiceNameKeepproxy: np.Keepproxy.Listen,
332 ServiceNameKeepstore: np.Keepstore.Listen,
336 type SystemServiceInstance struct {