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
09026e0d
Commit
09026e0d
authored
Mar 03, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass value to p2p converter
Fixed bug in planner We still get en exception from the deployer
parent
ea6686fc
Changes
17
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
268 additions
and
105 deletions
+268
-105
.gitignore
.gitignore
+2
-1
DeployController.java
.../main/java/nl/uva/sne/drip/api/rest/DeployController.java
+1
-1
PlannerController.java
...main/java/nl/uva/sne/drip/api/rest/PlannerController.java
+2
-3
ProvisionController.java
...in/java/nl/uva/sne/drip/api/rest/ProvisionController.java
+1
-1
DRIPCaller.java
...api/src/main/java/nl/uva/sne/drip/api/rpc/DRIPCaller.java
+18
-7
PlannerCaller.java
.../src/main/java/nl/uva/sne/drip/api/rpc/PlannerCaller.java
+33
-1
PlannerService.java
...main/java/nl/uva/sne/drip/api/service/PlannerService.java
+45
-4
SimplePlannerService.java
...ava/nl/uva/sne/drip/api/service/SimplePlannerService.java
+1
-1
Converter.java
...rc/main/java/nl/uva/sne/drip/commons/utils/Converter.java
+34
-3
rpc_server.py
drip-planner/rpc_server.py
+19
-19
nb-configuration.xml
drip-planner2provisioner/nb-configuration.xml
+18
-0
P2PConverter.java
...ain/java/nl/uva/sne/drip/drip/converter/P2PConverter.java
+24
-31
Component.java
...nl/uva/sne/drip/drip/converter/planner/out/Component.java
+69
-0
Parameter.java
...nl/uva/sne/drip/drip/converter/planner/out/Parameter.java
+0
-12
PlannerOutput.java
...va/sne/drip/drip/converter/planner/out/PlannerOutput.java
+0
-11
Value.java
...ava/nl/uva/sne/drip/drip/converter/planner/out/Value.java
+0
-9
testConverter.java
drip-planner2provisioner/src/test/java/testConverter.java
+1
-1
No files found.
.gitignore
View file @
09026e0d
...
...
@@ -5,3 +5,4 @@
/drip-simple_planner/target/
/drip-provisioner/target/
/target/
/drip-planner2provisioner/target/
\ No newline at end of file
drip-api/src/main/java/nl/uva/sne/drip/api/rest/DeployController.java
View file @
09026e0d
...
...
@@ -80,7 +80,7 @@ public class DeployController {
try
(
DRIPCaller
deployer
=
new
DeployerCaller
(
messageBrokerHost
);)
{
Message
deployerInvokationMessage
=
buildDeployerMessage
(
provisionID
,
clusterType
.
toLowerCase
());
// Message response = deployer.
call(deployerInvokationMessage
);
// Message response = deployer.
unmarshall(deployer.call(deployerInvokationMessage)
);
Message
response
=
generateFakeResponse
();
List
<
MessageParameter
>
params
=
response
.
getParameters
();
ClusterCredentials
clusterCred
=
new
ClusterCredentials
();
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/rest/PlannerController.java
View file @
09026e0d
...
...
@@ -33,7 +33,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
nl.uva.sne.drip.api.service.PlannerService
;
import
nl.uva.sne.drip.api.service.ToscaService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.commons.types.Plan
;
import
org.springframework.web.bind.annotation.RequestParam
;
...
...
@@ -47,7 +46,7 @@ import org.springframework.web.bind.annotation.RequestParam;
@Component
public
class
PlannerController
{
@Autowired
//
@Autowired
private
SimplePlannerService
simplePlannerService
;
@Autowired
...
...
@@ -76,7 +75,7 @@ public class PlannerController {
public
@ResponseBody
String
get
(
@PathVariable
(
"id"
)
String
id
,
@RequestParam
(
value
=
"format"
)
String
format
)
{
try
{
return
simpleP
lannerService
.
get
(
id
,
format
);
return
p
lannerService
.
get
(
id
,
format
);
}
catch
(
JSONException
ex
)
{
Logger
.
getLogger
(
ToscaController
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/rest/ProvisionController.java
View file @
09026e0d
...
...
@@ -102,7 +102,7 @@ public class ProvisionController {
try
(
DRIPCaller
provisioner
=
new
ProvisionerCaller
(
messageBrokerHost
);)
{
Message
provisionerInvokationMessage
=
buildProvisionerMessage
(
req
);
Message
response
=
provisioner
.
call
(
provisionerInvokationMessage
);
Message
response
=
(
provisioner
.
call
(
provisionerInvokationMessage
)
);
// Message response = generateFakeResponse();
List
<
MessageParameter
>
params
=
response
.
getParameters
();
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/rpc/DRIPCaller.java
View file @
09026e0d
...
...
@@ -17,6 +17,7 @@ import java.util.concurrent.BlockingQueue;
import
java.util.concurrent.TimeoutException
;
import
nl.uva.sne.drip.commons.types.Message
;
import
nl.uva.sne.drip.commons.types.MessageParameter
;
import
nl.uva.sne.drip.commons.utils.Converter
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -46,6 +47,7 @@ public abstract class DRIPCaller implements AutoCloseable {
private
final
Channel
channel
;
private
final
String
replyQueueName
;
private
final
String
requestQeueName
;
private
final
ObjectMapper
mapper
;
public
DRIPCaller
(
String
messageBrokerHost
,
String
requestQeueName
)
throws
IOException
,
TimeoutException
{
ConnectionFactory
factory
=
new
ConnectionFactory
();
...
...
@@ -59,6 +61,8 @@ public abstract class DRIPCaller implements AutoCloseable {
// create a single callback queue per client not per requests.
replyQueueName
=
channel
.
queueDeclare
().
getQueue
();
this
.
requestQeueName
=
requestQeueName
;
this
.
mapper
=
new
ObjectMapper
();
mapper
.
configure
(
JsonParser
.
Feature
.
ALLOW_SINGLE_QUOTES
,
true
);
}
/**
...
...
@@ -94,8 +98,6 @@ public abstract class DRIPCaller implements AutoCloseable {
public
Message
call
(
Message
r
)
throws
IOException
,
TimeoutException
,
InterruptedException
,
JSONException
{
ObjectMapper
mapper
=
new
ObjectMapper
();
mapper
.
configure
(
JsonParser
.
Feature
.
ALLOW_SINGLE_QUOTES
,
true
);
String
jsonInString
=
mapper
.
writeValueAsString
(
r
);
//Build a correlation ID to distinguish responds
...
...
@@ -117,11 +119,13 @@ public abstract class DRIPCaller implements AutoCloseable {
}
}
});
String
strResponse
=
response
.
take
();
strResponse
=
strResponse
.
replaceAll
(
"'null'"
,
"null"
).
replaceAll
(
"\'"
,
"\""
).
replaceAll
(
" "
,
""
);
System
.
err
.
println
(
strResponse
);
// return unMarshallWithSimpleJson(strResponse);
return
mapper
.
readValue
(
strResponse
,
Message
.
class
);
String
resp
=
response
.
take
();
String
clean
=
resp
.
replaceAll
(
"'null'"
,
"null"
).
replaceAll
(
"\'"
,
"\""
).
replaceAll
(
" "
,
""
);
if
(
clean
.
contains
(
"\"value\":{\""
))
{
return
Converter
.
string2Message
(
clean
);
}
return
mapper
.
readValue
(
clean
,
Message
.
class
);
}
private
Message
unMarshallWithSimpleJson
(
String
strResponse
)
throws
JSONException
{
...
...
@@ -147,4 +151,11 @@ public abstract class DRIPCaller implements AutoCloseable {
}
// public Message unmarshall(String strResponse) throws IOException {
//
// mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
// strResponse = strResponse.replaceAll("'null'", "null").replaceAll("\'", "\"").replaceAll(" ", "");
//// return unMarshallWithSimpleJson(strResponse);
// return mapper.readValue(strResponse, Message.class);
// }
}
drip-api/src/main/java/nl/uva/sne/drip/api/rpc/PlannerCaller.java
View file @
09026e0d
...
...
@@ -15,9 +15,12 @@
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
rpc
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
java.io.IOException
;
import
java.util.concurrent.TimeoutException
;
import
nl.uva.sne.drip.commons.types.Message
;
/**
*
...
...
@@ -31,4 +34,33 @@ public class PlannerCaller extends DRIPCaller {
super
(
messageBrokerHost
,
REQUEST_QUEUE_NAME
);
}
public
String
generateFakeResponse
(
Message
plannerInvokationMessage
)
throws
IOException
{
return
"{\n"
+
" \"creationDate\": 1487002029722,\n"
+
" \"parameters\": [\n"
+
" {\n"
+
" \"url\": null,\n"
+
" \"encoding\": \"UTF-8\",\n"
+
" \"value\": \"{\\\"name\\\":\\\"2d13d708e3a9441ab8336ce874e08dd1\\\",\\\"size\\\":\\\"Small\\\",\\\"docker\\\":\\\"mogswitch/InputDistributor\\\"}\",\n"
+
" \"name\": \"component\",\n"
+
" \"attributes\": null\n"
+
" },\n"
+
" {\n"
+
" \"url\": null,\n"
+
" \"encoding\": \"UTF-8\",\n"
+
" \"value\": \"{\\\"name\\\":\\\"8fcc1788d9ee462c826572c79fdb2a6a\\\",\\\"size\\\":\\\"Small\\\",\\\"docker\\\":\\\"mogswitch/InputDistributor\\\"}\",\n"
+
" \"name\": \"component\",\n"
+
" \"attributes\": null\n"
+
" },\n"
+
" {\n"
+
" \"url\": null,\n"
+
" \"encoding\": \"UTF-8\",\n"
+
" \"value\": \"{\\\"name\\\":\\\"5e0add703c8a43938a39301f572e46c0\\\",\\\"size\\\":\\\"Small\\\",\\\"docker\\\":\\\"mogswitch/InputDistributor\\\"}\",\n"
+
" \"name\": \"component\",\n"
+
" \"attributes\": null\n"
+
" }\n"
+
" ]\n"
+
"}"
;
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/service/PlannerService.java
View file @
09026e0d
...
...
@@ -27,6 +27,7 @@ import java.util.Set;
import
java.util.concurrent.TimeoutException
;
import
nl.uva.sne.drip.api.dao.PlanDao
;
import
nl.uva.sne.drip.api.exception.BadRequestException
;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
import
nl.uva.sne.drip.api.rpc.PlannerCaller
;
import
nl.uva.sne.drip.commons.types.Message
;
import
nl.uva.sne.drip.commons.types.MessageParameter
;
...
...
@@ -60,12 +61,24 @@ public class PlannerService {
try
(
PlannerCaller
planner
=
new
PlannerCaller
(
messageBrokerHost
))
{
Message
plannerInvokationMessage
=
buildPlannerMessage
(
toscaId
);
Message
plannerReturnedMessage
=
planner
.
call
(
plannerInvokationMessage
);
Message
plannerReturnedMessage
=
(
planner
.
call
(
plannerInvokationMessage
));
// Message plannerReturnedMessage = (planner.generateFakeResponse(plannerInvokationMessage)
);
ObjectMapper
mapper
=
new
ObjectMapper
();
mapper
.
configure
(
JsonParser
.
Feature
.
ALLOW_SINGLE_QUOTES
,
true
);
String
jsonString
=
mapper
.
writeValueAsString
(
plannerReturnedMessage
);
SimplePlanContainer
simplePlan
=
P2PConverter
.
transfer
(
jsonString
,
"zh9314"
,
"Ubuntu 16.04"
,
"swarm"
);
List
<
MessageParameter
>
messageParams
=
plannerReturnedMessage
.
getParameters
();
StringBuilder
jsonArrayString
=
new
StringBuilder
();
jsonArrayString
.
append
(
"["
);
String
prefix
=
""
;
for
(
MessageParameter
mp
:
messageParams
)
{
String
value
=
mp
.
getValue
();
jsonArrayString
.
append
(
prefix
);
prefix
=
","
;
String
jsonValue
=
value
.
replaceAll
(
"\\\""
,
"\""
);
jsonArrayString
.
append
(
jsonValue
);
}
jsonArrayString
.
append
(
"]"
);
SimplePlanContainer
simplePlan
=
P2PConverter
.
convert
(
jsonArrayString
.
toString
(),
"zh9314"
,
"Ubuntu 16.04"
,
"swarm"
);
Plan
topLevel
=
new
Plan
();
topLevel
.
setLevel
(
0
);
topLevel
.
setToscaID
(
toscaId
);
...
...
@@ -113,4 +126,32 @@ public class PlannerService {
return
invokationMessage
;
}
public
String
get
(
String
id
,
String
fromat
)
throws
JSONException
{
Plan
plan
=
planDao
.
findOne
(
id
);
if
(
plan
==
null
)
{
throw
new
NotFoundException
();
}
Map
<
String
,
Object
>
map
=
plan
.
getKvMap
();
Set
<
String
>
ids
=
plan
.
getLoweLevelPlanIDs
();
for
(
String
lowID
:
ids
)
{
Map
<
String
,
Object
>
lowLevelMap
=
planDao
.
findOne
(
lowID
).
getKvMap
();
map
.
putAll
(
lowLevelMap
);
}
if
(
fromat
!=
null
&&
fromat
.
equals
(
"yml"
))
{
String
ymlStr
=
Converter
.
map2YmlString
(
map
);
ymlStr
=
ymlStr
.
replaceAll
(
"\\uff0E"
,
"\\."
);
return
ymlStr
;
}
if
(
fromat
!=
null
&&
fromat
.
equals
(
"json"
))
{
String
jsonStr
=
Converter
.
map2JsonString
(
map
);
jsonStr
=
jsonStr
.
replaceAll
(
"\\uff0E"
,
"\\."
);
return
jsonStr
;
}
String
ymlStr
=
Converter
.
map2YmlString
(
map
);
ymlStr
=
ymlStr
.
replaceAll
(
"\\uff0E"
,
"\\."
);
return
ymlStr
;
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/service/SimplePlannerService.java
View file @
09026e0d
...
...
@@ -61,7 +61,7 @@ public class SimplePlannerService {
Plan
topLevel
;
try
(
PlannerCaller
planner
=
new
PlannerCaller
(
messageBrokerHost
))
{
Message
plannerReturnedMessage
=
planner
.
call
(
plannerInvokationMessage
);
Message
plannerReturnedMessage
=
(
planner
.
call
(
plannerInvokationMessage
)
);
List
<
MessageParameter
>
planFiles
=
plannerReturnedMessage
.
getParameters
();
topLevel
=
new
Plan
();
Set
<
String
>
ids
=
topLevel
.
getLoweLevelPlanIDs
();
...
...
drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/Converter.java
View file @
09026e0d
...
...
@@ -16,7 +16,6 @@
package
nl
.
uva
.
sne
.
drip
.
commons
.
utils
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.JsonMappingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
java.io.IOException
;
import
java.io.InputStream
;
...
...
@@ -28,8 +27,8 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Properties
;
import
nl.uva.sne.drip.commons.types.CloudCredentials
;
import
nl.uva.sne.drip.
drip.converter.P2PConverter
;
import
nl.uva.sne.drip.
drip.converter.SimplePlanContain
er
;
import
nl.uva.sne.drip.
commons.types.Message
;
import
nl.uva.sne.drip.
commons.types.MessageParamet
er
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -143,4 +142,36 @@ public class Converter {
EC2_NAME_MAP
.
put
(
"key"
,
"AWSSecretKey"
);
}
public
static
Message
string2Message
(
String
clean
)
throws
JSONException
,
IOException
{
Message
mess
=
new
Message
();
JSONObject
jsonObj
=
new
JSONObject
(
clean
);
long
creationDate
=
jsonObj
.
getLong
(
"creationDate"
);
mess
.
setCreationDate
(
creationDate
);
JSONArray
jsonParams
=
(
JSONArray
)
jsonObj
.
get
(
"parameters"
);
List
<
MessageParameter
>
params
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
jsonParams
.
length
();
i
++)
{
MessageParameter
p
=
new
MessageParameter
();
JSONObject
jsonParam
=
(
JSONObject
)
jsonParams
.
get
(
i
);
String
url
;
if
(!
jsonObj
.
isNull
(
"url"
))
{
p
.
setURL
((
String
)
jsonObj
.
get
(
"url"
));
}
if
(!
jsonObj
.
isNull
(
"encoding"
))
{
p
.
setEncoding
(
jsonObj
.
getString
(
"encoding"
));
}
if
(!
jsonObj
.
isNull
(
"attributes"
))
{
Map
<
String
,
String
>
attributes
=
new
ObjectMapper
().
readValue
(
""
,
Map
.
class
);
p
.
setAttributes
(
attributes
);
}
String
val
=
jsonParam
.
getString
(
"value"
);
val
=
val
.
replaceAll
(
"\""
,
"\\\""
);
p
.
setValue
(
val
);
params
.
add
(
p
);
}
mess
.
setParameters
(
params
);
return
mess
;
}
}
drip-planner/rpc_server.py
View file @
09026e0d
...
...
@@ -48,7 +48,7 @@ def handleDelivery(message):
i
=
1
for
j
in
json1
:
if
not
json1
[
j
][
'type'
]
==
"Switch.nodes.Application.Connection"
:
print
j
,
json1
[
j
]
#
print j, json1[j]
nodeDic
[
j
]
=
i
nodeDic1
[
i
]
=
j
i
=
i
+
1
...
...
@@ -57,8 +57,8 @@ def handleDelivery(message):
links
=
[]
for
j
in
json1
:
if
json1
[
j
][
'type'
]
==
"Switch.nodes.Application.Connection"
:
print
json1
[
j
][
'properties'
][
'source'
][
'component_name'
]
print
json1
[
j
][
'properties'
][
'target'
][
'component_name'
]
#
print json1[j]['properties']['source']['component_name']
#
print json1[j]['properties']['target']['component_name']
link
=
{}
link
[
'source'
]
=
nodeDic
[
json1
[
j
][
'properties'
][
'source'
][
'component_name'
]]
link
[
'target'
]
=
nodeDic
[
json1
[
j
][
'properties'
][
'target'
][
'component_name'
]]
...
...
@@ -88,7 +88,7 @@ def handleDelivery(message):
performance
[
str
(
value
)]
=
"1,2,3"
wfJson
[
'performance'
]
=
performance
print
wfJson
#
print wfJson
#send request to the server
start
=
time
.
time
()
...
...
@@ -100,27 +100,27 @@ def handleDelivery(message):
res
=
wf
.
generateJSON
()
end
=
time
.
time
()
print
(
end
-
start
)
#
print (end - start)
# convert the json to the file required
res1
=
{}
for
key
,
value
in
sorted_nodeDic
:
res1_value
=
{}
res1_value
[
"size"
]
=
res
[
str
(
value
)]
res1_value
[
"docker"
]
=
json1
[
nodeDic1
[
value
]]
.
get
(
'artifacts'
)
.
get
(
'docker_image'
)
.
get
(
'file'
)
res1
[
str
(
nodeDic1
[
value
])]
=
res1_value
print
res1
# generate the json files in the corresponding format as the
outcontent
=
{}
current_milli_time
=
lambda
:
int
(
round
(
time
.
time
()
*
1000
))
outcontent
[
"creationDate"
]
=
current_milli_time
()
outcontent
[
"parameters"
]
=
[]
par1
=
{}
par1
[
"url"
]
=
"null"
par1
[
"encoding"
]
=
"UTF-8"
par1
[
"value"
]
=
res1
par1
[
"attributes"
]
=
"null"
outcontent
[
"parameters"
]
.
append
(
par1
)
for
key
,
value
in
sorted_nodeDic
:
par
=
{}
par
[
"url"
]
=
"null"
par
[
"encoding"
]
=
"UTF-8"
docker
=
json1
[
nodeDic1
[
value
]]
.
get
(
'artifacts'
)
.
get
(
'docker_image'
)
.
get
(
'file'
)
res1
[
"name"
]
=
str
(
nodeDic1
[
value
])
res1
[
"size"
]
=
res
[
str
(
value
)]
res1
[
"docker"
]
=
str
(
docker
)
#v = str("{\\'name\\':\\'"+str(nodeDic1[value])+"\\',\\'size\\':\\'"+res[str(value)]+"\\',\\'docker\\':\\'"+docker+"\\'}")
par
[
"value"
]
=
res1
par
[
"attributes"
]
=
"null"
outcontent
[
"parameters"
]
.
append
(
par
)
return
outcontent
...
...
drip-planner2provisioner/nb-configuration.xml
0 → 100644
View file @
09026e0d
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties
xmlns=
"http://www.netbeans.org/ns/maven-properties-data/1"
>
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<netbeans.hint.licensePath>
${project.basedir}/../licenseheader.txt
</netbeans.hint.licensePath>
</properties>
</project-shared-configuration>
drip-planner2provisioner/src/main/java/nl/uva/sne/drip/drip/converter/P2PConverter.java
View file @
09026e0d
package
nl
.
uva
.
sne
.
drip
.
drip
.
converter
;
import
nl.uva.sne.drip.drip.converter.planner.out.Component
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
...
...
@@ -10,11 +11,10 @@ import com.fasterxml.jackson.core.JsonParseException;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.JsonMappingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.dataformat.yaml.YAMLFactory
;
import
java.util.List
;
import
nl.uva.sne.drip.drip.converter.planner.out.Parameter
;
import
nl.uva.sne.drip.drip.converter.planner.out.PlannerOutput
;
import
nl.uva.sne.drip.drip.converter.planner.out.Value
;
import
nl.uva.sne.drip.drip.converter.provisioner.in.Eth
;
import
nl.uva.sne.drip.drip.converter.provisioner.in.SubTopology
;
import
nl.uva.sne.drip.drip.converter.provisioner.in.SubTopologyInfo
;
...
...
@@ -24,9 +24,9 @@ import nl.uva.sne.drip.drip.converter.provisioner.in.VM;
public
class
P2PConverter
{
public
static
SimplePlanContainer
transfer
(
String
plannerOutputJson
,
String
userName
,
String
OStype
,
String
clusterType
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
public
static
SimplePlanContainer
convert
(
String
plannerOutputJson
,
String
userName
,
String
OStype
,
String
clusterType
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
Parameter
plannerOutput
=
getInfoFromPlanner
(
plannerOutputJson
);
List
<
Component
>
components
=
getInfoFromPlanner
(
plannerOutputJson
);
TopTopology
topTopology
=
new
TopTopology
();
SubTopology
subTopology
=
new
SubTopology
();
...
...
@@ -35,7 +35,7 @@ public class P2PConverter {
sti
.
cloudProvider
=
"EC2"
;
sti
.
topology
=
UUID
.
randomUUID
().
toString
();
subTopology
.
publicKeyPath
=
null
;
subTopology
.
publicKeyPath
=
"~/.ssh/id_dsa.pub"
;
subTopology
.
userName
=
userName
;
Subnet
s
=
new
Subnet
();
...
...
@@ -43,40 +43,32 @@ public class P2PConverter {
s
.
subnet
=
"192.168.10.0"
;
s
.
netmask
=
"255.255.255.0"
;
subTopology
.
subnets
=
new
ArrayList
<
Subnet
>();
subTopology
.
subnets
=
new
ArrayList
<>();
subTopology
.
subnets
.
add
(
s
);
subTopology
.
components
=
new
ArrayList
<
VM
>();
subTopology
.
components
=
new
ArrayList
<>();
boolean
firstVM
=
true
;
for
(
int
vi
=
0
;
vi
<
plannerOutput
.
value
.
size
();
vi
++)
{
Value
curValue
=
plannerOutput
.
value
.
get
(
vi
);
int
count
=
0
;
for
(
Component
cmp
:
components
)
{
VM
curVM
=
new
VM
();
curVM
.
name
=
c
urValue
.
name
;
curVM
.
name
=
c
mp
.
getName
()
;
curVM
.
type
=
"Switch.nodes.Compute"
;
curVM
.
OStype
=
OStype
;
curVM
.
domain
=
"ec2.us-east-1.amazonaws.com"
;
curVM
.
clusterType
=
clusterType
;
curVM
.
dockers
=
curValue
.
docker
;
curVM
.
public_address
=
curValue
.
name
;
if
(
curValue
.
size
.
trim
().
toLowerCase
().
equals
(
"small"
))
{
curVM
.
nodeType
=
"t2.small"
;
}
else
if
(
curValue
.
size
.
trim
().
toLowerCase
().
equals
(
"medium"
))
{
curVM
.
nodeType
=
"t2.medium"
;
}
else
if
(
curValue
.
size
.
trim
().
toLowerCase
().
equals
(
"large"
))
{
curVM
.
nodeType
=
"t2.large"
;
}
else
{
throw
new
IllegalArgumentException
(
"Invalid value for field 'size' in input JSON String"
);
}
curVM
.
dockers
=
cmp
.
getDocker
();
curVM
.
public_address
=
cmp
.
getName
();
curVM
.
nodeType
=
"t2"
+
cmp
.
getSize
().
toLowerCase
();
Eth
eth
=
new
Eth
();
eth
.
name
=
"p1"
;
eth
.
subnet_name
=
"s1"
;
int
hostNum
=
10
+
vi
;
int
hostNum
=
10
+
count
++
;
String
priAddress
=
"192.168.10."
+
hostNum
;
eth
.
address
=
priAddress
;
curVM
.
ethernet_port
=
new
ArrayList
<
Eth
>();
curVM
.
ethernet_port
=
new
ArrayList
<>();
curVM
.
ethernet_port
.
add
(
eth
);
if
(
firstVM
)
{
curVM
.
role
=
"master"
;
...
...
@@ -89,7 +81,7 @@ public class P2PConverter {
sti
.
subTopology
=
subTopology
;
topTopology
.
topologies
=
new
ArrayList
<
SubTopologyInfo
>();
topTopology
.
topologies
=
new
ArrayList
<>();
topTopology
.
topologies
.
add
(
sti
);
SimplePlanContainer
spc
=
generateInfo
(
topTopology
);
...
...
@@ -97,11 +89,12 @@ public class P2PConverter {
return
spc
;
}
private
static
Parameter
getInfoFromPlanner
(
String
json
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
private
static
List
<
Component
>
getInfoFromPlanner
(
String
json
)
throws
IOException
{
ObjectMapper
mapper
=
new
ObjectMapper
();
PlannerOutput
po
=
mapper
.
readValue
(
json
,
PlannerOutput
.
class
);
System
.
out
.
println
(
""
);
return
po
.
parameters
.
get
(
0
);
TypeReference
<
List
<
Component
>>
mapType
=
new
TypeReference
<
List
<
Component
>>()
{
};
List
<
Component
>
components
=
mapper
.
readValue
(
json
,
mapType
);
return
components
;
}
private
static
SimplePlanContainer
generateInfo
(
TopTopology
topTopology
)
throws
JsonProcessingException
{
...
...
@@ -111,7 +104,7 @@ public class P2PConverter {
String
yamlString
=
mapper
.
writeValueAsString
(
topTopology
);
spc
.
topLevelContents
=
yamlString
.
substring
(
4
);
Map
<
String
,
String
>
output
=
new
HashMap
<
String
,
String
>();
Map
<
String
,
String
>
output
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
topTopology
.
topologies
.
size
();
i
++)
{
String
key
=
topTopology
.
topologies
.
get
(
i
).
topology
;
String
value
=
mapper
.
writeValueAsString
(
topTopology
.
topologies
.
get
(
i
).
subTopology
);
...
...
drip-planner2provisioner/src/main/java/nl/uva/sne/drip/drip/converter/planner/out/Component.java
0 → 100644
View file @
09026e0d
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
nl
.
uva
.
sne
.
drip
.
drip
.
converter
.
planner
.
out
;
/**
*
* @author S. Koulouzis
*/
public
class
Component
{
private
String
name
;
private
String
size
;
private
String
docker
;
/**
* @return the name
*/
public
String
getName
()
{
return
name
;
}
/**
* @param name the name to set
*/
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
/**
* @return the size
*/
public
String
getSize
()
{
return
size
;
}
/**
* @param size the size to set
*/
public
void
setSize
(
String
size
)
{
this
.
size
=
size
;
}
/**
* @return the docker
*/
public
String
getDocker
()
{
return
docker
;
}
/**
* @param docker the docker to set
*/
public
void
setDocker
(
String
docker
)
{
this
.
docker
=
docker
;
}
}
drip-planner2provisioner/src/main/java/nl/uva/sne/drip/drip/converter/planner/out/Parameter.java
deleted
100644 → 0
View file @
ea6686fc
package
nl
.
uva
.
sne
.
drip
.
drip
.
converter
.
planner
.
out
;
import
java.util.ArrayList
;
public
class
Parameter
{
public
String
url
;
public
String
attributes
;
public
ArrayList
<
Value
>
value
;
public
String
encoding
;
}
drip-planner2provisioner/src/main/java/nl/uva/sne/drip/drip/converter/planner/out/PlannerOutput.java
deleted
100644 → 0
View file @
ea6686fc
package
nl
.
uva
.
sne
.
drip
.
drip
.
converter
.
planner
.
out
;
import
java.util.ArrayList
;
public
class
PlannerOutput
{
public
String
creationDate
;
public
ArrayList
<
Parameter
>
parameters
;
}
drip-planner2provisioner/src/main/java/nl/uva/sne/drip/drip/converter/planner/out/Value.java
deleted
100644 → 0
View file @
ea6686fc
package
nl
.
uva
.
sne
.
drip
.
drip
.
converter
.
planner
.
out
;
public
class
Value
{
public
String
name
;
public
String
size
;
public
String
docker
;
}
drip-planner2provisioner/src/test/java/testConverter.java
View file @
09026e0d
...
...
@@ -23,7 +23,7 @@ public class testConverter {
}
try
{
SimplePlanContainer
spc
=
P2PConverter
.
transfer
(
json
,
"zh9314"
,
"Ubuntu 16.04"
,
"kubernetes"
);
SimplePlanContainer
spc
=
P2PConverter
.
convert
(
json
,
"zh9314"
,
"Ubuntu 16.04"
,
"kubernetes"
);
System
.
out
.
println
(
"--topLevel:\n"
+
spc
.
topLevelContents
);
System
.
out
.
println
(
"--lowLevel:"
);
for
(
Map
.
Entry
<
String
,
String
>
entry
:
spc
.
lowerLevelContents
.
entrySet
()){
...
...
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