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
1611ae99
Commit
1611ae99
authored
Mar 01, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor data types: Each agent has its own data type
parent
75da4d65
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
454 additions
and
159 deletions
+454
-159
PlanDao.java
drip-api/src/main/java/nl/uva/sne/drip/api/dao/PlanDao.java
+27
-0
ProvisionDao.java
...i/src/main/java/nl/uva/sne/drip/api/dao/ProvisionDao.java
+27
-0
PlannerController.java
...main/java/nl/uva/sne/drip/api/rest/PlannerController.java
+14
-8
ProvisionController.java
...in/java/nl/uva/sne/drip/api/rest/ProvisionController.java
+62
-25
ToscaController.java
...c/main/java/nl/uva/sne/drip/api/rest/ToscaController.java
+4
-5
PlannerService.java
...main/java/nl/uva/sne/drip/api/service/PlannerService.java
+1
-2
ProvisionService.java
...in/java/nl/uva/sne/drip/api/service/ProvisionService.java
+45
-0
SimplePlannerService.java
...ava/nl/uva/sne/drip/api/service/SimplePlannerService.java
+80
-26
ToscaService.java
...c/main/java/nl/uva/sne/drip/api/service/ToscaService.java
+10
-34
Plan.java
...ons/src/main/java/nl/uva/sne/drip/commons/types/Plan.java
+120
-0
Provision.java
...rc/main/java/nl/uva/sne/drip/commons/types/Provision.java
+37
-1
ToscaRepresentation.java
...va/nl/uva/sne/drip/commons/types/ToscaRepresentation.java
+1
-55
Consumer.java
.../main/java/nl/uva/sne/drip/drip/provisioner/Consumer.java
+26
-3
No files found.
drip-api/src/main/java/nl/uva/sne/drip/api/dao/PlanDao.java
0 → 100644
View file @
1611ae99
/*
* 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
.
api
.
dao
;
import
nl.uva.sne.drip.commons.types.Plan
;
import
org.springframework.data.mongodb.repository.MongoRepository
;
/**
*
* @author S. Koulouzis
*/
public
interface
PlanDao
extends
MongoRepository
<
Plan
,
String
>
{
}
drip-api/src/main/java/nl/uva/sne/drip/api/dao/ProvisionDao.java
0 → 100644
View file @
1611ae99
/*
* 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
.
api
.
dao
;
import
nl.uva.sne.drip.commons.types.Provision
;
import
org.springframework.data.mongodb.repository.MongoRepository
;
/**
*
* @author S. Koulouzis
*/
public
interface
ProvisionDao
extends
MongoRepository
<
Provision
,
String
>
{
}
drip-api/src/main/java/nl/uva/sne/drip/api/rest/PlannerController.java
View file @
1611ae99
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
package
nl
.
uva
.
sne
.
drip
.
api
.
rest
;
package
nl
.
uva
.
sne
.
drip
.
api
.
rest
;
import
nl.uva.sne.drip.api.service.SimplePlannerService
;
import
nl.uva.sne.drip.api.service.SimplePlannerService
;
import
nl.uva.sne.drip.commons.types.ToscaRepresentation
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -36,6 +35,7 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -36,6 +35,7 @@ import org.springframework.web.bind.annotation.RestController;
import
nl.uva.sne.drip.api.service.PlannerService
;
import
nl.uva.sne.drip.api.service.PlannerService
;
import
nl.uva.sne.drip.api.service.ToscaService
;
import
nl.uva.sne.drip.api.service.ToscaService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.commons.types.Plan
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RequestParam
;
/**
/**
...
@@ -62,8 +62,8 @@ public class PlannerController {
...
@@ -62,8 +62,8 @@ public class PlannerController {
String
plan
(
@PathVariable
(
"tosca_id"
)
String
toscaId
)
{
String
plan
(
@PathVariable
(
"tosca_id"
)
String
toscaId
)
{
try
{
try
{
ToscaRepresentatio
n
plan
=
simplePlannerService
.
getPlan
(
toscaId
);
Pla
n
plan
=
simplePlannerService
.
getPlan
(
toscaId
);
//
ToscaRepresentatio
n plan = plannerService.getPlan(toscaId);
//
Pla
n plan = plannerService.getPlan(toscaId);
if
(
plan
==
null
)
{
if
(
plan
==
null
)
{
throw
new
NotFoundException
(
"Could not make plan"
);
throw
new
NotFoundException
(
"Could not make plan"
);
}
}
...
@@ -79,29 +79,35 @@ public class PlannerController {
...
@@ -79,29 +79,35 @@ public class PlannerController {
public
@ResponseBody
public
@ResponseBody
String
get
(
@PathVariable
(
"id"
)
String
id
,
@RequestParam
(
value
=
"format"
)
String
format
)
{
String
get
(
@PathVariable
(
"id"
)
String
id
,
@RequestParam
(
value
=
"format"
)
String
format
)
{
try
{
try
{
return
toscaService
.
get
(
id
,
format
,
ToscaRepresentation
.
Type
.
PLAN
);
return
simplePlannerService
.
get
(
id
,
format
);
}
catch
(
JSONException
ex
)
{
}
catch
(
JSONException
ex
)
{
Logger
.
getLogger
(
ToscaController
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
Logger
.
getLogger
(
ToscaController
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
return
null
;
return
null
;
}
}
@RequestMapping
(
value
=
"/tosca/{id}"
,
method
=
RequestMethod
.
GET
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
String
getToscaID
(
@PathVariable
(
"id"
)
String
id
)
{
return
simplePlannerService
.
getToscaID
(
id
);
}
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
DELETE
)
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
DELETE
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
public
@ResponseBody
String
delete
(
@PathVariable
(
"id"
)
String
id
)
{
String
delete
(
@PathVariable
(
"id"
)
String
id
)
{
toscaService
.
delete
(
id
,
ToscaRepresentation
.
Type
.
PLAN
);
simplePlannerService
.
getDao
().
delete
(
id
);
return
"Deleted tosca :"
+
id
;
return
"Deleted tosca :"
+
id
;
}
}
// http://localhost:8080/drip-api/tosca/ids
@RequestMapping
(
value
=
"/ids"
)
@RequestMapping
(
value
=
"/ids"
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
public
@ResponseBody
List
<
String
>
getIds
()
{
List
<
String
>
getIds
()
{
List
<
ToscaRepresentation
>
all
=
toscaService
.
findAll
(
ToscaRepresentation
.
Type
.
PLAN
);
List
<
Plan
>
all
=
simplePlannerService
.
findAll
(
);
List
<
String
>
ids
=
new
ArrayList
<>();
List
<
String
>
ids
=
new
ArrayList
<>();
for
(
ToscaRepresentatio
n
tr
:
all
)
{
for
(
Pla
n
tr
:
all
)
{
ids
.
add
(
tr
.
getId
());
ids
.
add
(
tr
.
getId
());
}
}
return
ids
;
return
ids
;
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/rest/ProvisionController.java
View file @
1611ae99
...
@@ -15,10 +15,11 @@
...
@@ -15,10 +15,11 @@
*/
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
rest
;
package
nl
.
uva
.
sne
.
drip
.
api
.
rest
;
import
nl.uva.sne.drip.commons.types.ProvisionRequest
;
import
com.fasterxml.jackson.core.JsonParser
;
import
nl.uva.sne.drip.commons.types.Provision
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
nl.uva.sne.drip.commons.types.ToscaRepresentation
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -46,14 +47,17 @@ import nl.uva.sne.drip.api.exception.BadRequestException;
...
@@ -46,14 +47,17 @@ import nl.uva.sne.drip.api.exception.BadRequestException;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
import
nl.uva.sne.drip.api.rpc.DRIPCaller
;
import
nl.uva.sne.drip.api.rpc.DRIPCaller
;
import
nl.uva.sne.drip.api.rpc.ProvisionerCaller
;
import
nl.uva.sne.drip.api.rpc.ProvisionerCaller
;
import
nl.uva.sne.drip.api.service.ToscaService
;
import
nl.uva.sne.drip.api.service.ProvisionService
;
import
nl.uva.sne.drip.api.service.SimplePlannerService
;
import
nl.uva.sne.drip.api.service.UserKeyService
;
import
nl.uva.sne.drip.api.service.UserKeyService
;
import
nl.uva.sne.drip.api.service.UserScriptService
;
import
nl.uva.sne.drip.api.service.UserScriptService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.commons.types.CloudCredentials
;
import
nl.uva.sne.drip.commons.types.CloudCredentials
;
import
nl.uva.sne.drip.commons.types.LoginKey
;
import
nl.uva.sne.drip.commons.types.LoginKey
;
import
nl.uva.sne.drip.commons.types.Plan
;
import
nl.uva.sne.drip.commons.types.UserScript
;
import
nl.uva.sne.drip.commons.types.UserScript
;
import
org.apache.commons.io.FilenameUtils
;
import
org.apache.commons.io.FilenameUtils
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
/**
/**
...
@@ -68,9 +72,6 @@ public class ProvisionController {
...
@@ -68,9 +72,6 @@ public class ProvisionController {
@Value
(
"${message.broker.host}"
)
@Value
(
"${message.broker.host}"
)
private
String
messageBrokerHost
;
private
String
messageBrokerHost
;
@Autowired
private
ToscaService
toscaService
;
@Autowired
@Autowired
private
UserScriptService
userScriptService
;
private
UserScriptService
userScriptService
;
...
@@ -80,35 +81,48 @@ public class ProvisionController {
...
@@ -80,35 +81,48 @@ public class ProvisionController {
@Autowired
@Autowired
private
CloudCredentialsDao
cloudCredentialsDao
;
private
CloudCredentialsDao
cloudCredentialsDao
;
@RequestMapping
(
value
=
"/get"
,
method
=
RequestMethod
.
GET
)
@Autowired
private
ProvisionService
provisionService
;
@Autowired
private
SimplePlannerService
planService
;
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
GET
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
public
@ResponseBody
ProvisionRequest
get
()
{
Provision
get
(
@PathVariable
(
"id"
)
String
id
)
{
ProvisionRequest
re
=
new
ProvisionRequest
();
return
provisionService
.
getDao
().
findOne
(
id
);
re
.
setCloudConfID
(
"58a1f0a963d42f004b1d63ad"
);
re
.
setPlanID
(
"58ad99d578b6ba941aeb22a4"
);
re
.
setUserKeyID
(
"58a20be263d4a5898835676e"
);
re
.
setUserScriptID
(
"58a2112363d41754cca042b4"
);
return
re
;
}
}
@RequestMapping
(
value
=
"/provision"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/provision"
,
method
=
RequestMethod
.
POST
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
public
@ResponseBody
String
plann
(
@RequestBody
ProvisionRequest
req
)
{
String
plann
(
@RequestBody
Provision
req
)
{
try
(
DRIPCaller
provisioner
=
new
ProvisionerCaller
(
messageBrokerHost
);)
{
try
(
DRIPCaller
provisioner
=
new
ProvisionerCaller
(
messageBrokerHost
);)
{
Message
provisionerInvokationMessage
=
buildProvisionerMessage
(
req
);
Message
provisionerInvokationMessage
=
buildProvisionerMessage
(
req
);
Message
response
=
provisioner
.
call
(
provisionerInvokationMessage
);
// Message response = provisioner.call(provisionerInvokationMessage);
return
""
;
Message
response
=
generateFakeResponse
();
List
<
Parameter
>
params
=
response
.
getParameters
();
for
(
Parameter
p
:
params
)
{
String
name
=
p
.
getName
();
if
(!
name
.
equals
(
"kubernetes"
))
{
String
value
=
p
.
getValue
();
Map
<
String
,
Object
>
kvMap
=
Converter
.
ymlString2Map
(
value
);
req
.
setKvMap
(
kvMap
);
req
.
setPlanID
(
req
.
getPlanID
());
provisionService
.
getDao
().
save
(
req
);
}
}
return
req
.
getId
();
}
catch
(
IOException
|
TimeoutException
|
JSONException
|
InterruptedException
ex
)
{
}
catch
(
IOException
|
TimeoutException
|
JSONException
|
InterruptedException
ex
)
{
Logger
.
getLogger
(
ProvisionController
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
Logger
.
getLogger
(
ProvisionController
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
return
null
;
return
null
;
}
}
private
Message
buildProvisionerMessage
(
Provision
Request
pReq
)
throws
JSONException
,
IOException
{
private
Message
buildProvisionerMessage
(
Provision
pReq
)
throws
JSONException
,
IOException
{
Message
invokationMessage
=
new
Message
();
Message
invokationMessage
=
new
Message
();
List
<
Parameter
>
parameters
=
new
ArrayList
();
List
<
Parameter
>
parameters
=
new
ArrayList
();
CloudCredentials
cred
=
cloudCredentialsDao
.
findOne
(
pReq
.
getCloudConfID
());
CloudCredentials
cred
=
cloudCredentialsDao
.
findOne
(
pReq
.
getCloudConfID
());
...
@@ -178,7 +192,7 @@ public class ProvisionController {
...
@@ -178,7 +192,7 @@ public class ProvisionController {
}
}
private
List
<
Parameter
>
buildTopologyParams
(
String
planID
)
throws
JSONException
{
private
List
<
Parameter
>
buildTopologyParams
(
String
planID
)
throws
JSONException
{
ToscaRepresentation
plan
=
toscaService
.
get
(
planID
,
ToscaRepresentation
.
Type
.
PLAN
);
Plan
plan
=
planService
.
getDao
().
findOne
(
planID
);
if
(
plan
==
null
)
{
if
(
plan
==
null
)
{
throw
new
NotFoundException
();
throw
new
NotFoundException
();
}
}
...
@@ -192,15 +206,15 @@ public class ProvisionController {
...
@@ -192,15 +206,15 @@ public class ProvisionController {
topology
.
setAttributes
(
attributes
);
topology
.
setAttributes
(
attributes
);
parameters
.
add
(
topology
);
parameters
.
add
(
topology
);
Set
<
String
>
ids
=
plan
.
getLowe
rLevel
IDs
();
Set
<
String
>
ids
=
plan
.
getLowe
LevelPlan
IDs
();
for
(
String
lowID
:
ids
)
{
for
(
String
lowID
:
ids
)
{
plan
=
toscaService
.
get
(
lowID
,
ToscaRepresentation
.
Type
.
PLAN
);
Plan
lowPlan
=
planService
.
getDao
().
findOne
(
lowID
);
topology
=
new
Parameter
();
topology
=
new
Parameter
();
topology
.
setName
(
"topology"
);
topology
.
setName
(
"topology"
);
topology
.
setValue
(
Converter
.
map2YmlString
(
p
lan
.
getKvMap
()));
topology
.
setValue
(
Converter
.
map2YmlString
(
lowP
lan
.
getKvMap
()));
attributes
=
new
HashMap
<>();
attributes
=
new
HashMap
<>();
attributes
.
put
(
"level"
,
String
.
valueOf
(
p
lan
.
getLevel
()));
attributes
.
put
(
"level"
,
String
.
valueOf
(
lowP
lan
.
getLevel
()));
attributes
.
put
(
"filename"
,
FilenameUtils
.
removeExtension
(
p
lan
.
getName
()));
attributes
.
put
(
"filename"
,
FilenameUtils
.
removeExtension
(
lowP
lan
.
getName
()));
topology
.
setAttributes
(
attributes
);
topology
.
setAttributes
(
attributes
);
parameters
.
add
(
topology
);
parameters
.
add
(
topology
);
}
}
...
@@ -249,4 +263,27 @@ public class ProvisionController {
...
@@ -249,4 +263,27 @@ public class ProvisionController {
return
parameters
;
return
parameters
;
}
}
private
Message
generateFakeResponse
()
throws
IOException
,
TimeoutException
,
InterruptedException
,
JSONException
{
String
strResponse
=
"{\"creationDate\":1488368936945,\"parameters\":["
+
"{\"name\":\"f293ff03-4b82-49e2-871a-899aadf821ce\","
+
"\"encoding\":\"UTF-8\",\"value\":"
+
"\"publicKeyPath: /tmp/Input-4007028381500/user.pem\\nuserName: "
+
"zh9314\\nsubnets:\\n- {name: s1, subnet: 192.168.10.0, "
+
"netmask: 255.255.255.0}\\ncomponents:\\n- "
+
"name: faab6756-61b6-4800-bffa-ae9d859a9d6c\\n "
+
"type: Switch.nodes.Compute\\n nodetype: t2.medium\\n "
+
"OStype: Ubuntu 16.04\\n domain: ec2.us-east-1.amazonaws.com\\n "
+
"script: /tmp/Input-4007028381500/guiscipt.sh\\n "
+
"installation: null\\n role: master\\n "
+
"dockers: mogswitch/InputDistributor\\n "
+
"public_address: 54.144.0.91\\n instanceId: i-0e78cbf853328b820\\n "
+
"ethernet_port:\\n - {name: p1, subnet_name: s1, "
+
"address: 192.168.10.10}\\n- name: 1c75eedf-8497-46fe-aeb8-dab6a62154cb\\n "
+
"type: Switch.nodes.Compute\\n nodetype: t2.medium\\n OStype: Ubuntu 16.04\\n domain: ec2.us-east-1.amazonaws.com\\n script: /tmp/Input-4007028381500/guiscipt.sh\\n installation: null\\n role: slave\\n dockers: mogswitch/ProxyTranscoder\\n public_address: 34.207.254.160\\n instanceId: i-0a99ea18fcc77ed7a\\n ethernet_port:\\n - {name: p1, subnet_name: s1, address: 192.168.10.11}\\n\"},{\"name\":\"kubernetes\",\"encoding\":\"UTF-8\",\"value\":\"54.144.0.91 ubuntu /tmp/Input-4007028381500/Virginia.pem master\\n34.207.254.160 ubuntu /tmp/Input-4007028381500/Virginia.pem slave\\n\"}]}"
;
ObjectMapper
mapper
=
new
ObjectMapper
();
mapper
.
configure
(
JsonParser
.
Feature
.
ALLOW_SINGLE_QUOTES
,
true
);
return
mapper
.
readValue
(
strResponse
,
Message
.
class
);
}
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/rest/ToscaController.java
View file @
1611ae99
...
@@ -57,11 +57,10 @@ public class ToscaController {
...
@@ -57,11 +57,10 @@ public class ToscaController {
throw
new
BadRequestException
(
"Must uplaod a file"
);
throw
new
BadRequestException
(
"Must uplaod a file"
);
}
}
try
{
try
{
return
toscaService
.
save
(
file
,
ToscaRepresentation
.
Type
.
SIDE
);
return
toscaService
.
save
(
file
);
}
catch
(
IOException
|
IllegalStateException
ex
)
{
}
catch
(
IOException
|
IllegalStateException
ex
)
{
Logger
.
getLogger
(
ToscaController
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
Logger
.
getLogger
(
ToscaController
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
return
null
;
return
null
;
}
}
...
@@ -71,7 +70,7 @@ public class ToscaController {
...
@@ -71,7 +70,7 @@ public class ToscaController {
public
@ResponseBody
public
@ResponseBody
String
get
(
@PathVariable
(
"id"
)
String
id
,
@RequestParam
(
value
=
"format"
)
String
format
)
{
String
get
(
@PathVariable
(
"id"
)
String
id
,
@RequestParam
(
value
=
"format"
)
String
format
)
{
try
{
try
{
return
toscaService
.
get
(
id
,
format
,
ToscaRepresentation
.
Type
.
SIDE
);
return
toscaService
.
get
(
id
,
format
);
}
catch
(
JSONException
ex
)
{
}
catch
(
JSONException
ex
)
{
Logger
.
getLogger
(
ToscaController
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
Logger
.
getLogger
(
ToscaController
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
...
@@ -82,7 +81,7 @@ public class ToscaController {
...
@@ -82,7 +81,7 @@ public class ToscaController {
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
public
@ResponseBody
String
delete
(
@PathVariable
(
"id"
)
String
id
)
{
String
delete
(
@PathVariable
(
"id"
)
String
id
)
{
toscaService
.
delete
(
id
,
ToscaRepresentation
.
Type
.
SIDE
);
toscaService
.
delete
(
id
);
return
"Deleted tosca :"
+
id
;
return
"Deleted tosca :"
+
id
;
}
}
...
@@ -91,7 +90,7 @@ public class ToscaController {
...
@@ -91,7 +90,7 @@ public class ToscaController {
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
public
@ResponseBody
List
<
String
>
getIds
()
{
List
<
String
>
getIds
()
{
List
<
ToscaRepresentation
>
all
=
toscaService
.
findAll
(
ToscaRepresentation
.
Type
.
SIDE
);
List
<
ToscaRepresentation
>
all
=
toscaService
.
findAll
();
List
<
String
>
ids
=
new
ArrayList
<>();
List
<
String
>
ids
=
new
ArrayList
<>();
for
(
ToscaRepresentation
tr
:
all
)
{
for
(
ToscaRepresentation
tr
:
all
)
{
ids
.
add
(
tr
.
getId
());
ids
.
add
(
tr
.
getId
());
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/service/PlannerService.java
View file @
1611ae99
...
@@ -58,7 +58,6 @@ public class PlannerService {
...
@@ -58,7 +58,6 @@ public class PlannerService {
ToscaRepresentation
tr
=
new
ToscaRepresentation
();
ToscaRepresentation
tr
=
new
ToscaRepresentation
();
Map
<
String
,
Object
>
kvMap
=
null
;
Map
<
String
,
Object
>
kvMap
=
null
;
tr
.
setKvMap
(
kvMap
);
tr
.
setKvMap
(
kvMap
);
tr
.
setType
(
ToscaRepresentation
.
Type
.
PLAN
);
return
null
;
return
null
;
}
}
...
@@ -66,7 +65,7 @@ public class PlannerService {
...
@@ -66,7 +65,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
||
t2
.
getType
().
equals
(
ToscaRepresentation
.
Type
.
PLAN
)
)
{
if
(
t2
==
null
)
{
throw
new
BadRequestException
(
"The description: "
+
toscaId
+
" is a plan. Cannot be used as planner input"
);
throw
new
BadRequestException
(
"The description: "
+
toscaId
+
" is a plan. Cannot be used as planner input"
);
}
}
Map
<
String
,
Object
>
map
=
t2
.
getKvMap
();
Map
<
String
,
Object
>
map
=
t2
.
getKvMap
();
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/service/ProvisionService.java
0 → 100644
View file @
1611ae99
/*
* 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
.
api
.
service
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
import
nl.uva.sne.drip.api.dao.ProvisionDao
;
import
nl.uva.sne.drip.api.dao.ToscaDao
;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
import
nl.uva.sne.drip.commons.types.ToscaRepresentation
;
import
nl.uva.sne.drip.commons.utils.Converter
;
import
org.json.JSONException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
/**
*
* @author S. Koulouzis
*/
@Service
public
class
ProvisionService
{
@Autowired
private
ProvisionDao
dao
;
public
ProvisionDao
getDao
()
{
return
dao
;
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/service/SimplePlannerService.java
View file @
1611ae99
...
@@ -26,11 +26,12 @@ import java.util.List;
...
@@ -26,11 +26,12 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.concurrent.TimeoutException
;
import
java.util.concurrent.TimeoutException
;
import
nl.uva.sne.drip.api.
exception.BadRequestException
;
import
nl.uva.sne.drip.api.
dao.PlanDao
;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
import
nl.uva.sne.drip.api.rpc.PlannerCaller
;
import
nl.uva.sne.drip.api.rpc.PlannerCaller
;
import
nl.uva.sne.drip.commons.types.Message
;
import
nl.uva.sne.drip.commons.types.Message
;
import
nl.uva.sne.drip.commons.types.Parameter
;
import
nl.uva.sne.drip.commons.types.Parameter
;
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
org.json.JSONException
;
import
org.json.JSONException
;
...
@@ -51,17 +52,29 @@ public class SimplePlannerService {
...
@@ -51,17 +52,29 @@ public class SimplePlannerService {
@Autowired
@Autowired
private
ToscaService
toscaService
;
private
ToscaService
toscaService
;
public
ToscaRepresentation
getPlan
(
String
toscaId
)
throws
JSONException
,
IOException
,
TimeoutException
,
InterruptedException
{
@Autowired
Message
plannerInvokationMessage
=
buildSimplePlannerMessage
(
toscaId
);
private
PlanDao
planDao
;
ToscaRepresentation
topLevel
;
public
Plan
getPlan
(
String
toscaId
)
throws
JSONException
,
IOException
,
TimeoutException
,
InterruptedException
{
ToscaRepresentation
tosca
=
toscaService
.
getDao
().
findOne
(
toscaId
);
Message
plannerInvokationMessage
=
buildSimplePlannerMessage
(
tosca
);
Plan
topLevel
;
try
(
PlannerCaller
planner
=
new
PlannerCaller
(
messageBrokerHost
))
{
try
(
PlannerCaller
planner
=
new
PlannerCaller
(
messageBrokerHost
))
{
Message
plannerReturnedMessage
=
planner
.
call
(
plannerInvokationMessage
);
Message
plannerReturnedMessage
=
planner
.
call
(
plannerInvokationMessage
);
List
<
Parameter
>
toscaFiles
=
plannerReturnedMessage
.
getParameters
();
List
<
Parameter
>
planFiles
=
plannerReturnedMessage
.
getParameters
();
topLevel
=
new
ToscaRepresentation
();
topLevel
=
new
Plan
();
ToscaRepresentation
tr
=
null
;
Set
<
String
>
ids
=
topLevel
.
getLoweLevelPlanIDs
();
for
(
Parameter
p
:
toscaFiles
)
{
if
(
ids
==
null
)
{
ids
=
new
HashSet
<>();
}
Plan
lowerLevelPlan
=
null
;
for
(
Parameter
p
:
planFiles
)
{
//Should have levels in attributes
//Should have levels in attributes
Map
<
String
,
String
>
attributess
=
p
.
getAttributes
();
Map
<
String
,
String
>
attributess
=
p
.
getAttributes
();
if
(
attributess
!=
null
)
{
attributess
.
get
(
"level"
);
}
String
originalFileName
=
p
.
getName
();
String
originalFileName
=
p
.
getName
();
String
name
=
System
.
currentTimeMillis
()
+
"_"
+
originalFileName
;
String
name
=
System
.
currentTimeMillis
()
+
"_"
+
originalFileName
;
if
(
originalFileName
.
equals
(
"planner_output_all.yml"
))
{
if
(
originalFileName
.
equals
(
"planner_output_all.yml"
))
{
...
@@ -69,30 +82,24 @@ public class SimplePlannerService {
...
@@ -69,30 +82,24 @@ public class SimplePlannerService {
topLevel
.
setLevel
(
0
);
topLevel
.
setLevel
(
0
);
topLevel
.
setKvMap
(
Converter
.
ymlString2Map
(
p
.
getValue
()));
topLevel
.
setKvMap
(
Converter
.
ymlString2Map
(
p
.
getValue
()));
}
else
{
}
else
{
tr
=
new
ToscaRepresentation
();
lowerLevelPlan
=
new
Plan
();
tr
.
setName
(
name
);
lowerLevelPlan
.
setName
(
name
);
tr
.
setKvMap
(
Converter
.
ymlString2Map
(
p
.
getValue
()));
lowerLevelPlan
.
setKvMap
(
Converter
.
ymlString2Map
(
p
.
getValue
()));
tr
.
setLevel
(
1
);
lowerLevelPlan
.
setLevel
(
1
);
}
planDao
.
save
(
lowerLevelPlan
);
tr
.
setType
(
ToscaRepresentation
.
Type
.
PLAN
);
ids
.
add
(
lowerLevelPlan
.
getId
());
toscaService
.
getDao
().
save
(
tr
);
Set
<
String
>
ids
=
topLevel
.
getLowerLevelIDs
();
if
(
ids
==
null
)
{
ids
=
new
HashSet
<>();
}
}
ids
.
add
(
tr
.
getId
());
topLevel
.
setLowerLevelIDs
(
ids
);
}
}
topLevel
.
setType
(
ToscaRepresentation
.
Type
.
PLAN
);
topLevel
.
setLoweLevelPlansIDs
(
ids
);
toscaService
.
getDao
().
save
(
topLevel
);
}
}
topLevel
.
setToscaID
(
toscaId
);
planDao
.
save
(
topLevel
);
return
topLevel
;
return
topLevel
;
}
}
private
Message
buildSimplePlannerMessage
(
String
toscaId
)
throws
JSONException
,
UnsupportedEncodingException
,
IOException
{
private
Message
buildSimplePlannerMessage
(
ToscaRepresentation
t2
)
throws
JSONException
,
UnsupportedEncodingException
,
IOException
{
ToscaRepresentation
t2
=
toscaService
.
getDao
().
findOne
(
toscaId
);
if
(
t2
==
null
)
{
if
(
t2
==
null
||
t2
.
getType
().
equals
(
ToscaRepresentation
.
Type
.
PLAN
))
{
throw
new
NotFoundException
();
throw
new
BadRequestException
(
"The description: "
+
toscaId
+
" is a plan. Cannot be used as planner input"
);
}
}
Map
<
String
,
Object
>
map
=
t2
.
getKvMap
();
Map
<
String
,
Object
>
map
=
t2
.
getKvMap
();
String
ymlStr
=
Converter
.
map2YmlString
(
map
);
String
ymlStr
=
Converter
.
map2YmlString
(
map
);
...
@@ -120,4 +127,51 @@ public class SimplePlannerService {
...
@@ -120,4 +127,51 @@ public class SimplePlannerService {
invokationMessage
.
setCreationDate
((
System
.
currentTimeMillis
()));
invokationMessage
.
setCreationDate
((
System
.
currentTimeMillis
()));
return
invokationMessage
;
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
;
}
public
PlanDao
getDao
()
{
return
planDao
;
}
public
String
getToscaID
(
String
id
)
{
return
planDao
.
findOne
(
id
).
getToscaID
();
}
public
List
<
Plan
>
findAll
()
{
List
<
Plan
>
all
=
planDao
.
findAll
();
List
<
Plan
>
topLevel
=
new
ArrayList
<>();
for
(
Plan
p
:
all
)
{
if
(
p
.
getLevel
()
==
0
)
{
topLevel
.
add
(
p
);
}
}
return
topLevel
;
}
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/service/ToscaService.java
View file @
1611ae99
...
@@ -16,10 +16,8 @@
...
@@ -16,10 +16,8 @@
package
nl
.
uva
.
sne
.
drip
.
api
.
service
;
package
nl
.
uva
.
sne
.
drip
.
api
.
service
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
nl.uva.sne.drip.api.dao.ToscaDao
;
import
nl.uva.sne.drip.api.dao.ToscaDao
;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
import
nl.uva.sne.drip.commons.types.ToscaRepresentation
;
import
nl.uva.sne.drip.commons.types.ToscaRepresentation
;
...
@@ -39,18 +37,13 @@ public class ToscaService {
...
@@ -39,18 +37,13 @@ public class ToscaService {
@Autowired
@Autowired
private
ToscaDao
dao
;
private
ToscaDao
dao
;
public
String
get
(
String
id
,
String
fromat
,
ToscaRepresentation
.
Type
type
)
throws
JSONException
{
public
String
get
(
String
id
,
String
fromat
)
throws
JSONException
{
ToscaRepresentation
tosca
=
dao
.
findOne
(
id
);
ToscaRepresentation
tosca
=
dao
.
findOne
(
id
);
if
(
tosca
==
null
||
!
tosca
.
getType
().
equals
(
type
)
)
{
if
(
tosca
==
null
)
{
throw
new
NotFoundException
();
throw
new
NotFoundException
();
}
}
Set
<
String
>
ids
=
tosca
.
getLowerLevelIDs
();
Map
<
String
,
Object
>
map
=
tosca
.
getKvMap
();
Map
<
String
,
Object
>
map
=
tosca
.
getKvMap
();
if
(
ids
!=
null
)
{
for
(
String
lowID
:
ids
)
{
map
.
putAll
(
dao
.
findOne
(
lowID
).
getKvMap
());
}
}
if
(
fromat
!=
null
&&
fromat
.
equals
(
"yml"
))
{
if
(
fromat
!=
null
&&
fromat
.
equals
(
"yml"
))
{
String
ymlStr
=
Converter
.
map2YmlString
(
map
);
String
ymlStr
=
Converter
.
map2YmlString
(
map
);
...
@@ -67,7 +60,7 @@ public class ToscaService {
...
@@ -67,7 +60,7 @@ public class ToscaService {
return
ymlStr
;
return
ymlStr
;
}
}
public
String
save
(
MultipartFile
file
,
ToscaRepresentation
.
Type
type
)
throws
IOException
{
public
String
save
(
MultipartFile
file
)
throws
IOException
{
String
originalFileName
=
file
.
getOriginalFilename
();
String
originalFileName
=
file
.
getOriginalFilename
();
String
name
=
System
.
currentTimeMillis
()
+
"_"
+
originalFileName
;
String
name
=
System
.
currentTimeMillis
()
+
"_"
+
originalFileName
;
byte
[]
bytes
=
file
.
getBytes
();
byte
[]
bytes
=
file
.
getBytes
();
...
@@ -78,42 +71,25 @@ public class ToscaService {
...
@@ -78,42 +71,25 @@ public class ToscaService {
ToscaRepresentation
t
=
new
ToscaRepresentation
();
ToscaRepresentation
t
=
new
ToscaRepresentation
();
t
.
setName
(
name
);
t
.
setName
(
name
);
t
.
setKvMap
(
map
);
t
.
setKvMap
(
map
);
t
.
setType
(
type
);
dao
.
save
(
t
);
dao
.
save
(
t
);
return
t
.
getId
();
return
t
.
getId
();
}
}
public
void
delete
(
String
id
,
ToscaRepresentation
.
Type
type
)
{
public
void
delete
(
String
id
)
{
ToscaRepresentation
tosca
=
dao
.
findOne
(
id
);
dao
.
delete
(
id
);
if
(!
tosca
.
getType
().
equals
(
type
))
{
throw
new
NotFoundException
();
}
else
{
dao
.
delete
(
id
);
}
}
}
public
List
<
ToscaRepresentation
>
findAll
(
ToscaRepresentation
.
Type
type
)
{
public
List
<
ToscaRepresentation
>
findAll
()
{
List
<
ToscaRepresentation
>
all
=
dao
.
findAll
();
return
dao
.
findAll
();
List
<
ToscaRepresentation
>
allType
=
new
ArrayList
<>();
if
(
all
==
null
)
{
throw
new
NotFoundException
();
}
for
(
ToscaRepresentation
tr
:
all
)
{
if
(
tr
.
getType
()
!=
null
&&
tr
.
getType
().
equals
(
type
))
{
allType
.
add
(
tr
);
}
}
return
allType
;
}
}
public
ToscaDao
getDao
()
{
public
ToscaDao
getDao
()
{
return
dao
;
return
dao
;
}
}
public
ToscaRepresentation
get
(
String
planID
,
ToscaRepresentation
.
Type
type
)
{
public
ToscaRepresentation
get
(
String
planID
)
{
ToscaRepresentation
tosca
=
dao
.
findOne
(
planID
);
ToscaRepresentation
tosca
=
dao
.
findOne
(
planID
);
if
(
tosca
==
null
||
!
tosca
.
getType
().
equals
(
type
)
)
{
if
(
tosca
==
null
)
{
throw
new
NotFoundException
();
throw
new
NotFoundException
();
}
}
return
tosca
;
return
tosca
;
...
...
drip-commons/src/main/java/nl/uva/sne/drip/commons/types/Plan.java
0 → 100644
View file @
1611ae99
/*
* 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
.
commons
.
types
;
import
java.util.Map
;
import
java.util.Set
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
/**
*
* @author S. Koulouzis
*/
@Document
public
class
Plan
{
@Id
private
String
id
;
private
String
toscaID
;
private
String
name
;
private
Integer
level
;
private
Set
<
String
>
loweLevelPlansIDs
;
private
Map
<
String
,
Object
>
kvMap
;
public
final
String
getId
()
{
return
id
;
}
public
final
void
setId
(
final
String
id
)
{
this
.
id
=
id
;
}
/**
* @return the kvMap
*/
public
Map
<
String
,
Object
>
getKvMap
()
{
return
kvMap
;
}
/**
* @param kvMap the kvMap to set
*/
public
void
setKvMap
(
Map
<
String
,
Object
>
kvMap
)
{
this
.
kvMap
=
kvMap
;
}
/**
* @return the name
*/
public
String
getName
()
{
return
name
;
}
/**
* @param name the name to set
*/
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
/**
* @return the toscaID
*/
public
String
getToscaID
()
{
return
toscaID
;
}
/**
* @param toscaID the toscaID to set
*/
public
void
setToscaID
(
String
toscaID
)
{
this
.
toscaID
=
toscaID
;
}
/**
* @return the level
*/
public
Integer
getLevel
()
{
return
level
;
}
/**
* @param level the level to set
*/
public
void
setLevel
(
Integer
level
)
{
this
.
level
=
level
;
}
/**
* @return the loweLevelPlansIDs
*/
public
Set
<
String
>
getLoweLevelPlanIDs
()
{
return
loweLevelPlansIDs
;
}
/**
* @param loweLevelPlans the loweLevelPlansIDs to set
*/
public
void
setLoweLevelPlansIDs
(
Set
<
String
>
loweLevelPlansIDs
)
{
this
.
loweLevelPlansIDs
=
loweLevelPlansIDs
;
}
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/types/Provision
Request
.java
→
drip-commons/src/main/java/nl/uva/sne/drip/commons/types/Provision.java
View file @
1611ae99
...
@@ -15,11 +15,17 @@
...
@@ -15,11 +15,17 @@
*/
*/
package
nl
.
uva
.
sne
.
drip
.
commons
.
types
;
package
nl
.
uva
.
sne
.
drip
.
commons
.
types
;
import
java.util.Map
;
import
org.springframework.data.annotation.Id
;
/**
/**
*
*
* @author S. Koulouzis
* @author S. Koulouzis
*/
*/
public
class
ProvisionRequest
{
public
class
Provision
{
@Id
private
String
id
;
private
String
cloudConfID
;
private
String
cloudConfID
;
...
@@ -29,6 +35,8 @@ public class ProvisionRequest {
...
@@ -29,6 +35,8 @@ public class ProvisionRequest {
private
String
userKeyID
;
private
String
userKeyID
;
private
Map
<
String
,
Object
>
kvMap
;
/**
/**
* @return the cloudConfID
* @return the cloudConfID
*/
*/
...
@@ -85,4 +93,32 @@ public class ProvisionRequest {
...
@@ -85,4 +93,32 @@ public class ProvisionRequest {
this
.
userKeyID
=
userKeyID
;
this
.
userKeyID
=
userKeyID
;
}
}
/**
* @return the id
*/
public
String
getId
()
{
return
id
;
}
/**
* @param id the id to set
*/
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
/**
* @return the kvMap
*/
public
Map
<
String
,
Object
>
getKvMap
()
{
return
kvMap
;
}
/**
* @param kvMap the kvMap to set
*/
public
void
setKvMap
(
Map
<
String
,
Object
>
kvMap
)
{
this
.
kvMap
=
kvMap
;
}
}
}
drip-commons/src/main/java/nl/uva/sne/drip/commons/types/ToscaRepresentation.java
View file @
1611ae99
...
@@ -30,35 +30,10 @@ public class ToscaRepresentation {
...
@@ -30,35 +30,10 @@ public class ToscaRepresentation {
@Id
@Id
private
String
id
;
private
String
id
;
private
Set
<
String
>
lowerLevelIDs
;
private
String
name
;
private
String
name
;
private
Map
<
String
,
Object
>
kvMap
;
private
Map
<
String
,
Object
>
kvMap
;
private
Integer
level
;
private
Type
type
;
public
static
enum
Type
{
PLAN
,
SIDE
}
/**
* @return the type
*/
public
Type
getType
()
{
return
type
;
}
/**
* @param type the type to set
*/
public
void
setType
(
Type
type
)
{
this
.
type
=
type
;
}
public
final
String
getId
()
{
public
final
String
getId
()
{
return
id
;
return
id
;
}
}
...
@@ -94,33 +69,4 @@ public class ToscaRepresentation {
...
@@ -94,33 +69,4 @@ public class ToscaRepresentation {
public
void
setName
(
String
name
)
{
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
this
.
name
=
name
;
}
}
/**
* @return the level
*/
public
Integer
getLevel
()
{
return
level
;
}
/**
* @param level the level to set
*/
public
void
setLevel
(
Integer
level
)
{
this
.
level
=
level
;
}
/**
* @return the lowerLevelIDs
*/
public
Set
<
String
>
getLowerLevelIDs
()
{
return
lowerLevelIDs
;
}
/**
* @param lowerLevelIDs the lowerLevelIDs to set
*/
public
void
setLowerLevelIDs
(
Set
<
String
>
lowerLevelIDs
)
{
this
.
lowerLevelIDs
=
lowerLevelIDs
;
}
}
}
drip-provisioner/src/main/java/nl/uva/sne/drip/drip/provisioner/Consumer.java
View file @
1611ae99
...
@@ -118,9 +118,16 @@ public class Consumer extends DefaultConsumer {
...
@@ -118,9 +118,16 @@ public class Consumer extends DefaultConsumer {
topologyInfoArray
=
invokeProvisioner
(
message
,
tempInputDirPath
);
topologyInfoArray
=
invokeProvisioner
(
message
,
tempInputDirPath
);
response
=
generateResponse
(
topologyInfoArray
);
response
=
generateResponse
(
topologyInfoArray
);
}
catch
(
IOException
|
JSONException
ex
)
{
}
catch
(
Throwable
ex
)
{
response
=
ex
.
getMessage
();
try
{
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
response
=
generateExeptionResponse
(
ex
);
Logger
.
getLogger
(
Consumer
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
JSONException
ex1
)
{
response
=
"{\"creationDate\": "
+
System
.
currentTimeMillis
()
+
",\"parameters\": [{\"url\": null,\"encoding\": UTF-8,"
+
"\"value\": \""
+
ex
.
getMessage
()
+
"\",\"name\": \""
+
ex
.
getClass
().
getName
()
+
"\",\"attributes\": null}]}"
;
}
}
finally
{
}
finally
{
//We send the response back. No need to change anything here
//We send the response back. No need to change anything here
channel
.
basicPublish
(
""
,
properties
.
getReplyTo
(),
replyProps
,
response
.
getBytes
(
"UTF-8"
));
channel
.
basicPublish
(
""
,
properties
.
getReplyTo
(),
replyProps
,
response
.
getBytes
(
"UTF-8"
));
...
@@ -336,6 +343,22 @@ public class Consumer extends DefaultConsumer {
...
@@ -336,6 +343,22 @@ public class Consumer extends DefaultConsumer {
return
jo
.
toString
();
return
jo
.
toString
();
}
}
private
String
generateExeptionResponse
(
Throwable
ex
)
throws
JSONException
{
JSONObject
jo
=
new
JSONObject
();
jo
.
put
(
"creationDate"
,
(
System
.
currentTimeMillis
()));
List
parameters
=
new
ArrayList
();
String
charset
=
"UTF-8"
;
Map
<
String
,
String
>
errorArgument
=
new
HashMap
<>();
errorArgument
.
put
(
"encoding"
,
charset
);
errorArgument
.
put
(
"name"
,
ex
.
getClass
().
getName
());
errorArgument
.
put
(
"value"
,
ex
.
getMessage
());
parameters
.
add
(
errorArgument
);
jo
.
put
(
"parameters"
,
parameters
);
return
jo
.
toString
();
}
private
void
writeValueToFile
(
String
value
,
File
file
)
throws
FileNotFoundException
{
private
void
writeValueToFile
(
String
value
,
File
file
)
throws
FileNotFoundException
{
try
(
PrintWriter
out
=
new
PrintWriter
(
file
))
{
try
(
PrintWriter
out
=
new
PrintWriter
(
file
))
{
out
.
print
(
value
);
out
.
print
(
value
);
...
...
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