Commit ea6686fc authored by Spiros Koulouzis's avatar Spiros Koulouzis

Added converter with hardcoded values

parent 33c29ff2
......@@ -119,6 +119,13 @@
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip-planner2provisioner</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
......
......@@ -22,11 +22,15 @@ import org.springframework.web.bind.annotation.ResponseStatus;
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "MMMMMMMMMMMMMMMMMM")
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public class BadRequestException extends RuntimeException {
public BadRequestException(String massage) {
super(massage);
}
public BadRequestException() {
super();
}
}
......@@ -33,6 +33,8 @@ import nl.uva.sne.drip.commons.types.MessageParameter;
import nl.uva.sne.drip.commons.types.Plan;
import nl.uva.sne.drip.commons.types.ToscaRepresentation;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.drip.converter.P2PConverter;
import nl.uva.sne.drip.drip.converter.SimplePlanContainer;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -63,13 +65,13 @@ public class PlannerService {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
String jsonString = mapper.writeValueAsString(plannerReturnedMessage);
SimplePlanContainer simplePlan = Converter.plannerOutput2SimplePlanContainer(jsonString);
SimplePlanContainer simplePlan = P2PConverter.transfer(jsonString, "zh9314", "Ubuntu 16.04", "swarm");
Plan topLevel = new Plan();
topLevel.setLevel(0);
topLevel.setToscaID(toscaId);
topLevel.setName("planner_output_all.yml");
topLevel.setKvMap(Converter.ymlString2Map(simplePlan.getTopLevel()));
Map<String, String> map = simplePlan.getLowerLevels();
topLevel.setKvMap(Converter.ymlString2Map(simplePlan.topLevelContents));
Map<String, String> map = simplePlan.lowerLevelContents;
Set<String> loweLevelPlansIDs = new HashSet<>();
for (String lowLevelNames : map.keySet()) {
Plan lowLevelPlan = new Plan();
......@@ -90,7 +92,7 @@ public class PlannerService {
private Message buildPlannerMessage(String toscaId) throws JSONException, UnsupportedEncodingException {
ToscaRepresentation t2 = toscaService.getDao().findOne(toscaId);
if (t2 == null) {
throw new BadRequestException("The description: " + toscaId + " is a plan. Cannot be used as planner input");
throw new BadRequestException();
}
Map<String, Object> map = t2.getKvMap();
String json = Converter.map2JsonString(map);
......
......@@ -58,12 +58,21 @@
<version>1.10.0.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>4.2.1.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip-planner2provisioner</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
......
......@@ -31,7 +31,6 @@ public class CloudCredentials {
private String key;
private String keyIdAlias;
private List<LoginKey> loginKeys;
......
......@@ -16,7 +16,9 @@
package nl.uva.sne.drip.commons.utils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Enumeration;
......@@ -26,6 +28,8 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import nl.uva.sne.drip.commons.types.CloudCredentials;
import nl.uva.sne.drip.drip.converter.P2PConverter;
import nl.uva.sne.drip.drip.converter.SimplePlanContainer;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
......@@ -71,10 +75,6 @@ public class Converter {
return jsonObject2Map(jsonObject);
}
public static SimplePlanContainer plannerOutput2SimplePlanContainer(String jsonString) throws JSONException {
return null;
}
public static Map<String, Object> jsonObject2Map(JSONObject object) throws JSONException {
Map<String, Object> map = new HashMap();
......
package nl.uva.sne.drip.drip.converter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -23,10 +22,9 @@ import nl.uva.sne.drip.drip.converter.provisioner.in.Subnet;
import nl.uva.sne.drip.drip.converter.provisioner.in.TopTopology;
import nl.uva.sne.drip.drip.converter.provisioner.in.VM;
public class P2PConverter {
public static SimplePlanContainer transfer(String plannerOutputJson, String userName, String OStype, String clusterType) throws JsonParseException, JsonMappingException, IOException{
public static SimplePlanContainer transfer(String plannerOutputJson, String userName, String OStype, String clusterType) throws JsonParseException, JsonMappingException, IOException {
Parameter plannerOutput = getInfoFromPlanner(plannerOutputJson);
......@@ -51,7 +49,7 @@ public class P2PConverter {
subTopology.components = new ArrayList<VM>();
boolean firstVM = true;
for(int vi = 0 ; vi < plannerOutput.value.size() ; vi++){
for (int vi = 0; vi < plannerOutput.value.size(); vi++) {
Value curValue = plannerOutput.value.get(vi);
VM curVM = new VM();
curVM.name = curValue.name;
......@@ -62,29 +60,30 @@ public class P2PConverter {
curVM.dockers = curValue.docker;
curVM.public_address = curValue.name;
if(curValue.size.trim().toLowerCase().equals("small"))
if (curValue.size.trim().toLowerCase().equals("small")) {
curVM.nodeType = "t2.small";
else if(curValue.size.trim().toLowerCase().equals("medium"))
} else if (curValue.size.trim().toLowerCase().equals("medium")) {
curVM.nodeType = "t2.medium";
else if(curValue.size.trim().toLowerCase().equals("large"))
} else if (curValue.size.trim().toLowerCase().equals("large")) {
curVM.nodeType = "t2.large";
else{
} else {
throw new IllegalArgumentException("Invalid value for field 'size' in input JSON String");
}
Eth eth = new Eth();
eth.name = "p1";
eth.subnet_name = "s1";
int hostNum = 10+vi;
String priAddress = "192.168.10."+hostNum;
int hostNum = 10 + vi;
String priAddress = "192.168.10." + hostNum;
eth.address = priAddress;
curVM.ethernet_port = new ArrayList<Eth>();
curVM.ethernet_port.add(eth);
if(firstVM){
if (firstVM) {
curVM.role = "master";
firstVM = false;
}else
} else {
curVM.role = "slave";
}
subTopology.components.add(curVM);
}
......@@ -98,14 +97,14 @@ public class P2PConverter {
return spc;
}
private static Parameter getInfoFromPlanner(String json) throws JsonParseException, JsonMappingException, IOException{
private static Parameter getInfoFromPlanner(String json) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper mapper = new ObjectMapper();
PlannerOutput po = mapper.readValue(json, PlannerOutput.class);
System.out.println("");
return po.parameters.get(0);
}
private static SimplePlanContainer generateInfo(TopTopology topTopology) throws JsonProcessingException{
private static SimplePlanContainer generateInfo(TopTopology topTopology) throws JsonProcessingException {
SimplePlanContainer spc = new SimplePlanContainer();
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
......@@ -113,7 +112,7 @@ public class P2PConverter {
spc.topLevelContents = yamlString.substring(4);
Map<String, String> output = new HashMap<String, String>();
for(int i = 0 ; i<topTopology.topologies.size() ; i++){
for (int i = 0; i < topTopology.topologies.size(); i++) {
String key = topTopology.topologies.get(i).topology;
String value = mapper.writeValueAsString(topTopology.topologies.get(i).subTopology);
output.put(key, value.substring(4));
......@@ -121,7 +120,6 @@ public class P2PConverter {
spc.lowerLevelContents = output;
return spc;
}
......
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