Merge pull request #2 from wtsi-hgi/feature/arv-view
[arvados.git] / sdk / go / keepclient / support.go
index 6393503e965b92b7ff27e8320e46e28eed69857d..b467d06b21ed91ecaa06b1537ae30a6cddcb6ce2 100644 (file)
@@ -1,4 +1,3 @@
-/* Internal methods to support keepclient.go */
 package keepclient
 
 import (
@@ -21,6 +20,7 @@ type keepDisk struct {
        Port     int    `json:"service_port"`
        SSL      bool   `json:"service_ssl_flag"`
        SvcType  string `json:"service_type"`
+       ReadOnly bool   `json:"read_only"`
 }
 
 func Md5String(s string) string {
@@ -93,6 +93,7 @@ func (this *KeepClient) DiscoverKeepServers() error {
        listed := make(map[string]bool)
        localRoots := make(map[string]string)
        gatewayRoots := make(map[string]string)
+       writableLocalRoots := make(map[string]string)
 
        for _, service := range m.Items {
                scheme := "http"
@@ -114,6 +115,11 @@ func (this *KeepClient) DiscoverKeepServers() error {
                        localRoots[service.Uuid] = url
                        this.Using_proxy = true
                }
+
+               if service.ReadOnly == false {
+                       writableLocalRoots[service.Uuid] = url
+               }
+
                // Gateway services are only used when specified by
                // UUID, so there's nothing to gain by filtering them
                // by service type. Including all accessible services
@@ -128,7 +134,7 @@ func (this *KeepClient) DiscoverKeepServers() error {
                this.setClientSettingsStore()
        }
 
-       this.SetServiceRoots(localRoots, gatewayRoots)
+       this.SetServiceRoots(localRoots, writableLocalRoots, gatewayRoots)
        return nil
 }
 
@@ -212,7 +218,7 @@ func (this KeepClient) putReplicas(
        requestId := fmt.Sprintf("%x", md5.Sum([]byte(locator+time.Now().String())))[0:8]
 
        // Calculate the ordering for uploading to servers
-       sv := NewRootSorter(this.LocalRoots(), hash).GetSortedRoots()
+       sv := NewRootSorter(this.WritableLocalRoots(), hash).GetSortedRoots()
 
        // The next server to try contacting
        next_server := 0