// No need to query local cluster again
continue
}
+ if remoteID == "*" {
+ // This isn't a real remote cluster: it just sets defaults for unlisted remotes.
+ continue
+ }
wg.Add(1)
go func(remote string) {
var errors []string
for len(errorChan) > 0 {
err := <-errorChan
- if httperr, ok := err.(HTTPError); ok {
- if httperr.Code != http.StatusNotFound {
- errorCode = http.StatusBadGateway
- }
+ if httperr, ok := err.(HTTPError); !ok || httperr.Code != http.StatusNotFound {
+ errorCode = http.StatusBadGateway
}
errors = append(errors, err.Error())
}
if all404 {
return notFoundError{}
}
- // FIXME: choose appropriate HTTP status
- return fmt.Errorf("errors: %v", errs)
+ return httpErrorf(http.StatusBadGateway, "errors: %v", errs)
}
func (conn *Conn) CollectionCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Collection, error) {
// hash+size+hints; only hash+size need to
// match the computed PDH.
if pdh := portableDataHash(c.ManifestText); pdh != options.UUID && !strings.HasPrefix(options.UUID, pdh+"+") {
- ctxlog.FromContext(ctx).Warnf("bad portable data hash %q received from remote %q (expected %q)", pdh, remoteID, options.UUID)
- return notFoundError{}
+ err = httpErrorf(http.StatusBadGateway, "bad portable data hash %q received from remote %q (expected %q)", pdh, remoteID, options.UUID)
+ ctxlog.FromContext(ctx).Warn(err)
+ return err
}
if remoteID != "" {
c.ManifestText = rewriteManifest(c.ManifestText, remoteID)
Proxy: true,
Scheme: "http",
},
+ "*": {
+ Scheme: "https",
+ },
}
c.Assert(s.testServer.Start(), check.IsNil)
func (s *FederationSuite) TestGetCollectionByPDHError(c *check.C) {
defer s.localServiceReturns404(c).Close()
+ // zmock's normal response (200 with an empty body) would
+ // change the outcome from 404 to 502
+ delete(s.testHandler.Cluster.RemoteClusters, "zmock")
+
req := httptest.NewRequest("GET", "/arvados/v1/collections/99999999999999999999999999999999+99", nil)
req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
func (s *FederationSuite) TestGetCollectionByPDHErrorBadHash(c *check.C) {
defer s.localServiceReturns404(c).Close()
+ // zmock's normal response (200 with an empty body) would
+ // change the outcome
+ delete(s.testHandler.Cluster.RemoteClusters, "zmock")
+
srv2 := &httpserver.Server{
Server: http.Server{
Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
resp := s.testRequest(req).Result()
defer resp.Body.Close()
- c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
+ c.Check(resp.StatusCode, check.Equals, http.StatusBadGateway)
}
func (s *FederationSuite) TestSaltedTokenGetCollectionByPDH(c *check.C) {
func (s *FederationSuite) TestSaltedTokenGetCollectionByPDHError(c *check.C) {
arvadostest.SetServiceURL(&s.testHandler.Cluster.Services.RailsAPI, "https://"+os.Getenv("ARVADOS_TEST_API_HOST"))
+ // zmock's normal response (200 with an empty body) would
+ // change the outcome
+ delete(s.testHandler.Cluster.RemoteClusters, "zmock")
+
req := httptest.NewRequest("GET", "/arvados/v1/collections/99999999999999999999999999999999+99", nil)
req.Header.Set("Authorization", "Bearer v2/zzzzz-gj3su-077z32aux8dg2s1/282d7d172b6cfdce364c5ed12ddf7417b2d00065")
resp := s.testRequest(req).Result()