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
1fa55427
Commit
1fa55427
authored
Jun 12, 2019
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
try to query nodes with capabilities
parent
0e54d79b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
23 deletions
+47
-23
winery_planner.py
drip_planner2/src/planner/winery_planner.py
+47
-23
No files found.
drip_planner2/src/planner/winery_planner.py
View file @
1fa55427
...
@@ -19,6 +19,7 @@ class WineryPlanner:
...
@@ -19,6 +19,7 @@ class WineryPlanner:
topology_templates
=
None
topology_templates
=
None
node_templates
=
None
node_templates
=
None
requirements
=
{}
requirements
=
{}
all_node_types
=
[]
def
__init__
(
self
,
tosca_reposetory_api_base_url
,
namespace
,
servicetemplate_id
):
def
__init__
(
self
,
tosca_reposetory_api_base_url
,
namespace
,
servicetemplate_id
):
# dict_tpl = self.load_file(service_templaete_file_path)
# dict_tpl = self.load_file(service_templaete_file_path)
...
@@ -33,17 +34,11 @@ class WineryPlanner:
...
@@ -33,17 +34,11 @@ class WineryPlanner:
service_templates
=
self
.
get_service_template
(
dict_tpl
)
service_templates
=
self
.
get_service_template
(
dict_tpl
)
requirements
=
self
.
get_all_requirements
(
service_templates
)
requirements
=
self
.
get_all_requirements
(
service_templates
)
relationships
=
self
.
get_all_relationships
(
dict_tpl
)
relationships
=
self
.
get_all_relationships
(
dict_tpl
)
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
# unmet_requirements = self.get_unmet_requirements(requirements)
unmet_requirements
=
self
.
get_unmet_requirements
(
requirements
,
relationships
)
# print(unmet_requirements)
# yaml_dict_tpl = self.trnsform_to_tosca(yaml_dict_tpl)
condiate_nodes
=
self
.
get_condiate_nodes
(
unmet_requirements
)
...
@@ -74,13 +69,14 @@ class WineryPlanner:
...
@@ -74,13 +69,14 @@ class WineryPlanner:
def
target_meets_requirement
(
self
,
target_relationship_element
,
requirement
):
def
target_meets_requirement
(
self
,
target_relationship_element
,
requirement
):
node
=
self
.
get_node
(
target_relationship_element
)
node
=
self
.
get_node
(
target_relationship_element
)
print
(
node
)
if
'capabilities'
in
node
:
print
(
'dddddddddddd'
)
else
:
supertypes
=
self
.
get_super_types
(
node
[
'type'
],
None
)
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
# print(supertypes)
return
False
def
get_relationship_of_source_node
(
self
,
source_id
,
relationships
):
def
get_relationship_of_source_node
(
self
,
source_id
,
relationships
):
for
rel
in
relationships
:
for
rel
in
relationships
:
...
@@ -110,10 +106,38 @@ class WineryPlanner:
...
@@ -110,10 +106,38 @@ class WineryPlanner:
return
self
.
requirements
return
self
.
requirements
def
get_unmet_requirements
(
self
,
requirements
):
def
get_unmet_requirements
(
self
,
requirements
,
relationships
):
for
requirement
in
requirements
:
unmet_requirements
=
{}
requirement_type
=
self
.
get_requirement_type
(
requirement
)
for
node_name
in
requirements
:
print
(
requirement_type
)
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
):
for
node_name
in
unmet_requirements
:
node_types
=
self
.
get_node_types_with_capability
(
unmet_requirements
[
node_name
])
print
(
unmet_requirements
[
node_name
])
def
get_node_types_with_capability
(
self
,
capability
):
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"
))
for
node
in
self
.
all_node_types
:
self
.
all_node_types
(
node
[
'id'
])
print
(
node
[
'id'
])
def
get_all_relationships
(
self
,
dict_tpl
):
def
get_all_relationships
(
self
,
dict_tpl
):
all_relationships
=
[]
all_relationships
=
[]
...
@@ -175,7 +199,7 @@ class WineryPlanner:
...
@@ -175,7 +199,7 @@ class WineryPlanner:
for
req
in
c
[
'requirementDefinitions'
][
'requirementDefinition'
]:
for
req
in
c
[
'requirementDefinitions'
][
'requirementDefinition'
]:
requirements
.
append
(
req
[
'requirementType'
])
requirements
.
append
(
req
[
'requirementType'
])
if
'derivedFrom'
in
c
and
c
[
'derivedFrom'
]
and
c
[
'derivedFrom'
][
'type'
]:
if
'derivedFrom'
in
c
and
c
[
'derivedFrom'
]
and
c
[
'derivedFrom'
][
'type'
]:
self
.
get_super_types_requirements
(
c
[
'derivedFrom'
][
'type'
],
requirements
)
return
self
.
get_super_types_requirements
(
c
[
'derivedFrom'
][
'type'
],
requirements
)
return
requirements
return
requirements
...
...
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