Commit bc784604 authored by Spiros Koulouzis's avatar Spiros Koulouzis

added libs in setup

parent e29afddc
...@@ -3,6 +3,12 @@ ...@@ -3,6 +3,12 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment=""> <list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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/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> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
...@@ -177,7 +183,14 @@ ...@@ -177,7 +183,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1571246443192</updated> <updated>1571246443192</updated>
</task> </task>
<option name="localTasksCounter" value="10" /> <task id="LOCAL-00010" summary="try to analyze policies">
<created>1571247029429</created>
<option name="number" value="00010" />
<option name="presentableId" value="LOCAL-00010" />
<option name="project" value="LOCAL" />
<updated>1571247029429</updated>
</task>
<option name="localTasksCounter" value="11" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
...@@ -215,8 +228,13 @@ ...@@ -215,8 +228,13 @@
</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/utils/tosca.py</url>
<line>32</line> <line>123</line>
<option name="timeStamp" value="51" /> <option name="timeStamp" value="84" />
</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" />
</line-breakpoint> </line-breakpoint>
</breakpoints> </breakpoints>
<default-breakpoints> <default-breakpoints>
......
...@@ -16,6 +16,7 @@ import matplotlib.pyplot as plt ...@@ -16,6 +16,7 @@ import matplotlib.pyplot as plt
class Planner: class Planner:
def __init__(self, path, spec_service): def __init__(self, path, spec_service):
self.path = path
self.tosca_template = ToscaTemplate(path) self.tosca_template = ToscaTemplate(path)
self.tosca_node_types = self.tosca_template.nodetemplates[0].type_definition.TOSCA_DEF self.tosca_node_types = self.tosca_template.nodetemplates[0].type_definition.TOSCA_DEF
self.all_custom_def = self.tosca_template.nodetemplates[0].custom_def self.all_custom_def = self.tosca_template.nodetemplates[0].custom_def
...@@ -35,7 +36,7 @@ class Planner: ...@@ -35,7 +36,7 @@ class Planner:
def set_infrastructure_specifications(self, required_nodes): def set_infrastructure_specifications(self, required_nodes):
# Start bottom up and (node without requirements leaf) and find the root of the graph. # Start bottom up and (node without requirements leaf) and find the root of the graph.
# Get root performance, version requirements and set specs to required node # Get root performance, version requirements and set specs to required node
specification_analyzer = SimpleAnalyzer(required_nodes, self.tosca_template) specification_analyzer = SimpleAnalyzer(self.tosca_template, required_nodes)
required_nodes = specification_analyzer.set_node_specifications() required_nodes = specification_analyzer.set_node_specifications()
return required_nodes return required_nodes
......
...@@ -4,49 +4,27 @@ import networkx as nx ...@@ -4,49 +4,27 @@ import networkx as nx
import logging import logging
def set_node_properties_for_policy(affected_node, policy):
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':
logging.info('Do placement')
return affected_node
def set_specs(node_name, policy, nodes_in_template):
for node in nodes_in_template:
if node.name == node_name:
affected_node = node
break
logging.info('node to implement policy: ' + str(affected_node.type))
affected_node = set_node_properties_for_policy(affected_node, policy)
return affected_node
class SimpleAnalyzer(SpecificationAnalyzer): class SimpleAnalyzer(SpecificationAnalyzer):
def __init__(self, required_nodes, tosca_template): def __init__(self, tosca_template, required_nodes):
super(SimpleAnalyzer, self).__init__(required_nodes, tosca_template) super(SimpleAnalyzer, self).__init__(tosca_template, required_nodes)
def set_node_specifications(self): def set_node_specifications(self):
# nx.draw(g, with_labels=True)
# plt.savefig("/tmp/graph.png")
# plt.show()
nodes_to_implement_policy = self.get_nodes_to_implement_policy() nodes_to_implement_policy = self.get_nodes_to_implement_policy()
for node_name in nodes_to_implement_policy: for node_name in nodes_to_implement_policy:
policy = nodes_to_implement_policy[node_name] policy = nodes_to_implement_policy[node_name]
affected_node = set_specs(node_name, policy, self.nodes_in_template) affected_node = self.set_specs(node_name, policy, 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_policy = {}
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))
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_policy:
policy_list = [] policy_list = []
...@@ -56,16 +34,23 @@ class SimpleAnalyzer(SpecificationAnalyzer): ...@@ -56,16 +34,23 @@ class SimpleAnalyzer(SpecificationAnalyzer):
nodes_to_implement_policy[affected_node_name] = policy_list nodes_to_implement_policy[affected_node_name] = policy_list
return nodes_to_implement_policy return nodes_to_implement_policy
def build_graph(self, node_templates): def set_node_properties_for_policy(self, affected_node, policy):
graph = nx.DiGraph() logging.info('Seeting properties for: ' + str(affected_node.type))
for node in node_templates:
graph.add_node(node.name, attr_dict=node.entity_tpl) ancestors_types = tosca_util.get_all_ancestors_types(affected_node)
for req in node.requirements:
req_name = next(iter(req)) if affected_node.type == 'tosca.nodes.ARTICONF.Orchestrator':
req_node_name = req[req_name]['node'] if policy.type == 'tosca.policies.ARTICONF.Performance.CPU':
if 'type' in req[req_name]['relationship']: logging.info('Do placement')
relationship_type = req[req_name]['relationship']['type'] return affected_node
else:
relationship_type = req[req_name]['relationship'] def set_specs(self, node_name, policies, nodes_in_template):
graph.add_edge(node.name, req_node_name, relationship=relationship_type) for node in nodes_in_template:
return graph if node.name == node_name:
affected_node = node
break
logging.info('node: ' + str(affected_node.type) + ' will implement policies: ' + str(len(policies)))
affected_node = self.set_node_properties_for_policy(affected_node, policies)
return affected_node
from abc import abstractmethod, ABCMeta from abc import abstractmethod, ABCMeta
from toscaparser.tosca_template import ToscaTemplate
import networkx as nx
from src.utils import tosca as tosca_util from src.utils import tosca as tosca_util
import matplotlib.pyplot as plt
class SpecificationAnalyzer(metaclass=ABCMeta): class SpecificationAnalyzer(metaclass=ABCMeta):
def __init__(self, required_nodes, tosca_template): def __init__(self, tosca_template, required_nodes):
self.tosca_template = tosca_template self.tosca_template = tosca_template
self.tosca_node_types = self.tosca_template.nodetemplates[0].type_definition.TOSCA_DEF self.tosca_node_types = self.tosca_template.nodetemplates[0].type_definition.TOSCA_DEF
self.all_custom_def = self.tosca_template.nodetemplates[0].custom_def self.all_custom_def = self.tosca_template.nodetemplates[0].custom_def
self.all_node_types = {} self.all_node_types = {}
self.all_node_types.update(self.tosca_node_types.items()) self.all_node_types.update(self.tosca_node_types.items())
self.all_node_types.update(self.all_custom_def.items()) self.all_node_types.update(self.all_custom_def.items())
self.required_nodes = []
self.required_nodes = required_nodes self.required_nodes = required_nodes
self.nodes_in_template = [] self.nodes_in_template = []
for req_node in required_nodes: for req_node in required_nodes:
node_template = tosca_util.node_type_2_node_template(req_node) node_template = tosca_util.node_type_2_node_template(req_node)
self.nodes_in_template.append(node_template) self.nodes_in_template.append(node_template)
self.nodes_in_template += tosca_template.nodetemplates
self.nodes_in_template += self.tosca_template.nodetemplates
self.g = self.build_graph(self.nodes_in_template) self.g = self.build_graph(self.nodes_in_template)
self.root_nodes = [] self.root_nodes = []
...@@ -29,6 +36,24 @@ class SpecificationAnalyzer(metaclass=ABCMeta): ...@@ -29,6 +36,24 @@ class SpecificationAnalyzer(metaclass=ABCMeta):
if degree == 0: if degree == 0:
self.leaf_nodes.append(node_name) self.leaf_nodes.append(node_name)
def build_graph(self, node_templates):
graph = nx.DiGraph()
for node in node_templates:
graph.add_node(node.name, attr_dict=node.entity_tpl)
for req in node.requirements:
req_name = next(iter(req))
req_node_name = req[req_name]['node']
if 'type' in req[req_name]['relationship']:
relationship_type = req[req_name]['relationship']['type']
else:
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")
# plt.show()
return graph
@abstractmethod @abstractmethod
def set_node_specifications(self): def set_node_specifications(self):
raise NotImplementedError('Must implement upload in subclasses') raise NotImplementedError('Must implement upload in subclasses')
from setuptools import setup, find_packages from setuptools import setup, find_packages
setup ( setup(
name='drip_planner2', name='drip_planner2',
version='0.1', version='0.1',
packages=find_packages(), packages=find_packages(),
# Declare your packages' dependencies here, for eg: # Declare your packages' dependencies here, for eg:
install_requires=['matplotlib>=3.1.1'], install_requires=['matplotlib==3.1.1', 'pika==1.1.0', 'tosca-parser==1.6.0', 'names==0.3.0', 'networkx==2.4',
'matplotlib==3.1.1'],
# Fill in these to make your Egg ready for upload to # Fill in these to make your Egg ready for upload to
# PyPI # PyPI
author='S. Koulouzis', author='S. Koulouzis',
author_email='', author_email='',
#summary = 'Just another Python package for the cheese shop', # summary = 'Just another Python package for the cheese shop',
url='', url='',
license='', license='',
long_description='Long description of the package', long_description='Long description of the package',
# could also include long_description, download_url, classifiers, etc. # could also include long_description, download_url, classifiers, etc.
)
)
\ No newline at end of file
...@@ -122,5 +122,5 @@ def set_node_properties(node, properties): ...@@ -122,5 +122,5 @@ def set_node_properties(node, properties):
def get_all_ancestors_types(child_node): def get_all_ancestors_types(child_node):
logging.info('child_node: ' + str(child_node.type)) logging.info('child_node: ' + str(child_node.type))
parent_type = get_parent_type(child_node) parent_type = get_parent_type(child_node)
# logging.info('child_node.parent_type: ' + str(parent_type)) logging.info('child_node.parent_type: ' + str(parent_type))
return None return None
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