8 Copyright (C) The Arvados Authors. All rights reserved.
10 SPDX-License-Identifier: CC-BY-SA-3.0
13 h2. Cancel a container request
15 {% codeblock as python %}
17 arvados.api().container_requests().update(uuid=container_request_uuid, body={"priority": 0}).execute()
20 h2. Cancel all container requests
22 {% codeblock as python %}
25 result = api.container_requests().list(filters=[["state", "=", "Committed"], ["priority", ">", "0"]]).execute()["items"]
26 for container_request in result:
27 api.container_requests().update(uuid=container_request["uuid"], body={"priority": 0}).execute()
30 h2. List completed container requests
32 {% codeblock as python %}
35 result = api.container_requests().list(filters=[["name", "like", name], ["state", "=", "Final"]]).execute()["items"]
36 container_uuids = [cr["container_uuid"] for cr in result]
37 containers = api.containers().list(filters=[["uuid", "in", container_uuids]]).execute()["items"]
38 container_dict = {c["uuid"]: c for c in containers}
40 for container_request in result:
41 container = container_dict[container_request["container_uuid"]]
42 print("%s, %s, %s" % (container_request["uuid"], container_request["name"], "Success" if container["exit_code"] == 0 else "Failed"))
45 h2. Get input of a CWL workflow
47 {% codeblock as python %}
50 container_request_uuid="qr1hi-xvhdp-zzzzzzzzzzzzzzz"
51 container_request = arvados.api().container_requests().get(uuid=container_request_uuid).execute()
52 print(container_request["mounts"]["/var/lib/cwl/cwl.input.json"])
55 h2. Get output of a CWL workflow
57 {% codeblock as python %}
59 import arvados.collection
61 container_request_uuid="qr1hi-xvhdp-zzzzzzzzzzzzzzz"
62 container_request = arvados.api().container_requests().get(uuid=container_request_uuid).execute()
63 collection = arvados.collection.CollectionReader(container_request["output_uuid"])
64 print(collection.open("cwl.output.json").read())
67 h2. List input of child requests
69 {% codeblock as python %}
72 parent_request_uuid = "qr1hi-xvhdp-zzzzzzzzzzzzzzz"
73 namefilter = "bwa%" # the "like" filter uses SQL pattern match syntax
74 container_request = arvados.api().container_requests().get(uuid=parent_request_uuid).execute()
75 parent_container_uuid = container_request["container_uuid"]
76 child_requests = arvados.api().container_requests().list(filters=[
77 ["requesting_container_uuid", "=", parent_container_uuid],
78 ["name", "like", namefilter]]).execute()
79 for c in child_requests["items"]:
80 print("%s" % c["name"])
81 for m in c["mounts"].values():
82 if "portable_data_hash" in m:
83 print(" %s" % m["portable_data_hash"])
86 h2. List output of child requests
88 {% codeblock as python %}
91 parent_request_uuid = "qr1hi-xvhdp-zzzzzzzzzzzzzzz"
92 namefilter = "bwa%" # the "like" filter uses SQL pattern match syntax
93 container_request = arvados.api().container_requests().get(uuid=parent_request_uuid).execute()
94 parent_container_uuid = container_request["container_uuid"]
95 child_requests = arvados.api().container_requests().list(filters=[
96 ["requesting_container_uuid", "=", parent_container_uuid],
97 ["name", "like", namefilter]]).execute()
98 output_uuids = [c["output_uuid"] for c in child_requests["items"]]
99 collections = arvados.api().collections().list(filters=[["uuid", "in", output_uuids]]).execute()
100 uuid_to_pdh = {c["uuid"]: c["portable_data_hash"] for c in collections["items"]}
101 for c in child_requests["items"]:
102 print("%s -> %s" % (c["name"], uuid_to_pdh[c["output_uuid"]]))
105 h2. List failed child requests
107 {% codeblock as python %}
110 parent_request_uuid = "qr1hi-xvhdp-zzzzzzzzzzzzzzz"
111 container_request = arvados.api().container_requests().get(uuid=parent_request_uuid).execute()
112 parent_container_uuid = container_request["container_uuid"]
113 child_requests = arvados.api().container_requests().list(filters=[
114 ["requesting_container_uuid", "=", parent_container_uuid]], limit=1000).execute()
115 child_containers = {c["container_uuid"]: c for c in child_requests["items"]}
116 cancelled_child_containers = arvados.api().containers().list(filters=[
117 ["exit_code", "!=", "0"],
118 ["uuid", "in", child_containers.keys()]], limit=1000).execute()
119 for c in cancelled_child_containers["items"]:
120 print("%s (%s)" % (child_containers[c["uuid"]]["name"], child_containers[c["uuid"]]["uuid"]))
123 h2. Get log of a child request
125 {% codeblock as python %}
127 import arvados.collection
129 container_request_uuid = "qr1hi-xvhdp-zzzzzzzzzzzzzzz"
130 container_request = arvados.api().container_requests().get(uuid=container_request_uuid).execute()
131 collection = arvados.collection.CollectionReader(container_request["log_uuid"])
133 print(collection.open(c).read())
136 h2. Create a collection sharing link
138 {% codeblock as python %}
141 download="https://your.download.server"
142 collection_uuid="qr1hi-4zz18-zzzzzzzzzzzzzzz"
143 token = api.api_client_authorizations().create(body={"api_client_authorization":{"scopes": [
144 "GET /arvados/v1/collections/%s" % collection_uuid,
145 "GET /arvados/v1/collections/%s/" % collection_uuid,
146 "GET /arvados/v1/keep_services/accessible"]}}).execute()
147 print("%s/c=%s/t=%s/_/" % (download, collection_uuid, token["api_token"]))
150 h2. Combine two or more collections
152 Note, if two collections have files of the same name, the contents will be concatenated in the resulting manifest.
154 {% codeblock as python %}
156 import arvados.collection
158 project_uuid = "qr1hi-tpzed-zzzzzzzzzzzzzzz"
159 collection_uuids = ["qr1hi-4zz18-aaaaaaaaaaaaaaa", "qr1hi-4zz18-bbbbbbbbbbbbbbb"]
160 combined_manifest = ""
161 for u in collection_uuids:
162 c = api.collections().get(uuid=u).execute()
163 combined_manifest += c["manifest_text"]
164 newcol = arvados.collection.Collection(combined_manifest)
165 newcol.save_new(name="My combined collection", owner_uuid=project_uuid)
168 h2. Upload a file into a new collection
170 {% codeblock as python %}
172 import arvados.collection
174 project_uuid = "qr1hi-j7d0g-zzzzzzzzzzzzzzz"
175 collection_name = "My collection"
176 filename = "file1.txt"
179 c = arvados.collection.Collection()
180 with open(filename, "rb") as reader:
181 with c.open(filename, "wb") as writer:
182 content = reader.read(128*1024)
184 writer.write(content)
185 content = reader.read(128*1024)
186 c.save_new(name=collection_name, owner_uuid=project_uuid)
187 print("Saved %s to %s" % (collection_name, c.manifest_locator()))
190 h2. Download a file from a collection
192 {% codeblock as python %}
194 import arvados.collection
196 collection_uuid = "qr1hi-4zz18-zzzzzzzzzzzzzzz"
197 filename = "file1.txt"
200 c = arvados.collection.CollectionReader(collection_uuid)
201 with c.open(filename, "rb") as reader:
202 with open(filename, "wb") as writer:
203 content = reader.read(128*1024)
205 writer.write(content)
206 content = reader.read(128*1024)
207 print("Finished downloading %s" % filename)