// the client is outside the cluster.
External bool
+ // Use provided list of keep services, instead of using the
+ // API to discover available services.
+ KeepServiceURIs []string
+
// Discovery document
DiscoveryDoc Dict
External: external,
Retries: 2}
+ if s := os.Getenv("ARVADOS_KEEP_SERVICES"); s != "" {
+ ac.KeepServiceURIs = strings.Split(s, " ")
+ }
+
if ac.ApiServer == "" {
return ac, MissingArvadosApiHost
}
"time"
)
-// DiscoverKeepServers gets list of available keep services from api server
+// DiscoverKeepServers gets list of available keep services from the
+// API server.
+//
+// If a list of services is provided in the arvadosclient (e.g., from
+// an environment variable or local config), that list is used
+// instead.
func (this *KeepClient) DiscoverKeepServers() error {
+ if this.Arvados.KeepServiceURIs != nil {
+ this.foundNonDiskSvc = true
+ this.replicasPerService = 0
+ this.setClientSettingsNonDisk()
+ roots := make(map[string]string)
+ for i, uri := range this.Arvados.KeepServiceURIs {
+ roots[fmt.Sprintf("00000-bi6l4-%015d", i)] = uri
+ }
+ this.SetServiceRoots(roots, roots, roots)
+ return nil
+ }
+
var list svcList
// Get keep services from api server
package keepclient
import (
+ "crypto/md5"
"fmt"
+ "gopkg.in/check.v1"
+ "net/http"
+ "os"
"time"
"git.curoverse.com/arvados.git/sdk/go/arvadosclient"
+ "git.curoverse.com/arvados.git/sdk/go/arvadostest"
)
func ExampleRefreshServices() {
go kc.RefreshServices(5*time.Minute, 3*time.Second)
fmt.Printf("LocalRoots: %#v\n", kc.LocalRoots())
}
+
+func (s *ServerRequiredSuite) TestOverrideDiscovery(c *check.C) {
+ defer os.Setenv("ARVADOS_KEEP_SERVICES", "")
+
+ hash := fmt.Sprintf("%x+3", md5.Sum([]byte("TestOverrideDiscovery")))
+ st := StubGetHandler{
+ c,
+ hash,
+ arvadostest.ActiveToken,
+ http.StatusOK,
+ []byte("TestOverrideDiscovery")}
+ ks := RunSomeFakeKeepServers(st, 2)
+
+ os.Setenv("ARVADOS_KEEP_SERVICES", "")
+ arv1, err := arvadosclient.MakeArvadosClient()
+ c.Assert(err, check.IsNil)
+ arv1.ApiToken = arvadostest.ActiveToken
+
+ os.Setenv("ARVADOS_KEEP_SERVICES", ks[0].url+" "+ks[1].url)
+ arv2, err := arvadosclient.MakeArvadosClient()
+ c.Assert(err, check.IsNil)
+ arv2.ApiToken = arvadostest.ActiveToken
+
+ // ARVADOS_KEEP_SERVICES was empty when we created arv1, but
+ // it pointed to our stub servers when we created
+ // arv2. Regardless of what it's set to now, a keepclient for
+ // arv2 should use our stub servers, but one created for arv1
+ // should not.
+
+ kc1, err := MakeKeepClient(&arv1)
+ c.Assert(err, check.IsNil)
+ kc2, err := MakeKeepClient(&arv2)
+ c.Assert(err, check.IsNil)
+
+ _, _, _, err = kc1.Get(hash)
+ c.Check(err, check.NotNil)
+ _, _, _, err = kc2.Get(hash)
+ c.Check(err, check.IsNil)
+}
// caller can reuse/modify them after SetServiceRoots returns, but
// they should not be modified by any other goroutine while
// SetServiceRoots is running.
-func (kc *KeepClient) SetServiceRoots(newLocals, newWritableLocals map[string]string, newGateways map[string]string) {
+func (kc *KeepClient) SetServiceRoots(newLocals, newWritableLocals, newGateways map[string]string) {
locals := make(map[string]string)
for uuid, root := range newLocals {
locals[uuid] = root