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 @@
...
@@ -119,6 +119,13 @@
<version>
1.3
</version>
<version>
1.3
</version>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
nl.uva.sne.drip
</groupId>
<artifactId>
drip-planner2provisioner
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<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;
...
@@ -22,11 +22,15 @@ import org.springframework.web.bind.annotation.ResponseStatus;
*
*
* @author S. Koulouzis
* @author S. Koulouzis
*/
*/
@ResponseStatus
(
value
=
HttpStatus
.
BAD_REQUEST
,
reason
=
"MMMMMMMMMMMMMMMMMM"
)
@ResponseStatus
(
value
=
HttpStatus
.
BAD_REQUEST
)
public
class
BadRequestException
extends
RuntimeException
{
public
class
BadRequestException
extends
RuntimeException
{
public
BadRequestException
(
String
massage
)
{
public
BadRequestException
(
String
massage
)
{
super
(
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;
...
@@ -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.Plan
;
import
nl.uva.sne.drip.commons.types.ToscaRepresentation
;
import
nl.uva.sne.drip.commons.types.ToscaRepresentation
;
import
nl.uva.sne.drip.commons.utils.Converter
;
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.json.JSONException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
...
@@ -63,13 +65,13 @@ public class PlannerService {
...
@@ -63,13 +65,13 @@ public class PlannerService {
ObjectMapper
mapper
=
new
ObjectMapper
();
ObjectMapper
mapper
=
new
ObjectMapper
();
mapper
.
configure
(
JsonParser
.
Feature
.
ALLOW_SINGLE_QUOTES
,
true
);
mapper
.
configure
(
JsonParser
.
Feature
.
ALLOW_SINGLE_QUOTES
,
true
);
String
jsonString
=
mapper
.
writeValueAsString
(
plannerReturnedMessage
);
String
jsonString
=
mapper
.
writeValueAsString
(
plannerReturnedMessage
);
SimplePlanContainer
simplePlan
=
Converter
.
plannerOutput2SimplePlanContainer
(
jsonString
);
SimplePlanContainer
simplePlan
=
P2PConverter
.
transfer
(
jsonString
,
"zh9314"
,
"Ubuntu 16.04"
,
"swarm"
);
Plan
topLevel
=
new
Plan
();
Plan
topLevel
=
new
Plan
();
topLevel
.
setLevel
(
0
);
topLevel
.
setLevel
(
0
);
topLevel
.
setToscaID
(
toscaId
);
topLevel
.
setToscaID
(
toscaId
);
topLevel
.
setName
(
"planner_output_all.yml"
);
topLevel
.
setName
(
"planner_output_all.yml"
);
topLevel
.
setKvMap
(
Converter
.
ymlString2Map
(
simplePlan
.
getTopLevel
()
));
topLevel
.
setKvMap
(
Converter
.
ymlString2Map
(
simplePlan
.
topLevelContents
));
Map
<
String
,
String
>
map
=
simplePlan
.
getLowerLevels
()
;
Map
<
String
,
String
>
map
=
simplePlan
.
lowerLevelContents
;
Set
<
String
>
loweLevelPlansIDs
=
new
HashSet
<>();
Set
<
String
>
loweLevelPlansIDs
=
new
HashSet
<>();
for
(
String
lowLevelNames
:
map
.
keySet
())
{
for
(
String
lowLevelNames
:
map
.
keySet
())
{
Plan
lowLevelPlan
=
new
Plan
();
Plan
lowLevelPlan
=
new
Plan
();
...
@@ -90,7 +92,7 @@ public class PlannerService {
...
@@ -90,7 +92,7 @@ public class PlannerService {
private
Message
buildPlannerMessage
(
String
toscaId
)
throws
JSONException
,
UnsupportedEncodingException
{
private
Message
buildPlannerMessage
(
String
toscaId
)
throws
JSONException
,
UnsupportedEncodingException
{
ToscaRepresentation
t2
=
toscaService
.
getDao
().
findOne
(
toscaId
);
ToscaRepresentation
t2
=
toscaService
.
getDao
().
findOne
(
toscaId
);
if
(
t2
==
null
)
{
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
();
Map
<
String
,
Object
>
map
=
t2
.
getKvMap
();
String
json
=
Converter
.
map2JsonString
(
map
);
String
json
=
Converter
.
map2JsonString
(
map
);
...
...
drip-commons/pom.xml
View file @
ea6686fc
...
@@ -58,12 +58,21 @@
...
@@ -58,12 +58,21 @@
<version>
1.10.0.RELEASE
</version>
<version>
1.10.0.RELEASE
</version>
<type>
jar
</type>
<type>
jar
</type>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.security
</groupId>
<groupId>
org.springframework.security
</groupId>
<artifactId>
spring-security-core
</artifactId>
<artifactId>
spring-security-core
</artifactId>
<version>
4.2.1.RELEASE
</version>
<version>
4.2.1.RELEASE
</version>
<type>
jar
</type>
<type>
jar
</type>
</dependency>
</dependency>
<dependency>
<groupId>
nl.uva.sne.drip
</groupId>
<artifactId>
drip-planner2provisioner
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
</dependencies>
</dependencies>
<properties>
<properties>
<maven.compiler.source>
1.8
</maven.compiler.source>
<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 {
...
@@ -30,7 +30,6 @@ public class CloudCredentials {
private
String
id
;
private
String
id
;
private
String
key
;
private
String
key
;
private
String
keyIdAlias
;
private
String
keyIdAlias
;
...
...
drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/Converter.java
View file @
ea6686fc
...
@@ -16,7 +16,9 @@
...
@@ -16,7 +16,9 @@
package
nl
.
uva
.
sne
.
drip
.
commons
.
utils
;
package
nl
.
uva
.
sne
.
drip
.
commons
.
utils
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.JsonMappingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Enumeration
;
import
java.util.Enumeration
;
...
@@ -26,6 +28,8 @@ import java.util.List;
...
@@ -26,6 +28,8 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.Properties
;
import
nl.uva.sne.drip.commons.types.CloudCredentials
;
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.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
...
@@ -71,10 +75,6 @@ public class Converter {
...
@@ -71,10 +75,6 @@ public class Converter {
return
jsonObject2Map
(
jsonObject
);
return
jsonObject2Map
(
jsonObject
);
}
}
public
static
SimplePlanContainer
plannerOutput2SimplePlanContainer
(
String
jsonString
)
throws
JSONException
{
return
null
;
}
public
static
Map
<
String
,
Object
>
jsonObject2Map
(
JSONObject
object
)
throws
JSONException
{
public
static
Map
<
String
,
Object
>
jsonObject2Map
(
JSONObject
object
)
throws
JSONException
{
Map
<
String
,
Object
>
map
=
new
HashMap
();
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
;
package
nl
.
uva
.
sne
.
drip
.
drip
.
converter
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -23,106 +22,105 @@ import nl.uva.sne.drip.drip.converter.provisioner.in.Subnet;
...
@@ -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.TopTopology
;
import
nl.uva.sne.drip.drip.converter.provisioner.in.VM
;
import
nl.uva.sne.drip.drip.converter.provisioner.in.VM
;
public
class
P2PConverter
{
public
class
P2PConverter
{
public
static
SimplePlanContainer
transfer
(
String
plannerOutputJson
,
String
userName
,
String
OStype
,
String
clusterType
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
public
static
SimplePlanContainer
transfer
(
String
plannerOutputJson
,
String
userName
,
String
OStype
,
String
clusterType
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
Parameter
plannerOutput
=
getInfoFromPlanner
(
plannerOutputJson
);
Parameter
plannerOutput
=
getInfoFromPlanner
(
plannerOutputJson
);
TopTopology
topTopology
=
new
TopTopology
();
TopTopology
topTopology
=
new
TopTopology
();
SubTopology
subTopology
=
new
SubTopology
();
SubTopology
subTopology
=
new
SubTopology
();
SubTopologyInfo
sti
=
new
SubTopologyInfo
();
SubTopologyInfo
sti
=
new
SubTopologyInfo
();
sti
.
cloudProvider
=
"EC2"
;
sti
.
cloudProvider
=
"EC2"
;
sti
.
topology
=
UUID
.
randomUUID
().
toString
();
sti
.
topology
=
UUID
.
randomUUID
().
toString
();
subTopology
.
publicKeyPath
=
null
;
subTopology
.
publicKeyPath
=
null
;
subTopology
.
userName
=
userName
;
subTopology
.
userName
=
userName
;
Subnet
s
=
new
Subnet
();
Subnet
s
=
new
Subnet
();
s
.
name
=
"s1"
;
s
.
name
=
"s1"
;
s
.
subnet
=
"192.168.10.0"
;
s
.
subnet
=
"192.168.10.0"
;
s
.
netmask
=
"255.255.255.0"
;
s
.
netmask
=
"255.255.255.0"
;
subTopology
.
subnets
=
new
ArrayList
<
Subnet
>();
subTopology
.
subnets
=
new
ArrayList
<
Subnet
>();
subTopology
.
subnets
.
add
(
s
);
subTopology
.
subnets
.
add
(
s
);
subTopology
.
components
=
new
ArrayList
<
VM
>();
subTopology
.
components
=
new
ArrayList
<
VM
>();
boolean
firstVM
=
true
;
boolean
firstVM
=
true
;
for
(
int
vi
=
0
;
vi
<
plannerOutput
.
value
.
size
()
;
vi
++)
{
for
(
int
vi
=
0
;
vi
<
plannerOutput
.
value
.
size
();
vi
++)
{
Value
curValue
=
plannerOutput
.
value
.
get
(
vi
);
Value
curValue
=
plannerOutput
.
value
.
get
(
vi
);
VM
curVM
=
new
VM
();
VM
curVM
=
new
VM
();
curVM
.
name
=
curValue
.
name
;
curVM
.
name
=
curValue
.
name
;
curVM
.
type
=
"Switch.nodes.Compute"
;
curVM
.
type
=
"Switch.nodes.Compute"
;
curVM
.
OStype
=
OStype
;
curVM
.
OStype
=
OStype
;
curVM
.
domain
=
"ec2.us-east-1.amazonaws.com"
;
curVM
.
domain
=
"ec2.us-east-1.amazonaws.com"
;
curVM
.
clusterType
=
clusterType
;
curVM
.
clusterType
=
clusterType
;
curVM
.
dockers
=
curValue
.
docker
;
curVM
.
dockers
=
curValue
.
docker
;
curVM
.
public_address
=
curValue
.
name
;
curVM
.
public_address
=
curValue
.
name
;
if
(
curValue
.
size
.
trim
().
toLowerCase
().
equals
(
"small"
))
if
(
curValue
.
size
.
trim
().
toLowerCase
().
equals
(
"small"
))
{
curVM
.
nodeType
=
"t2.small"
;
curVM
.
nodeType
=
"t2.small"
;
else
if
(
curValue
.
size
.
trim
().
toLowerCase
().
equals
(
"medium"
))
}
else
if
(
curValue
.
size
.
trim
().
toLowerCase
().
equals
(
"medium"
))
{
curVM
.
nodeType
=
"t2.medium"
;
curVM
.
nodeType
=
"t2.medium"
;
else
if
(
curValue
.
size
.
trim
().
toLowerCase
().
equals
(
"large"
))
}
else
if
(
curValue
.
size
.
trim
().
toLowerCase
().
equals
(
"large"
))
{
curVM
.
nodeType
=
"t2.large"
;
curVM
.
nodeType
=
"t2.large"
;
else
{
}
else
{
throw
new
IllegalArgumentException
(
"Invalid value for field 'size' in input JSON String"
);
throw
new
IllegalArgumentException
(
"Invalid value for field 'size' in input JSON String"
);
}
}
Eth
eth
=
new
Eth
();
Eth
eth
=
new
Eth
();
eth
.
name
=
"p1"
;
eth
.
name
=
"p1"
;
eth
.
subnet_name
=
"s1"
;
eth
.
subnet_name
=
"s1"
;
int
hostNum
=
10
+
vi
;
int
hostNum
=
10
+
vi
;
String
priAddress
=
"192.168.10."
+
hostNum
;
String
priAddress
=
"192.168.10."
+
hostNum
;
eth
.
address
=
priAddress
;
eth
.
address
=
priAddress
;
curVM
.
ethernet_port
=
new
ArrayList
<
Eth
>();
curVM
.
ethernet_port
=
new
ArrayList
<
Eth
>();
curVM
.
ethernet_port
.
add
(
eth
);
curVM
.
ethernet_port
.
add
(
eth
);
if
(
firstVM
)
{
if
(
firstVM
)
{
curVM
.
role
=
"master"
;
curVM
.
role
=
"master"
;
firstVM
=
false
;
firstVM
=
false
;
}
else
}
else
{
curVM
.
role
=
"slave"
;
curVM
.
role
=
"slave"
;
subTopology
.
components
.
add
(
curVM
);
}
}
subTopology
.
components
.
add
(
curVM
);
}
sti
.
subTopology
=
subTopology
;
sti
.
subTopology
=
subTopology
;
topTopology
.
topologies
=
new
ArrayList
<
SubTopologyInfo
>();
topTopology
.
topologies
.
add
(
sti
);
topTopology
.
topologies
=
new
ArrayList
<
SubTopologyInfo
>(
);
topTopology
.
topologies
.
add
(
sti
);
SimplePlanContainer
spc
=
generateInfo
(
topTopology
);
SimplePlanContainer
spc
=
generateInfo
(
topTopology
);
return
spc
;
}
return
spc
;
}
private
static
Parameter
getInfoFromPlanner
(
String
json
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
ObjectMapper
mapper
=
new
ObjectMapper
();
private
static
Parameter
getInfoFromPlanner
(
String
json
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
PlannerOutput
po
=
mapper
.
readValue
(
json
,
PlannerOutput
.
class
);
ObjectMapper
mapper
=
new
ObjectMapper
(
);
System
.
out
.
println
(
""
);
PlannerOutput
po
=
mapper
.
readValue
(
json
,
PlannerOutput
.
class
);
return
po
.
parameters
.
get
(
0
);
System
.
out
.
println
(
""
);
}
return
po
.
parameters
.
get
(
0
);
}
private
static
SimplePlanContainer
generateInfo
(
TopTopology
topTopology
)
throws
JsonProcessingException
{
SimplePlanContainer
spc
=
new
SimplePlanContainer
();
private
static
SimplePlanContainer
generateInfo
(
TopTopology
topTopology
)
throws
JsonProcessingException
{
ObjectMapper
mapper
=
new
ObjectMapper
(
new
YAMLFactory
()
);
SimplePlanContainer
spc
=
new
SimplePlanContainer
(
);
ObjectMapper
mapper
=
new
ObjectMapper
(
new
YAMLFactory
());
String
yamlString
=
mapper
.
writeValueAsString
(
topTopology
);
spc
.
topLevelContents
=
yamlString
.
substring
(
4
);
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
++){
Map
<
String
,
String
>
output
=
new
HashMap
<
String
,
String
>();
String
key
=
topTopology
.
topologies
.
get
(
i
).
topology
;
for
(
int
i
=
0
;
i
<
topTopology
.
topologies
.
size
();
i
++)
{
String
value
=
mapper
.
writeValueAsString
(
topTopology
.
topologies
.
get
(
i
).
subTopology
)
;
String
key
=
topTopology
.
topologies
.
get
(
i
).
topology
;
output
.
put
(
key
,
value
.
substring
(
4
)
);
String
value
=
mapper
.
writeValueAsString
(
topTopology
.
topologies
.
get
(
i
).
subTopology
);
}
output
.
put
(
key
,
value
.
substring
(
4
));
}
spc
.
lowerLevelContents
=
output
;
spc
.
lowerLevelContents
=
output
;
return
spc
;
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