14262: Handle container_request posted as a string parameter
authorPeter Amstutz <pamstutz@veritasgenetics.com>
Tue, 23 Oct 2018 18:30:39 +0000 (14:30 -0400)
committerPeter Amstutz <pamstutz@veritasgenetics.com>
Tue, 30 Oct 2018 18:12:02 +0000 (14:12 -0400)
Needs to be parsed as json second time (this is how the Ruby 'arv'
client submits it, unfortunately.)

Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz@veritasgenetics.com>

lib/controller/fed_collections.go
lib/controller/fed_containers.go
sdk/go/httpserver/id_generator.go

index 62f98367cc162f2ec9bf1c90aaa477e454ab793d..70dbdc3f51b54e7f7268638489663cd6d682a1a5 100644 (file)
@@ -178,7 +178,7 @@ func (s *searchRemoteClusterForPDH) filterRemoteClusterResponse(resp *http.Respo
                // Suppress returning unsuccessful result.  Maybe
                // another request will find it.
                // TODO collect and return error responses.
-               *s.errors = append(*s.errors, fmt.Sprintf("Response from %q: %v", s.remoteID, resp.Status))
+               *s.errors = append(*s.errors, fmt.Sprintf("Response to %q from %q: %v", httpserver.GetRequestID(resp.Header), s.remoteID, resp.Status))
                if resp.StatusCode != 404 {
                        // Got a non-404 error response, convert into BadGateway
                        *s.statusCode = http.StatusBadGateway
index 32ae25fc4b87dd26c128d8d4e2a52edd382c0a3c..e8cc739b02bed8aca5776fc66cb434099e9c685e 100644 (file)
@@ -33,10 +33,23 @@ func remoteContainerRequestCreate(
        defer req.Body.Close()
        var request map[string]interface{}
        err := json.NewDecoder(req.Body).Decode(&request)
+       if err != nil {
+               return false
+       }
+
+       crString, ok := request["container_request"].(string)
+       if ok {
+               var crJson map[string]interface{}
+               err := json.Unmarshal([]byte(crString), &crJson)
+               if err != nil {
+                       return false
+               }
+
+               request["container_request"] = crJson
+       }
 
        containerRequest, ok := request["container_request"].(map[string]interface{})
        if !ok {
-               log.Printf("wah wah")
                return false
        }
 
index 6452136d85eede6896f1dca1648e00b4ba6ae8e7..6093a8a7b720b9eb6258b4873c4f7b52964e78e7 100644 (file)
@@ -53,3 +53,7 @@ func AddRequestIDs(h http.Handler) http.Handler {
                h.ServeHTTP(w, req)
        })
 }
+
+func GetRequestID(h http.Header) string {
+       return h.Get("X-Request-Id")
+}