Skip to content

Commit 7fb759a

Browse files
committed
propagate existing allowed_accounts
Closes #870.
1 parent 7bcaa8d commit 7fb759a

File tree

1 file changed

+37
-18
lines changed

1 file changed

+37
-18
lines changed

io-met.py

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,51 @@
11
#!/usr/bin/env python
22
from __future__ import print_function
3-
import sys
4-
import json
5-
import os
6-
import re
3+
import os, sys, json, re
74

8-
import hysds_commons.request_utils
5+
from hysds_commons.request_utils import requests_json_response
96
from hysds.celery import app
107
import utils
118

9+
10+
def add_hysds_io(rest_url, metadata):
11+
"""Index hysds-io into respective components ES preserving allowed_accounts
12+
if hysds-io already is registered."""
13+
14+
# get hysds-io if exists
15+
doc = requests_json_response("GET", os.path.join(rest_url, "hysds_io/type"),
16+
data={ "id": metadata['id'] }, verify=False,
17+
ignore_errors=True)
18+
19+
# copy existing allowed accounts
20+
if doc is not None:
21+
metadata['allowed_accounts'] = list(metadata['allowed_accounts'] +
22+
doc['result'].get('allowed_accounts', []))
23+
24+
# index
25+
requests_json_response("POST", os.path.join(rest_url ,"hysds_io/add"),
26+
data={ "spec":json.dumps(metadata) }, verify=False)
27+
28+
1229
def usage_and_exit():
13-
'''
14-
Prints usage and exit
15-
'''
16-
print("Usage:\n\t{0} <hysds-io> <job-spec> <version>".format(sys.argv[0]),file=sys.stderr)
30+
"""Prints usage and exit"""
31+
32+
print("Usage:\n\t{0} <hysds-io> <job-spec> <version>".format(sys.argv[0]), file=sys.stderr)
1733
sys.exit(-1)
1834

35+
1936
if __name__ == "__main__":
20-
'''
21-
Main program routing arguments to file
22-
'''
23-
if len(sys.argv) != 4:
24-
usage_and_exit()
37+
"""Main program routing arguments to file"""
38+
39+
if len(sys.argv) != 4: usage_and_exit()
40+
2541
#Read arguments
2642
specification = sys.argv[1]
2743
job_spec = sys.argv[2]
28-
version=sys.argv[3]
44+
version = sys.argv[3]
45+
2946
#Generate product name
30-
product=utils.get_product_id(specification,version)
47+
product = utils.get_product_id(specification, version)
48+
3149
#Prepare dataset metadata
3250
metadata = {
3351
"job-specification": job_spec,
@@ -37,12 +55,13 @@ def usage_and_exit():
3755
if not utils.check_exists(job_spec):
3856
print("[ERROR] Job Specification, {0}, does not exist. Cannot create HySDS-IO.".format(job_spec),file=sys.stderr)
3957
sys.exit(-2)
58+
4059
#Read specification metadata and merge it
4160
with open(specification,"r") as fp:
4261
metadata.update(json.load(fp))
4362
metadata["id"] = product
4463
if metadata.get("component","tosca") == "mozart":
45-
hysds_commons.request_utils.requests_json_response("POST", os.path.join(app.conf["MOZART_REST_URL"],"hysds_io/add"), data={"spec":json.dumps(metadata)}, verify=False)
64+
add_hysds_io(app.conf["MOZART_REST_URL"], metadata)
4665
else:
47-
hysds_commons.request_utils.requests_json_response("POST", os.path.join(app.conf["GRQ_REST_URL"],"hysds_io/add"), data={"spec":json.dumps(metadata)}, verify=False)
66+
add_hysds_io(app.conf["GRQ_REST_URL"], metadata)
4867
sys.exit(0)

0 commit comments

Comments
 (0)