Commit 129648d4 authored by unknown's avatar unknown
Browse files

link to s2d

parent 6765c1f1
......@@ -26,6 +26,8 @@ import org.zeromq.ZMQ.Socket;
import org.jeromq.*;
//The metasolver is responsible for calling the different solvers in PaaSage.
import eu.paasage.upperware.metasolver.exception.MetricMapperException;
public class RPListener implements Runnable{
......@@ -92,8 +94,14 @@ public class RPListener implements Runnable{
String address1 = subscriber1.recvStr ();
contents1 = subscriber1.recvStr ();
System.out.println(" Rule Processor Notification " + address1 + " : " + contents1); }
//invoke MILP Solver
mslv.invokeMILP(contents1);
//invoke MILP Solver -- hardwired as only solver present
solutionPublisherMQ spq = new solutionPublisherMQ();
try {
spq.MILPpubMQ(contents1);
} catch (MetricMapperException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
subscriber1.close ();
cntx1.term ();
}
......
......@@ -29,6 +29,7 @@ public class messageListener {
// Read message contents
String contents = subscriber.recvStr ();
System.out.println(address + " : " + contents);
//take contents and get new KPI
}
subscriber.close ();
cntx.term ();
......
......@@ -9,7 +9,9 @@
package eu.paasage.upperware.metasolver;
//package org.ow2.paasage.upperware.metasolver;
import org.zeromq.ZMQ;
import org.zeromq.ZMQ.Context;
import org.zeromq.ZMQ.Socket;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
......@@ -31,9 +33,9 @@ import org.eclipse.emf.ecore.EObject;
//The metasolver is responsible for calling the different solvers in PaaSage.
public class metasolver{
static metricsListener ml = new metricsListener("metricID");
static metricsListener ml = new metricsListener("metricID");
static solutionsListener sl = new solutionsListener("metricID");
static adaptorListener al = new adaptorListener("metricID");
// static adaptorListener al = new adaptorListener("metricID");
static RPListener rpl = new RPListener("metricID");
//Currently we only have one solver and this is invoked taking in the ResourceID from the masterscript
......@@ -65,14 +67,18 @@ public class metasolver{
//}
public void startSolving(){
System.out.println("starting solving");
go();
System.out.println("all subscriptions complete");
}
public void go(){
System.out.println("go method");
System.out.println("rpl start");
rpl.start();
ml.start();
al.start();
System.out.println("rpl done");
ml.start();
// al.start();
sl.start();
}
......
......@@ -23,7 +23,7 @@ import org.eclipse.emf.ecore.EObject;
import org.zeromq.ZMQ;
import org.zeromq.ZMQ.Context;
import org.zeromq.ZMQ.Socket;
import org.jeromq.*;
//import org.jeromq.*;
//The metasolver is responsible for calling the different solvers in PaaSage.
......@@ -32,9 +32,9 @@ public class metricsListener implements Runnable{
private Thread t;
private String threadName = "metricsListener";
private Context context1;
private Context context2;
private Context context3;
private Context context1 = null;
private Context context2 = null;
private Context context3 = null;
private Socket socket1;
private Socket socket2;
......
......@@ -26,6 +26,8 @@ import org.zeromq.ZMQ.Socket;
import org.jeromq.*;
//The metasolver is responsible for calling the different solvers in PaaSage.
import eu.paasage.upperware.metasolver.exception.MetricMapperException;
public class solutionListener implements Runnable{
......@@ -83,41 +85,60 @@ public class solutionListener implements Runnable{
Socket subscriber2 = cntx2.socket (zmq.SUB);
Socket subscriber3 = cntx3.socket (zmq.SUB);
System.out.println("socket set .....");
subscriber1.connect ("tcp://localhost:5545");
subscriber2.connect ("tcp://localhost:5546");
subscriber3.connect ("tcp://localhost:5547");
subscriber1.connect ("tcp://localhost:5540");
subscriber2.connect ("tcp://localhost:5554");
subscriber3.connect ("tcp://localhost:5541");
System.out.println("connection set .....");
subscriber1.subscribe("B_2".getBytes());//listening to meessages on ...
subscriber2.subscribe("B_3".getBytes());//listening to meessages on ...
subscriber3.subscribe("B_4".getBytes());//listening to meessages on ...
subscriber1.subscribe("MILPsolutionAvailable".getBytes());//listening to meessages on ...
subscriber2.subscribe("CPsolutionAvailable".getBytes());//listening to meessages on ...
subscriber3.subscribe("SIMULATORsolutionAvailable".getBytes());//listening to meessages on ...
System.out.println("subscription done .....");
solutionPublisherMQ sp = new solutionPublisherMQ();
while (!Thread.currentThread ().isInterrupted () && subscriber1.recvStr() != null) {
System.out.println("got1");
System.out.println("got MILP Solution");
// Read envelope with address
String address1 = subscriber1.recvStr ();
String contents1 = subscriber1.recvStr ();
System.out.println(" bell1 " + address1 + " : " + contents1);
System.out.println("MILP solution " + address1 + " : " + contents1);
try {
sp.S2D(contents1);
} catch (MetricMapperException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
while (!Thread.currentThread ().isInterrupted () && subscriber2.recvStr() != null) {
System.out.println("got2");
System.out.println("got CP Solution");
// Read envelope with address
String address2 = subscriber1.recvStr ();
String contents2 = subscriber1.recvStr ();
System.out.println(" bell2 " + address2 + " : " + contents2);
System.out.println(" CP solution " + address2 + " : " + contents2);
try {
sp.S2D(contents2);
} catch (MetricMapperException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
while (!Thread.currentThread ().isInterrupted () && subscriber1.recvStr() != null) {
System.out.println("listening");
System.out.println("got Simulation Solver Solution");
// Read envelope with address
String address3 = subscriber1.recvStr ();
String contents3 = subscriber1.recvStr ();
System.out.println(" bell3 " + address3 + " : " + contents3);
System.out.println("Simulated Solver Solution " + address3 + " : " + contents3);
try {
sp.S2D(contents3);
} catch (MetricMapperException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
subscriber1.close ();
subscriber2.close ();
......
package eu.paasage.upperware.metasolver;
import org.zeromq.ZMQ;
import org.zeromq.ZMQ.Context;
import org.zeromq.ZMQ.Socket;
import eu.paasage.upperware.metasolver.exception.MetricMapperException;
import eu.paasage.upperware.metasolver.metrics.Mapper;
public class solutionPublisherMQ {
public String MILPpubMQ (String model) throws MetricMapperException{
Context context = ZMQ.context(1);
Socket publisher = context.socket(ZMQ.PUB);
System.out.println("binding .... ");
publisher.bind("tcp://*:5554");
while (!Thread.currentThread ().isInterrupted ()) {
// Write two messages, each with an envelope and content
System.out.println("publishing .... ");
//topic
publisher.sendMore ("startDeployment");
//contents
Mapper map = new Mapper();
long mapResult = map.mapMetricVariables(model);
publisher.send(model + " , " + mapResult);
System.out.println("done publishing .... ");
}
publisher.close ();
context.term ();
return "done";
}
public String S2D (String model) throws MetricMapperException{
Context context = ZMQ.context(1);
Socket publisher = context.socket(ZMQ.PUB);
System.out.println("binding .... ");
publisher.bind("tcp://*:5546");
while (!Thread.currentThread ().isInterrupted ()) {
// Write two messages, each with an envelope and content
System.out.println("publishing .... ");
//topic
publisher.sendMore ("newDeploymentCAMELModel");
//contents
Mapper map = new Mapper();
long mapResult = map.mapMetricVariables(model);
publisher.send(model + " , " + mapResult);
System.out.println("done publishing to S2D.... ");
}
publisher.close ();
context.term ();
return "done S2D";
}
}
package eu.paasage.upperware.metasolver;
import org.zeromq.ZMQ;
import org.zeromq.ZMQ.Context;
import org.zeromq.ZMQ.Socket;
public class test2 {
public static void main (String args[]){
System.out.println("testing metasolver main");
System.out.println("testing metasolver start solving");
try{
System.out.println("in try ");
metasolver mslv = new metasolver();
System.out.println("call to start solving");
mslv.startSolving();
}
catch(Exception e)
{
System.out.println("Exception " + e);
}
}
}
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