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
f102f1f4
Commit
f102f1f4
authored
Mar 09, 2017
by
skoulouzis
Committed by
GitHub
Mar 09, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #30 from skoulouzis/v0.0_API
Implmented provisioner for v0.0
parents
bda62e5e
416a104a
Changes
25
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
566 additions
and
560 deletions
+566
-560
WebAppInitializer.java
...main/java/nl/uva/sne/drip/api/conf/WebAppInitializer.java
+1
-1
ScriptDao.java
...-api/src/main/java/nl/uva/sne/drip/api/dao/ScriptDao.java
+1
-1
CloudCredentialsService.java
.../nl/uva/sne/drip/api/service/CloudCredentialsService.java
+15
-11
PlannerService.java
...main/java/nl/uva/sne/drip/api/service/PlannerService.java
+27
-8
ProvisionService.java
...in/java/nl/uva/sne/drip/api/service/ProvisionService.java
+299
-2
SimplePlannerService.java
...ava/nl/uva/sne/drip/api/service/SimplePlannerService.java
+1
-1
ToscaService.java
...c/main/java/nl/uva/sne/drip/api/service/ToscaService.java
+25
-15
UserKeyService.java
...main/java/nl/uva/sne/drip/api/service/UserKeyService.java
+31
-7
UserScriptService.java
...n/java/nl/uva/sne/drip/api/service/UserScriptService.java
+35
-4
CloudConfigurationController0.java
...a/sne/drip/api/v0/rest/CloudConfigurationController0.java
+3
-2
PlannerController0.java
.../java/nl/uva/sne/drip/api/v0/rest/PlannerController0.java
+7
-26
ProvisionController0.java
...ava/nl/uva/sne/drip/api/v0/rest/ProvisionController0.java
+56
-196
CloudCredentialsController.java
.../uva/sne/drip/api/v1/rest/CloudCredentialsController.java
+0
-2
DeployController.java
...in/java/nl/uva/sne/drip/api/v1/rest/DeployController.java
+5
-6
PlannerController.java
...n/java/nl/uva/sne/drip/api/v1/rest/PlannerController.java
+1
-2
ProvisionController.java
...java/nl/uva/sne/drip/api/v1/rest/ProvisionController.java
+20
-265
ToscaController.java
...ain/java/nl/uva/sne/drip/api/v1/rest/ToscaController.java
+1
-1
UserPublicKeysController.java
...nl/uva/sne/drip/api/v1/rest/UserPublicKeysController.java
+2
-2
UserScriptController.java
...ava/nl/uva/sne/drip/api/v1/rest/UserScriptController.java
+2
-2
Converter.java
...rc/main/java/nl/uva/sne/drip/commons/utils/Converter.java
+28
-0
Upload.java
...rc/main/java/nl/uva/sne/drip/commons/v0/types/Upload.java
+3
-1
KeyValueHolder.java
...java/nl/uva/sne/drip/commons/v1/types/KeyValueHolder.java
+1
-1
LoginKey.java
.../main/java/nl/uva/sne/drip/commons/v1/types/LoginKey.java
+1
-1
Script.java
...rc/main/java/nl/uva/sne/drip/commons/v1/types/Script.java
+1
-1
ToscaRepresentation.java
...nl/uva/sne/drip/commons/v1/types/ToscaRepresentation.java
+0
-2
No files found.
drip-api/src/main/java/nl/uva/sne/drip/api/conf/WebAppInitializer.java
View file @
f102f1f4
...
@@ -28,7 +28,7 @@ public class WebAppInitializer implements WebApplicationInitializer {
...
@@ -28,7 +28,7 @@ public class WebAppInitializer implements WebApplicationInitializer {
ctx
.
register
(
MultipartConfig
.
class
);
ctx
.
register
(
MultipartConfig
.
class
);
ctx
.
register
(
MongoConfig
.
class
);
ctx
.
register
(
MongoConfig
.
class
);
ctx
.
register
(
SecurityConfig
.
class
);
ctx
.
register
(
SecurityConfig
.
class
);
ctx
.
register
(
MethodSecurityConfig
.
class
);
//
ctx.register(MethodSecurityConfig.class);
ctx
.
setServletContext
(
servletContext
);
ctx
.
setServletContext
(
servletContext
);
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/dao/
User
ScriptDao.java
→
drip-api/src/main/java/nl/uva/sne/drip/api/dao/ScriptDao.java
View file @
f102f1f4
...
@@ -22,6 +22,6 @@ import org.springframework.data.mongodb.repository.MongoRepository;
...
@@ -22,6 +22,6 @@ import org.springframework.data.mongodb.repository.MongoRepository;
*
*
* @author S. Koulouzis
* @author S. Koulouzis
*/
*/
public
interface
User
ScriptDao
extends
MongoRepository
<
Script
,
String
>
{
public
interface
ScriptDao
extends
MongoRepository
<
Script
,
String
>
{
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/service/CloudCredentialsService.java
View file @
f102f1f4
...
@@ -18,10 +18,12 @@ package nl.uva.sne.drip.api.service;
...
@@ -18,10 +18,12 @@ package nl.uva.sne.drip.api.service;
import
java.util.List
;
import
java.util.List
;
import
nl.uva.sne.drip.api.dao.CloudCredentialsDao
;
import
nl.uva.sne.drip.api.dao.CloudCredentialsDao
;
import
nl.uva.sne.drip.commons.v1.types.CloudCredentials
;
import
nl.uva.sne.drip.commons.v1.types.CloudCredentials
;
import
nl.uva.sne.drip.commons.v1.types.User
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PostAuthorize
;
import
org.springframework.security.access.prepost.PostFilter
;
import
org.springframework.security.access.prepost.PostFilter
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.
access.prepost.PreFilt
er
;
import
org.springframework.security.
core.context.SecurityContextHold
er
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
/**
/**
...
@@ -29,33 +31,35 @@ import org.springframework.stereotype.Service;
...
@@ -29,33 +31,35 @@ import org.springframework.stereotype.Service;
* @author S. Koulouzis
* @author S. Koulouzis
*/
*/
@Service
@Service
@PreAuthorize
(
"isAuthenticated()"
)
public
class
CloudCredentialsService
{
public
class
CloudCredentialsService
{
@Autowired
@Autowired
private
CloudCredentialsDao
dao
;
private
CloudCredentialsDao
dao
;
// @PreFilter("(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public
CloudCredentials
save
(
CloudCredentials
cloudCredentials
)
{
public
CloudCredentials
save
(
CloudCredentials
cloudCredentials
)
{
User
user
=
(
User
)
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
// String owner = user.getUsername();
String
owner
=
user
.
getUsername
();
// cloudCredentials.setOwner(owner);
cloudCredentials
.
setOwner
(
owner
);
System
.
err
.
println
(
cloudCredentials
.
getOwner
());
return
dao
.
save
(
cloudCredentials
);
return
dao
.
save
(
cloudCredentials
);
}
}
// @PreAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
@PostAuthorize
(
"(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
@PreAuthorize
(
"hasPermission(#returnObject, 'read')"
)
public
CloudCredentials
findOne
(
String
id
)
{
public
CloudCredentials
findOne
(
String
id
)
{
CloudCredentials
creds
=
dao
.
findOne
(
id
);
CloudCredentials
creds
=
dao
.
findOne
(
id
);
return
creds
;
return
creds
;
}
}
public
void
delete
(
String
id
)
{
@PostAuthorize
(
"(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
dao
.
delete
(
id
);
public
CloudCredentials
delete
(
String
id
)
{
CloudCredentials
creds
=
dao
.
findOne
(
id
);
dao
.
delete
(
creds
);
return
creds
;
}
}
// @PreAuthorize(" (hasRole('ROLE_ADMIN')) or (hasRole('ROLE_USER'))")
// @PreAuthorize(" (hasRole('ROLE_ADMIN')) or (hasRole('ROLE_USER'))")
// @PostFilter("(filterObject.owner == authentication.name)")
@PostFilter
(
"(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
// @PostFilter("hasPermission(filterObject, 'read') or hasPermission(filterObject, 'admin')")
public
List
<
CloudCredentials
>
findAll
()
{
public
List
<
CloudCredentials
>
findAll
()
{
return
dao
.
findAll
();
return
dao
.
findAll
();
}
}
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/service/PlannerService.java
View file @
f102f1f4
...
@@ -34,11 +34,14 @@ import nl.uva.sne.drip.commons.v1.types.MessageParameter;
...
@@ -34,11 +34,14 @@ import nl.uva.sne.drip.commons.v1.types.MessageParameter;
import
nl.uva.sne.drip.commons.v1.types.Plan
;
import
nl.uva.sne.drip.commons.v1.types.Plan
;
import
nl.uva.sne.drip.commons.v1.types.ToscaRepresentation
;
import
nl.uva.sne.drip.commons.v1.types.ToscaRepresentation
;
import
nl.uva.sne.drip.commons.utils.Converter
;
import
nl.uva.sne.drip.commons.utils.Converter
;
import
nl.uva.sne.drip.commons.v1.types.User
;
import
nl.uva.sne.drip.drip.converter.P2PConverter
;
import
nl.uva.sne.drip.drip.converter.P2PConverter
;
import
nl.uva.sne.drip.drip.converter.SimplePlanContainer
;
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
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
/**
/**
...
@@ -46,6 +49,7 @@ import org.springframework.stereotype.Service;
...
@@ -46,6 +49,7 @@ import org.springframework.stereotype.Service;
* @author S. Koulouzis
* @author S. Koulouzis
*/
*/
@Service
@Service
@PreAuthorize
(
"isAuthenticated()"
)
public
class
PlannerService
{
public
class
PlannerService
{
@Autowired
@Autowired
...
@@ -92,18 +96,18 @@ public class PlannerService {
...
@@ -92,18 +96,18 @@ public class PlannerService {
lowLevelPlan
.
setToscaID
(
toscaId
);
lowLevelPlan
.
setToscaID
(
toscaId
);
lowLevelPlan
.
setName
(
lowLevelNames
);
lowLevelPlan
.
setName
(
lowLevelNames
);
lowLevelPlan
.
setKvMap
(
Converter
.
ymlString2Map
(
map
.
get
(
lowLevelNames
)));
lowLevelPlan
.
setKvMap
(
Converter
.
ymlString2Map
(
map
.
get
(
lowLevelNames
)));
planDao
.
save
(
lowLevelPlan
);
save
(
lowLevelPlan
);
loweLevelPlansIDs
.
add
(
lowLevelPlan
.
getId
());
loweLevelPlansIDs
.
add
(
lowLevelPlan
.
getId
());
}
}
topLevel
.
setLoweLevelPlansIDs
(
loweLevelPlansIDs
);
topLevel
.
setLoweLevelPlansIDs
(
loweLevelPlansIDs
);
planDao
.
save
(
topLevel
);
save
(
topLevel
);
return
topLevel
;
return
topLevel
;
}
}
}
}
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
.
findOne
(
toscaId
);
if
(
t2
==
null
)
{
if
(
t2
==
null
)
{
throw
new
BadRequestException
();
throw
new
BadRequestException
();
}
}
...
@@ -136,7 +140,9 @@ public class PlannerService {
...
@@ -136,7 +140,9 @@ public class PlannerService {
Set
<
String
>
ids
=
plan
.
getLoweLevelPlanIDs
();
Set
<
String
>
ids
=
plan
.
getLoweLevelPlanIDs
();
for
(
String
lowID
:
ids
)
{
for
(
String
lowID
:
ids
)
{
Map
<
String
,
Object
>
lowLevelMap
=
planDao
.
findOne
(
lowID
).
getKeyValue
();
Map
<
String
,
Object
>
lowLevelMap
=
planDao
.
findOne
(
lowID
).
getKeyValue
();
map
.
putAll
(
lowLevelMap
);
if
(
lowLevelMap
!=
null
)
{
map
.
putAll
(
lowLevelMap
);
}
}
}
if
(
fromat
!=
null
&&
fromat
.
equals
(
"yml"
))
{
if
(
fromat
!=
null
&&
fromat
.
equals
(
"yml"
))
{
...
@@ -158,10 +164,6 @@ public class PlannerService {
...
@@ -158,10 +164,6 @@ public class PlannerService {
return
planDao
.
findOne
(
id
).
getToscaID
();
return
planDao
.
findOne
(
id
).
getToscaID
();
}
}
public
PlanDao
getDao
()
{
return
this
.
planDao
;
}
public
List
<
Plan
>
findAll
()
{
public
List
<
Plan
>
findAll
()
{
List
<
Plan
>
all
=
planDao
.
findAll
();
List
<
Plan
>
all
=
planDao
.
findAll
();
List
<
Plan
>
topLevel
=
new
ArrayList
<>();
List
<
Plan
>
topLevel
=
new
ArrayList
<>();
...
@@ -173,4 +175,21 @@ public class PlannerService {
...
@@ -173,4 +175,21 @@ public class PlannerService {
return
topLevel
;
return
topLevel
;
}
}
public
Plan
save
(
Plan
plan
)
{
User
user
=
(
User
)
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
String
owner
=
user
.
getUsername
();
plan
.
setOwner
(
owner
);
return
planDao
.
save
(
plan
);
}
public
Plan
findOne
(
String
lowiID
)
{
return
planDao
.
findOne
(
lowiID
);
}
public
Plan
delete
(
String
id
)
{
Plan
plan
=
planDao
.
findOne
(
id
);
planDao
.
delete
(
plan
);
return
plan
;
}
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/service/ProvisionService.java
View file @
f102f1f4
...
@@ -15,22 +15,319 @@
...
@@ -15,22 +15,319 @@
*/
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
service
;
package
nl
.
uva
.
sne
.
drip
.
api
.
service
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.Set
;
import
java.util.concurrent.TimeoutException
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
nl.uva.sne.drip.api.dao.ProvisionInfoDao
;
import
nl.uva.sne.drip.api.dao.ProvisionInfoDao
;
import
nl.uva.sne.drip.api.exception.BadRequestException
;
import
nl.uva.sne.drip.api.exception.CloudCredentialsNotFoundException
;
import
nl.uva.sne.drip.api.exception.ExceptionHandler
;
import
nl.uva.sne.drip.api.exception.PlanNotFoundException
;
import
nl.uva.sne.drip.api.rpc.DRIPCaller
;
import
nl.uva.sne.drip.api.rpc.ProvisionerCaller
;
import
nl.uva.sne.drip.api.v1.rest.ProvisionController
;
import
nl.uva.sne.drip.commons.utils.Converter
;
import
nl.uva.sne.drip.commons.v1.types.CloudCredentials
;
import
nl.uva.sne.drip.commons.v1.types.DeployParameter
;
import
nl.uva.sne.drip.commons.v1.types.LoginKey
;
import
nl.uva.sne.drip.commons.v1.types.Message
;
import
nl.uva.sne.drip.commons.v1.types.MessageParameter
;
import
nl.uva.sne.drip.commons.v1.types.Plan
;
import
nl.uva.sne.drip.commons.v1.types.ProvisionInfo
;
import
nl.uva.sne.drip.commons.v1.types.Script
;
import
nl.uva.sne.drip.commons.v1.types.User
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.io.FilenameUtils
;
import
org.json.JSONException
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.security.access.prepost.PostAuthorize
;
import
org.springframework.security.access.prepost.PostFilter
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.core.context.SecurityContextHolder
;
/**
/**
*
*
* @author S. Koulouzis
* @author S. Koulouzis
*/
*/
@Service
@Service
@PreAuthorize
(
"isAuthenticated()"
)
public
class
ProvisionService
{
public
class
ProvisionService
{
@Autowired
@Autowired
private
ProvisionInfoDao
dao
;
private
ProvisionInfoDao
dao
;
public
ProvisionInfoDao
getDao
()
{
@Autowired
return
dao
;
private
CloudCredentialsService
cloudCredentialsService
;
@Autowired
private
SimplePlannerService
planService
;
@Autowired
private
UserScriptService
userScriptService
;
@Autowired
private
UserKeyService
userKeysService
;
@Value
(
"${message.broker.host}"
)
private
String
messageBrokerHost
;
public
ProvisionInfo
save
(
ProvisionInfo
provisionInfo
)
{
User
user
=
(
User
)
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
String
owner
=
user
.
getUsername
();
provisionInfo
.
setOwner
(
owner
);
return
dao
.
save
(
provisionInfo
);
}
@PostAuthorize
(
"(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
public
ProvisionInfo
findOne
(
String
id
)
{
ProvisionInfo
provisionInfo
=
dao
.
findOne
(
id
);
return
provisionInfo
;
}
@PostAuthorize
(
"(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
public
ProvisionInfo
delete
(
String
id
)
{
ProvisionInfo
provisionInfo
=
dao
.
findOne
(
id
);
dao
.
delete
(
provisionInfo
);
return
provisionInfo
;
}
// @PreAuthorize(" (hasRole('ROLE_ADMIN')) or (hasRole('ROLE_USER'))")
@PostFilter
(
"(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
// @PostFilter("hasPermission(filterObject, 'read') or hasPermission(filterObject, 'admin')")
public
List
<
ProvisionInfo
>
findAll
()
{
return
dao
.
findAll
();
}
public
ProvisionInfo
provisionResources
(
ProvisionInfo
req
)
throws
IOException
,
TimeoutException
,
JSONException
,
InterruptedException
{
try
(
DRIPCaller
provisioner
=
new
ProvisionerCaller
(
messageBrokerHost
);)
{
Message
provisionerInvokationMessage
=
buildProvisionerMessage
(
req
);
Message
response
=
(
provisioner
.
call
(
provisionerInvokationMessage
));
// Message response = generateFakeResponse(System.getProperty("user.home")
// + File.separator + "workspace" + File.separator + "DRIP"
// + File.separator + "doc" + File.separator + "json_samples" +
// File.separator + "ec2_provisioner_provisoned2.json");
List
<
MessageParameter
>
params
=
response
.
getParameters
();
for
(
MessageParameter
p
:
params
)
{
String
name
=
p
.
getName
();
if
(
name
.
toLowerCase
().
contains
(
"exception"
))
{
RuntimeException
ex
=
ExceptionHandler
.
generateException
(
name
,
p
.
getValue
());
Logger
.
getLogger
(
ProvisionController
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
throw
ex
;
}
if
(!
name
.
equals
(
"kubernetes"
))
{
String
value
=
p
.
getValue
();
Map
<
String
,
Object
>
kvMap
=
Converter
.
ymlString2Map
(
value
);
req
.
setKvMap
(
kvMap
);
req
.
setPlanID
(
req
.
getPlanID
());
}
else
{
String
value
=
p
.
getValue
();
String
[]
lines
=
value
.
split
(
"\n"
);
List
<
DeployParameter
>
deployParameters
=
new
ArrayList
<>();
for
(
String
line
:
lines
)
{
DeployParameter
deployParam
=
new
DeployParameter
();
String
[]
parts
=
line
.
split
(
" "
);
String
deployIP
=
parts
[
0
];
String
deployUser
=
parts
[
1
];
String
deployCertPath
=
parts
[
2
];
String
cloudCertificateName
=
FilenameUtils
.
removeExtension
(
FilenameUtils
.
getBaseName
(
deployCertPath
));
String
deployRole
=
parts
[
3
];
deployParam
.
setIP
(
deployIP
);
deployParam
.
setRole
(
deployRole
);
deployParam
.
setUser
(
deployUser
);
deployParam
.
setCloudCertificateName
(
cloudCertificateName
);
deployParameters
.
add
(
deployParam
);
}
req
.
setDeployParameters
(
deployParameters
);
}
}
req
=
save
(
req
);
return
req
;
}
}
}
private
Message
buildProvisionerMessage
(
ProvisionInfo
pReq
)
throws
JSONException
,
IOException
{
Message
invokationMessage
=
new
Message
();
List
<
MessageParameter
>
parameters
=
new
ArrayList
();
CloudCredentials
cred
=
cloudCredentialsService
.
findOne
(
pReq
.
getCloudcloudCredentialsID
());
if
(
cred
==
null
)
{
throw
new
CloudCredentialsNotFoundException
();
}
MessageParameter
conf
=
buildCloudConfParam
(
cred
);
parameters
.
add
(
conf
);
List
<
MessageParameter
>
certs
=
buildCertificatesParam
(
cred
);
parameters
.
addAll
(
certs
);
List
<
MessageParameter
>
topologies
=
buildTopologyParams
(
pReq
.
getPlanID
());
parameters
.
addAll
(
topologies
);
String
scriptID
=
pReq
.
getscriptID
();
if
(
scriptID
!=
null
)
{
List
<
MessageParameter
>
userScripts
=
buildScriptParams
(
scriptID
);
parameters
.
addAll
(
userScripts
);
}
String
userKeyID
=
pReq
.
getUserKeyID
();
if
(
userKeyID
!=
null
)
{
List
<
MessageParameter
>
userKeys
=
buildKeysParams
(
userKeyID
);
parameters
.
addAll
(
userKeys
);
}
invokationMessage
.
setParameters
(
parameters
);
invokationMessage
.
setCreationDate
((
System
.
currentTimeMillis
()));
return
invokationMessage
;
}
private
MessageParameter
buildCloudConfParam
(
CloudCredentials
cred
)
throws
JsonProcessingException
,
JSONException
,
IOException
{
MessageParameter
conf
=
null
;
String
provider
=
cred
.
getCloudProviderName
();
if
(
provider
==
null
)
{
throw
new
BadRequestException
(
"Provider name can't be null. Check the cloud credentials: "
+
cred
.
getId
());
}
switch
(
cred
.
getCloudProviderName
().
toLowerCase
())
{
case
"ec2"
:
conf
=
buildEC2Conf
(
cred
);
break
;
}
return
conf
;
}
private
List
<
MessageParameter
>
buildCertificatesParam
(
CloudCredentials
cred
)
{
List
<
LoginKey
>
loginKeys
=
cred
.
getLoginKeys
();
if
(
loginKeys
==
null
||
loginKeys
.
isEmpty
())
{
throw
new
BadRequestException
(
"Log in keys can't be empty"
);
}
List
<
MessageParameter
>
parameters
=
new
ArrayList
<>();
for
(
LoginKey
lk
:
loginKeys
)
{
String
domainName
=
lk
.
getAttributes
().
get
(
"domain_name"
);
if
(
domainName
==
null
)
{
domainName
=
lk
.
getAttributes
().
get
(
"domain_name "
);
}
MessageParameter
cert
=
new
MessageParameter
();
cert
.
setName
(
"certificate"
);
cert
.
setValue
(
lk
.
getKey
());
Map
<
String
,
String
>
attributes
=
new
HashMap
<>();
attributes
.
put
(
"filename"
,
domainName
);
cert
.
setAttributes
(
attributes
);
parameters
.
add
(
cert
);
}
return
parameters
;
}
private
List
<
MessageParameter
>
buildTopologyParams
(
String
planID
)
throws
JSONException
{
Plan
plan
=
planService
.
getDao
().
findOne
(
planID
);
if
(
plan
==
null
)
{
throw
new
PlanNotFoundException
();
}
List
<
MessageParameter
>
parameters
=
new
ArrayList
();
MessageParameter
topology
=
new
MessageParameter
();
topology
.
setName
(
"topology"
);
topology
.
setValue
(
Converter
.
map2YmlString
(
plan
.
getKeyValue
()));
Map
<
String
,
String
>
attributes
=
new
HashMap
<>();
attributes
.
put
(
"level"
,
String
.
valueOf
(
plan
.
getLevel
()));
attributes
.
put
(
"filename"
,
FilenameUtils
.
removeExtension
(
plan
.
getName
()));
topology
.
setAttributes
(
attributes
);
parameters
.
add
(
topology
);
Set
<
String
>
ids
=
plan
.
getLoweLevelPlanIDs
();
for
(
String
lowID
:
ids
)
{
Plan
lowPlan
=
planService
.
getDao
().
findOne
(
lowID
);
topology
=
new
MessageParameter
();
topology
.
setName
(
"topology"
);
topology
.
setValue
(
Converter
.
map2YmlString
(
lowPlan
.
getKeyValue
()));
attributes
=
new
HashMap
<>();
attributes
.
put
(
"level"
,
String
.
valueOf
(
lowPlan
.
getLevel
()));
attributes
.
put
(
"filename"
,
FilenameUtils
.
removeExtension
(
lowPlan
.
getName
()));
topology
.
setAttributes
(
attributes
);
parameters
.
add
(
topology
);
}
return
parameters
;
}
private
MessageParameter
buildEC2Conf
(
CloudCredentials
cred
)
throws
JsonProcessingException
,
JSONException
,
IOException
{
Properties
prop
=
Converter
.
getEC2Properties
(
cred
);
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
prop
.
store
(
baos
,
null
);
byte
[]
bytes
=
baos
.
toByteArray
();
MessageParameter
conf
=
new
MessageParameter
();
conf
.
setName
(
"ec2.conf"
);
String
charset
=
"UTF-8"
;
conf
.
setValue
(
new
String
(
bytes
,
charset
));
return
conf
;
}
private
List
<
MessageParameter
>
buildScriptParams
(
String
userScriptID
)
{
Script
script
=
userScriptService
.
findOne
(
userScriptID
);
if
(
script
==
null
)
{
throw
new
BadRequestException
(
"User script: "
+
userScriptID
+
" was not found"
);
}
List
<
MessageParameter
>
parameters
=
new
ArrayList
();
MessageParameter
scriptParameter
=
new
MessageParameter
();
scriptParameter
.
setName
(
"guiscript"
);
scriptParameter
.
setValue
(
script
.
getContents
());
scriptParameter
.
setEncoding
(
"UTF-8"
);
parameters
.
add
(
scriptParameter
);
return
parameters
;
}
private
List
<
MessageParameter
>
buildKeysParams
(
String
userKeyID
)
{
LoginKey
key
=
userKeysService
.
get
(
userKeyID
,
LoginKey
.
Type
.
PUBLIC
);
if
(
key
==
null
)
{
throw
new
BadRequestException
(
"User key: "
+
userKeyID
+
" was not found"
);
}
List
<
MessageParameter
>
parameters
=
new
ArrayList
();
MessageParameter
keyParameter
=
new
MessageParameter
();
keyParameter
.
setName
(
"sshkey"
);
keyParameter
.
setValue
(
key
.
getKey
());
keyParameter
.
setEncoding
(
"UTF-8"
);
parameters
.
add
(
keyParameter
);
return
parameters
;
}
private
Message
generateFakeResponse
(
String
path
)
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\"}]}";
// String strResponse = "{\"creationDate\":1488805337447,\"parameters\":[{\"name\":\"2e5dafb6-5a1c-4a66-9dca-5841f99ea735\",\"encoding\":\"UTF-8\",\"value\":\"publicKeyPath: /tmp/Input-11594765342486/user.pem\\nuserName: zh9314\\nsubnets:\\n- {name: s1, subnet: 192.168.10.0, netmask: 255.255.255.0}\\ncomponents:\\n- name: 8fcc1788d9ee462c826572c79fdb2a6a\\n type: Switch.nodes.Compute\\n nodeType: t2.medium\\n OStype: Ubuntu 16.04\\n script: /tmp/Input-11594765342486/guiscipt.sh\\n domain: ec2.us-east-1.amazonaws.com\\n installation: null\\n clusterType: swarm\\n role: master\\n dockers: mogswitch/ProxyTranscoder:1.0\\n public_address: 34.207.73.18\\n instanceId: i-0e82b5624a0df99b1\\n ethernet_port:\\n - {name: p1, subnet_name: s1, address: 192.168.10.10}\\n- name: 8fcc1788d9ee462c826572c79fdb2a6a\\n type: Switch.nodes.Compute\\n nodeType: t2.medium\\n OStype: Ubuntu 16.04\\n script: /tmp/Input-11594765342486/guiscipt.sh\\n domain: ec2.us-east-1.amazonaws.com\\n installation: null\\n clusterType: swarm\\n role: slave\\n dockers: mogswitch/ProxyTranscoder:1.0\\n public_address: 34.207.73.18\\n instanceId: i-0e82b5624a0df99b1\\n ethernet_port:\\n - {name: p1, subnet_name: s1, address: 192.168.10.11}\\n\"},{\"name\":\"kubernetes\",\"encoding\":\"UTF-8\",\"value\":\"34.207.73.18 ubuntu /tmp/Input-11594765342486/Virginia.pem master\\n34.207.73.18 ubuntu /tmp/Input-11594765342486/Virginia.pem slave\\n\"}]}";
String
strResponse
=
FileUtils
.
readFileToString
(
new
File
(
path
));
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/service/SimplePlannerService.java
View file @
f102f1f4
...
@@ -56,7 +56,7 @@ public class SimplePlannerService {
...
@@ -56,7 +56,7 @@ public class SimplePlannerService {
private
PlanDao
planDao
;
private
PlanDao
planDao
;
public
Plan
getPlan
(
String
toscaId
)
throws
JSONException
,
IOException
,
TimeoutException
,
InterruptedException
{
public
Plan
getPlan
(
String
toscaId
)
throws
JSONException
,
IOException
,
TimeoutException
,
InterruptedException
{
ToscaRepresentation
tosca
=
toscaService
.
getDao
().
findOne
(
toscaId
);
ToscaRepresentation
tosca
=
toscaService
.
findOne
(
toscaId
);
Message
plannerInvokationMessage
=
buildSimplePlannerMessage
(
tosca
);
Message
plannerInvokationMessage
=
buildSimplePlannerMessage
(
tosca
);
Plan
topLevel
;
Plan
topLevel
;
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/service/ToscaService.java
View file @
f102f1f4
...
@@ -22,8 +22,13 @@ import nl.uva.sne.drip.api.dao.ToscaDao;
...
@@ -22,8 +22,13 @@ 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.v1.types.ToscaRepresentation
;
import
nl.uva.sne.drip.commons.v1.types.ToscaRepresentation
;
import
nl.uva.sne.drip.commons.utils.Converter
;
import
nl.uva.sne.drip.commons.utils.Converter
;
import
nl.uva.sne.drip.commons.v1.types.User
;
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.security.access.prepost.PostAuthorize
;
import
org.springframework.security.access.prepost.PostFilter
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
...
@@ -32,13 +37,14 @@ import org.springframework.web.multipart.MultipartFile;
...
@@ -32,13 +37,14 @@ import org.springframework.web.multipart.MultipartFile;
* @author S. Koulouzis
* @author S. Koulouzis
*/
*/
@Service
@Service
@PreAuthorize
(
"isAuthenticated()"
)
public
class
ToscaService
{
public
class
ToscaService
{
@Autowired
@Autowired
private
ToscaDao
dao
;
private
ToscaDao
dao
;
public
String
get
(
String
id
,
String
fromat
)
throws
JSONException
{
public
String
get
(
String
id
,
String
fromat
)
throws
JSONException
{
ToscaRepresentation
tosca
=
dao
.
findOne
(
id
);
ToscaRepresentation
tosca
=
findOne
(
id
);
if
(
tosca
==
null
)
{
if
(
tosca
==
null
)
{
throw
new
NotFoundException
();
throw
new
NotFoundException
();
}
}
...
@@ -60,7 +66,7 @@ public class ToscaService {
...
@@ -60,7 +66,7 @@ public class ToscaService {
return
ymlStr
;
return
ymlStr
;
}
}
public
String
save
(
MultipartFile
file
)
throws
IOException
{
public
String
save
File
(
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
();
...
@@ -71,11 +77,11 @@ public class ToscaService {
...
@@ -71,11 +77,11 @@ public class ToscaService {
ToscaRepresentation
t
=
new
ToscaRepresentation
();
ToscaRepresentation
t
=
new
ToscaRepresentation
();
t
.
setName
(
name
);
t
.
setName
(
name
);
t
.
setKvMap
(
map
);
t
.
setKvMap
(
map
);
dao
.
save
(
t
);
save
(
t
);
return
t
.
getId
();
return
t
.
getId
();
}
}
public
String
save
(
String
yamlString
,
String
name
)
throws
IOException
{
public
String
save
YamlString
(
String
yamlString
,
String
name
)
throws
IOException
{
if
(
name
==
null
)
{
if
(
name
==
null
)
{
name
=
System
.
currentTimeMillis
()
+
"_"
+
"tosca.yaml"
;
name
=
System
.
currentTimeMillis
()
+
"_"
+
"tosca.yaml"
;
}
}
...
@@ -84,27 +90,31 @@ public class ToscaService {
...
@@ -84,27 +90,31 @@ public class ToscaService {
ToscaRepresentation
t
=
new
ToscaRepresentation
();
ToscaRepresentation
t
=
new
ToscaRepresentation
();
t
.
setName
(
name
);
t
.
setName
(
name
);
t
.
setKvMap
(
map
);
t
.
setKvMap
(
map
);
dao
.
save
(
t
);
save
(
t
);
return
t
.
getId
();
return
t
.
getId
();
}
}
public
void
delete
(
String
id
)
{
@PostAuthorize
(
"(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
dao
.
delete
(
id
);
public
ToscaRepresentation
delete
(
String
id
)
{
ToscaRepresentation
tr
=
dao
.
findOne
(
id
);
dao
.
delete
(
tr
);
return
tr
;
}
}
@PostFilter
(
"(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
public
List
<
ToscaRepresentation
>
findAll
()
{
public
List
<
ToscaRepresentation
>
findAll
()
{
return
dao
.
findAll
();
return
dao
.
findAll
();
}
}
public
ToscaDao
getDao
()
{
@PostAuthorize
(
"(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
return
dao
;
public
ToscaRepresentation
findOne
(
String
id
)
{
return
dao
.
findOne
(
id
);
}
}
public
ToscaRepresentation
get
(
String
planID
)
{
private
ToscaRepresentation
save
(
ToscaRepresentation
t
)
{
ToscaRepresentation
tosca
=
dao
.
findOne
(
planID
);
User
user
=
(
User
)
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
if
(
tosca
==
null
)
{
String
owner
=
user
.
getUsername
();
throw
new
NotFoundException
();
t
.
setOwner
(
owner
);
}
return
dao
.
save
(
t
);
return
tosca
;
}
}
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/service/UserKeyService.java
View file @
f102f1f4
...
@@ -19,7 +19,11 @@ import java.util.ArrayList;
...
@@ -19,7 +19,11 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.List
;
import
nl.uva.sne.drip.api.dao.UserKeyDao
;
import
nl.uva.sne.drip.api.dao.UserKeyDao
;
import
nl.uva.sne.drip.commons.v1.types.LoginKey
;
import
nl.uva.sne.drip.commons.v1.types.LoginKey
;
import
nl.uva.sne.drip.commons.v1.types.User
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PostAuthorize
;
import
org.springframework.security.access.prepost.PostFilter
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
/**
/**
...
@@ -32,12 +36,8 @@ public class UserKeyService {
...
@@ -32,12 +36,8 @@ public class UserKeyService {
@Autowired
@Autowired
UserKeyDao
dao
;
UserKeyDao
dao
;
public
UserKeyDao
getDao
()
{
return
dao
;
}
public
List
<
LoginKey
>
getAll
(
LoginKey
.
Type
type
)
{
public
List
<
LoginKey
>
getAll
(
LoginKey
.
Type
type
)
{
List
<
LoginKey
>
all
=
getDao
().
findAll
();
List
<
LoginKey
>
all
=
findAll
();
if
(
all
!=
null
)
{
if
(
all
!=
null
)
{
List
<
LoginKey
>
allPublic
=
new
ArrayList
<>();
List
<
LoginKey
>
allPublic
=
new
ArrayList
<>();
for
(
LoginKey
tr
:
all
)
{
for
(
LoginKey
tr
:
all
)
{
...
@@ -51,7 +51,7 @@ public class UserKeyService {
...
@@ -51,7 +51,7 @@ public class UserKeyService {
}
}
public
LoginKey
get
(
String
id
,
LoginKey
.
Type
type
)
{
public
LoginKey
get
(
String
id
,
LoginKey
.
Type
type
)
{
LoginKey
key
=
getDao
().
findOne
(
id
);
LoginKey
key
=
findOne
(
id
);
if
(
key
.
getType
().
equals
(
type
))
{
if
(
key
.
getType
().
equals
(
type
))
{
return
key
;
return
key
;
}
}
...
@@ -61,7 +61,31 @@ public class UserKeyService {
...
@@ -61,7 +61,31 @@ public class UserKeyService {
public
void
delete
(
String
id
,
LoginKey
.
Type
type
)
{
public
void
delete
(
String
id
,
LoginKey
.
Type
type
)
{
LoginKey
k
=
get
(
id
,
type
);
LoginKey
k
=
get
(
id
,
type
);
if
(
k
!=
null
)
{
if
(
k
!=
null
)
{
getDao
().
delete
(
k
);
delete
(
k
);
}
}
}
}
@PostFilter
(
"(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
public
List
<
LoginKey
>
findAll
()
{
return
dao
.
findAll
();
}
@PostAuthorize
(
"(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
public
LoginKey
findOne
(
String
id
)
{
return
dao
.
findOne
(
id
);
}
@PostAuthorize
(
"(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
public
LoginKey
delete
(
LoginKey
k
)
{
k
=
dao
.
findOne
(
k
.
getId
());
dao
.
delete
(
k
);
return
k
;
}
public
LoginKey
save
(
LoginKey
upk
)
{
User
user
=
(
User
)
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
String
owner
=
user
.
getUsername
();
upk
.
setOwner
(
owner
);
return
dao
.
save
(
upk
);
}
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/service/UserScriptService.java
View file @
f102f1f4
...
@@ -15,21 +15,52 @@
...
@@ -15,21 +15,52 @@
*/
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
service
;
package
nl
.
uva
.
sne
.
drip
.
api
.
service
;
import
nl.uva.sne.drip.api.dao.UserScriptDao
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
nl.uva.sne.drip.api.dao.ScriptDao
;
import
nl.uva.sne.drip.commons.v1.types.Script
;
import
nl.uva.sne.drip.commons.v1.types.User
;
import
org.springframework.security.access.prepost.PostAuthorize
;
import
org.springframework.security.access.prepost.PostFilter
;
import
org.springframework.security.core.context.SecurityContextHolder
;
/**
/**
*
*
* @author S. Koulouzis
* @author S. Koulouzis
*/
*/
@Service
@Service
@PreAuthorize
(
"isAuthenticated()"
)
public
class
UserScriptService
{
public
class
UserScriptService
{
@Autowired
@Autowired
User
ScriptDao
dao
;
ScriptDao
dao
;
public
UserScriptDao
getDao
()
{
public
Script
save
(
Script
script
)
{
return
dao
;
User
user
=
(
User
)
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
String
owner
=
user
.
getUsername
();
script
.
setOwner
(
owner
);
return
dao
.
save
(
script
);
}
@PostAuthorize
(
"(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
public
Script
findOne
(
String
id
)
{
Script
script
=
dao
.
findOne
(
id
);
return
script
;
}
@PostAuthorize
(
"(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
public
Script
delete
(
String
id
)
{
Script
script
=
dao
.
findOne
(
id
);
dao
.
delete
(
script
);
return
script
;
}
// @PreAuthorize(" (hasRole('ROLE_ADMIN')) or (hasRole('ROLE_USER'))")
@PostFilter
(
"(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
// @PostFilter("hasPermission(filterObject, 'read') or hasPermission(filterObject, 'admin')")
public
List
<
Script
>
findAll
()
{
return
dao
.
findAll
();
}
}
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/v0/rest/CloudConfigurationController0.java
View file @
f102f1f4
...
@@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.RestController;
import
nl.uva.sne.drip.api.dao.CloudCredentialsDao
;
import
nl.uva.sne.drip.api.dao.CloudCredentialsDao
;
import
nl.uva.sne.drip.api.exception.NullKeyException
;
import
nl.uva.sne.drip.api.exception.NullKeyException
;
import
nl.uva.sne.drip.api.exception.NullKeyIDException
;
import
nl.uva.sne.drip.api.exception.NullKeyIDException
;
import
nl.uva.sne.drip.api.service.CloudCredentialsService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.commons.v0.types.Configure
;
import
nl.uva.sne.drip.commons.v0.types.Configure
;
import
nl.uva.sne.drip.commons.v1.types.LoginKey
;
import
nl.uva.sne.drip.commons.v1.types.LoginKey
;
...
@@ -49,7 +50,7 @@ import org.springframework.web.bind.annotation.RequestBody;
...
@@ -49,7 +50,7 @@ import org.springframework.web.bind.annotation.RequestBody;
public
class
CloudConfigurationController0
{
public
class
CloudConfigurationController0
{
@Autowired
@Autowired
private
CloudCredentials
Dao
cloudCredentialsDao
;
private
CloudCredentials
Service
cloudCredentialsDao
;
@RequestMapping
(
value
=
"/ec2"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
TEXT_XML_VALUE
)
@RequestMapping
(
value
=
"/ec2"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
TEXT_XML_VALUE
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
...
@@ -77,7 +78,7 @@ public class CloudConfigurationController0 {
...
@@ -77,7 +78,7 @@ public class CloudConfigurationController0 {
}
}
cloudCredentials
.
setLogineKeys
(
loginKeys
);
cloudCredentials
.
setLogineKeys
(
loginKeys
);
cloudCredentials
.
setCloudProviderName
(
"ec2"
);
cloudCredentials
.
setCloudProviderName
(
"ec2"
);
cloudCredentials
=
cloudCredentialsDao
.
save
(
cloudCredentials
);
cloudCredentials
=
cloudCredentialsDao
.
save
(
cloudCredentials
);
return
"Success: "
+
cloudCredentials
.
getId
();
return
"Success: "
+
cloudCredentials
.
getId
();
}
}
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/v0/rest/PlannerController0.java
View file @
f102f1f4
...
@@ -35,7 +35,6 @@ import nl.uva.sne.drip.api.service.UserService;
...
@@ -35,7 +35,6 @@ import nl.uva.sne.drip.api.service.UserService;
import
nl.uva.sne.drip.commons.utils.Converter
;
import
nl.uva.sne.drip.commons.utils.Converter
;
import
nl.uva.sne.drip.commons.v0.types.File
;
import
nl.uva.sne.drip.commons.v0.types.File
;
import
nl.uva.sne.drip.commons.v0.types.Plan
;
import
nl.uva.sne.drip.commons.v0.types.Plan
;
import
org.apache.commons.io.FilenameUtils
;
import
org.json.JSONException
;
import
org.json.JSONException
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
@@ -65,44 +64,26 @@ public class PlannerController0 {
...
@@ -65,44 +64,26 @@ public class PlannerController0 {
try
{
try
{
String
yaml
=
plan0
.
file
;
String
yaml
=
plan0
.
file
;
yaml
=
yaml
.
replaceAll
(
"\\\\n"
,
"\n"
);
yaml
=
yaml
.
replaceAll
(
"\\\\n"
,
"\n"
);
String
id
=
toscaService
.
save
(
yaml
,
null
);
String
id
=
toscaService
.
save
YamlString
(
yaml
,
null
);
nl
.
uva
.
sne
.
drip
.
commons
.
v1
.
types
.
Plan
plan1
=
plannerService
.
getPlan
(
id
);
nl
.
uva
.
sne
.
drip
.
commons
.
v1
.
types
.
Plan
plan1
=
plannerService
.
getPlan
(
id
);
Result
r
=
new
Result
();
Result
r
=
new
Result
();
r
.
info
=
(
"INFO"
);
r
.
info
=
(
"INFO"
);
r
.
status
=
(
"Success"
);
r
.
status
=
(
"Success"
);
List
<
File
>
files
=
new
ArrayList
<>();
List
<
File
>
files
=
new
ArrayList
<>();
File
e
=
new
File
();
File
e
=
Converter
.
plan1toFile
(
plan1
);
e
.
level
=
String
.
valueOf
(
plan1
.
getLevel
());
String
p1Name
=
FilenameUtils
.
getBaseName
(
plan1
.
getName
());
if
(
p1Name
==
null
)
{
p1Name
=
"Planned_tosca_file_"
+
plan1
.
getLevel
();
plan1
.
setName
(
p1Name
);
plannerService
.
getDao
().
save
(
plan1
);
}
e
.
name
=
p1Name
;
e
.
content
=
Converter
.
map2YmlString
(
plan1
.
getKeyValue
()).
replaceAll
(
"\n"
,
"\\n"
);
files
.
add
(
e
);
files
.
add
(
e
);
for
(
String
lowiID
:
plan1
.
getLoweLevelPlanIDs
())
{
for
(
String
lowiID
:
plan1
.
getLoweLevelPlanIDs
())
{
nl
.
uva
.
sne
.
drip
.
commons
.
v1
.
types
.
Plan
lowPlan1
=
plannerService
.
getDao
().
findOne
(
lowiID
);
nl
.
uva
.
sne
.
drip
.
commons
.
v1
.
types
.
Plan
lowPlan1
=
plannerService
.
findOne
(
lowiID
);
e
=
new
File
();
e
=
Converter
.
plan1toFile
(
lowPlan1
);
e
.
level
=
String
.
valueOf
(
lowPlan1
.
getLevel
());
p1Name
=
lowPlan1
.
getName
();
if
(
p1Name
==
null
)
{
p1Name
=
"Planned_tosca_file_"
+
lowPlan1
.
getLevel
();
plan1
.
setName
(
p1Name
);
plannerService
.
getDao
().
save
(
lowPlan1
);
}
e
.
name
=
p1Name
;
e
.
content
=
Converter
.
map2YmlString
(
lowPlan1
.
getKeyValue
()).
replaceAll
(
"\n"
,
"\\n"
);;
files
.
add
(
e
);
files
.
add
(
e
);
//Don't save them cause they will be re-uploaded in the provision step
plannerService
.
delete
(
lowPlan1
.
getId
());
}
}
r
.
file
=
files
;
r
.
file
=
files
;
plannerService
.
delete
(
plan1
.
getId
());
return
r
;
return
r
;
}
catch
(
IOException
|
JSONException
|
TimeoutException
|
InterruptedException
ex
)
{
}
catch
(
IOException
|
JSONException
|
TimeoutException
|
InterruptedException
ex
)
{
Logger
.
getLogger
(
PlannerController0
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
Logger
.
getLogger
(
PlannerController0
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/v0/rest/ProvisionController0.java
View file @
f102f1f4
...
@@ -15,24 +15,16 @@
...
@@ -15,24 +15,16 @@
*/
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
v0
.
rest
;
package
nl
.
uva
.
sne
.
drip
.
api
.
v0
.
rest
;
import
com.fasterxml.jackson.core.JsonParser
;
import
nl.uva.sne.drip.commons.v1.types.ProvisionInfo
;
import
nl.uva.sne.drip.commons.v1.types.ProvisionInfo
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Hash
Map
;
import
java.util.Hash
Set
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.concurrent.TimeoutException
;
import
java.util.concurrent.TimeoutException
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
javax.annotation.security.RolesAllowed
;
import
javax.annotation.security.RolesAllowed
;
import
nl.uva.sne.drip.api.dao.CloudCredentialsDao
;
import
nl.uva.sne.drip.commons.v1.types.Message
;
import
nl.uva.sne.drip.commons.v1.types.MessageParameter
;
import
nl.uva.sne.drip.commons.utils.Converter
;
import
nl.uva.sne.drip.commons.utils.Converter
;
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
;
...
@@ -41,21 +33,18 @@ import org.springframework.web.bind.annotation.RequestMapping;
...
@@ -41,21 +33,18 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
nl.uva.sne.drip.api.exception.BadRequestException
;
import
nl.uva.sne.drip.api.service.CloudCredentialsService
;
import
nl.uva.sne.drip.api.exception.CloudCredentialsNotFoundException
;
import
nl.uva.sne.drip.api.service.PlannerService
;
import
nl.uva.sne.drip.api.exception.PlanNotFoundException
;
import
nl.uva.sne.drip.api.service.ProvisionService
;
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.v0.types.File
;
import
nl.uva.sne.drip.commons.v0.types.Upload
;
import
nl.uva.sne.drip.commons.v0.types.Upload
;
import
nl.uva.sne.drip.commons.v1.types.CloudCredentials
;
import
nl.uva.sne.drip.commons.v1.types.CloudCredentials
;
import
nl.uva.sne.drip.commons.v1.types.LoginKey
;
import
nl.uva.sne.drip.commons.v1.types.LoginKey
;
import
nl.uva.sne.drip.commons.v1.types.Plan
;
import
nl.uva.sne.drip.commons.v1.types.Plan
;
import
nl.uva.sne.drip.commons.v1.types.Script
;
import
nl.uva.sne.drip.commons.v1.types.Script
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.io.FilenameUtils
;
import
org.json.JSONException
;
import
org.json.JSONException
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
@@ -71,9 +60,6 @@ import org.springframework.web.bind.annotation.RequestBody;
...
@@ -71,9 +60,6 @@ import org.springframework.web.bind.annotation.RequestBody;
@Component
@Component
public
class
ProvisionController0
{
public
class
ProvisionController0
{
@Value
(
"${message.broker.host}"
)
private
String
messageBrokerHost
;
@Autowired
@Autowired
private
UserScriptService
userScriptService
;
private
UserScriptService
userScriptService
;
...
@@ -81,13 +67,34 @@ public class ProvisionController0 {
...
@@ -81,13 +67,34 @@ public class ProvisionController0 {
private
UserKeyService
userKeysService
;
private
UserKeyService
userKeysService
;
@Autowired
@Autowired
private
CloudCredentials
Dao
cloudCredentialsDao
;
private
CloudCredentials
Service
cloudCredentialsService
;
@Autowired
@Autowired
private
ProvisionService
provisionService
;
private
ProvisionService
provisionService
;
@Autowired
@Autowired
private
SimplePlannerService
planService
;
private
PlannerService
planService
;
@RequestMapping
(
value
=
"/get"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
TEXT_XML_VALUE
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
Upload
provision
()
{
try
{
Upload
up
=
new
Upload
();
up
.
user
=
"user"
;
up
.
pwd
=
"123"
;
List
<
File
>
files
=
new
ArrayList
<>();
Plan
plan1
=
planService
.
findAll
().
get
(
0
);
File
f
=
Converter
.
plan1toFile
(
plan1
);
files
.
add
(
f
);
up
.
file
=
files
;
return
up
;
}
catch
(
JSONException
ex
)
{
Logger
.
getLogger
(
ProvisionController0
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
return
null
;
}
@RequestMapping
(
value
=
"/upload"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
TEXT_XML_VALUE
)
@RequestMapping
(
value
=
"/upload"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
TEXT_XML_VALUE
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
...
@@ -95,185 +102,38 @@ public class ProvisionController0 {
...
@@ -95,185 +102,38 @@ public class ProvisionController0 {
String
provision
(
@RequestBody
Upload
upload
)
{
String
provision
(
@RequestBody
Upload
upload
)
{
ProvisionInfo
provInfo
=
new
ProvisionInfo
();
ProvisionInfo
provInfo
=
new
ProvisionInfo
();
String
cloudCredID
=
null
;
CloudCredentials
cloudCred
=
cloudCredentialsService
.
findAll
().
get
(
0
);
String
cloudCredID
=
cloudCred
.
getId
();
provInfo
.
setCloudcloudCredentialsID
(
cloudCredID
);
provInfo
.
setCloudcloudCredentialsID
(
cloudCredID
);
String
planID
=
null
;
List
<
nl
.
uva
.
sne
.
drip
.
commons
.
v0
.
types
.
File
>
plans
=
upload
.
file
;
provInfo
.
setPlanID
(
planID
);
nl
.
uva
.
sne
.
drip
.
commons
.
v1
.
types
.
Plan
topLevelPlan
=
null
;
String
userKeyID
=
null
;
Set
<
String
>
loweLevelPlansIDs
=
new
HashSet
<>();
provInfo
.
setUserKeyID
(
userKeyID
);
for
(
nl
.
uva
.
sne
.
drip
.
commons
.
v0
.
types
.
File
p
:
plans
)
{
String
scriptID
=
null
;
nl
.
uva
.
sne
.
drip
.
commons
.
v1
.
types
.
Plan
plan1
=
Converter
.
File2Plan1
(
p
);
provInfo
.
setScriptID
(
scriptID
);
if
(
plan1
.
getLevel
()
==
0
)
{
topLevelPlan
=
plan1
;
provisionService
.
getDao
().
save
(
provInfo
);
}
else
{
loweLevelPlansIDs
.
add
(
plan1
.
getId
());
return
"Success: Infrastructure files are uploaded! Action number: "
planService
.
save
(
plan1
);
+
provInfo
.
getId
();
}
private
Message
buildProvisionerMessage
(
ProvisionInfo
pReq
)
throws
JSONException
,
IOException
{
Message
invokationMessage
=
new
Message
();
List
<
MessageParameter
>
parameters
=
new
ArrayList
();
CloudCredentials
cred
=
cloudCredentialsDao
.
findOne
(
pReq
.
getCloudcloudCredentialsID
());
if
(
cred
==
null
)
{
throw
new
CloudCredentialsNotFoundException
();
}
MessageParameter
conf
=
buildCloudConfParam
(
cred
);
parameters
.
add
(
conf
);
List
<
MessageParameter
>
certs
=
buildCertificatesParam
(
cred
);
parameters
.
addAll
(
certs
);
List
<
MessageParameter
>
topologies
=
buildTopologyParams
(
pReq
.
getPlanID
());
parameters
.
addAll
(
topologies
);
String
scriptID
=
pReq
.
getscriptID
();
if
(
scriptID
!=
null
)
{
List
<
MessageParameter
>
userScripts
=
buildScriptParams
(
scriptID
);
parameters
.
addAll
(
userScripts
);
}
String
userKeyID
=
pReq
.
getUserKeyID
();
if
(
userKeyID
!=
null
)
{
List
<
MessageParameter
>
userKeys
=
buildKeysParams
(
userKeyID
);
parameters
.
addAll
(
userKeys
);
}
invokationMessage
.
setParameters
(
parameters
);
invokationMessage
.
setCreationDate
((
System
.
currentTimeMillis
()));
return
invokationMessage
;
}
private
MessageParameter
buildCloudConfParam
(
CloudCredentials
cred
)
throws
JsonProcessingException
,
JSONException
,
IOException
{
MessageParameter
conf
=
null
;
String
provider
=
cred
.
getCloudProviderName
();
if
(
provider
==
null
)
{
throw
new
BadRequestException
(
"Provider name can't be null. Check the cloud credentials: "
+
cred
.
getId
());
}
switch
(
cred
.
getCloudProviderName
().
toLowerCase
())
{
case
"ec2"
:
conf
=
buildEC2Conf
(
cred
);
break
;
}
return
conf
;
}
private
List
<
MessageParameter
>
buildCertificatesParam
(
CloudCredentials
cred
)
{
List
<
LoginKey
>
loginKeys
=
cred
.
getLoginKeys
();
if
(
loginKeys
==
null
||
loginKeys
.
isEmpty
())
{
throw
new
BadRequestException
(
"Log in keys can't be empty"
);
}
List
<
MessageParameter
>
parameters
=
new
ArrayList
<>();
for
(
LoginKey
lk
:
loginKeys
)
{
String
domainName
=
lk
.
getAttributes
().
get
(
"domain_name"
);
if
(
domainName
==
null
)
{
domainName
=
lk
.
getAttributes
().
get
(
"domain_name "
);
}
}
MessageParameter
cert
=
new
MessageParameter
();
cert
.
setName
(
"certificate"
);
cert
.
setValue
(
lk
.
getKey
());
Map
<
String
,
String
>
attributes
=
new
HashMap
<>();
attributes
.
put
(
"filename"
,
domainName
);
cert
.
setAttributes
(
attributes
);
parameters
.
add
(
cert
);
}
return
parameters
;
}
private
List
<
MessageParameter
>
buildTopologyParams
(
String
planID
)
throws
JSONException
{
Plan
plan
=
planService
.
getDao
().
findOne
(
planID
);
if
(
plan
==
null
)
{
throw
new
PlanNotFoundException
();
}
List
<
MessageParameter
>
parameters
=
new
ArrayList
();
MessageParameter
topology
=
new
MessageParameter
();
topology
.
setName
(
"topology"
);
topology
.
setValue
(
Converter
.
map2YmlString
(
plan
.
getKeyValue
()));
Map
<
String
,
String
>
attributes
=
new
HashMap
<>();
attributes
.
put
(
"level"
,
String
.
valueOf
(
plan
.
getLevel
()));
attributes
.
put
(
"filename"
,
FilenameUtils
.
removeExtension
(
plan
.
getName
()));
topology
.
setAttributes
(
attributes
);
parameters
.
add
(
topology
);
Set
<
String
>
ids
=
plan
.
getLoweLevelPlanIDs
();
for
(
String
lowID
:
ids
)
{
Plan
lowPlan
=
planService
.
getDao
().
findOne
(
lowID
);
topology
=
new
MessageParameter
();
topology
.
setName
(
"topology"
);
topology
.
setValue
(
Converter
.
map2YmlString
(
lowPlan
.
getKeyValue
()));
attributes
=
new
HashMap
<>();
attributes
.
put
(
"level"
,
String
.
valueOf
(
lowPlan
.
getLevel
()));
attributes
.
put
(
"filename"
,
FilenameUtils
.
removeExtension
(
lowPlan
.
getName
()));
topology
.
setAttributes
(
attributes
);
parameters
.
add
(
topology
);
}
}
return
parameters
;
topLevelPlan
.
setLoweLevelPlansIDs
(
loweLevelPlansIDs
);
}
topLevelPlan
=
planService
.
save
(
topLevelPlan
);
String
planID
=
topLevelPlan
.
getId
();
private
MessageParameter
buildEC2Conf
(
CloudCredentials
cred
)
throws
JsonProcessingException
,
JSONException
,
IOException
{
provInfo
.
setPlanID
(
planID
);
List
<
LoginKey
>
allKeys
=
userKeysService
.
findAll
();
Properties
prop
=
Converter
.
getEC2Properties
(
cred
);
if
(
allKeys
!=
null
&&
!
allKeys
.
isEmpty
())
{
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
String
userKeyID
=
allKeys
.
get
(
0
).
getId
();
prop
.
store
(
baos
,
null
);
provInfo
.
setUserKeyID
(
userKeyID
);
byte
[]
bytes
=
baos
.
toByteArray
();
MessageParameter
conf
=
new
MessageParameter
();
conf
.
setName
(
"ec2.conf"
);
String
charset
=
"UTF-8"
;
conf
.
setValue
(
new
String
(
bytes
,
charset
));
return
conf
;
}
private
List
<
MessageParameter
>
buildScriptParams
(
String
userScriptID
)
{
Script
script
=
userScriptService
.
getDao
().
findOne
(
userScriptID
);
if
(
script
==
null
)
{
throw
new
BadRequestException
(
"User script: "
+
userScriptID
+
" was not found"
);
}
}
List
<
MessageParameter
>
parameters
=
new
ArrayList
();
List
<
Script
>
allScripts
=
userScriptService
.
findAll
();
MessageParameter
scriptParameter
=
new
MessageParameter
();
if
(
allScripts
!=
null
&&
!
allScripts
.
isEmpty
())
{
scriptParameter
.
setName
(
"guiscript"
);
String
scriptID
=
allScripts
.
get
(
0
).
getId
();
scriptParameter
.
setValue
(
script
.
getContents
());
provInfo
.
setScriptID
(
scriptID
);
scriptParameter
.
setEncoding
(
"UTF-8"
);
parameters
.
add
(
scriptParameter
);
return
parameters
;
}
private
List
<
MessageParameter
>
buildKeysParams
(
String
userKeyID
)
{
LoginKey
key
=
userKeysService
.
get
(
userKeyID
,
LoginKey
.
Type
.
PUBLIC
);
if
(
key
==
null
)
{
throw
new
BadRequestException
(
"User key: "
+
userKeyID
+
" was not found"
);
}
}
List
<
MessageParameter
>
parameters
=
new
ArrayList
();
provInfo
=
provisionService
.
save
(
provInfo
);
MessageParameter
keyParameter
=
new
MessageParameter
();
return
"Success: Infrastructure files are uploaded! Action number: "
keyParameter
.
setName
(
"sshkey"
);
+
provInfo
.
getId
();
keyParameter
.
setValue
(
key
.
getKey
());
keyParameter
.
setEncoding
(
"UTF-8"
);
parameters
.
add
(
keyParameter
);
return
parameters
;
}
}
private
Message
generateFakeResponse
(
String
path
)
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\"}]}";
// String strResponse = "{\"creationDate\":1488805337447,\"parameters\":[{\"name\":\"2e5dafb6-5a1c-4a66-9dca-5841f99ea735\",\"encoding\":\"UTF-8\",\"value\":\"publicKeyPath: /tmp/Input-11594765342486/user.pem\\nuserName: zh9314\\nsubnets:\\n- {name: s1, subnet: 192.168.10.0, netmask: 255.255.255.0}\\ncomponents:\\n- name: 8fcc1788d9ee462c826572c79fdb2a6a\\n type: Switch.nodes.Compute\\n nodeType: t2.medium\\n OStype: Ubuntu 16.04\\n script: /tmp/Input-11594765342486/guiscipt.sh\\n domain: ec2.us-east-1.amazonaws.com\\n installation: null\\n clusterType: swarm\\n role: master\\n dockers: mogswitch/ProxyTranscoder:1.0\\n public_address: 34.207.73.18\\n instanceId: i-0e82b5624a0df99b1\\n ethernet_port:\\n - {name: p1, subnet_name: s1, address: 192.168.10.10}\\n- name: 8fcc1788d9ee462c826572c79fdb2a6a\\n type: Switch.nodes.Compute\\n nodeType: t2.medium\\n OStype: Ubuntu 16.04\\n script: /tmp/Input-11594765342486/guiscipt.sh\\n domain: ec2.us-east-1.amazonaws.com\\n installation: null\\n clusterType: swarm\\n role: slave\\n dockers: mogswitch/ProxyTranscoder:1.0\\n public_address: 34.207.73.18\\n instanceId: i-0e82b5624a0df99b1\\n ethernet_port:\\n - {name: p1, subnet_name: s1, address: 192.168.10.11}\\n\"},{\"name\":\"kubernetes\",\"encoding\":\"UTF-8\",\"value\":\"34.207.73.18 ubuntu /tmp/Input-11594765342486/Virginia.pem master\\n34.207.73.18 ubuntu /tmp/Input-11594765342486/Virginia.pem slave\\n\"}]}";
String
strResponse
=
FileUtils
.
readFileToString
(
new
File
(
path
));
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/v1/rest/CloudCredentialsController.java
View file @
f102f1f4
...
@@ -39,9 +39,7 @@ import nl.uva.sne.drip.api.exception.NullKeyIDException;
...
@@ -39,9 +39,7 @@ import nl.uva.sne.drip.api.exception.NullKeyIDException;
import
nl.uva.sne.drip.api.service.CloudCredentialsService
;
import
nl.uva.sne.drip.api.service.CloudCredentialsService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.commons.v1.types.LoginKey
;
import
nl.uva.sne.drip.commons.v1.types.LoginKey
;
import
nl.uva.sne.drip.commons.v1.types.User
;
import
org.apache.commons.io.FilenameUtils
;
import
org.apache.commons.io.FilenameUtils
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RequestParam
;
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/v1/rest/DeployController.java
View file @
f102f1f4
...
@@ -26,7 +26,6 @@ import java.util.concurrent.TimeoutException;
...
@@ -26,7 +26,6 @@ import java.util.concurrent.TimeoutException;
import
java.util.logging.Level
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
java.util.logging.Logger
;
import
javax.annotation.security.RolesAllowed
;
import
javax.annotation.security.RolesAllowed
;
import
nl.uva.sne.drip.api.dao.CloudCredentialsDao
;
import
nl.uva.sne.drip.api.exception.BadRequestException
;
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.commons.v1.types.Message
;
import
nl.uva.sne.drip.commons.v1.types.Message
;
...
@@ -34,13 +33,13 @@ import nl.uva.sne.drip.commons.v1.types.MessageParameter;
...
@@ -34,13 +33,13 @@ import nl.uva.sne.drip.commons.v1.types.MessageParameter;
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
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
nl.uva.sne.drip.api.rpc.DRIPCaller
;
import
nl.uva.sne.drip.api.rpc.DRIPCaller
;
import
nl.uva.sne.drip.api.rpc.DeployerCaller
;
import
nl.uva.sne.drip.api.rpc.DeployerCaller
;
import
nl.uva.sne.drip.api.service.CloudCredentialsService
;
import
nl.uva.sne.drip.api.service.ClusterCredentialService
;
import
nl.uva.sne.drip.api.service.ClusterCredentialService
;
import
nl.uva.sne.drip.api.service.ProvisionService
;
import
nl.uva.sne.drip.api.service.ProvisionService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.api.service.UserService
;
...
@@ -67,7 +66,7 @@ public class DeployController {
...
@@ -67,7 +66,7 @@ public class DeployController {
private
String
messageBrokerHost
;
private
String
messageBrokerHost
;
@Autowired
@Autowired
private
CloudCredentials
Dao
cloudCredentialsDao
;
private
CloudCredentials
Service
cloudCredentialsService
;
@Autowired
@Autowired
private
ProvisionService
provisionService
;
private
ProvisionService
provisionService
;
...
@@ -152,19 +151,19 @@ public class DeployController {
...
@@ -152,19 +151,19 @@ public class DeployController {
String
delete
(
@PathVariable
(
"id"
)
String
id
)
{
String
delete
(
@PathVariable
(
"id"
)
String
id
)
{
ClusterCredentials
cred
=
clusterCredentialService
.
getDao
().
findOne
(
id
);
ClusterCredentials
cred
=
clusterCredentialService
.
getDao
().
findOne
(
id
);
if
(
cred
!=
null
)
{
if
(
cred
!=
null
)
{
provisionService
.
getDao
().
delete
(
id
);
provisionService
.
delete
(
id
);
return
"Deleted : "
+
id
;
return
"Deleted : "
+
id
;
}
}
throw
new
NotFoundException
();
throw
new
NotFoundException
();
}
}
private
Message
buildDeployerMessage
(
String
provisionID
,
String
clusterType
)
{
private
Message
buildDeployerMessage
(
String
provisionID
,
String
clusterType
)
{
ProvisionInfo
pro
=
provisionService
.
getDao
().
findOne
(
provisionID
);
ProvisionInfo
pro
=
provisionService
.
findOne
(
provisionID
);
if
(
pro
==
null
)
{
if
(
pro
==
null
)
{
throw
new
NotFoundException
();
throw
new
NotFoundException
();
}
}
String
cloudConfID
=
pro
.
getCloudcloudCredentialsID
();
String
cloudConfID
=
pro
.
getCloudcloudCredentialsID
();
CloudCredentials
cCred
=
cloudCredentials
Dao
.
findOne
(
cloudConfID
);
CloudCredentials
cCred
=
cloudCredentials
Service
.
findOne
(
cloudConfID
);
List
<
LoginKey
>
loginKeys
=
cCred
.
getLoginKeys
();
List
<
LoginKey
>
loginKeys
=
cCred
.
getLoginKeys
();
List
<
DeployParameter
>
deployParams
=
pro
.
getDeployParameters
();
List
<
DeployParameter
>
deployParams
=
pro
.
getDeployParameters
();
List
<
MessageParameter
>
parameters
=
new
ArrayList
<>();
List
<
MessageParameter
>
parameters
=
new
ArrayList
<>();
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/v1/rest/PlannerController.java
View file @
f102f1f4
...
@@ -25,7 +25,6 @@ import javax.annotation.security.RolesAllowed;
...
@@ -25,7 +25,6 @@ import javax.annotation.security.RolesAllowed;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
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.stereotype.Component
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
...
@@ -117,7 +116,7 @@ public class PlannerController {
...
@@ -117,7 +116,7 @@ public class PlannerController {
@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
)
{
plannerService
.
getDao
().
delete
(
id
);
plannerService
.
delete
(
id
);
return
"Deleted : "
+
id
;
return
"Deleted : "
+
id
;
}
}
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/v1/rest/ProvisionController.java
View file @
f102f1f4
...
@@ -15,60 +15,31 @@
...
@@ -15,60 +15,31 @@
*/
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
v1
.
rest
;
package
nl
.
uva
.
sne
.
drip
.
api
.
v1
.
rest
;
import
com.fasterxml.jackson.core.JsonParser
;
import
nl.uva.sne.drip.commons.v1.types.ProvisionInfo
;
import
nl.uva.sne.drip.commons.v1.types.ProvisionInfo
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.Set
;
import
java.util.concurrent.TimeoutException
;
import
java.util.concurrent.TimeoutException
;
import
java.util.logging.Level
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
java.util.logging.Logger
;
import
javax.annotation.security.RolesAllowed
;
import
javax.annotation.security.RolesAllowed
;
import
nl.uva.sne.drip.api.dao.CloudCredentialsDao
;
import
nl.uva.sne.drip.commons.v1.types.Message
;
import
nl.uva.sne.drip.commons.v1.types.MessageParameter
;
import
nl.uva.sne.drip.commons.utils.Converter
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
nl.uva.sne.drip.api.exception.BadRequestException
;
import
nl.uva.sne.drip.api.exception.CloudCredentialsNotFoundException
;
import
nl.uva.sne.drip.api.exception.ExceptionHandler
;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
import
nl.uva.sne.drip.api.exception.PlanNotFoundException
;
import
nl.uva.sne.drip.api.rpc.DRIPCaller
;
import
nl.uva.sne.drip.api.rpc.ProvisionerCaller
;
import
nl.uva.sne.drip.api.service.ProvisionService
;
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.UserScriptService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.commons.v1.types.CloudCredentials
;
import
nl.uva.sne.drip.commons.v1.types.DeployParameter
;
import
nl.uva.sne.drip.commons.v1.types.LoginKey
;
import
nl.uva.sne.drip.commons.v1.types.Plan
;
import
nl.uva.sne.drip.commons.v1.types.Script
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.io.FilenameUtils
;
import
org.json.JSONException
;
import
org.json.JSONException
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
/**
/**
* This controller is responsible for obtaining resources from cloud providers
* This controller is responsible for obtaining resources from cloud providers
* based the plan generated by the planner
* based the plan generated by the planner
*
* @author S. Koulouzis
* @author S. Koulouzis
*/
*/
@RestController
@RestController
...
@@ -76,26 +47,16 @@ import org.springframework.web.bind.annotation.RequestBody;
...
@@ -76,26 +47,16 @@ import org.springframework.web.bind.annotation.RequestBody;
@Component
@Component
public
class
ProvisionController
{
public
class
ProvisionController
{
@Value
(
"${message.broker.host}"
)
private
String
messageBrokerHost
;
@Autowired
private
UserScriptService
userScriptService
;
@Autowired
private
UserKeyService
userKeysService
;
@Autowired
private
CloudCredentialsDao
cloudCredentialsDao
;
@Autowired
@Autowired
private
ProvisionService
provisionService
;
private
ProvisionService
provisionService
;
@Autowired
private
SimplePlannerService
planService
;
/**
/**
* Gets the ProvisionInfo
* Gets the ProvisionInfo
*
* @param id. The id of the ProvisionInfo
* @param id. The id of the ProvisionInfo
* @return the requested ProvisionInfo
* @return the requested ProvisionInfo
*/
*/
...
@@ -103,11 +64,12 @@ public class ProvisionController {
...
@@ -103,11 +64,12 @@ public class ProvisionController {
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
public
@ResponseBody
ProvisionInfo
get
(
@PathVariable
(
"id"
)
String
id
)
{
ProvisionInfo
get
(
@PathVariable
(
"id"
)
String
id
)
{
return
provisionService
.
getDao
().
findOne
(
id
);
return
provisionService
.
findOne
(
id
);
}
}
/**
/**
* Deletes the ProvisionInfo
* Deletes the ProvisionInfo
*
* @param id. The ID of the ProvisionInfo to be deleted
* @param id. The ID of the ProvisionInfo to be deleted
* @return the ID of the deleted ProvisionInfo
* @return the ID of the deleted ProvisionInfo
*/
*/
...
@@ -115,24 +77,24 @@ public class ProvisionController {
...
@@ -115,24 +77,24 @@ public class ProvisionController {
@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
)
{
ProvisionInfo
provPlan
=
provisionService
.
getDao
().
findOne
(
id
);
ProvisionInfo
provPlan
=
provisionService
.
findOne
(
id
);
if
(
provPlan
!=
null
)
{
if
(
provPlan
!=
null
)
{
provisionService
.
getDao
().
delete
(
id
);
provisionService
.
delete
(
id
);
return
"Deleted : "
+
id
;
return
"Deleted : "
+
id
;
}
}
throw
new
NotFoundException
();
throw
new
NotFoundException
();
}
}
/**
/**
* Gets the IDs of all the stored ProvisionInfo
* Gets the IDs of all the stored ProvisionInfo
* @return a list of IDs
*
* @return a list of IDs
*/
*/
@RequestMapping
(
value
=
"/ids"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/ids"
,
method
=
RequestMethod
.
GET
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
public
@ResponseBody
List
<
String
>
getIds
()
{
List
<
String
>
getIds
()
{
List
<
ProvisionInfo
>
all
=
provisionService
.
getDao
().
findAll
();
List
<
ProvisionInfo
>
all
=
provisionService
.
findAll
();
List
<
String
>
ids
=
new
ArrayList
<>(
all
.
size
());
List
<
String
>
ids
=
new
ArrayList
<>(
all
.
size
());
for
(
ProvisionInfo
pi
:
all
)
{
for
(
ProvisionInfo
pi
:
all
)
{
ids
.
add
(
pi
.
getId
());
ids
.
add
(
pi
.
getId
());
...
@@ -141,233 +103,26 @@ public class ProvisionController {
...
@@ -141,233 +103,26 @@ public class ProvisionController {
}
}
/**
/**
* Provison the resources specified by a plan.
* Provison the resources specified by a plan.
* @param req. The ProvisionInfo. This is a container the plan ID,
*
* cloud credent ID, etc.
* @param req. The ProvisionInfo. This is a container the plan ID, cloud
* credent ID, etc.
* @return The ID of the provisioned ProvisionInfo
* @return The ID of the provisioned ProvisionInfo
*/
*/
@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
provision
(
@RequestBody
ProvisionInfo
req
)
{
String
provision
(
@RequestBody
ProvisionInfo
req
)
{
try
(
DRIPCaller
provisioner
=
new
ProvisionerCaller
(
messageBrokerHost
);)
{
Message
provisionerInvokationMessage
=
buildProvisionerMessage
(
req
);
Message
response
=
(
provisioner
.
call
(
provisionerInvokationMessage
));
// Message response = generateFakeResponse(System.getProperty("user.home")
// + File.separator + "workspace" + File.separator + "DRIP"
// + File.separator + "doc" + File.separator + "json_samples" +
// File.separator + "ec2_provisioner_provisoned2.json");
List
<
MessageParameter
>
params
=
response
.
getParameters
();
for
(
MessageParameter
p
:
params
)
{
try
{
String
name
=
p
.
getName
();
req
=
provisionService
.
provisionResources
(
req
);
if
(
name
.
toLowerCase
().
contains
(
"exception"
))
{
RuntimeException
ex
=
ExceptionHandler
.
generateException
(
name
,
p
.
getValue
());
Logger
.
getLogger
(
ProvisionController
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
throw
ex
;
}
if
(!
name
.
equals
(
"kubernetes"
))
{
String
value
=
p
.
getValue
();
Map
<
String
,
Object
>
kvMap
=
Converter
.
ymlString2Map
(
value
);
req
.
setKvMap
(
kvMap
);
req
.
setPlanID
(
req
.
getPlanID
());
}
else
{
String
value
=
p
.
getValue
();
String
[]
lines
=
value
.
split
(
"\n"
);
List
<
DeployParameter
>
deployParameters
=
new
ArrayList
<>();
for
(
String
line
:
lines
)
{
DeployParameter
deployParam
=
new
DeployParameter
();
String
[]
parts
=
line
.
split
(
" "
);
String
deployIP
=
parts
[
0
];
String
deployUser
=
parts
[
1
];
String
deployCertPath
=
parts
[
2
];
String
cloudCertificateName
=
FilenameUtils
.
removeExtension
(
FilenameUtils
.
getBaseName
(
deployCertPath
));
String
deployRole
=
parts
[
3
];
deployParam
.
setIP
(
deployIP
);
deployParam
.
setRole
(
deployRole
);
deployParam
.
setUser
(
deployUser
);
deployParam
.
setCloudCertificateName
(
cloudCertificateName
);
deployParameters
.
add
(
deployParam
);
}
req
.
setDeployParameters
(
deployParameters
);
}
}
provisionService
.
getDao
().
save
(
req
);
return
req
.
getId
();
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
(
ProvisionInfo
pReq
)
throws
JSONException
,
IOException
{
Message
invokationMessage
=
new
Message
();
List
<
MessageParameter
>
parameters
=
new
ArrayList
();
CloudCredentials
cred
=
cloudCredentialsDao
.
findOne
(
pReq
.
getCloudcloudCredentialsID
());
if
(
cred
==
null
)
{
throw
new
CloudCredentialsNotFoundException
();
}
MessageParameter
conf
=
buildCloudConfParam
(
cred
);
parameters
.
add
(
conf
);
List
<
MessageParameter
>
certs
=
buildCertificatesParam
(
cred
);
parameters
.
addAll
(
certs
);
List
<
MessageParameter
>
topologies
=
buildTopologyParams
(
pReq
.
getPlanID
());
parameters
.
addAll
(
topologies
);
String
scriptID
=
pReq
.
getscriptID
();
if
(
scriptID
!=
null
)
{
List
<
MessageParameter
>
userScripts
=
buildScriptParams
(
scriptID
);
parameters
.
addAll
(
userScripts
);
}
String
userKeyID
=
pReq
.
getUserKeyID
();
if
(
userKeyID
!=
null
)
{
List
<
MessageParameter
>
userKeys
=
buildKeysParams
(
userKeyID
);
parameters
.
addAll
(
userKeys
);
}
invokationMessage
.
setParameters
(
parameters
);
invokationMessage
.
setCreationDate
((
System
.
currentTimeMillis
()));
return
invokationMessage
;
}
private
MessageParameter
buildCloudConfParam
(
CloudCredentials
cred
)
throws
JsonProcessingException
,
JSONException
,
IOException
{
MessageParameter
conf
=
null
;
String
provider
=
cred
.
getCloudProviderName
();
if
(
provider
==
null
)
{
throw
new
BadRequestException
(
"Provider name can't be null. Check the cloud credentials: "
+
cred
.
getId
());
}
switch
(
cred
.
getCloudProviderName
().
toLowerCase
())
{
case
"ec2"
:
conf
=
buildEC2Conf
(
cred
);
break
;
}
return
conf
;
}
private
List
<
MessageParameter
>
buildCertificatesParam
(
CloudCredentials
cred
)
{
List
<
LoginKey
>
loginKeys
=
cred
.
getLoginKeys
();
if
(
loginKeys
==
null
||
loginKeys
.
isEmpty
())
{
throw
new
BadRequestException
(
"Log in keys can't be empty"
);
}
List
<
MessageParameter
>
parameters
=
new
ArrayList
<>();
for
(
LoginKey
lk
:
loginKeys
)
{
String
domainName
=
lk
.
getAttributes
().
get
(
"domain_name"
);
if
(
domainName
==
null
)
{
domainName
=
lk
.
getAttributes
().
get
(
"domain_name "
);
}
MessageParameter
cert
=
new
MessageParameter
();
cert
.
setName
(
"certificate"
);
cert
.
setValue
(
lk
.
getKey
());
Map
<
String
,
String
>
attributes
=
new
HashMap
<>();
attributes
.
put
(
"filename"
,
domainName
);
cert
.
setAttributes
(
attributes
);
parameters
.
add
(
cert
);
}
return
parameters
;
}
private
List
<
MessageParameter
>
buildTopologyParams
(
String
planID
)
throws
JSONException
{
Plan
plan
=
planService
.
getDao
().
findOne
(
planID
);
if
(
plan
==
null
)
{
throw
new
PlanNotFoundException
();
}
List
<
MessageParameter
>
parameters
=
new
ArrayList
();
MessageParameter
topology
=
new
MessageParameter
();
topology
.
setName
(
"topology"
);
topology
.
setValue
(
Converter
.
map2YmlString
(
plan
.
getKeyValue
()));
Map
<
String
,
String
>
attributes
=
new
HashMap
<>();
attributes
.
put
(
"level"
,
String
.
valueOf
(
plan
.
getLevel
()));
attributes
.
put
(
"filename"
,
FilenameUtils
.
removeExtension
(
plan
.
getName
()));
topology
.
setAttributes
(
attributes
);
parameters
.
add
(
topology
);
Set
<
String
>
ids
=
plan
.
getLoweLevelPlanIDs
();
for
(
String
lowID
:
ids
)
{
Plan
lowPlan
=
planService
.
getDao
().
findOne
(
lowID
);
topology
=
new
MessageParameter
();
topology
.
setName
(
"topology"
);
topology
.
setValue
(
Converter
.
map2YmlString
(
lowPlan
.
getKeyValue
()));
attributes
=
new
HashMap
<>();
attributes
.
put
(
"level"
,
String
.
valueOf
(
lowPlan
.
getLevel
()));
attributes
.
put
(
"filename"
,
FilenameUtils
.
removeExtension
(
lowPlan
.
getName
()));
topology
.
setAttributes
(
attributes
);
parameters
.
add
(
topology
);
}
return
parameters
;
}
private
MessageParameter
buildEC2Conf
(
CloudCredentials
cred
)
throws
JsonProcessingException
,
JSONException
,
IOException
{
Properties
prop
=
Converter
.
getEC2Properties
(
cred
);
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
prop
.
store
(
baos
,
null
);
byte
[]
bytes
=
baos
.
toByteArray
();
MessageParameter
conf
=
new
MessageParameter
();
conf
.
setName
(
"ec2.conf"
);
String
charset
=
"UTF-8"
;
conf
.
setValue
(
new
String
(
bytes
,
charset
));
return
conf
;
}
private
List
<
MessageParameter
>
buildScriptParams
(
String
userScriptID
)
{
Script
script
=
userScriptService
.
getDao
().
findOne
(
userScriptID
);
if
(
script
==
null
)
{
throw
new
BadRequestException
(
"User script: "
+
userScriptID
+
" was not found"
);
}
List
<
MessageParameter
>
parameters
=
new
ArrayList
();
MessageParameter
scriptParameter
=
new
MessageParameter
();
scriptParameter
.
setName
(
"guiscript"
);
scriptParameter
.
setValue
(
script
.
getContents
());
scriptParameter
.
setEncoding
(
"UTF-8"
);
parameters
.
add
(
scriptParameter
);
return
parameters
;
}
private
List
<
MessageParameter
>
buildKeysParams
(
String
userKeyID
)
{
LoginKey
key
=
userKeysService
.
get
(
userKeyID
,
LoginKey
.
Type
.
PUBLIC
);
if
(
key
==
null
)
{
throw
new
BadRequestException
(
"User key: "
+
userKeyID
+
" was not found"
);
}
List
<
MessageParameter
>
parameters
=
new
ArrayList
();
MessageParameter
keyParameter
=
new
MessageParameter
();
keyParameter
.
setName
(
"sshkey"
);
keyParameter
.
setValue
(
key
.
getKey
());
keyParameter
.
setEncoding
(
"UTF-8"
);
parameters
.
add
(
keyParameter
);
return
parameters
;
}
private
Message
generateFakeResponse
(
String
path
)
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\"}]}";
// String strResponse = "{\"creationDate\":1488805337447,\"parameters\":[{\"name\":\"2e5dafb6-5a1c-4a66-9dca-5841f99ea735\",\"encoding\":\"UTF-8\",\"value\":\"publicKeyPath: /tmp/Input-11594765342486/user.pem\\nuserName: zh9314\\nsubnets:\\n- {name: s1, subnet: 192.168.10.0, netmask: 255.255.255.0}\\ncomponents:\\n- name: 8fcc1788d9ee462c826572c79fdb2a6a\\n type: Switch.nodes.Compute\\n nodeType: t2.medium\\n OStype: Ubuntu 16.04\\n script: /tmp/Input-11594765342486/guiscipt.sh\\n domain: ec2.us-east-1.amazonaws.com\\n installation: null\\n clusterType: swarm\\n role: master\\n dockers: mogswitch/ProxyTranscoder:1.0\\n public_address: 34.207.73.18\\n instanceId: i-0e82b5624a0df99b1\\n ethernet_port:\\n - {name: p1, subnet_name: s1, address: 192.168.10.10}\\n- name: 8fcc1788d9ee462c826572c79fdb2a6a\\n type: Switch.nodes.Compute\\n nodeType: t2.medium\\n OStype: Ubuntu 16.04\\n script: /tmp/Input-11594765342486/guiscipt.sh\\n domain: ec2.us-east-1.amazonaws.com\\n installation: null\\n clusterType: swarm\\n role: slave\\n dockers: mogswitch/ProxyTranscoder:1.0\\n public_address: 34.207.73.18\\n instanceId: i-0e82b5624a0df99b1\\n ethernet_port:\\n - {name: p1, subnet_name: s1, address: 192.168.10.11}\\n\"},{\"name\":\"kubernetes\",\"encoding\":\"UTF-8\",\"value\":\"34.207.73.18 ubuntu /tmp/Input-11594765342486/Virginia.pem master\\n34.207.73.18 ubuntu /tmp/Input-11594765342486/Virginia.pem slave\\n\"}]}";
String
strResponse
=
FileUtils
.
readFileToString
(
new
File
(
path
));
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/v1/rest/ToscaController.java
View file @
f102f1f4
...
@@ -62,7 +62,7 @@ public class ToscaController {
...
@@ -62,7 +62,7 @@ public class ToscaController {
throw
new
BadRequestException
(
"Must uplaod a file"
);
throw
new
BadRequestException
(
"Must uplaod a file"
);
}
}
try
{
try
{
return
toscaService
.
save
(
file
);
return
toscaService
.
save
File
(
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
);
}
}
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/v1/rest/UserPublicKeysController.java
View file @
f102f1f4
...
@@ -77,7 +77,7 @@ public class UserPublicKeysController {
...
@@ -77,7 +77,7 @@ public class UserPublicKeysController {
upk
.
setName
(
name
);
upk
.
setName
(
name
);
upk
.
setType
(
LoginKey
.
Type
.
PUBLIC
);
upk
.
setType
(
LoginKey
.
Type
.
PUBLIC
);
service
.
getDao
().
save
(
upk
);
service
.
save
(
upk
);
return
upk
.
getId
();
return
upk
.
getId
();
}
catch
(
IOException
|
IllegalStateException
ex
)
{
}
catch
(
IOException
|
IllegalStateException
ex
)
{
...
@@ -119,7 +119,7 @@ public class UserPublicKeysController {
...
@@ -119,7 +119,7 @@ public class UserPublicKeysController {
key
.
setName
(
name
);
key
.
setName
(
name
);
key
.
setType
(
LoginKey
.
Type
.
PUBLIC
);
key
.
setType
(
LoginKey
.
Type
.
PUBLIC
);
service
.
getDao
().
save
(
key
);
service
.
save
(
key
);
return
key
.
getId
();
return
key
.
getId
();
}
}
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/v1/rest/UserScriptController.java
View file @
f102f1f4
...
@@ -28,10 +28,10 @@ import org.springframework.web.bind.annotation.RequestParam;
...
@@ -28,10 +28,10 @@ import org.springframework.web.bind.annotation.RequestParam;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
nl.uva.sne.drip.api.dao.UserScriptDao
;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
import
nl.uva.sne.drip.commons.v1.types.Script
;
import
nl.uva.sne.drip.commons.v1.types.Script
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
nl.uva.sne.drip.api.dao.ScriptDao
;
/**
/**
* This controller is responsible for handling user scripts. These user can be
* This controller is responsible for handling user scripts. These user can be
...
@@ -45,7 +45,7 @@ import org.springframework.web.bind.annotation.PathVariable;
...
@@ -45,7 +45,7 @@ import org.springframework.web.bind.annotation.PathVariable;
public
class
UserScriptController
{
public
class
UserScriptController
{
@Autowired
@Autowired
private
User
ScriptDao
dao
;
private
ScriptDao
dao
;
// curl -v -X POST -F "file=@script.sh" localhost:8080/drip-api/rest/user_script/upload
// curl -v -X POST -F "file=@script.sh" localhost:8080/drip-api/rest/user_script/upload
/**
/**
...
...
drip-api/src/main/java/nl/uva/sne/drip/commons/utils/Converter.java
View file @
f102f1f4
...
@@ -26,9 +26,12 @@ import java.util.Iterator;
...
@@ -26,9 +26,12 @@ import java.util.Iterator;
import
java.util.List
;
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.v0.types.File
;
import
nl.uva.sne.drip.commons.v1.types.CloudCredentials
;
import
nl.uva.sne.drip.commons.v1.types.CloudCredentials
;
import
nl.uva.sne.drip.commons.v1.types.Message
;
import
nl.uva.sne.drip.commons.v1.types.Message
;
import
nl.uva.sne.drip.commons.v1.types.MessageParameter
;
import
nl.uva.sne.drip.commons.v1.types.MessageParameter
;
import
nl.uva.sne.drip.commons.v1.types.Plan
;
import
org.apache.commons.io.FilenameUtils
;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
...
@@ -174,4 +177,29 @@ public class Converter {
...
@@ -174,4 +177,29 @@ public class Converter {
return
mess
;
return
mess
;
}
}
public
static
File
plan1toFile
(
Plan
plan1
)
throws
JSONException
{
File
e
=
new
File
();
e
.
level
=
String
.
valueOf
(
plan1
.
getLevel
());
String
p1Name
=
FilenameUtils
.
getBaseName
(
plan1
.
getName
());
if
(
p1Name
==
null
)
{
p1Name
=
"Planned_tosca_file_"
+
plan1
.
getLevel
();
plan1
.
setName
(
p1Name
);
}
e
.
name
=
p1Name
;
String
ymlString
=
Converter
.
map2YmlString
(
plan1
.
getKeyValue
());
e
.
content
=
ymlString
.
replaceAll
(
"\n"
,
"\\\\n"
);
return
e
;
}
public
static
Plan
File2Plan1
(
File
p0
)
{
Plan
p1
=
new
Plan
();
p1
.
setLevel
(
Integer
.
valueOf
(
p0
.
level
));
p1
.
setName
(
p0
.
name
);
String
yaml
=
p0
.
content
.
replaceAll
(
"\\\\n"
,
"\n"
);
p1
.
setKvMap
(
ymlString2Map
(
yaml
));
return
p1
;
}
}
}
drip-api/src/main/java/nl/uva/sne/drip/commons/v0/types/Upload.java
View file @
f102f1f4
...
@@ -16,16 +16,18 @@
...
@@ -16,16 +16,18 @@
package
nl
.
uva
.
sne
.
drip
.
commons
.
v0
.
types
;
package
nl
.
uva
.
sne
.
drip
.
commons
.
v0
.
types
;
import
java.util.List
;
import
java.util.List
;
import
javax.xml.bind.annotation.XmlRootElement
;
/**
/**
*
*
* @author S. Koulouzis
* @author S. Koulouzis
*/
*/
@XmlRootElement
public
class
Upload
{
public
class
Upload
{
public
String
user
;
public
String
user
;
public
String
pwd
;
public
String
pwd
;
List
<
File
>
file
;
public
List
<
File
>
file
;
}
}
drip-api/src/main/java/nl/uva/sne/drip/commons/v1/types/KeyValueHolder.java
View file @
f102f1f4
...
@@ -24,7 +24,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
...
@@ -24,7 +24,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
* @author S. Koulouzis
* @author S. Koulouzis
*/
*/
@Document
@Document
public
class
KeyValueHolder
{
public
class
KeyValueHolder
extends
OwnedObject
{
@Id
@Id
private
String
id
;
private
String
id
;
...
...
drip-api/src/main/java/nl/uva/sne/drip/commons/v1/types/LoginKey.java
View file @
f102f1f4
...
@@ -28,7 +28,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
...
@@ -28,7 +28,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
* @author S. Koulouzis
* @author S. Koulouzis
*/
*/
@Document
@Document
public
class
LoginKey
{
public
class
LoginKey
extends
OwnedObject
{
@Id
@Id
private
String
id
;
private
String
id
;
...
...
drip-api/src/main/java/nl/uva/sne/drip/commons/v1/types/Script.java
View file @
f102f1f4
...
@@ -25,7 +25,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
...
@@ -25,7 +25,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
* @author S. Koulouzis
* @author S. Koulouzis
*/
*/
@Document
@Document
public
class
Script
{
public
class
Script
extends
OwnedObject
{
@Id
@Id
private
String
id
;
private
String
id
;
...
...
drip-api/src/main/java/nl/uva/sne/drip/commons/v1/types/ToscaRepresentation.java
View file @
f102f1f4
...
@@ -15,8 +15,6 @@
...
@@ -15,8 +15,6 @@
*/
*/
package
nl
.
uva
.
sne
.
drip
.
commons
.
v1
.
types
;
package
nl
.
uva
.
sne
.
drip
.
commons
.
v1
.
types
;
import
java.util.Map
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.Document
;
/**
/**
...
...
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