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;
import nl.uva.sne.drip.model.Exceptions.TypeExeption;
import nl.uva.sne.drip.model.NodeTemplate;
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.ToscaTemplate;
import nl.uva.sne.drip.sure.tosca.client.DefaultApi;
......@@ -261,4 +262,14 @@ public class ToscaHelper {
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;
import java.io.IOException;
import java.util.List;
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.sure.tosca.client.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
@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 {
public ResponseEntity<String> deleteToscaTemplateByID(@ApiParam(value = "ID of topolog template to return", required = true) @PathVariable("id") String id) {
String accept = request.getHeader("Accept");
if (accept != null && accept.contains("*/*")) {
toscaTemplateService.deleteByID(id);
return new ResponseEntity<>("", HttpStatus.OK);
try {
toscaTemplateService.deleteByID(id);
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 {
return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
}
......
......@@ -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.Message;
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.ToscaTemplate;
import nl.uva.sne.drip.rpc.DRIPCaller;
......@@ -49,7 +50,14 @@ public class DRIPService {
@Autowired
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 {
......@@ -115,22 +123,23 @@ public class DRIPService {
public String provision(String id) throws MissingCredentialsException, ApiException, TypeExeption, IOException, JsonProcessingException, TimeoutException, InterruptedException, NotFoundException {
ToscaTemplate toscaTemplate = initExecution(id);
toscaTemplate = addCredentials(toscaTemplate);
toscaTemplate = setProvisionOperation(toscaTemplate, OPERATION_PROVISION);
toscaTemplate = setProvisionerOperation(toscaTemplate, PROVISIONER_OPERATION.PROVISION);
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();
for (NodeTemplateMap vmTopologyMap : vmTopologies) {
Map<String, Object> provisionerInterface = helper.getProvisionerInterfaceFromVMTopology(vmTopologyMap);
if (!provisionerInterface.containsKey("provision")) {
Map<String, Object> inputsMap = new HashMap<>();
inputsMap.put(operation, caller);
Map<String, Object> provisionMap = new HashMap<>();
provisionMap.put("inputs", inputsMap);
provisionerInterface.put(operation, caller);
vmTopologyMap = helper.setProvisionerInterfaceInVMTopology(vmTopologyMap, provisionerInterface);
toscaTemplate = helper.setNodeInToscaTemplate(toscaTemplate, vmTopologyMap);
if (!provisionerInterface.containsKey(operation.toString().toLowerCase())) {
throw new RuntimeException("Fix this code. We are adding wrong interfaces");
// Map<String, Object> inputsMap = new HashMap<>();
// inputsMap.put(operation.toString().toLowerCase(), caller);
// Map<String, Object> provisionMap = new HashMap<>();
// provisionMap.put("inputs", inputsMap);
// provisionerInterface.put(operation.toString().toLowerCase(), caller);
// vmTopologyMap = helper.setProvisionerInterfaceInVMTopology(vmTopologyMap, provisionerInterface);
// toscaTemplate = helper.setNodeInToscaTemplate(toscaTemplate, vmTopologyMap);
}
}
return toscaTemplate;
......@@ -150,7 +159,7 @@ public class DRIPService {
return execute(toscaTemplate);
}
private ToscaTemplate initExecution(String id) throws JsonProcessingException, NotFoundException, IOException, ApiException {
private ToscaTemplate initExecution(String id) throws JsonProcessingException, NotFoundException, IOException, ApiException {
String ymlToscaTemplate = toscaTemplateService.findByID(id);
Logger.getLogger(DRIPService.class.getName()).log(Level.FINE, "Found ToscaTemplate with id: {0}", id);
ToscaTemplate toscaTemplate = toscaTemplateService.getYaml2ToscaTemplate(ymlToscaTemplate);
......@@ -158,4 +167,12 @@ public class DRIPService {
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;
import java.io.IOException;
import java.util.ArrayList;
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.dao.ToscaTemplateDAO;
import nl.uva.sne.drip.model.Exceptions.TypeExeption;
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.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
......@@ -39,6 +44,8 @@ public class ToscaTemplateService {
@Autowired
private ToscaTemplateDAO dao;
@Autowired
private DRIPService dripService;
public String save(ToscaTemplate tt) {
dao.save(tt);
......@@ -69,14 +76,16 @@ public class ToscaTemplateService {
public String findByID(String id) throws JsonProcessingException, NotFoundException {
ToscaTemplate tt = dao.findById(id).get();
if(tt==null){
throw new NotFoundException(404, "ToscaTemplate with id: "+id+" not found");
if (tt == null) {
throw new NotFoundException(404, "ToscaTemplate with id: " + id + " not found");
}
String ymlStr = objectMapper.writeValueAsString(tt);
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);
}
......
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