if clusterId != "" && clusterId != h.handler.Cluster.ClusterID {
// request for remote collection by uuid
- resp, cancel, err := h.handler.remoteClusterRequest(clusterId, req)
- if cancel != nil {
- defer cancel()
- }
+ resp, err := h.handler.remoteClusterRequest(clusterId, req)
newResponse, err := rewriteSignatures(clusterId, "", resp, err)
h.handler.proxy.ForwardResponse(w, newResponse, err)
return
// Request for collection by PDH. Search the federation.
// First, query the local cluster.
- resp, localClusterRequestCancel, err := h.handler.localClusterRequest(req)
- if localClusterRequestCancel != nil {
- defer localClusterRequestCancel()
- }
+ resp, err := h.handler.localClusterRequest(req)
newResp, err := filterLocalClusterResponse(resp, err)
if newResp != nil || err != nil {
h.handler.proxy.ForwardResponse(w, newResp, err)
default:
}
- resp, _, err := h.handler.remoteClusterRequest(remote, req)
+ resp, err := h.handler.remoteClusterRequest(remote, req)
wasSuccess := false
defer func() {
if resp != nil && !wasSuccess {
resp.Body.Close()
}
}()
- // Don't need to do anything with the cancel
- // function returned by remoteClusterRequest
- // because the context inherits from
- // sharedContext, so when sharedContext is
- // cancelled it should cancel that one as
- // well.
if err != nil {
errorChan <- err
return
"encoding/json"
"fmt"
"io/ioutil"
- "log"
"net/http"
"git.curoverse.com/arvados.git/sdk/go/auth"
// If runtime_token is not set, create a new token
if _, ok := containerRequest["runtime_token"]; !ok {
- log.Printf("ok %v", ok)
-
// First make sure supplied token is valid.
creds := auth.NewCredentials()
creds.LoadTokensFromHTTPRequest(req)
req.ContentLength = int64(buf.Len())
req.Header.Set("Content-Length", fmt.Sprintf("%v", buf.Len()))
- resp, cancel, err := h.handler.remoteClusterRequest(*clusterId, req)
- if cancel != nil {
- defer cancel()
- }
+ resp, err := h.handler.remoteClusterRequest(*clusterId, req)
h.handler.proxy.ForwardResponse(w, resp, err)
return true
}
import (
"bytes"
- "context"
"encoding/json"
"fmt"
"io/ioutil"
rc := multiClusterQueryResponseCollector{clusterID: clusterID}
var resp *http.Response
- var cancel context.CancelFunc
if clusterID == h.handler.Cluster.ClusterID {
- resp, cancel, err = h.handler.localClusterRequest(&remoteReq)
+ resp, err = h.handler.localClusterRequest(&remoteReq)
} else {
- resp, cancel, err = h.handler.remoteClusterRequest(clusterID, &remoteReq)
+ resp, err = h.handler.remoteClusterRequest(clusterID, &remoteReq)
}
rc.collectResponse(resp, err)
- if cancel != nil {
- cancel()
- }
if rc.error != nil {
return nil, "", rc.error
if clusterId == "" || clusterId == h.handler.Cluster.ClusterID {
h.next.ServeHTTP(w, req)
} else {
- resp, cancel, err := h.handler.remoteClusterRequest(clusterId, req)
- if cancel != nil {
- defer cancel()
- }
+ resp, err := h.handler.remoteClusterRequest(clusterId, req)
h.handler.proxy.ForwardResponse(w, resp, err)
}
}
import (
"bytes"
- "context"
"database/sql"
"encoding/json"
"fmt"
var collectionRe = regexp.MustCompile(fmt.Sprintf(pathPattern, "collections", "4zz18"))
var collectionByPDHRe = regexp.MustCompile(`^/arvados/v1/collections/([0-9a-fA-F]{32}\+[0-9]+)+$`)
-func (h *Handler) remoteClusterRequest(remoteID string, req *http.Request) (*http.Response, context.CancelFunc, error) {
+func (h *Handler) remoteClusterRequest(remoteID string, req *http.Request) (*http.Response, error) {
remote, ok := h.Cluster.RemoteClusters[remoteID]
if !ok {
- return nil, nil, HTTPError{fmt.Sprintf("no proxy available for cluster %v", remoteID), http.StatusNotFound}
+ return nil, HTTPError{fmt.Sprintf("no proxy available for cluster %v", remoteID), http.StatusNotFound}
}
scheme := remote.Scheme
if scheme == "" {
}
saltedReq, err := h.saltAuthToken(req, remoteID)
if err != nil {
- return nil, nil, err
+ return nil, err
}
urlOut := &url.URL{
Scheme: scheme,
`))
req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
req.Header.Set("Content-type", "application/json")
+
+ np := arvados.NodeProfile{
+ Controller: arvados.SystemServiceInstance{Listen: ":"},
+ RailsAPI: arvados.SystemServiceInstance{Listen: os.Getenv("ARVADOS_TEST_API_HOST"),
+ TLS: true, Insecure: true}}
+ s.testHandler.Cluster.ClusterID = "zzzzz"
+ s.testHandler.Cluster.NodeProfiles["*"] = np
+ s.testHandler.NodeProfile = &np
+
resp := s.testRequest(req)
c.Check(resp.StatusCode, check.Equals, http.StatusOK)
var cr struct {
req.URL.Path = strings.Replace(req.URL.Path, "//", "/", -1)
}
}
+ if h.Cluster.HTTPRequestTimeout > 0 {
+ ctx, cancel := context.WithDeadline(req.Context(), time.Now().Add(time.Duration(h.Cluster.HTTPRequestTimeout)))
+ req = req.WithContext(ctx)
+ defer cancel()
+ }
+
h.handlerStack.ServeHTTP(w, req)
}
h.insecureClient = &ic
h.proxy = &proxy{
- Name: "arvados-controller",
- RequestTimeout: time.Duration(h.Cluster.HTTPRequestTimeout),
+ Name: "arvados-controller",
}
}
})
}
-func (h *Handler) localClusterRequest(req *http.Request) (*http.Response, context.CancelFunc, error) {
+func (h *Handler) localClusterRequest(req *http.Request) (*http.Response, error) {
urlOut, insecure, err := findRailsAPI(h.Cluster, h.NodeProfile)
if err != nil {
- return nil, nil, err
+ return nil, err
}
urlOut = &url.URL{
Scheme: urlOut.Scheme,
}
func (h *Handler) proxyRailsAPI(w http.ResponseWriter, req *http.Request, next http.Handler) {
- resp, cancel, err := h.localClusterRequest(req)
- if cancel != nil {
- defer cancel()
- }
+ resp, err := h.localClusterRequest(req)
n, err := h.proxy.ForwardResponse(w, resp, err)
if err != nil {
httpserver.Logger(req).WithError(err).WithField("bytesCopied", n).Error("error copying response body")
package controller
import (
- "context"
"io"
"net/http"
"net/url"
- "time"
"git.curoverse.com/arvados.git/sdk/go/httpserver"
)
type proxy struct {
- Name string // to use in Via header
- RequestTimeout time.Duration
+ Name string // to use in Via header
}
type HTTPError struct {
func (p *proxy) Do(
reqIn *http.Request,
urlOut *url.URL,
- client *http.Client) (*http.Response, context.CancelFunc, error) {
+ client *http.Client) (*http.Response, error) {
// Copy headers from incoming request, then add/replace proxy
// headers like Via and X-Forwarded-For.
}
hdrOut.Add("Via", reqIn.Proto+" arvados-controller")
- ctx := reqIn.Context()
- var cancel context.CancelFunc
- if p.RequestTimeout > 0 {
- ctx, cancel = context.WithDeadline(ctx, time.Now().Add(time.Duration(p.RequestTimeout)))
- }
-
reqOut := (&http.Request{
Method: reqIn.Method,
URL: urlOut,
Host: reqIn.Host,
Header: hdrOut,
Body: reqIn.Body,
- }).WithContext(ctx)
+ }).WithContext(reqIn.Context())
resp, err := client.Do(reqOut)
- return resp, cancel, err
+ return resp, err
}
// Copy a response (or error) to the downstream client