2798: Turns list of keep disk objects into sorted slice of http URLs for keep servers
authorPeter Amstutz <peter.amstutz@curoverse.com>
Sat, 10 May 2014 20:05:59 +0000 (16:05 -0400)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Sat, 10 May 2014 20:05:59 +0000 (16:05 -0400)
sdk/go/src/arvados.org/keepclient/keepclient.go
sdk/go/src/arvados.org/keepclient/keepclient_test.go

index 6bd6cbf7818f88553580479b814e86cd83300fcc..2bb5ff3eb19e163c4e1a52fca1c79507a2189f4b 100644 (file)
@@ -3,15 +3,18 @@ package keepclient
 import (
        "crypto/tls"
        "encoding/json"
+       "fmt"
        "net/http"
+       "sort"
 )
 
 type KeepDisk struct {
        Hostname string `json:"service_host"`
        Port     int    `json:"service_port"`
+       SSL      bool   `json:"service_ssl_flag"`
 }
 
-func KeepDisks() (disks []KeepDisk, err error) {
+func KeepDisks() (service_roots []string, err error) {
        tr := &http.Transport{
                TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
        }
@@ -37,5 +40,23 @@ func KeepDisks() (disks []KeepDisk, err error) {
                return nil, err
        }
 
-       return m.Items, nil
+       service_roots = make([]string, len(m.Items))
+       for index, element := range m.Items {
+               n := ""
+               if element.SSL {
+                       n = "s"
+               }
+               service_roots[index] = fmt.Sprintf("http%s://%s:%d",
+                       n, element.Hostname, element.Port)
+       }
+       sort.Strings(service_roots)
+       return service_roots, nil
+}
+
+/*
+func ProbeSequence(service_roots []string) (pseq []string) {
+       pseq = make([]string, 0, len(disks))
+       pool := disks[:]
+
 }
+*/
index 95f6c3cc65d44545292d9697f1b79f00a646cd75..ac0c85af83346ca3af5c981c94652335aa395ac5 100644 (file)
@@ -13,11 +13,10 @@ type MySuite struct{}
 var _ = Suite(&MySuite{})
 
 func (s *MySuite) TestGetKeepDisks(c *C) {
-       k, err := KeepDisks()
+       sr, err := KeepDisks()
        c.Assert(err, Equals, nil)
-       c.Assert(len(k), Equals, 2)
-       c.Assert(k[0].Hostname, Equals, "localhost")
-       c.Assert(k[0].Port, Equals, 25108)
-       c.Assert(k[1].Hostname, Equals, "localhost")
-       c.Assert(k[1].Port, Equals, 25107)
+       c.Assert(len(sr), Equals, 2)
+       c.Assert(sr[0], Equals, "http://localhost:25107")
+       c.Assert(sr[1], Equals, "http://localhost:25108")
+
 }