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
416a104a
Commit
416a104a
authored
Mar 09, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implmented provisioner for v0.0
parent
bda62e5e
Changes
25
Expand all
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 @
416a104a
...
@@ -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 @
416a104a
...
@@ -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 @
416a104a
...
@@ -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 @
416a104a
...
@@ -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 @
416a104a
This diff is collapsed.
Click to expand it.
drip-api/src/main/java/nl/uva/sne/drip/api/service/SimplePlannerService.java
View file @
416a104a
...
@@ -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 @
416a104a
...
@@ -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 @
416a104a
...
@@ -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 @
416a104a
...
@@ -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 @
416a104a
...
@@ -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 @
416a104a
...
@@ -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 @
416a104a
This diff is collapsed.
Click to expand it.
drip-api/src/main/java/nl/uva/sne/drip/api/v1/rest/CloudCredentialsController.java
View file @
416a104a
...
@@ -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 @
416a104a
...
@@ -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 @
416a104a
...
@@ -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 @
416a104a
This diff is collapsed.
Click to expand it.
drip-api/src/main/java/nl/uva/sne/drip/api/v1/rest/ToscaController.java
View file @
416a104a
...
@@ -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 @
416a104a
...
@@ -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 @
416a104a
...
@@ -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 @
416a104a
...
@@ -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 @
416a104a
...
@@ -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 @
416a104a
...
@@ -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 @
416a104a
...
@@ -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 @
416a104a
...
@@ -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 @
416a104a
...
@@ -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