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
493da3df
Commit
493da3df
authored
Jul 09, 2019
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adds missing nodes. But we miss on node (wordpress) from the initial template
parent
69b3d53d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
39 deletions
+81
-39
application_example.yaml
TOSCA/application_example.yaml
+1
-7
basic_planner.py
drip_planner2/src/planner/basic_planner.py
+77
-31
rpc_server.py
drip_planner2/src/rpc_server.py
+2
-0
TOSCA_parser.py
drip_planner2/src/utils/TOSCA_parser.py
+1
-1
No files found.
TOSCA/application_example.yaml
View file @
493da3df
...
@@ -48,12 +48,6 @@ topology_template:
...
@@ -48,12 +48,6 @@ topology_template:
file
:
mysql:5.7
file
:
mysql:5.7
repository
:
docker_hub
repository
:
docker_hub
#guillermo_kubernetes:
#type: tosca.nodes.ARTICONF.Orchestrator.Kubernetes
#cluster:
#type: tosca.nodes.Compute
...
...
drip_planner2/src/planner/basic_planner.py
View file @
493da3df
...
@@ -14,6 +14,7 @@ import pdb
...
@@ -14,6 +14,7 @@ import pdb
import
names
import
names
import
yaml
import
yaml
from
utils.TOSCA_parser
import
*
from
utils.TOSCA_parser
import
*
import
logging
...
@@ -29,53 +30,63 @@ class BasicPlanner:
...
@@ -29,53 +30,63 @@ class BasicPlanner:
self
.
all_nodes
.
update
(
self
.
all_custom_def
.
items
())
self
.
all_nodes
.
update
(
self
.
all_custom_def
.
items
())
node_templates
=
[]
capable_node_name
=
''
for
node
in
self
.
template
.
nodetemplates
:
missing_requirements
=
self
.
get_missing_requirements
(
node
)
for
req
in
missing_requirements
:
for
key
in
req
:
capable_node
=
self
.
get_node_types_by_capability
(
req
[
key
][
'capability'
])
capable_node_type
=
next
(
iter
(
capable_node
))
if
self
.
node_requered_once
(
capable_node
)
and
not
self
.
contains_node_type
(
node_templates
,
capable_node_type
):
capable_node_template
=
self
.
node_type_2_node_template
(
capable_node
)
capable_node_name
=
capable_node_template
.
name
node_templates
.
append
(
capable_node_template
)
req
[
next
(
iter
(
req
))][
'node'
]
=
capable_node_name
node
.
requirements
.
append
(
req
)
node_templates
.
append
(
node
)
# capable_node_name = ''
for
node
in
self
.
template
.
nodetemplates
:
node_templates
=
self
.
add_reqired_nods
(
node
,
None
)
# missing_requirements = self.get_missing_requirements(node)
# for req in missing_requirements:
# for key in req:
# capable_node = self.get_node_types_by_capability(req[key]['capability'])
# capable_node_type = next(iter(capable_node))
#
# if self.node_requered_once(capable_node) and not self.contains_node_type(node_templates,capable_node_type):
# capable_node_template = self.node_type_2_node_template(capable_node)
# capable_node_name = capable_node_template.name
# node_templates.append(capable_node_template)
#
# req[next(iter(req))]['node'] = capable_node_name
# node.requirements.append(req)
# node_templates.append(node)
if
node_templates
:
self
.
template
.
nodetemplates
=
node_templates
self
.
template
.
nodetemplates
=
node_templates
t
=
self
.
template
else
:
logging
.
info
(
'The TOSCA template in: '
+
path
+
' has no requirements'
)
tp
=
TOSCAParser
()
tp
=
TOSCAParser
()
tp
.
tosca_template2_yaml
(
t
)
yaml_str
=
tp
.
tosca_template2_yaml
(
self
.
template
)
logging
.
info
(
'TOSCA template:
\n
'
+
yaml_str
)
print
(
'------------------'
)
# print(yaml_str)
# print(node.get_capabilities().keys)
def
get_missing_requirements
(
self
,
node
):
def
get_missing_requirements
(
self
,
node
):
logging
.
info
(
'Looking for requirements for node: '
+
node
.
name
)
def_type
=
self
.
all_nodes
[
node
.
type
]
def_type
=
self
.
all_nodes
[
node
.
type
]
def_requirements
=
[]
if
'requirements'
in
def_type
.
keys
():
def_requirements
=
def_type
[
'requirements'
]
def_requirements
=
def_type
[
'requirements'
]
logging
.
info
(
'Found requirements: '
+
str
(
def_requirements
)
+
' for node: '
+
node
.
name
)
missing_requirements
=
[]
missing_requirements
=
[]
if
not
node
.
requirements
:
if
not
node
.
requirements
:
missing_requirements
=
def_requirements
missing_requirements
=
def_requirements
el
se
:
el
if
def_requirements
:
for
def_requirement
in
def_requirements
:
for
def_requirement
in
def_requirements
:
for
key
in
def_requirement
:
for
key
in
def_requirement
:
for
node_req
in
node
.
requirements
:
for
node_req
in
node
.
requirements
:
if
key
not
in
(
node_req
)
:
if
key
not
in
node_req
:
missing_requirements
.
append
(
def_requirement
)
missing_requirements
.
append
(
def_requirement
)
break
if
node
.
parent_type
:
#Make sure we have the deffinition. Otherwise we get an error in the recursion
if
'derived_from'
in
def_type
.
keys
()
and
not
def_type
[
'derived_from'
]
in
node
.
custom_def
.
keys
():
node
.
custom_def
[
def_type
[
'derived_from'
]]
=
self
.
all_custom_def
[
def_type
[
'derived_from'
]]
if
node
.
parent_type
and
node
.
parent_type
.
requirements
:
logging
.
info
(
'Adding to : '
+
str
(
node
.
name
)
+
' parent requirements from: '
+
str
(
node
.
parent_type
.
type
))
missing_requirements
=
missing_requirements
+
node
.
parent_type
.
requirements
missing_requirements
=
missing_requirements
+
node
.
parent_type
.
requirements
return
missing_requirements
return
missing_requirements
...
@@ -129,6 +140,8 @@ class BasicPlanner:
...
@@ -129,6 +140,8 @@ class BasicPlanner:
def
contains_node_type
(
self
,
capable_node_types_list
,
node_type
):
def
contains_node_type
(
self
,
capable_node_types_list
,
node_type
):
if
capable_node_types_list
==
None
:
return
False
for
capable_node_type
in
capable_node_types_list
:
for
capable_node_type
in
capable_node_types_list
:
if
isinstance
(
capable_node_type
,
NodeTemplate
):
if
isinstance
(
capable_node_type
,
NodeTemplate
):
type_name
=
capable_node_type
.
type
type_name
=
capable_node_type
.
type
...
@@ -167,3 +180,36 @@ class BasicPlanner:
...
@@ -167,3 +180,36 @@ class BasicPlanner:
if
self
.
has_capability_max_one_occurrence
(
capabilities
[
cap
]):
if
self
.
has_capability_max_one_occurrence
(
capabilities
[
cap
]):
return
True
return
True
return
False
return
False
def
add_reqired_nods
(
self
,
node
,
node_templates
):
if
not
node_templates
:
node_templates
=
[]
missing_requirements
=
self
.
get_missing_requirements
(
node
)
if
not
missing_requirements
:
logging
.
info
(
'Node: '
+
node
.
name
+
' of type: '
+
node
.
type
+
' has no requirements'
)
# return node_templates
capable_node_name
=
''
for
req
in
missing_requirements
:
for
key
in
req
:
logging
.
info
(
'Looking for capability: '
+
req
[
key
][
'capability'
]
+
' for node: '
+
node
.
name
)
capable_node
=
self
.
get_node_types_by_capability
(
req
[
key
][
'capability'
])
if
capable_node
:
capable_node_type
=
next
(
iter
(
capable_node
))
logging
.
info
(
'Found : '
+
str
(
capable_node_type
))
else
:
logging
.
error
(
'Did not find node with reuired capability: '
+
str
(
req
[
key
][
'capability'
]))
if
self
.
node_requered_once
(
capable_node
)
and
not
self
.
contains_node_type
(
node_templates
,
capable_node_type
):
capable_node_template
=
self
.
node_type_2_node_template
(
capable_node
)
capable_node_name
=
capable_node_template
.
name
node_templates
.
append
(
capable_node_template
)
#recursively fulfill all requirements
self
.
add_reqired_nods
(
capable_node_template
,
node_templates
)
req
[
next
(
iter
(
req
))][
'node'
]
=
capable_node_name
node
.
requirements
.
append
(
req
)
if
not
self
.
contains_node_type
(
node_templates
,
node
):
node_templates
.
append
(
node
)
return
node_templates
\ No newline at end of file
drip_planner2/src/rpc_server.py
View file @
493da3df
...
@@ -13,6 +13,7 @@ from planner.basic_planner import *
...
@@ -13,6 +13,7 @@ from planner.basic_planner import *
import
sys
import
sys
import
tempfile
import
tempfile
import
time
import
time
import
logging
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -111,6 +112,7 @@ def handle_delivery(message):
...
@@ -111,6 +112,7 @@ def handle_delivery(message):
return
json
.
dumps
(
response
)
return
json
.
dumps
(
response
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
logging
.
basicConfig
(
level
=
logging
.
INFO
)
if
(
sys
.
argv
[
1
]
==
"test_local"
):
if
(
sys
.
argv
[
1
]
==
"test_local"
):
# home = expanduser("~")
# home = expanduser("~")
# tosca_reposetory_api_base_url = "http://localhost:8080/winery"
# tosca_reposetory_api_base_url = "http://localhost:8080/winery"
...
...
drip_planner2/src/utils/TOSCA_parser.py
View file @
493da3df
...
@@ -49,7 +49,7 @@ class TOSCAParser:
...
@@ -49,7 +49,7 @@ class TOSCAParser:
# If we don't add this then dump uses references for the same dictionary entries i.e. '&id001'
# If we don't add this then dump uses references for the same dictionary entries i.e. '&id001'
yaml
.
Dumper
.
ignore_aliases
=
lambda
*
args
:
True
yaml
.
Dumper
.
ignore_aliases
=
lambda
*
args
:
True
print
(
yaml
.
dump
(
topology_dict
,
default_flow_style
=
False
))
return
(
yaml
.
dump
(
topology_dict
,
default_flow_style
=
False
))
def
get_node_template_dict
(
self
,
node_template
):
def
get_node_template_dict
(
self
,
node_template
):
...
...
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