8a6fc9d7346b471101de1b3c8a495195348b17a7
[arvados.git] / sdk / cwl / arvados_cwl / done.py
1 def done(self, record, tmpdir, outdir, keepdir):
2     colname = "Output %s of %s" % (record["output"][0:7], self.name)
3
4     # check if collection already exists with same owner, name and content
5     collection_exists = self.arvrunner.api.collections().list(
6         filters=[["owner_uuid", "=", self.arvrunner.project_uuid],
7                  ['portable_data_hash', '=', record["output"]],
8                  ["name", "=", colname]]
9     ).execute(num_retries=self.arvrunner.num_retries)
10
11     if not collection_exists["items"]:
12         # Create a collection located in the same project as the
13         # pipeline with the contents of the output.
14         # First, get output record.
15         collections = self.arvrunner.api.collections().list(
16             limit=1,
17             filters=[['portable_data_hash', '=', record["output"]]],
18             select=["manifest_text"]
19         ).execute(num_retries=self.arvrunner.num_retries)
20
21         if not collections["items"]:
22             raise WorkflowException(
23                 "Job output '%s' cannot be found on API server" % (
24                     record["output"]))
25
26         # Create new collection in the parent project
27         # with the output contents.
28         self.arvrunner.api.collections().create(body={
29             "owner_uuid": self.arvrunner.project_uuid,
30             "name": colname,
31             "portable_data_hash": record["output"],
32             "manifest_text": collections["items"][0]["manifest_text"]
33         }, ensure_unique_name=True).execute(
34             num_retries=self.arvrunner.num_retries)
35
36     self.builder.outdir = outdir
37     self.builder.pathmapper.keepdir = keepdir
38     return self.collect_outputs("keep:" + record["output"])