Commit 18012161 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Throw exception if provider name is null

parent a2148dd6
......@@ -43,6 +43,7 @@ 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.BadRequestException;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.rpc.DRIPCaller;
import nl.uva.sne.drip.api.rpc.ProvisionerCaller;
......@@ -74,7 +75,7 @@ public class ProvisionController {
ProvisionRequest get() {
ProvisionRequest re = new ProvisionRequest();
re.setCloudConfID("58a1f0a963d42f004b1d63ad");
re.setPlanID("58ac1e70e4949b54f8ac1051");
re.setPlanID("58ad99d578b6ba941aeb22a4");
re.setUserKeyID("58a20be263d4a5898835676e");
re.setUserScriptID("58a2112363d41754cca042b4");
return re;
......@@ -123,6 +124,10 @@ public class ProvisionController {
private Parameter buildCloudConfParam(CloudCredentials cred) throws JsonProcessingException, JSONException, IOException {
Parameter conf = null;
String provider = cred.getCloudProviderName();
if (provider == null) {
throw new BadRequestException("Provider name can't be null. Check the cloud credentials: " + cred.getId());
}
switch (cred.getCloudProviderName().toLowerCase()) {
case "ec2":
conf = buildEC2Conf(cred);
......
......@@ -118,11 +118,16 @@ public abstract class DRIPCaller implements AutoCloseable {
}
});
String strResponse = response.take();
// return unMarshallWithSimpleJson(strResponse);
return mapper.readValue(strResponse, Message.class);
}
private Message unMarshallWithSimpleJson(String strResponse) throws JSONException {
strResponse = strResponse.replaceAll("'null'", "null").replaceAll("\'", "\"").replaceAll(" ", "");
// System.err.println(strResponse);
JSONObject jsonObj = new JSONObject(strResponse);
Message responseMessage = new Message();
responseMessage.setCreationDate((Long) jsonObj.get("creationDate"));
JSONArray jsonParams = (JSONArray) jsonObj.get("parameters");
List<Parameter> parameters = new ArrayList<>();
......@@ -137,7 +142,8 @@ public abstract class DRIPCaller implements AutoCloseable {
}
responseMessage.setParameters(parameters);
return responseMessage;//mapper.readValue(strResponse, Message.class);
return responseMessage;//
}
}
......@@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeoutException;
import nl.uva.sne.drip.api.exception.BadRequestException;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.rpc.PlannerCaller;
import nl.uva.sne.drip.commons.types.Message;
import nl.uva.sne.drip.commons.types.Parameter;
......@@ -51,8 +53,8 @@ public class PlannerService {
Message plannerReturnedMessage = planner.call(plannerInvokationMessage);
List<Parameter> parameters = plannerReturnedMessage.getParameters();
for(Parameter param: parameters){
for (Parameter param : parameters) {
}
ToscaRepresentation tr = new ToscaRepresentation();
Map<String, Object> kvMap = null;
......@@ -65,6 +67,9 @@ public class PlannerService {
private Message buildPlannerMessage(String toscaId) throws JSONException, UnsupportedEncodingException {
ToscaRepresentation t2 = toscaService.getDao().findOne(toscaId);
if (t2 == null || t2.getType().equals(ToscaRepresentation.Type.PLAN)) {
throw new BadRequestException("The description: " + toscaId + " is a plan. Cannot be used as planner input");
}
Map<String, Object> map = t2.getKvMap();
String json = Converter.map2JsonString(map);
json = json.replaceAll("\\uff0E", "\\.");
......
......@@ -26,6 +26,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeoutException;
import nl.uva.sne.drip.api.exception.BadRequestException;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.rpc.PlannerCaller;
import nl.uva.sne.drip.commons.types.Message;
......@@ -81,7 +82,8 @@ public class SimplePlannerService {
}
ids.add(tr.getId());
topLevel.setLowerLevelIDs(ids);
} topLevel.setType(ToscaRepresentation.Type.PLAN);
}
topLevel.setType(ToscaRepresentation.Type.PLAN);
toscaService.getDao().save(topLevel);
}
return topLevel;
......@@ -89,8 +91,8 @@ public class SimplePlannerService {
private Message buildSimplePlannerMessage(String toscaId) throws JSONException, UnsupportedEncodingException, IOException {
ToscaRepresentation t2 = toscaService.getDao().findOne(toscaId);
if (t2 == null) {
throw new NotFoundException();
if (t2 == null || t2.getType().equals(ToscaRepresentation.Type.PLAN)) {
throw new BadRequestException("The description: " + toscaId + " is a plan. Cannot be used as planner input");
}
Map<String, Object> map = t2.getKvMap();
String ymlStr = Converter.map2YmlString(map);
......
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