Commit c6a1b02d authored by Spiros Koulouzis's avatar Spiros Koulouzis

fixed invalid type

parent bc784604
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
<change beforePath="$PROJECT_DIR$/src/planner/planner.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/planner/planner.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/planner/planner.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/planner/planner.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/planner/simple_spec_alayzer.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/planner/simple_spec_alayzer.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/planner/simple_spec_alayzer.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/planner/simple_spec_alayzer.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/planner/specification_analyzer.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/planner/specification_analyzer.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/planner/specification_analyzer.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/planner/specification_analyzer.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/setup.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/setup.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/utils/tosca.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/utils/tosca.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/utils/tosca.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/utils/tosca.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/setuptools-40.8.0-py3.6.egg" beforeDir="false" afterPath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/setuptools-40.8.0-py3.6.egg" afterDir="false" /> <change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/setuptools-40.8.0-py3.6.egg" beforeDir="false" afterPath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/setuptools-40.8.0-py3.6.egg" afterDir="false" />
</list> </list>
...@@ -190,7 +189,14 @@ ...@@ -190,7 +189,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1571247029429</updated> <updated>1571247029429</updated>
</task> </task>
<option name="localTasksCounter" value="11" /> <task id="LOCAL-00011" summary="added libs in setup">
<created>1571320780678</created>
<option name="number" value="00011" />
<option name="presentableId" value="LOCAL-00011" />
<option name="project" value="LOCAL" />
<updated>1571320780678</updated>
</task>
<option name="localTasksCounter" value="12" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
...@@ -216,7 +222,8 @@ ...@@ -216,7 +222,8 @@
<MESSAGE value="split methods to util and set node properties to default" /> <MESSAGE value="split methods to util and set node properties to default" />
<MESSAGE value="slolved cap error" /> <MESSAGE value="slolved cap error" />
<MESSAGE value="try to analyze policies" /> <MESSAGE value="try to analyze policies" />
<option name="LAST_COMMIT_MESSAGE" value="try to analyze policies" /> <MESSAGE value="added libs in setup" />
<option name="LAST_COMMIT_MESSAGE" value="added libs in setup" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>
...@@ -227,14 +234,14 @@ ...@@ -227,14 +234,14 @@
<option name="timeStamp" value="1" /> <option name="timeStamp" value="1" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line"> <line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/src/utils/tosca.py</url> <url>file://$PROJECT_DIR$/src/planner/simple_spec_alayzer.py</url>
<line>123</line> <line>39</line>
<option name="timeStamp" value="84" /> <option name="timeStamp" value="125" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line"> <line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/src/planner/specification_analyzer.py</url> <url>file://$PROJECT_DIR$/src/utils/tosca.py</url>
<line>51</line> <line>18</line>
<option name="timeStamp" value="88" /> <option name="timeStamp" value="128" />
</line-breakpoint> </line-breakpoint>
</breakpoints> </breakpoints>
<default-breakpoints> <default-breakpoints>
......
...@@ -75,6 +75,10 @@ class Planner: ...@@ -75,6 +75,10 @@ class Planner:
matching_node_type_name = next(iter(matching_node)) matching_node_type_name = next(iter(matching_node))
matching_node_type_name = next(iter(matching_node)) matching_node_type_name = next(iter(matching_node))
matching_node_template = tosca_util.node_type_2_node_template(matching_node) matching_node_template = tosca_util.node_type_2_node_template(matching_node)
# For some reason the definitions of swarm are missing. We add them manually here
if len(matching_node_template.custom_def) < len(self.all_custom_def):
matching_node_template.custom_def.update(self.all_custom_def)
node = self.add_missing_requirements(node, missing_requirements, matching_node_template.name) node = self.add_missing_requirements(node, missing_requirements, matching_node_template.name)
if not tosca_util.contains_node_type(self.required_nodes, matching_node_type_name): if not tosca_util.contains_node_type(self.required_nodes, matching_node_type_name):
logging.info(' Adding: ' + str(matching_node_template.name)) logging.info(' Adding: ' + str(matching_node_template.name))
......
...@@ -10,37 +10,37 @@ class SimpleAnalyzer(SpecificationAnalyzer): ...@@ -10,37 +10,37 @@ class SimpleAnalyzer(SpecificationAnalyzer):
super(SimpleAnalyzer, self).__init__(tosca_template, required_nodes) super(SimpleAnalyzer, self).__init__(tosca_template, required_nodes)
def set_node_specifications(self): def set_node_specifications(self):
nodes_to_implement_policy = self.get_nodes_to_implement_policy() nodes_to_implement_policies = self.get_nodes_to_implement_policy()
for node_name in nodes_to_implement_policy: for node_name in nodes_to_implement_policies:
policy = nodes_to_implement_policy[node_name] policies = nodes_to_implement_policies[node_name]
affected_node = self.set_specs(node_name, policy, self.nodes_in_template) affected_node = self.set_specs(node_name, policies, self.nodes_in_template)
return self.required_nodes return self.required_nodes
def get_nodes_to_implement_policy(self): def get_nodes_to_implement_policy(self):
nodes_to_implement_policy = {} nodes_to_implement_policies = {}
for policy in self.tosca_template.policies: for policy in self.tosca_template.policies:
for target in policy.targets: for target in policy.targets:
for leaf in self.leaf_nodes: for leaf in self.leaf_nodes:
logging.info('From: ' + target + ' to: ' + str(leaf)) logging.info('From: ' + target + ' to: ' + str(leaf))
for affected_node_name in (nx.shortest_path(self.g, source=target, target=leaf)): for affected_node_name in (nx.shortest_path(self.g, source=target, target=leaf)):
if affected_node_name not in nodes_to_implement_policy: if affected_node_name not in nodes_to_implement_policies:
policy_list = [] policy_list = []
nodes_to_implement_policy[affected_node_name] = policy_list nodes_to_implement_policies[affected_node_name] = policy_list
policy_list = nodes_to_implement_policy[affected_node_name] policy_list = nodes_to_implement_policies[affected_node_name]
policy_list.append(policy) policy_list.append(policy.type)
nodes_to_implement_policy[affected_node_name] = policy_list nodes_to_implement_policies[affected_node_name] = policy_list
return nodes_to_implement_policy return nodes_to_implement_policies
def set_node_properties_for_policy(self, affected_node, policy): def set_node_properties_for_policy(self, affected_node, policies):
logging.info('Seeting properties for: ' + str(affected_node.type)) logging.info('Setting properties for: ' + str(affected_node.type))
ancestors_types = tosca_util.get_all_ancestors_types(affected_node) ancestors_types = tosca_util.get_all_ancestors_types(affected_node, self.all_node_types)
if 'tosca.nodes.ARTICONF.Orchestrator' in ancestors_types:
if affected_node.type == 'tosca.nodes.ARTICONF.Orchestrator': logging.info('Do Something')
if policy.type == 'tosca.policies.ARTICONF.Performance.CPU': if 'tosca.policies.ARTICONF.Performance.CPU' in policies:
logging.info('Do placement') logging.info('Do placement')
return affected_node return affected_node
......
...@@ -49,8 +49,8 @@ class SpecificationAnalyzer(metaclass=ABCMeta): ...@@ -49,8 +49,8 @@ class SpecificationAnalyzer(metaclass=ABCMeta):
relationship_type = req[req_name]['relationship'] relationship_type = req[req_name]['relationship']
graph.add_edge(node.name, req_node_name, relationship=relationship_type) graph.add_edge(node.name, req_node_name, relationship=relationship_type)
# nx.draw(graph, with_labels=True) nx.draw(graph, with_labels=True)
# plt.savefig("/tmp/graph.png") plt.savefig("/tmp/graph.png")
# plt.show() # plt.show()
return graph return graph
......
from itertools import chain
from toscaparser.elements.nodetype import NodeType
from toscaparser.nodetemplate import NodeTemplate from toscaparser.nodetemplate import NodeTemplate
from utils.TOSCA_parser import TOSCAParser from utils.TOSCA_parser import TOSCAParser
...@@ -9,7 +12,13 @@ node_type_key_names_to_remove = ['capabilities', 'derived_from'] ...@@ -9,7 +12,13 @@ node_type_key_names_to_remove = ['capabilities', 'derived_from']
def get_node_type_name(node): def get_node_type_name(node):
if isinstance(node, NodeTemplate): if isinstance(node, NodeTemplate):
node_type = node.type if node.type:
if node.type and isinstance(node.type, str):
node_type = node.type
elif isinstance(node.type, NodeTemplate):
node_type = node.type.type
else:
node_type = None
elif isinstance(node, dict): elif isinstance(node, dict):
node_type = next(iter(node)) node_type = next(iter(node))
return node_type return node_type
...@@ -28,7 +37,10 @@ def get_node_requirements(node): ...@@ -28,7 +37,10 @@ def get_node_requirements(node):
def get_parent_type(node): def get_parent_type(node):
if isinstance(node, NodeTemplate): if isinstance(node, NodeTemplate):
parent_type = node.parent_type if node.parent_type:
parent_type = node.parent_type.type
else:
parent_type = None
elif isinstance(node, dict): elif isinstance(node, dict):
parent_type = node[next(iter(node))]['derived_from'] parent_type = node[next(iter(node))]['derived_from']
return parent_type return parent_type
...@@ -63,20 +75,20 @@ def get_node_types_with_interface(nodes): ...@@ -63,20 +75,20 @@ def get_node_types_with_interface(nodes):
def node_type_2_node_template(node_type): def node_type_2_node_template(node_type):
nodetemplate_dict = {} node_template_dict = {}
type_name = next(iter(node_type)) type_name = next(iter(node_type))
node_type_array = type_name.split(".") node_type_array = type_name.split(".")
name = node_type_array[len(node_type_array) - 1].lower() name = node_type_array[len(node_type_array) - 1].lower()
nodetemplate_dict[name] = node_type[next(iter(node_type))].copy() node_template_dict[name] = node_type[next(iter(node_type))].copy()
nodetemplate_dict[name]['type'] = type_name node_template_dict[name]['type'] = type_name
for name_to_remove in node_type_key_names_to_remove: for name_to_remove in node_type_key_names_to_remove:
if name_to_remove in nodetemplate_dict[name]: if name_to_remove in node_template_dict[name]:
nodetemplate_dict[name].pop(name_to_remove) node_template_dict[name].pop(name_to_remove)
if 'type' in node_type[next(iter(node_type))]: if 'type' in node_type[next(iter(node_type))]:
node_type[next(iter(node_type))].pop('type') node_type[next(iter(node_type))].pop('type')
return NodeTemplate(name, nodetemplate_dict, node_type) return NodeTemplate(name, node_template_dict, node_type)
def get_tosca_template_2_topology_template(template): def get_tosca_template_2_topology_template(template):
...@@ -119,8 +131,16 @@ def set_node_properties(node, properties): ...@@ -119,8 +131,16 @@ def set_node_properties(node, properties):
return node return node
def get_all_ancestors_types(child_node): def get_node_by_type(node_type, all_nodes):
logging.info('child_node: ' + str(child_node.type)) return all_nodes[node_type]
def get_all_ancestors_types(child_node, all_nodes, ancestors_types=None):
if not ancestors_types:
ancestors_types = [get_node_type_name(child_node)]
parent_type = get_parent_type(child_node) parent_type = get_parent_type(child_node)
logging.info('child_node.parent_type: ' + str(parent_type)) if parent_type:
return None ancestors_types.append(parent_type)
parent_type = node_type_2_node_template({'name': all_nodes[parent_type]})
get_all_ancestors_types(parent_type, all_nodes, ancestors_types)
return ancestors_types
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment