21978: Broaden replace_files argument summary to match new features.
[arvados.git] / doc / api / methods / collections.html.textile.liquid
1 ---
2 layout: default
3 navsection: api
4 navmenu: API Methods
5 title: "collections"
6
7 ...
8 {% comment %}
9 Copyright (C) The Arvados Authors. All rights reserved.
10
11 SPDX-License-Identifier: CC-BY-SA-3.0
12 {% endcomment %}
13
14 API endpoint base: @https://{{ site.arvados_api_host }}/arvados/v1/collections@
15
16 Object type: @4zz18@
17
18 Example UUID: @zzzzz-4zz18-0123456789abcde@
19
20 h2. Resource
21
22 Collections describe sets of files in terms of data blocks stored in Keep.  See "Keep - Content-Addressable Storage":{{site.baseurl}}/architecture/storage.html and "using collection versioning":../../user/topics/collection-versioning.html for details.
23
24 Each collection has, in addition to the "Common resource fields":{{site.baseurl}}/api/resources.html:
25
26 table(table table-bordered table-condensed).
27 |_. Attribute|_. Type|_. Description|_. Example|
28 |name|string|||
29 |description|text|Free text description of the group.  May be HTML formatted, must be appropriately sanitized before display.||
30 |properties|hash|User-defined metadata, may be used in queries using "subproperty filters":{{site.baseurl}}/api/methods.html#subpropertyfilters ||
31 |portable_data_hash|string|The MD5 sum of the manifest text stripped of block hints other than the size hint.||
32 |manifest_text|text|The manifest describing how to assemble blocks into files, in the "Arvados manifest format":{{site.baseurl}}/architecture/manifest-format.html||
33 |replication_desired|number|Minimum storage replication level desired for each data block referenced by this collection. A value of @null@ signifies that the site default replication level (typically 2) is desired.|@2@|
34 |replication_confirmed|number|Replication level most recently confirmed by the storage system. This field is null when a collection is first created, and is reset to null when the manifest_text changes in a way that introduces a new data block. An integer value indicates the replication level of the _least replicated_ data block in the collection.|@2@, null|
35 |replication_confirmed_at|datetime|When @replication_confirmed@ was confirmed. If @replication_confirmed@ is null, this field is also null.||
36 |storage_classes_desired|list|An optional list of storage class names where the blocks should be saved. If not provided, the cluster's default storage class(es) will be set.|@['archival']@|
37 |storage_classes_confirmed|list|Storage classes most recently confirmed by the storage system. This field is an empty list when a collection is first created.|@'archival']@, @[]@|
38 |storage_classes_confirmed_at|datetime|When @storage_classes_confirmed@ was confirmed. If @storage_classes_confirmed@ is @[]@, this field is null.||
39 |trash_at|datetime|If @trash_at@ is non-null and in the past, this collection will be hidden from API calls.  May be untrashed.||
40 |delete_at|datetime|If @delete_at@ is non-null and in the past, the collection may be permanently deleted.||
41 |is_trashed|boolean|True if @trash_at@ is in the past, false if not.||
42 |current_version_uuid|string|UUID of the collection's current version. On new collections, it'll be equal to the @uuid@ attribute.||
43 |version|number|Version number, starting at 1 on new collections. This attribute is read-only.||
44 |preserve_version|boolean|When set to true on a current version, it will be persisted. When passing @true@ as part of a bigger update call, both current and newly created versions are persisted.||
45 |file_count|number|The total number of files in the collection. This attribute is read-only.||
46 |file_size_total|number|The sum of the file sizes in the collection. This attribute is read-only.||
47
48 h3. Conditions of creating a Collection
49
50 If a new @portable_data_hash@ is specified when creating or updating a Collection, it must match the cryptographic digest of the supplied @manifest_text@.
51
52 h3. Side effects of creating a Collection
53
54 Referenced blocks are protected from garbage collection in Keep.
55
56 Data can be shared with other users via the Arvados permission model.
57
58 h3(#trashing). Trashing collections
59
60 Collections can be trashed by updating the record and setting the @trash_at@ field, or with the "delete":#delete method.  The delete method sets @trash_at@ to "now".
61
62 The value of @trash_at@ can be set to a time in the future as a feature to automatically expire collections.
63
64 When @trash_at@ is set, @delete_at@ will also be set.  Normally @delete_at = trash_at + Collections.DefaultTrashLifetime@.  When the @trash_at@ time is past but @delete_at@ is in the future, the trashed collection is invisible to most API calls unless the @include_trash@ parameter is true.  Collections in the trashed state can be "untrashed":#untrash so long as @delete_at@ has not past.  Collections are also trashed if they are contained in a "trashed group":groups.html#trashing
65
66 Once @delete_at@ is past, the collection and all of its previous versions will be deleted permanently and can no longer be untrashed.
67
68 h3(#replace_files). Using "replace_files" to create or update a collection
69
70 The @replace_files@ option can be used with the "create":#create and "update":#update APIs to efficiently and atomically copy individual files and directory trees from other collections, copy/rename/delete items within an existing collection, and add new items to a collection.
71
72 @replace_files@ keys indicate target paths in the new collection, and values specify sources that should be copied to the target paths.
73 * Each target path must be an absolute canonical path beginning with @/@. It must not contain @.@ or @..@ components, consecutive @/@ characters, or a trailing @/@ after the final component.
74 * Each source must be one of the following:
75 ** an empty string (signifying that the target path is to be deleted),
76 ** @<PDH>/<path>@ where @<PDH>@ is the portable data hash of a collection on the cluster and @<path>@ is a file or directory in that collection,
77 ** @manifest_text/<path>@ where @<path>@ is an existing file or directory in a collection supplied in the @manifest_text@ attribute in the request, or
78 ** @current/<path>@ where @<path>@ is an existing file or directory in the collection being updated.
79
80 In an @update@ request, sources may reference the current portable data hash of the collection being updated. However, in many cases it is more appropriate to use a @current/<path>@ source instead, to ensure the latest content is used even if the collection has been updated since the PDH was last retrieved.
81
82 h4(#replace_files-delete). Delete a file
83
84 Delete @foo.txt@.
85
86 <notextile><pre>
87 "replace_files": {
88   "/foo.txt": ""
89 }
90 </pre></notextile>
91
92 h4(#replace_files-rename). Rename a file
93
94 Rename @foo.txt@ to @bar.txt@.
95
96 <notextile><pre>
97 "replace_files": {
98   "/foo.txt": "",
99   "/bar.txt": "current/foo.txt"
100 }
101 </pre></notextile>
102
103 h4(#replace_files-swap). Swap files
104
105 Swap contents of files @foo@ and @bar@.
106
107 <notextile><pre>
108 "replace_files": {
109   "/foo": "current/bar",
110   "/bar": "current/foo"
111 }
112 </pre></notextile>
113
114 h4(#replace_files-add). Add a file
115
116 <notextile><pre>
117 "replace_files": {
118   "/new_directory/new_file.txt": "manifest_text/new_file.txt"
119 },
120 "collection": {
121   "manifest_text": ". acbd18db4cc2f85cedef654fccc4a4d8+3+A82740cd577ff5745925af5780de5992cbb25d937@668efec4 0:3:new_file.txt\n"
122 }
123 </pre></notextile>
124
125 h4(#replace_files-replace). Replace all content with new content
126
127 Note this is equivalent to omitting the @replace_files@ argument.
128
129 <notextile><pre>
130 "replace_files": {
131   "/": "manifest_text/"
132 },
133 "collection": {
134   "manifest_text": "./new_directory acbd18db4cc2f85cedef654fccc4a4d8+3+A82740cd577ff5745925af5780de5992cbb25d937@668efec4 0:3:new_file.txt\n"
135 }
136 </pre></notextile>
137
138 h4(#replace_files-rename-and-replace). Atomic rename and replace
139
140 Rename @current_file.txt@ to @old_file.txt@ and replace @current_file.txt@ with new content, all in a single atomic operation.
141
142 <notextile><pre>
143 "replace_files": {
144   "/current_file.txt": "manifest_text/new_file.txt",
145   "/old_file.txt": "current/current_file.txt"
146 },
147 "collection": {
148   "manifest_text": ". acbd18db4cc2f85cedef654fccc4a4d8+3+A82740cd577ff5745925af5780de5992cbb25d937@668efec4 0:3:new_file.txt\n"
149 }
150 </pre></notextile>
151
152 h4(#replace_files-combine). Combine collections
153
154 Delete all current content, then copy content from other collections into new subdirectories.
155
156 <notextile><pre>
157 "replace_files": {
158   "/": "",
159   "/copy of collection 1": "1f4b0bc7583c2a7f9102c395f4ffc5e3+45/",
160   "/copy of collection 2": "ea10d51bcf88862dbcc36eb292017dfd+45/"
161 }
162 </pre></notextile>
163
164 h4(#replace_files-extract-subdirectory). Extract a subdirectory
165
166 Replace all current content with a copy of a subdirectory from another collection.
167
168 <notextile><pre>
169 "replace_files": {
170   "/": "1f4b0bc7583c2a7f9102c395f4ffc5e3+45/subdir"
171 }
172 </pre></notextile>
173
174 h4(#replace_files-usage-restrictions). Usage restrictions
175
176 A target path with a non-empty source cannot be the ancestor of another target path in the same request. For example, the following request is invalid:
177
178 <notextile><pre>
179 "replace_files": {
180   "/foo": "fa7aeb5140e2848d39b416daeef4ffc5+45/",
181   "/foo/this_will_return_an_error": ""
182 }
183 </pre></notextile>
184
185 It is an error to supply a non-empty @manifest_text@ that is unused, i.e., the @replace_files@ argument does not contain any values beginning with @"manifest_text/"@. For example, the following request is invalid:
186
187 <notextile><pre>
188 "replace_files": {
189   "/foo": "current/bar"
190 },
191 "collection": {
192   "manifest_text": ". acbd18db4cc2f85cedef654fccc4a4d8+3+A82740cd577ff5745925af5780de5992cbb25d937@668efec4 0:3:new_file.txt\n"
193 }
194 </pre></notextile>
195
196 Collections on other clusters in a federation cannot be used as sources. Each source must exist on the current cluster and be readable by the current user.
197
198 Similarly, if @manifest_text@ is provided, it must only reference data blocks that are stored on the current cluster. This API does not copy data from other clusters in a federation.
199
200 h2. Methods
201
202 See "Common resource methods":{{site.baseurl}}/api/methods.html for more information about @create@, @delete@, @get@, @list@, and @update@.
203
204 Required arguments are displayed in %{background:#ccffcc}green%.
205
206 Supports federated @get@ only, which may be called with either a uuid or a portable data hash.  When requesting a portable data hash which is not available on the home cluster, the query is forwarded to all the clusters listed in @RemoteClusters@ and returns the first successful result.
207
208 h3(#create). create
209
210 Create a new Collection.
211
212 Arguments:
213
214 table(table table-bordered table-condensed).
215 |_. Argument |_. Type |_. Description |_. Location |_. Example |
216 |collection|object||query||
217 |replace_files|object|Initialize files and directories with new content and/or content from other collections|query||
218
219 The new collection's content can be initialized by providing a @manifest_text@ key in the provided @collection@ object, or by using the @replace_files@ option (see "replace_files":#replace_files above).
220
221 h3(#delete). delete
222
223 Put a Collection in the trash.  This sets the @trash_at@ field to @now@ and @delete_at@ field to @now@ + token TTL.  A trashed collection is invisible to most API calls unless the @include_trash@ parameter is true.
224
225 Arguments:
226
227 table(table table-bordered table-condensed).
228 |_. Argument |_. Type |_. Description |_. Location |_. Example |
229 {background:#ccffcc}.|uuid|string|The UUID of the Collection in question.|path||
230
231 h3. get
232
233 Gets a Collection's metadata by UUID or portable data hash.  When making a request by portable data hash, attributes other than @portable_data_hash@, @manifest_text@, and @trash_at@ are not returned, even when requested explicitly using the @select@ parameter.
234
235 Arguments:
236
237 table(table table-bordered table-condensed).
238 |_. Argument |_. Type |_. Description |_. Location |_. Example |
239 {background:#ccffcc}.|uuid|string|The UUID or portable data hash of the Collection in question.|path||
240
241 h3. list
242
243 List collections.
244
245 See "common resource list method.":{{site.baseurl}}/api/methods.html#index
246
247 table(table table-bordered table-condensed).
248 |_. Argument |_. Type |_. Description |_. Location |_. Example |
249 |include_trash|boolean (default false)|Include trashed collections.|query||
250 |include_old_versions|boolean (default false)|Include past versions of the collection(s) being listed, if any.|query||
251
252 Note: Because adding access tokens to manifests can be computationally expensive, the @manifest_text@ field is not included in results by default.  If you need it, pass a @select@ parameter that includes @manifest_text@.
253
254 h4. Searching Collections for names of file or directories
255
256 You can search collections for specific file or directory names (whole or part) using the following filter in a @list@ query.
257
258 <pre>
259 filters: [["file_names", "ilike", "%sample1234.fastq%"]]
260 </pre>
261
262 Note: @file_names@ is a hidden field used for indexing.  It is not returned by any API call.  On the client, you can programmatically enumerate all the files in a collection using @arv-ls@, the Python SDK @Collection@ class, Go SDK @FileSystem@ struct, the WebDAV API, or the S3-compatible API.
263
264 As of this writing (Arvados 2.4), you can also search for directory paths, but _not_ complete file paths.
265
266 In other words, this will work (when @dir3@ is a directory):
267
268 <pre>
269 filters: [["file_names", "ilike", "%dir1/dir2/dir3%"]]
270 </pre>
271
272 However, this will _not_ return the desired results (where @sample1234.fastq@ is a file):
273
274 <pre>
275 filters: [["file_names", "ilike", "%dir1/dir2/dir3/sample1234.fastq%"]]
276 </pre>
277
278 As a workaround, you can search for both the directory path and file name separately, and then filter on the client side.
279
280 <pre>
281 filters: [["file_names", "ilike", "%dir1/dir2/dir3%"], ["file_names", "ilike", "%sample1234.fastq%"]]
282 </pre>
283
284 h3(#update). update
285
286 Update attributes of an existing Collection.
287
288 Arguments:
289
290 table(table table-bordered table-condensed).
291 |_. Argument |_. Type |_. Description |_. Location |_. Example |
292 {background:#ccffcc}.|uuid|string|The UUID of the Collection in question.|path||
293 |collection|object||query||
294 |replace_files|object|Add, delete, and replace files and directories with new content and/or content from other collections|query||
295
296 The collection's existing content can be replaced entirely by providing a @manifest_text@ key in the provided @collection@ object, or updated in place by using the @replace_files@ option (see "replace_files":#replace_files above).
297
298 h3(#untrash). untrash
299
300 Remove a Collection from the trash.  This sets the @trash_at@ and @delete_at@ fields to @null@.
301
302 Arguments:
303
304 table(table table-bordered table-condensed).
305 |_. Argument |_. Type |_. Description |_. Location |_. Example |
306 {background:#ccffcc}.|uuid|string|The UUID of the Collection to untrash.|path||
307 |ensure_unique_name|boolean (default false)|Rename collection uniquely if untrashing it would fail with a unique name conflict.|query||
308
309
310 h3. provenance
311
312 Returns a list of objects in the database that directly or indirectly contributed to producing this collection, such as the container request that produced this collection as output.
313
314 The general algorithm is:
315
316 # Visit the container request that produced this collection (via @output_uuid@ or @log_uuid@ attributes of the container request)
317 # Visit the input collections to that container request (via @mounts@ and @container_image@ of the container request)
318 # Iterate until there are no more objects to visit
319
320 Arguments:
321
322 table(table table-bordered table-condensed).
323 |_. Argument |_. Type |_. Description |_. Location |_. Example |
324 {background:#ccffcc}.|uuid|string|The UUID of the Collection to get provenance.|path||
325
326 h3. used_by
327
328 Returns a list of objects in the database this collection directly or indirectly contributed to, such as containers that takes this collection as input.
329
330 The general algorithm is:
331
332 # Visit containers that take this collection as input (via @mounts@ or @container_image@ of the container)
333 # Visit collections produced by those containers (via @output@ or @log@ of the container)
334 # Iterate until there are no more objects to visit
335
336 Arguments:
337
338 table(table table-bordered table-condensed).
339 |_. Argument |_. Type |_. Description |_. Location |_. Example |
340 {background:#ccffcc}.|uuid|string|The UUID of the Collection to get usage.|path||