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
Hide 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,20 +123,34 @@ class WineryPlanner:
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
])
#
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
:
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"
))
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'
])
# print(node['qName'])
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
):
...
...
@@ -149,13 +163,13 @@ class WineryPlanner:
all_relationships
.
append
(
rel
)
return
all_relationships
def
get_super_types
(
self
,
component_typ
e
,
supertypes
):
def
get_super_types
(
self
,
type_qNam
e
,
supertypes
):
if
(
supertypes
==
None
):
supertypes
=
[]
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
)
id
=
component_typ
e
.
replace
(
"{"
+
namespace
+
"}"
,
""
)
id
=
type_qNam
e
.
replace
(
"{"
+
namespace
+
"}"
,
""
)
header
=
{
'accept'
:
'application/json'
}
#winery needs it double percent-encoded
encoded_namespace
=
urllib
.
parse
.
quote
(
namespace
,
safe
=
''
)
...
...
@@ -175,13 +189,13 @@ class WineryPlanner:
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
):
requirements
=
[]
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
)
id
=
component_typ
e
.
replace
(
"{"
+
namespace
+
"}"
,
""
)
id
=
type_qNam
e
.
replace
(
"{"
+
namespace
+
"}"
,
""
)
header
=
{
'accept'
:
'application/json'
}
#winery needs it double percent-encoded
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