Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable importing of container name-only images and user-rules via sdscli #106

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdscli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from __future__ import division
from __future__ import absolute_import

__version__ = "1.3.1"
__version__ = "1.3.2"
__url__ = "https://github.com/sdskit/sdscli"
__description__ = "Command line interface for SDSKit"
33 changes: 26 additions & 7 deletions sdscli/adapters/hysds/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import division
from __future__ import absolute_import
from builtins import open
from datetime import datetime
from future import standard_library
standard_library.install_aliases()

Expand All @@ -23,6 +24,8 @@
JOB_SPECS_INDEX = "job_specs"
HYSDS_IOS_MOZART_INDEX = "hysds_ios-mozart"
HYSDS_IOS_GRQ_INDEX = "hysds_ios-grq"
USER_RULES_MOZART_INDEX = 'user_rules-mozart'
USER_RULES_GRQ_INDEX = 'user_rules-grq'

mozart_es = get_mozart_es()

Expand Down Expand Up @@ -62,9 +65,10 @@ def export(args):

validate_dir(export_dir) # create export directory

# download container
get(cont_info['url'], export_dir)
cont_info['url'] = os.path.basename(cont_info['url'])
# download container if url provided
if cont_info.get('url', None) != None:
get(cont_info['url'], export_dir)
cont_info['url'] = os.path.basename(cont_info['url'])

query = {
"query": {
Expand Down Expand Up @@ -218,11 +222,13 @@ def import_pkg(args):
logger.debug("code_bucket: %s" % code_bucket)
logger.debug("code_bucket_url: %s" % code_bucket_url)

# upload container image to s3
cont_info = manifest['containers']
cont_image = os.path.join(export_dir, cont_info['url'])
cont_info['url'] = "{}/{}".format(code_bucket_url, cont_info['url'])
put(cont_image, cont_info['url'])

# upload container image to s3
if cont_info.get('url', None) != None:
cont_image = os.path.join(export_dir, cont_info['url'])
cont_info['url'] = "{}/{}".format(code_bucket_url, cont_info['url'])
put(cont_image, cont_info['url'])

# index container in ES
indexed_container = mozart_es.index_document(index=CONTAINERS_INDEX, body=cont_info, id=cont_info['id'])
Expand Down Expand Up @@ -260,6 +266,19 @@ def import_pkg(args):
indexed_hysds_io = mozart_es.index_document(index=HYSDS_IOS_GRQ_INDEX, body=hysds_io, id=hysds_io_id)
logger.debug(indexed_hysds_io)

# index user_rules to ES
for component in (('mozart', USER_RULES_MOZART_INDEX), ('grq', USER_RULES_GRQ_INDEX)):
for rule in manifest.get('user_rules', {}).get(component[0], []):
now = datetime.utcnow().isoformat() + 'Z'

if not rule.get('creation_time', None):
rule['creation_time'] = now
if not rule.get('modified_time', None):
rule['modified_time'] = now

result = mozart_es.index_document(index=component[1], body=rule) # indexing user rules
logger.debug(result)

shutil.rmtree(export_dir) # remove package dir


Expand Down