Commit 1c0b0780 authored by Spiros Koulouzis's avatar Spiros Koulouzis

added tests and get topology status

parent 41ce522b
...@@ -32,6 +32,7 @@ import java.util.logging.Logger; ...@@ -32,6 +32,7 @@ import java.util.logging.Logger;
import nl.uva.sne.drip.model.Exceptions.TypeExeption; import nl.uva.sne.drip.model.Exceptions.TypeExeption;
import nl.uva.sne.drip.model.NodeTemplate; import nl.uva.sne.drip.model.NodeTemplate;
import nl.uva.sne.drip.model.NodeTemplateMap; import nl.uva.sne.drip.model.NodeTemplateMap;
import nl.uva.sne.drip.model.cloud.storm.CloudsStormSubTopology;
import nl.uva.sne.drip.model.tosca.Credential; import nl.uva.sne.drip.model.tosca.Credential;
import nl.uva.sne.drip.model.tosca.ToscaTemplate; import nl.uva.sne.drip.model.tosca.ToscaTemplate;
import nl.uva.sne.drip.sure.tosca.client.DefaultApi; import nl.uva.sne.drip.sure.tosca.client.DefaultApi;
...@@ -261,4 +262,14 @@ public class ToscaHelper { ...@@ -261,4 +262,14 @@ public class ToscaHelper {
return "vm_user"; return "vm_user";
} }
public CloudsStormSubTopology.StatusEnum getVMTopologyTemplateStatus(NodeTemplateMap nodeTemplateMap) throws TypeExeption {
NodeTemplate nodeTemplate = nodeTemplateMap.getNodeTemplate();
if (nodeTemplate.getType().equals(VM_TOPOLOGY)) {
String status = (String) nodeTemplate.getAttributes().get("status");
return CloudsStormSubTopology.StatusEnum.fromValue(status);
} else {
throw new TypeExeption("NodeTemplateMap is not of type: " + VM_TOPOLOGY + " it is of type: " + nodeTemplate.getType());
}
}
} }
...@@ -17,7 +17,9 @@ import javax.servlet.http.HttpServletRequest; ...@@ -17,7 +17,9 @@ import javax.servlet.http.HttpServletRequest;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import nl.uva.sne.drip.model.Exceptions.TypeExeption;
import nl.uva.sne.drip.service.ToscaTemplateService; import nl.uva.sne.drip.service.ToscaTemplateService;
import nl.uva.sne.drip.sure.tosca.client.ApiException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-10-10T17:15:46.465Z") @javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-10-10T17:15:46.465Z")
...@@ -41,8 +43,13 @@ public class ToscaTemplateApiController implements ToscaTemplateApi { ...@@ -41,8 +43,13 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
public ResponseEntity<String> deleteToscaTemplateByID(@ApiParam(value = "ID of topolog template to return", required = true) @PathVariable("id") String id) { public ResponseEntity<String> deleteToscaTemplateByID(@ApiParam(value = "ID of topolog template to return", required = true) @PathVariable("id") String id) {
String accept = request.getHeader("Accept"); String accept = request.getHeader("Accept");
if (accept != null && accept.contains("*/*")) { if (accept != null && accept.contains("*/*")) {
try {
toscaTemplateService.deleteByID(id); toscaTemplateService.deleteByID(id);
return new ResponseEntity<>("", HttpStatus.OK); return new ResponseEntity<>("", HttpStatus.OK);
} catch (NotFoundException | IOException | ApiException | TypeExeption ex) {
java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.SEVERE, null, ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
} else { } else {
return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE); return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
} }
......
...@@ -19,6 +19,7 @@ import nl.uva.sne.drip.model.Exceptions.MissingCredentialsException; ...@@ -19,6 +19,7 @@ import nl.uva.sne.drip.model.Exceptions.MissingCredentialsException;
import nl.uva.sne.drip.model.Exceptions.TypeExeption; import nl.uva.sne.drip.model.Exceptions.TypeExeption;
import nl.uva.sne.drip.model.Message; import nl.uva.sne.drip.model.Message;
import nl.uva.sne.drip.model.NodeTemplateMap; import nl.uva.sne.drip.model.NodeTemplateMap;
import nl.uva.sne.drip.model.cloud.storm.CloudsStormSubTopology;
import nl.uva.sne.drip.model.tosca.Credential; import nl.uva.sne.drip.model.tosca.Credential;
import nl.uva.sne.drip.model.tosca.ToscaTemplate; import nl.uva.sne.drip.model.tosca.ToscaTemplate;
import nl.uva.sne.drip.rpc.DRIPCaller; import nl.uva.sne.drip.rpc.DRIPCaller;
...@@ -49,7 +50,14 @@ public class DRIPService { ...@@ -49,7 +50,14 @@ public class DRIPService {
@Autowired @Autowired
ProvisionerService provisionerService; ProvisionerService provisionerService;
private static final String OPERATION_PROVISION = "provision";
enum PROVISIONER_OPERATION {
PROVISION, DELETE, START, STOP, H_SCALE, V_SCALE, CONFIGURE
}
enum DELETE_ACTIONS {
PROVISION, DEPLOYMENT
}
private String execute(ToscaTemplate toscaTemplate) throws JsonProcessingException, ApiException, IOException, TimeoutException, InterruptedException { private String execute(ToscaTemplate toscaTemplate) throws JsonProcessingException, ApiException, IOException, TimeoutException, InterruptedException {
...@@ -115,22 +123,23 @@ public class DRIPService { ...@@ -115,22 +123,23 @@ public class DRIPService {
public String provision(String id) throws MissingCredentialsException, ApiException, TypeExeption, IOException, JsonProcessingException, TimeoutException, InterruptedException, NotFoundException { public String provision(String id) throws MissingCredentialsException, ApiException, TypeExeption, IOException, JsonProcessingException, TimeoutException, InterruptedException, NotFoundException {
ToscaTemplate toscaTemplate = initExecution(id); ToscaTemplate toscaTemplate = initExecution(id);
toscaTemplate = addCredentials(toscaTemplate); toscaTemplate = addCredentials(toscaTemplate);
toscaTemplate = setProvisionOperation(toscaTemplate, OPERATION_PROVISION); toscaTemplate = setProvisionerOperation(toscaTemplate, PROVISIONER_OPERATION.PROVISION);
return execute(toscaTemplate); return execute(toscaTemplate);
} }
private ToscaTemplate setProvisionOperation(ToscaTemplate toscaTemplate, String operation) throws IOException, JsonProcessingException, ApiException { private ToscaTemplate setProvisionerOperation(ToscaTemplate toscaTemplate, PROVISIONER_OPERATION operation) throws IOException, JsonProcessingException, ApiException {
List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates(); List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
for (NodeTemplateMap vmTopologyMap : vmTopologies) { for (NodeTemplateMap vmTopologyMap : vmTopologies) {
Map<String, Object> provisionerInterface = helper.getProvisionerInterfaceFromVMTopology(vmTopologyMap); Map<String, Object> provisionerInterface = helper.getProvisionerInterfaceFromVMTopology(vmTopologyMap);
if (!provisionerInterface.containsKey("provision")) { if (!provisionerInterface.containsKey(operation.toString().toLowerCase())) {
Map<String, Object> inputsMap = new HashMap<>(); throw new RuntimeException("Fix this code. We are adding wrong interfaces");
inputsMap.put(operation, caller); // Map<String, Object> inputsMap = new HashMap<>();
Map<String, Object> provisionMap = new HashMap<>(); // inputsMap.put(operation.toString().toLowerCase(), caller);
provisionMap.put("inputs", inputsMap); // Map<String, Object> provisionMap = new HashMap<>();
provisionerInterface.put(operation, caller); // provisionMap.put("inputs", inputsMap);
vmTopologyMap = helper.setProvisionerInterfaceInVMTopology(vmTopologyMap, provisionerInterface); // provisionerInterface.put(operation.toString().toLowerCase(), caller);
toscaTemplate = helper.setNodeInToscaTemplate(toscaTemplate, vmTopologyMap); // vmTopologyMap = helper.setProvisionerInterfaceInVMTopology(vmTopologyMap, provisionerInterface);
// toscaTemplate = helper.setNodeInToscaTemplate(toscaTemplate, vmTopologyMap);
} }
} }
return toscaTemplate; return toscaTemplate;
...@@ -158,4 +167,12 @@ public class DRIPService { ...@@ -158,4 +167,12 @@ public class DRIPService {
return toscaTemplate; return toscaTemplate;
} }
void deleteActions(ToscaTemplate toscaTemplate) throws ApiException, TypeExeption {
List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
for (NodeTemplateMap vmTopology : vmTopologies){
CloudsStormSubTopology.StatusEnum status = helper.getVMTopologyTemplateStatus(vmTopology);
}
}
} }
...@@ -14,9 +14,14 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature; ...@@ -14,9 +14,14 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.api.NotFoundException; import nl.uva.sne.drip.api.NotFoundException;
import nl.uva.sne.drip.dao.ToscaTemplateDAO; import nl.uva.sne.drip.dao.ToscaTemplateDAO;
import nl.uva.sne.drip.model.Exceptions.TypeExeption;
import nl.uva.sne.drip.model.tosca.ToscaTemplate; import nl.uva.sne.drip.model.tosca.ToscaTemplate;
import nl.uva.sne.drip.sure.tosca.client.ApiException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -39,6 +44,8 @@ public class ToscaTemplateService { ...@@ -39,6 +44,8 @@ public class ToscaTemplateService {
@Autowired @Autowired
private ToscaTemplateDAO dao; private ToscaTemplateDAO dao;
@Autowired
private DRIPService dripService;
public String save(ToscaTemplate tt) { public String save(ToscaTemplate tt) {
dao.save(tt); dao.save(tt);
...@@ -69,14 +76,16 @@ public class ToscaTemplateService { ...@@ -69,14 +76,16 @@ public class ToscaTemplateService {
public String findByID(String id) throws JsonProcessingException, NotFoundException { public String findByID(String id) throws JsonProcessingException, NotFoundException {
ToscaTemplate tt = dao.findById(id).get(); ToscaTemplate tt = dao.findById(id).get();
if(tt==null){ if (tt == null) {
throw new NotFoundException(404, "ToscaTemplate with id: "+id+" not found"); throw new NotFoundException(404, "ToscaTemplate with id: " + id + " not found");
} }
String ymlStr = objectMapper.writeValueAsString(tt); String ymlStr = objectMapper.writeValueAsString(tt);
return ymlStr; return ymlStr;
} }
public void deleteByID(String id) { public void deleteByID(String id) throws JsonProcessingException, NotFoundException, IOException, ApiException, TypeExeption {
ToscaTemplate toscaTemplate = getYaml2ToscaTemplate(findByID(id));
dripService.deleteActions(toscaTemplate);
dao.deleteById(id); dao.deleteById(id);
} }
......
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