EOX GitLab Instance

Skip to content
Snippets Groups Projects
Commit dd01c9da authored by Lubomir Dolezal's avatar Lubomir Dolezal
Browse files

add product_exists method to check if 2 or more files in target and...

add product_exists method to check if 2 or more files in target and target.replace configuration default to false
parent 0b9072aa
Branches
Tags
No related merge requests found
...@@ -11,6 +11,7 @@ source: ...@@ -11,6 +11,7 @@ source:
user_domain_name: !env '${OS_USER_DOMAIN_NAME_DOWNLOAD}' user_domain_name: !env '${OS_USER_DOMAIN_NAME_DOWNLOAD}'
target: target:
type: swift type: swift
replace: false
kwargs: kwargs:
username: !env '${OS_USERNAME}' username: !env '${OS_USERNAME}'
password: !env '${OS_PASSWORD}' password: !env '${OS_PASSWORD}'
......
...@@ -22,6 +22,7 @@ source: ...@@ -22,6 +22,7 @@ source:
# user_domain_name: !env{{OS_USER_DOMAIN_NAME}} # user_domain_name: !env{{OS_USER_DOMAIN_NAME}}
target: target:
type: local type: local
replace: true
kwargs: kwargs:
storage_path: /mnt/data/target storage_path: /mnt/data/target
......
...@@ -11,6 +11,7 @@ source: ...@@ -11,6 +11,7 @@ source:
user_domain_name: !env '${OS_USER_DOMAIN_NAME_DOWNLOAD}' user_domain_name: !env '${OS_USER_DOMAIN_NAME_DOWNLOAD}'
target: target:
type: swift type: swift
replace: false
kwargs: kwargs:
username: !env '${OS_USERNAME}' username: !env '${OS_USERNAME}'
password: !env '${OS_PASSWORD}' password: !env '${OS_PASSWORD}'
......
...@@ -117,8 +117,6 @@ The following ``.env`` files are typically used: ...@@ -117,8 +117,6 @@ The following ``.env`` files are typically used:
django admin user to be used with the admin GUI. django admin user to be used with the admin GUI.
* ``<stack-name>_obs.env``: This contains access parameters for the object * ``<stack-name>_obs.env``: This contains access parameters for the object
storage(s). storage(s).
* ``<stack-name>_preprocessor.env``: Preprocessor related environment
variables
* ``<stack-name>_redis.env``: Redis access credentials and queue names * ``<stack-name>_redis.env``: Redis access credentials and queue names
...@@ -173,6 +171,7 @@ retrieve the original product files: ...@@ -173,6 +171,7 @@ retrieve the original product files:
* ``OS_REGION_NAME_DOWNLOAD`` * ``OS_REGION_NAME_DOWNLOAD``
* ``OS_AUTH_URL_DOWNLOAD`` * ``OS_AUTH_URL_DOWNLOAD``
* ``ST_AUTH_VERSION_DOWNLOAD`` * ``ST_AUTH_VERSION_DOWNLOAD``
* ``OS_USER_DOMAIN_NAME_DOWNLOAD``
VS Environment Variables VS Environment Variables
^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^
......
...@@ -26,6 +26,10 @@ properties: ...@@ -26,6 +26,10 @@ properties:
description: Extra arguments. Use depends on actual implementation. description: Extra arguments. Use depends on actual implementation.
type: object type: object
# required: [type] # required: [type]
replace:
description: If set to true, output replaces already existing files on target. If no existing are present, preprocessing does not start.
type: boolean
default: false
workdir: workdir:
description: The local directory, where intermediary files are to be stored. description: The local directory, where intermediary files are to be stored.
type: string type: string
......
...@@ -124,6 +124,16 @@ def preprocess_file(config: dict, file_path: os.PathLike, use_dir: os.PathLike=N ...@@ -124,6 +124,16 @@ def preprocess_file(config: dict, file_path: os.PathLike, use_dir: os.PathLike=N
""" """
with workdir(config, use_dir) as dirname, Timer() as preprocess_timer: with workdir(config, use_dir) as dirname, Timer() as preprocess_timer:
logger.info('Preprocessing %s in %s' % (file_path, dirname)) logger.info('Preprocessing %s in %s' % (file_path, dirname))
target_config = config['target']
# check if target.replace is configured and if not, check storage if files there
if not target_config['replace']:
uploader = get_uploader(
target_config['type'], target_config.get('args'), target_config.get('kwargs')
)
if uploader.product_exists(file_path):
raise Exception('Target.replace configuration is not set to true and objects already exist in target %s.' % file_path)
else:
logger.debug('Product does not yet exist on target')
# check if we can reuse a previous download # check if we can reuse a previous download
if not os.path.isdir('download'): if not os.path.isdir('download'):
os.mkdir('download') os.mkdir('download')
...@@ -198,7 +208,6 @@ def preprocess_file(config: dict, file_path: os.PathLike, use_dir: os.PathLike=N ...@@ -198,7 +208,6 @@ def preprocess_file(config: dict, file_path: os.PathLike, use_dir: os.PathLike=N
preprocess_internal(preprocess_config, 'unpack') preprocess_internal(preprocess_config, 'unpack')
# get an uploader for the finalized images # get an uploader for the finalized images
target_config = config['target']
uploader = get_uploader( uploader = get_uploader(
target_config['type'], target_config.get('args'), target_config.get('kwargs') target_config['type'], target_config.get('args'), target_config.get('kwargs')
) )
......
...@@ -30,3 +30,7 @@ class Uploader(ABC): ...@@ -30,3 +30,7 @@ class Uploader(ABC):
@abstractmethod @abstractmethod
def upload(self, local_path: Union[PathLike, List[PathLike]], remote_dir: PathLike) -> List[PathLike]: def upload(self, local_path: Union[PathLike, List[PathLike]], remote_dir: PathLike) -> List[PathLike]:
pass pass
@abstractmethod
def product_exists(self, remote_dir: PathLike) -> bool:
pass
...@@ -39,3 +39,10 @@ class Uploader(Base): ...@@ -39,3 +39,10 @@ class Uploader(Base):
shutil.copy2(local_path, remote_path) shutil.copy2(local_path, remote_path)
return remote_paths return remote_paths
def product_exists(self, remote_dir: os.PathLike) -> bool:
remote_path = os.path.join(self.storage_path, remote_dir)
for r, d, f in os.walk(remote_path):
if len(f) >= 2:
return True
return False
...@@ -98,8 +98,8 @@ class Uploader(Base): ...@@ -98,8 +98,8 @@ class Uploader(Base):
options['use_slo'] = True options['use_slo'] = True
with self.get_service() as swift: with self.get_service() as swift:
# use container first part of path of container as upload container # use container or first part of path
container = self.container or paths[0].partition('/')[0] container = self.container or remote_dir.partition('/')[0]
results = swift.upload(container=container, objects=objects, options=options) results = swift.upload(container=container, objects=objects, options=options)
for result in results: for result in results:
...@@ -120,3 +120,16 @@ class Uploader(Base): ...@@ -120,3 +120,16 @@ class Uploader(Base):
raise Exception('Failed to upload %s' % result["error"]) raise Exception('Failed to upload %s' % result["error"])
return remote_paths return remote_paths
def product_exists(self, remote_dir: os.PathLike) -> bool:
with self.get_service() as swift:
# use container or first part of path
container = self.container or remote_dir.partition('/')[0]
list_parts_gen = swift.list(
container=container, options={"prefix": remote_dir},
)
for page in list_parts_gen:
if page["success"] and len(page["listing"]) >= 2:
# at least two files present -> pass validation
return True
return False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment