Commit 00a13b34 authored by Oceans's avatar Oceans

Merge branch 'package' of https://github.com/skoulouzis/DRIP into package

parents 0d4ddf27 5e0247c7
......@@ -15,17 +15,23 @@
*/
package nl.uva.sne.drip.api.service;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeoutException;
import nl.uva.sne.drip.api.dao.PlanDao;
import nl.uva.sne.drip.api.exception.BadRequestException;
import nl.uva.sne.drip.api.rpc.PlannerCaller;
import nl.uva.sne.drip.commons.types.Message;
import nl.uva.sne.drip.commons.types.MessageParameter;
import nl.uva.sne.drip.commons.types.Plan;
import nl.uva.sne.drip.commons.types.SimplePlanContainer;
import nl.uva.sne.drip.commons.types.ToscaRepresentation;
import nl.uva.sne.drip.commons.utils.Converter;
import org.json.JSONException;
......@@ -43,6 +49,9 @@ public class PlannerService {
@Autowired
private ToscaService toscaService;
@Autowired
private PlanDao planDao;
@Value("${message.broker.host}")
private String messageBrokerHost;
......@@ -52,15 +61,30 @@ public class PlannerService {
Message plannerInvokationMessage = buildPlannerMessage(toscaId);
Message plannerReturnedMessage = planner.call(plannerInvokationMessage);
List<MessageParameter> parameters = plannerReturnedMessage.getParameters();
for (MessageParameter param : parameters) {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
String jsonString = mapper.writeValueAsString(plannerReturnedMessage);
SimplePlanContainer simplePlan = Converter.plannerOutput2SimplePlanContainer(jsonString);
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();
Set<String> loweLevelPlansIDs = new HashSet<>();
for (String lowLevelNames : map.keySet()) {
Plan lowLevelPlan = new Plan();
lowLevelPlan.setLevel(1);
lowLevelPlan.setToscaID(toscaId);
lowLevelPlan.setName(lowLevelNames);
lowLevelPlan.setKvMap(Converter.ymlString2Map(map.get(lowLevelNames)));
planDao.save(lowLevelPlan);
loweLevelPlansIDs.add(lowLevelPlan.getId());
}
ToscaRepresentation tr = new ToscaRepresentation();
Map<String, Object> kvMap = null;
tr.setKvMap(kvMap);
return null;
topLevel.setLoweLevelPlansIDs(loweLevelPlansIDs);
planDao.save(topLevel);
return topLevel;
}
}
......
......@@ -15,7 +15,6 @@
*/
package nl.uva.sne.drip.commons.types;
import java.util.Map;
import org.springframework.data.annotation.Id;
/**
......@@ -27,7 +26,7 @@ public class ClusterCredentials {
@Id
private String id;
private Map<String, Object> kvMap;
private String contents;
/**
* @return the id
......@@ -44,17 +43,17 @@ public class ClusterCredentials {
}
/**
* @return the kvMap
* @return the contents
*/
public Map<String, Object> getKvMap() {
return kvMap;
public String getContents() {
return contents;
}
/**
* @param kvMap the kvMap to set
* @param contents the contents to set
*/
public void setKvMap(Map<String, Object> kvMap) {
this.kvMap = kvMap;
public void setContents(String contents) {
this.contents = contents;
}
}
......@@ -71,6 +71,11 @@ 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();
......
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