[DCAE] INFO.yaml update
[dcaegen2/platform.git] / adapter / acumos / aoconversion / utils.py
1 # ============LICENSE_START====================================================
2 # org.onap.dcae
3 # =============================================================================
4 # Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
5 # Copyright (c) 2021 highstreet technologies GmbH. All rights reserved.
6 # =============================================================================
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #      http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 # ============LICENSE_END======================================================
19
20 import json
21
22
23 class FetchSchemaError(RuntimeError):
24     pass
25
26
27 class _Schema:
28     def __init__(self, path):
29         self.ret = None
30         self.path = path
31
32     def get(self):
33         try:
34             if self.ret is None:
35                 with open(self.path, 'r') as f:
36                     self.ret = json.loads(f.read())
37             return self.ret
38         except Exception as e:
39             raise FetchSchemaError("Unexpected error from fetching schema", e)
40
41
42 schema_schema = _Schema('schemas/schema.json')
43 component_schema = _Schema('schemas/compspec.json')
44 dataformat_schema = _Schema('schemas/dataformat.json')
45
46
47 def get_metadata(model_repo_path, model_name):
48     # for now, assume it's called "metadata.json"
49     return json.loads(open("{0}/{1}/metadata.json".format(model_repo_path, model_name), "r").read())
50
51
52 def validate_format(meta, method, type):
53     """
54     Method to check for the metadata structure of the Acumos Model
55     due to change in tree structure of the input and output with Acumos-Demeter's release
56     Solution for Issue id: DCAEGEN2-2825
57     """
58     try:
59         df_name = meta["methods"][method][type]["name"]
60
61     except TypeError:
62         df_name = meta["methods"][method][type]
63     return df_name