Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
8760f131
Commit
8760f131
authored
Oct 21, 2019
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
set default properties
parent
bd92f9e9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
115 additions
and
39 deletions
+115
-39
workspace.xml
drip_planner2/.idea/workspace.xml
+27
-4
planner.py
drip_planner2/src/planner/planner.py
+12
-8
simple_spec_alayzer.py
drip_planner2/src/planner/simple_spec_alayzer.py
+62
-13
specification_analyzer.py
drip_planner2/src/planner/specification_analyzer.py
+6
-9
rpc_server.py
drip_planner2/src/rpc_server.py
+1
-1
tosca.py
drip_planner2/src/utils/tosca.py
+7
-4
No files found.
drip_planner2/.idea/workspace.xml
View file @
8760f131
...
...
@@ -205,7 +205,14 @@
<option
name=
"project"
value=
"LOCAL"
/>
<updated>
1571326903675
</updated>
</task>
<option
name=
"localTasksCounter"
value=
"13"
/>
<task
id=
"LOCAL-00013"
summary=
"added comments"
>
<created>
1571415019998
</created>
<option
name=
"number"
value=
"00013"
/>
<option
name=
"presentableId"
value=
"LOCAL-00013"
/>
<option
name=
"project"
value=
"LOCAL"
/>
<updated>
1571415019998
</updated>
</task>
<option
name=
"localTasksCounter"
value=
"14"
/>
<servers
/>
</component>
<component
name=
"Vcs.Log.Tabs.Properties"
>
...
...
@@ -233,7 +240,8 @@
<MESSAGE
value=
"try to analyze policies"
/>
<MESSAGE
value=
"added libs in setup"
/>
<MESSAGE
value=
"fixed invalid type"
/>
<option
name=
"LAST_COMMIT_MESSAGE"
value=
"fixed invalid type"
/>
<MESSAGE
value=
"added comments"
/>
<option
name=
"LAST_COMMIT_MESSAGE"
value=
"added comments"
/>
</component>
<component
name=
"XDebuggerManager"
>
<breakpoint-manager>
...
...
@@ -250,8 +258,23 @@
</line-breakpoint>
<line-breakpoint
enabled=
"true"
suspend=
"THREAD"
type=
"python-line"
>
<url>
file://$PROJECT_DIR$/src/planner/planner.py
</url>
<line>
69
</line>
<option
name=
"timeStamp"
value=
"211"
/>
<line>
173
</line>
<option
name=
"timeStamp"
value=
"218"
/>
</line-breakpoint>
<line-breakpoint
enabled=
"true"
suspend=
"THREAD"
type=
"python-line"
>
<url>
file://$PROJECT_DIR$/src/planner/simple_spec_alayzer.py
</url>
<line>
67
</line>
<option
name=
"timeStamp"
value=
"293"
/>
</line-breakpoint>
<line-breakpoint
enabled=
"true"
suspend=
"THREAD"
type=
"python-line"
>
<url>
file://$PROJECT_DIR$/src/planner/simple_spec_alayzer.py
</url>
<line>
68
</line>
<option
name=
"timeStamp"
value=
"294"
/>
</line-breakpoint>
<line-breakpoint
enabled=
"true"
suspend=
"THREAD"
type=
"python-line"
>
<url>
file://$PROJECT_DIR$/src/planner/simple_spec_alayzer.py
</url>
<line>
88
</line>
<option
name=
"timeStamp"
value=
"295"
/>
</line-breakpoint>
</breakpoints>
<default-breakpoints>
...
...
drip_planner2/src/planner/planner.py
View file @
8760f131
...
...
@@ -33,12 +33,17 @@ class Planner:
self
.
tosca_template
.
nodetemplates
.
append
(
node_template
)
return
self
.
tosca_template
def
set_infrastructure_specifications
(
self
,
required_nodes
):
def
set_infrastructure_specifications
(
self
):
# 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
(
self
.
tosca_template
,
required_nodes
)
required_nodes
=
specification_analyzer
.
set_node_specifications
()
return
required_nodes
specification_analyzer
=
SimpleAnalyzer
(
self
.
tosca_template
)
nodes_with_new_specifications
=
specification_analyzer
.
set_node_specifications
()
for
new_spec_node
in
nodes_with_new_specifications
:
logging
.
info
(
'new_spec_node.name : '
+
new_spec_node
.
name
)
for
index
,
node_in_temple
in
enumerate
(
self
.
tosca_template
.
nodetemplates
):
if
new_spec_node
.
name
==
node_in_temple
.
name
:
self
.
tosca_template
.
nodetemplates
[
index
]
=
new_spec_node
nodes_with_new_relationship_occurrences
=
specification_analyzer
.
set_relationship_occurrences
()
def
get_node_template_property
(
self
,
prop_key
,
node_prop_dict
):
prop_value
=
self
.
spec_service
.
get_property
(
prop_key
)
...
...
@@ -75,7 +80,6 @@ class Planner:
# Only add node that is not in node_templates
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
,
self
.
all_custom_def
)
# Add the requirements to the node we analyzed. e.g. docker needed host now we added the type and name of host
...
...
@@ -87,7 +91,7 @@ class Planner:
self
.
add_required_nodes
(
matching_node
)
def
get_all_requirements
(
self
,
node
):
"""Returns all requirements for an input node """
"""Returns all requirements for an input node
including all parents requirements
"""
node_type_name
=
tosca_util
.
get_node_type_name
(
node
)
logging
.
info
(
' Looking for requirements for node: '
+
node_type_name
)
...
...
@@ -166,8 +170,8 @@ class Planner:
logging
.
info
(
' Found: '
+
str
(
node_type
))
matching_nodes
.
update
(
capable_nodes
)
else
:
logging
.
error
(
'Did not find
node with required capability: '
+
str
(
req
[
key
][
'capability'
]
))
r
eturn
None
logging
.
error
(
'Did not find
any node with required capability: '
+
str
(
capability
))
r
aise
Exception
(
'Did not find any node with required capability: '
+
str
(
capability
))
# if we only found 1 return it
if
len
(
matching_nodes
)
==
1
:
return
matching_nodes
...
...
drip_planner2/src/planner/simple_spec_alayzer.py
View file @
8760f131
from
toscaparser.nodetemplate
import
NodeTemplate
from
toscaparser.properties
import
Property
from
src.utils
import
tosca
as
tosca_util
from
src.planner.specification_analyzer
import
SpecificationAnalyzer
import
networkx
as
nx
...
...
@@ -6,17 +9,22 @@ import logging
class
SimpleAnalyzer
(
SpecificationAnalyzer
):
def
__init__
(
self
,
tosca_template
,
required_nodes
):
super
(
SimpleAnalyzer
,
self
)
.
__init__
(
tosca_template
,
required_nodes
)
def
__init__
(
self
,
tosca_template
):
super
(
SimpleAnalyzer
,
self
)
.
__init__
(
tosca_template
)
def
set_relationship_occurrences
(
self
):
return
None
def
set_node_specifications
(
self
):
nodes_to_implement_policies
=
self
.
get_nodes_to_implement_policy
()
affected_nodes
=
[]
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
)
affected_node
=
self
.
set_specs
(
node_name
,
policies
,
self
.
tosca_template
.
nodetemplates
)
if
affected_node
:
affected_nodes
.
append
(
affected_node
)
return
self
.
requir
ed_nodes
return
affect
ed_nodes
def
get_nodes_to_implement_policy
(
self
):
nodes_to_implement_policies
=
{}
...
...
@@ -38,15 +46,32 @@ class SimpleAnalyzer(SpecificationAnalyzer):
logging
.
info
(
'Setting properties for: '
+
str
(
affected_node
.
type
))
ancestors_types
=
tosca_util
.
get_all_ancestors_types
(
affected_node
,
self
.
all_node_types
,
self
.
all_custom_def
)
if
'tosca.nodes.ARTICONF.Orchestrator'
in
ancestors_types
:
logging
.
info
(
'Do Something'
)
properties
=
tosca_util
.
get_all_ancestors_properties
(
affected_node
,
self
.
all_node_types
,
self
.
all_custom_def
)
for
node_property
in
properties
:
property_dict
=
{}
logging
.
info
(
'property: '
+
str
(
node_property
.
name
)
+
' val: '
+
str
(
node_property
.
value
))
# if 'tosca.nodes.ARTICONF.Orchestrator' in ancestors_types:
# logging.info('Do Something')
properties
=
tosca_util
.
get_all_ancestors_properties
(
affected_node
,
self
.
all_node_types
,
self
.
all_custom_def
)
return
affected_node
default_properties
=
{}
for
node_property
in
properties
:
default_property
=
self
.
get_defult_value
(
node_property
)
if
default_property
:
default_properties
[
next
(
iter
(
default_property
))]
=
default_property
[
next
(
iter
(
default_property
))]
if
default_properties
:
for
default_property
in
default_properties
:
affected_node
.
get_properties_objects
()
.
append
(
default_property
)
if
'properties'
not
in
affected_node
.
templates
[
next
(
iter
(
affected_node
.
templates
))]:
affected_node
.
templates
[
next
(
iter
(
affected_node
.
templates
))][
'properties'
]
=
default_properties
else
:
for
prop_name
in
affected_node
.
templates
[
next
(
iter
(
affected_node
.
templates
))][
'properties'
]:
if
'required'
in
affected_node
.
templates
[
next
(
iter
(
affected_node
.
templates
))][
'properties'
][
prop_name
]
and
'type'
in
affected_node
.
templates
[
next
(
iter
(
affected_node
.
templates
))][
'properties'
][
prop_name
]:
# del affected_node.templates[next(iter(affected_node.templates))]['properties'][prop_name]
affected_node
.
templates
[
next
(
iter
(
affected_node
.
templates
))][
'properties'
][
prop_name
]
=
None
affected_node
.
templates
[
next
(
iter
(
affected_node
.
templates
))][
'properties'
]
.
update
(
default_properties
)
return
affected_node
else
:
return
None
def
set_specs
(
self
,
node_name
,
policies
,
nodes_in_template
):
logging
.
info
(
'node_name: '
+
str
(
node_name
)
+
' will implement policies: '
+
str
(
len
(
policies
)))
...
...
@@ -59,3 +84,27 @@ class SimpleAnalyzer(SpecificationAnalyzer):
affected_node
=
self
.
set_node_properties_for_policy
(
affected_node
,
policies
)
return
affected_node
def
get_defult_value
(
self
,
node_property
):
if
isinstance
(
node_property
.
value
,
dict
)
and
'required'
in
node_property
.
value
and
'type'
in
node_property
.
value
:
if
node_property
.
value
[
'required'
]:
default_prop
=
{}
if
'default'
in
node_property
.
value
:
if
node_property
.
value
[
'type'
]
==
'integer'
:
default_prop
=
int
(
node_property
.
value
[
'default'
])
else
:
default_prop
=
str
(
node_property
.
value
[
'default'
])
elif
'constraints'
in
node_property
.
value
:
constraints
=
node_property
.
value
[
'constraints'
]
for
constraint
in
constraints
:
for
constraint_key
in
constraint
:
if
'equal'
in
constraint_key
:
if
node_property
.
value
[
'type'
]
==
'integer'
:
default_prop
=
int
(
constraint
[
constraint_key
])
else
:
default_prop
=
str
(
constraint
[
constraint_key
])
name
=
node_property
.
name
node_property
=
None
node_property
=
{
name
:
default_prop
}
return
node_property
return
None
drip_planner2/src/planner/specification_analyzer.py
View file @
8760f131
...
...
@@ -9,7 +9,7 @@ import matplotlib.pyplot as plt
class
SpecificationAnalyzer
(
metaclass
=
ABCMeta
):
def
__init__
(
self
,
tosca_template
,
required_nodes
):
def
__init__
(
self
,
tosca_template
):
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
...
...
@@ -18,14 +18,7 @@ class SpecificationAnalyzer(metaclass=ABCMeta):
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
.
all_custom_def
)
self
.
nodes_in_template
.
append
(
node_template
)
self
.
nodes_in_template
+=
self
.
tosca_template
.
nodetemplates
self
.
g
=
self
.
build_graph
(
self
.
nodes_in_template
)
self
.
g
=
self
.
build_graph
(
self
.
tosca_template
.
nodetemplates
)
self
.
root_nodes
=
[]
self
.
leaf_nodes
=
[]
...
...
@@ -57,3 +50,7 @@ class SpecificationAnalyzer(metaclass=ABCMeta):
@
abstractmethod
def
set_node_specifications
(
self
):
raise
NotImplementedError
(
'Must implement upload in subclasses'
)
@
abstractmethod
def
set_relationship_occurrences
(
self
):
raise
NotImplementedError
(
'Must implement upload in subclasses'
)
drip_planner2/src/rpc_server.py
View file @
8760f131
...
...
@@ -114,8 +114,8 @@ if __name__ == "__main__":
spec_service
=
SpecService
(
conf
)
test_planner
=
Planner
(
tosca_file_path
,
spec_service
)
test_planner_required_nodes
=
test_planner
.
resolve_requirements
()
test_planner_required_nodes
=
test_planner
.
set_infrastructure_specifications
(
test_planner_required_nodes
)
test_planner
.
add_required_nodes_to_template
(
test_planner_required_nodes
)
test_planner_required_nodes
=
test_planner
.
set_infrastructure_specifications
()
template
=
tosca_util
.
get_tosca_template_2_topology_template
(
test_planner
.
tosca_template
)
logger
.
info
(
"template ----:
\n
"
+
template
)
else
:
...
...
drip_planner2/src/utils/tosca.py
View file @
8760f131
...
...
@@ -166,7 +166,7 @@ def get_all_ancestors_types(child_node, all_nodes, all_custom_def, ancestors_typ
if
parent_type
:
ancestors_types
.
append
(
parent_type
)
parent_type
=
node_type_2_node_template
({
'name'
:
all_nodes
[
parent_type
]},
all_custom_def
)
get_all_ancestors_types
(
parent_type
,
all_nodes
,
all_custom_def
,
ancestors_types
)
get_all_ancestors_types
(
parent_type
,
all_nodes
,
all_custom_def
,
ancestors_types
)
return
ancestors_types
...
...
@@ -174,16 +174,19 @@ def get_all_ancestors_properties(node, all_nodes, all_custom_def, ancestors_prop
if
not
ancestors_properties
:
ancestors_properties
=
[]
ancestors_properties_names
=
[]
node_prop_names
=
[]
if
node
.
get_properties_objects
():
ancestors_properties
.
extend
(
node
.
get_properties_objects
())
for
node_prop
in
node
.
get_properties_objects
():
node_prop_names
.
append
(
node_prop
.
name
)
ancestors_properties
.
append
(
node_prop
)
if
not
ancestors_types
:
ancestors_types
=
get_all_ancestors_types
(
node
,
all_nodes
,
all_custom_def
)
ancestors_types
=
get_all_ancestors_types
(
node
,
all_nodes
,
all_custom_def
)
for
ancestors_type
in
ancestors_types
:
ancestor
=
node_type_2_node_template
({
'name'
:
all_nodes
[
ancestors_type
]},
all_custom_def
)
if
ancestor
.
get_properties_objects
():
for
ancestor_prop
in
ancestor
.
get_properties_objects
():
if
ancestor_prop
.
name
not
in
ancestors_properties_names
:
if
ancestor_prop
.
name
not
in
ancestors_properties_names
and
ancestor_prop
.
name
not
in
node_prop_names
:
ancestors_properties_names
.
append
(
ancestor_prop
.
name
)
ancestors_properties
.
append
(
ancestor_prop
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment