Commit f28be060 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Added user key and script for API 0.0

parent 0472a4af
...@@ -120,11 +120,11 @@ public class ProvisionService { ...@@ -120,11 +120,11 @@ public class ProvisionService {
try (DRIPCaller provisioner = new ProvisionerCaller(messageBrokerHost);) { try (DRIPCaller provisioner = new ProvisionerCaller(messageBrokerHost);) {
Message provisionerInvokationMessage = buildProvisionerMessage(req); Message provisionerInvokationMessage = buildProvisionerMessage(req);
// Message response = (provisioner.call(provisionerInvokationMessage)); Message response = (provisioner.call(provisionerInvokationMessage));
Message response = generateFakeResponse(System.getProperty("user.home") // Message response = generateFakeResponse(System.getProperty("user.home")
+ File.separator + "workspace" + File.separator + "DRIP" // + File.separator + "workspace" + File.separator + "DRIP"
+ File.separator + "doc" + File.separator + "json_samples" // + File.separator + "doc" + File.separator + "json_samples"
+ File.separator + "ec2_provisioner_provisoned2.json"); // + File.separator + "ec2_provisioner_provisoned2.json");
List<MessageParameter> params = response.getParameters(); List<MessageParameter> params = response.getParameters();
for (MessageParameter p : params) { for (MessageParameter p : params) {
......
...@@ -18,6 +18,7 @@ package nl.uva.sne.drip.api.service; ...@@ -18,6 +18,7 @@ package nl.uva.sne.drip.api.service;
import java.util.ArrayList; 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.api.exception.NotFoundException;
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 nl.uva.sne.drip.commons.v1.types.User;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -72,7 +73,11 @@ public class UserKeyService { ...@@ -72,7 +73,11 @@ public class UserKeyService {
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))") @PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public LoginKey findOne(String id) { 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'))") @PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
......
...@@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -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.DeployClusterService;
import nl.uva.sne.drip.api.service.UserService; 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.Deploy;
import nl.uva.sne.drip.commons.v0.types.File; import nl.uva.sne.drip.commons.v0.types.Attribute;
import nl.uva.sne.drip.commons.v0.types.Result; import nl.uva.sne.drip.commons.v0.types.Result;
import nl.uva.sne.drip.commons.v1.types.ClusterCredentials; import nl.uva.sne.drip.commons.v1.types.ClusterCredentials;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
...@@ -71,8 +71,8 @@ public class DeployController0 { ...@@ -71,8 +71,8 @@ public class DeployController0 {
Result res = new Result(); Result res = new Result();
res.info = "INFO"; res.info = "INFO";
res.status = "Success"; res.status = "Success";
List<File> files = new ArrayList<>(); List<Attribute> files = new ArrayList<>();
File e = new File(); Attribute e = new Attribute();
e.content = clusterCred.getKey(); e.content = clusterCred.getKey();
files.add(e); files.add(e);
res.file = files; res.file = files;
......
...@@ -33,7 +33,7 @@ import nl.uva.sne.drip.api.service.PlannerService; ...@@ -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.ToscaService;
import nl.uva.sne.drip.api.service.UserService; 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.Attribute;
import nl.uva.sne.drip.commons.v0.types.Plan; import nl.uva.sne.drip.commons.v0.types.Plan;
import org.json.JSONException; import org.json.JSONException;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
...@@ -70,8 +70,8 @@ public class PlannerController0 { ...@@ -70,8 +70,8 @@ public class PlannerController0 {
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<Attribute> files = new ArrayList<>();
File e = Converter.plan1toFile(plan1); Attribute e = Converter.plan1toFile(plan1);
files.add(e); files.add(e);
......
...@@ -40,12 +40,11 @@ import nl.uva.sne.drip.api.service.UserKeyService; ...@@ -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.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.Execute; import nl.uva.sne.drip.commons.v0.types.Execute;
import nl.uva.sne.drip.commons.v0.types.File; import nl.uva.sne.drip.commons.v0.types.Attribute;
import nl.uva.sne.drip.commons.v0.types.Result; import nl.uva.sne.drip.commons.v0.types.Result;
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.Script; import nl.uva.sne.drip.commons.v1.types.Script;
import org.json.JSONException; import org.json.JSONException;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
...@@ -90,11 +89,11 @@ public class ProvisionController0 { ...@@ -90,11 +89,11 @@ public class ProvisionController0 {
CloudCredentials cloudCred = cloudCredentialsService.findAll().get(0); CloudCredentials cloudCred = cloudCredentialsService.findAll().get(0);
String cloudCredID = cloudCred.getId(); String cloudCredID = cloudCred.getId();
provInfo.setCloudcloudCredentialsID(cloudCredID); provInfo.setCloudcloudCredentialsID(cloudCredID);
List<nl.uva.sne.drip.commons.v0.types.File> plans = upload.file; List<nl.uva.sne.drip.commons.v0.types.Attribute> plans = upload.file;
nl.uva.sne.drip.commons.v1.types.Plan topLevelPlan = null; nl.uva.sne.drip.commons.v1.types.Plan topLevelPlan = null;
Set<String> loweLevelPlansIDs = new HashSet<>(); Set<String> loweLevelPlansIDs = new HashSet<>();
for (nl.uva.sne.drip.commons.v0.types.File p : plans) { for (nl.uva.sne.drip.commons.v0.types.Attribute p : plans) {
nl.uva.sne.drip.commons.v1.types.Plan plan1 = Converter.File2Plan1(p); nl.uva.sne.drip.commons.v1.types.Plan plan1 = Converter.File2Plan1(p);
if (plan1.getLevel() == 0) { if (plan1.getLevel() == 0) {
topLevelPlan = plan1; topLevelPlan = plan1;
...@@ -135,8 +134,8 @@ public class ProvisionController0 { ...@@ -135,8 +134,8 @@ public class ProvisionController0 {
yaml = yaml.replaceAll("\n", "\\\\n"); yaml = yaml.replaceAll("\n", "\\\\n");
Result res = new Result(); Result res = new Result();
List<File> files = new ArrayList<>(); List<Attribute> files = new ArrayList<>();
File e = new File(); Attribute e = new Attribute();
e.content = yaml; e.content = yaml;
e.level = "0"; e.level = "0";
e.name = "provisioned_" + exc.action; e.name = "provisioned_" + exc.action;
......
/*
* 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();
}
}
/*
* 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();
}
}
...@@ -32,6 +32,7 @@ import nl.uva.sne.drip.api.exception.NotFoundException; ...@@ -32,6 +32,7 @@ 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; 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 * This controller is responsible for handling user scripts. These user can be
...@@ -45,7 +46,7 @@ import nl.uva.sne.drip.api.dao.ScriptDao; ...@@ -45,7 +46,7 @@ import nl.uva.sne.drip.api.dao.ScriptDao;
public class UserScriptController { public class UserScriptController {
@Autowired @Autowired
private ScriptDao dao; private UserScriptService userScriptService;
// 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
/** /**
...@@ -68,7 +69,7 @@ public class UserScriptController { ...@@ -68,7 +69,7 @@ public class UserScriptController {
us.setContents(conents); us.setContents(conents);
us.setName(name); us.setName(name);
dao.save(us); userScriptService.save(us);
return us.getId(); return us.getId();
} catch (IOException | IllegalStateException ex) { } catch (IOException | IllegalStateException ex) {
...@@ -87,16 +88,16 @@ public class UserScriptController { ...@@ -87,16 +88,16 @@ public class UserScriptController {
@RequestMapping(value = "/{id}", method = RequestMethod.GET) @RequestMapping(value = "/{id}", method = RequestMethod.GET)
public @ResponseBody public @ResponseBody
Script get(@PathVariable("id") String id) { Script get(@PathVariable("id") String id) {
return dao.findOne(id); return userScriptService.findOne(id);
} }
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE) @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public String delete(@PathVariable("id") String id) { public String delete(@PathVariable("id") String id) {
Script script = dao.findOne(id); Script script = userScriptService.findOne(id);
if (script == null) { if (script == null) {
throw new NotFoundException(); throw new NotFoundException();
} }
dao.delete(id); userScriptService.delete(id);
return "Deleted: " + id; return "Deleted: " + id;
} }
...@@ -108,7 +109,7 @@ public class UserScriptController { ...@@ -108,7 +109,7 @@ public class UserScriptController {
@RequestMapping(value = "/ids", method = RequestMethod.GET) @RequestMapping(value = "/ids", method = RequestMethod.GET)
public @ResponseBody public @ResponseBody
List<String> getIds() { List<String> getIds() {
List<Script> all = dao.findAll(); List<Script> all = userScriptService.findAll();
List<String> ids = new ArrayList<>(); List<String> ids = new ArrayList<>();
for (Script us : all) { for (Script us : all) {
ids.add(us.getId()); ids.add(us.getId());
......
...@@ -26,7 +26,7 @@ import java.util.Iterator; ...@@ -26,7 +26,7 @@ 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.v0.types.Attribute;
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;
...@@ -177,8 +177,8 @@ public class Converter { ...@@ -177,8 +177,8 @@ public class Converter {
return mess; return mess;
} }
public static File plan1toFile(Plan plan1) throws JSONException { public static Attribute plan1toFile(Plan plan1) throws JSONException {
File e = new File(); Attribute e = new Attribute();
e.level = String.valueOf(plan1.getLevel()); e.level = String.valueOf(plan1.getLevel());
String p1Name = FilenameUtils.getBaseName(plan1.getName()); String p1Name = FilenameUtils.getBaseName(plan1.getName());
if (p1Name == null) { if (p1Name == null) {
...@@ -192,7 +192,7 @@ public class Converter { ...@@ -192,7 +192,7 @@ public class Converter {
return e; return e;
} }
public static Plan File2Plan1(File p0) { public static Plan File2Plan1(Attribute p0) {
Plan p1 = new Plan(); Plan p1 = new Plan();
p1.setLevel(Integer.valueOf(p0.level)); p1.setLevel(Integer.valueOf(p0.level));
p1.setName(p0.name); p1.setName(p0.name);
......
...@@ -22,7 +22,7 @@ import javax.xml.bind.annotation.XmlValue; ...@@ -22,7 +22,7 @@ import javax.xml.bind.annotation.XmlValue;
* *
* @author S. Koulouzis * @author S. Koulouzis
*/ */
public class File { public class Attribute {
@XmlAttribute @XmlAttribute
public String name; public String name;
......
/*
* 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;
}
/*
* 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;
}
...@@ -28,6 +28,6 @@ public class Result { ...@@ -28,6 +28,6 @@ public class Result {
public String status; public String status;
public String info; public String info;
public List<File> file; public List<Attribute> file;
} }
...@@ -28,6 +28,6 @@ public class Upload { ...@@ -28,6 +28,6 @@ public class Upload {
public String user; public String user;
public String pwd; public String pwd;
public List<File> file; public List<Attribute> file;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment