bugfixes + env variables
This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.logging.Logger;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
|
||||
import ch.unisg.roster.roster.adapter.common.clients.TapasMqttClient;
|
||||
import ch.unisg.roster.roster.adapter.in.messaging.mqtt.ExecutorEventMqttListener;
|
||||
@@ -16,11 +17,12 @@ public class RosterApplication {
|
||||
|
||||
static Logger logger = Logger.getLogger(RosterApplication.class.getName());
|
||||
|
||||
public static String MQTT_BROKER = "tcp://broker.hivemq.com:1883";
|
||||
private static ConfigurableEnvironment ENVIRONMENT;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(RosterApplication.class, args);
|
||||
|
||||
SpringApplication rosterApp = new SpringApplication(RosterApplication.class);
|
||||
ENVIRONMENT = rosterApp.run(args).getEnvironment();
|
||||
bootstrapMarketplaceWithMqtt();
|
||||
}
|
||||
|
||||
@@ -29,9 +31,11 @@ public class RosterApplication {
|
||||
* one another
|
||||
*/
|
||||
private static void bootstrapMarketplaceWithMqtt() {
|
||||
String broker = ENVIRONMENT.getProperty("mqtt.broker.uri");
|
||||
|
||||
try {
|
||||
ExecutorEventsMqttDispatcher dispatcher = new ExecutorEventsMqttDispatcher();
|
||||
TapasMqttClient client = TapasMqttClient.getInstance(MQTT_BROKER, dispatcher);
|
||||
TapasMqttClient client = TapasMqttClient.getInstance(broker, dispatcher);
|
||||
client.startReceivingMessages();
|
||||
} catch (MqttException e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
|
@@ -25,7 +25,6 @@ public class TaskCompletedController {
|
||||
**/
|
||||
@PostMapping(path = "/task/completed", consumes = {"application/json"})
|
||||
public ResponseEntity<Void> addNewTaskTaskToTaskList(@RequestBody Task task) {
|
||||
System.out.println("TEST");
|
||||
TaskCompletedCommand command = new TaskCompletedCommand(task.getTaskID(),
|
||||
task.getStatus(), task.getOutputData());
|
||||
|
||||
|
@@ -1,63 +0,0 @@
|
||||
package ch.unisg.roster.roster.adapter.out.web;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import ch.unisg.roster.roster.application.port.out.GetAllExecutorInExecutorPoolByTypePort;
|
||||
import ch.unisg.roster.roster.domain.valueobject.ExecutorType;
|
||||
|
||||
@Component
|
||||
@Primary
|
||||
public class GetAllExecutorInExecutorPoolByTypeAdapter implements GetAllExecutorInExecutorPoolByTypePort {
|
||||
|
||||
@Value("${executor-pool.url}")
|
||||
private String server;
|
||||
|
||||
/**
|
||||
* Requests all executor of the give type from the executor-pool and cheks if there is one
|
||||
* avaialable of this type.
|
||||
* @return Whether an executor exist or not
|
||||
**/
|
||||
@Override
|
||||
public boolean doesExecutorTypeExist(ExecutorType type) {
|
||||
|
||||
Logger logger = Logger.getLogger(PublishNewTaskEventAdapter.class.getName());
|
||||
|
||||
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(server + "/executor-pool/GetAllExecutorInExecutorPoolByType/" + type.getValue()))
|
||||
.header("Content-Type", "application/json")
|
||||
.GET()
|
||||
.build();
|
||||
|
||||
|
||||
try {
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
if (response.statusCode() == HttpStatus.OK.value()) {
|
||||
JSONArray jsonArray = new JSONArray(response.body());
|
||||
if (jsonArray.length() > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@@ -19,10 +19,10 @@ import ch.unisg.roster.roster.domain.event.NewTaskEvent;
|
||||
@Primary
|
||||
public class PublishNewTaskEventAdapter implements NewTaskEventPort {
|
||||
|
||||
@Value("${executor1.url}")
|
||||
@Value("${executor-robot.uri}")
|
||||
private String server;
|
||||
|
||||
@Value("${executor2.url}")
|
||||
@Value("${executor-computation.uri}")
|
||||
private String server2;
|
||||
|
||||
Logger logger = Logger.getLogger(PublishNewTaskEventAdapter.class.getName());
|
||||
|
@@ -20,7 +20,7 @@ import ch.unisg.roster.roster.domain.event.TaskAssignedEvent;
|
||||
@Primary
|
||||
public class PublishTaskAssignedEventAdapter implements TaskAssignedEventPort {
|
||||
|
||||
@Value("${task-list.url}")
|
||||
@Value("${task-list.uri}")
|
||||
private String server;
|
||||
|
||||
Logger logger = Logger.getLogger(PublishTaskAssignedEventAdapter.class.getName());
|
||||
@@ -32,26 +32,26 @@ public class PublishTaskAssignedEventAdapter implements TaskAssignedEventPort {
|
||||
@Override
|
||||
public void publishTaskAssignedEvent(TaskAssignedEvent event) {
|
||||
|
||||
// String body = new JSONObject()
|
||||
// .put("taskId", event.taskID)
|
||||
// .toString();
|
||||
String body = new JSONObject()
|
||||
.put("taskId", event.taskID)
|
||||
.toString();
|
||||
|
||||
// HttpClient client = HttpClient.newHttpClient();
|
||||
// HttpRequest request = HttpRequest.newBuilder()
|
||||
// .uri(URI.create(server + "/tasks/assignTask"))
|
||||
// .header("Content-Type", "application/task+json")
|
||||
// .POST(HttpRequest.BodyPublishers.ofString(body))
|
||||
// .build();
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(server + "/tasks/assignTask"))
|
||||
.header("Content-Type", "application/task+json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||
.build();
|
||||
|
||||
|
||||
// try {
|
||||
// client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
// } catch (InterruptedException e) {
|
||||
// logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
// Thread.currentThread().interrupt();
|
||||
// } catch (IOException e) {
|
||||
// logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
// }
|
||||
try {
|
||||
client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
} catch (InterruptedException e) {
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ import ch.unisg.roster.roster.domain.event.TaskCompletedEvent;
|
||||
@Primary
|
||||
public class PublishTaskCompletedEventAdapter implements TaskCompletedEventPort {
|
||||
|
||||
@Value("${task-list.url}")
|
||||
@Value("${task-list.uri}")
|
||||
private String server;
|
||||
|
||||
Logger logger = Logger.getLogger(PublishTaskCompletedEventAdapter.class.getName());
|
||||
@@ -32,22 +32,17 @@ public class PublishTaskCompletedEventAdapter implements TaskCompletedEventPort
|
||||
@Override
|
||||
public void publishTaskCompleted(TaskCompletedEvent event) {
|
||||
|
||||
System.out.println("PublishTaskCompletedEventAdapter.publishTaskCompleted()");
|
||||
System.out.print(server);
|
||||
|
||||
String body = new JSONObject()
|
||||
.put("taskId", event.taskID)
|
||||
.put("status", event.status)
|
||||
.put("outputData", event.result)
|
||||
.toString();
|
||||
|
||||
System.out.println(event.taskID);
|
||||
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(server + "/tasks/completeTask/" + event.taskID))
|
||||
.uri(URI.create(server + "/tasks/completeTask/"))
|
||||
.header("Content-Type", "application/task+json")
|
||||
.GET()
|
||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||
.build();
|
||||
|
||||
|
||||
|
@@ -1,13 +0,0 @@
|
||||
package ch.unisg.roster.roster.application.port.out;
|
||||
|
||||
import ch.unisg.roster.roster.domain.valueobject.ExecutorType;
|
||||
|
||||
public interface GetAllExecutorInExecutorPoolByTypePort {
|
||||
/**
|
||||
* Checks if a executor with the given type exist in our executor pool
|
||||
* @return boolean
|
||||
**/
|
||||
boolean doesExecutorTypeExist(ExecutorType type);
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
server.port=8082
|
||||
executor-pool.url=http://127.0.0.1:8083
|
||||
executor1.url=http://127.0.0.1:8084
|
||||
executor2.url=http://127.0.0.1:8085
|
||||
task-list.url=http://127.0.0.1:8081
|
||||
executor-robot.uri=http://127.0.0.1:8084
|
||||
executor-computation.uri=http://127.0.0.1:8085
|
||||
task-list.uri=http://127.0.0.1:8081
|
||||
mqtt.broker.uri=tcp://localhost:1883
|
||||
|
Reference in New Issue
Block a user