Commit 748a4066 authored by Spiros Koulouzis's avatar Spiros Koulouzis

select cloud provider based on avaliable credentials

parent ade73225
......@@ -34,6 +34,7 @@ import nl.uva.sne.drip.drip.commons.data.internal.MessageParameter;
import nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.ToscaRepresentation;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials;
import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import nl.uva.sne.drip.drip.converter.P2PConverter;
import nl.uva.sne.drip.drip.converter.SimplePlanContainer;
......@@ -57,13 +58,16 @@ public class PlannerService {
@Autowired
private ToscaService toscaService;
@Autowired
private CloudCredentialsService credentialService;
@Autowired
private PlanDao planDao;
@Value("${message.broker.host}")
private String messageBrokerHost;
public PlanResponse getPlan(String toscaId, String vmUser, String cloudProvider, String domainName) throws JSONException, UnsupportedEncodingException, IOException, TimeoutException, InterruptedException {
public PlanResponse getPlan(String toscaId) throws JSONException, UnsupportedEncodingException, IOException, TimeoutException, InterruptedException {
try (PlannerCaller planner = new PlannerCaller(messageBrokerHost)) {
Message plannerInvokationMessage = buildPlannerMessage(toscaId);
Message plannerReturnedMessage = (planner.call(plannerInvokationMessage));
......@@ -83,8 +87,11 @@ public class PlannerService {
}
jsonArrayString.append("]");
String cloudProvider = getBestCloudProvider();
String domainName = getBestDomain(cloudProvider);
// SimplePlanContainer simplePlan = P2PConverter.convert(jsonArrayString.toString(), "vm_user", "Ubuntu 16.04", clusterType);
SimplePlanContainer simplePlan = P2PConverter.transfer(jsonArrayString.toString(), vmUser, domainName, cloudProvider);
SimplePlanContainer simplePlan = P2PConverter.transfer(jsonArrayString.toString(), "vm_user", domainName, cloudProvider);
PlanResponse topLevel = new PlanResponse();
topLevel.setTimestamp(System.currentTimeMillis());
......@@ -253,4 +260,19 @@ public class PlannerService {
return false;
}
private String getBestCloudProvider() {
List<CloudCredentials> creds = credentialService.findAll();
return creds.get(0).getCloudProviderName();
}
private String getBestDomain(String cloudProvider) {
switch (cloudProvider.trim().toLowerCase()) {
case "ec2":
return "Virginia";
case "egi":
return "CESNET";
}
return null;
}
}
......@@ -61,12 +61,11 @@ public class PlannerController0 {
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
Result plan(@RequestBody Plan plan0) {
try {
String yaml = plan0.file;
yaml = yaml.replaceAll("\\\\n", "\n");
String id = toscaService.saveYamlString(yaml, null);
nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse plan1 = plannerService.getPlan(id, "vm_user", "EC2", "Virginia");
nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse plan1 = plannerService.getPlan(id);
Result r = new Result();
r.info = ("INFO");
r.status = ("Success");
......
......@@ -87,8 +87,7 @@ public class PlannerController {
String plan(@PathVariable("tosca_id") String toscaId) {
try {
PlanResponse plan = plannerService.getPlan(toscaId,
"vm_user", "EC2", "Virginia");
PlanResponse plan = plannerService.getPlan(toscaId);
if (plan == null) {
throw new NotFoundException("Could not make plan");
}
......
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