integration + fixes
This commit is contained in:
@@ -30,9 +30,9 @@ public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort
|
||||
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(server+"/task/"+event.getTaskID()))
|
||||
.uri(URI.create(server+"/task/completed"))
|
||||
.header("Content-Type", "application/json")
|
||||
.PUT(HttpRequest.BodyPublishers.ofString(body))
|
||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||
.build();
|
||||
|
||||
try {
|
||||
|
@@ -1,11 +1,16 @@
|
||||
package ch.unisg.executorBase.executor.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.JSONObject;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import ch.unisg.executorBase.executor.application.port.out.NotifyExecutorPoolPort;
|
||||
@@ -17,34 +22,36 @@ public class NotifyExecutorPoolAdapter implements NotifyExecutorPoolPort {
|
||||
|
||||
String server = "http://127.0.0.1:8083";
|
||||
|
||||
Logger logger = Logger.getLogger(NotifyExecutorPoolAdapter.class.getName());
|
||||
|
||||
@Override
|
||||
public boolean notifyExecutorPool(String ip, int port, ExecutorType executorType) {
|
||||
|
||||
String body = new JSONObject()
|
||||
.put("executorType", executorType)
|
||||
.put("ip", ip)
|
||||
.put("port", port)
|
||||
.put("executorTaskType", executorType)
|
||||
.put("executorIp", ip)
|
||||
.put("executorPort", Integer.toString(port))
|
||||
.toString();
|
||||
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(server+"/executor/new/"))
|
||||
.uri(URI.create(server+"/executor-pool/AddExecutor"))
|
||||
.header("Content-Type", "application/json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||
.build();
|
||||
|
||||
/** Needs the other service running
|
||||
try {
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
if (response.statusCode() == HttpStatus.CREATED.value()) {
|
||||
return true;
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
// Restore interrupted state...
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
**/
|
||||
|
||||
// TODO return true or false depending on result of http request;
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user