Add --output-tags to arvados-cwl-runner and tests
authorJiayong Li <jiayong@math.mit.edu>
Tue, 8 Nov 2016 19:15:42 +0000 (14:15 -0500)
committerJiayong Li <jiayong@math.mit.edu>
Tue, 8 Nov 2016 19:15:42 +0000 (14:15 -0500)
sdk/cwl/arvados_cwl/__init__.py
sdk/cwl/arvados_cwl/arvcontainer.py
sdk/cwl/arvados_cwl/arvjob.py
sdk/cwl/arvados_cwl/crunch_script.py
sdk/cwl/tests/test_make_output.py
sdk/cwl/tests/test_submit.py

index 3144592fc98f47083581e06fabcf900517d7ab01..a22b075ce44668a665c7ace08315dd68522b2432 100644 (file)
@@ -183,7 +183,7 @@ class ArvCwlRunner(object):
             for v in obj:
                 self.check_writable(v)
 
-    def make_output_collection(self, name, outputObj):
+    def make_output_collection(self, name, outputObj, tagsString):
         outputObj = copy.deepcopy(outputObj)
 
         files = []
@@ -234,6 +234,11 @@ class ArvCwlRunner(object):
                     final.api_response()["name"],
                     final.manifest_locator())
 
+        final_uuid = final.manifest_locator()
+        tags = tagsString.split(',')
+        for tag in tags:
+             self.api.links().create(body={"head_uuid": final_uuid, "link_class": "tag", "name": tag}).execute()
+
         self.final_output_collection = final
 
     def set_crunch_output(self):
@@ -390,7 +395,7 @@ class ArvCwlRunner(object):
         else:
             if self.output_name is None:
                 self.output_name = "Output of %s" % (shortname(tool.tool["id"]))
-            self.make_output_collection(self.output_name, self.final_output)
+            self.make_output_collection(self.output_name, self.final_output, kwargs.get("output_tags", ""))
             self.set_crunch_output()
 
         if self.final_status != "success":
@@ -448,6 +453,7 @@ def arg_parser():  # type: () -> argparse.ArgumentParser
 
     parser.add_argument("--project-uuid", type=str, metavar="UUID", help="Project that will own the workflow jobs, if not provided, will go to home project.")
     parser.add_argument("--output-name", type=str, help="Name to use for collection that stores the final output.", default=None)
+    parser.add_argument("--output-tags", type=str, help="Tags for the final output collection separated by commas, e.g., '--output-tags tag0,tag1,tag2'.", default=None)
     parser.add_argument("--ignore-docker-for-reuse", action="store_true",
                         help="Ignore Docker image version when deciding whether to reuse past jobs.",
                         default=False)
index c0d82d9585a70488c450f085d9e91704718a5b46..cae9027c484f3eb462d03ab3180d7a577fae4f2c 100644 (file)
@@ -189,6 +189,9 @@ class RunnerContainer(Runner):
         if self.output_name:
             command.append("--output-name=" + self.output_name)
 
+        if kwargs.get("output_tags"):
+            command.append("--output-tags=" + kwargs.get("output_tags"))
+
         if self.enable_reuse:
             command.append("--enable-reuse")
         else:
index 4336c0fb1000d0848f3decaf58e03ab88e353796..3d99391449f3c3906b953df08535a5d6193a1ca9 100644 (file)
@@ -239,6 +239,9 @@ class RunnerJob(Runner):
         if self.output_name:
             self.job_order["arv:output_name"] = self.output_name
 
+        if kwargs.get("output_tags"):
+            self.job_order["arv:output_tags"] = kwargs.get("output_tags")
+
         self.job_order["arv:enable_reuse"] = self.enable_reuse
 
         return {
index 173eb93daf2c4070ba92f28fca2ac053952f1662..cc9d87899cc9973bcc02e645848ec175227b752d 100644 (file)
@@ -68,6 +68,10 @@ def run():
             output_name = job_order_object["arv:output_name"]
             del job_order_object["arv:output_name"]
 
+        if "arv:output_tags" in job_order_object:
+            args.output_tags = job_order_object["arv:output_tags"]
+            del job_order_object["arv:output_tags"]
+
         if "arv:enable_reuse" in job_order_object:
             enable_reuse = job_order_object["arv:enable_reuse"]
             del job_order_object["arv:enable_reuse"]
index 0b08b2e6ec10b36cfe7dabf9be0263050893d878..0a33649adb1d86f72a355e32878cd6e94e7f0018 100644 (file)
@@ -44,7 +44,7 @@ class TestMakeOutput(unittest.TestCase):
                 "location": "keep:99999999999999999999999999999992+99/bar.txt",
                 "basename": "baz.txt"
             }
-        })
+        }, "")
 
         final.copy.assert_has_calls([mock.call('bar.txt', 'baz.txt', overwrite=False, source_collection=readermock)])
         final.copy.assert_has_calls([mock.call('foo.txt', 'foo.txt', overwrite=False, source_collection=readermock)])
index c195b03916992561f5e52b1d970c3cabd778df30..2371c33370ce75acc534a274d85692be72c75f82 100644 (file)
@@ -269,6 +269,27 @@ class TestSubmit(unittest.TestCase):
         self.assertEqual(capture_stdout.getvalue(),
                          stubs.expect_pipeline_uuid + '\n')
 
+    @mock.patch("time.sleep")
+    @stubs
+    def test_submit_output_tags(self, stubs, tm):
+        output_tags = "tag0,tag1,tag2"
+
+        capture_stdout = cStringIO.StringIO()
+        exited = arvados_cwl.main(
+            ["--submit", "--no-wait", "--debug", "--output-tags", output_tags,
+             "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
+            capture_stdout, sys.stderr, api_client=stubs.api)
+        self.assertEqual(exited, 0)
+
+        stubs.expect_pipeline_instance["components"]["cwl-runner"]["script_parameters"]["arv:output_tags"] = "tag0,tag1,tag2"
+
+        expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
+        expect_pipeline["owner_uuid"] = stubs.fake_user_uuid
+        stubs.api.pipeline_instances().create.assert_called_with(
+            body=expect_pipeline)
+        self.assertEqual(capture_stdout.getvalue(),
+                         stubs.expect_pipeline_uuid + '\n')
+
     @mock.patch("time.sleep")
     @stubs
     def test_submit_with_project_uuid(self, stubs, tm):