Skip to content

Commit dae9d9f

Browse files
authored
Merge pull request #120 from unity-sds/split-stage-in-out
breaking: split stage in stage out
2 parents 25a30d8 + 3172b4c commit dae9d9f

34 files changed

+649
-261
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
.idea
3+
.eggs
34
build
45
scratch*
56
local*

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.0.0] - 2023-01-23
9+
### Breaking
10+
- [#120](https://github.com/unity-sds/unity-data-services/pull/120) breakup upload and download dockers into search + download & upload + catalog
11+
812
## [1.10.1] - 2023-01-23
913
### Fixed
1014
- [#112](https://github.com/unity-sds/unity-data-services/pull/112) update dockerfile base images

cumulus_lambda_functions/cumulus_download_granules/__main__.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

cumulus_lambda_functions/cumulus_upload_granules/__init__.py

Whitespace-only changes.

cumulus_lambda_functions/docker_entrypoint/__main__.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,29 @@
22
import os
33
from sys import argv
44

5-
from cumulus_lambda_functions.cumulus_download_granules.download_granules import DownloadGranules
6-
from cumulus_lambda_functions.cumulus_upload_granules.upload_granules import UploadGranules
5+
from cumulus_lambda_functions.stage_in_out.catalog_granules_factory import CatalogGranulesFactory
6+
from cumulus_lambda_functions.stage_in_out.download_granules_s3 import DownloadGranulesS3
7+
from cumulus_lambda_functions.stage_in_out.search_granules_factory import SearchGranulesFactory
8+
from cumulus_lambda_functions.stage_in_out.upoad_granules_factory import UploadGranulesFactory
79

810

911
def choose_process():
12+
if argv[1].strip().upper() == 'SEARCH':
13+
logging.info('starting SEARCH script')
14+
return SearchGranulesFactory().get_class(os.getenv('GRANULES_SEARCH_DOMAIN', 'MISSING_GRANULES_SEARCH_DOMAIN')).search()
1015
if argv[1].strip().upper() == 'DOWNLOAD':
1116
logging.info('starting DOWNLOAD script')
12-
DownloadGranules().start()
13-
elif argv[1].strip().upper() == 'UPLOAD':
17+
return DownloadGranulesS3().download()
18+
if argv[1].strip().upper() == 'UPLOAD':
1419
logging.info('starting UPLOAD script')
15-
logging.info(UploadGranules().start())
16-
else:
17-
raise ValueError(f'invalid argument: {argv}')
18-
return
20+
return UploadGranulesFactory().get_class(os.getenv('GRANULES_UPLOAD_TYPE', 'MISSING_GRANULES_UPLOAD_TYPE')).upload()
21+
if argv[1].strip().upper() == 'CATALOG':
22+
logging.info('starting CATALOG script')
23+
return CatalogGranulesFactory().get_class(os.getenv('GRANULES_CATALOG_TYPE', 'MISSING_GRANULES_CATALOG_TYPE')).catalog()
24+
raise ValueError(f'invalid argument: {argv}')
1925

2026

2127
if __name__ == '__main__':
2228
logging.basicConfig(level=int(os.environ.get('LOG_LEVEL', '10')),
2329
format="%(asctime)s [%(levelname)s] [%(name)s::%(lineno)d] %(message)s")
24-
choose_process()
30+
print(choose_process())
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from abc import ABC, abstractmethod
2+
3+
4+
class CatalogGranulesAbstract(ABC):
5+
@abstractmethod
6+
def catalog(self, **kwargs):
7+
raise NotImplementedError()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class CatalogGranulesFactory:
2+
UNITY = 'UNITY'
3+
4+
def get_class(self, upload_type):
5+
if upload_type == CatalogGranulesFactory.UNITY:
6+
from cumulus_lambda_functions.stage_in_out.catalog_granules_unity import CatalogGranulesUnity
7+
return CatalogGranulesUnity()
8+
raise ValueError(f'unknown search_type: {upload_type}')
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from cumulus_lambda_functions.cumulus_dapa_client.dapa_client import DapaClient
2+
from cumulus_lambda_functions.stage_in_out.catalog_granules_abstract import CatalogGranulesAbstract
3+
import json
4+
import logging
5+
import os
6+
7+
LOGGER = logging.getLogger(__name__)
8+
9+
10+
class CatalogGranulesUnity(CatalogGranulesAbstract):
11+
PROVIDER_ID_KEY = 'PROVIDER_ID'
12+
UPLOADED_FILES_JSON = 'UPLOADED_FILES_JSON'
13+
VERIFY_SSL_KEY = 'VERIFY_SSL'
14+
15+
def __init__(self) -> None:
16+
super().__init__()
17+
self.__provider_id = ''
18+
self.__uploaded_files_json = None
19+
self.__verify_ssl = True
20+
21+
def __set_props_from_env(self):
22+
missing_keys = [k for k in [self.UPLOADED_FILES_JSON, self.PROVIDER_ID_KEY] if k not in os.environ]
23+
if len(missing_keys) > 0:
24+
raise ValueError(f'missing environment keys: {missing_keys}')
25+
self.__provider_id = os.environ.get(self.PROVIDER_ID_KEY)
26+
self.__uploaded_files_json = json.loads(os.environ.get(self.UPLOADED_FILES_JSON))
27+
self.__verify_ssl = os.environ.get(self.VERIFY_SSL_KEY, 'TRUE').strip().upper() == 'TRUE'
28+
return self
29+
30+
def catalog(self, **kwargs):
31+
self.__set_props_from_env()
32+
dapa_body = {
33+
"provider_id": self.__provider_id,
34+
"features": self.__uploaded_files_json
35+
}
36+
dapa_client = DapaClient().with_verify_ssl(self.__verify_ssl)
37+
LOGGER.debug(f'dapa_body_granules: {dapa_body}')
38+
dapa_ingest_result = dapa_client.ingest_granules_w_cnm(dapa_body)
39+
return dapa_ingest_result
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from abc import ABC, abstractmethod
2+
3+
4+
class DownloadGranulesAbstract(ABC):
5+
@abstractmethod
6+
def download(self, **kwargs) -> list:
7+
raise NotImplementedError()

0 commit comments

Comments
 (0)