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

added interface type

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