Commit 111c45c0 authored by Spiros Koulouzis's avatar Spiros Koulouzis

added planner service

parent cf85aed9
...@@ -103,7 +103,7 @@ public abstract class DRIPCaller implements AutoCloseable { ...@@ -103,7 +103,7 @@ public abstract class DRIPCaller implements AutoCloseable {
.correlationId(corrId) .correlationId(corrId)
.replyTo(getReplyQueueName()) .replyTo(getReplyQueueName())
.build(); .build();
Logger.getLogger(DRIPCaller.class.getName()).log(Level.INFO, "Sending: " + jsonInString + " to queue: " + requestQeueName); Logger.getLogger(DRIPCaller.class.getName()).log(Level.INFO, "Sending: {0} to queue: {1}", new Object[]{jsonInString, requestQeueName});
getChannel().basicPublish("", requestQeueName, props, jsonInString.getBytes("UTF-8")); getChannel().basicPublish("", requestQeueName, props, jsonInString.getBytes("UTF-8"));
final BlockingQueue<String> response = new ArrayBlockingQueue(1); final BlockingQueue<String> response = new ArrayBlockingQueue(1);
......
...@@ -17,13 +17,6 @@ package nl.uva.sne.drip.drip.commons.data.internal; ...@@ -17,13 +17,6 @@ package nl.uva.sne.drip.drip.commons.data.internal;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
//import javax.persistence.Column;
//import javax.persistence.Entity;
//import javax.persistence.GeneratedValue;
//import javax.persistence.GenerationType;
//import javax.persistence.Id;
//import javax.persistence.Temporal;
//import javax.persistence.TemporalType;
/** /**
* *
......
...@@ -86,10 +86,8 @@ ...@@ -86,10 +86,8 @@
<type>jar</type> <type>jar</type>
</dependency> </dependency>
<dependency> <dependency>
<groupId>nl.uva.sne.drip</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>drip-commons</artifactId> <artifactId>spring-boot-starter-amqp</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency> </dependency>
<dependency> <dependency>
......
package nl.uva.sne.drip; package nl.uva.sne.drip;
import nl.uva.sne.drip.dao.ToscaTemplateDAO; import nl.uva.sne.drip.dao.ToscaTemplateDAO;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.ExitCodeGenerator; import org.springframework.boot.ExitCodeGenerator;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication @SpringBootApplication
@EnableSwagger2 @EnableSwagger2
@PropertySources({
@PropertySource(value = "classpath:application.properties", ignoreResourceNotFound = true)
})
@EnableMongoRepositories(basePackageClasses = {ToscaTemplateDAO.class}) @EnableMongoRepositories(basePackageClasses = {ToscaTemplateDAO.class})
@ComponentScan(basePackages = {"nl.uva.sne.drip", "nl.uva.sne.drip.api", "nl.uva.sne.drip.configuration", "nl.uva.sne.drip.dao", "nl.uva.sne.drip.model", "nl.uva.sne.drip.service"}) @ComponentScan(basePackages = {"nl.uva.sne.drip", "nl.uva.sne.drip.api",
"nl.uva.sne.drip.configuration", "nl.uva.sne.drip.dao", "nl.uva.sne.drip.model",
"nl.uva.sne.drip.service"})
public class Swagger2SpringBoot implements CommandLineRunner { public class Swagger2SpringBoot implements CommandLineRunner {
@Value("${message.broker.host}")
private String messageBrokerHost;
@Value("${message.broker.username}")
private String messageBrokerUsername;
@Value("${message.broker.password}")
private String messageBrokerPassword;
@Override @Override
public void run(String... arg0) throws Exception { public void run(String... arg0) throws Exception {
if (arg0.length > 0 && arg0[0].equals("exitcode")) { if (arg0.length > 0 && arg0[0].equals("exitcode")) {
...@@ -28,6 +43,7 @@ public class Swagger2SpringBoot implements CommandLineRunner { ...@@ -28,6 +43,7 @@ public class Swagger2SpringBoot implements CommandLineRunner {
} }
class ExitException extends RuntimeException implements ExitCodeGenerator { class ExitException extends RuntimeException implements ExitCodeGenerator {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override
......
...@@ -9,12 +9,9 @@ import org.springframework.http.ResponseEntity; ...@@ -9,12 +9,9 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
import nl.uva.sne.drip.service.PlannerService; import nl.uva.sne.drip.service.PlannerService;
import nl.uva.sne.drip.service.ToscaTemplateService;
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")
@Controller @Controller
public class PlannerApiController implements PlannerApi { public class PlannerApiController implements PlannerApi {
...@@ -29,9 +26,6 @@ public class PlannerApiController implements PlannerApi { ...@@ -29,9 +26,6 @@ public class PlannerApiController implements PlannerApi {
@Autowired @Autowired
private PlannerService plannerService; private PlannerService plannerService;
@Autowired
private ToscaTemplateService toscaTemplateService;
@org.springframework.beans.factory.annotation.Autowired @org.springframework.beans.factory.annotation.Autowired
public PlannerApiController(ObjectMapper objectMapper, HttpServletRequest request) { public PlannerApiController(ObjectMapper objectMapper, HttpServletRequest request) {
...@@ -41,18 +35,16 @@ public class PlannerApiController implements PlannerApi { ...@@ -41,18 +35,16 @@ public class PlannerApiController implements PlannerApi {
public ResponseEntity<String> planToscaTemplateByID(@ApiParam(value = "ID of topolog template to plan",required=true) @PathVariable("id") String id) { @Override
public ResponseEntity<String> planToscaTemplateByID(@ApiParam(
value = "ID of topolog template to plan",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("text/plain")) {
try { String planedYemplateId = plannerService.plan(id);
return new ResponseEntity<String>(objectMapper.readValue("", String.class), HttpStatus.NOT_IMPLEMENTED); return new ResponseEntity<>(planedYemplateId, HttpStatus.OK);
} catch (IOException e) {
log.error("Couldn't serialize response for content type ", e);
return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR);
}
} }
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
} }
} }
...@@ -32,8 +32,6 @@ import org.springframework.data.mongodb.repository.config.EnableMongoRepositorie ...@@ -32,8 +32,6 @@ import org.springframework.data.mongodb.repository.config.EnableMongoRepositorie
@EnableMongoRepositories(basePackages = "nl.uva.sne.drip.api") @EnableMongoRepositories(basePackages = "nl.uva.sne.drip.api")
@PropertySources({ @PropertySources({
@PropertySource(value = "classpath:application.properties", ignoreResourceNotFound = true) @PropertySource(value = "classpath:application.properties", ignoreResourceNotFound = true)
,
@PropertySource(value = "file:etc/application.properties", ignoreResourceNotFound = true)
}) })
@ComponentScan(basePackages = {"nl.uva.sne.drip", "nl.uva.sne.drip.api", "nl.uva.sne.drip.configuration", "nl.uva.sne.drip.dao", "nl.uva.sne.drip.model", "nl.uva.sne.drip.service"}) @ComponentScan(basePackages = {"nl.uva.sne.drip", "nl.uva.sne.drip.api", "nl.uva.sne.drip.configuration", "nl.uva.sne.drip.dao", "nl.uva.sne.drip.model", "nl.uva.sne.drip.service"})
public class MongoConfig extends AbstractMongoConfiguration { public class MongoConfig extends AbstractMongoConfiguration {
......
/*
* 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.configuration;
import com.rabbitmq.client.ConnectionFactory;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import nl.uva.sne.drip.rpc.PlannerCaller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
*
* @author S. Koulouzis
*/
@Configuration
public class RPCCallersConfig {
@Autowired
ConnectionFactory factory;
}
/*
* 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.configuration;
import com.rabbitmq.client.ConnectionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
*
* @author S. Koulouzis
*/
@Configuration
public class RabbitMQConfig {
@Value("${message.broker.host}")
private String messageBrokerHost;
@Value("${message.broker.username}")
private String messageBrokerUsername;
@Value("${message.broker.password}")
private String messageBrokerPassword;
@Bean
public ConnectionFactory connectionFactory() {
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.setHost(messageBrokerHost);
connectionFactory.setUsername(messageBrokerUsername);
connectionFactory.setPassword(messageBrokerPassword);
return connectionFactory;
}
}
/*
* Copyright 2017 S. Koulouzis.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.model;
import java.io.Serializable;
import java.util.List;
/**
*
*
*
* @author S. Koulouzis.
*/
public class Message implements Serializable {
private String owner;
private Long creationDate;
private List<MessageParameter> parameters;
private ToscaTemplate toscaTemplate;
public Long getCreationDate() {
return this.creationDate;
}
public void setParameters(List<MessageParameter> parameters) {
this.parameters = parameters;
}
public List<MessageParameter> getParameters() {
return this.parameters;
}
public void setCreationDate(Long creationDate) {
this.creationDate = creationDate;
}
/**
* @return the owner
*/
public String getOwner() {
return owner;
}
/**
* @param owner the owner to set
*/
public void setOwner(String owner) {
this.owner = owner;
}
/**
* @return the toscaTemplate
*/
public ToscaTemplate getToscaTemplate() {
return toscaTemplate;
}
/**
* @param toscaTemplate the toscaTemplate to set
*/
public void setToscaTemplate(ToscaTemplate toscaTemplate) {
this.toscaTemplate = toscaTemplate;
}
}
/*
* Copyright 2017 S. Koulouzis.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.model;
import java.io.Serializable;
import java.util.Map;
/**
*
* @author S. Koulouzis.
*/
public class MessageParameter implements Serializable {
private String url;
private String encoding;
private String value;
private String name;
private Map<String, String> attributes;
public static final String NAME = "name";
public static final String URL = "url";
public static final String VALUE = "value";
public static final String ENCODING = "encoding";
public static final String TOSCA_TEMPLATE = "tosca_template";
public String getURL() {
return this.url;
}
public void setURL(String url) {
this.url = url;
}
public String getEncoding() {
return this.encoding;
}
public void setEncoding(String encoding) {
this.encoding = encoding;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
/**
* @return the attributes
*/
public Map<String, String> getAttributes() {
return attributes;
}
/**
* @param attributes the attributes to set
*/
public void setAttributes(Map<String, String> attributes) {
this.attributes = attributes;
}
}
...@@ -19,6 +19,7 @@ import org.springframework.data.annotation.Id; ...@@ -19,6 +19,7 @@ import org.springframework.data.annotation.Id;
*/ */
@Validated @Validated
@JsonInclude(Include.NON_NULL) @JsonInclude(Include.NON_NULL)
public class ToscaTemplate { public class ToscaTemplate {
@Id @Id
......
package nl.uva.sne.drip.rpc;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.model.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*
* @author S. Koulouzis
*/
public abstract class DRIPCaller implements AutoCloseable {
private final Connection connection;
private final Channel channel;
private final String replyQueueName;
private final String requestQeueName;
private final ObjectMapper mapper;
public DRIPCaller(String requestQeueName, ConnectionFactory factory) throws IOException, TimeoutException {
// factory.setHost(messageBrokerHost);
// factory.setPort(AMQP.PROTOCOL.PORT);
// factory.setUsername(username);
// factory.setPassword(password);
connection = factory.newConnection();
channel = connection.createChannel();
// create a single callback queue per client not per requests.
replyQueueName = channel.queueDeclare().getQueue();
this.requestQeueName = requestQeueName;
this.mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
}
/**
* @return the connection
*/
public Connection getConnection() {
return connection;
}
/**
* @return the channel
*/
public Channel getChannel() {
return channel;
}
/**
* @return the replyQueueName
*/
public String getReplyQueueName() {
return replyQueueName;
}
@Override
public void close() throws IOException, TimeoutException {
if (channel != null && channel.isOpen()) {
channel.close();
}
if (connection != null && connection.isOpen()) {
connection.close();
}
}
public Message call(Message r) throws IOException, TimeoutException, InterruptedException {
String jsonInString = mapper.writeValueAsString(r);
//Build a correlation ID to distinguish responds
final String corrId = UUID.randomUUID().toString();
AMQP.BasicProperties props = new AMQP.BasicProperties.Builder()
.correlationId(corrId)
.replyTo(getReplyQueueName())
.build();
Logger.getLogger(DRIPCaller.class.getName()).log(Level.INFO, "Sending: {0} to queue: {1}", new Object[]{jsonInString, requestQeueName});
getChannel().basicPublish("", requestQeueName, props, jsonInString.getBytes("UTF-8"));
final BlockingQueue<String> response = new ArrayBlockingQueue(1);
getChannel().basicConsume(getReplyQueueName(), true, new DefaultConsumer(getChannel()) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
if (properties.getCorrelationId().equals(corrId)) {
response.offer(new String(body, "UTF-8"));
}
}
});
String resp = response.take();
Logger.getLogger(DRIPCaller.class.getName()).log(Level.INFO, "Got: {0}", resp);
return mapper.readValue(resp, Message.class);
}
}
/*
* Copyright 2017 S. Koulouzis.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.rpc;
import com.rabbitmq.client.ConnectionFactory;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
*
* @author S. Koulouzis.
*/
@Component
public class PlannerCaller extends DRIPCaller {
private static final String REQUEST_QUEUE_NAME = "planner_queue";
@Autowired
ConnectionFactory factory;
@Autowired
public PlannerCaller(ConnectionFactory factory) throws IOException, TimeoutException {
super(REQUEST_QUEUE_NAME, factory);
}
}
...@@ -6,10 +6,6 @@ ...@@ -6,10 +6,6 @@
package nl.uva.sne.drip.service; package nl.uva.sne.drip.service;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
......
...@@ -5,10 +5,58 @@ ...@@ -5,10 +5,58 @@
*/ */
package nl.uva.sne.drip.service; package nl.uva.sne.drip.service;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.model.Message;
import nl.uva.sne.drip.model.MessageParameter;
import nl.uva.sne.drip.model.ToscaTemplate;
import nl.uva.sne.drip.rpc.DRIPCaller;
import nl.uva.sne.drip.rpc.PlannerCaller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/** /**
* *
* @author S. Koulouzis * @author S. Koulouzis
*/ */
@Service
public class PlannerService { public class PlannerService {
@Autowired
private ToscaTemplateService toscaTemplateService;
@Autowired
PlannerCaller plannerCaller;
public String plan(String id) {
try {
String ymlToscaTemplate = toscaTemplateService.findByID(id);
ToscaTemplate toscaTemplate = toscaTemplateService.getYaml2ToscaTemplate(ymlToscaTemplate);
Message message = new Message();
message.setCreationDate(System.currentTimeMillis());
message.setToscaTemplate(toscaTemplate);
Message plannerResponse = plannerCaller.call(message);
ToscaTemplate plannedToscaTemplate = plannerResponse.getToscaTemplate();
return toscaTemplateService.save(plannedToscaTemplate);
} catch (IOException | TimeoutException | InterruptedException ex) {
Logger.getLogger(PlannerService.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
plannerCaller.close();
} catch (IOException | TimeoutException ex) {
Logger.getLogger(PlannerService.class.getName()).log(Level.SEVERE, null, ex);
}
}
return null;
}
} }
...@@ -44,7 +44,6 @@ public class ToscaTemplateService { ...@@ -44,7 +44,6 @@ public class ToscaTemplateService {
} }
public String saveFile(MultipartFile file) throws IOException, ApiException { public String saveFile(MultipartFile file) throws IOException, ApiException {
String originalFileName = file.getOriginalFilename(); String originalFileName = file.getOriginalFilename();
String name = System.currentTimeMillis() + "_" + originalFileName; String name = System.currentTimeMillis() + "_" + originalFileName;
byte[] bytes = file.getBytes(); byte[] bytes = file.getBytes();
...@@ -88,6 +87,9 @@ public class ToscaTemplateService { ...@@ -88,6 +87,9 @@ public class ToscaTemplateService {
void deleteAll() { void deleteAll() {
dao.deleteAll(); dao.deleteAll();
} }
public ToscaTemplate getYaml2ToscaTemplate(String ymlStr) throws IOException {
return objectMapper.readValue(ymlStr, ToscaTemplate.class);
}
} }
...@@ -5,6 +5,9 @@ spring.jackson.date-format=nl.uva.sne.drip.RFC3339DateFormat ...@@ -5,6 +5,9 @@ spring.jackson.date-format=nl.uva.sne.drip.RFC3339DateFormat
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
message.broker.host=127.0.0.1 message.broker.host=127.0.0.1
message.broker.username=guest
message.broker.password=guest
db.host=127.0.0.1 db.host=127.0.0.1
db.name=drip db.name=drip
db.username=drip-user db.username=drip-user
......
...@@ -2,30 +2,22 @@ ...@@ -2,30 +2,22 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment="slolved cap error"> <list default="true" id="462ede19-adfe-472b-975e-fefefa973fe0" name="Default Changelist" comment="slolved cap error">
<change beforePath="$PROJECT_DIR$/../docs/NOTES" beforeDir="false" afterPath="$PROJECT_DIR$/../docs/NOTES" afterDir="false" /> <change afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/Message.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/nb-configuration.xml" beforeDir="false" /> <change afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/MessageParameter.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/rpc/DRIPCaller.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/rpc/PlannerCaller.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/rpc/DRIPCaller.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-api/src/main/java/nl/uva/sne/drip/api/rpc/DRIPCaller.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/data/internal/Message.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-commons/src/main/java/nl/uva/sne/drip/drip/commons/data/internal/Message.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/pom.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../drip-manager/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/pom.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/Swagger2SpringBoot.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/Swagger2SpringBoot.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/Swagger2SpringBoot.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/Swagger2SpringBoot.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/ApiException.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/ApiException.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/PlannerApiController.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/PlannerApiController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/ApiOriginFilter.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/ApiOriginFilter.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/ApiResponseMessage.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/ApiResponseMessage.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/NotFoundException.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/NotFoundException.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/TopologTemplateApi.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/TopologTemplateApiController.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/UserApi.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/UserApi.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/UserApiController.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/api/UserApiController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/configuration/CustomInstantDeserializer.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/configuration/CustomInstantDeserializer.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/configuration/MongoConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/configuration/MongoConfig.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/configuration/MongoConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/configuration/MongoConfig.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/configuration/SwaggerDocumentationConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/configuration/SwaggerDocumentationConfig.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/service/CredentialService.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/service/CredentialService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/dao/TopologTemplateDAO.java" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/service/PlannerService.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/service/PlannerService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/NodeTemplate.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/NodeTemplate.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/service/ToscaTemplateService.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/service/ToscaTemplateService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/TopologyTemplate.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/TopologyTemplate.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../drip-manager/src/main/resources/application.properties" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/resources/application.properties" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/ToscaTemplate.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/ToscaTemplate.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/User.java" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/model/User.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/src/main/java/nl/uva/sne/drip/service/TopologTemplateService.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../drip-manager/swagger.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/../drip-manager/swagger.yaml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/setuptools-40.8.0-py3.6.egg" beforeDir="false" afterPath="$PROJECT_DIR$/venv/lib/python3.6/site-packages/setuptools-40.8.0-py3.6.egg" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/rpc_server.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/rpc_server.py" afterDir="false" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
...@@ -111,7 +103,7 @@ ...@@ -111,7 +103,7 @@
<option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/src/rpc_server.py" /> <option name="SCRIPT_NAME" value="$PROJECT_DIR$/src/rpc_server.py" />
<option name="PARAMETERS" value="test_local" /> <option name="PARAMETERS" value="localhost planner_queue" />
<option name="SHOW_COMMAND_LINE" value="false" /> <option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" /> <option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" /> <option name="MODULE_MODE" value="false" />
...@@ -228,6 +220,11 @@ ...@@ -228,6 +220,11 @@
<line>64</line> <line>64</line>
<option name="timeStamp" value="1" /> <option name="timeStamp" value="1" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/src/rpc_server.py</url>
<line>95</line>
<option name="timeStamp" value="11" />
</line-breakpoint>
</breakpoints> </breakpoints>
<default-breakpoints> <default-breakpoints>
<breakpoint type="python-exception"> <breakpoint type="python-exception">
......
...@@ -7,6 +7,8 @@ import logging ...@@ -7,6 +7,8 @@ import logging
import os import os
import os.path import os.path
from builtins import print from builtins import print
import yaml
from planner.basic_planner import * from planner.basic_planner import *
from planner.planner import * from planner.planner import *
import pika import pika
...@@ -18,13 +20,15 @@ import base64 ...@@ -18,13 +20,15 @@ import base64
from utils import tosca as tosca_util from utils import tosca as tosca_util
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
# if not getattr(logger, 'handler_set', None): # if not getattr(logger, 'handler_set', None):
# logger.setLevel(logging.INFO) # logger.setLevel(logging.INFO)
# h = logging.StreamHandler() # h = logging.StreamHandler()
# formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') # formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# h.setFormatter(formatter) # h.setFormatter(formatter)
# logger.addHandler(h) # logger.addHandler(h)
# logger.handler_set = True # logger.handler_set = True
def init_chanel(args): def init_chanel(args):
...@@ -41,12 +45,11 @@ def init_chanel(args): ...@@ -41,12 +45,11 @@ def init_chanel(args):
return channel return channel
def start(channel): def start(this_channel):
channel.basic_qos(prefetch_count=1) this_channel.basic_qos(prefetch_count=1)
channel.basic_consume(on_request, queue=queue_name) this_channel.basic_consume(queue=queue_name, on_message_callback=on_request)
logger.info(" [x] Awaiting RPC requests") logger.info(" [x] Awaiting RPC requests")
channel.start_consuming() this_channel.start_consuming()
def on_request(ch, method, props, body): def on_request(ch, method, props, body):
...@@ -61,77 +64,63 @@ def on_request(ch, method, props, body): ...@@ -61,77 +64,63 @@ def on_request(ch, method, props, body):
def handle_delivery(message): def handle_delivery(message):
logger.info("Got: "+str(message)) logger.info("Got: " + str(message))
try: try:
message = message.decode() message = message.decode()
except (UnicodeDecodeError, AttributeError): except (UnicodeDecodeError, AttributeError):
pass pass
parsed_json_message = json.loads(message) parsed_json_message = json.loads(message)
params = parsed_json_message["parameters"]
owner = parsed_json_message['owner'] owner = parsed_json_message['owner']
tosca_value = {} tosca_file_name = 'tosca_template'
tosca_file_name = '' tosca_template_json = parsed_json_message['toscaTemplate']
max_vms = -1
for param in params: input_current_milli_time = lambda: int(round(time.time() * 1000))
value = param['value']
name = param["name"] # rabbit = DRIPLoggingHandler(host=rabbitmq_host, port=5672, user=owner)
if name == 'tosca_input': # logger.addHandler(rabbit)
tosca_value = json.loads(value)
tosca_file_name = name
if name == 'max_vm':
max_vms = int(value)
current_milli_time = lambda: int(round(time.time() * 1000))
#rabbit = DRIPLoggingHandler(host=rabbitmq_host, port=5672, user=owner)
#logger.addHandler(rabbit)
try: try:
tosca_file_path = tempfile.gettempdir() + "/planner_files/" + str(current_milli_time()) + "/" tosca_folder_path = os.path.join(tempfile.gettempdir(), "planner_files", str(input_current_milli_time()))
except NameError: except NameError:
import sys import sys
tosca_file_path = os.path.dirname(os.path.abspath(sys.argv[0])) + "/planner_files/" + str( tosca_folder_path = os.path.dirname(os.path.abspath(sys.argv[0])) + os.path.join(tempfile.gettempdir(),
current_milli_time()) + "/" "planner_files",
str(current_milli_time()))
if not os.path.exists(tosca_file_path):
os.makedirs(tosca_file_path) if not os.path.exists(tosca_folder_path):
with open(tosca_file_path + "/" + tosca_file_name + ".yml", 'w') as outfile: os.makedirs(tosca_folder_path)
outfile.write(json.dumps(tosca_value)) input_tosca_file_path = os.path.join(tosca_folder_path, tosca_file_name + ".yml")
with open(input_tosca_file_path, 'w') as outfile:
response = {} outfile.write(yaml.dump(tosca_template_json))
current_milli_time = lambda: int(round(time.time() * 1000))
response["creationDate"] = current_milli_time() planner = Planner(input_tosca_file_path)
required_nodes = planner.resolve_requirements()
required_nodes = planner.set_infrastructure_specifications(required_nodes)
planner.add_required_nodes_to_template(required_nodes)
planned_template = tosca_util.get_tosca_template_as_yml(planner.template)
logger.info("template ----: \n" + planned_template)
template_dict = yaml.load(planned_template)
response = {'toscaTemplate': template_dict}
output_current_milli_time = lambda: int(round(time.time() * 1000))
response["creationDate"] = output_current_milli_time
response["parameters"] = [] response["parameters"] = []
if queue_name == "planner_queue": if queue_name == "planner_queue":
planner = BasicPlanner(tosca_file_path + "/" + tosca_file_name + ".yml") logger.info("Planning")
plan = planner.get_plan()
parameter = {}
encodedBytes = base64.b64encode(plan.encode("utf-8"))
encodedStr = str(encodedBytes, "utf-8")
parameter['value'] = encodedStr
parameter['name'] = 'tosca_plan'
parameter['encoding'] = 'UTF-8'
response["parameters"].append(parameter)
logger.info("Returning plan") logger.info("Returning plan")
logger.info("Output message:" + json.dumps(response)) logger.info("Output message:" + json.dumps(response))
return json.dumps(response) return json.dumps(response)
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
if (sys.argv[1] == "test_local"): if sys.argv[1] == "test_local":
# home = expanduser("~")
# tosca_reposetory_api_base_url = "http://localhost:8080/winery"
# namespace = "http%253A%252F%252Fsne.uva.nl%252Fservicetemplates"
# servicetemplate_id = "wordpress_w1-wip1"
# planner = WineryPlanner(tosca_reposetory_api_base_url,namespace,servicetemplate_id)
tosca_file_path = "../../TOSCA/application_example.yaml" tosca_file_path = "../../TOSCA/application_example.yaml"
# planner = BasicPlanner(tosca_file_path) # planner = BasicPlanner(tosca_file_path)
planner = Planner(tosca_file_path) test_planner = Planner(tosca_file_path)
required_nodes = planner.resolve_requirements() test_planner_required_nodes = test_planner.resolve_requirements()
required_nodes = planner.set_infrastructure_specifications(required_nodes) test_planner_required_nodes = test_planner.set_infrastructure_specifications(test_planner_required_nodes)
planner.add_required_nodes_to_template(required_nodes) test_planner.add_required_nodes_to_template(test_planner_required_nodes)
template = tosca_util.get_tosca_template_as_yml(planner.template) template = tosca_util.get_tosca_template_as_yml(test_planner.template)
logger.info("template ----: \n" + template) logger.info("template ----: \n" + template)
else: else:
logger.info("Input args: " + sys.argv[0] + ' ' + sys.argv[1] + ' ' + sys.argv[2]) logger.info("Input args: " + sys.argv[0] + ' ' + sys.argv[1] + ' ' + sys.argv[2])
......
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