This commit is contained in:
Marcel 2021-12-21 15:30:33 +01:00
parent 0eb21d2083
commit 56788d7150
17 changed files with 66 additions and 42 deletions

View File

@ -67,8 +67,9 @@ services:
- ./:/data/
environment:
mqtt.broker.uri: tcp://broker.hivemq.com:1883
discovery.endpoint.uri: https://tapas-auction-house.86.119.35.213.nip.io/discovery/
discovery.endpoint.uri: https://tapas-auction-house.86-119-34-242.nip.io
auction.house.uri: https://tapas-auction-house.86-119-35-40.nip.io
tasks.list.uri: https://tapas-tasks.86-119-35-40.nip.io
labels:
- "traefik.enable=true"
- "traefik.http.routers.tapas-auction-house.rule=Host(`tapas-auction-house.${PUB_IP}.nip.io`)"

View File

@ -107,5 +107,6 @@ jobs:
cd /home/${{ secrets.SSH_USER }}/
touch acme.json
sudo chmod 0600 acme.json
sudo docker-compose down --remove-orphans
sudo echo "PUB_IP=$(wget -qO- http://ipecho.net/plain | xargs echo)" | sed -e 's/\./-/g' > .env
sudo docker-compose up -d --build --force-recreate
sudo docker-compose up -d

View File

@ -67,6 +67,17 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<version>21.3.0</version>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
<version>21.3.0</version>
</dependency>
</dependencies>
<build>

View File

@ -11,7 +11,7 @@
</parent>
<groupId>ch.unisg</groupId>
<artifactId>executor-humidity</artifactId>
<version>1.0-SNAPSHOT</version>
<version>0.0.1-SNAPSHOT</version>
<name>executor-humidity</name>
<description>Demo project for Spring Boot</description>
<properties>

View File

@ -21,7 +21,8 @@ public class Executor extends ExecutorBase {
@Override
protected
String execution(String input) {
return userToRobotPort.userToRobot();
userToRobotPort.userToRobot();
return "";
}
}

View File

