Commit 03737f98 authored by Spiros Koulouzis's avatar Spiros Koulouzis

added interface type

parent ba498120
......@@ -111,13 +111,6 @@ node_types:
credential:
type: tosca.datatypes.Credential
required: false
status:
type: string
required: true
default: "fresh"
description: The state of this topology
constraints:
- valid_values: [ "fresh" , "running" ,"deleted", "failed", "stopped" ]
subnet:
type: string
required: false
......
......@@ -22,6 +22,9 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import nl.uva.sne.drip.model.TopologyTemplate;
import nl.uva.sne.drip.model.ToscaTemplate;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
/**
*
......@@ -29,9 +32,10 @@ import java.util.Set;
*/
public class TOSCAUtils {
public static List<Map<String, Object>> getVMsFromTopology(Map<String, Object> toscaPlan) {
List<String> vmNames = getVMsNodeNamesFromTopology(toscaPlan);
Map<String, Object> nodeTemplates = (Map<String, Object>) ((Map<String, Object>) toscaPlan.get("topology_template")).get("node_templates");
public static List<Map<String, Object>> getVMsFromTopology(ToscaTemplate toscaTemplate) {
List<String> vmNames = getVMsNodeNamesFromTopology(toscaTemplate);
TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate();
Map<String, Object> nodeTemplates = topologyTemplate.getNodeTemplates();
List<Map<String, Object>> vmList = new ArrayList<>();
for (String vmName : vmNames) {
Map<String, Object> vm = (Map<String, Object>) nodeTemplates.get(vmName);
......@@ -41,9 +45,11 @@ public class TOSCAUtils {
return vmList;
}
public static List<String> getVMsNodeNamesFromTopology(Map<String, Object> toscaPlan) {
Map<String, Object> topologyTemplate = (Map<String, Object>) toscaPlan.get("topology_template");
Map<String, Object> nodeTemplates = (Map<String, Object>) (topologyTemplate).get("node_templates");
public static List<String> getVMsNodeNamesFromTopology(ToscaTemplate toscaTemplate) {
TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate();
Map<String, Object> nodeTemplates = topologyTemplate.getNodeTemplates();
Iterator it = nodeTemplates.entrySet().iterator();
List<String> vmNames = new ArrayList<>();
while (it.hasNext()) {
......@@ -79,21 +85,13 @@ public class TOSCAUtils {
return outputs;
}
public static Map<String, String> getOutputsForNode(Map<String, Object> toscaProvisonMap, String nodeName) {
Map<String, Object> topologyTemplate = (Map<String, Object>) ((Map<String, Object>) toscaProvisonMap.get("topology_template"));
Map<String, Object> outputs = (Map<String, Object>) topologyTemplate.get("outputs");
Map<String, String> matchedOutputs = new HashMap<>();
Iterator it = outputs.entrySet().iterator();
while (it.hasNext()) {
Map.Entry output = (Map.Entry) it.next();
List<Map<String, String>> val = (List<Map<String, String>>) output.getValue();
for (Map<String, String> map : val) {
if (map.containsKey(nodeName)) {
matchedOutputs.put((String) output.getKey(), map.get(nodeName));
}
}
}
return matchedOutputs;
public static Map<String, String> getOutputsForNode(ToscaTemplate toscaTemplate, String nodeName) {
TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate();
List<Map<String, Object>> outputs = topologyTemplate.getOutputs();
List<Map<String, Object>> matchedOutputs = new ArrayList<>();
throw new NotImplementedException();
}
public static List<String> getOutputPair(Map<String, Object> outputs, String key) {
......@@ -101,9 +99,9 @@ public class TOSCAUtils {
return outputPair;
}
public static List<Map.Entry> getDockerContainers(Map<String, Object> toscaPlan) {
Map<String, Object> topologyTemplate = (Map<String, Object>) toscaPlan.get("topology_template");
Map<String, Object> nodeTemplates = (Map<String, Object>) (topologyTemplate).get("node_templates");
public static List<Map.Entry> getDockerContainers(ToscaTemplate toscaTemplate) {
TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate();
Map<String, Object> nodeTemplates = topologyTemplate.getNodeTemplates();
Iterator it = nodeTemplates.entrySet().iterator();
List<Map.Entry> dockerContainers = new ArrayList<>();
while (it.hasNext()) {
......@@ -117,8 +115,8 @@ public class TOSCAUtils {
return dockerContainers;
}
public static List<Map<String, Object>> tosca2KubernetesDeployment(Map<String, Object> toscaPlan) {
List<Map.Entry> dockerContainers = getDockerContainers(toscaPlan);
public static List<Map<String, Object>> tosca2KubernetesDeployment(ToscaTemplate toscaTemplate) {
List<Map.Entry> dockerContainers = getDockerContainers(toscaTemplate);
List<Map<String, Object>> deployments = new ArrayList<>();
Iterator<Map.Entry> dicIt = dockerContainers.iterator();
......@@ -162,8 +160,8 @@ public class TOSCAUtils {
return deployments;
}
public static List<Map<String, Object>> tosca2KubernetesService(Map<String, Object> toscaPlan) {
List<Map.Entry> dockerContainers = getDockerContainers(toscaPlan);
public static List<Map<String, Object>> tosca2KubernetesService(ToscaTemplate toscaTemplate) {
List<Map.Entry> dockerContainers = getDockerContainers(toscaTemplate);
List<Map<String, Object>> services = new ArrayList<>();
Iterator<Map.Entry> dicIt = dockerContainers.iterator();
while (dicIt.hasNext()) {
......
......@@ -11,7 +11,9 @@ import org.springframework.web.bind.annotation.PathVariable;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import nl.uva.sne.drip.service.DRIPService;
import nl.uva.sne.drip.service.ProvisionerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -26,10 +28,8 @@ public class ProvisionerApiController implements ProvisionerApi {
private final HttpServletRequest request;
@Value("${message.broker.queue.provisioner}")
private String queueName;
@Autowired
private DRIPService dripService;
private ProvisionerService provisionerService;
@org.springframework.beans.factory.annotation.Autowired
public ProvisionerApiController(ObjectMapper objectMapper, HttpServletRequest request) {
......@@ -39,13 +39,16 @@ public class ProvisionerApiController implements ProvisionerApi {
@Override
public ResponseEntity<String> provisionPlanToscaTemplateByID(
@ApiParam(value = "ID of topolog template to plan", required = true)
@ApiParam(value = "ID of topolog template to provision", required = true)
@PathVariable("id") String id) {
String accept = request.getHeader("Accept");
if (accept != null && accept.contains("text/plain")) {
dripService.setRequestQeueName(queueName);
String planedYemplateId = dripService.execute(id);
return new ResponseEntity<>(planedYemplateId, HttpStatus.NOT_IMPLEMENTED);
try {
String planedYemplateId = provisionerService.provision(id);
return new ResponseEntity<>(planedYemplateId, HttpStatus.OK);
} catch (IOException ex) {
java.util.logging.Logger.getLogger(ProvisionerApiController.class.getName()).log(Level.SEVERE, null, ex);
}
}
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package nl.uva.sne.drip.service;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.commons.utils.TOSCAUtils;
import nl.uva.sne.drip.model.Message;
import nl.uva.sne.drip.model.ToscaTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
*
* @author S. Koulouzis
*/
@Service
public class ProvisionerService {
@Value("${message.broker.queue.provisioner}")
private String queueName;
@Value("${tosca.types.interface}")
private String toscaTypesInterface;
@Autowired
private ToscaTemplateService toscaTemplateService;
public String provision(String id) throws IOException {
String ymlToscaTemplate = toscaTemplateService.findByID(id);
ToscaTemplate toscaTemplate = toscaTemplateService.getYaml2ToscaTemplate(ymlToscaTemplate);
TOSCAUtils.getVMsFromTopology(toscaTemplate);
return null;
}
}
......@@ -17,4 +17,7 @@ db.username=drip-user
db.password=drip-pass
spring.jackson.deserialization.UNWRAP_ROOT_VALUE=true
\ No newline at end of file
spring.jackson.deserialization.UNWRAP_ROOT_VALUE=true
tosca.types.interface=https://raw.githubusercontent.com/skoulouzis/DRIP/DRIP_3.0/TOSCA/interfaces/interface_types.yml
\ No newline at end of file
......@@ -25,8 +25,18 @@
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.9.3</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip-commons</artifactId>
<version>3.0.0</version>
<type>jar</type>
</dependency>
</dependencies>
......
......@@ -15,6 +15,8 @@
*/
package nl.uva.sne.drip.drip.provisioner;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
......@@ -25,6 +27,7 @@ import java.io.IOException;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.model.Message;
/**
*
......@@ -36,16 +39,15 @@ import java.util.logging.Logger;
public class Consumer extends DefaultConsumer {
private final Channel channel;
// Map<String, String> em = new HashMap<>();
private final Logger logger;
private final String messageBrokerHost;
private final ObjectMapper objectMapper;
public Consumer(Channel channel, String messageBrokerHost) throws IOException, TimeoutException {
public Consumer(Channel channel) throws IOException, TimeoutException {
super(channel);
this.channel = channel;
this.messageBrokerHost = messageBrokerHost;
logger = Logger.getLogger(Consumer.class.getName());
this.objectMapper = new ObjectMapper();
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}
@Override
......@@ -56,18 +58,15 @@ public class Consumer extends DefaultConsumer {
.correlationId(properties.getCorrelationId())
.build();
String response = "";
//The queue only moves bytes so we need to convert them to string
String message = new String(body, "UTF-8");
Message message = objectMapper.readValue(new String(body, "UTF-8"), Message.class);
String tempInputDirPath = System.getProperty("java.io.tmpdir") + File.separator + "Input-" + Long.toString(System.nanoTime()) + File.separator;
File tempInputDir = new File(tempInputDirPath);
if (!(tempInputDir.mkdirs())) {
throw new FileNotFoundException("Could not create input directory: " + tempInputDir.getAbsolutePath());
}
response = "response";
String response = objectMapper.writeValueAsString(message);
logger.log(Level.INFO, "Sending Response: '{'0'}'{0}", response);
// Logger.getLogger(Consumer.class.getName()).log(Level.INFO, "Sending Response: {0}", response);
......
......@@ -70,7 +70,7 @@ public class RPCServer {
//We define the queue name
channel.queueDeclare(prop.getProperty("message.broker.queue.provisioner", "provisioner"), false, false, false, null);
DefaultConsumer c;
c = new nl.uva.sne.drip.drip.provisioner.Consumer(channel, prop.getProperty("message.broker.host"));
c = new nl.uva.sne.drip.drip.provisioner.Consumer(channel);
//Start listening for messages
channel.basicConsume(prop.getProperty("message.broker.queue.provisioner", "provisioner"), false, c);
......
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