Implemented the following points:
- Roster/Auctionhouse send initial getExecutors request - Remove executor (made DELETE endpoint in executor pool)
This commit is contained in:
@@ -8,6 +8,7 @@ import javax.annotation.PostConstruct;
|
||||
|
||||
import ch.unisg.roster.roster.adapter.out.persistence.mongodb.RosterRepository;
|
||||
import ch.unisg.roster.roster.application.port.in.LoadRosterItemPort;
|
||||
import ch.unisg.roster.roster.application.service.GetExecutorsService;
|
||||
import ch.unisg.roster.roster.domain.Roster;
|
||||
import ch.unisg.roster.roster.domain.RosterItem;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
@@ -36,6 +37,8 @@ public class RosterApplication {
|
||||
SpringApplication rosterApp = new SpringApplication(RosterApplication.class);
|
||||
ENVIRONMENT = rosterApp.run(args).getEnvironment();
|
||||
bootstrapMarketplaceWithMqtt();
|
||||
var getExecutorsService = new GetExecutorsService();
|
||||
getExecutorsService.getExecutorsFromExecutorPool();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -0,0 +1,61 @@
|
||||
package ch.unisg.roster.roster.adapter.out.web;
|
||||
|
||||
import ch.unisg.roster.roster.domain.ExecutorInfo;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
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.LinkedList;
|
||||
import java.util.List;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class GetExecutorsInExecutorPoolWebAdapter {
|
||||
private static final Logger LOGGER = LogManager.getLogger(GetExecutorsInExecutorPoolWebAdapter.class);
|
||||
|
||||
// TODO get from config
|
||||
String server = "http://localhost:8083";
|
||||
|
||||
public List<ExecutorInfo> getExecutorsInExecutorPool(){
|
||||
var client = HttpClient.newHttpClient();
|
||||
var request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(server + "/executor-pool/GetAllExecutorsInExecutorPool"))
|
||||
.GET()
|
||||
.build();
|
||||
|
||||
try {
|
||||
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
if(response.statusCode() != HttpStatus.OK.value()){
|
||||
LOGGER.log(Level.INFO, "Could not get executors from Executor Pool");
|
||||
return null;
|
||||
}
|
||||
|
||||
LOGGER.log(Level.INFO, "Executors received from ExecutorPool: " + response.body());
|
||||
|
||||
var jsonExecutorArray = new JSONArray(response.body());
|
||||
var executorList = new LinkedList<ExecutorInfo>();
|
||||
|
||||
for(int i = 0; i < jsonExecutorArray.length(); i++){
|
||||
var jsonExecutorObject = jsonExecutorArray.getJSONObject(i);
|
||||
var executorURI = jsonExecutorObject.getString("executorUri");
|
||||
var executorType = jsonExecutorObject.getString("executorTaskType");
|
||||
executorList.add(new ExecutorInfo(executorURI, executorType));
|
||||
}
|
||||
|
||||
return executorList;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package ch.unisg.roster.roster.application.service;
|
||||
|
||||
import ch.unisg.roster.roster.adapter.out.web.GetExecutorsInExecutorPoolWebAdapter;
|
||||
import ch.unisg.roster.roster.domain.ExecutorRegistry;
|
||||
|
||||
// TODO should this implement a port in the Hexagonal architecture?
|
||||
public class GetExecutorsService {
|
||||
|
||||
public boolean getExecutorsFromExecutorPool(){
|
||||
var getExecutorsAdapter = new GetExecutorsInExecutorPoolWebAdapter();
|
||||
var executors = getExecutorsAdapter.getExecutorsInExecutorPool();
|
||||
if(executors == null){
|
||||
return false;
|
||||
}
|
||||
var executorRegistry = ExecutorRegistry.getInstance();
|
||||
return executorRegistry.addExecutors(executors);
|
||||
}
|
||||
}
|
@@ -5,6 +5,8 @@ import ch.unisg.common.valueobject.ExecutorURI;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public class ExecutorInfo {
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -13,4 +15,9 @@ public class ExecutorInfo {
|
||||
@Getter
|
||||
@Setter
|
||||
private ExecutorType executorType;
|
||||
|
||||
public ExecutorInfo(String executorURI, String executorType){
|
||||
this.executorURI = new ExecutorURI(executorURI);
|
||||
this.executorType = new ExecutorType(executorType);
|
||||
}
|
||||
}
|
||||
|
@@ -30,8 +30,8 @@ public class ExecutorRegistry {
|
||||
/**
|
||||
* Adds an executor to the registry for a given task type.
|
||||
*
|
||||
* @param taskType the type of the task
|
||||
* @param executorIdentifier the identifier of the executor (can be any string)
|
||||
* @param executorType the type of the task
|
||||
* @param executorURI the identifier of the executor (can be any string)
|
||||
* @return true unless a runtime exception occurs
|
||||
*/
|
||||
public boolean addExecutor(ExecutorType executorType, ExecutorURI executorURI) {
|
||||
@@ -44,6 +44,15 @@ public class ExecutorRegistry {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean addExecutors(List<ExecutorInfo> executors){
|
||||
for (var executor : executors) {
|
||||
if(!addExecutor(executor.getExecutorType(), executor.getExecutorURI())){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an executor from the registry. The executor is disassociated from all known task types.
|
||||
*
|
||||
|
Reference in New Issue
Block a user