fixed multiple bugs & updated cicd workflows
This commit is contained in:
@@ -1,13 +1,41 @@
|
||||
package ch.unisg.roster;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import ch.unisg.roster.roster.adapter.common.clients.TapasMqttClient;
|
||||
import ch.unisg.roster.roster.adapter.in.messaging.mqtt.ExecutorEventMqttListener;
|
||||
import ch.unisg.roster.roster.adapter.in.messaging.mqtt.ExecutorEventsMqttDispatcher;
|
||||
|
||||
@SpringBootApplication
|
||||
public class RosterApplication {
|
||||
|
||||
static Logger logger = Logger.getLogger(RosterApplication.class.getName());
|
||||
|
||||
public static String MQTT_BROKER = "tcp://localhost:1883";
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(RosterApplication.class, args);
|
||||
|
||||
bootstrapMarketplaceWithMqtt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to an MQTT broker, presumably the one used by all TAPAS groups to communicate with
|
||||
* one another
|
||||
*/
|
||||
private static void bootstrapMarketplaceWithMqtt() {
|
||||
try {
|
||||
ExecutorEventsMqttDispatcher dispatcher = new ExecutorEventsMqttDispatcher();
|
||||
TapasMqttClient client = TapasMqttClient.getInstance(MQTT_BROKER, dispatcher);
|
||||
client.startReceivingMessages();
|
||||
} catch (MqttException e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,6 +17,9 @@ public class ExecutorAddedEventListenerMqttAdapter extends ExecutorEventMqttList
|
||||
|
||||
@Override
|
||||
public boolean handleEvent(MqttMessage message) {
|
||||
|
||||
System.out.println("New Executor added!");
|
||||
|
||||
String payload = new String(message.getPayload());
|
||||
|
||||
try {
|
||||
@@ -25,7 +28,7 @@ public class ExecutorAddedEventListenerMqttAdapter extends ExecutorEventMqttList
|
||||
JsonNode data = new ObjectMapper().readTree(payload);
|
||||
|
||||
String taskType = data.get("executorTaskType").asText();
|
||||
String executorId = data.get("executorURI").asText();
|
||||
String executorId = data.get("executorUri").asText();
|
||||
|
||||
ExecutorAddedEvent executorAddedEvent = new ExecutorAddedEvent(
|
||||
new ExecutorURI(executorId),
|
||||
|
@@ -16,8 +16,8 @@ public class ExecutorEventsMqttDispatcher {
|
||||
|
||||
// TODO: Register here your topics and event listener adapters
|
||||
private void initRouter() {
|
||||
router.put("ch/unisg/tapas-group-tutors/executors/added", new ExecutorAddedEventListenerMqttAdapter());
|
||||
router.put("ch/unisg/tapas-group-tutors/executors/removed", new ExecutorRemovedEventListenerMqttAdapter());
|
||||
router.put("ch/unisg/tapas/executors/added", new ExecutorAddedEventListenerMqttAdapter());
|
||||
router.put("ch/unisg/tapas/executors/removed", new ExecutorRemovedEventListenerMqttAdapter());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package ch.unisg.roster.roster.adapter.in.web;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -18,6 +20,8 @@ public class NewTaskController {
|
||||
this.newTaskUseCase = newTaskUseCase;
|
||||
}
|
||||
|
||||
Logger logger = Logger.getLogger(NewTaskController.class.getName());
|
||||
|
||||
/**
|
||||
* Controller which handles the new task event from the tasklist
|
||||
* @return 201 Create or 409 Conflict
|
||||
@@ -25,10 +29,14 @@ public class NewTaskController {
|
||||
@PostMapping(path = "/task", consumes = {"application/task+json"})
|
||||
public ResponseEntity<Void> newTaskController(@RequestBody Task task) {
|
||||
|
||||
logger.info("New task with id:" + task.getTaskID());
|
||||
|
||||
NewTaskCommand command = new NewTaskCommand(task.getTaskID(), task.getTaskType());
|
||||
|
||||
boolean success = newTaskUseCase.addNewTaskToQueue(command);
|
||||
|
||||
logger.info("Could create task: " + success);
|
||||
|
||||
if (success) {
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
@@ -34,21 +34,23 @@ public class PublishNewTaskEventAdapter implements NewTaskEventPort {
|
||||
@Override
|
||||
public void publishNewTaskEvent(NewTaskEvent event) {
|
||||
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(server + "/newtask/" + event.taskType.getValue()))
|
||||
.GET()
|
||||
.build();
|
||||
System.out.println(server2);
|
||||
|
||||
// HttpClient client = HttpClient.newHttpClient();
|
||||
// HttpRequest request = HttpRequest.newBuilder()
|
||||
// .uri(URI.create(server + "/newtask/" + event.taskType.getValue()))
|
||||
// .GET()
|
||||
// .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);
|
||||
// }
|
||||
|
||||
HttpClient client2 = HttpClient.newHttpClient();
|
||||
HttpRequest request2 = HttpRequest.newBuilder()
|
||||
|
@@ -29,6 +29,7 @@ public class NewTaskService implements NewTaskUseCase {
|
||||
public boolean addNewTaskToQueue(NewTaskCommand command) {
|
||||
|
||||
ExecutorRegistry executorRegistry = ExecutorRegistry.getInstance();
|
||||
|
||||
if (!executorRegistry.containsTaskType(command.getTaskType())) {
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user