Commit 669bec93 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Use LoginKeys and get rid of PublicKeys

Implemented tosca servcie 
Plan is now GET 
Implemented provison controller 
parent ac265194
...@@ -15,13 +15,13 @@ ...@@ -15,13 +15,13 @@
*/ */
package nl.uva.sne.drip.api.dao; package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.commons.types.UserPublicKey; import nl.uva.sne.drip.commons.types.LoginKey;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
/** /**
* *
* @author S. Koulouzis * @author S. Koulouzis
*/ */
public interface UserKeyDao extends MongoRepository<UserPublicKey, String> { public interface UserKeyDao extends MongoRepository<LoginKey, String> {
} }
/*
* 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.api.rest;
import nl.uva.sne.drip.commons.types.ProvisionRequest;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.io.ByteArrayOutputStream;
import nl.uva.sne.drip.commons.types.ToscaRepresentation;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.api.dao.CloudCredentialsDao;
import nl.uva.sne.drip.commons.types.Message;
import nl.uva.sne.drip.commons.types.Parameter;
import nl.uva.sne.drip.commons.utils.Converter;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
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.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.dao.ToscaDao;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.rpc.DRIPCaller;
import nl.uva.sne.drip.api.rpc.ProvisionerCaller;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.commons.types.CloudCredentials;
import nl.uva.sne.drip.commons.types.LoginKey;
import org.apache.commons.io.FilenameUtils;
import org.springframework.web.bind.annotation.RequestBody;
/**
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/user/provisioner")
@Component
public class ProvisionController {
@Value("${message.broker.host}")
private String messageBrokerHost;
@Autowired
private ToscaDao toscaDao;
@Autowired
private CloudCredentialsDao cloudCredentialsDao;
@RequestMapping(value = "/get", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
ProvisionRequest get() {
ProvisionRequest re = new ProvisionRequest();
re.setCloudConfID("58a1f0a963d42f004b1d63ad");
re.setPlanID("58ac1e70e4949b54f8ac1051");
re.setUserKeyID("58a20be263d4a5898835676e");
re.setUserScriptID("58a2112363d41754cca042b4");
return re;
}
@RequestMapping(value = "/provision", method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String plann(@RequestBody ProvisionRequest req) {
DRIPCaller provisioner = null;
try {
Message provisionerInvokationMessage = buildProvisionerMessage(req);
provisioner = new ProvisionerCaller(messageBrokerHost);
Message response = provisioner.call(provisionerInvokationMessage);
return "";
} catch (IOException | TimeoutException | JSONException | InterruptedException ex) {
Logger.getLogger(ProvisionController.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if (provisioner != null) {
try {
provisioner.close();
} catch (IOException | TimeoutException ex) {
Logger.getLogger(ProvisionController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
return null;
}
private Message buildProvisionerMessage(ProvisionRequest pReq) throws JSONException, IOException {
Message invokationMessage = new Message();
List<Parameter> parameters = new ArrayList();
CloudCredentials cred = cloudCredentialsDao.findOne(pReq.getCloudConfID());
Parameter conf = buildCloudConfParam(cred);
parameters.add(conf);
List<Parameter> certs = buildCertificatesParam(cred);
parameters.addAll(certs);
List<Parameter> topologies = buildTopologyParams(pReq.getPlanID());
parameters.addAll(topologies);
List<Parameter> userScripts = buildScriptParams(pReq.getUserScriptID());
parameters.addAll(userScripts);
List<Parameter> userKeys = buildKeysParams(pReq.getUserKeyID());
parameters.addAll(userScripts);
invokationMessage.setParameters(parameters);
invokationMessage.setCreationDate((System.currentTimeMillis()));
return invokationMessage;
}
private Parameter buildCloudConfParam(CloudCredentials cred) throws JsonProcessingException, JSONException, IOException {
Parameter conf = null;
switch (cred.getCloudProviderName().toLowerCase()) {
case "ec2":
conf = buildEC2Conf(cred);
break;
}
return conf;
}
private List<Parameter> buildCertificatesParam(CloudCredentials cred) {
List<LoginKey> loginKeys = cred.getLoginKeys();
List<Parameter> parameters = new ArrayList<>();
for (LoginKey lk : loginKeys) {
String domainName = lk.getAttributes().get("domain_name");
if (domainName == null) {
domainName = lk.getAttributes().get("domain_name ");
}
Parameter cert = new Parameter();
cert.setName("certificate");
cert.setValue(lk.getKey());
Map<String, String> attributes = new HashMap<>();
attributes.put("filename", domainName);
cert.setAttributes(attributes);
parameters.add(cert);
}
return parameters;
}
private List<Parameter> buildTopologyParams(String planID) throws JSONException {
ToscaRepresentation plan = toscaDao.findOne(planID);
if (plan == null) {
throw new NotFoundException();
}
List<Parameter> parameters = new ArrayList();
Parameter topology = new Parameter();
topology.setName("topology");
topology.setValue(Converter.map2YmlString(plan.getKvMap()));
Map<String, String> attributes = new HashMap<>();
attributes.put("level", String.valueOf(plan.getLevel()));
attributes.put("filename", FilenameUtils.removeExtension(plan.getName()));
topology.setAttributes(attributes);
parameters.add(topology);
Set<String> ids = plan.getLowerLevelIDs();
for (String lowID : ids) {
plan = toscaDao.findOne(lowID);
topology = new Parameter();
topology.setName("topology");
topology.setValue(Converter.map2YmlString(plan.getKvMap()));
attributes = new HashMap<>();
attributes.put("level", String.valueOf(plan.getLevel()));
attributes.put("filename", FilenameUtils.removeExtension(plan.getName()));
topology.setAttributes(attributes);
parameters.add(topology);
}
return parameters;
}
private Parameter buildEC2Conf(CloudCredentials cred) throws JsonProcessingException, JSONException, IOException {
Properties prop = Converter.getEC2Properties(cred);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
prop.store(baos, null);
byte[] bytes = baos.toByteArray();
Parameter conf = new Parameter();
conf.setName("ec2.conf");
String charset = "UTF-8";
conf.setValue(new String(bytes, charset));
return conf;
}
private List<Parameter> buildScriptParams(String userScriptID) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private List<Parameter> buildKeysParams(String userKeyID) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
...@@ -19,11 +19,9 @@ import nl.uva.sne.drip.commons.types.ToscaRepresentation; ...@@ -19,11 +19,9 @@ import nl.uva.sne.drip.commons.types.ToscaRepresentation;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
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.commons.utils.Converter;
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.stereotype.Component;
...@@ -34,8 +32,8 @@ import org.springframework.web.bind.annotation.ResponseBody; ...@@ -34,8 +32,8 @@ 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 org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import nl.uva.sne.drip.api.dao.ToscaDao;
import nl.uva.sne.drip.api.exception.BadRequestException; import nl.uva.sne.drip.api.exception.BadRequestException;
import nl.uva.sne.drip.api.service.ToscaService;
import nl.uva.sne.drip.api.service.UserService; import nl.uva.sne.drip.api.service.UserService;
/** /**
...@@ -48,7 +46,7 @@ import nl.uva.sne.drip.api.service.UserService; ...@@ -48,7 +46,7 @@ import nl.uva.sne.drip.api.service.UserService;
public class ToscaController { public class ToscaController {
@Autowired @Autowired
private ToscaDao dao; private ToscaService toscaService;
// curl -X POST -F "file=@DRIP/input.yaml" localhost:8080/drip-api/upload // curl -X POST -F "file=@DRIP/input.yaml" localhost:8080/drip-api/upload
@RequestMapping(value = "/upload", method = RequestMethod.POST) @RequestMapping(value = "/upload", method = RequestMethod.POST)
...@@ -59,18 +57,7 @@ public class ToscaController { ...@@ -59,18 +57,7 @@ public class ToscaController {
throw new BadRequestException("Must uplaod a file"); throw new BadRequestException("Must uplaod a file");
} }
try { try {
String originalFileName = file.getOriginalFilename(); return toscaService.save(file, ToscaRepresentation.Type.SIDE);
String name = System.currentTimeMillis() + "_" + originalFileName;
byte[] bytes = file.getBytes();
String str = new String(bytes, "UTF-8");
str = str.replaceAll("\\.", "\uff0E");
Map<String, Object> map = Converter.ymlString2Map(str);
ToscaRepresentation t = new ToscaRepresentation();
t.setName(name);
t.setKvMap(map);
dao.save(t);
return t.getId();
} 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);
} }
...@@ -79,25 +66,12 @@ public class ToscaController { ...@@ -79,25 +66,12 @@ public class ToscaController {
} }
// curl http://localhost:8080/drip-api/tosca/589e1160d9925f9dc127e882/?fromat=yaml // curl http://localhost:8080/drip-api/tosca/589e1160d9925f9dc127e882/?fromat=yaml
@RequestMapping(value = "/{id}", method = RequestMethod.GET, params = {"fromat"}) @RequestMapping(value = "/{id}", method = RequestMethod.GET, params = {"format"})
@RolesAllowed({UserService.USER, UserService.ADMIN}) @RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody public @ResponseBody
String get(@PathVariable("id") String id, @RequestParam(value = "fromat") String fromat) { String get(@PathVariable("id") String id, @RequestParam(value = "format") String format) {
try { try {
Map<String, Object> map = dao.findOne(id).getKvMap(); return toscaService.get(id, format,ToscaRepresentation.Type.SIDE);
if (fromat != null && fromat.equals("yml")) {
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
return ymlStr;
}
if (fromat != null && fromat.equals("json")) {
String jsonStr = Converter.map2JsonString(map);
jsonStr = jsonStr.replaceAll("\\uff0E", "\\.");
return jsonStr;
}
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
return ymlStr;
} catch (JSONException ex) { } catch (JSONException ex) {
Logger.getLogger(ToscaController.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(ToscaController.class.getName()).log(Level.SEVERE, null, ex);
} }
...@@ -108,7 +82,7 @@ public class ToscaController { ...@@ -108,7 +82,7 @@ public class ToscaController {
@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) {
dao.delete(id); toscaService.delete(id,ToscaRepresentation.Type.SIDE);
return "Deleted tosca :" + id; return "Deleted tosca :" + id;
} }
...@@ -117,7 +91,7 @@ public class ToscaController { ...@@ -117,7 +91,7 @@ public class ToscaController {
@RolesAllowed({UserService.USER, UserService.ADMIN}) @RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody public @ResponseBody
List<String> getIds() { List<String> getIds() {
List<ToscaRepresentation> all = dao.findAll(); List<ToscaRepresentation> all = toscaService.findAll(ToscaRepresentation.Type.SIDE);
List<String> ids = new ArrayList<>(); List<String> ids = new ArrayList<>();
for (ToscaRepresentation tr : all) { for (ToscaRepresentation tr : all) {
ids.add(tr.getId()); ids.add(tr.getId());
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
*/ */
package nl.uva.sne.drip.api.rest; package nl.uva.sne.drip.api.rest;
import nl.uva.sne.drip.commons.types.UserPublicKey; import nl.uva.sne.drip.commons.types.LoginKey;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -32,6 +32,7 @@ import org.springframework.web.bind.annotation.ResponseBody; ...@@ -32,6 +32,7 @@ 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.UserKeyDao; import nl.uva.sne.drip.api.dao.UserKeyDao;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.service.UserService; import nl.uva.sne.drip.api.service.UserService;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
...@@ -59,9 +60,10 @@ public class UserPublicKeysController { ...@@ -59,9 +60,10 @@ public class UserPublicKeysController {
byte[] bytes = file.getBytes(); byte[] bytes = file.getBytes();
String key = new String(bytes, "UTF-8"); String key = new String(bytes, "UTF-8");
UserPublicKey upk = new UserPublicKey(); LoginKey upk = new LoginKey();
upk.setKey(key); upk.setKey(key);
upk.setName(name); upk.setName(name);
upk.setType(LoginKey.Type.PUBLIC);
dao.save(upk); dao.save(upk);
return upk.getId(); return upk.getId();
...@@ -73,21 +75,25 @@ public class UserPublicKeysController { ...@@ -73,21 +75,25 @@ public class UserPublicKeysController {
} }
// curl -H "Content-Type: application/json" -X POST -d '{"key":"ssh-rsa AAAAB3NzaDWBqs75i849MytgwgQcRYMcsXIki0yeYTKABH6JqoiyFBHtYlyh/EV1t6cujb9LyNP4J5EN4fPbtwKYvxecd0LojSPxl4wjQlfrHyg6iKUYB7hVzGqACMvgYZHrtHPfrdEmOGPplPVPpoaX2j+u0BZ0yYhrWMKjzyYZKa68yy5N18+Gq+1p83HfUDwIU9wWaUYdgEvDujqF6b8p3z6LDx9Ob+RanSMZSt+b8eZRcd+F2Oy/gieJEJ8kc152VIOv8UY1xB3hVEwVnSRGgrAsa+9PChfF6efXUGWiKf8KBlWgBOYsSTsOY4ks9zkXMnbcTdC+o7xspOkyIcWjv us@u\n","name":"id_rsa.pub"}' localhost:8080/drip-api/user_key/ // curl -H "Content-Type: application/json" -X POST -d '{"key":"ssh-rsa AAAAB3NzaDWBqs75i849MytgwgQcRYMcsXIki0yeYTKABH6JqoiyFBHtYlyh/EV1t6cujb9LyNP4J5EN4fPbtwKYvxecd0LojSPxl4wjQlfrHyg6iKUYB7hVzGqACMvgYZHrtHPfrdEmOGPplPVPpoaX2j+u0BZ0yYhrWMKjzyYZKa68yy5N18+Gq+1p83HfUDwIU9wWaUYdgEvDujqF6b8p3z6LDx9Ob+RanSMZSt+b8eZRcd+F2Oy/gieJEJ8kc152VIOv8UY1xB3hVEwVnSRGgrAsa+9PChfF6efXUGWiKf8KBlWgBOYsSTsOY4ks9zkXMnbcTdC+o7xspOkyIcWjv us@u\n","name":"id_rsa.pub"}' localhost:8080/drip-api/user_key/
@RequestMapping(method = RequestMethod.POST) // @RequestMapping(method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN}) // @RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody // public @ResponseBody
String postConf(UserPublicKey uk) throws JSONException { // String postConf(LoginKey uk) throws JSONException {
String name = System.currentTimeMillis() + "_" + uk.getName(); // String name = System.currentTimeMillis() + "_" + uk.getName();
uk.setName(name); // uk.setName(name);
dao.save(uk); // dao.save(uk);
return uk.getId(); // return uk.getId();
} // }
//curl localhost:8080/drip-api/user_key/58a20be263d4a5898835676e //curl localhost:8080/drip-api/user_key/58a20be263d4a5898835676e
@RequestMapping(value = "/{id}", method = RequestMethod.GET) @RequestMapping(value = "/{id}", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN}) @RolesAllowed({UserService.USER, UserService.ADMIN})
public UserPublicKey get(@PathVariable("id") String id) { public LoginKey get(@PathVariable("id") String id) {
return dao.findOne(id); LoginKey key = dao.findOne(id);
if (key == null || !key.getType().equals(LoginKey.Type.PUBLIC)) {
throw new NotFoundException();
}
return key;
} }
// localhost:8080/drip-api/user_key/ids // localhost:8080/drip-api/user_key/ids
...@@ -95,10 +101,12 @@ public class UserPublicKeysController { ...@@ -95,10 +101,12 @@ public class UserPublicKeysController {
@RolesAllowed({UserService.USER, UserService.ADMIN}) @RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody public @ResponseBody
List<String> getIds() { List<String> getIds() {
List<UserPublicKey> all = dao.findAll(); List<LoginKey> all = dao.findAll();
List<String> ids = new ArrayList<>(); List<String> ids = new ArrayList<>();
for (UserPublicKey tr : all) { for (LoginKey tr : all) {
ids.add(tr.getId()); if (tr.getType().equals(LoginKey.Type.PUBLIC)) {
ids.add(tr.getId());
}
} }
return ids; return ids;
} }
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
*/ */
package nl.uva.sne.drip.api.service; package nl.uva.sne.drip.api.service;
import nl.uva.sne.drip.api.dao.ToscaDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
...@@ -24,4 +26,8 @@ import org.springframework.stereotype.Service; ...@@ -24,4 +26,8 @@ import org.springframework.stereotype.Service;
@Service @Service
public class PlannerService { public class PlannerService {
} }
/*
* 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.api.service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import nl.uva.sne.drip.api.dao.ToscaDao;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.commons.types.ToscaRepresentation;
import nl.uva.sne.drip.commons.utils.Converter;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
/**
*
* @author S. Koulouzis
*/
@Service
public class ToscaService {
@Autowired
private ToscaDao dao;
public String get(String id, String fromat, ToscaRepresentation.Type type) throws JSONException {
ToscaRepresentation tosca = dao.findOne(id);
if (tosca == null || !tosca.getType().equals(type)) {
throw new NotFoundException();
}
Set<String> ids = tosca.getLowerLevelIDs();
Map<String, Object> map = tosca.getKvMap();
if (ids != null) {
for (String lowID : ids) {
map.putAll(dao.findOne(lowID).getKvMap());
}
}
if (fromat != null && fromat.equals("yml")) {
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
return ymlStr;
}
if (fromat != null && fromat.equals("json")) {
String jsonStr = Converter.map2JsonString(map);
jsonStr = jsonStr.replaceAll("\\uff0E", "\\.");
return jsonStr;
}
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
return ymlStr;
}
public String save(MultipartFile file, ToscaRepresentation.Type type) throws IOException {
String originalFileName = file.getOriginalFilename();
String name = System.currentTimeMillis() + "_" + originalFileName;
byte[] bytes = file.getBytes();
String str = new String(bytes, "UTF-8");
str = str.replaceAll("\\.", "\uff0E");
Map<String, Object> map = Converter.ymlString2Map(str);
ToscaRepresentation t = new ToscaRepresentation();
t.setName(name);
t.setKvMap(map);
t.setType(type);
dao.save(t);
return t.getId();
}
public void delete(String id, ToscaRepresentation.Type type) {
ToscaRepresentation tosca = dao.findOne(id);
if (!tosca.getType().equals(type)) {
throw new NotFoundException();
} else {
dao.delete(id);
}
}
public List<ToscaRepresentation> findAll(ToscaRepresentation.Type type) {
List<ToscaRepresentation> all = dao.findAll();
List<ToscaRepresentation> allType = new ArrayList<>();
if (all == null) {
throw new NotFoundException();
}
for (ToscaRepresentation tr : all) {
if (tr.getType() != null && tr.getType().equals(type)) {
allType.add(tr);
}
}
return allType;
}
public ToscaDao getDao() {
return dao;
}
}
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package nl.uva.sne.drip.commons.types; package nl.uva.sne.drip.commons.types;
import java.util.Map; 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;
/** /**
...@@ -25,11 +26,37 @@ import org.springframework.data.mongodb.core.mapping.Document; ...@@ -25,11 +26,37 @@ import org.springframework.data.mongodb.core.mapping.Document;
@Document @Document
public class LoginKey { public class LoginKey {
@Id
private String id;
private Map<String, String> attributes; private Map<String, String> attributes;
private String key; private String key;
private Type type; private Type type;
private String name;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}
public static enum Type { public static enum Type {
PRIVATE, PRIVATE,
......
...@@ -15,62 +15,74 @@ ...@@ -15,62 +15,74 @@
*/ */
package nl.uva.sne.drip.commons.types; package nl.uva.sne.drip.commons.types;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/** /**
* *
* @author S. Koulouzis * @author S. Koulouzis
*/ */
@Document public class ProvisionRequest {
public class UserPublicKey {
private String cloudConfID;
private String planID;
@Id private String userScriptID;
private String id;
private String key; private String userKeyID;
private String name; /**
* @return the cloudConfID
*/
public String getCloudConfID() {
return cloudConfID;
}
/** /**
* @return the id * @param cloudConfID the cloudConfID to set
*/ */
public String getId() { public void setCloudConfID(String cloudConfID) {
return id; this.cloudConfID = cloudConfID;
} }
/** /**
* @param id the id to set * @return the planID
*/ */
public void setId(String id) { public String getPlanID() {
this.id = id; return planID;
} }
/** /**
* @return the key * @param planID the planID to set
*/ */
public String getKey() { public void setPlanID(String planID) {
return key; this.planID = planID;
} }
/** /**
* @param key the key to set * @return the userScriptID
*/ */
public void setKey(String key) { public String getUserScriptID() {
this.key = key; return userScriptID;
} }
/** /**
* @return the name * @param userScriptID the userScriptID to set
*/ */
public String getName() { public void setUserScriptID(String userScriptID) {
return name; this.userScriptID = userScriptID;
} }
/** /**
* @param name the name to set * @return the userKeyID
*/ */
public void setName(String name) { public String getUserKeyID() {
this.name = name; return userKeyID;
} }
/**
* @param userKeyID the userKeyID to set
*/
public void setUserKeyID(String userKeyID) {
this.userKeyID = userKeyID;
}
} }
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
*/ */
package nl.uva.sne.drip.commons.types; package nl.uva.sne.drip.commons.types;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
...@@ -29,15 +29,36 @@ public class ToscaRepresentation { ...@@ -29,15 +29,36 @@ public class ToscaRepresentation {
@Id @Id
private String id; private String id;
private List<String> lowerLevelIDs; private Set<String> lowerLevelIDs;
private String name; private String name;
private Map<String, Object> kvMap; private Map<String, Object> kvMap;
private Integer level; private Integer level;
private Type type;
public static enum Type {
PLAN,
SIDE
}
/**
* @return the type
*/
public Type getType() {
return type;
}
/**
* @param type the type to set
*/
public void setType(Type type) {
this.type = type;
}
public final String getId() { public final String getId() {
return id; return id;
} }
...@@ -91,14 +112,14 @@ public class ToscaRepresentation { ...@@ -91,14 +112,14 @@ public class ToscaRepresentation {
/** /**
* @return the lowerLevelIDs * @return the lowerLevelIDs
*/ */
public List<String> getLowerLevelIDs() { public Set<String> getLowerLevelIDs() {
return lowerLevelIDs; return lowerLevelIDs;
} }
/** /**
* @param lowerLevelIDs the lowerLevelIDs to set * @param lowerLevelIDs the lowerLevelIDs to set
*/ */
public void setLowerLevelIDs(List<String> lowerLevelIDs) { public void setLowerLevelIDs(Set<String> lowerLevelIDs) {
this.lowerLevelIDs = lowerLevelIDs; this.lowerLevelIDs = lowerLevelIDs;
} }
......
...@@ -30,10 +30,8 @@ import java.io.IOException; ...@@ -30,10 +30,8 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -382,7 +380,6 @@ public class Consumer extends DefaultConsumer { ...@@ -382,7 +380,6 @@ public class Consumer extends DefaultConsumer {
byte[] bytes = Files.readAllBytes(Paths.get(f.getAbsolutePath())); byte[] bytes = Files.readAllBytes(Paths.get(f.getAbsolutePath()));
fileArguments.put("value", new String(bytes, charset)); fileArguments.put("value", new String(bytes, charset));
parameters.add(fileArguments); parameters.add(fileArguments);
} else { } else {
fileArguments.put("name", outputs.get(i).topologyName); fileArguments.put("name", outputs.get(i).topologyName);
fileArguments.put("value", "ERROR::There is no output for topology " + outputs.get(i).topologyName); fileArguments.put("value", "ERROR::There is no output for topology " + outputs.get(i).topologyName);
......
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