X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/4a78e8e91fdad38e567fef0cd43aa8cb6bd33580..1010c9e519409f0eb36971df6c382fc7cc0e2732:/sdk/cwl/arvados_cwl/pathmapper.py?ds=sidebyside diff --git a/sdk/cwl/arvados_cwl/pathmapper.py b/sdk/cwl/arvados_cwl/pathmapper.py index b54fcdcc7b..d083b78f5a 100644 --- a/sdk/cwl/arvados_cwl/pathmapper.py +++ b/sdk/cwl/arvados_cwl/pathmapper.py @@ -7,8 +7,8 @@ import logging import uuid import os import urllib -import datetime +from arvados_cwl.util import get_current_container, get_intermediate_collection_info import arvados.commands.run import arvados.collection @@ -44,7 +44,7 @@ class ArvPathMapper(PathMapper): pdh_dirpath = re.compile(r'^keep:[0-9a-f]{32}\+\d+(/.*)?$') def __init__(self, arvrunner, referenced_files, input_basedir, - collection_pattern, file_pattern, name=None, single_collection=False, **kwargs): + collection_pattern, file_pattern, name=None, single_collection=False): self.arvrunner = arvrunner self.input_basedir = input_basedir self.collection_pattern = collection_pattern @@ -155,12 +155,13 @@ class ArvPathMapper(PathMapper): for l in srcobj.get("listing", []): self.addentry(l, c, ".", remap) - info = self._get_intermediate_collection_info() + container = get_current_container(self.arvrunner.api, self.arvrunner.num_retries, logger) + info = get_intermediate_collection_info(None, container, self.arvrunner.intermediate_output_ttl) c.save_new(name=info["name"], - owner_uuid=self.arvrunner.project_uuid, - ensure_unique_name=True, - trash_at=info["trash_at"], + owner_uuid=self.arvrunner.project_uuid, + ensure_unique_name=True, + trash_at=info["trash_at"], properties=info["properties"]) ab = self.collection_pattern % c.portable_data_hash() @@ -173,12 +174,13 @@ class ArvPathMapper(PathMapper): num_retries=self.arvrunner.num_retries ) self.addentry(srcobj, c, ".", remap) - info = self._get_intermediate_collection_info() + container = get_current_container(self.arvrunner.api, self.arvrunner.num_retries, logger) + info = get_intermediate_collection_info(None, container, self.arvrunner.intermediate_output_ttl) c.save_new(name=info["name"], - owner_uuid=self.arvrunner.project_uuid, - ensure_unique_name=True, - trash_at=info["trash_at"], + owner_uuid=self.arvrunner.project_uuid, + ensure_unique_name=True, + trash_at=info["trash_at"], properties=info["properties"]) ab = self.file_pattern % (c.portable_data_hash(), srcobj["basename"]) @@ -212,26 +214,6 @@ class ArvPathMapper(PathMapper): else: return None - def _get_intermediate_collection_info(self): - trash_time = None - if self.arvrunner.intermediate_output_ttl > 0: - trash_time = datetime.datetime.now() + datetime.timedelta(seconds=self.arvrunner.intermediate_output_ttl) - - current_container_uuid = None - try: - current_container = self.arvrunner.api.containers().current().execute(num_retries=self.arvrunner.num_retries) - current_container_uuid = current_container['uuid'] - except ApiError as e: - # Status code 404 just means we're not running in a container. - if e.resp.status != 404: - logger.info("Getting current container: %s", e) - props = {"type": "Intermediate", - "container": current_container_uuid} - - return {"name" : "Intermediate collection", - "trash_at" : trash_time, - "properties" : props} - class StagingPathMapper(PathMapper): _follow_dirs = True