Commit a5bb42ce authored by Spiros Koulouzis's avatar Spiros Koulouzis

implemented message for drip componets

implmented example planner 
parent 92988cd0
/drip-commons/target/ /drip-commons/target/
/drip-api/target/ /drip-api/target/
\ No newline at end of file /drip-planner/target/
\ No newline at end of file
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
*/ */
package nl.uva.sne.drip.api.rest; package nl.uva.sne.drip.api.rest;
import nl.uva.sne.drip.commons.types.FileParameter;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import nl.uva.sne.drip.api.rpc.Planner; import nl.uva.sne.drip.api.rpc.PlannerCaller;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -28,25 +28,16 @@ import java.util.List; ...@@ -28,25 +28,16 @@ import java.util.List;
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 javax.annotation.security.RolesAllowed; import nl.uva.sne.drip.commons.types.Message;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import nl.uva.sne.drip.commons.types.IRequest;
import nl.uva.sne.drip.commons.types.Request;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import nl.uva.sne.drip.commons.types.IMessage;
/** /**
* *
...@@ -71,22 +62,33 @@ public class UploadToscaController { ...@@ -71,22 +62,33 @@ public class UploadToscaController {
try { try {
String originalFileName = file.getOriginalFilename(); String originalFileName = file.getOriginalFilename();
String name = originalFileName + System.currentTimeMillis(); String name = System.currentTimeMillis() + "_" + originalFileName;
File targetToscaFile = new File(inputToscaFolderPath + File.separator + name); // File targetToscaFile = new File(inputToscaFolderPath + File.separator + name);
file.transferTo(targetToscaFile); // file.transferTo(targetToscaFile);
Planner planner = new Planner(messageBrokerHost); Message invokationMessage = new Message();
Request r = new Request(); List parameters = new ArrayList();
List args = new ArrayList(); FileParameter fileArgument = new FileParameter();
FileArgument fileArg = new FileArgument(); byte[] bytes = file.getBytes();//Files.readAllBytes(Paths.get(targetToscaFile.getAbsolutePath()));
fileArg.setURL(targetToscaFile.toURI().toString()); String charset = "UTF-8";
args.add(targetToscaFile); fileArgument.setValue(new String(bytes, charset));
r.setArguments(args); fileArgument.setEncoding(charset);
r.setCreationDate(new Date(System.currentTimeMillis())); fileArgument.setName(name);
r.setStatus(IRequest.Status.SUCCESS); parameters.add(fileArgument);
String returned = planner.plan(r); fileArgument = new FileParameter();
bytes = Files.readAllBytes(Paths.get("/home/alogo/Downloads/DRIP/example_a.yml"));
fileArgument.setValue(new String(bytes, charset));
fileArgument.setEncoding(charset);
fileArgument.setName("example_a.yml");
parameters.add(fileArgument);
invokationMessage.setParameters(parameters);
invokationMessage.setCreationDate(new Date(System.currentTimeMillis()));
PlannerCaller planner = new PlannerCaller(messageBrokerHost);
String returned = planner.plan(invokationMessage);
planner.close(); planner.close();
return "You successfully uploaded " + name + " into " + name + "-uploaded !"; return "You successfully uploaded " + name + " into " + name + "-uploaded !";
...@@ -98,26 +100,25 @@ public class UploadToscaController { ...@@ -98,26 +100,25 @@ public class UploadToscaController {
} }
@RequestMapping(value = "/args", method = RequestMethod.GET) @RequestMapping(value = "/args", method = RequestMethod.GET)
public Request args() { public Message args() {
try { try {
Request r = new Request(); Message r = new Message();
List args = new ArrayList(); List args = new ArrayList();
args.add(1); args.add(1);
args.add("str"); args.add("str");
FileArgument targetToscaFile = new FileArgument(); FileParameter targetToscaFile = new FileParameter();
byte[] bytes = Files.readAllBytes(Paths.get("/home/alogo/Downloads/planner_output_all.yml")); byte[] bytes = Files.readAllBytes(Paths.get("/home/alogo/Downloads/planner_output_all.yml"));
targetToscaFile.setContents(new String(bytes, "UTF-8")); targetToscaFile.setValue(new String(bytes, "UTF-8"));
targetToscaFile.setName("planner_output_all.yml");
targetToscaFile.setEncoding("UTF-8"); targetToscaFile.setEncoding("UTF-8");
args.add(targetToscaFile); args.add(targetToscaFile);
r.setArguments(args); r.setParameters(args);
r.setCreationDate(new Date(System.currentTimeMillis())); r.setCreationDate(new Date(System.currentTimeMillis()));
r.setStatus(IRequest.Status.SUCCESS);
ObjectMapper mapper = new ObjectMapper();
String jsonInString = mapper.writeValueAsString(r);
System.err.println(jsonInString);
// ObjectMapper mapper = new ObjectMapper();
// String jsonInString = mapper.writeValueAsString(r);
// System.err.println(jsonInString);
return r; return r;
} catch (IOException ex) { } catch (IOException ex) {
Logger.getLogger(UploadToscaController.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(UploadToscaController.class.getName()).log(Level.SEVERE, null, ex);
......
...@@ -19,9 +19,9 @@ package nl.uva.sne.drip.api.rpc; ...@@ -19,9 +19,9 @@ package nl.uva.sne.drip.api.rpc;
* *
* @author S. Koulouzis. * @author S. Koulouzis.
*/ */
class DRIPComponent { class DRIPComponentCaller {
public DRIPComponent(){ public DRIPComponentCaller(){
} }
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
package nl.uva.sne.drip.api.rpc; package nl.uva.sne.drip.api.rpc;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import com.rabbitmq.client.AMQP; import com.rabbitmq.client.AMQP;
...@@ -25,27 +24,24 @@ import com.rabbitmq.client.Connection; ...@@ -25,27 +24,24 @@ import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory; import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DefaultConsumer; import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope; import com.rabbitmq.client.Envelope;
import com.rabbitmq.client.RpcClient;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import nl.uva.sne.drip.commons.types.Request; import nl.uva.sne.drip.commons.types.Message;
/** /**
* *
* @author S. Koulouzis. * @author S. Koulouzis.
*/ */
public class Planner { public class PlannerCaller {
private static final String REQUEST_QUEUE_NAME = "planner_queue"; private static final String REQUEST_QUEUE_NAME = "planner_queue";
private final Connection connection; private final Connection connection;
private final Channel channel; private final Channel channel;
private final String replyQueueName; private final String replyQueueName;
public Planner(String messageBrokerHost) throws IOException, TimeoutException { public PlannerCaller(String messageBrokerHost) throws IOException, TimeoutException {
ConnectionFactory factory = new ConnectionFactory(); ConnectionFactory factory = new ConnectionFactory();
factory.setHost(messageBrokerHost); factory.setHost(messageBrokerHost);
...@@ -59,7 +55,7 @@ public class Planner { ...@@ -59,7 +55,7 @@ public class Planner {
replyQueueName = channel.queueDeclare().getQueue(); replyQueueName = channel.queueDeclare().getQueue();
} }
public String plan(Request r) throws IOException, TimeoutException, InterruptedException { public String plan(Message r) throws IOException, TimeoutException, InterruptedException {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
String jsonInString = mapper.writeValueAsString(r); String jsonInString = mapper.writeValueAsString(r);
......
...@@ -13,35 +13,25 @@ ...@@ -13,35 +13,25 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package nl.uva.sne.drip.api.rest; package nl.uva.sne.drip.commons.types;
import java.io.Serializable; import java.io.Serializable;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
/** /**
* *
* @author S. Koulouzis. * @author S. Koulouzis.
*/ */
class FileArgument implements IFileArgument, Serializable { public class FileParameter implements IFileParameter, IParameter, Serializable {
@Id public static final String NAME = "name";
@GeneratedValue(strategy = GenerationType.AUTO) public static final String URL = "url";
private String id; public static final String VALUE = "value";
public static final String ENCODING = "encoding";
private String url; private String url;
private String encoding; private String encoding;
private String contents; private String value;
private String name;
@Override
public void setID(String id) {
this.id = id;
}
@Override
public String getID() {
return this.id;
}
@Override @Override
public String getURL() { public String getURL() {
...@@ -64,13 +54,23 @@ class FileArgument implements IFileArgument, Serializable { ...@@ -64,13 +54,23 @@ class FileArgument implements IFileArgument, Serializable {
} }
@Override @Override
public String getContents() { public void setName(String name) {
return this.contents; this.name = name;
}
@Override
public String getName() {
return this.name;
}
@Override
public String getValue() {
return this.value;
} }
@Override @Override
public void setContents(String contents) { public void setValue(String value) {
this.contents = contents; this.value = value;
} }
} }
...@@ -13,17 +13,13 @@ ...@@ -13,17 +13,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package nl.uva.sne.drip.api.rest; package nl.uva.sne.drip.commons.types;
/** /**
* *
* @author S. Koulouzis. * @author S. Koulouzis.
*/ */
interface IFileArgument { public interface IFileParameter {
public void setID(String id);
public String getID();
public String getURL(); public String getURL();
...@@ -33,8 +29,8 @@ interface IFileArgument { ...@@ -33,8 +29,8 @@ interface IFileArgument {
public void setEncoding(String encoding); public void setEncoding(String encoding);
public String getContents(); public void setName(String name);
public void setContents(String contents); public String getName();
} }
...@@ -22,27 +22,14 @@ import java.util.List; ...@@ -22,27 +22,14 @@ import java.util.List;
* *
* @author S. Koulouzis * @author S. Koulouzis
*/ */
public interface IRequest { public interface IMessage {
public enum Status {
FAILED,
SUCCESS;
}
public void setID(String id);
public String getID();
public Date getCreationDate();
public void setCreationDate(Date creationDate); public Date getCreationDate();
public Status getStatus();
public void setStatus(Status status); public void setCreationDate(Date creationDate);
public void setArguments(List args); public void setParameters(List args);
public List getArguments(); public List getParameters();
} }
/*
* 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.
*/
package nl.uva.sne.drip.commons.types;
/**
*
* @author S. Koulouzis
*/
public interface IParameter {
public void setName(String name);
public String getName();
public String getValue();
public void setValue(String value);
}
...@@ -34,55 +34,28 @@ import java.util.List; ...@@ -34,55 +34,28 @@ import java.util.List;
* @author S. Koulouzis. * @author S. Koulouzis.
*/ */
//@Entity //@Entity
public class Request implements IRequest, Serializable { public class Message implements IMessage, Serializable {
// @Id
// @GeneratedValue(strategy = GenerationType.AUTO)
private String id;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.S") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.S")
// @Temporal(TemporalType.DATE) // @Temporal(TemporalType.DATE)
private Date creationDate; private Date creationDate;
// @Column // @Column
private Status status; private List<IParameter> parameters;
// @Column
private List arguments;
@Override
public void setID(String id) {
this.id = id;
}
@Override
public String getID() {
return this.id;
}
@Override @Override
public Date getCreationDate() { public Date getCreationDate() {
return this.creationDate; return this.creationDate;
} }
@Override @Override
public Status getStatus() { public void setParameters(List args) {
return this.status; this.parameters = args;
}
@Override
public void setStatus(Status status) {
status = this.status;
}
@Override
public void setArguments(List args) {
this.arguments = args;
} }
@Override @Override
public List getArguments() { public List getParameters() {
return this.arguments; return this.parameters;
} }
@Override @Override
......
...@@ -14,10 +14,28 @@ ...@@ -14,10 +14,28 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip-commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>com.rabbitmq</groupId> <groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId> <artifactId>amqp-client</artifactId>
<version>4.0.2</version> <version>4.0.2</version>
</dependency> </dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
<type>jar</type>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
...@@ -15,11 +15,32 @@ ...@@ -15,11 +15,32 @@
*/ */
package nl.uva.sne.drip.drip.planner; package nl.uva.sne.drip.drip.planner;
import com.fasterxml.jackson.databind.ObjectMapper;
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;
import com.rabbitmq.client.Envelope; import com.rabbitmq.client.Envelope;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.commons.types.FileParameter;
import nl.uva.sne.drip.commons.types.Message;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import nl.uva.sne.drip.commons.types.IFileParameter;
/** /**
* *
...@@ -27,13 +48,13 @@ import java.io.IOException; ...@@ -27,13 +48,13 @@ import java.io.IOException;
*/ */
public class Consumer extends DefaultConsumer { public class Consumer extends DefaultConsumer {
private static final String RPC_QUEUE_NAME = "planner_queue";
private static final String HOST = "172.17.0.2";
private final Channel channel; private final Channel channel;
private final Planner panner;
public Consumer(Channel channel) { public Consumer(Channel channel) {
super(channel); super(channel);
this.channel = channel; this.channel = channel;
this.panner = new Planner();
} }
@Override @Override
...@@ -41,22 +62,119 @@ public class Consumer extends DefaultConsumer { ...@@ -41,22 +62,119 @@ public class Consumer extends DefaultConsumer {
AMQP.BasicProperties replyProps = new AMQP.BasicProperties.Builder() AMQP.BasicProperties replyProps = new AMQP.BasicProperties.Builder()
.correlationId(properties.getCorrelationId()) .correlationId(properties.getCorrelationId())
.build(); .build();
String response = ""; String response = "";
try { try {
String message = new String(body, "UTF-8"); String message = new String(body, "UTF-8");
System.out.println(" [.] fib(" + message + ")"); File[] inputFiles;
inputFiles = jacksonUnmarshalExample(message);
panner.plan(inputFiles[0].getAbsolutePath(), inputFiles[1].getAbsolutePath(), "/tmp/out");
inputFiles = simpleJsonUnmarshalExample(message);
List<File> files = panner.plan(inputFiles[0].getAbsolutePath(), inputFiles[1].getAbsolutePath(), "/tmp/out");
response = jacksonMarshalExample(files);
System.err.println(response);
response = simpleJsonMarshalExample(files);
System.err.println(response);
response += message; } catch (RuntimeException | JSONException ex) {
} catch (RuntimeException e) { Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex);
System.out.println(" [.] " + e.toString());
} finally { } finally {
channel.basicPublish("", properties.getReplyTo(), replyProps, response.getBytes("UTF-8")); channel.basicPublish("", properties.getReplyTo(), replyProps, response.getBytes("UTF-8"));
channel.basicAck(envelope.getDeliveryTag(), false); channel.basicAck(envelope.getDeliveryTag(), false);
} }
} }
private File[] jacksonUnmarshalExample(String message) throws IOException {
File[] files = new File[2];
ObjectMapper mapper = new ObjectMapper();
Message request = mapper.readValue(message, Message.class);
//We know that in parameters 0-1 we should have files
for (int i = 0; i < 2; i++) {
Map<String, String> fileArg = (java.util.LinkedHashMap) request.getParameters().get(i);
String fileName = fileArg.get(FileParameter.NAME);
//If not null should be able to use it to download file
String url = fileArg.get(FileParameter.URL);
if (url != null) {
//download
}
String encoding = fileArg.get(FileParameter.ENCODING);
String value = fileArg.get(FileParameter.VALUE);
try (PrintWriter out = new PrintWriter(fileName)) {
out.print(value);
}
files[i] = new File(fileName);
}
return files;
}
private File[] simpleJsonUnmarshalExample(String message) throws JSONException, FileNotFoundException {
File[] files = new File[2];
JSONObject jo = new JSONObject(message);
JSONArray args = jo.getJSONArray("parameters");
//We know that in parameters 0-2 we should have files
for (int i = 0; i < 2; i++) {
JSONObject arg = (JSONObject) args.get(i);
String fileName = (String) arg.get(FileParameter.NAME);
//If not null should be able to use it to download file
if (!arg.isNull("url")) {
String url = (String) arg.get("url");
//download
}
//Otherwise get contents as string
String value = (String) arg.get(FileParameter.VALUE);
String encoding = (String) arg.get(FileParameter.ENCODING);
try (PrintWriter out = new PrintWriter(fileName)) {
out.print(value);
}
files[i] = new File(fileName);
}
return files;
}
private String jacksonMarshalExample(List<File> files) throws UnsupportedEncodingException, IOException {
Message responseMessage = new Message();
List parameters = new ArrayList();
String charset = "UTF-8";
for (File f : files) {
FileParameter fileParam = new FileParameter();
byte[] bytes = Files.readAllBytes(Paths.get(f.getAbsolutePath()));
fileParam.setValue(new String(bytes, charset));
fileParam.setEncoding(charset);
fileParam.setName(f.getName());
parameters.add(fileParam);
}
responseMessage.setParameters(parameters);
responseMessage.setCreationDate(new Date(System.currentTimeMillis()));
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(responseMessage);
}
private String simpleJsonMarshalExample(List<File> files) throws JSONException, IOException {
JSONObject jo = new JSONObject();
jo.put("creationDate", new Date(System.currentTimeMillis()));
List parameters = new ArrayList();
String charset = "UTF-8";
for (File f : files) {
Map<String, String> fileArguments = new HashMap<>();
fileArguments.put("encoding", charset);
fileArguments.put("name", f.getName());
byte[] bytes = Files.readAllBytes(Paths.get(f.getAbsolutePath()));
fileArguments.put("value", new String(bytes, charset));
parameters.add(fileArguments);
}
jo.put("parameters", parameters);
return jo.toString();
}
} }
...@@ -16,97 +16,101 @@ ...@@ -16,97 +16,101 @@
package nl.uva.sne.drip.drip.planner; package nl.uva.sne.drip.drip.planner;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
/** /**
* *
* @author S. Koulouzis * @author S. Koulouzis
*/ */
public class Panner { public class Planner {
public void plan(String input, String example, String outputDirPath) { public List<File> plan(String input, String example, String outputDirPath) throws FileNotFoundException, IOException {
// TODO Auto-generated method stub // TODO Auto-generated method stub
BufferedReader in; BufferedReader in;
try {
in = new BufferedReader(new FileReader(input)); in = new BufferedReader(new FileReader(input));
String line = null; String line;
boolean check = false; boolean check = false;
ArrayList<String> dockerNames = new ArrayList<>(); ArrayList<String> dockerNames = new ArrayList<>();
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
if (line.contains("topology_template")) { if (line.contains("topology_template")) {
check = true; check = true;
} }
if (check) { if (check) {
if (line.contains("file")) { if (line.contains("file")) {
String content = line.trim().replace('\"', ' '); String content = line.trim().replace('\"', ' ');
String[] cs = content.split(":"); String[] cs = content.split(":");
String docker_name = cs[1].trim(); String docker_name = cs[1].trim();
dockerNames.add(docker_name); dockerNames.add(docker_name);
}
}
if (line.contains("tosca_definitions_version")
|| line.contains("description")
|| line.contains("repositories")
|| line.contains("artifact_types") || line.contains("data_types")
|| line.contains("node_types")) {
check = false;
} }
} }
in.close(); if (line.contains("tosca_definitions_version")
|| line.contains("description")
|| line.contains("repositories")
|| line.contains("artifact_types") || line.contains("data_types")
|| line.contains("node_types")) {
check = false;
}
}
in.close();
in = new BufferedReader(new FileReader(example)); in = new BufferedReader(new FileReader(example));
String block = ""; String block = "";
String head = ""; String head = "";
boolean block_b = false; boolean block_b = false;
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
if (line.contains("components")) { if (line.contains("components")) {
block_b = true; block_b = true;
continue; continue;
} }
if (block_b) { if (block_b) {
block += line + "\n"; block += line + "\n";
}
if (!block_b) {
head += line + "\n";
}
} }
if (!block_b) {
head += line + "\n";
}
}
in.close(); in.close();
UUID fuuid = UUID.randomUUID(); UUID fuuid = UUID.randomUUID();
String file_guid = fuuid.toString(); String file_guid = fuuid.toString();
String outfPath = outputDirPath + "/" + file_guid + ".yml"; String outfPath = outputDirPath + "/" + file_guid + ".yml";
FileWriter outputf = new FileWriter(outfPath); FileWriter outputf = new FileWriter(outfPath);
outputf.write(head); outputf.write(head);
outputf.write("components:\n"); outputf.write("components:\n");
for (int i = 0; i < dockerNames.size(); i++) { for (int i = 0; i < dockerNames.size(); i++) {
UUID uuid = UUID.randomUUID(); UUID uuid = UUID.randomUUID();
String name_guid = uuid.toString(); String name_guid = uuid.toString();
String privateAddress = "192.168.10." + (i + 10); String privateAddress = "192.168.10." + (i + 10);
if (i == 0) { if (i == 0) {
outputf.write(generateVM(block, name_guid, dockerNames.get(i), privateAddress, "master")); outputf.write(generateVM(block, name_guid, dockerNames.get(i), privateAddress, "master"));
} else { } else {
outputf.write(generateVM(block, name_guid, dockerNames.get(i), privateAddress, "slave")); outputf.write(generateVM(block, name_guid, dockerNames.get(i), privateAddress, "slave"));
}
} }
outputf.close();
String allFilePath = outputDirPath + "/" + "planner_output_all.yml";
outputf = new FileWriter(allFilePath);
outputf.write("topologies:\n");
outputf.write(" - topology: " + file_guid + "\n");
outputf.write(" cloudProvider: EC2\n");
outputf.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
outputf.close();
String allFilePath = outputDirPath + "/" + "planner_output_all.yml";
outputf = new FileWriter(allFilePath);
outputf.write("topologies:\n");
outputf.write(" - topology: " + file_guid + "\n");
outputf.write(" cloudProvider: EC2\n");
outputf.close();
List<File> outputFiles = new ArrayList<>();
outputFiles.add(new File(outfPath));
outputFiles.add(new File(allFilePath));
return outputFiles;
} }
private String generateVM(String block, String nodeName, String dockerName, String privateAddress, String role) { private String generateVM(String block, String nodeName, String dockerName, String privateAddress, String role) {
......
/*
* 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.
*/
package nl.uva.sne.drip.drip.planner;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author S. Koulouzis
*/
public class RPCServer {
private static final String RPC_QUEUE_NAME = "planner_queue";
private static final String HOST = "172.17.0.2";
public static void main(String[] argv) {
start();
}
private static void start() {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(HOST);
try (Connection connection = factory.newConnection()) {
Channel channel = connection.createChannel();
channel.queueDeclare(RPC_QUEUE_NAME, false, false, false, null);
Consumer c = new Consumer(channel);
channel.basicConsume(RPC_QUEUE_NAME, false, c);
//Block so we don't close the channel
while (true) {
try {
Thread.sleep(100);
} catch (InterruptedException _ignore) {
}
}
} catch (IOException | TimeoutException ex) {
Logger.getLogger(RPCServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
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