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

Hc 163 container builder #11

Merged
merged 4 commits into from
Feb 25, 2020
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
*.pyc
*.key
*.pem

*.pyc
build
*.egg-info
Expand Down
9 changes: 3 additions & 6 deletions container-met.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python

import sys
import json
import os
import osaka.main

Expand All @@ -24,7 +22,7 @@
url = os.path.join(repo, os.path.basename(product))

# OSAKA call goes here
osaka.main.put("./"+product, url)
osaka.main.put("./" + product, url)

metadata = {
"name": ident,
Expand All @@ -34,8 +32,7 @@
"digest": digest
}

# headers = {"Content-Type": "application/json"}
hysds_commons.request_utils.requests_json_response("POST", os.path.join(
mozart_rest_url, "container/add"), data=metadata, verify=False)
add_container_endpoint = os.path.join(mozart_rest_url, "container/add")
hysds_commons.request_utils.requests_json_response("POST", add_container_endpoint, data=metadata, verify=False)

sys.exit(0)
38 changes: 20 additions & 18 deletions io-met.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,40 @@
import os
import sys
import json
import re

from hysds_commons.request_utils import requests_json_response
import utils


def add_hysds_io(rest_url, metadata):
"""Index hysds-io into respective components ES preserving allowed_accounts
if hysds-io already is registered."""
def add_hysds_io(rest_url, data):
"""
Index hysds-io into respective components ES preserving allowed_accounts
if hysds-io already is registered.
"""

# get hysds-io if exists
doc = requests_json_response("GET", os.path.join(rest_url, "hysds_io/type"),
data={"id": metadata['id']}, verify=False,
ignore_errors=True)
hysds_io_obj = {
"id": data['id']
}
hysds_io_endpoint = os.path.join(rest_url, "hysds_io/type")
doc = requests_json_response("GET", hysds_io_endpoint, data=hysds_io_obj, verify=False, ignore_errors=True)

# copy existing allowed accounts
if doc is not None:
merged_accounts = list(set(metadata.get('allowed_accounts', []) +
doc['result'].get('allowed_accounts', [])))
merged_accounts = list(set(data.get('allowed_accounts', []) + doc['result'].get('allowed_accounts', [])))
if len(merged_accounts) > 0:
metadata['allowed_accounts'] = merged_accounts
data['allowed_accounts'] = merged_accounts

# index
requests_json_response("POST", os.path.join(rest_url, "hysds_io/add"),
data={"spec": json.dumps(metadata)}, verify=False)
data = {
"spec": json.dumps(data)
}
requests_json_response("POST", os.path.join(rest_url, "hysds_io/add"), data=data, verify=False)


def usage_and_exit():
"""Prints usage and exit"""

print("Usage:\n\t{0} <hysds-io> <job-spec> <version> <mozart_rest_url> <grq_rest_url>".format(
sys.argv[0]), file=sys.stderr)
print("Usage: {0}".format(sys.argv[0]), file=sys.stderr)
print("Arguments must be supplied: (hysds-io, job-spec, version, mozart_rest_url, grq_rest_ur)", file=sys.stderr)
sys.exit(-1)


Expand All @@ -60,15 +62,15 @@ def usage_and_exit():
"resource": "hysds-io-specification"
}
if not utils.check_exists(job_spec, mozart_rest_url):
print("[ERROR] Job Specification, {0}, does not exist. Cannot create HySDS-IO.".format(
job_spec), file=sys.stderr)
print("ERROR: Job Specification {0} does not exist. Cannot create HySDS-IO.".format(job_spec), file=sys.stderr)
sys.exit(-2)

# Read specification metadata and merge it
with open(specification, "r") as fp:
metadata.update(json.load(fp))

metadata["id"] = product

if metadata.get("component", "tosca") in ("mozart", "figaro"):
add_hysds_io(mozart_rest_url, metadata)
else:
Expand Down
14 changes: 4 additions & 10 deletions job-met.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
#!/usr/bin/env python

import sys
import json
import os
import re
import hysds_commons.request_utils
import utils
from string import Template


def usage_and_exit():
"""
Prints usage and exit
"""
print(
"Usage:\n\t{0} <job-spec> <container> <version> <storage>".format(sys.argv[0]), file=sys.stderr)
"""Prints usage and exit"""
print("Usage:\n\t{0} <job-spec> <container> <version> <storage>".format(sys.argv[0]), file=sys.stderr)
sys.exit(-1)


def resolve_dependency_images(payload, storage):
"""
Resolve dependency images located in the cluster's code bucket
"""
"""Resolve dependency images located in the cluster's code bucket"""
if storage.endswith('/'):
storage = storage[:-1]
dep_cfgs = payload.get('dependency_images', [])
Expand Down Expand Up @@ -62,6 +55,7 @@ def resolve_dependency_images(payload, storage):
metadata.update(payload)

metadata["id"] = product

hysds_commons.request_utils.requests_json_response("POST", os.path.join(
mozart_rest_url, "job_spec/add"), data={"spec": json.dumps(metadata)}, verify=False)

Expand Down
16 changes: 7 additions & 9 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import os
import re
import subprocess
Expand All @@ -9,28 +8,27 @@


def get_repo(directory):
'''
"""
Get the repository for a given directory
@param directory: directory to check git repo for
@return: git repo of supplied directory
'''
"""
sto, ste = subprocess.Popen("cd {0}; git remote -v".format(
directory), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
for line in sto.split("\n"):
match = REPO_RE.match(line)
if match:
return match.group(1)
raise Exception(
"Failed to determine git repo of: {0}.{1}".format(directory, ste))
raise Exception("Failed to determine git repo of: {0}.{1}".format(directory, ste))


def get_product_id(specification, version):
'''
"""
Get the product id from the specification and version.
@param specification: specification name to create product id from
@param version: version to used to create the product
@return: product id
'''
"""
match = TYPE_TAIL_RE.match(specification)
if not match or not match.group(1) in ["job-spec", "hysds-io"]:
raise Exception("Invalid specification path")
Expand All @@ -42,11 +40,11 @@ def get_product_id(specification, version):


def check_exists(item, rest_url):
'''
"""
Checks the existence of item in ES
@param item: item to check
@return: True if item exists
'''
"""

ptype = "container"
if item.startswith("job"):
Expand Down