Commit bc784604 authored by Spiros Koulouzis's avatar Spiros Koulouzis

added libs in setup

parent e29afddc
......@@ -3,6 +3,12 @@
<component name="ChangeListManager">
<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$/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>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
......@@ -177,7 +183,14 @@
<option name="project" value="LOCAL" />
<updated>1571246443192</updated>
</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 />
</component>
<component name="Vcs.Log.Tabs.Properties">
......@@ -215,8 +228,13 @@
</line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/src/utils/tosca.py</url>
<line>32</line>
<option name="timeStamp" value="51" />
<line>123</line>
<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>
</breakpoints>
<default-breakpoints>
......
......@@ -16,6 +16,7 @@ import matplotlib.pyplot as plt
class Planner:
def __init__(self, path, spec_service):
self.path = path
self.tosca_template = ToscaTemplate(path)
self.tosca_node_types = self.tosca_template.nodetemplates[0].type_definition.TOSCA_DEF
self.all_custom_def = self.tosca_template.nodetemplates[0].custom_def
......@@ -35,7 +36,7 @@ class Planner:
def set_infrastructure_specifications(self, required_nodes):
# 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
specification_analyzer = SimpleAnalyzer(required_nodes, self.tosca_template)
specification_analyzer = SimpleAnalyzer(self.tosca_template, required_nodes)
required_nodes = specification_analyzer.set_node_specifications()
return required_nodes
......
......@@ -4,49 +4,27 @@ import networkx as nx
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):
def __init__(self, required_nodes, tosca_template):
super(SimpleAnalyzer, self).__init__(required_nodes, tosca_template)
def __init__(self, tosca_template, required_nodes):
super(SimpleAnalyzer, self).__init__(tosca_template, required_nodes)
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()
for node_name in nodes_to_implement_policy:
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
def get_nodes_to_implement_policy(self):
nodes_to_implement_policy = {}
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:
policy_list = []
......@@ -56,16 +34,23 @@ class SimpleAnalyzer(SpecificationAnalyzer):
nodes_to_implement_policy[affected_node_name] = policy_list
return nodes_to_implement_policy
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)
return graph
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':
logging.info('Do placement')
return affected_node
def set_specs(self, node_name, policies, nodes_in_template):
for node in nodes_in_template:
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 toscaparser.tosca_template import ToscaTemplate
import networkx as nx
from src.utils import tosca as tosca_util
import matplotlib.pyplot as plt
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_node_types = self.tosca_template.nodetemplates[0].type_definition.TOSCA_DEF
self.all_custom_def = self.tosca_template.nodetemplates[0].custom_def
self.all_node_types = {}
self.all_node_types.update(self.tosca_node_types.items())
self.all_node_types.update(self.all_custom_def.items())
self.required_nodes = []
self.required_nodes = required_nodes
self.nodes_in_template = []
for req_node in required_nodes:
node_template = tosca_util.node_type_2_node_template(req_node)
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.root_nodes = []
......@@ -29,6 +36,24 @@ class SpecificationAnalyzer(metaclass=ABCMeta):
if degree == 0:
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
def set_node_specifications(self):
raise NotImplementedError('Must implement upload in subclasses')
from setuptools import setup, find_packages
setup (
name='drip_planner2',
version='0.1',
packages=find_packages(),
setup(
name='drip_planner2',
version='0.1',
packages=find_packages(),
# Declare your packages' dependencies here, for eg:
install_requires=['matplotlib>=3.1.1'],
# Declare your packages' dependencies here, for eg:
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
# PyPI
author='S. Koulouzis',
author_email='',
# Fill in these to make your Egg ready for upload to
# PyPI
author='S. Koulouzis',
author_email='',
#summary = 'Just another Python package for the cheese shop',
url='',
license='',
long_description='Long description of the package',
# summary = 'Just another Python package for the cheese shop',
url='',
license='',
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):
def get_all_ancestors_types(child_node):
logging.info('child_node: ' + str(child_node.type))
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
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