Commit 3793b78f authored by Spiros Koulouzis's avatar Spiros Koulouzis

Refactor data types: Each agent has its own data type

parent 1611ae99
......@@ -15,13 +15,13 @@
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.commons.types.Provision;
import nl.uva.sne.drip.commons.types.ProvisionInfo;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
*
* @author S. Koulouzis
*/
public interface ProvisionDao extends MongoRepository<Provision, String> {
public interface ProvisionInfoDao extends MongoRepository<ProvisionInfo, String> {
}
......@@ -16,7 +16,7 @@
package nl.uva.sne.drip.api.rest;
import com.fasterxml.jackson.core.JsonParser;
import nl.uva.sne.drip.commons.types.Provision;
import nl.uva.sne.drip.commons.types.ProvisionInfo;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.ByteArrayOutputStream;
......@@ -90,14 +90,14 @@ public class ProvisionController {
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
Provision get(@PathVariable("id") String id) {
ProvisionInfo get(@PathVariable("id") String id) {
return provisionService.getDao().findOne(id);
}
@RequestMapping(value = "/provision", method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String plann(@RequestBody Provision req) {
String plann(@RequestBody ProvisionInfo req) {
try (DRIPCaller provisioner = new ProvisionerCaller(messageBrokerHost);) {
Message provisionerInvokationMessage = buildProvisionerMessage(req);
......@@ -113,6 +113,19 @@ public class ProvisionController {
req.setKvMap(kvMap);
req.setPlanID(req.getPlanID());
provisionService.getDao().save(req);
} else {
String value = p.getValue();
String[] lines = value.split("\n");
for (String line : lines) {
String[] parts = line.split(" ");
String deployIP = parts[0];
String deployUser = parts[1];
String deployCertPath = parts[2];
String deployRole = parts[3];
req.setDeployIP(deployIP);
req.setDeployUser(deployUser);
req.setDeployRole(deployRole);
}
}
}
return req.getId();
......@@ -122,7 +135,7 @@ public class ProvisionController {
return null;
}
private Message buildProvisionerMessage(Provision pReq) throws JSONException, IOException {
private Message buildProvisionerMessage(ProvisionInfo pReq) throws JSONException, IOException {
Message invokationMessage = new Message();
List<Parameter> parameters = new ArrayList();
CloudCredentials cred = cloudCredentialsDao.findOne(pReq.getCloudConfID());
......
......@@ -18,7 +18,6 @@ package nl.uva.sne.drip.api.service;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import nl.uva.sne.drip.api.dao.ProvisionDao;
import nl.uva.sne.drip.api.dao.ToscaDao;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.commons.types.ToscaRepresentation;
......@@ -27,6 +26,7 @@ import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import nl.uva.sne.drip.api.dao.ProvisionInfoDao;
/**
*
......@@ -36,9 +36,9 @@ import org.springframework.web.multipart.MultipartFile;
public class ProvisionService {
@Autowired
private ProvisionDao dao;
private ProvisionInfoDao dao;
public ProvisionDao getDao() {
public ProvisionInfoDao getDao() {
return dao;
}
......
......@@ -22,7 +22,7 @@ import org.springframework.data.annotation.Id;
*
* @author S. Koulouzis
*/
public class Provision {
public class ProvisionInfo {
@Id
private String id;
......@@ -36,6 +36,9 @@ public class Provision {
private String userKeyID;
private Map<String, Object> kvMap;
private String deployIP;
private String deployUser;
private String deployRole;
/**
* @return the cloudConfID
......@@ -121,4 +124,40 @@ public class Provision {
this.kvMap = kvMap;
}
public void setDeployIP(String deployIP) {
this.deployIP = deployIP;
}
public void setDeployRole(String deployRole) {
this.deployRole = deployRole;
}
/**
* @return the deployIP
*/
public String getDeployIP() {
return deployIP;
}
/**
* @return the deployRole
*/
public String getDeployRole() {
return deployRole;
}
/**
* @return the deployUser
*/
public String getDeployUser() {
return deployUser;
}
/**
* @param deployUser the deployUser to set
*/
public void setDeployUser(String deployUser) {
this.deployUser = deployUser;
}
}
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