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 lglvl = logging.INFO+1
17 logging.basicConfig(level=lglvl, format='%(message)s')
20 Given a list of collections missing blocks (as produced by
21 keep-balance), produce a report listing affected collections and
25 def rerun_request(arv, container_requests_to_rerun, ct):
26 requests = arvados.util.list_all(arv.container_requests().list, filters=[["container_uuid", "=", ct["uuid"]]])
28 if cr["requesting_container_uuid"]:
29 rerun_request(arv, container_requests_to_rerun, arv.containers().get(uuid=cr["requesting_container_uuid"]).execute())
31 container_requests_to_rerun[cr["uuid"]] = cr
33 def get_owner(arv, owners, record):
34 uuid = record["owner_uuid"]
35 if uuid not in owners:
36 if uuid[6:11] == "tpzed":
37 owners[uuid] = (arv.users().get(uuid=uuid).execute()["full_name"], uuid)
39 grp = arv.groups().get(uuid=uuid).execute()
40 _, ou = get_owner(arv, owners, grp)
41 owners[uuid] = (grp["name"], ou)
45 parser = argparse.ArgumentParser(description='Re-run containers associated with missing blocks')
46 parser.add_argument('inp')
47 args = parser.parse_args()
49 arv = arvados.api('v1')
51 busted_collections = set()
53 logging.log(lglvl, "Reading %s", args.inp)
55 # Get the list of bad collection PDHs
56 blocksfile = open(args.inp, "rt")
57 for line in blocksfile:
58 # Ignore the first item, that's the block id
59 collections = line.rstrip().split(" ")[1:]
61 busted_collections.add(c)
63 out = csv.writer(sys.stdout)
65 out.writerow(("collection uuid", "container request uuid", "record name", "modified at", "owner uuid", "owner name", "root owner uuid", "root owner name", "notes"))
67 logging.log(lglvl, "Finding collections")
70 collections_to_delete = {}
71 container_requests_to_rerun = {}
72 # Get containers that produced these collections
74 for b in busted_collections:
76 logging.log(lglvl, "%d/%d", i, len(busted_collections))
78 collections_to_delete = arvados.util.list_all(arv.collections().list, filters=[["portable_data_hash", "=", b]])
79 for d in collections_to_delete:
81 if d["properties"].get("type") not in ("output", "log"):
82 t = "\"type\" was '%s', expected one of 'output' or 'log'" % d["properties"].get("type")
83 ou = get_owner(arv, owners, d)
84 out.writerow((d["uuid"], "", d["name"], d["modified_at"], d["owner_uuid"], ou[0], ou[1], owners[ou[1]][0], t))
86 maybe_containers_to_rerun = arvados.util.list_all(arv.containers().list, filters=[["output", "=", b]])
87 for ct in maybe_containers_to_rerun:
88 rerun_request(arv, container_requests_to_rerun, ct)
90 logging.log(lglvl, "%d/%d", i, len(busted_collections))
91 logging.log(lglvl, "Finding container requests")
94 for _, cr in container_requests_to_rerun.items():
96 logging.log(lglvl, "%d/%d", i, len(container_requests_to_rerun))
98 ou = get_owner(arv, owners, cr)
99 out.writerow(("", cr["uuid"], cr["name"], cr["modified_at"], cr["owner_uuid"], ou[0], ou[1], owners[ou[1]][0], ""))
101 logging.log(lglvl, "%d/%d", i, len(container_requests_to_rerun))
103 if __name__ == "__main__":