Merge branch '15848-controller-list-sort'
[arvados.git] / lib / controller / federation / generated.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package federation
6
7 import (
8         "context"
9         "sort"
10         "sync"
11         "sync/atomic"
12
13         "git.curoverse.com/arvados.git/sdk/go/arvados"
14 )
15
16 //
17 // -- this file is auto-generated -- do not edit -- edit list.go and run "go generate" instead --
18 //
19
20 func (conn *Conn) ContainerList(ctx context.Context, options arvados.ListOptions) (arvados.ContainerList, error) {
21         var mtx sync.Mutex
22         var merged arvados.ContainerList
23         var needSort atomic.Value
24         needSort.Store(false)
25         err := conn.splitListRequest(ctx, options, func(ctx context.Context, _ string, backend arvados.API, options arvados.ListOptions) ([]string, error) {
26                 cl, err := backend.ContainerList(ctx, options)
27                 if err != nil {
28                         return nil, err
29                 }
30                 mtx.Lock()
31                 defer mtx.Unlock()
32                 if len(merged.Items) == 0 {
33                         merged = cl
34                 } else if len(cl.Items) > 0 {
35                         merged.Items = append(merged.Items, cl.Items...)
36                         needSort.Store(true)
37                 }
38                 uuids := make([]string, 0, len(cl.Items))
39                 for _, item := range cl.Items {
40                         uuids = append(uuids, item.UUID)
41                 }
42                 return uuids, nil
43         })
44         if needSort.Load().(bool) {
45                 // Apply the default/implied order, "modified_at desc"
46                 sort.Slice(merged.Items, func(i, j int) bool {
47                         mi, mj := merged.Items[i].ModifiedAt, merged.Items[j].ModifiedAt
48                         return mj.Before(mi)
49                 })
50         }
51         return merged, err
52 }
53
54 func (conn *Conn) SpecimenList(ctx context.Context, options arvados.ListOptions) (arvados.SpecimenList, error) {
55         var mtx sync.Mutex
56         var merged arvados.SpecimenList
57         var needSort atomic.Value
58         needSort.Store(false)
59         err := conn.splitListRequest(ctx, options, func(ctx context.Context, _ string, backend arvados.API, options arvados.ListOptions) ([]string, error) {
60                 cl, err := backend.SpecimenList(ctx, options)
61                 if err != nil {
62                         return nil, err
63                 }
64                 mtx.Lock()
65                 defer mtx.Unlock()
66                 if len(merged.Items) == 0 {
67                         merged = cl
68                 } else if len(cl.Items) > 0 {
69                         merged.Items = append(merged.Items, cl.Items...)
70                         needSort.Store(true)
71                 }
72                 uuids := make([]string, 0, len(cl.Items))
73                 for _, item := range cl.Items {
74                         uuids = append(uuids, item.UUID)
75                 }
76                 return uuids, nil
77         })
78         if needSort.Load().(bool) {
79                 // Apply the default/implied order, "modified_at desc"
80                 sort.Slice(merged.Items, func(i, j int) bool {
81                         mi, mj := merged.Items[i].ModifiedAt, merged.Items[j].ModifiedAt
82                         return mj.Before(mi)
83                 })
84         }
85         return merged, err
86 }