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
9b8e13e4
Commit
9b8e13e4
authored
Apr 18, 2019
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
analyze requirements
parent
bf40680e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
24 deletions
+96
-24
dum_planner.cpython-36.pyc
...anner2/src/planner/__pycache__/dum_planner.cpython-36.pyc
+0
-0
dum_planner.py
drip_planner2/src/planner/dum_planner.py
+91
-23
rpc_server.py
drip_planner2/src/rpc_server.py
+5
-1
No files found.
drip_planner2/src/planner/__pycache__/dum_planner.cpython-36.pyc
View file @
9b8e13e4
No preview for this file type
drip_planner2/src/planner/dum_planner.py
View file @
9b8e13e4
...
...
@@ -3,6 +3,8 @@ import toscaparser.utils.yamlparser
import
re
import
operator
import
json
import
urllib
import
urllib.parse
class
DumpPlanner
:
...
...
@@ -11,13 +13,29 @@ class DumpPlanner:
node_template_names
=
[
'nodeTemplates'
]
requirement_names
=
[
'requirements'
]
type_names
=
[
'type'
]
relationships_names
=
[
'relationshipTemplates'
]
service_templates
=
None
topology_templates
=
None
node_templates
=
None
requirements
=
{}
def
__init__
(
self
,
tosca_reposetory_api_base_url
,
namespace
,
servicetemplate_id
):
# dict_tpl = self.load_file(service_templaete_file_path)
self
.
tosca_reposetory_api_base_url
=
tosca_reposetory_api_base_url
servicetemplate_url
=
tosca_reposetory_api_base_url
+
"/servicetemplates/"
+
namespace
+
"/"
+
servicetemplate_id
+
"/"
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
()
dict_tpl
=
json
.
loads
(
res_body
.
decode
(
"utf-8"
))
def
__init__
(
self
,
service_templaete_file_path
):
dict_tpl
=
self
.
load_file
(
service_templaete_file_path
)
requirements
=
self
.
get_all_requirements
(
dict_tpl
)
unmet_requirements
=
self
.
get_unmet_requirements
(
requirements
)
print
(
unmet_requirements
)
service_templates
=
self
.
get_service_template
(
dict_tpl
)
req
=
self
.
get_all_requirements
(
service_templates
)
print
(
req
)
# relationships = self.get_all_relationships(dict_tpl)
# print(relationships)
# unmet_requirements = self.get_unmet_requirements(requirements)
# print(unmet_requirements)
# yaml_dict_tpl = self.trnsform_to_tosca(yaml_dict_tpl)
...
...
@@ -48,18 +66,23 @@ class DumpPlanner:
print
(
exception
)
def
get_all_requirements
(
self
,
dict_tpl
):
all_requirements
=
[]
service_templates
=
self
.
get_service_template
(
dict_tpl
)
def
get_all_requirements
(
self
,
service_templates
):
if
(
not
self
.
requirements
):
for
service
in
service_templates
:
topology_template
=
self
.
get_topology_template
(
service
)
node_templates
=
self
.
get_node_templates
(
topology_template
)
for
node_template
in
node_templates
:
requirements
=
self
.
get_requirements
(
node_template
)
if
requirements
:
for
requirement
in
requirements
[
'requirement'
]:
all_requirements
.
append
(
requirement
)
return
all_requirements
node_type
=
node_template
[
'type'
]
all_requirements
=
self
.
get_super_types_requirements
(
node_type
,
'nodetypes'
,
None
)
id
=
node_template
[
'id'
]
req
=
self
.
get_requirements
(
node_template
)
if
(
req
):
for
r
in
req
[
'requirement'
]:
all_requirements
.
add
(
r
[
'type'
])
self
.
requirements
[
id
]
=
all_requirements
return
self
.
requirements
def
get_unmet_requirements
(
self
,
requirements
):
...
...
@@ -67,18 +90,63 @@ class DumpPlanner:
requirement_type
=
self
.
get_requirement_type
(
requirement
)
print
(
requirement_type
)
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
)
all_relationships
.
append
(
relationships
)
return
all_relationships
def
get_super_types_requirements
(
self
,
component_type
,
type_name
,
requirements
):
if
(
requirements
==
None
):
requirements
=
set
()
regex
=
r"\{(.*?)\}"
matches
=
re
.
finditer
(
regex
,
component_type
,
re
.
MULTILINE
|
re
.
DOTALL
)
namespace
=
next
(
matches
)
.
group
(
1
)
id
=
component_type
.
replace
(
"{"
+
namespace
+
"}"
,
""
)
header
=
{
'accept'
:
'application/json'
}
#winery needs it double percent-encoded
encoded_namespace
=
urllib
.
parse
.
quote
(
namespace
,
safe
=
''
)
encoded_namespace
=
urllib
.
parse
.
quote
(
encoded_namespace
,
safe
=
''
)
servicetemplate_url
=
self
.
tosca_reposetory_api_base_url
+
"/"
+
type_name
+
"/"
+
encoded_namespace
+
"/"
+
id
+
"/"
req
=
urllib
.
request
.
Request
(
url
=
servicetemplate_url
,
headers
=
header
,
method
=
'GET'
)
res
=
urllib
.
request
.
urlopen
(
req
,
timeout
=
5
)
res_body
=
res
.
read
()
component
=
json
.
loads
(
res_body
.
decode
(
"utf-8"
))
for
c
in
component
[
'serviceTemplateOrNodeTypeOrNodeTypeImplementation'
]:
if
'requirementDefinitions'
in
c
and
'requirementDefinition'
in
c
[
'requirementDefinitions'
]:
for
req
in
c
[
'requirementDefinitions'
][
'requirementDefinition'
]:
requirements
.
add
(
req
[
'requirementType'
])
if
'derivedFrom'
in
c
and
c
[
'derivedFrom'
]
and
c
[
'derivedFrom'
][
'type'
]:
self
.
get_super_types_requirements
(
c
[
'derivedFrom'
][
'type'
],
type_name
,
requirements
)
return
requirements
def
get_service_template
(
self
,
dict_tpl
):
return
self
.
find
(
dict_tpl
,
self
.
service_template_names
)
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
):
return
self
.
find
(
dict_tpl
,
self
.
topology_template_names
)
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
):
return
self
.
find
(
dict_tpl
,
self
.
node_template_names
)
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
)
...
...
drip_planner2/src/rpc_server.py
View file @
9b8e13e4
...
...
@@ -13,6 +13,7 @@ import sys
import
tempfile
import
time
logger
=
logging
.
getLogger
(
__name__
)
if
not
getattr
(
logger
,
'handler_set'
,
None
):
logger
.
setLevel
(
logging
.
INFO
)
...
...
@@ -111,7 +112,10 @@ def handle_delivery(message):
if
__name__
==
"__main__"
:
if
(
sys
.
argv
[
1
]
==
"test_local"
):
home
=
expanduser
(
"~"
)
planner
=
DumpPlanner
(
home
+
"/Downloads/topology.json"
)
tosca_reposetory_api_base_url
=
"http://localhost:8080/winery"
namespace
=
"http
%253
A
%252
F
%252
Fsne.uva.nl
%252
Fservicetemplates"
servicetemplate_id
=
"wordpress_w1-wip1"
planner
=
DumpPlanner
(
tosca_reposetory_api_base_url
,
namespace
,
servicetemplate_id
)
else
:
logger
.
info
(
"Input args: "
+
sys
.
argv
[
0
]
+
' '
+
sys
.
argv
[
1
]
+
' '
+
sys
.
argv
[
2
])
channel
=
init_chanel
(
sys
.
argv
)
...
...
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