17702: Federated lists supports cluster_id parameter
[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.arvados.org/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) generated_ContainerList(ctx context.Context, options arvados.ListOptions) (arvados.ContainerList, error) {
21         if options.ClusterID != "" {
22                 // explicitly selected cluster
23                 options.ForwardedFor = conn.cluster.ClusterID + "-" + options.ForwardedFor
24                 return conn.chooseBackend(options.ClusterID).ContainerList(ctx, options)
25         }
26
27         var mtx sync.Mutex
28         var merged arvados.ContainerList
29         var needSort atomic.Value
30         needSort.Store(false)
31         err := conn.splitListRequest(ctx, options, func(ctx context.Context, _ string, backend arvados.API, options arvados.ListOptions) ([]string, error) {
32                 options.ForwardedFor = conn.cluster.ClusterID + "-" + options.ForwardedFor
33                 cl, err := backend.ContainerList(ctx, options)
34                 if err != nil {
35                         return nil, err
36                 }
37                 mtx.Lock()
38                 defer mtx.Unlock()
39                 if len(merged.Items) == 0 {
40                         merged = cl
41                 } else if len(cl.Items) > 0 {
42                         merged.Items = append(merged.Items, cl.Items...)
43                         needSort.Store(true)
44                 }
45                 uuids := make([]string, 0, len(cl.Items))
46                 for _, item := range cl.Items {
47                         uuids = append(uuids, item.UUID)
48                 }
49                 return uuids, nil
50         })
51         if needSort.Load().(bool) {
52                 // Apply the default/implied order, "modified_at desc"
53                 sort.Slice(merged.Items, func(i, j int) bool {
54                         mi, mj := merged.Items[i].ModifiedAt, merged.Items[j].ModifiedAt
55                         return mj.Before(mi)
56                 })
57         }
58         if merged.Items == nil {
59                 // Return empty results as [], not null
60                 // (https://github.com/golang/go/issues/27589 might be
61                 // a better solution in the future)
62                 merged.Items = []arvados.Container{}
63         }
64         return merged, err
65 }
66
67 func (conn *Conn) generated_ContainerRequestList(ctx context.Context, options arvados.ListOptions) (arvados.ContainerRequestList, error) {
68         if options.ClusterID != "" {
69                 // explicitly selected cluster
70                 options.ForwardedFor = conn.cluster.ClusterID + "-" + options.ForwardedFor
71                 return conn.chooseBackend(options.ClusterID).ContainerRequestList(ctx, options)
72         }
73
74         var mtx sync.Mutex
75         var merged arvados.ContainerRequestList
76         var needSort atomic.Value
77         needSort.Store(false)
78         err := conn.splitListRequest(ctx, options, func(ctx context.Context, _ string, backend arvados.API, options arvados.ListOptions) ([]string, error) {
79                 options.ForwardedFor = conn.cluster.ClusterID + "-" + options.ForwardedFor
80                 cl, err := backend.ContainerRequestList(ctx, options)
81                 if err != nil {
82                         return nil, err
83                 }
84                 mtx.Lock()
85                 defer mtx.Unlock()
86                 if len(merged.Items) == 0 {
87                         merged = cl
88                 } else if len(cl.Items) > 0 {
89                         merged.Items = append(merged.Items, cl.Items...)
90                         needSort.Store(true)
91                 }
92                 uuids := make([]string, 0, len(cl.Items))
93                 for _, item := range cl.Items {
94                         uuids = append(uuids, item.UUID)
95                 }
96                 return uuids, nil
97         })
98         if needSort.Load().(bool) {
99                 // Apply the default/implied order, "modified_at desc"
100                 sort.Slice(merged.Items, func(i, j int) bool {
101                         mi, mj := merged.Items[i].ModifiedAt, merged.Items[j].ModifiedAt
102                         return mj.Before(mi)
103                 })
104         }
105         if merged.Items == nil {
106                 // Return empty results as [], not null
107                 // (https://github.com/golang/go/issues/27589 might be
108                 // a better solution in the future)
109                 merged.Items = []arvados.ContainerRequest{}
110         }
111         return merged, err
112 }
113
114 func (conn *Conn) generated_GroupList(ctx context.Context, options arvados.ListOptions) (arvados.GroupList, error) {
115         if options.ClusterID != "" {
116                 // explicitly selected cluster
117                 options.ForwardedFor = conn.cluster.ClusterID + "-" + options.ForwardedFor
118                 return conn.chooseBackend(options.ClusterID).GroupList(ctx, options)
119         }
120
121         var mtx sync.Mutex
122         var merged arvados.GroupList
123         var needSort atomic.Value
124         needSort.Store(false)
125         err := conn.splitListRequest(ctx, options, func(ctx context.Context, _ string, backend arvados.API, options arvados.ListOptions) ([]string, error) {
126                 options.ForwardedFor = conn.cluster.ClusterID + "-" + options.ForwardedFor
127                 cl, err := backend.GroupList(ctx, options)
128                 if err != nil {
129                         return nil, err
130                 }
131                 mtx.Lock()
132                 defer mtx.Unlock()
133                 if len(merged.Items) == 0 {
134                         merged = cl
135                 } else if len(cl.Items) > 0 {
136                         merged.Items = append(merged.Items, cl.Items...)
137                         needSort.Store(true)
138                 }
139                 uuids := make([]string, 0, len(cl.Items))
140                 for _, item := range cl.Items {
141                         uuids = append(uuids, item.UUID)
142                 }
143                 return uuids, nil
144         })
145         if needSort.Load().(bool) {
146                 // Apply the default/implied order, "modified_at desc"
147                 sort.Slice(merged.Items, func(i, j int) bool {
148                         mi, mj := merged.Items[i].ModifiedAt, merged.Items[j].ModifiedAt
149                         return mj.Before(mi)
150                 })
151         }
152         if merged.Items == nil {
153                 // Return empty results as [], not null
154                 // (https://github.com/golang/go/issues/27589 might be
155                 // a better solution in the future)
156                 merged.Items = []arvados.Group{}
157         }
158         return merged, err
159 }
160
161 func (conn *Conn) generated_SpecimenList(ctx context.Context, options arvados.ListOptions) (arvados.SpecimenList, error) {
162         if options.ClusterID != "" {
163                 // explicitly selected cluster
164                 options.ForwardedFor = conn.cluster.ClusterID + "-" + options.ForwardedFor
165                 return conn.chooseBackend(options.ClusterID).SpecimenList(ctx, options)
166         }
167
168         var mtx sync.Mutex
169         var merged arvados.SpecimenList
170         var needSort atomic.Value
171         needSort.Store(false)
172         err := conn.splitListRequest(ctx, options, func(ctx context.Context, _ string, backend arvados.API, options arvados.ListOptions) ([]string, error) {
173                 options.ForwardedFor = conn.cluster.ClusterID + "-" + options.ForwardedFor
174                 cl, err := backend.SpecimenList(ctx, options)
175                 if err != nil {
176                         return nil, err
177                 }
178                 mtx.Lock()
179                 defer mtx.Unlock()
180                 if len(merged.Items) == 0 {
181                         merged = cl
182                 } else if len(cl.Items) > 0 {
183                         merged.Items = append(merged.Items, cl.Items...)
184                         needSort.Store(true)
185                 }
186                 uuids := make([]string, 0, len(cl.Items))
187                 for _, item := range cl.Items {
188                         uuids = append(uuids, item.UUID)
189                 }
190                 return uuids, nil
191         })
192         if needSort.Load().(bool) {
193                 // Apply the default/implied order, "modified_at desc"
194                 sort.Slice(merged.Items, func(i, j int) bool {
195                         mi, mj := merged.Items[i].ModifiedAt, merged.Items[j].ModifiedAt
196                         return mj.Before(mi)
197                 })
198         }
199         if merged.Items == nil {
200                 // Return empty results as [], not null
201                 // (https://github.com/golang/go/issues/27589 might be
202                 // a better solution in the future)
203                 merged.Items = []arvados.Specimen{}
204         }
205         return merged, err
206 }
207
208 func (conn *Conn) generated_UserList(ctx context.Context, options arvados.ListOptions) (arvados.UserList, error) {
209         if options.ClusterID != "" {
210                 // explicitly selected cluster
211                 options.ForwardedFor = conn.cluster.ClusterID + "-" + options.ForwardedFor
212                 return conn.chooseBackend(options.ClusterID).UserList(ctx, options)
213         }
214
215         var mtx sync.Mutex
216         var merged arvados.UserList
217         var needSort atomic.Value
218         needSort.Store(false)
219         err := conn.splitListRequest(ctx, options, func(ctx context.Context, _ string, backend arvados.API, options arvados.ListOptions) ([]string, error) {
220                 options.ForwardedFor = conn.cluster.ClusterID + "-" + options.ForwardedFor
221                 cl, err := backend.UserList(ctx, options)
222                 if err != nil {
223                         return nil, err
224                 }
225                 mtx.Lock()
226                 defer mtx.Unlock()
227                 if len(merged.Items) == 0 {
228                         merged = cl
229                 } else if len(cl.Items) > 0 {
230                         merged.Items = append(merged.Items, cl.Items...)
231                         needSort.Store(true)
232                 }
233                 uuids := make([]string, 0, len(cl.Items))
234                 for _, item := range cl.Items {
235                         uuids = append(uuids, item.UUID)
236                 }
237                 return uuids, nil
238         })
239         if needSort.Load().(bool) {
240                 // Apply the default/implied order, "modified_at desc"
241                 sort.Slice(merged.Items, func(i, j int) bool {
242                         mi, mj := merged.Items[i].ModifiedAt, merged.Items[j].ModifiedAt
243                         return mj.Before(mi)
244                 })
245         }
246         if merged.Items == nil {
247                 // Return empty results as [], not null
248                 // (https://github.com/golang/go/issues/27589 might be
249                 // a better solution in the future)
250                 merged.Items = []arvados.User{}
251         }
252         return merged, err
253 }