-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtosca-parser.py
110 lines (86 loc) · 3.62 KB
/
tosca-parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""
Use of microanalyser package
"""
import os
# from six import print_
from toscaparser.common.exception import ValidationError
from toscaparser.tosca_template import ToscaTemplate
from microfreshener.core.model import Service, Datastore, CommunicationPattern
from microfreshener.core.model import InteractsWith
from microfreshener.core.model.microtosca import MicroToscaModel
from microfreshener.core.analyser.analyser import MicroToscaAnalyser
from microfreshener.core.importer import YMLImporter
from microfreshener.core.importer import JSONImporter
from microfreshener.core.exporter import JSONExporter
from microfreshener.core.exporter import YMLExporter
from microfreshener.core.analyser.builder import MicroToscaAnalyserBuilder
from microfreshener.core.analyser.analyser import MicroToscaAnalyser
from microfreshener.core.analyser.constant import INDEPENDENT_DEPLOYABILITY
from microfreshener.core.analyser.sniffer import EndpointBasedServiceInteractionSmellSniffer, NoApiGatewaySmellSniffer, WobblyServiceInteractionSmellSniffer, SharedPersistencySmellSniffer
import pprint
example = 'data/testshelloworld_squads.yml'
json_ex = 'data/testshelloworld.json'
yml_ex = 'data/testshelloworld.yml'
# path_refactored = '/home/dido/code/micro-tosca/data/testshelloworld.refactored.yml'
path_to_yml = os.path.join(os.path.dirname(os.path.realpath(__file__)), yml_ex)
path_to_json= os.path.join(os.path.dirname(os.path.realpath(__file__)), json_ex )
#**********************************
# VALIDATOR: Open stack
# *********************************
tosca = ToscaTemplate(path_to_yml, None)
if tosca.version:
print("\nversion: " + tosca.version)
#********************************
# LOADER: yml, json
#*******************************
# Yml loader
loader = YMLImporter()
micro_model = loader.Import(path_to_yml)
#JSON loader
# loader = JSONImporter()
# micro_model = loader.Import(path_to_json)
#********************************
# MICRO MODEL
#*******************************
# add node
# s = Service(name="new")
# s.add_deployment_time(micro_model["order"])
# s.add_run_time(micro_model["order_db"])
# micro_model.add_node(s)
# remove node
#micro_model.delete_node(micro_model["new"])
#*************************************************************
# ANALYSER
#*************************************************************
an = MicroToscaAnalyser(micro_model)
an.add_node_smell_sniffer(EndpointBasedServiceInteractionSmellSniffer())
an.add_node_smell_sniffer(WobblyServiceInteractionSmellSniffer())
# an.add_node_smell_sniffer(SharedPersistencySmellSniffer())
# an.add_group_smell_sniffer(NoApiGatewaySmellSniffer())
# an.add_node_smell_sniffer(SharedPersistencySmellSniffer())
an.ignore_smell_for_node(micro_model['shipping'], EndpointBasedServiceInteractionSmell)
res = an.run()
pprint.pprint(res)
# print(res)
#*******************************
# PLANNER
#*******************************
# def merge_services(micro_model, shared_persistency):
# copy_micro_model = micro_model.copy()
# new_name = "_".join([node.name for node in shared_persistency.source_nodes])
# new_service = Service(new_name)
# for node in shared_persistency.source_nodes:
# pass
# copy_micro_model.delete_node(node)
#*******************************
# TRANFORMER
#*******************************
# transformer = YMLExporter()
# r = transformer.Export(micro_model)
# pprint.pprint(r)
#*******************************
# OUTPUTTER
#*******************************
# imput: dictionary,
# convert the dictionary into a format (json, yml) and output it into
# different types of output: console, file, socket ??