1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
11 "git.curoverse.com/arvados.git/sdk/go/config"
14 const DefaultConfigFile = "/etc/arvados/config.yml"
17 Clusters map[string]Cluster
20 // GetConfig returns the current system config, loading it from
21 // configFile if needed.
22 func GetConfig(configFile string) (*Config, error) {
24 err := config.LoadFile(&cfg, configFile)
28 // GetCluster returns the cluster ID and config for the given
29 // cluster, or the default/only configured cluster if clusterID is "".
30 func (sc *Config) GetCluster(clusterID string) (*Cluster, error) {
32 if len(sc.Clusters) == 0 {
33 return nil, fmt.Errorf("no clusters configured")
34 } else if len(sc.Clusters) > 1 {
35 return nil, fmt.Errorf("multiple clusters configured, cannot choose")
37 for id, cc := range sc.Clusters {
43 if cc, ok := sc.Clusters[clusterID]; !ok {
44 return nil, fmt.Errorf("cluster %q is not configured", clusterID)
46 cc.ClusterID = clusterID
52 ClusterID string `json:"-"`
53 ManagementToken string
54 SystemNodes map[string]SystemNode
55 InstanceTypes []InstanceType
56 HTTPRequestTimeout Duration
59 type InstanceType struct {
68 // GetThisSystemNode returns a SystemNode for the node we're running
70 func (cc *Cluster) GetThisSystemNode() (*SystemNode, error) {
71 return cc.GetSystemNode("")
74 // GetSystemNode returns a SystemNode for the given hostname. An error
75 // is returned if the appropriate configuration can't be determined
76 // (e.g., this does not appear to be a system node). If node is empty,
77 // use the OS-reported hostname.
78 func (cc *Cluster) GetSystemNode(node string) (*SystemNode, error) {
80 hostname, err := os.Hostname()
86 if cfg, ok := cc.SystemNodes[node]; ok {
89 // If node is not listed, but "*" gives a default system node
90 // config, use the default config.
91 if cfg, ok := cc.SystemNodes["*"]; ok {
94 return nil, fmt.Errorf("config does not provision host %q as a system node", node)
97 type SystemNode struct {
98 Controller SystemServiceInstance `json:"arvados-controller"`
99 Health SystemServiceInstance `json:"arvados-health"`
100 Keepproxy SystemServiceInstance `json:"keepproxy"`
101 Keepstore SystemServiceInstance `json:"keepstore"`
102 Keepweb SystemServiceInstance `json:"keep-web"`
103 Nodemanager SystemServiceInstance `json:"arvados-node-manager"`
104 RailsAPI SystemServiceInstance `json:"arvados-api-server"`
105 Websocket SystemServiceInstance `json:"arvados-ws"`
106 Workbench SystemServiceInstance `json:"arvados-workbench"`
109 type ServiceName string
112 ServiceNameRailsAPI ServiceName = "arvados-api-server"
113 ServiceNameController ServiceName = "arvados-controller"
114 ServiceNameNodemanager ServiceName = "arvados-node-manager"
115 ServiceNameWorkbench ServiceName = "arvados-workbench"
116 ServiceNameWebsocket ServiceName = "arvados-ws"
117 ServiceNameKeepweb ServiceName = "keep-web"
118 ServiceNameKeepproxy ServiceName = "keepproxy"
119 ServiceNameKeepstore ServiceName = "keepstore"
122 // ServicePorts returns the configured listening address (or "" if
123 // disabled) for each service on the node.
124 func (sn *SystemNode) ServicePorts() map[ServiceName]string {
125 return map[ServiceName]string{
126 ServiceNameRailsAPI: sn.RailsAPI.Listen,
127 ServiceNameController: sn.Controller.Listen,
128 ServiceNameNodemanager: sn.Nodemanager.Listen,
129 ServiceNameWorkbench: sn.Workbench.Listen,
130 ServiceNameWebsocket: sn.Websocket.Listen,
131 ServiceNameKeepweb: sn.Keepweb.Listen,
132 ServiceNameKeepproxy: sn.Keepproxy.Listen,
133 ServiceNameKeepstore: sn.Keepstore.Listen,
137 type SystemServiceInstance struct {