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
04c7719b
Commit
04c7719b
authored
Jun 13, 2019
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
match capabilities with requirements
parent
1fa55427
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
11 deletions
+25
-11
winery_planner.py
drip_planner2/src/planner/winery_planner.py
+25
-11
No files found.
drip_planner2/src/planner/winery_planner.py
View file @
04c7719b
...
@@ -123,10 +123,15 @@ class WineryPlanner:
...
@@ -123,10 +123,15 @@ class WineryPlanner:
def
get_condiate_nodes
(
self
,
unmet_requirements
):
def
get_condiate_nodes
(
self
,
unmet_requirements
):
for
node_name
in
unmet_requirements
:
for
node_name
in
unmet_requirements
:
node_types
=
self
.
get_node_types_with_capability
(
unmet_requirements
[
node_name
])
node_types
=
self
.
get_node_types_with_capability
(
unmet_requirements
[
node_name
])
print
(
unmet_requirements
[
node_name
])
#
print(unmet_requirements[node_name])
def
get_node_types_with_capability
(
self
,
capability
):
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
:
if
not
self
.
all_node_types
:
servicetemplate_url
=
self
.
tosca_reposetory_api_base_url
+
"/nodetypes/"
servicetemplate_url
=
self
.
tosca_reposetory_api_base_url
+
"/nodetypes/"
header
=
{
'accept'
:
'application/json'
}
header
=
{
'accept'
:
'application/json'
}
...
@@ -135,8 +140,17 @@ class WineryPlanner:
...
@@ -135,8 +140,17 @@ class WineryPlanner:
res_body
=
res
.
read
()
res_body
=
res
.
read
()
self
.
all_node_types
=
json
.
loads
(
res_body
.
decode
(
"utf-8"
))
self
.
all_node_types
=
json
.
loads
(
res_body
.
decode
(
"utf-8"
))
for
node
in
self
.
all_node_types
:
for
node
in
self
.
all_node_types
:
self
.
all_node_types
(
node
[
'id'
])
# print(node['qName'])
print
(
node
[
'id'
])
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
:
print
(
cap_id
+
" matches "
+
req_id
)
def
get_all_relationships
(
self
,
dict_tpl
):
def
get_all_relationships
(
self
,
dict_tpl
):
...
@@ -149,13 +163,13 @@ class WineryPlanner:
...
@@ -149,13 +163,13 @@ class WineryPlanner:
all_relationships
.
append
(
rel
)
all_relationships
.
append
(
rel
)
return
all_relationships
return
all_relationships
def
get_super_types
(
self
,
component_typ
e
,
supertypes
):
def
get_super_types
(
self
,
type_qNam
e
,
supertypes
):
if
(
supertypes
==
None
):
if
(
supertypes
==
None
):
supertypes
=
[]
supertypes
=
[]
regex
=
r"\{(.*?)\}"
regex
=
r"\{(.*?)\}"
matches
=
re
.
finditer
(
regex
,
component_typ
e
,
re
.
MULTILINE
|
re
.
DOTALL
)
matches
=
re
.
finditer
(
regex
,
type_qNam
e
,
re
.
MULTILINE
|
re
.
DOTALL
)
namespace
=
next
(
matches
)
.
group
(
1
)
namespace
=
next
(
matches
)
.
group
(
1
)
id
=
component_typ
e
.
replace
(
"{"
+
namespace
+
"}"
,
""
)
id
=
type_qNam
e
.
replace
(
"{"
+
namespace
+
"}"
,
""
)
header
=
{
'accept'
:
'application/json'
}
header
=
{
'accept'
:
'application/json'
}
#winery needs it double percent-encoded
#winery needs it double percent-encoded
encoded_namespace
=
urllib
.
parse
.
quote
(
namespace
,
safe
=
''
)
encoded_namespace
=
urllib
.
parse
.
quote
(
namespace
,
safe
=
''
)
...
@@ -175,13 +189,13 @@ class WineryPlanner:
...
@@ -175,13 +189,13 @@ class WineryPlanner:
return
supertypes
return
supertypes
def
get_super_types_requirements
(
self
,
component_typ
e
,
requirements
):
def
get_super_types_requirements
(
self
,
type_qNam
e
,
requirements
):
if
(
requirements
==
None
):
if
(
requirements
==
None
):
requirements
=
[]
requirements
=
[]
regex
=
r"\{(.*?)\}"
regex
=
r"\{(.*?)\}"
matches
=
re
.
finditer
(
regex
,
component_typ
e
,
re
.
MULTILINE
|
re
.
DOTALL
)
matches
=
re
.
finditer
(
regex
,
type_qNam
e
,
re
.
MULTILINE
|
re
.
DOTALL
)
namespace
=
next
(
matches
)
.
group
(
1
)
namespace
=
next
(
matches
)
.
group
(
1
)
id
=
component_typ
e
.
replace
(
"{"
+
namespace
+
"}"
,
""
)
id
=
type_qNam
e
.
replace
(
"{"
+
namespace
+
"}"
,
""
)
header
=
{
'accept'
:
'application/json'
}
header
=
{
'accept'
:
'application/json'
}
#winery needs it double percent-encoded
#winery needs it double percent-encoded
encoded_namespace
=
urllib
.
parse
.
quote
(
namespace
,
safe
=
''
)
encoded_namespace
=
urllib
.
parse
.
quote
(
namespace
,
safe
=
''
)
...
...
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