Commit 97fcf58a authored by Spiros Koulouzis's avatar Spiros Koulouzis

implementing vm scaling. We hit null pointer exception at EGISEngine line 654

parent a3d328f3
...@@ -53,7 +53,7 @@ import nl.uva.sne.drip.api.exception.KeyException; ...@@ -53,7 +53,7 @@ import nl.uva.sne.drip.api.exception.KeyException;
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.ConfigurationRepresentation; import nl.uva.sne.drip.drip.commons.data.v1.external.ConfigurationRepresentation;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair; import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
import nl.uva.sne.drip.drip.commons.data.v1.external.ScaleDeploymetRequest; import nl.uva.sne.drip.drip.commons.data.v1.external.ScaleRequest;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleOutput; import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleOutput;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleResult; import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleResult;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.BenchmarkResult; import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.BenchmarkResult;
...@@ -274,19 +274,19 @@ public class DeployService { ...@@ -274,19 +274,19 @@ public class DeployService {
return scaleParameter; return scaleParameter;
} }
public DeployResponse scale(ScaleDeploymetRequest scaleReq) throws IOException, TimeoutException, InterruptedException, JSONException, Exception { public DeployResponse scale(ScaleRequest scaleReq) throws IOException, TimeoutException, InterruptedException, JSONException, Exception {
//Deployer needs configurationID -> name_of_deployment //Deployer needs configurationID -> name_of_deployment
String deployId = scaleReq.getDeployID(); String deployId = scaleReq.getScaleTargetID();
DeployResponse deployment = this.findOne(deployId); DeployResponse deployment = this.findOne(deployId);
String confID = deployment.getConfigurationID(); String confID = deployment.getConfigurationID();
ConfigurationRepresentation configuration = configurationService.findOne(confID); ConfigurationRepresentation configuration = configurationService.findOne(confID);
Map<String, Object> map = configuration.getKeyValue(); Map<String, Object> map = configuration.getKeyValue();
Map<String, Object> services = (Map<String, Object>) map.get("services"); Map<String, Object> services = (Map<String, Object>) map.get("services");
if (!services.containsKey(scaleReq.getServiceName())) { if (!services.containsKey(scaleReq.getScaleTargetName())) {
throw new BadRequestException("Service name does not exist in this deployment"); throw new BadRequestException("Service name does not exist in this deployment");
} }
Message message = buildDeployerMessage(deployment.getProvisionID(), "scale", confID, scaleReq.getServiceName(), scaleReq.getNumOfInstances()); Message message = buildDeployerMessage(deployment.getProvisionID(), "scale", confID, scaleReq.getScaleTargetName(), scaleReq.getNumOfInstances());
try (DRIPCaller deployer = new DeployerCaller(messageBrokerHost);) { try (DRIPCaller deployer = new DeployerCaller(messageBrokerHost);) {
Message response = (deployer.call(message)); Message response = (deployer.call(message));
......
...@@ -58,10 +58,10 @@ import org.springframework.security.access.prepost.PostFilter; ...@@ -58,10 +58,10 @@ import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import nl.uva.sne.drip.api.dao.ProvisionResponseDao; import nl.uva.sne.drip.api.dao.ProvisionResponseDao;
import nl.uva.sne.drip.api.dao.KeyPairDao;
import nl.uva.sne.drip.api.rpc.ProvisionerCaller1; import nl.uva.sne.drip.api.rpc.ProvisionerCaller1;
import nl.uva.sne.drip.drip.commons.data.v1.external.Key; import nl.uva.sne.drip.drip.commons.data.v1.external.Key;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair; import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
import nl.uva.sne.drip.drip.commons.data.v1.external.ScaleRequest;
/** /**
* *
...@@ -74,14 +74,11 @@ public class ProvisionService { ...@@ -74,14 +74,11 @@ public class ProvisionService {
@Autowired @Autowired
private ProvisionResponseDao provisionDao; private ProvisionResponseDao provisionDao;
@Autowired
private KeyPairDao keyDao;
@Autowired @Autowired
private CloudCredentialsService cloudCredentialsService; private CloudCredentialsService cloudCredentialsService;
@Autowired @Autowired
private SimplePlannerService planService; private SimplePlannerService simplePlanService;
@Autowired @Autowired
private ScriptService userScriptService; private ScriptService userScriptService;
...@@ -232,7 +229,7 @@ public class ProvisionService { ...@@ -232,7 +229,7 @@ public class ProvisionService {
} }
private List<MessageParameter> buildTopologyParams(String planID) throws JSONException, FileNotFoundException { private List<MessageParameter> buildTopologyParams(String planID) throws JSONException, FileNotFoundException {
PlanResponse plan = planService.getDao().findOne(planID); PlanResponse plan = simplePlanService.getDao().findOne(planID);
if (plan == null) { if (plan == null) {
throw new PlanNotFoundException(); throw new PlanNotFoundException();
...@@ -252,7 +249,7 @@ public class ProvisionService { ...@@ -252,7 +249,7 @@ public class ProvisionService {
Set<String> ids = plan.getLoweLevelPlanIDs(); Set<String> ids = plan.getLoweLevelPlanIDs();
if (ids != null) { if (ids != null) {
for (String lowID : ids) { for (String lowID : ids) {
PlanResponse lowPlan = planService.getDao().findOne(lowID); PlanResponse lowPlan = simplePlanService.getDao().findOne(lowID);
topology = new MessageParameter(); topology = new MessageParameter();
topology.setName("topology"); topology.setName("topology");
String value = Converter.map2YmlString(lowPlan.getKeyValue()); String value = Converter.map2YmlString(lowPlan.getKeyValue());
...@@ -446,7 +443,7 @@ public class ProvisionService { ...@@ -446,7 +443,7 @@ public class ProvisionService {
// + File.separator + "docs" + File.separator + "json_samples" // + File.separator + "docs" + File.separator + "json_samples"
// + File.separator + "ec2_provisioner_provisoned3.json"); // + File.separator + "ec2_provisioner_provisoned3.json");
return parseCreateResourcesResponse(response.getParameters(), provisionRequest); return parseCreateResourcesResponse(response.getParameters(), provisionRequest, null);
} }
...@@ -454,23 +451,68 @@ public class ProvisionService { ...@@ -454,23 +451,68 @@ public class ProvisionService {
private ProvisionResponse callProvisioner1(ProvisionRequest provisionRequest) throws IOException, TimeoutException, JSONException, InterruptedException, Exception { private ProvisionResponse callProvisioner1(ProvisionRequest provisionRequest) throws IOException, TimeoutException, JSONException, InterruptedException, Exception {
try (DRIPCaller provisioner = new ProvisionerCaller1(messageBrokerHost);) { try (DRIPCaller provisioner = new ProvisionerCaller1(messageBrokerHost);) {
Message provisionerInvokationMessage = buildProvisione1Message(provisionRequest); Message provisionerInvokationMessage = buildProvisioner1Message(provisionRequest);
Message response = (provisioner.call(provisionerInvokationMessage)); Message response = (provisioner.call(provisionerInvokationMessage));
return parseCreateResourcesResponse(response.getParameters(), provisionRequest); return parseCreateResourcesResponse(response.getParameters(), provisionRequest, null);
} }
} }
public void deleteProvisionedResources(ProvisionResponse provisionInfo) throws IOException, TimeoutException, InterruptedException, JSONException { public void deleteProvisionedResources(ProvisionResponse provisionInfo) throws IOException, TimeoutException, InterruptedException, JSONException {
try (DRIPCaller provisioner = new ProvisionerCaller1(messageBrokerHost);) { try (DRIPCaller provisioner = new ProvisionerCaller1(messageBrokerHost);) {
Message deleteInvokationMessage = buildDeleteMessage(provisionInfo); Message deleteInvokationMessage = buildTopoplogyModificationMessage(provisionInfo, "kill_topology", null);
Message response = (provisioner.call(deleteInvokationMessage)); Message response = (provisioner.call(deleteInvokationMessage));
parseDeleteResourcesResponse(response.getParameters(), provisionInfo); parseDeleteResourcesResponse(response.getParameters(), provisionInfo);
} }
}
public ProvisionResponse scale(ScaleRequest scaleRequest) throws IOException, TimeoutException, JSONException, InterruptedException, Exception {
String provisionID = scaleRequest.getScaleTargetID();
String scaleName = scaleRequest.getScaleTargetName();
if (scaleName == null || scaleName.length() < 1) {
throw new BadRequestException("Must specify wich topology to scale. \'scaleName\' was empty ");
}
ProvisionResponse provisionInfo = findOne(provisionID);
boolean scaleNameExists = false;
Map<String, Object> plan = provisionInfo.getKeyValue();
String cloudProvider = null;
String domain = null;
for (String key : plan.keySet()) {
Map<String, Object> subMap = (Map<String, Object>) plan.get(key);
if (subMap.containsKey("topologies")) {
List< Map<String, Object>> topologies = (List< Map<String, Object>>) subMap.get("topologies");
for (Map<String, Object> topology : topologies) {
if (topology.get("tag").equals("scaling") && topology.get("topology").equals(scaleName)) {
cloudProvider = (String) topology.get("cloudProvider");
domain = (String) topology.get("domain");
scaleNameExists = true;
break;
}
}
}
if (scaleNameExists) {
break;
} }
}
if (!scaleNameExists) {
throw new BadRequestException("Name of topology dosen't exist");
}
try (DRIPCaller provisioner = new ProvisionerCaller1(messageBrokerHost);) {
Map<String, String> extra = new HashMap<>();
extra.put("scale_topology_name", scaleName);
extra.put("number_of_instances", String.valueOf(scaleRequest.getNumOfInstances()));
extra.put("cloud_provider", cloudProvider);
extra.put("domain", domain);
Message scaleMessage = buildTopoplogyModificationMessage(provisionInfo, "scale_topology", extra);
Message response = provisioner.call(scaleMessage);
parseCreateResourcesResponse(response.getParameters(), null, provisionInfo);
private Message buildProvisione1Message(ProvisionRequest provisionRequest) throws JSONException, FileNotFoundException, IOException { }
return provisionInfo;
}
private Message buildProvisioner1Message(ProvisionRequest provisionRequest) throws JSONException, FileNotFoundException, IOException {
Message invokationMessage = new Message(); Message invokationMessage = new Message();
List<MessageParameter> parameters = new ArrayList(); List<MessageParameter> parameters = new ArrayList();
...@@ -512,13 +554,13 @@ public class ProvisionService { ...@@ -512,13 +554,13 @@ public class ProvisionService {
} }
private Message buildDeleteMessage(ProvisionResponse provisionInfo) throws JSONException, IOException { private Message buildTopoplogyModificationMessage(ProvisionResponse provisionInfo, String actionName, Map<String, String> extraAttributes) throws JSONException, IOException {
Message invokationMessage = new Message(); Message invokationMessage = new Message();
List<MessageParameter> parameters = new ArrayList(); List<MessageParameter> parameters = new ArrayList();
MessageParameter action = new MessageParameter(); MessageParameter action = new MessageParameter();
action.setName("action"); action.setName("action");
action.setValue("kill_topology"); action.setValue(actionName);
parameters.add(action); parameters.add(action);
List<MessageParameter> topologies = buildProvisionedTopologyParams(provisionInfo); List<MessageParameter> topologies = buildProvisionedTopologyParams(provisionInfo);
...@@ -541,7 +583,17 @@ public class ProvisionService { ...@@ -541,7 +583,17 @@ public class ProvisionService {
List<MessageParameter> cloudCredentialParams = buildCloudCredentialParam(cred, 1); List<MessageParameter> cloudCredentialParams = buildCloudCredentialParam(cred, 1);
parameters.addAll(cloudCredentialParams); parameters.addAll(cloudCredentialParams);
} }
if (extraAttributes != null && extraAttributes.containsKey("scale_topology_name")) {
MessageParameter scale = new MessageParameter();
scale.setName("scale_topology_name");
scale.setValue(extraAttributes.get("scale_topology_name"));
Map<String, String> attributes = new HashMap<>();
attributes.put("number_of_instances", extraAttributes.get("number_of_instances"));
attributes.put("cloud_provider", extraAttributes.get("cloud_provider"));
attributes.put("domain", extraAttributes.get("domain"));
scale.setAttributes(attributes);
parameters.add(scale);
}
invokationMessage.setParameters(parameters); invokationMessage.setParameters(parameters);
invokationMessage.setCreationDate(System.currentTimeMillis()); invokationMessage.setCreationDate(System.currentTimeMillis());
return invokationMessage; return invokationMessage;
...@@ -563,9 +615,12 @@ public class ProvisionService { ...@@ -563,9 +615,12 @@ public class ProvisionService {
return parameters; return parameters;
} }
private ProvisionResponse parseCreateResourcesResponse(List<MessageParameter> parameters, ProvisionRequest provisionRequest) throws Exception { private ProvisionResponse parseCreateResourcesResponse(List<MessageParameter> parameters, ProvisionRequest provisionRequest, ProvisionResponse provisionResponse) throws Exception {
ProvisionResponse provisionResponse = new ProvisionResponse(); if (provisionResponse == null) {
provisionResponse = new ProvisionResponse();
provisionResponse.setTimestamp(System.currentTimeMillis()); provisionResponse.setTimestamp(System.currentTimeMillis());
}
List<DeployParameter> deployParameters = new ArrayList<>(); List<DeployParameter> deployParameters = new ArrayList<>();
Map<String, Object> kvMap = null; Map<String, Object> kvMap = null;
KeyPair userKey = new KeyPair(); KeyPair userKey = new KeyPair();
...@@ -658,8 +713,13 @@ public class ProvisionService { ...@@ -658,8 +713,13 @@ public class ProvisionService {
break; break;
} }
} }
List<String> userKeyIds = null;
if (provisionRequest != null) {
userKeyIds = provisionRequest.getUserKeyPairIDs();
} else {
userKeyIds = provisionResponse.getCloudKeyPairIDs();
}
List<String> userKeyIds = provisionRequest.getUserKeyPairIDs();
if (userKeyIds != null && !userKeyIds.isEmpty()) { if (userKeyIds != null && !userKeyIds.isEmpty()) {
} else { } else {
userKeyIds = new ArrayList<>(); userKeyIds = new ArrayList<>();
...@@ -688,16 +748,16 @@ public class ProvisionService { ...@@ -688,16 +748,16 @@ public class ProvisionService {
provisionResponse.setDeployParameters(deployParameters); provisionResponse.setDeployParameters(deployParameters);
provisionResponse.setKvMap(kvMap); provisionResponse.setKvMap(kvMap);
if (provisionRequest != null) {
provisionResponse.setCloudCredentialsIDs(provisionRequest.getCloudCredentialsIDs()); provisionResponse.setCloudCredentialsIDs(provisionRequest.getCloudCredentialsIDs());
provisionResponse.setPlanID(provisionRequest.getPlanID());
}
provisionResponse.setUserKeyPairIDs(userKeyIds); provisionResponse.setUserKeyPairIDs(userKeyIds);
provisionResponse.setDeployerKeyPairIDs(deployerKeyIds); provisionResponse.setDeployerKeyPairIDs(deployerKeyIds);
provisionResponse.setPlanID(provisionRequest.getPlanID());
provisionResponse = save(provisionResponse); provisionResponse = save(provisionResponse);
return provisionResponse; return provisionResponse;
} }
private void parseDeleteResourcesResponse(List<MessageParameter> parameters, ProvisionResponse provisionInfo) { private void parseDeleteResourcesResponse(List<MessageParameter> parameters, ProvisionResponse provisionInfo) {
...@@ -705,5 +765,4 @@ public class ProvisionService { ...@@ -705,5 +765,4 @@ public class ProvisionService {
// System.err.println(p.getName() + " : " + p.getValue()); // System.err.println(p.getName() + " : " + p.getValue());
// } // }
} }
} }
...@@ -35,7 +35,6 @@ import nl.uva.sne.drip.api.service.DeployService; ...@@ -35,7 +35,6 @@ import nl.uva.sne.drip.api.service.DeployService;
import nl.uva.sne.drip.api.service.UserService; import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.drip.commons.data.v1.external.DeployRequest; import nl.uva.sne.drip.drip.commons.data.v1.external.DeployRequest;
import nl.uva.sne.drip.drip.commons.data.v1.external.DeployResponse; import nl.uva.sne.drip.drip.commons.data.v1.external.DeployResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.ScaleDeploymetRequest;
import nl.uva.sne.drip.drip.commons.data.v1.external.ScaleRequest; import nl.uva.sne.drip.drip.commons.data.v1.external.ScaleRequest;
import org.json.JSONException; import org.json.JSONException;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
...@@ -91,9 +90,8 @@ public class DeployController { ...@@ -91,9 +90,8 @@ public class DeployController {
@RequestMapping(value = "/scale", method = RequestMethod.POST) @RequestMapping(value = "/scale", method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN}) @RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody public @ResponseBody
String scaleDeployment(@RequestBody ScaleDeploymetRequest scaleRequest) { String scaleDeployment(@RequestBody ScaleRequest scaleRequest) {
try { try {
return deployService.scale(scaleRequest).getId(); return deployService.scale(scaleRequest).getId();
......
...@@ -37,6 +37,7 @@ import nl.uva.sne.drip.api.exception.NotFoundException; ...@@ -37,6 +37,7 @@ import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.service.ProvisionService; import nl.uva.sne.drip.api.service.ProvisionService;
import nl.uva.sne.drip.api.service.UserService; import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionResponse; import nl.uva.sne.drip.drip.commons.data.v1.external.ProvisionResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.ScaleRequest;
import org.json.JSONException; import org.json.JSONException;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
...@@ -188,6 +189,19 @@ public class ProvisionController { ...@@ -188,6 +189,19 @@ public class ProvisionController {
return resp.getId(); return resp.getId();
} }
@RequestMapping(value = "/scale", method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String scaleDeployment(@RequestBody ScaleRequest scaleRequest) {
try {
return provisionService.scale(scaleRequest).getId();
} catch (IOException | TimeoutException | JSONException ex) {
Logger.getLogger(ProvisionController.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(ProvisionController.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
@RequestMapping(value = "/sample", method = RequestMethod.GET) @RequestMapping(value = "/sample", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN}) @RolesAllowed({UserService.USER, UserService.ADMIN})
......
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