summaryrefslogtreecommitdiffstats
path: root/adapter/acumos/aoconversion
diff options
context:
space:
mode:
Diffstat (limited to 'adapter/acumos/aoconversion')
-rw-r--r--adapter/acumos/aoconversion/dataformat_gen.py21
-rw-r--r--adapter/acumos/aoconversion/scanner.py5
-rw-r--r--adapter/acumos/aoconversion/spec_gen.py12
-rw-r--r--adapter/acumos/aoconversion/utils.py26
4 files changed, 33 insertions, 31 deletions
diff --git a/adapter/acumos/aoconversion/dataformat_gen.py b/adapter/acumos/aoconversion/dataformat_gen.py
index a5ead96..71b1617 100644
--- a/adapter/acumos/aoconversion/dataformat_gen.py
+++ b/adapter/acumos/aoconversion/dataformat_gen.py
@@ -1,7 +1,7 @@
# ============LICENSE_START====================================================
# org.onap.dcae
# =============================================================================
-# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
# =============================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -19,22 +19,9 @@
from subprocess import PIPE, Popen
import json
from jsonschema import validate
-import requests
from aoconversion import utils, exceptions
-def _get_js_schema():
- res = requests.get("http://json-schema.org/draft-04/schema#")
- return res.json()
-
-
-def _get_dcae_df_schema():
- res = requests.get(
- "https://gerrit.onap.org/r/gitweb?p=dcaegen2/platform/cli.git;a=blob_plain;f=component-json-schemas/data-format/dcae-cli-v1/data-format-schema.json;hb=HEAD"
- )
- return res.json()
-
-
def _protobuf_to_js(proto_path):
"""
Converts a protobuf to jsonschema and returns the generated schema as a JSON object.
@@ -52,7 +39,7 @@ def _protobuf_to_js(proto_path):
defs[defn.split(".")[1]] = defs.pop(defn)
# make sure what we got out is a valid jsonschema
- draft4 = _get_js_schema()
+ draft4 = utils.schema_schema.get()
validate(instance=asjson, schema=draft4)
return asjson
@@ -141,8 +128,8 @@ def generate_dcae_data_formats(model_repo_path, model_name):
data_formats = _generate_dcae_data_formats(
"{0}/{1}/model.proto".format(model_repo_path, model_name),
utils.get_metadata(model_repo_path, model_name),
- _get_dcae_df_schema(),
- _get_js_schema(),
+ utils.dataformat_schema.get(),
+ utils.schema_schema.get()
)
# now we iterate over these and write a file to disk for each, since the dcae cli seems to want that
diff --git a/adapter/acumos/aoconversion/scanner.py b/adapter/acumos/aoconversion/scanner.py
index cf3ac79..aecf760 100644
--- a/adapter/acumos/aoconversion/scanner.py
+++ b/adapter/acumos/aoconversion/scanner.py
@@ -1,7 +1,7 @@
# ============LICENSE_START====================================================
# org.onap.dcae
# =============================================================================
-# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
# =============================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -47,8 +47,7 @@ class Config(object):
Configuration parameters as attributes, make sure the required ones are there,
populate defaults.
"""
- def __init__(self, dcaeurl, dcaeuser, onboardingurl, onboardinguser, onboardingpass, certfile, dockerregistry, dockeruser, dockerpass, acumosurl=None, interval=900, dockerhost='tcp://localhost:2375', tmpdir='/var/tmp/aoadapter', certverify=True, catalogs=None, port=None, **extras):
- self.dcaeurl = dcaeurl
+ def __init__(self, dcaeuser, onboardingurl, onboardinguser, onboardingpass, certfile, dockerregistry, dockeruser, dockerpass, acumosurl=None, interval=900, dockerhost='tcp://localhost:2375', tmpdir='/var/tmp/aoadapter', certverify=True, catalogs=None, port=None, **extras):
self.dcaeuser = dcaeuser
def x(fmt, *args, **kwargs):
diff --git a/adapter/acumos/aoconversion/spec_gen.py b/adapter/acumos/aoconversion/spec_gen.py
index 4230f6d..8564434 100644
--- a/adapter/acumos/aoconversion/spec_gen.py
+++ b/adapter/acumos/aoconversion/spec_gen.py
@@ -1,7 +1,7 @@
# ============LICENSE_START====================================================
# org.onap.dcae
# =============================================================================
-# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
# =============================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -23,17 +23,9 @@ Generates DCAE component specs
import json
from jsonschema import validate
-import requests
from aoconversion import utils
-def _get_dcae_cs_schema():
- res = requests.get(
- "https://git.onap.org/dcaegen2/platform/plain/mod/component-json-schemas/component-specification/dcae-cli-v2/component-spec-schema.json"
- )
- return res.json()
-
-
def _get_format_version(target_name, data_formats):
"""
search through the data formats for name, make sure we have it, and retrieve the version
@@ -103,7 +95,7 @@ def generate_spec(model_repo_path, model_name, data_formats, docker_uri):
Returns the spec
"""
spec = _generate_spec(
- model_name, utils.get_metadata(model_repo_path, model_name), _get_dcae_cs_schema(), data_formats, docker_uri
+ model_name, utils.get_metadata(model_repo_path, model_name), utils.component_schema.get(), data_formats, docker_uri
)
fname = "{0}_dcae_component_specification.json".format(model_name)
with open("{0}/{1}".format(model_repo_path, fname), "w") as f:
diff --git a/adapter/acumos/aoconversion/utils.py b/adapter/acumos/aoconversion/utils.py
index a5aae75..7403505 100644
--- a/adapter/acumos/aoconversion/utils.py
+++ b/adapter/acumos/aoconversion/utils.py
@@ -1,7 +1,7 @@
# ============LICENSE_START====================================================
# org.onap.dcae
# =============================================================================
-# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
# =============================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -19,6 +19,30 @@
import json
+class FetchSchemaError(RuntimeError):
+ pass
+
+
+class _Schema:
+ def __init__(self, path):
+ self.ret = None
+ self.path = path
+
+ def get(self):
+ try:
+ if self.ret is None:
+ with open(self.path, 'r') as f:
+ self.ret = json.loads(f.read())
+ return self.ret
+ except Exception as e:
+ raise FetchSchemaError("Unexpected error from fetching schema", e)
+
+
+schema_schema = _Schema('schemas/schema.json')
+component_schema = _Schema('schemas/compspec.json')
+dataformat_schema = _Schema('schemas/dataformat.json')
+
+
def get_metadata(model_repo_path, model_name):
# for now, assume it's called "metadata.json"
return json.loads(open("{0}/{1}/metadata.json".format(model_repo_path, model_name), "r").read())