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
ea6686fc
Commit
ea6686fc
authored
Mar 03, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added converter with hardcoded values
parent
33c29ff2
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
129 additions
and
110 deletions
+129
-110
pom.xml
drip-api/pom.xml
+7
-0
BadRequestException.java
...va/nl/uva/sne/drip/api/exception/BadRequestException.java
+5
-1
PlannerService.java
...main/java/nl/uva/sne/drip/api/service/PlannerService.java
+6
-4
pom.xml
drip-commons/pom.xml
+9
-0
CloudCredentials.java
.../java/nl/uva/sne/drip/commons/types/CloudCredentials.java
+0
-1
Converter.java
...rc/main/java/nl/uva/sne/drip/commons/utils/Converter.java
+4
-4
P2PConverter.java
...ain/java/nl/uva/sne/drip/drip/converter/P2PConverter.java
+98
-100
No files found.
drip-api/pom.xml
View file @
ea6686fc
...
...
@@ -119,6 +119,13 @@
<version>
1.3
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
nl.uva.sne.drip
</groupId>
<artifactId>
drip-planner2provisioner
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
</dependencies>
<build>
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/exception/BadRequestException.java
View file @
ea6686fc
...
...
@@ -22,11 +22,15 @@ import org.springframework.web.bind.annotation.ResponseStatus;
*
* @author S. Koulouzis
*/
@ResponseStatus
(
value
=
HttpStatus
.
BAD_REQUEST
,
reason
=
"MMMMMMMMMMMMMMMMMM"
)
@ResponseStatus
(
value
=
HttpStatus
.
BAD_REQUEST
)
public
class
BadRequestException
extends
RuntimeException
{
public
BadRequestException
(
String
massage
)
{
super
(
massage
);
}
public
BadRequestException
()
{
super
();
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/service/PlannerService.java
View file @
ea6686fc
...
...
@@ -33,6 +33,8 @@ import nl.uva.sne.drip.commons.types.MessageParameter;
import
nl.uva.sne.drip.commons.types.Plan
;
import
nl.uva.sne.drip.commons.types.ToscaRepresentation
;
import
nl.uva.sne.drip.commons.utils.Converter
;
import
nl.uva.sne.drip.drip.converter.P2PConverter
;
import
nl.uva.sne.drip.drip.converter.SimplePlanContainer
;
import
org.json.JSONException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
@@ -63,13 +65,13 @@ public class PlannerService {
ObjectMapper
mapper
=
new
ObjectMapper
();
mapper
.
configure
(
JsonParser
.
Feature
.
ALLOW_SINGLE_QUOTES
,
true
);
String
jsonString
=
mapper
.
writeValueAsString
(
plannerReturnedMessage
);
SimplePlanContainer
simplePlan
=
Converter
.
plannerOutput2SimplePlanContainer
(
jsonString
);
SimplePlanContainer
simplePlan
=
P2PConverter
.
transfer
(
jsonString
,
"zh9314"
,
"Ubuntu 16.04"
,
"swarm"
);
Plan
topLevel
=
new
Plan
();
topLevel
.
setLevel
(
0
);
topLevel
.
setToscaID
(
toscaId
);
topLevel
.
setName
(
"planner_output_all.yml"
);
topLevel
.
setKvMap
(
Converter
.
ymlString2Map
(
simplePlan
.
getTopLevel
()
));
Map
<
String
,
String
>
map
=
simplePlan
.
getLowerLevels
()
;
topLevel
.
setKvMap
(
Converter
.
ymlString2Map
(
simplePlan
.
topLevelContents
));
Map
<
String
,
String
>
map
=
simplePlan
.
lowerLevelContents
;
Set
<
String
>
loweLevelPlansIDs
=
new
HashSet
<>();
for
(
String
lowLevelNames
:
map
.
keySet
())
{
Plan
lowLevelPlan
=
new
Plan
();
...
...
@@ -90,7 +92,7 @@ public class PlannerService {
private
Message
buildPlannerMessage
(
String
toscaId
)
throws
JSONException
,
UnsupportedEncodingException
{
ToscaRepresentation
t2
=
toscaService
.
getDao
().
findOne
(
toscaId
);
if
(
t2
==
null
)
{
throw
new
BadRequestException
(
"The description: "
+
toscaId
+
" is a plan. Cannot be used as planner input"
);
throw
new
BadRequestException
();
}
Map
<
String
,
Object
>
map
=
t2
.
getKvMap
();
String
json
=
Converter
.
map2JsonString
(
map
);
...
...
drip-commons/pom.xml
View file @
ea6686fc
...
...
@@ -58,12 +58,21 @@
<version>
1.10.0.RELEASE
</version>
<type>
jar
</type>
</dependency>
<dependency>
<groupId>
org.springframework.security
</groupId>
<artifactId>
spring-security-core
</artifactId>
<version>
4.2.1.RELEASE
</version>
<type>
jar
</type>
</dependency>
<dependency>
<groupId>
nl.uva.sne.drip
</groupId>
<artifactId>
drip-planner2provisioner
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>
1.8
</maven.compiler.source>
...
...
drip-commons/src/main/java/nl/uva/sne/drip/commons/types/CloudCredentials.java
View file @
ea6686fc
...
...
@@ -30,7 +30,6 @@ public class CloudCredentials {
private
String
id
;
private
String
key
;
private
String
keyIdAlias
;
...
...
drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/Converter.java
View file @
ea6686fc
...
...
@@ -16,7 +16,9 @@
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
;
import
java.util.ArrayList
;
import
java.util.Enumeration
;
...
...
@@ -26,6 +28,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.SimplePlanContainer
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -71,10 +75,6 @@ public class Converter {
return
jsonObject2Map
(
jsonObject
);
}
public
static
SimplePlanContainer
plannerOutput2SimplePlanContainer
(
String
jsonString
)
throws
JSONException
{
return
null
;
}
public
static
Map
<
String
,
Object
>
jsonObject2Map
(
JSONObject
object
)
throws
JSONException
{
Map
<
String
,
Object
>
map
=
new
HashMap
();
...
...
drip-planner2provisioner/src/main/java/nl/uva/sne/drip/drip/converter/P2PConverter.java
View file @
ea6686fc
package
nl
.
uva
.
sne
.
drip
.
drip
.
converter
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
...
...
@@ -23,106 +22,105 @@ import nl.uva.sne.drip.drip.converter.provisioner.in.Subnet;
import
nl.uva.sne.drip.drip.converter.provisioner.in.TopTopology
;
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
{
Parameter
plannerOutput
=
getInfoFromPlanner
(
plannerOutputJson
);
TopTopology
topTopology
=
new
TopTopology
();
SubTopology
subTopology
=
new
SubTopology
();
SubTopologyInfo
sti
=
new
SubTopologyInfo
();
sti
.
cloudProvider
=
"EC2"
;
sti
.
topology
=
UUID
.
randomUUID
().
toString
();
subTopology
.
publicKeyPath
=
null
;
subTopology
.
userName
=
userName
;
Subnet
s
=
new
Subnet
();
s
.
name
=
"s1"
;
s
.
subnet
=
"192.168.10.0"
;
s
.
netmask
=
"255.255.255.0"
;
subTopology
.
subnets
=
new
ArrayList
<
Subnet
>();
subTopology
.
subnets
.
add
(
s
);
subTopology
.
components
=
new
ArrayList
<
VM
>();
boolean
firstVM
=
true
;
for
(
int
vi
=
0
;
vi
<
plannerOutput
.
value
.
size
()
;
vi
++)
{
Value
curValue
=
plannerOutput
.
value
.
get
(
vi
);
VM
curVM
=
new
VM
();
curVM
.
name
=
curValue
.
name
;
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"
);
}
Eth
eth
=
new
Eth
();
eth
.
name
=
"p1"
;
eth
.
subnet_name
=
"s1"
;
int
hostNum
=
10
+
vi
;
String
priAddress
=
"192.168.10."
+
hostNum
;
eth
.
address
=
priAddress
;
curVM
.
ethernet_port
=
new
ArrayList
<
Eth
>();
curVM
.
ethernet_port
.
add
(
eth
);
if
(
firstVM
)
{
curVM
.
role
=
"master"
;
firstVM
=
false
;
}
else
curVM
.
role
=
"slave"
;
subTopology
.
components
.
add
(
curVM
);
}
sti
.
subTopology
=
subTopology
;
topTopology
.
topologies
=
new
ArrayList
<
SubTopologyInfo
>();
topTopology
.
topologies
.
add
(
sti
);
SimplePlanContainer
spc
=
generateInfo
(
topTopology
);
return
spc
;
}
private
static
Parameter
getInfoFromPlanner
(
String
json
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
ObjectMapper
mapper
=
new
ObjectMapper
();
PlannerOutput
po
=
mapper
.
readValue
(
json
,
PlannerOutput
.
class
);
System
.
out
.
println
(
""
);
return
po
.
parameters
.
get
(
0
);
}
private
static
SimplePlanContainer
generateInfo
(
TopTopology
topTopology
)
throws
JsonProcessingException
{
SimplePlanContainer
spc
=
new
SimplePlanContainer
();
ObjectMapper
mapper
=
new
ObjectMapper
(
new
YAMLFactory
()
);
String
yamlString
=
mapper
.
writeValueAsString
(
topTopology
);
spc
.
topLevelContents
=
yamlString
.
substring
(
4
);
Map
<
String
,
String
>
output
=
new
HashMap
<
String
,
String
>();
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
)
;
output
.
put
(
key
,
value
.
substring
(
4
)
);
}
spc
.
lowerLevelContents
=
output
;
return
spc
;
}
public
static
SimplePlanContainer
transfer
(
String
plannerOutputJson
,
String
userName
,
String
OStype
,
String
clusterType
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
Parameter
plannerOutput
=
getInfoFromPlanner
(
plannerOutputJson
);
TopTopology
topTopology
=
new
TopTopology
();
SubTopology
subTopology
=
new
SubTopology
();
SubTopologyInfo
sti
=
new
SubTopologyInfo
();
sti
.
cloudProvider
=
"EC2"
;
sti
.
topology
=
UUID
.
randomUUID
().
toString
();
subTopology
.
publicKeyPath
=
null
;
subTopology
.
userName
=
userName
;
Subnet
s
=
new
Subnet
();
s
.
name
=
"s1"
;
s
.
subnet
=
"192.168.10.0"
;
s
.
netmask
=
"255.255.255.0"
;
subTopology
.
subnets
=
new
ArrayList
<
Subnet
>();
subTopology
.
subnets
.
add
(
s
);
subTopology
.
components
=
new
ArrayList
<
VM
>();
boolean
firstVM
=
true
;
for
(
int
vi
=
0
;
vi
<
plannerOutput
.
value
.
size
();
vi
++)
{
Value
curValue
=
plannerOutput
.
value
.
get
(
vi
);
VM
curVM
=
new
VM
();
curVM
.
name
=
curValue
.
name
;
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"
);
}
Eth
eth
=
new
Eth
();
eth
.
name
=
"p1"
;
eth
.
subnet_name
=
"s1"
;
int
hostNum
=
10
+
vi
;
String
priAddress
=
"192.168.10."
+
hostNum
;
eth
.
address
=
priAddress
;
curVM
.
ethernet_port
=
new
ArrayList
<
Eth
>();
curVM
.
ethernet_port
.
add
(
eth
);
if
(
firstVM
)
{
curVM
.
role
=
"master"
;
firstVM
=
false
;
}
else
{
curVM
.
role
=
"slave"
;
}
subTopology
.
components
.
add
(
curVM
);
}
sti
.
subTopology
=
subTopology
;
topTopology
.
topologies
=
new
ArrayList
<
SubTopologyInfo
>(
);
topTopology
.
topologies
.
add
(
sti
);
SimplePlanContainer
spc
=
generateInfo
(
topTopology
);
return
spc
;
}
private
static
Parameter
getInfoFromPlanner
(
String
json
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
ObjectMapper
mapper
=
new
ObjectMapper
(
);
PlannerOutput
po
=
mapper
.
readValue
(
json
,
PlannerOutput
.
class
);
System
.
out
.
println
(
""
);
return
po
.
parameters
.
get
(
0
);
}
private
static
SimplePlanContainer
generateInfo
(
TopTopology
topTopology
)
throws
JsonProcessingException
{
SimplePlanContainer
spc
=
new
SimplePlanContainer
(
);
ObjectMapper
mapper
=
new
ObjectMapper
(
new
YAMLFactory
());
String
yamlString
=
mapper
.
writeValueAsString
(
topTopology
);
spc
.
topLevelContents
=
yamlString
.
substring
(
4
);
Map
<
String
,
String
>
output
=
new
HashMap
<
String
,
String
>();
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
);
output
.
put
(
key
,
value
.
substring
(
4
));
}
spc
.
lowerLevelContents
=
output
;
return
spc
;
}
}
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