Merge branch '20241-validate-ssh-keys'
[arvados.git] / sdk / cwl / arvados_cwl / runner.py
index b921b7905ad801c4486b15eb2026c38b4fdef7de..54af2be5173eb0b3ea9b4a843d9344f6d129ece0 100644 (file)
@@ -334,8 +334,6 @@ def upload_dependencies(arvrunner, name, document_loader,
     if optional_deps:
         sc_result.extend(optional_deps)
 
-    #print("BOING", uri, sc_result)
-
     sc = []
     uuids = {}
 
@@ -657,6 +655,33 @@ def update_from_mapper(workflowobj, mapper):
     with Perf(metrics, "setloc"):
         visit_class(workflowobj, ("File", "Directory"), partial(setloc, mapper))
 
+def apply_merged_map(merged_map, workflowobj):
+    def visit(v, cur_id):
+        if isinstance(v, dict):
+            if v.get("class") in ("CommandLineTool", "Workflow", "ExpressionTool"):
+                if "id" in v:
+                    cur_id = v["id"]
+            if "path" in v and "location" not in v:
+                v["location"] = v["path"]
+                del v["path"]
+            if "location" in v and cur_id in merged_map:
+                if v["location"] in merged_map[cur_id].resolved:
+                    v["location"] = merged_map[cur_id].resolved[v["location"]]
+                if v["location"] in merged_map[cur_id].secondaryFiles:
+                    v["secondaryFiles"] = merged_map[cur_id].secondaryFiles[v["location"]]
+            #if v.get("class") == "DockerRequirement":
+            #    v["http://arvados.org/cwl#dockerCollectionPDH"] = arvados_cwl.arvdocker.arv_docker_get_image(arvrunner.api, v, True,
+            #                                                                                                 runtimeContext)
+            for l in v:
+                visit(v[l], cur_id)
+        if isinstance(v, list):
+            for l in v:
+                visit(l, cur_id)
+    visit(workflowobj, None)
+
+def update_from_merged_map(tool, merged_map):
+    tool.visit(partial(apply_merged_map, merged_map))
+
 def upload_job_order(arvrunner, name, tool, job_order, runtimeContext):
     """Upload local files referenced in the input object and return updated input
     object with 'location' updated to the proper keep references.
@@ -708,8 +733,6 @@ def upload_job_order(arvrunner, name, tool, job_order, runtimeContext):
 
     update_from_mapper(job_order, jobmapper)
 
-    #print(json.dumps(job_order, indent=2))
-
     return job_order, jobmapper
 
 FileUpdates = namedtuple("FileUpdates", ["resolved", "secondaryFiles"])
@@ -754,8 +777,6 @@ def upload_workflow_deps(arvrunner, tool, runtimeContext):
         for k,v in pm.items():
             toolmap[k] = v.resolved
 
-        #print("visited", deptool["id"], toolmap, discovered_secondaryfiles)
-
         merged_map[deptool["id"]] = FileUpdates(toolmap, discovered_secondaryfiles)
 
     return merged_map