15003: Split out deprecated config stuff.
authorTom Clegg <tclegg@veritasgenetics.com>
Tue, 23 Apr 2019 14:28:52 +0000 (10:28 -0400)
committerTom Clegg <tclegg@veritasgenetics.com>
Tue, 23 Apr 2019 17:30:07 +0000 (13:30 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

lib/config/deprecated.go [new file with mode: 0644]
lib/config/deprecated_test.go [new file with mode: 0644]
lib/config/load.go
lib/config/load_test.go

diff --git a/lib/config/deprecated.go b/lib/config/deprecated.go
new file mode 100644 (file)
index 0000000..5d6796e
--- /dev/null
@@ -0,0 +1,81 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+package config
+
+import (
+       "fmt"
+       "os"
+       "strings"
+
+       "git.curoverse.com/arvados.git/sdk/go/arvados"
+       "github.com/ghodss/yaml"
+)
+
+type deprRequestLimits struct {
+       MaxItemsPerResponse            *int
+       MultiClusterRequestConcurrency *int
+}
+
+type deprCluster struct {
+       RequestLimits deprRequestLimits
+       NodeProfiles  map[string]arvados.NodeProfile
+}
+
+type deprecatedConfig struct {
+       Clusters map[string]deprCluster
+}
+
+func applyDeprecatedConfig(cfg *arvados.Config, configdata []byte, log logger) error {
+       var dc deprecatedConfig
+       err := yaml.Unmarshal(configdata, &dc)
+       if err != nil {
+               return err
+       }
+       hostname, err := os.Hostname()
+       if err != nil {
+               return err
+       }
+       for id, dcluster := range dc.Clusters {
+               cluster, ok := cfg.Clusters[id]
+               if !ok {
+                       return fmt.Errorf("can't load legacy config %q that is not present in current config", id)
+               }
+               for name, np := range dcluster.NodeProfiles {
+                       if name == "*" || name == os.Getenv("ARVADOS_NODE_PROFILE") || name == hostname {
+                               applyDeprecatedNodeProfile(hostname, np.RailsAPI, &cluster.Services.RailsAPI)
+                               applyDeprecatedNodeProfile(hostname, np.Controller, &cluster.Services.Controller)
+                               applyDeprecatedNodeProfile(hostname, np.DispatchCloud, &cluster.Services.DispatchCloud)
+                       }
+               }
+               if dst, n := &cluster.API.MaxItemsPerResponse, dcluster.RequestLimits.MaxItemsPerResponse; n != nil && *n != *dst {
+                       log.Warnf("overriding Clusters.%s.API.MaxItemsPerResponse with deprecated config RequestLimits.MultiClusterRequestConcurrency = %d", id, *n)
+                       *dst = *n
+               }
+               if dst, n := &cluster.API.MaxRequestAmplification, dcluster.RequestLimits.MultiClusterRequestConcurrency; n != nil && *n != *dst {
+                       log.Warnf("overriding Clusters.%s.API.MaxRequestAmplification with deprecated config RequestLimits.MultiClusterRequestConcurrency = %d", id, *n)
+                       *dst = *n
+               }
+               cfg.Clusters[id] = cluster
+       }
+       return nil
+}
+
+func applyDeprecatedNodeProfile(hostname string, ssi arvados.SystemServiceInstance, svc *arvados.Service) {
+       scheme := "https"
+       if !ssi.TLS {
+               scheme = "http"
+       }
+       if svc.InternalURLs == nil {
+               svc.InternalURLs = map[arvados.URL]arvados.ServiceInstance{}
+       }
+       host := ssi.Listen
+       if host == "" {
+               return
+       }
+       if strings.HasPrefix(host, ":") {
+               host = hostname + host
+       }
+       svc.InternalURLs[arvados.URL{Scheme: scheme, Host: host}] = arvados.ServiceInstance{}
+}
diff --git a/lib/config/deprecated_test.go b/lib/config/deprecated_test.go
new file mode 100644 (file)
index 0000000..bdce5b5
--- /dev/null
@@ -0,0 +1,51 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+package config
+
+import (
+       "os"
+
+       check "gopkg.in/check.v1"
+)
+
+func (s *LoadSuite) TestDeprecatedNodeProfilesToServices(c *check.C) {
+       hostname, err := os.Hostname()
+       c.Assert(err, check.IsNil)
+       s.checkEquivalent(c, `
+Clusters:
+ z1111:
+  NodeProfiles:
+   "*":
+    arvados-dispatch-cloud:
+     listen: ":9006"
+    arvados-controller:
+     listen: ":9004"
+   `+hostname+`:
+    arvados-api-server:
+     listen: ":8000"
+`, `
+Clusters:
+ z1111:
+  Services:
+   RailsAPI:
+    InternalURLs:
+     "http://`+hostname+`:8000": {}
+   Controller:
+    InternalURLs:
+     "http://`+hostname+`:9004": {}
+   DispatchCloud:
+    InternalURLs:
+     "http://`+hostname+`:9006": {}
+  NodeProfiles:
+   "*":
+    arvados-dispatch-cloud:
+     listen: ":9006"
+    arvados-controller:
+     listen: ":9004"
+   `+hostname+`:
+    arvados-api-server:
+     listen: ":8000"
+`)
+}
index 5a690b03c2280bcc46039c16197800f5a088afa9..e9ae5c6d186da13eff36aa5f4a5eb9e55326d914 100644 (file)
@@ -12,7 +12,6 @@ import (
        "io"
        "io/ioutil"
        "os"
-       "strings"
 
        "git.curoverse.com/arvados.git/sdk/go/arvados"
        "github.com/ghodss/yaml"
@@ -23,20 +22,6 @@ type logger interface {
        Warnf(string, ...interface{})
 }
 
-type deprRequestLimits struct {
-       MaxItemsPerResponse            *int
-       MultiClusterRequestConcurrency *int
-}
-
-type deprCluster struct {
-       RequestLimits deprRequestLimits
-       NodeProfiles  map[string]arvados.NodeProfile
-}
-
-type deprecatedConfig struct {
-       Clusters map[string]deprCluster
-}
-
 func LoadFile(path string, log logger) (*arvados.Config, error) {
        f, err := os.Open(path)
        if err != nil {
@@ -102,62 +87,9 @@ func Load(rdr io.Reader, log logger) (*arvados.Config, error) {
                return nil, fmt.Errorf("transcoding config data: %s", err)
        }
 
-       var dc deprecatedConfig
-       err = yaml.Unmarshal(buf, &dc)
-       if err != nil {
-               return nil, err
-       }
-       err = applyDeprecatedConfig(&cfg, &dc, log)
+       err = applyDeprecatedConfig(&cfg, buf, log)
        if err != nil {
                return nil, err
        }
        return &cfg, nil
 }
-
-func applyDeprecatedConfig(cfg *arvados.Config, dc *deprecatedConfig, log logger) error {
-       hostname, err := os.Hostname()
-       if err != nil {
-               return err
-       }
-       for id, dcluster := range dc.Clusters {
-               cluster, ok := cfg.Clusters[id]
-               if !ok {
-                       return fmt.Errorf("can't load legacy config %q that is not present in current config", id)
-               }
-               for name, np := range dcluster.NodeProfiles {
-                       if name == "*" || name == os.Getenv("ARVADOS_NODE_PROFILE") || name == hostname {
-                               applyDeprecatedNodeProfile(hostname, np.RailsAPI, &cluster.Services.RailsAPI)
-                               applyDeprecatedNodeProfile(hostname, np.Controller, &cluster.Services.Controller)
-                               applyDeprecatedNodeProfile(hostname, np.DispatchCloud, &cluster.Services.DispatchCloud)
-                       }
-               }
-               if dst, n := &cluster.API.MaxItemsPerResponse, dcluster.RequestLimits.MaxItemsPerResponse; n != nil && *n != *dst {
-                       log.Warnf("overriding Clusters.%s.API.MaxItemsPerResponse with deprecated config RequestLimits.MultiClusterRequestConcurrency = %d", id, *n)
-                       *dst = *n
-               }
-               if dst, n := &cluster.API.MaxRequestAmplification, dcluster.RequestLimits.MultiClusterRequestConcurrency; n != nil && *n != *dst {
-                       log.Warnf("overriding Clusters.%s.API.MaxRequestAmplification with deprecated config RequestLimits.MultiClusterRequestConcurrency = %d", id, *n)
-                       *dst = *n
-               }
-               cfg.Clusters[id] = cluster
-       }
-       return nil
-}
-
-func applyDeprecatedNodeProfile(hostname string, ssi arvados.SystemServiceInstance, svc *arvados.Service) {
-       scheme := "https"
-       if !ssi.TLS {
-               scheme = "http"
-       }
-       if svc.InternalURLs == nil {
-               svc.InternalURLs = map[arvados.URL]arvados.ServiceInstance{}
-       }
-       host := ssi.Listen
-       if host == "" {
-               return
-       }
-       if strings.HasPrefix(host, ":") {
-               host = hostname + host
-       }
-       svc.InternalURLs[arvados.URL{Scheme: scheme, Host: host}] = arvados.ServiceInstance{}
-}
index 277ff423a4f78607f5d018e64eeb240f9fa788ed..315e021ebb17b51c1a5b0dd9115d242aea543966 100644 (file)
@@ -53,46 +53,6 @@ func (s *LoadSuite) TestMultipleClusters(c *check.C) {
        c.Check(c2.ClusterID, check.Equals, "z2222")
 }
 
-func (s *LoadSuite) TestNodeProfilesToServices(c *check.C) {
-       hostname, err := os.Hostname()
-       c.Assert(err, check.IsNil)
-       s.checkEquivalent(c, `
-Clusters:
- z1111:
-  NodeProfiles:
-   "*":
-    arvados-dispatch-cloud:
-     listen: ":9006"
-    arvados-controller:
-     listen: ":9004"
-   `+hostname+`:
-    arvados-api-server:
-     listen: ":8000"
-`, `
-Clusters:
- z1111:
-  Services:
-   RailsAPI:
-    InternalURLs:
-     "http://`+hostname+`:8000": {}
-   Controller:
-    InternalURLs:
-     "http://`+hostname+`:9004": {}
-   DispatchCloud:
-    InternalURLs:
-     "http://`+hostname+`:9006": {}
-  NodeProfiles:
-   "*":
-    arvados-dispatch-cloud:
-     listen: ":9006"
-    arvados-controller:
-     listen: ":9004"
-   `+hostname+`:
-    arvados-api-server:
-     listen: ":8000"
-`)
-}
-
 func (s *LoadSuite) TestMovedKeys(c *check.C) {
        s.checkEquivalent(c, `# config has old keys only
 Clusters: