Send AMPL to optimiser if connected to ActiveMQ
Change-Id: I2415c0e480241f9801e95ec2ebe46ee0f560bd0f
This commit is contained in:
@@ -43,8 +43,9 @@ public class ExnConnector {
|
||||
/** The topic where we send AMPL messages */
|
||||
// 1 object with key: filename, value: AMPL file (serialized)
|
||||
public static final String ampl_message_channel = "eu.nebulouscloud.optimiser.ampl";
|
||||
|
||||
private final Publisher ampl_message_producer;
|
||||
/** Message producer for sending AMPL files, shared between all
|
||||
* NebulousApp instances. */
|
||||
private final Publisher ampl_message_publisher;
|
||||
|
||||
/**
|
||||
* Create a connection to ActiveMQ via the exn middleware, and set up the
|
||||
@@ -59,18 +60,22 @@ public class ExnConnector {
|
||||
* Connector#start} method has connected and set up all handlers.
|
||||
*/
|
||||
public ExnConnector(String host, int port, String name, String password, ConnectorHandler callback) {
|
||||
ampl_message_producer = new Publisher("controller_ampl", ampl_message_channel, true, true);
|
||||
ampl_message_publisher = new Publisher("controller_ampl", ampl_message_channel, true, true);
|
||||
|
||||
conn = new Connector("optimiser_controller",
|
||||
callback,
|
||||
// List.of(new Publisher("config", "config", true)),
|
||||
List.of(ampl_message_producer),
|
||||
List.of(ampl_message_publisher),
|
||||
List.of(new Consumer("ui_app_messages", app_creation_channel, new AppCreationMessageHandler(), true, true)),
|
||||
false,
|
||||
false,
|
||||
new StaticExnConfig(host, port, name, password, 15, "eu.nebulouscloud"));
|
||||
}
|
||||
|
||||
public Publisher getAmplPublisher() {
|
||||
return ampl_message_publisher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to ActiveMQ and activate all publishers and consumers. It is
|
||||
* an error to start the controller more than once.
|
||||
@@ -116,7 +121,7 @@ public class ExnConnector {
|
||||
try {
|
||||
String app_id = message.subject();
|
||||
log.info("App creation message received for app {}", app_id);
|
||||
NebulousApp app = NebulousApp.newFromAppMessage(mapper.valueToTree(body), ampl_message_producer);
|
||||
NebulousApp app = NebulousApp.newFromAppMessage(mapper.valueToTree(body), ampl_message_publisher);
|
||||
NebulousApps.add(app);
|
||||
app.sendAMPL();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -13,7 +13,6 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import picocli.CommandLine.Command;
|
||||
import picocli.CommandLine.Option;
|
||||
import picocli.CommandLine.Parameters;
|
||||
import picocli.CommandLine.ParentCommand;
|
||||
|
||||
@@ -36,18 +35,18 @@ public class LocalExecution implements Callable<Integer> {
|
||||
private Path app_creation_msg;
|
||||
|
||||
@Override public Integer call() {
|
||||
int success = 0;
|
||||
if (app_creation_msg != null) {
|
||||
try {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode msg = mapper.readTree(Files.readString(app_creation_msg, StandardCharsets.UTF_8));
|
||||
NebulousApp app = NebulousApp.newFromAppMessage(msg, null);
|
||||
System.out.println(app.generateAMPL());
|
||||
} catch (IOException e) {
|
||||
log.error("Could not read an input file: ", e);
|
||||
success = 1;
|
||||
}
|
||||
}
|
||||
return success;
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode msg;
|
||||
try {
|
||||
msg = mapper.readTree(Files.readString(app_creation_msg, StandardCharsets.UTF_8));
|
||||
} catch (IOException e) {
|
||||
log.error("Could not read an input file: ", e);
|
||||
return 1;
|
||||
}
|
||||
NebulousApp app = NebulousApp.newFromAppMessage(msg,
|
||||
main.activemq_connector == null ? null : main.activemq_connector.getAmplPublisher());
|
||||
System.out.println(app.generateAMPL());
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user