Commit c6a1b02d authored by Spiros Koulouzis's avatar Spiros Koulouzis

fixed invalid type

parent bc784604
......@@ -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/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/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$/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>
......@@ -190,7 +189,14 @@
<option name="project" value="LOCAL" />
<updated>1571247029429</updated>
</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 />
</component>
<component name="Vcs.Log.Tabs.Properties">
......@@ -216,7 +222,8 @@
<MESSAGE value="split methods to util and set node properties to default" />
<MESSAGE value="slolved cap error" />
<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 name="XDebuggerManager">
<breakpoint-manager>
......@@ -227,14 +234,14 @@
<option name="timeStamp" value="1" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/src/utils/tosca.py</url>
<line>123</line>
<option name="timeStamp" value="84" />
<url>file://$PROJECT_DIR$/src/planner/simple_spec_alayzer.py</url>
<line>39</line>
<option name="timeStamp" value="125" />
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/src/planner/specification_analyzer.py</url>
<line>51</line>
<option name="timeStamp" value="88" />
<url>file://$PROJECT_DIR$/src/utils/tosca.py</url>
<line>18</line>
<option name="timeStamp" value="128" />
</line-breakpoint>
</breakpoints>
<default-breakpoints>
......
......@@ -75,6 +75,10 @@ class Planner:
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)
# 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)
if not tosca_util.contains_node_type(self.required_nodes, matching_node_type_name):
logging.info(' Adding: ' + str(matching_node_template.name))
......
......@@ -10,37 +10,37 @@ class SimpleAnalyzer(SpecificationAnalyzer):
super(SimpleAnalyzer, self).__init__(tosca_template, required_nodes)
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:
policy = nodes_to_implement_policy[node_name]
affected_node = self.set_specs(node_name, policy, self.nodes_in_template)
for node_name in nodes_to_implement_policies:
policies = nodes_to_implement_policies[node_name]
affected_node = self.set_specs(node_name, policies, self.nodes_in_template)
return self.required_nodes
def get_nodes_to_implement_policy(self):
nodes_to_implement_policy = {}
nodes_to_implement_policies = {}
for policy in self.tosca_template.policies:
for target in policy.targets:
for leaf in self.leaf_nodes:
logging.info('From: ' + target + ' to: ' + str(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 = []
nodes_to_implement_policy[affected_node_name] = policy_list
policy_list = nodes_to_implement_policy[affected_node_name]
policy_list.append(policy)
nodes_to_implement_policy[affected_node_name] = policy_list
return nodes_to_implement_policy
def set_node_properties_for_policy(self, affected_node, policy):
logging.info('Seeting properties for: ' + str(affected_node.type))
ancestors_types = tosca_util.get_all_ancestors_types(affected_node)
if affected_node.type == 'tosca.nodes.ARTICONF.Orchestrator':
if policy.type == 'tosca.policies.ARTICONF.Performance.CPU':
nodes_to_implement_policies[affected_node_name] = policy_list
policy_list = nodes_to_implement_policies[affected_node_name]
policy_list.append(policy.type)
nodes_to_implement_policies[affected_node_name] = policy_list
return nodes_to_implement_policies
def set_node_properties_for_policy(self, affected_node, policies):
logging.info('Setting properties for: ' + str(affected_node.type))
ancestors_types = tosca_util.get_all_ancestors_types(affected_node, self.all_node_types)
if 'tosca.nodes.ARTICONF.Orchestrator' in ancestors_types:
logging.info('Do Something')
if 'tosca.policies.ARTICONF.Performance.CPU' in policies:
logging.info('Do placement')
return affected_node
......
......@@ -49,8 +49,8 @@ class SpecificationAnalyzer(metaclass=ABCMeta):
relationship_type = req[req_name]['relationship']
graph.add_edge(node.name, req_node_name, relationship=relationship_type)
# nx.draw(graph, with_labels=True)
# plt.savefig("/tmp/graph.png")
nx.draw(graph, with_labels=True)
plt.savefig("/tmp/graph.png")
# plt.show()
return graph
......
from itertools import chain
from toscaparser.elements.nodetype import NodeType
from toscaparser.nodetemplate import NodeTemplate
from utils.TOSCA_parser import TOSCAParser
......@@ -9,7 +12,13 @@ node_type_key_names_to_remove = ['capabilities', 'derived_from']
def get_node_type_name(node):
if isinstance(node, NodeTemplate):
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):
node_type = next(iter(node))
return node_type
......@@ -28,7 +37,10 @@ def get_node_requirements(node):
def get_parent_type(node):
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):
parent_type = node[next(iter(node))]['derived_from']
return parent_type
......@@ -63,20 +75,20 @@ def get_node_types_with_interface(nodes):
def node_type_2_node_template(node_type):
nodetemplate_dict = {}
node_template_dict = {}
type_name = next(iter(node_type))
node_type_array = type_name.split(".")
name = node_type_array[len(node_type_array) - 1].lower()
nodetemplate_dict[name] = node_type[next(iter(node_type))].copy()
nodetemplate_dict[name]['type'] = type_name
node_template_dict[name] = node_type[next(iter(node_type))].copy()
node_template_dict[name]['type'] = type_name
for name_to_remove in node_type_key_names_to_remove:
if name_to_remove in nodetemplate_dict[name]:
nodetemplate_dict[name].pop(name_to_remove)
if name_to_remove in node_template_dict[name]:
node_template_dict[name].pop(name_to_remove)
if 'type' in node_type[next(iter(node_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):
......@@ -119,8 +131,16 @@ def set_node_properties(node, properties):
return node
def get_all_ancestors_types(child_node):
logging.info('child_node: ' + str(child_node.type))
def get_node_by_type(node_type, all_nodes):
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)
logging.info('child_node.parent_type: ' + str(parent_type))
return None
if parent_type:
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