1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
13 "git.curoverse.com/arvados.git/sdk/go/config"
16 const DefaultConfigFile = "/etc/arvados/config.yml"
19 Clusters map[string]Cluster
22 // GetConfig returns the current system config, loading it from
23 // configFile if needed.
24 func GetConfig(configFile string) (*Config, error) {
26 err := config.LoadFile(&cfg, configFile)
30 // GetCluster returns the cluster ID and config for the given
31 // cluster, or the default/only configured cluster if clusterID is "".
32 func (sc *Config) GetCluster(clusterID string) (*Cluster, error) {
34 if len(sc.Clusters) == 0 {
35 return nil, fmt.Errorf("no clusters configured")
36 } else if len(sc.Clusters) > 1 {
37 return nil, fmt.Errorf("multiple clusters configured, cannot choose")
39 for id, cc := range sc.Clusters {
45 if cc, ok := sc.Clusters[clusterID]; !ok {
46 return nil, fmt.Errorf("cluster %q is not configured", clusterID)
48 cc.ClusterID = clusterID
54 ClusterID string `json:"-"`
55 ManagementToken string
56 NodeProfiles map[string]NodeProfile
57 InstanceTypes InstanceTypeMap
58 HTTPRequestTimeout Duration
59 RemoteClusters map[string]RemoteCluster
63 type PostgreSQL struct {
64 Connection PostgreSQLConnection
68 type PostgreSQLConnection map[string]string
70 type RemoteCluster struct {
71 // API endpoint host or host:port; default is {id}.arvadosapi.com
73 // Perform a proxy request when a local client requests an
74 // object belonging to this remote.
76 // Scheme, default "https". Can be set to "http" for testing.
78 // Disable TLS verify. Can be set to true for testing.
82 type InstanceType struct {
92 type InstanceTypeMap map[string]InstanceType
94 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
96 // UnmarshalJSON handles old config files that provide an array of
97 // instance types instead of a hash.
98 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
99 if len(data) > 0 && data[0] == '[' {
100 var arr []InstanceType
101 err := json.Unmarshal(data, &arr)
109 *it = make(map[string]InstanceType, len(arr))
110 for _, t := range arr {
111 if _, ok := (*it)[t.Name]; ok {
112 return errDuplicateInstanceTypeName
118 var hash map[string]InstanceType
119 err := json.Unmarshal(data, &hash)
123 // Fill in Name field using hash key.
124 *it = InstanceTypeMap(hash)
125 for name, t := range *it {
132 // GetNodeProfile returns a NodeProfile for the given hostname. An
133 // error is returned if the appropriate configuration can't be
134 // determined (e.g., this does not appear to be a system node). If
135 // node is empty, use the OS-reported hostname.
136 func (cc *Cluster) GetNodeProfile(node string) (*NodeProfile, error) {
138 hostname, err := os.Hostname()
144 if cfg, ok := cc.NodeProfiles[node]; ok {
147 // If node is not listed, but "*" gives a default system node
148 // config, use the default config.
149 if cfg, ok := cc.NodeProfiles["*"]; ok {
152 return nil, fmt.Errorf("config does not provision host %q as a system node", node)
155 type NodeProfile struct {
156 Controller SystemServiceInstance `json:"arvados-controller"`
157 Health SystemServiceInstance `json:"arvados-health"`
158 Keepproxy SystemServiceInstance `json:"keepproxy"`
159 Keepstore SystemServiceInstance `json:"keepstore"`
160 Keepweb SystemServiceInstance `json:"keep-web"`
161 Nodemanager SystemServiceInstance `json:"arvados-node-manager"`
162 RailsAPI SystemServiceInstance `json:"arvados-api-server"`
163 Websocket SystemServiceInstance `json:"arvados-ws"`
164 Workbench SystemServiceInstance `json:"arvados-workbench"`
167 type ServiceName string
170 ServiceNameRailsAPI ServiceName = "arvados-api-server"
171 ServiceNameController ServiceName = "arvados-controller"
172 ServiceNameNodemanager ServiceName = "arvados-node-manager"
173 ServiceNameWorkbench ServiceName = "arvados-workbench"
174 ServiceNameWebsocket ServiceName = "arvados-ws"
175 ServiceNameKeepweb ServiceName = "keep-web"
176 ServiceNameKeepproxy ServiceName = "keepproxy"
177 ServiceNameKeepstore ServiceName = "keepstore"
180 // ServicePorts returns the configured listening address (or "" if
181 // disabled) for each service on the node.
182 func (np *NodeProfile) ServicePorts() map[ServiceName]string {
183 return map[ServiceName]string{
184 ServiceNameRailsAPI: np.RailsAPI.Listen,
185 ServiceNameController: np.Controller.Listen,
186 ServiceNameNodemanager: np.Nodemanager.Listen,
187 ServiceNameWorkbench: np.Workbench.Listen,
188 ServiceNameWebsocket: np.Websocket.Listen,
189 ServiceNameKeepweb: np.Keepweb.Listen,
190 ServiceNameKeepproxy: np.Keepproxy.Listen,
191 ServiceNameKeepstore: np.Keepstore.Listen,
195 type SystemServiceInstance struct {