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
0e9b7d25
Commit
0e9b7d25
authored
Jul 01, 2019
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
find missing requirements
parent
311272e2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
143 deletions
+30
-143
application_example.yaml
TOSCA/application_example.yaml
+2
-1
nodes.yaml
TOSCA/types/nodes.yaml
+2
-6
basic_planner.py
drip_planner2/src/planner/basic_planner.py
+26
-136
No files found.
TOSCA/application_example.yaml
View file @
0e9b7d25
...
...
@@ -14,8 +14,9 @@ topology_template:
requirements
:
-
service
:
node
:
mysql
relationship
:
relationship
:
type
:
tosca.relationships.ConnectsTo
#type: tosca.relationships.DependsOn
artifacts
:
my_image
:
file
:
wordpress:latest
...
...
TOSCA/types/nodes.yaml
View file @
0e9b7d25
...
...
@@ -3,7 +3,7 @@ tosca_definitions_version: tosca_simple_yaml_1_0
node_types
:
tosca.nodes.SWITCH.Container.Application.Docker
:
derived_from
:
tosca.nodes.Container.Application.Docker
#
derived_from: tosca.nodes.Container.Application.Docker
description
:
description of container
capabilities
:
service
:
...
...
@@ -30,11 +30,7 @@ node_types:
type
:
list
required
:
false
requirements
:
-
service
:
capability
:
tosca.capabilities.Container.Docker
node
:
tosca.nodes.SWITCH.Container.Application.Docker
relationship
:
tosca.relationships.ConnectsTo
-
host
:
capability
:
tosca.capabilities.Compute
node
:
tosca.nodes.Compute
relationship
:
tosca.relationships.HostedOn
relationship
:
tosca.relationships.HostedOn
drip_planner2/src/planner/basic_planner.py
View file @
0e9b7d25
...
...
@@ -4,6 +4,8 @@ import pdb
import
re
from
toscaparser.tosca_template
import
ToscaTemplate
from
toscaparser.topology_template
import
TopologyTemplate
from
toscaparser.elements.nodetype
import
NodeType
from
toscaparser.nodetemplate
import
NodeTemplate
import
toscaparser.utils.yamlparser
import
urllib
import
urllib.parse
...
...
@@ -17,147 +19,35 @@ class BasicPlanner:
def
__init__
(
self
,
path
):
self
.
template
=
ToscaTemplate
(
path
)
print
(
"Description:"
+
self
.
template
.
description
)
for
node
in
self
.
template
.
nodetemplates
:
print
(
"Node: "
+
node
.
name
+
" Type:"
+
node
.
type
+
" Req: "
+
str
(
node
.
requirements
))
missing_requirements
=
self
.
get_missing_requirements
(
node
)
for
req
in
missing_requirements
:
node
.
requirements
.
append
(
req
)
print
(
'----------------------'
)
# print(node.get_properties().keys())
# print(node.get_capabilities().keys)
def
target_meets_requirement
(
self
,
target_relationship_element
,
requirement
):
node
=
self
.
get_node
(
target_relationship_element
)
supertypes
=
self
.
get_super_types
(
node
[
'type'
],
None
)
for
node_type
in
supertypes
:
if
'capabilityDefinitions'
in
node_type
:
for
cap
in
node_type
[
'capabilityDefinitions'
][
'capabilityDefinition'
]:
if
cap
[
'capabilityType'
]
==
requirement
:
return
True
return
False
def
get_relationship_of_source_node
(
self
,
source_id
,
relationships
):
for
rel
in
relationships
:
if
(
rel
[
'sourceElement'
][
'ref'
]
==
source_id
):
return
rel
def
get_node
(
self
,
node_type_id
):
for
node
in
self
.
node_templates
:
if
node
[
'id'
]
==
node_type_id
:
return
node
def
get_all_requirements
(
self
,
node_templates
):
requirements
=
{}
for
node_template_name
in
node_templates
:
node_template
=
node_templates
[
node_template_name
]
node_type
=
node_template
[
'type'
]
if
'requirements'
in
node_template
:
requirements
[
node_template_name
]
=
node_template
[
'requirements'
]
self
.
get_super_types_requirements
(
node_type
,
None
)
# id = node_template['id']
# req = self.get_requirements(node_template)
# if(req):
# for r in req['requirement']:
# all_requirements.append(r['type'])
# self.requirements[id] = all_requirements
def
get_unmet_requirements
(
self
,
requirements
,
relationships
):
unmet_requirements
=
{}
for
node_name
in
requirements
:
relationship
=
self
.
get_relationship_of_source_node
(
node_name
,
relationships
)
if
relationship
:
for
requirement
in
requirements
[
node_name
]:
if
(
not
self
.
target_meets_requirement
(
relationship
[
'targetElement'
][
'ref'
],
requirement
)):
unmet_requirements
[
node_name
]
=
requirement
else
:
for
requirement
in
requirements
[
node_name
]:
unmet_requirements
[
node_name
]
=
requirement
return
unmet_requirements
def
get_condiate_nodes
(
self
,
unmet_requirements
):
condiate_nodes
=
[]
for
node_name
in
unmet_requirements
:
node_types
=
self
.
get_node_types_with_capability
(
unmet_requirements
[
node_name
])
print
(
node_types
)
def
get_node_types_with_capability
(
self
,
requirement_qname
):
regex
=
r"\{(.*?)\}"
matches
=
re
.
finditer
(
regex
,
requirement_qname
,
re
.
MULTILINE
|
re
.
DOTALL
)
namespace
=
next
(
matches
)
.
group
(
1
)
req_id
=
requirement_qname
.
replace
(
"{"
+
namespace
+
"}"
,
""
)
if
not
self
.
all_node_types
:
servicetemplate_url
=
self
.
tosca_reposetory_api_base_url
+
"/nodetypes/"
header
=
{
'accept'
:
'application/json'
}
req
=
urllib
.
request
.
Request
(
url
=
servicetemplate_url
,
headers
=
header
,
method
=
'GET'
)
res
=
urllib
.
request
.
urlopen
(
req
,
timeout
=
5
)
res_body
=
res
.
read
()
self
.
all_node_types
=
json
.
loads
(
res_body
.
decode
(
"utf-8"
))
matching_nodes
=
{}
for
node
in
self
.
all_node_types
:
supertypes
=
self
.
get_super_types
(
node
[
'qName'
],
None
)
for
node
in
supertypes
:
if
'capabilityDefinitions'
in
node
:
for
cap
in
node
[
'capabilityDefinitions'
][
'capabilityDefinition'
]:
cap_qname
=
cap
[
'capabilityType'
]
cap_matches
=
re
.
finditer
(
regex
,
cap_qname
,
re
.
MULTILINE
|
re
.
DOTALL
)
namespace
=
next
(
cap_matches
)
.
group
(
1
)
cap_id
=
cap_qname
.
replace
(
"{"
+
namespace
+
"}"
,
""
)
if
cap_id
==
req_id
and
node
[
'name'
]
not
in
matching_nodes
:
matching_nodes
[
node
[
'name'
]]
=
node
def
get_missing_requirements
(
self
,
node
):
def_type
=
self
.
template
.
_get_all_custom_defs
()[
node
.
type
]
def_requirements
=
def_type
[
'requirements'
]
missing_requirements
=
[]
if
not
node
.
requirements
:
missing_requirements
=
def_requirements
else
:
for
def_requirement
in
def_requirements
:
for
key
in
def_requirement
:
for
node_req
in
node
.
requirements
:
if
key
not
in
(
node_req
):
missing_requirements
.
append
(
def_requirement
)
break
return
matching_nodes
.
values
()
def
get_all_relationships
(
self
,
dict_tpl
):
all_relationships
=
[]
service_templates
=
self
.
get_service_template
(
dict_tpl
)
for
service
in
service_templates
:
topology_template
=
self
.
get_topology_template
(
service
)
relationships
=
self
.
get_relationships
(
topology_template
)
for
rel
in
relationships
:
all_relationships
.
append
(
rel
)
return
all_relationships
def
get_super_types
(
self
,
type
,
supertypes
):
print
(
type
)
def
get_super_types_requirements
(
self
,
node_type
,
requirements
):
print
(
node_type
)
def
get_service_template
(
self
,
dict_tpl
):
if
(
not
self
.
service_templates
):
self
.
service_templates
=
self
.
find
(
dict_tpl
,
self
.
service_template_names
)
return
self
.
service_templates
def
get_topology_template
(
self
,
dict_tpl
):
if
(
not
self
.
topology_templates
):
self
.
topology_templates
=
self
.
find
(
dict_tpl
,
self
.
topology_template_names
)
return
self
.
topology_templates
def
get_node_templates
(
self
,
dict_tpl
):
if
(
not
self
.
node_templates
):
self
.
node_templates
=
self
.
find
(
dict_tpl
,
self
.
node_template_names
)
return
self
.
node_templates
def
get_requirements
(
self
,
dict_tpl
):
return
self
.
find
(
dict_tpl
,
self
.
requirement_names
)
def
get_relationships
(
self
,
dict_tpl
):
return
self
.
find
(
dict_tpl
,
self
.
relationships_names
)
def
get_requirement_type
(
self
,
dict_req
):
return
self
.
find
(
dict_req
,
self
.
type_names
)
def
find
(
self
,
dict_tpl
,
names
):
if
dict_tpl
:
for
name
in
names
:
if
(
name
in
dict_tpl
):
return
dict_tpl
[
name
]
\ No newline at end of file
if
node
.
parent_type
:
missing_requirements
=
missing_requirements
+
node
.
parent_type
.
requirements
return
missing_requirements
\ No newline at end of file
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