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
58 type InstanceType struct {
67 // GetThisSystemNode returns a SystemNode for the node we're running
69 func (cc *Cluster) GetThisSystemNode() (*SystemNode, error) {
70 hostname, err := os.Hostname()
74 return cc.GetSystemNode(hostname)
77 // GetSystemNode returns a SystemNode for the given hostname. An error
78 // is returned if the appropriate configuration can't be determined
79 // (e.g., this does not appear to be a system node).
80 func (cc *Cluster) GetSystemNode(node string) (*SystemNode, error) {
81 if cfg, ok := cc.SystemNodes[node]; ok {
84 // If node is not listed, but "*" gives a default system node
85 // config, use the default config.
86 if cfg, ok := cc.SystemNodes["*"]; ok {
89 return nil, fmt.Errorf("config does not provision host %q as a system node", node)
92 type SystemNode struct {
93 Controller SystemServiceInstance `json:"arvados-controller"`
94 Health SystemServiceInstance `json:"arvados-health"`
95 Keepproxy SystemServiceInstance `json:"keepproxy"`
96 Keepstore SystemServiceInstance `json:"keepstore"`
97 Keepweb SystemServiceInstance `json:"keep-web"`
98 Nodemanager SystemServiceInstance `json:"arvados-node-manager"`
99 RailsAPI SystemServiceInstance `json:"arvados-api-server"`
100 Websocket SystemServiceInstance `json:"arvados-ws"`
101 Workbench SystemServiceInstance `json:"arvados-workbench"`
104 type ServiceName string
107 ServiceNameRailsAPI ServiceName = "arvados-api-server"
108 ServiceNameController ServiceName = "arvados-controller"
109 ServiceNameNodemanager ServiceName = "arvados-node-manager"
110 ServiceNameWorkbench ServiceName = "arvados-workbench"
111 ServiceNameWebsocket ServiceName = "arvados-ws"
112 ServiceNameKeepweb ServiceName = "keep-web"
113 ServiceNameKeepproxy ServiceName = "keepproxy"
114 ServiceNameKeepstore ServiceName = "keepstore"
117 // ServicePorts returns the configured listening address (or "" if
118 // disabled) for each service on the node.
119 func (sn *SystemNode) ServicePorts() map[ServiceName]string {
120 return map[ServiceName]string{
121 ServiceNameRailsAPI: sn.RailsAPI.Listen,
122 ServiceNameController: sn.Controller.Listen,
123 ServiceNameNodemanager: sn.Nodemanager.Listen,
124 ServiceNameWorkbench: sn.Workbench.Listen,
125 ServiceNameWebsocket: sn.Websocket.Listen,
126 ServiceNameKeepweb: sn.Keepweb.Listen,
127 ServiceNameKeepproxy: sn.Keepproxy.Listen,
128 ServiceNameKeepstore: sn.Keepstore.Listen,
132 type SystemServiceInstance struct {