@ -51,8 +51,10 @@ public class TapasAuctionHouseApplication {
WebSubSubscriber subscriber = new WebSubSubscriber(ENVIRONMENT.getProperty("auction.house.uri"));
for (AuctionHouseDiscoveryInformation endpoint : AuctionHouseDiscovery.getInstance().getAuctionHouseDiscoveryList()) {
System.out.println(endpoint.getWebSubUri().getValue());
subscriber.subscribeToAuctionHouseEndpoint(endpoint.getWebSubUri().getValue());
// Don't subscribe to our own auction house
if (!endpoint.getWebSubUri().getValue().toString().equalsIgnoreCase("https://tapas-auction-house.86-119-35-40.nip.io/websub/auctions")) {
subscriber.subscribeToAuctionHouseEndpoint(endpoint.getWebSubUri().getValue());
}
}
// try {
// subscriber.subscribeToAuctionHouseEndpoint(new URI("http://6b4e-130-82-250-227.ngrok.io/websub-discovery"));

View File

@ -101,6 +101,9 @@ public class WebSubSubscriber {
return;
}
System.out.println("HUB: " + hub);
System.out.println("TOPIC: " + topic);
HttpRequest request = HttpRequest.newBuilder()
.uri(hubURI)
.header("Content-Type", "application/x-www-form-urlencoded")

View File

@ -22,11 +22,9 @@ import java.net.http.HttpResponse;
public class ExternalAuctionStartedEventListenerMqttAdapter extends AuctionEventMqttListener{
private static final Logger LOGGER = LogManager.getLogger(ExternalAuctionStartedEventListenerMqttAdapter.class);
// String auctionHouseURI = "https://tapas-auction-house.86-119-35-40.nip.io/";
String auctionHouseURI = "http://a888-77-59-152-182.eu.ngrok.io";
String auctionHouseURI = "https://tapas-auction-house.86-119-35-40.nip.io/";
// String taskListURI = "https://tapas-tasks.86-119-35-40.nip.io";
String taskListURI = "http://e021-77-59-152-182.ngrok.io";
String taskListURI = "https://tapas-tasks.86-119-35-40.nip.io";
@Override
public boolean handleEvent(MqttMessage message){

View File

@ -69,11 +69,9 @@ public class AuctionStartedEventListenerWebSubAdapter {
// }
// String auctionHouseURI = "https://tapas-auction-house.86-119-35-40.nip.io/";
String auctionHouseURI = "http://b311-130-82-247-153.eu.ngrok.io";
String auctionHouseURI = "https://tapas-auction-house.86-119-35-40.nip.io/";
// String taskListURI = "https://tapas-tasks.86-119-35-40.nip.io";
String taskListURI = "http://c64f-130-82-247-153.ngrok.io";
String taskListURI = "https://tapas-tasks.86-119-35-40.nip.io";
// TODO Sanitize URIs
String auctionId = auction.getString("auctionId");

View File

@ -30,7 +30,7 @@ public class AuctionHouseDiscoveryWebController {
this.auctionHouseDiscoveryUseCase = auctionHouseDiscoveryUseCase;
}
@GetMapping(path="/discovery/", consumes = AuctionHouseDiscoveryJsonRepresentation.MEDIA_TYPE)
@GetMapping(path="/discovery/")
public ResponseEntity<String> auctionHouseDiscovery() {
List<AuctionHouseDiscoveryInformation> auctionHouseDiscoveryInformation = auctionHouseDiscoveryUseCase.auctionHouseDiscovery();

View File

@ -27,9 +27,11 @@ public class WinningBidWebController {
@PostMapping(path = "/taskwinner", consumes = TaskJsonRepresentation.MEDIA_TYPE)
public ResponseEntity<String> winningBid(@RequestBody TaskJsonRepresentation payload){
LOGGER.info("New Task Winner");
try {
var body = payload.serialize();
LOGGER.info(body);
LOGGER.info("Task Winner body: " + body);
LOGGER.info("Task Winner taskListURI: " + taskListURI);
var postURI = URI.create(taskListURI + "/tasks/");
HttpRequest postRequest = HttpRequest.newBuilder()
.uri(postURI)
@ -40,7 +42,7 @@ public class WinningBidWebController {
HttpClient client = HttpClient.newHttpClient();
var postResponse = client.send(postRequest, HttpResponse.BodyHandlers.ofString());
LOGGER.info(postResponse.statusCode());
LOGGER.info("Create task internally with status code: " + postResponse.statusCode());
HttpHeaders responseHeaders = new HttpHeaders();

View File

@ -32,6 +32,7 @@ public class PublishAuctionStartedEventWebSubAdapter implements AuctionStartedEv
@Override
public void publishAuctionStartedEvent(AuctionStartedEvent event) {
logger.info("AuctionHouse | Publish auction started over WebSub!");
logger.info("AuctionHouse | AuctionHouseURI: " + auctionHouseUri + " WebSubHubUri: " + webSubHubUri);
HttpClient client = HttpClient.newHttpClient();

View File

@ -6,6 +6,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.http.HttpStatus;
import java.io.IOException;
import java.net.URI;
@ -22,36 +23,37 @@ public class AuctionHouseDiscoveryHttpAdapter implements AuctionHouseDiscoveryPo
public List<AuctionHouseDiscoveryInformation> fetchAuctionHouseInformation(URI auctionHouseURI){
System.out.println(auctionHouseURI);
try{
var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
.uri(auctionHouseURI)
.GET()
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
LOGGER.info(response.body());
var responseBody = new JSONObject(response.body());
HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
LOGGER.info("Response status code: " + response.statusCode());
LOGGER.info("Response body:" + response.body());
if (response.statusCode() == HttpStatus.OK.value()) {
var responseBody = new JSONObject(response.body());
var arrayOfInformation = responseBody.getJSONArray("auctionHouseInfo");
var returnList = new LinkedList<AuctionHouseDiscoveryInformation>();
var arrayOfInformation = responseBody.getJSONArray("auctionHouseInfo");
var returnList = new LinkedList<AuctionHouseDiscoveryInformation>();
for(int i = 0; i < arrayOfInformation.length(); i++)
{
var informationJSON = arrayOfInformation.getJSONObject(i);
var information = new AuctionHouseDiscoveryInformation(
new AuctionHouseDiscoveryInformation.AuctionHouseUri(URI.create(informationJSON.getString("auctionHouseUri"))),
new AuctionHouseDiscoveryInformation.WebSubUri(URI.create(informationJSON.getString("webSubUri"))),
new AuctionHouseDiscoveryInformation.TaskTypes(getTaskTypes(informationJSON.getJSONArray("taskTypes"))),
new AuctionHouseDiscoveryInformation.TimeStamp(Timestamp.valueOf(informationJSON.getString("timeStamp"))),
new AuctionHouseDiscoveryInformation.GroupName(informationJSON.getString("groupName"))
);
returnList.add(information);
}
return returnList;
for(int i = 0; i < arrayOfInformation.length(); i++)
{
var informationJSON = arrayOfInformation.getJSONObject(i);
var information = new AuctionHouseDiscoveryInformation(
new AuctionHouseDiscoveryInformation.AuctionHouseUri(URI.create(informationJSON.getString("auctionHouseUri"))),
new AuctionHouseDiscoveryInformation.WebSubUri(URI.create(informationJSON.getString("webSubUri"))),
new AuctionHouseDiscoveryInformation.TaskTypes(getTaskTypes(informationJSON.getJSONArray("taskTypes"))),
new AuctionHouseDiscoveryInformation.TimeStamp(Timestamp.valueOf(informationJSON.getString("timeStamp"))),
new AuctionHouseDiscoveryInformation.GroupName(informationJSON.getString("groupName"))
);
returnList.add(information);
}
return returnList;
}
return Collections.<AuctionHouseDiscoveryInformation>emptyList();
} catch (IOException e) {
e.printStackTrace();
return Collections.<AuctionHouseDiscoveryInformation>emptyList();

View File

@ -52,13 +52,18 @@ public class AuctionWonEventHttpAdapter implements AuctionWonEventPort {
LOGGER.info(response.body());
JSONObject responseBody = new JSONObject(response.body());
String inputData = "";
if (!responseBody.isNull("inputData")) {
inputData = responseBody.getString("inputData");
}
var task = new Task(
new Task.TaskName(responseBody.getString("taskName")),
new Task.TaskType(responseBody.getString("taskType")),
new Task.OriginalTaskUri(auction.get().getTaskUri().getValue().toString()),
new Task.TaskStatus(ch.unisg.tapas.auctionhouse.domain.Task.Status.ASSIGNED),
new Task.TaskId(responseBody.getString("taskId")),
new Task.InputData(responseBody.getString("inputData")),
new Task.InputData(inputData),
new Task.ServiceProvider("TODO")
);

View File

@ -7,7 +7,6 @@ websub.hub.publish=https://websub.appspot.com/
group=tapas-group-1
auction.house.uri=https://tapas-auction-house.86-119-35-40.nip.io
# auction.house.uri=http://a888-77-59-152-182.eu.ngrok.io
tasks.list.uri=http://localhost:8081
application.environment=development

View File

@ -43,7 +43,7 @@ public class ExternalTaskExecutedWebAdapter implements ExternalTaskExecutedEvent
op2 = new JSONObject()
.put("op", "add")
.put("path", "/outputData")
.put("value", externalTaskExecutedEvent.getOutputData());
.put("value", externalTaskExecutedEvent.getOutputData().getValue());
} catch (JSONException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
return;

View File

@ -2,7 +2,7 @@ server.port=8081
spring.data.mongodb.uri=mongodb://root:password@localhost:27017/
spring.data.mongodb.database=tapas-tasks
# baseuri=http://e021-77-59-152-182.ngrok.io/
baseuri=https://tapas-tasks.86-119-34-23.nip.io/
baseuri=https://tapas-tasks.86-119-35-40.nip.io/
roster.uri=http://127.0.0.1:8082