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
f28be060
Commit
f28be060
authored
Mar 10, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added user key and script for API 0.0
parent
0472a4af
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
233 additions
and
31 deletions
+233
-31
ProvisionService.java
...in/java/nl/uva/sne/drip/api/service/ProvisionService.java
+5
-5
UserKeyService.java
...main/java/nl/uva/sne/drip/api/service/UserKeyService.java
+6
-1
DeployController0.java
...n/java/nl/uva/sne/drip/api/v0/rest/DeployController0.java
+3
-3
PlannerController0.java
.../java/nl/uva/sne/drip/api/v0/rest/PlannerController0.java
+3
-3
ProvisionController0.java
...ava/nl/uva/sne/drip/api/v0/rest/ProvisionController0.java
+5
-6
UserPublicKeysController0.java
...l/uva/sne/drip/api/v0/rest/UserPublicKeysController0.java
+72
-0
UserScriptController0.java
...va/nl/uva/sne/drip/api/v0/rest/UserScriptController0.java
+66
-0
UserScriptController.java
...ava/nl/uva/sne/drip/api/v1/rest/UserScriptController.java
+7
-6
Converter.java
...rc/main/java/nl/uva/sne/drip/commons/utils/Converter.java
+4
-4
Attribute.java
...main/java/nl/uva/sne/drip/commons/v0/types/Attribute.java
+1
-1
ConfScript.java
...ain/java/nl/uva/sne/drip/commons/v0/types/ConfScript.java
+28
-0
ConfUserKey.java
...in/java/nl/uva/sne/drip/commons/v0/types/ConfUserKey.java
+31
-0
Result.java
...rc/main/java/nl/uva/sne/drip/commons/v0/types/Result.java
+1
-1
Upload.java
...rc/main/java/nl/uva/sne/drip/commons/v0/types/Upload.java
+1
-1
No files found.
drip-api/src/main/java/nl/uva/sne/drip/api/service/ProvisionService.java
View file @
f28be060
...
...
@@ -120,11 +120,11 @@ public class ProvisionService {
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"
);
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
)
{
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/service/UserKeyService.java
View file @
f28be060
...
...
@@ -18,6 +18,7 @@ package nl.uva.sne.drip.api.service;
import
java.util.ArrayList
;
import
java.util.List
;
import
nl.uva.sne.drip.api.dao.UserKeyDao
;
import
nl.uva.sne.drip.api.exception.NotFoundException
;
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
;
...
...
@@ -72,7 +73,11 @@ public class UserKeyService {
@PostAuthorize
(
"(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
public
LoginKey
findOne
(
String
id
)
{
return
dao
.
findOne
(
id
);
LoginKey
key
=
dao
.
findOne
(
id
);
if
(
key
==
null
)
{
throw
new
NotFoundException
();
}
return
key
;
}
@PostAuthorize
(
"(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))"
)
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/v0/rest/DeployController0.java
View file @
f28be060
...
...
@@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.RestController;
import
nl.uva.sne.drip.api.service.DeployClusterService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.commons.v0.types.Deploy
;
import
nl.uva.sne.drip.commons.v0.types.
Fil
e
;
import
nl.uva.sne.drip.commons.v0.types.
Attribut
e
;
import
nl.uva.sne.drip.commons.v0.types.Result
;
import
nl.uva.sne.drip.commons.v1.types.ClusterCredentials
;
import
org.springframework.http.MediaType
;
...
...
@@ -71,8 +71,8 @@ public class DeployController0 {
Result
res
=
new
Result
();
res
.
info
=
"INFO"
;
res
.
status
=
"Success"
;
List
<
Fil
e
>
files
=
new
ArrayList
<>();
File
e
=
new
Fil
e
();
List
<
Attribut
e
>
files
=
new
ArrayList
<>();
Attribute
e
=
new
Attribut
e
();
e
.
content
=
clusterCred
.
getKey
();
files
.
add
(
e
);
res
.
file
=
files
;
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/v0/rest/PlannerController0.java
View file @
f28be060
...
...
@@ -33,7 +33,7 @@ import nl.uva.sne.drip.api.service.PlannerService;
import
nl.uva.sne.drip.api.service.ToscaService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.commons.utils.Converter
;
import
nl.uva.sne.drip.commons.v0.types.
Fil
e
;
import
nl.uva.sne.drip.commons.v0.types.
Attribut
e
;
import
nl.uva.sne.drip.commons.v0.types.Plan
;
import
org.json.JSONException
;
import
org.springframework.http.MediaType
;
...
...
@@ -70,8 +70,8 @@ public class PlannerController0 {
Result
r
=
new
Result
();
r
.
info
=
(
"INFO"
);
r
.
status
=
(
"Success"
);
List
<
Fil
e
>
files
=
new
ArrayList
<>();
Fil
e
e
=
Converter
.
plan1toFile
(
plan1
);
List
<
Attribut
e
>
files
=
new
ArrayList
<>();
Attribut
e
e
=
Converter
.
plan1toFile
(
plan1
);
files
.
add
(
e
);
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/v0/rest/ProvisionController0.java
View file @
f28be060
...
...
@@ -40,12 +40,11 @@ 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.commons.v0.types.Execute
;
import
nl.uva.sne.drip.commons.v0.types.
Fil
e
;
import
nl.uva.sne.drip.commons.v0.types.
Attribut
e
;
import
nl.uva.sne.drip.commons.v0.types.Result
;
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.LoginKey
;
import
nl.uva.sne.drip.commons.v1.types.Plan
;
import
nl.uva.sne.drip.commons.v1.types.Script
;
import
org.json.JSONException
;
import
org.springframework.http.MediaType
;
...
...
@@ -90,11 +89,11 @@ public class ProvisionController0 {
CloudCredentials
cloudCred
=
cloudCredentialsService
.
findAll
().
get
(
0
);
String
cloudCredID
=
cloudCred
.
getId
();
provInfo
.
setCloudcloudCredentialsID
(
cloudCredID
);
List
<
nl
.
uva
.
sne
.
drip
.
commons
.
v0
.
types
.
Fil
e
>
plans
=
upload
.
file
;
List
<
nl
.
uva
.
sne
.
drip
.
commons
.
v0
.
types
.
Attribut
e
>
plans
=
upload
.
file
;
nl
.
uva
.
sne
.
drip
.
commons
.
v1
.
types
.
Plan
topLevelPlan
=
null
;
Set
<
String
>
loweLevelPlansIDs
=
new
HashSet
<>();
for
(
nl
.
uva
.
sne
.
drip
.
commons
.
v0
.
types
.
Fil
e
p
:
plans
)
{
for
(
nl
.
uva
.
sne
.
drip
.
commons
.
v0
.
types
.
Attribut
e
p
:
plans
)
{
nl
.
uva
.
sne
.
drip
.
commons
.
v1
.
types
.
Plan
plan1
=
Converter
.
File2Plan1
(
p
);
if
(
plan1
.
getLevel
()
==
0
)
{
topLevelPlan
=
plan1
;
...
...
@@ -135,8 +134,8 @@ public class ProvisionController0 {
yaml
=
yaml
.
replaceAll
(
"\n"
,
"\\\\n"
);
Result
res
=
new
Result
();
List
<
Fil
e
>
files
=
new
ArrayList
<>();
File
e
=
new
Fil
e
();
List
<
Attribut
e
>
files
=
new
ArrayList
<>();
Attribute
e
=
new
Attribut
e
();
e
.
content
=
yaml
;
e
.
level
=
"0"
;
e
.
name
=
"provisioned_"
+
exc
.
action
;
...
...
drip-api/src/main/java/nl/uva/sne/drip/api/v0/rest/UserPublicKeysController0.java
0 → 100644
View file @
f28be060
/*
* Copyright 2017 S. Koulouzis.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
v0
.
rest
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.annotation.security.RolesAllowed
;
import
nl.uva.sne.drip.api.service.ProvisionService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
nl.uva.sne.drip.api.service.UserKeyService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.commons.v0.types.ConfUserKey
;
import
nl.uva.sne.drip.commons.v0.types.Attribute
;
import
nl.uva.sne.drip.commons.v1.types.LoginKey
;
import
nl.uva.sne.drip.commons.v1.types.ProvisionInfo
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.RequestBody
;
/**
* This controller is responsible for handling user public keys. These keys can
* be used by the provisoner to allow the user to login to the VMs from the
* machine the keys correspond to.
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping
(
"/user/v0.0/switch/provision"
)
@Component
public
class
UserPublicKeysController0
{
@Autowired
private
UserKeyService
service
;
@Autowired
private
ProvisionService
provisionService
;
@RequestMapping
(
value
=
"/confuserkey"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
TEXT_XML_VALUE
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
String
uploadUserPublicKeys
(
@RequestBody
ConfUserKey
confUserKey
)
{
LoginKey
upk
=
new
LoginKey
();
upk
.
setKey
(
confUserKey
.
file
.
get
(
0
).
content
);
upk
.
setName
(
confUserKey
.
file
.
get
(
0
).
name
);
upk
.
setType
(
LoginKey
.
Type
.
PUBLIC
);
upk
=
service
.
save
(
upk
);
ProvisionInfo
provPlan
=
provisionService
.
findOne
(
confUserKey
.
action
);
provPlan
.
setUserKeyID
(
upk
.
getId
());
provisionService
.
save
(
provPlan
);
return
"Success: "
+
upk
.
getId
();
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/v0/rest/UserScriptController0.java
0 → 100644
View file @
f28be060
/*
* Copyright 2017 S. Koulouzis.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
nl
.
uva
.
sne
.
drip
.
api
.
v0
.
rest
;
import
javax.annotation.security.RolesAllowed
;
import
nl.uva.sne.drip.api.service.ProvisionService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
nl.uva.sne.drip.api.service.UserScriptService
;
import
nl.uva.sne.drip.api.service.UserService
;
import
nl.uva.sne.drip.commons.v0.types.ConfScript
;
import
nl.uva.sne.drip.commons.v1.types.ProvisionInfo
;
import
nl.uva.sne.drip.commons.v1.types.Script
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
/**
* This controller is responsible for handling user scripts. These user can be
* used by the provisoner to run on the created VMs.
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping
(
"/user/v0.0/switch/provision/"
)
@Component
public
class
UserScriptController0
{
@Autowired
private
UserScriptService
scriptService
;
@Autowired
private
ProvisionService
provisionService
;
@RequestMapping
(
value
=
"/confscript"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
TEXT_XML_VALUE
)
@RolesAllowed
({
UserService
.
USER
,
UserService
.
ADMIN
})
public
@ResponseBody
String
uploadUserScript
(
@RequestBody
ConfScript
confScript
)
{
Script
script
=
new
Script
();
script
.
setContents
(
confScript
.
script
);
script
=
scriptService
.
save
(
script
);
ProvisionInfo
provPlan
=
provisionService
.
findOne
(
confScript
.
action
);
provPlan
.
setScriptID
(
script
.
getId
());
provisionService
.
save
(
provPlan
);
return
"Success: script for GUI is uploaded: "
+
script
.
getId
();
}
}
drip-api/src/main/java/nl/uva/sne/drip/api/v1/rest/UserScriptController.java
View file @
f28be060
...
...
@@ -32,6 +32,7 @@ import nl.uva.sne.drip.api.exception.NotFoundException;
import
nl.uva.sne.drip.commons.v1.types.Script
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
nl.uva.sne.drip.api.dao.ScriptDao
;
import
nl.uva.sne.drip.api.service.UserScriptService
;
/**
* This controller is responsible for handling user scripts. These user can be
...
...
@@ -45,7 +46,7 @@ import nl.uva.sne.drip.api.dao.ScriptDao;
public
class
UserScriptController
{
@Autowired
private
ScriptDao
dao
;
private
UserScriptService
userScriptService
;
// curl -v -X POST -F "file=@script.sh" localhost:8080/drip-api/rest/user_script/upload
/**
...
...
@@ -68,7 +69,7 @@ public class UserScriptController {
us
.
setContents
(
conents
);
us
.
setName
(
name
);
dao
.
save
(
us
);
userScriptService
.
save
(
us
);
return
us
.
getId
();
}
catch
(
IOException
|
IllegalStateException
ex
)
{
...
...
@@ -87,16 +88,16 @@ public class UserScriptController {
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
GET
)
public
@ResponseBody
Script
get
(
@PathVariable
(
"id"
)
String
id
)
{
return
dao
.
findOne
(
id
);
return
userScriptService
.
findOne
(
id
);
}
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
DELETE
)
public
String
delete
(
@PathVariable
(
"id"
)
String
id
)
{
Script
script
=
dao
.
findOne
(
id
);
Script
script
=
userScriptService
.
findOne
(
id
);
if
(
script
==
null
)
{
throw
new
NotFoundException
();
}
dao
.
delete
(
id
);
userScriptService
.
delete
(
id
);
return
"Deleted: "
+
id
;
}
...
...
@@ -108,7 +109,7 @@ public class UserScriptController {
@RequestMapping
(
value
=
"/ids"
,
method
=
RequestMethod
.
GET
)
public
@ResponseBody
List
<
String
>
getIds
()
{
List
<
Script
>
all
=
dao
.
findAll
();
List
<
Script
>
all
=
userScriptService
.
findAll
();
List
<
String
>
ids
=
new
ArrayList
<>();
for
(
Script
us
:
all
)
{
ids
.
add
(
us
.
getId
());
...
...
drip-api/src/main/java/nl/uva/sne/drip/commons/utils/Converter.java
View file @
f28be060
...
...
@@ -26,7 +26,7 @@ import java.util.Iterator;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Properties
;
import
nl.uva.sne.drip.commons.v0.types.
Fil
e
;
import
nl.uva.sne.drip.commons.v0.types.
Attribut
e
;
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.MessageParameter
;
...
...
@@ -177,8 +177,8 @@ public class Converter {
return
mess
;
}
public
static
Fil
e
plan1toFile
(
Plan
plan1
)
throws
JSONException
{
File
e
=
new
Fil
e
();
public
static
Attribut
e
plan1toFile
(
Plan
plan1
)
throws
JSONException
{
Attribute
e
=
new
Attribut
e
();
e
.
level
=
String
.
valueOf
(
plan1
.
getLevel
());
String
p1Name
=
FilenameUtils
.
getBaseName
(
plan1
.
getName
());
if
(
p1Name
==
null
)
{
...
...
@@ -192,7 +192,7 @@ public class Converter {
return
e
;
}
public
static
Plan
File2Plan1
(
Fil
e
p0
)
{
public
static
Plan
File2Plan1
(
Attribut
e
p0
)
{
Plan
p1
=
new
Plan
();
p1
.
setLevel
(
Integer
.
valueOf
(
p0
.
level
));
p1
.
setName
(
p0
.
name
);
...
...
drip-api/src/main/java/nl/uva/sne/drip/commons/v0/types/
Fil
e.java
→
drip-api/src/main/java/nl/uva/sne/drip/commons/v0/types/
Attribut
e.java
View file @
f28be060
...
...
@@ -22,7 +22,7 @@ import javax.xml.bind.annotation.XmlValue;
*
* @author S. Koulouzis
*/
public
class
Fil
e
{
public
class
Attribut
e
{
@XmlAttribute
public
String
name
;
...
...
drip-api/src/main/java/nl/uva/sne/drip/commons/v0/types/ConfScript.java
0 → 100644
View file @
f28be060
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
nl
.
uva
.
sne
.
drip
.
commons
.
v0
.
types
;
import
javax.xml.bind.annotation.XmlRootElement
;
/**
*
* @author S. Koulouzis
*/
@XmlRootElement
public
class
ConfScript
extends
Execute
{
public
String
script
;
}
drip-api/src/main/java/nl/uva/sne/drip/commons/v0/types/ConfUserKey.java
0 → 100644
View file @
f28be060
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
nl
.
uva
.
sne
.
drip
.
commons
.
v0
.
types
;
import
java.util.List
;
import
javax.xml.bind.annotation.XmlElement
;
import
javax.xml.bind.annotation.XmlRootElement
;
/**
*
* @author S. Koulouzis
*/
@XmlRootElement
public
class
ConfUserKey
extends
Execute
{
@XmlElement
(
name
=
"userKey"
)
public
List
<
Attribute
>
file
;
}
drip-api/src/main/java/nl/uva/sne/drip/commons/v0/types/Result.java
View file @
f28be060
...
...
@@ -28,6 +28,6 @@ public class Result {
public
String
status
;
public
String
info
;
public
List
<
Fil
e
>
file
;
public
List
<
Attribut
e
>
file
;
}
drip-api/src/main/java/nl/uva/sne/drip/commons/v0/types/Upload.java
View file @
f28be060
...
...
@@ -28,6 +28,6 @@ public class Upload {
public
String
user
;
public
String
pwd
;
public
List
<
Fil
e
>
file
;
public
List
<
Attribut
e
>
file
;
}
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