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