Merging dev to main #107
|
@ -72,15 +72,15 @@ services:
|
|||
volumes:
|
||||
- ./executor-computation/src:/opt/app/src
|
||||
- ./executor-computation/target:/opt/app/target
|
||||
executor-robot:
|
||||
container_name: executor-robot
|
||||
build:
|
||||
context: "."
|
||||
dockerfile: "./executor-robot/Dockerfile"
|
||||
target: development
|
||||
ports:
|
||||
- "8084:8084"
|
||||
- "5009:5005"
|
||||
volumes:
|
||||
- ./executor-robot/src:/opt/app/src
|
||||
- ./executor-robot/target:/opt/app/target
|
||||
# executor-robot:
|
||||
# container_name: executor-robot
|
||||
# build:
|
||||
# context: "."
|
||||
# dockerfile: "./executor-robot/Dockerfile"
|
||||
# target: development
|
||||
# ports:
|
||||
# - "8084:8084"
|
||||
# - "5009:5005"
|
||||
# volumes:
|
||||
# - ./executor-robot/src:/opt/app/src
|
||||
# - ./executor-robot/target:/opt/app/target
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.util.logging.Logger;
|
|||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import ch.unisg.common.valueobject.ExecutorURI;
|
||||
|
@ -49,12 +50,13 @@ public class GetAssignmentAdapter implements GetAssignmentPort {
|
|||
.build();
|
||||
|
||||
try {
|
||||
logger.info("Sending getAssignment Request");
|
||||
logger.info("ExecutorBase | Sending getAssignment request");
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
logger.log(Level.INFO, "getAssignment request result:\n {0}", response.body());
|
||||
if (response.body().equals("")) {
|
||||
if (response.statusCode() != HttpStatus.CREATED.value()) {
|
||||
logger.info("ExecutorBase | No task assigned");
|
||||
return null;
|
||||
}
|
||||
logger.info("ExecutorBase | Task assigned");
|
||||
JSONObject responseBody = new JSONObject(response.body());
|
||||
|
||||
String inputData = responseBody.getString("inputData");
|
||||
|
|
|
@ -13,7 +13,7 @@ public class ExecutorcomputationApplication {
|
|||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(40);
|
||||
TimeUnit.SECONDS.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
server.port=8083
|
||||
|
||||
mqtt.broker.uri=tcp://localhost:1883
|
||||
# mqtt.broker.uri=tcp://localhost:1883
|
||||
mqtt.broker.uri=tcp://broker.hivemq.com
|
||||
|
||||
spring.data.mongodb.uri=mongodb://root:password@localhost:27017
|
||||
spring.data.mongodb.database=tapas-executors
|
||||
|
|
|
@ -33,7 +33,7 @@ public class RosterApplication {
|
|||
SpringApplication rosterApp = new SpringApplication(RosterApplication.class);
|
||||
ENVIRONMENT = rosterApp.run(args).getEnvironment();
|
||||
bootstrapMarketplaceWithMqtt();
|
||||
initialiseRoster();
|
||||
// initialiseRoster();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,8 @@ server.port=8082
|
|||
executor.robot.uri=http://127.0.0.1:8084
|
||||
executor.computation.uri=http://127.0.0.1:8085
|
||||
task.list.uri=http://127.0.0.1:8081
|
||||
mqtt.broker.uri=tcp://localhost:1883
|
||||
# mqtt.broker.uri=tcp://localhost:1883
|
||||
mqtt.broker.uri=tcp://broker.hivemq.com
|
||||
|
||||
spring.data.mongodb.uri=mongodb://root:password@localhost:27017/
|
||||
spring.data.mongodb.database=tapas-roster
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
|||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -36,20 +37,25 @@ public class TapasAuctionHouseApplication {
|
|||
// TODO Set start up of message services with config
|
||||
// We will use these bootstrap methods in Week 6:
|
||||
bootstrapMarketplaceWithWebSub();
|
||||
// bootstrapMarketplaceWithMqtt()
|
||||
//bootstrapMarketplaceWithMqtt();
|
||||
}
|
||||
/**
|
||||
* Discovers auction houses and subscribes to WebSub notifications
|
||||
*/
|
||||
private static void bootstrapMarketplaceWithWebSub() {
|
||||
discoverAuctionHouseEndpoints();
|
||||
// discoverAuctionHouseEndpoints();
|
||||
|
||||
WebSubSubscriber subscriber = new WebSubSubscriber(ENVIRONMENT.getProperty("auction.house.uri"));
|
||||
|
||||
for (AuctionHouseDiscoveryInformation endpoint : AuctionHouseDiscovery.getInstance().getAuctionHouseDiscoveryList()) {
|
||||
subscriber.subscribeToAuctionHouseEndpoint(endpoint.getWebSubUri().getValue());
|
||||
// for (AuctionHouseDiscoveryInformation endpoint : AuctionHouseDiscovery.getInstance().getAuctionHouseDiscoveryList()) {
|
||||
// subscriber.subscribeToAuctionHouseEndpoint(endpoint.getWebSubUri().getValue());
|
||||
// }
|
||||
try {
|
||||
subscriber.subscribeToAuctionHouseEndpoint(new URI("http://6b4e-130-82-250-227.ngrok.io/websub-discovery"));
|
||||
} catch (URISyntaxException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
//subscriber.subscribeToAuctionHouseEndpoint("https://websub.rocks/blog/100/v7wVgkzRrZXTadY3pXjx");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,25 +80,26 @@ public class TapasAuctionHouseApplication {
|
|||
}
|
||||
}
|
||||
|
||||
private static void discoverAuctionHouseEndpoints() {
|
||||
AuctionHouseResourceDirectory rd = new AuctionHouseResourceDirectory(
|
||||
URI.create(ENVIRONMENT.getProperty("discovery.endpoint.uri"))
|
||||
);
|
||||
// private static void discoverAuctionHouseEndpoints() {
|
||||
|
||||
AuctionHouseDiscovery.getInstance().addAuctionHouseDiscoveryInformation(rd.retrieveAuctionHouseEndpoints());
|
||||
// AuctionHouseResourceDirectory rd = new AuctionHouseResourceDirectory(
|
||||
// URI.create(ENVIRONMENT.getProperty("discovery.endpoint.uri"))
|
||||
// );
|
||||
|
||||
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
|
||||
executor.scheduleAtFixedRate(crawlerRunnable, 300, 300, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
||||
private static Runnable crawlerRunnable = new Runnable() {
|
||||
public void run() {
|
||||
AuctionHouseResourceDirectory rd = new AuctionHouseResourceDirectory(
|
||||
URI.create(ENVIRONMENT.getProperty("discovery.endpoint.uri"))
|
||||
);
|
||||
|
||||
AuctionHouseDiscovery.getInstance().addAuctionHouseDiscoveryInformation(rd.retrieveAuctionHouseEndpoints());
|
||||
}
|
||||
};
|
||||
// AuctionHouseDiscovery.getInstance().addAuctionHouseDiscoveryInformation(rd.retrieveAuctionHouseEndpoints());
|
||||
|
||||
// ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
|
||||
// executor.scheduleAtFixedRate(crawlerRunnable, 300, 300, TimeUnit.SECONDS);
|
||||
// }
|
||||
|
||||
|
||||
// private static Runnable crawlerRunnable = new Runnable() {
|
||||
// public void run() {
|
||||
// AuctionHouseResourceDirectory rd = new AuctionHouseResourceDirectory(
|
||||
// URI.create(ENVIRONMENT.getProperty("discovery.endpoint.uri"))
|
||||
// );
|
||||
|
||||
// AuctionHouseDiscovery.getInstance().addAuctionHouseDiscoveryInformation(rd.retrieveAuctionHouseEndpoints());
|
||||
// }
|
||||
// };
|
||||
}
|
||||
|
|
|
@ -38,8 +38,6 @@ public class WebSubSubscriber {
|
|||
|
||||
subscribeToWebSub(links.get("hub"), links.get("self"));
|
||||
|
||||
// Shoudl be done :D
|
||||
// TODO Subscribe to the auction house endpoint via WebSub:
|
||||
// 1. Send a request to the auction house in order to discover the WebSub hub to subscribe to.
|
||||
// The request URI should depend on the design of the Auction House HTTP API.
|
||||
// 2. Send a subscription request to the discovered WebSub hub to subscribe to events relevant
|
||||
|
|
|
@ -3,12 +3,16 @@ package ch.unisg.tapas.auctionhouse.adapter.common.formats;
|
|||
import ch.unisg.tapas.auctionhouse.domain.Auction;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.net.URI;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Used to expose a representation of the state of an auction through an interface. This class is
|
||||
|
@ -60,4 +64,28 @@ public class AuctionJsonRepresentation {
|
|||
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
|
||||
return mapper.writeValueAsString(representation);
|
||||
}
|
||||
|
||||
public static Auction deserialize(String auctionJson) throws JsonProcessingException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode jsonNode = objectMapper.readTree(auctionJson);
|
||||
Auction.AuctionId auctionId = new Auction.AuctionId(jsonNode.get("auctionId").asText());
|
||||
Auction.AuctionHouseUri auctionHouseUri = new Auction.AuctionHouseUri(URI.create(jsonNode.get("auctionHouseUri").asText()));
|
||||
Auction.AuctionedTaskUri taskUri = new Auction.AuctionedTaskUri(URI.create(jsonNode.get("taskUri").asText()));
|
||||
Auction.AuctionedTaskType taskType = new Auction.AuctionedTaskType(jsonNode.get("taskType").asText());
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date parsedDate;
|
||||
try {
|
||||
parsedDate = dateFormat.parse(jsonNode.get("deadline").toString());
|
||||
Timestamp timestamp = new java.sql.Timestamp(parsedDate.getTime());
|
||||
Auction.AuctionDeadline deadline = new Auction.AuctionDeadline(timestamp);
|
||||
|
||||
Auction auction = new Auction(auctionId, auctionHouseUri, taskUri, taskType, deadline);
|
||||
return auction;
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,31 @@
|
|||
package ch.unisg.tapas.auctionhouse.adapter.in.messaging.websub;
|
||||
|
||||
import ch.unisg.tapas.auctionhouse.adapter.common.formats.AuctionJsonRepresentation;
|
||||
import ch.unisg.tapas.auctionhouse.adapter.common.formats.BidJsonRepresentation;
|
||||
import ch.unisg.tapas.auctionhouse.application.handler.AuctionStartedHandler;
|
||||
import ch.unisg.tapas.auctionhouse.application.port.in.AuctionStartedEvent;
|
||||
import ch.unisg.tapas.auctionhouse.domain.Auction;
|
||||
import ch.unisg.tapas.auctionhouse.domain.Bid;
|
||||
import ch.unisg.tapas.auctionhouse.domain.Auction.AuctionDeadline;
|
||||
import ch.unisg.tapas.auctionhouse.domain.Auction.AuctionHouseUri;
|
||||
import ch.unisg.tapas.auctionhouse.domain.Auction.AuctionId;
|
||||
import ch.unisg.tapas.auctionhouse.domain.Auction.AuctionedTaskType;
|
||||
import ch.unisg.tapas.auctionhouse.domain.Auction.AuctionedTaskUri;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.security.Timestamp;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -36,21 +47,87 @@ public class AuctionStartedEventListenerWebSubAdapter {
|
|||
**/
|
||||
// TODO generate a new capability ID instead of using a hardcoded one.
|
||||
@PostMapping(path = "/auction-started/74c72c7f-2739-4124-aa35-a3225171a97c")
|
||||
public ResponseEntity<Void> handleExecutorAddedEvent(@RequestBody Collection<AuctionJsonRepresentation> payload) throws URISyntaxException {
|
||||
public ResponseEntity<Void> handleExecutorAddedEvent(@RequestBody String payload) throws URISyntaxException {
|
||||
|
||||
System.out.println("new auctions :O");
|
||||
System.out.println(payload);
|
||||
|
||||
for (AuctionJsonRepresentation auction : payload) {
|
||||
auctionStartedHandler.handleAuctionStartedEvent(
|
||||
new AuctionStartedEvent(
|
||||
new Auction(new AuctionId(auction.getAuctionId()),
|
||||
new AuctionHouseUri(new URI(auction.getAuctionHouseUri())),
|
||||
new AuctionedTaskUri(new URI(auction.getTaskUri())),
|
||||
new AuctionedTaskType(auction.getTaskType()),
|
||||
new AuctionDeadline(auction.getDeadline()))
|
||||
));
|
||||
|
||||
JSONArray auctions = new JSONArray(payload);
|
||||
if (auctions.length() > 0) {
|
||||
JSONObject auction = auctions.getJSONObject(0);
|
||||
System.out.print(auction);
|
||||
// try {
|
||||
// System.out.println(auction.getString("deadline"));
|
||||
// System.out.println(AuctionJsonRepresentation.deserialize(auction.toString()));
|
||||
|
||||
// auctionStartedHandler.handleAuctionStartedEvent(
|
||||
// new AuctionStartedEvent(AuctionJsonRepresentation.deserialize(auction.toString())));
|
||||
// } catch (JsonProcessingException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
|
||||
// String auctionHouseURI = "https://tapas-auction-house.86-119-35-40.nip.io/";
|
||||
String auctionHouseURI = "http://b311-130-82-247-153.eu.ngrok.io";
|
||||
|
||||
// String taskListURI = "https://tapas-tasks.86-119-35-40.nip.io";
|
||||
String taskListURI = "http://c64f-130-82-247-153.ngrok.io";
|
||||
|
||||
// TODO Sanitize URIs
|
||||
String auctionId = auction.getString("auctionId");
|
||||
String auctionHouseUri = auction.getString("auctionHouseUri");
|
||||
String taskUri = auction.getString("taskUri");
|
||||
String taskType = auction.getString("taskType");
|
||||
String deadline = auction.getString("deadline");
|
||||
|
||||
var bid = new Bid(
|
||||
new Auction.AuctionId(auctionId),
|
||||
new Bid.BidderName("Group-1"),
|
||||
new Bid.BidderAuctionHouseUri(URI.create(auctionHouseURI)),
|
||||
new Bid.BidderTaskListUri(URI.create(taskListURI))
|
||||
);
|
||||
|
||||
String body;
|
||||
try {
|
||||
body = BidJsonRepresentation.serialize(bid);
|
||||
//LOGGER.info(body);
|
||||
var postURI = URI.create(auctionHouseUri + "/bid");
|
||||
HttpRequest postRequest = HttpRequest.newBuilder()
|
||||
.uri(postURI)
|
||||
.header("Content-Type", BidJsonRepresentation.MEDIA_TYPE)
|
||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||
.build();
|
||||
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
var postResponse = client.send(postRequest, HttpResponse.BodyHandlers.ofString());
|
||||
} catch (JsonProcessingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
//LOGGER.info(postResponse.statusCode());
|
||||
};
|
||||
|
||||
// for (JSONObject auction : auctions) {
|
||||
// auctionStartedHandler.handleAuctionStartedEvent(
|
||||
// new AuctionStartedEvent(
|
||||
// new Auction(new AuctionId(auction.getAuctionId()),
|
||||
// new AuctionHouseUri(new URI(auction.getAuctionHouseUri())),
|
||||
// new AuctionedTaskUri(new URI(auction.getTaskUri())),
|
||||
// new AuctionedTaskType(auction.getTaskType()),
|
||||
// new AuctionDeadline(auction.getDeadline()))
|
||||
// ));
|
||||
// }
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public class DiscoverWebSubAdapter {
|
|||
private String auctionHouseUri;
|
||||
|
||||
/**
|
||||
* Controller which listens to auction-started callbacks
|
||||
* Controller to discover our websub topic
|
||||
* @return 200 OK
|
||||
**/
|
||||
@GetMapping(path = "/websub/auctions")
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.springframework.context.annotation.Primary;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
// @Primary
|
||||
public class PublishAuctionStartedEventMqttAdapter implements AuctionStartedEventPort {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(PublishAuctionStartedEventMqttAdapter.class);
|
||||
|
|
|
@ -35,6 +35,7 @@ public class PublishAuctionStartedEventWebSubAdapter implements AuctionStartedEv
|
|||
|
||||
String body = "hub.url=" + auctionHouseUri + "/auctions/&hub.mode=publish";
|
||||
|
||||
logger.info("Auctions updated:" + body);
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(webSubHubUri))
|
||||
|
@ -45,6 +46,7 @@ public class PublishAuctionStartedEventWebSubAdapter implements AuctionStartedEv
|
|||
|
||||
try {
|
||||
client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
logger.info("WEBSUB send successfuly");
|
||||
} catch (InterruptedException e) {
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
|
|
|
@ -43,6 +43,7 @@ public class AuctionWonEventHttpAdapter implements AuctionWonEventPort {
|
|||
.uri(auction.get().getTaskUri().getValue())
|
||||
.GET()
|
||||
.build();
|
||||
|
||||
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
LOGGER.info(response.body());
|
||||
JSONObject responseBody = new JSONObject(response.body());
|
||||
|
|
|
@ -21,7 +21,7 @@ public class AuctionHouseDiscovery {
|
|||
};
|
||||
|
||||
// TODO load from config
|
||||
static String AUCTION_HOUSE_URI = "http://localhost:8086";
|
||||
// static String AUCTION_HOUSE_URI = "http://localhost:8086";
|
||||
|
||||
@Getter
|
||||
private List<AuctionHouseDiscoveryInformation> auctionHouseDiscoveryList = new ArrayList<>() {
|
||||
|
@ -31,8 +31,8 @@ public class AuctionHouseDiscovery {
|
|||
try {
|
||||
// Add our information to list
|
||||
auctionHouseDiscoveryList.add(new AuctionHouseDiscoveryInformation(
|
||||
new AuctionHouseDiscoveryInformation.AuctionHouseUri(new URI(AUCTION_HOUSE_URI)),
|
||||
new AuctionHouseDiscoveryInformation.WebSubUri(new URI(AUCTION_HOUSE_URI + "/websub/auctions")),
|
||||
new AuctionHouseDiscoveryInformation.AuctionHouseUri(new URI("http://localhost:8086")),
|
||||
new AuctionHouseDiscoveryInformation.WebSubUri(new URI("http://localhost:8086/websub/auctions")),
|
||||
new AuctionHouseDiscoveryInformation.TaskTypes(tasktypes),
|
||||
new AuctionHouseDiscoveryInformation.TimeStamp(new Timestamp(new Date().getTime())),
|
||||
new AuctionHouseDiscoveryInformation.GroupName("Group 1")
|
||||
|
|
|
@ -11,6 +11,7 @@ tasks.list.uri=http://localhost:8081
|
|||
|
||||
application.environment=development
|
||||
websub.hub.uri=https://pubsubhubbub.appspot.com
|
||||
mqtt.broker.uri=tcp://localhost:1883
|
||||
mqtt.broker.uri=tcp://broker.hivemq.com
|
||||
# mqtt.broker.uri=tcp://localhost:1883
|
||||
|
||||
discovery.endpoint.uri=http://localhost:3500/discovery/
|
||||
discovery.endpoint.uri=http://localhost:3500
|
||||
|
|
Loading…
Reference in New Issue
Block a user