added valueObjects & CustomErrors
This commit is contained in:
@@ -5,14 +5,9 @@ import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
import ch.unisg.executorBase.executor.application.port.out.ExecutionFinishedEventPort;
|
||||
import ch.unisg.executorBase.executor.domain.ExecutionFinishedEvent;
|
||||
|
||||
|
@@ -3,11 +3,8 @@ package ch.unisg.executorBase.executor.adapter.out.web;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -17,31 +14,22 @@ import ch.unisg.executorBase.executor.domain.ExecutorType;
|
||||
@Component
|
||||
@Primary
|
||||
public class NotifyExecutorPoolAdapter implements NotifyExecutorPoolPort {
|
||||
|
||||
//This is the base URI of the service interested in this event (in my setup, running locally as separate Spring Boot application)
|
||||
|
||||
String server = "http://127.0.0.1:8083";
|
||||
|
||||
@Override
|
||||
public boolean notifyExecutorPool(String ip, int port, ExecutorType executorType) {
|
||||
|
||||
var values = new HashMap<String, String>() {{
|
||||
put("ip", ip);
|
||||
put("port", Integer.toString(port));
|
||||
put("executorType", executorType.toString());
|
||||
}};
|
||||
|
||||
var objectMapper = new ObjectMapper();
|
||||
String requestBody = null;
|
||||
try {
|
||||
requestBody = objectMapper.writeValueAsString(values);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String body = new JSONObject()
|
||||
.put("executorType", executorType)
|
||||
.put("ip", ip)
|
||||
.put("port", port)
|
||||
.toString();
|
||||
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(server+"/executor/new/"))
|
||||
.POST(HttpRequest.BodyPublishers.ofString(requestBody))
|
||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||
.build();
|
||||
|
||||
/** Needs the other service running
|
||||
|
Reference in New Issue
Block a user