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
7b7ed666
Commit
7b7ed666
authored
Sep 23, 2019
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed missing docker bug
parent
7f272ffb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
131 additions
and
85 deletions
+131
-85
TOSCAUtils.java
...c/main/java/nl/uva/sne/drip/commons/utils/TOSCAUtils.java
+66
-26
workspace.xml
drip_planner2/.idea/workspace.xml
+6
-8
basic_planner.py
drip_planner2/src/planner/basic_planner.py
+59
-51
No files found.
drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/TOSCAUtils.java
View file @
7b7ed666
...
...
@@ -21,6 +21,7 @@ import java.util.HashMap;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
org.json.JSONException
;
...
...
@@ -121,16 +122,6 @@ public class TOSCAUtils {
public
static
List
<
Map
<
String
,
Object
>>
tosca2KubernetesDeployment
(
Map
<
String
,
Object
>
toscaPlan
)
{
List
<
Map
.
Entry
>
dockerContainers
=
getDockerContainers
(
toscaPlan
);
// String containerName = "mysql";
// String appName = containerName;
// String image1 = "mysql:5.7";
// String imageName1 = "mysql";
// Map<String, Object> envMap1 = new HashMap();
// envMap1.put("MYSQL_DATABASE", "wordpress");
// envMap1.put("MYSQL_PASSWORD", "wordpress");
// envMap1.put("MYSQL_ROOT_PASSWORD", "somewordpress");
// envMap1.put("MYSQL_USER", "wordpress");
List
<
Map
<
String
,
Object
>>
deployments
=
new
ArrayList
<>();
Iterator
<
Map
.
Entry
>
dicIt
=
dockerContainers
.
iterator
();
...
...
@@ -154,8 +145,15 @@ public class TOSCAUtils {
Map
<
String
,
Object
>
properties
=
(
Map
<
String
,
Object
>)
dockerValues
.
get
(
"properties"
);
Map
<
String
,
Object
>
envMap
=
(
Map
<
String
,
Object
>)
properties
.
get
(
"environment"
);
Map
<
String
,
Object
>
imageEnv
=
new
HashMap
();
imageEnv
.
put
(
"env"
,
envMap
);
List
<
Map
<
String
,
Object
>>
imageEnv
=
new
ArrayList
<>();
Set
<
String
>
keys
=
envMap
.
keySet
();
for
(
String
key
:
keys
)
{
Map
<
String
,
Object
>
kubernetesEnvMap
=
new
HashMap
();
kubernetesEnvMap
.
put
(
"name"
,
key
);
kubernetesEnvMap
.
put
(
"value"
,
envMap
.
get
(
key
));
imageEnv
.
add
(
kubernetesEnvMap
);
}
Map
<
String
,
Object
>
image
=
(
Map
<
String
,
Object
>)
((
Map
<
String
,
Object
>)
dockerValues
.
get
(
"artifacts"
)).
get
(
"image"
);
String
imageFile
=
(
String
)
image
.
get
(
"file"
);
...
...
@@ -166,26 +164,19 @@ public class TOSCAUtils {
List
<
String
>
toscaPortsList
=
(
List
<
String
>)
properties
.
get
(
"ports"
);
if
(
toscaPortsList
!=
null
)
{
Map
<
String
,
Object
>
ports
=
new
HashMap
();
System
.
err
.
println
(
toscaPortsList
);
for
(
String
portEntry
:
toscaPortsList
)
{
String
[]
portsArray
=
portEntry
.
split
(
":"
);
Map
<
String
,
Object
>
portMap
=
new
HashMap
();
portMap
.
put
(
"containerPort"
,
portsArray
[
0
]);
List
<
Map
<
String
,
Object
>>
kubernetesPortsList
=
new
ArrayList
<>();
kubernetesPortsList
.
add
(
portMap
);
container
.
put
(
"ports"
,
portMap
);
}
}
// ports.put("ports", portsList);
List
<
Map
<
String
,
Object
>>
containersList
=
new
ArrayList
<>();
containersList
.
add
(
container
);
Map
<
String
,
Object
>
containers
=
new
HashMap
();
containers
.
put
(
"containers"
,
containersList
);
Map
<
String
,
Object
>
spec1
=
new
HashMap
();
spec1
.
put
(
"containers"
,
containers
);
// spec1.put("ports", ports);
spec1
.
put
(
"containers"
,
containersList
);
topSpec
.
put
(
"spec"
,
spec1
);
Map
<
String
,
Object
>
deployment
=
new
HashMap
();
...
...
@@ -193,16 +184,65 @@ public class TOSCAUtils {
deployment
.
put
(
"metadata"
,
metadata
);
deployment
.
put
(
"kind"
,
"Deployment"
);
deployment
.
put
(
"apiVersion"
,
"extensions/v1beta1"
);
//
// try {
// System.err.println(Converter.map2YmlString(deployment));
// System.err.println("----------------------------------");
// } catch (JSONException ex) {
// Logger.getLogger(TOSCAUtils.class.getName()).log(Level.SEVERE, null, ex);
// }
deployments
.
add
(
deployment
);
}
return
deployments
;
}
public
static
List
<
Map
<
String
,
Object
>>
tosca2KubernetesService
(
Map
<
String
,
Object
>
toscaPlan
)
{
List
<
Map
.
Entry
>
dockerContainers
=
getDockerContainers
(
toscaPlan
);
List
<
Map
<
String
,
Object
>>
services
=
new
ArrayList
<>();
Iterator
<
Map
.
Entry
>
dicIt
=
dockerContainers
.
iterator
();
while
(
dicIt
.
hasNext
())
{
Map
.
Entry
docker
=
dicIt
.
next
();
String
name
=
(
String
)
docker
.
getKey
();
Map
<
String
,
Object
>
dockerValues
=
(
Map
<
String
,
Object
>)
docker
.
getValue
();
Map
<
String
,
Object
>
spec
=
new
HashMap
();
Map
<
String
,
Object
>
properties
=
(
Map
<
String
,
Object
>)
dockerValues
.
get
(
"properties"
);
List
<
String
>
toscaPortsList
=
(
List
<
String
>)
properties
.
get
(
"ports"
);
if
(
toscaPortsList
!=
null
)
{
for
(
String
portEntry
:
toscaPortsList
)
{
String
[]
portsArray
=
portEntry
.
split
(
":"
);
Map
<
String
,
Object
>
portMap
=
new
HashMap
();
portMap
.
put
(
"port"
,
portsArray
[
1
]);
spec
.
put
(
"ports"
,
portMap
);
}
}
Map
<
String
,
Object
>
selector
=
new
HashMap
();
selector
.
put
(
"app"
,
name
);
spec
.
put
(
"selector"
,
selector
);
Map
<
String
,
Object
>
labels
=
new
HashMap
();
labels
.
put
(
"app"
,
name
);
Map
<
String
,
Object
>
metadata
=
new
HashMap
();
metadata
.
put
(
"labels"
,
labels
);
metadata
.
put
(
"name"
,
name
);
Map
<
String
,
Object
>
service
=
new
HashMap
();
service
.
put
(
"spec"
,
spec
);
service
.
put
(
"metadata"
,
metadata
);
service
.
put
(
"kind"
,
"Service"
);
service
.
put
(
"apiVersion"
,
"v1"
);
try
{
System
.
err
.
println
(
Converter
.
map2YmlString
(
deployment
));
System
.
err
.
println
(
Converter
.
map2YmlString
(
service
));
System
.
err
.
println
(
"----------------------------------"
);
}
catch
(
JSONException
ex
)
{
Logger
.
getLogger
(
TOSCAUtils
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
deployments
.
add
(
deployment
);
}
return
deployments
;
return
services
;
}
}
drip_planner2/.idea/workspace.xml
View file @
7b7ed666
...
...
@@ -2,14 +2,7 @@
<project
version=
"4"
>
<component
name=
"ChangeListManager"
>
<list
default=
"true"
id=
"462ede19-adfe-472b-975e-fefefa973fe0"
name=
"Default Changelist"
comment=
"slolved cap error"
>
<change
beforePath=
"$PROJECT_DIR$/../drip-deployer/docker_engine.py"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-deployer/docker_engine.py"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-deployer/docker_kubernetes.py"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-deployer/docker_kubernetes.py"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-deployer/docker_kubernetes.sh"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-deployer/docker_kubernetes.sh"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-planner/ICPCP.py"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-planner/NewInstance.py"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-planner/rpc_server.py"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-planner/server.py"
beforeDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-planner2provisioner/src/main/java/nl/uva/sne/drip/drip/converter/P2PConverter.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-planner2provisioner/src/main/java/nl/uva/sne/drip/drip/converter/P2PConverter.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/TOSCAUtils.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/TOSCAUtils.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/.idea/workspace.xml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/.idea/workspace.xml"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/src/planner/basic_planner.py"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/src/planner/basic_planner.py"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/venv/lib/python3.6/site-packages/easy-install.pth"
beforeDir=
"false"
/>
...
...
@@ -169,6 +162,11 @@
<line>
64
</line>
<option
name=
"timeStamp"
value=
"1"
/>
</line-breakpoint>
<line-breakpoint
enabled=
"true"
suspend=
"THREAD"
type=
"python-line"
>
<url>
file://$PROJECT_DIR$/src/planner/basic_planner.py
</url>
<line>
322
</line>
<option
name=
"timeStamp"
value=
"3"
/>
</line-breakpoint>
</breakpoints>
<default-breakpoints>
<breakpoint
type=
"python-exception"
>
...
...
drip_planner2/src/planner/basic_planner.py
View file @
7b7ed666
...
...
@@ -16,6 +16,8 @@ import yaml
from
utils.TOSCA_parser
import
*
import
logging
from
src.utils.TOSCA_parser
import
TOSCAParser
def
get_cpu_frequency
():
return
'2.9 GHz'
...
...
@@ -71,13 +73,13 @@ def set_topology_properties(node_template_dict):
return
node_template_dict
def
fill_in_properties
(
nodetemplate_dict
):
if
'properties'
in
nodetemplate_dict
:
if
'type'
in
node
template_dict
and
node
template_dict
[
'type'
]
==
'tosca.nodes.ARTICONF.VM.topology'
:
node
template_dict
=
set_topology_properties
(
node
template_dict
)
if
'type'
in
node
template_dict
and
node
template_dict
[
'type'
]
==
'tosca.nodes.ARTICONF.VM.Compute'
:
node
template_dict
=
set_vm_properties
(
node
template_dict
)
return
nodetemplate_dict
def
fill_in_properties
(
node
_
template_dict
):
if
'properties'
in
node
_
template_dict
:
if
'type'
in
node
_template_dict
and
node_
template_dict
[
'type'
]
==
'tosca.nodes.ARTICONF.VM.topology'
:
node
_template_dict
=
set_topology_properties
(
node_
template_dict
)
if
'type'
in
node
_template_dict
and
node_
template_dict
[
'type'
]
==
'tosca.nodes.ARTICONF.VM.Compute'
:
node
_template_dict
=
set_vm_properties
(
node_
template_dict
)
return
node
_
template_dict
def
fix_occurrences
(
node_templates
):
...
...
@@ -112,7 +114,7 @@ def node_type_2_node_template(node_type):
def
contains_node_type
(
capable_node_types_list
,
node_type
):
if
capable_node_types_list
==
None
:
if
capable_node_types_list
is
None
:
return
False
for
capable_node_type
in
capable_node_types_list
:
if
isinstance
(
capable_node_type
,
NodeTemplate
):
...
...
@@ -147,6 +149,44 @@ def fix_duplicate_vm_names(yaml_str):
return
yaml
.
dump
(
topology_dict
)
def
get_optimal_num_of_occurrences
(
node_type
,
min_max_occurrences
):
max_occurrences
=
-
1
min_occurrences
=
-
1
if
min_max_occurrences
:
if
isinstance
(
min_max_occurrences
[
1
],
int
):
max_occurrences
=
int
(
min_max_occurrences
[
1
])
if
isinstance
(
min_max_occurrences
[
0
],
int
):
min_occurrences
=
int
(
min_max_occurrences
[
0
])
if
max_occurrences
and
max_occurrences
>
-
1
:
return
max_occurrences
if
max_occurrences
and
max_occurrences
<=
-
1
and
min_max_occurrences
[
1
]
==
'UNBOUNDED'
and
node_type
==
'tosca.nodes.ARTICONF.VM.Compute'
:
return
1
else
:
return
1
def
has_capability_max_one_occurrence
(
capability
):
if
'occurrences'
in
capability
and
capability
[
'occurrences'
][
1
]
==
1
:
return
True
else
:
return
False
def
copy_capabilities_with_one_occurrences
(
parent_capabilities
,
candidate_child_node
):
inherited_capabilities
=
[]
if
not
'capabilities'
in
candidate_child_node
.
keys
():
candidate_child_node
[
'capabilities'
]
=
{}
for
capability
in
parent_capabilities
:
inherited_capability
=
parent_capabilities
[
capability
]
if
has_capability_max_one_occurrence
(
inherited_capability
):
inherited_capabilities
.
append
(
parent_capabilities
)
for
key
in
parent_capabilities
:
candidate_child_node
[
'capabilities'
][
key
]
=
parent_capabilities
[
key
]
return
candidate_child_node
class
BasicPlanner
:
def
__init__
(
self
,
path
):
...
...
@@ -157,9 +197,10 @@ class BasicPlanner:
self
.
all_nodes
.
update
(
self
.
tosca_node_types
.
items
())
self
.
all_nodes
.
update
(
self
.
all_custom_def
.
items
())
# capable_node_name = ''
node_templates
=
[]
for
node
in
self
.
template
.
nodetemplates
:
node_templates
=
self
.
add_reqired_nods
(
node
,
None
)
node_templates
.
extend
(
self
.
add_required_nods
(
node
,
None
))
# node_templates = self.add_required_nods(node, None)
if
node_templates
:
node_templates
=
fix_occurrences
(
node_templates
)
...
...
@@ -172,7 +213,8 @@ class BasicPlanner:
yaml_str
=
yaml_str
.
replace
(
'tosca_definitions_version: tosca_simple_yaml_1_0'
,
''
)
yaml_str
=
yaml_str
.
replace
(
'description: TOSCA example'
,
''
)
yaml_str
=
yaml_str
.
replace
(
'tosca_template'
,
'topology_template'
)
self
.
formatted_yaml_str
=
'tosca_definitions_version: tosca_simple_yaml_1_0
\n
repositories:
\n
docker_hub: https://hub.docker.com/
\n
'
+
yaml_str
self
.
formatted_yaml_str
=
'tosca_definitions_version: tosca_simple_yaml_1_0
\n
repositories:
\n
docker_hub: '
\
'https://hub.docker.com/
\n
'
+
yaml_str
logging
.
info
(
'TOSCA template:
\n
'
+
self
.
formatted_yaml_str
)
def
get_plan
(
self
):
...
...
@@ -225,7 +267,7 @@ class BasicPlanner:
for
candidate_node_name
in
candidate_nodes
:
if
candidate_child_node
[
'derived_from'
]
==
candidate_node_name
:
candidate_child_nodes
[
tosca_node_type
]
=
self
.
all_nodes
[
tosca_node_type
]
candidate_child_nodes
[
tosca_node_type
]
=
self
.
copy_capabilities_with_one_occurrences
(
candidate_child_nodes
[
tosca_node_type
]
=
copy_capabilities_with_one_occurrences
(
candidate_nodes
[
candidate_node_name
][
'capabilities'
],
candidate_child_node
)
candidate_nodes
.
update
(
candidate_child_nodes
)
...
...
@@ -238,42 +280,7 @@ class BasicPlanner:
capable_nodes
[
candidate_node_name
]
=
candidate_nodes
[
candidate_node_name
]
return
capable_nodes
def
copy_capabilities_with_one_occurrences
(
self
,
parent_capabilities
,
candidate_child_node
):
inherited_capabilities
=
[]
if
not
'capabilities'
in
candidate_child_node
.
keys
():
candidate_child_node
[
'capabilities'
]
=
{}
for
capability
in
parent_capabilities
:
inherited_capability
=
parent_capabilities
[
capability
]
if
self
.
has_capability_max_one_occurrence
(
inherited_capability
):
inherited_capabilities
.
append
(
parent_capabilities
)
for
key
in
parent_capabilities
:
candidate_child_node
[
'capabilities'
][
key
]
=
parent_capabilities
[
key
]
return
candidate_child_node
def
has_capability_max_one_occurrence
(
self
,
capability
):
if
'occurrences'
in
capability
and
capability
[
'occurrences'
][
1
]
==
1
:
return
True
else
:
return
False
def
get_optimal_num_of_occurrences
(
self
,
node_type
,
min_max_occurrences
):
max_occurrences
=
-
1
min_occurrences
=
-
1
if
min_max_occurrences
:
if
isinstance
(
min_max_occurrences
[
1
],
int
):
max_occurrences
=
int
(
min_max_occurrences
[
1
])
if
isinstance
(
min_max_occurrences
[
0
],
int
):
min_occurrences
=
int
(
min_max_occurrences
[
0
])
if
max_occurrences
and
max_occurrences
>
-
1
:
return
max_occurrences
if
max_occurrences
and
max_occurrences
<=
-
1
and
min_max_occurrences
[
1
]
==
'UNBOUNDED'
and
node_type
==
'tosca.nodes.ARTICONF.VM.Compute'
:
return
1
else
:
return
1
def
add_reqired_nods
(
self
,
node
,
node_templates
):
def
add_required_nods
(
self
,
node
,
node_templates
):
if
not
node_templates
:
node_templates
=
[]
missing_requirements
=
self
.
get_missing_requirements
(
node
)
...
...
@@ -293,13 +300,13 @@ class BasicPlanner:
else
:
logging
.
error
(
'Did not find node with reuired capability: '
+
str
(
req
[
key
][
'capability'
]))
occurrences
=
self
.
get_optimal_num_of_occurrences
(
capable_node_type
,
min_max_occurrences
)
occurrences
=
get_optimal_num_of_occurrences
(
capable_node_type
,
min_max_occurrences
)
if
not
contains_node_type
(
node_templates
,
capable_node_type
)
and
occurrences
==
1
:
capable_node_template
=
node_type_2_node_template
(
capable_node
)
capable_node_name
=
capable_node_template
.
name
node_templates
.
append
(
capable_node_template
)
# recursively fulfill all requirements
self
.
add_reqired_nods
(
capable_node_template
,
node_templates
)
self
.
add_req
u
ired_nods
(
capable_node_template
,
node_templates
)
elif
occurrences
>
1
:
logging
.
info
(
'Creating: '
+
str
(
occurrences
)
+
' occurrences of '
+
capable_node_type
)
for
x
in
range
(
0
,
occurrences
):
...
...
@@ -308,11 +315,12 @@ class BasicPlanner:
logging
.
info
(
'Adding : '
+
str
(
capable_node_template
.
name
))
node_templates
.
append
(
capable_node_template
)
# recursively fulfill all requirements
self
.
add_reqired_nods
(
capable_node_template
,
node_templates
)
self
.
add_req
u
ired_nods
(
capable_node_template
,
node_templates
)
for
x
in
range
(
0
,
occurrences
):
req
[
next
(
iter
(
req
))][
'node'
]
=
capable_node_name
node
.
requirements
.
append
(
req
)
logging
.
info
(
'Adding: '
+
str
(
capable_node_name
)
+
' to node: '
+
node
.
name
)
if
not
contains_node_type
(
node_templates
,
node
):
node_templates
.
append
(
node
)
...
...
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