18700: Don't start workbench2 in integration test clusters.
[arvados.git] / lib / controller / federation / list.go
index 6ee813317417cd012d829387e10e04f2ea1dad17..039caac574e479bdad181dfeed745dd3255640cf 100644 (file)
@@ -27,6 +27,7 @@ func (conn *Conn) generated_CollectionList(ctx context.Context, options arvados.
        var needSort atomic.Value
        needSort.Store(false)
        err := conn.splitListRequest(ctx, options, func(ctx context.Context, _ string, backend arvados.API, options arvados.ListOptions) ([]string, error) {
+               options.ForwardedFor = conn.cluster.ClusterID + "-" + options.ForwardedFor
                cl, err := backend.CollectionList(ctx, options)
                if err != nil {
                        return nil, err
@@ -106,6 +107,18 @@ func (conn *Conn) generated_CollectionList(ctx context.Context, options arvados.
 // corresponding options argument suitable for sending to that
 // backend.
 func (conn *Conn) splitListRequest(ctx context.Context, opts arvados.ListOptions, fn func(context.Context, string, arvados.API, arvados.ListOptions) ([]string, error)) error {
+
+       if opts.BypassFederation || opts.ForwardedFor != "" {
+               // Client requested no federation.  Pass through.
+               _, err := fn(ctx, conn.cluster.ClusterID, conn.local, opts)
+               return err
+       }
+       if opts.ClusterID != "" {
+               // Client explicitly selected cluster
+               _, err := fn(ctx, conn.cluster.ClusterID, conn.chooseBackend(opts.ClusterID), opts)
+               return err
+       }
+
        cannotSplit := false
        var matchAllFilters map[string]bool
        for _, f := range opts.Filters {
@@ -197,8 +210,8 @@ func (conn *Conn) splitListRequest(ctx context.Context, opts arvados.ListOptions
        if opts.Count != "none" {
                return httpErrorf(http.StatusBadRequest, "cannot execute federated list query unless count==\"none\"")
        }
-       if opts.Limit >= 0 || opts.Offset != 0 || len(opts.Order) > 0 {
-               return httpErrorf(http.StatusBadRequest, "cannot execute federated list query with limit, offset, or order parameter")
+       if (opts.Limit >= 0 && opts.Limit < int64(nUUIDs)) || opts.Offset != 0 || len(opts.Order) > 0 {
+               return httpErrorf(http.StatusBadRequest, "cannot execute federated list query with limit (%d) < nUUIDs (%d), offset (%d) > 0, or order (%v) parameter", opts.Limit, nUUIDs, opts.Offset, opts.Order)
        }
        if max := conn.cluster.API.MaxItemsPerResponse; nUUIDs > max {
                return httpErrorf(http.StatusBadRequest, "cannot execute federated list query because number of UUIDs (%d) exceeds page size limit %d", nUUIDs, max)
@@ -242,7 +255,7 @@ func (conn *Conn) splitListRequest(ctx context.Context, opts arvados.ListOptions
 
                                done, err := fn(ctx, clusterID, backend, remoteOpts)
                                if err != nil {
-                                       errs <- httpErrorf(http.StatusBadGateway, err.Error())
+                                       errs <- httpErrorf(http.StatusBadGateway, "%s", err.Error())
                                        return
                                }
                                progress := false