18903: the user activity script needs to look up collections by PDH, not
authorWard Vandewege <ward@curii.com>
Wed, 23 Mar 2022 16:07:51 +0000 (12:07 -0400)
committerWard Vandewege <ward@curii.com>
Wed, 23 Mar 2022 16:07:51 +0000 (12:07 -0400)
       UUID (that field is not always populated with a UUID).

Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward@curii.com>

tools/user-activity/arvados_user_activity/main.py

index 841685f0179d304d31d029372c5bcd24aa85e20e..15383cd900bab7466d5be406685b21c2c646fadd 100755 (executable)
@@ -42,11 +42,13 @@ def getuserinfo(arv, uuid):
                                                        uuid, prof)
 
 collectionNameCache = {}
-def getCollectionName(arv, uuid):
-    if uuid not in collectionNameCache:
-        u = arv.collections().get(uuid=uuid).execute()
-        collectionNameCache[uuid] = u["name"]
-    return collectionNameCache[uuid]
+def getCollectionName(arv, pdh):
+    if pdh not in collectionNameCache:
+        u = arv.collections().list(filters=[["portable_data_hash","=",pdh]]).execute().get("items")
+        if len(u) < 1:
+            return "(deleted)"
+        collectionNameCache[pdh] = u[0]["name"]
+    return collectionNameCache[pdh]
 
 def getname(u):
     return "\"%s\" (%s)" % (u["name"], u["uuid"])
@@ -148,7 +150,7 @@ def main(arguments=None):
                 users.setdefault(e["object_uuid"], [])
                 users[e["object_uuid"]].append("%s Downloaded file \"%s\" from \"%s\" (%s) (%s)" % (event_at,
                                                                                        e["properties"].get("collection_file_path") or e["properties"].get("reqPath"),
-                                                                                       getCollectionName(arv, e["properties"].get("collection_uuid")),
+                                                                                       getCollectionName(arv, e["properties"].get("portable_data_hash")),
                                                                                        e["properties"].get("collection_uuid"),
                                                                                        e["properties"].get("portable_data_hash")))
 
@@ -156,7 +158,7 @@ def main(arguments=None):
                 users.setdefault(e["object_uuid"], [])
                 users[e["object_uuid"]].append("%s Uploaded file \"%s\" to \"%s\" (%s)" % (event_at,
                                                                                     e["properties"].get("collection_file_path") or e["properties"].get("reqPath"),
-                                                                                    getCollectionName(arv, e["properties"].get("collection_uuid")),
+                                                                                    getCollectionName(arv, e["properties"].get("portable_data_hash")),
                                                                                     e["properties"].get("collection_uuid")))
 
         else: