3 # Copyright (C) The Arvados Authors. All rights reserved.
5 # SPDX-License-Identifier: AGPL-3.0
8 from __future__ import print_function, absolute_import
16 Given a list of collections missing blocks (as produced by
17 keep-balance), delete the collections and re-run associated containers.
20 def rerun_request(arv, container_requests_to_rerun, ct):
21 requests = arvados.util.list_all(arv.container_requests().list, filters=[["container_uuid", "=", ct["uuid"]]])
23 if cr["requesting_container_uuid"]:
24 rerun_request(arv, container_requests_to_rerun, arv.containers().get(uuid=cr["requesting_container_uuid"]).execute())
26 container_requests_to_rerun[cr["uuid"]] = cr
28 def get_owner(arv, owners, uuid):
29 if uuid not in owners:
30 if uuid[6:11] == "tpzed":
31 owners[uuid] = arv.users().get(uuid=uuid).execute()["full_name"]
33 owners[uuid] = arv.groups().get(uuid=uuid).execute()["name"]
37 parser = argparse.ArgumentParser(description='Re-run containers associated with missing blocks')
38 parser.add_argument('inp')
39 args = parser.parse_args()
41 arv = arvados.api('v1')
43 busted_collections = set()
45 # Get the list of bad collection PDHs
46 blocksfile = open(args.inp, "rt")
47 for line in blocksfile:
48 # Ignore the first item, that's the block id
49 collections = line.rstrip().split(" ")[1:]
51 busted_collections.add(c)
53 out = csv.writer(sys.stdout)
55 out.writerow(("collection uuid", "container request uuid", "record name", "modified at", "owner uuid", "owner name", "notes"))
58 collections_to_delete = {}
59 container_requests_to_rerun = {}
60 # Get containers that produced these collections
62 for b in busted_collections:
64 collections_to_delete = arvados.util.list_all(arv.collections().list, filters=[["portable_data_hash", "=", b]])
65 for d in collections_to_delete:
67 if d["properties"].get("type") not in ("output", "log"):
68 t = "\"type\" was '%s', expected one of 'output' or 'log'" % d["properties"].get("type")
69 out.writerow((d["uuid"], "", d["name"], d["modified_at"], d["owner_uuid"], get_owner(arv, owners, d["owner_uuid"]), t))
71 maybe_containers_to_rerun = arvados.util.list_all(arv.containers().list, filters=[["output", "=", b]])
72 for ct in maybe_containers_to_rerun:
73 rerun_request(arv, container_requests_to_rerun, ct)
76 for _, cr in container_requests_to_rerun.items():
78 out.writerow(("", cr["uuid"], cr["name"], cr["modified_at"], cr["owner_uuid"], get_owner(arv, owners, cr["owner_uuid"]), ""))
81 if __name__ == "__main__":