Commit f102f1f4 authored by skoulouzis's avatar skoulouzis Committed by GitHub

Merge pull request #30 from skoulouzis/v0.0_API

Implmented provisioner for v0.0
parents bda62e5e 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);
......
...@@ -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 UserScriptDao extends MongoRepository<Script, String> { public interface ScriptDao extends MongoRepository<Script, String> {
} }
...@@ -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.PreFilter; import org.springframework.security.core.context.SecurityContextHolder;
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();
} }
......
...@@ -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;
}
} }
...@@ -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;
......
...@@ -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 saveFile(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 saveYamlString(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;
} }
} }
...@@ -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);
}
} }
...@@ -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
UserScriptDao 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();
} }
} }
...@@ -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 CloudCredentialsDao cloudCredentialsDao; private CloudCredentialsService 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();
} }
......
...@@ -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.saveYamlString(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);
......
...@@ -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;
......
...@@ -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 CloudCredentialsDao cloudCredentialsDao; private CloudCredentialsService 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 = cloudCredentialsDao.findOne(cloudConfID); CloudCredentials cCred = cloudCredentialsService.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<>();
......
...@@ -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;
} }
......
...@@ -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.saveFile(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);
} }
......
...@@ -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();
} }
......
...@@ -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 UserScriptDao 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
/** /**
......
...@@ -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;
}
} }
...@@ -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;
} }
...@@ -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;
......
...@@ -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;
......
...@@ -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;
......
...@@ -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;
/** /**
......
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