diff --git a/.deployment/docker-compose.yml b/.deployment/docker-compose.yml index 5a1329f..3fe4c2a 100644 --- a/.deployment/docker-compose.yml +++ b/.deployment/docker-compose.yml @@ -95,6 +95,9 @@ services: - roster volumes: - ./:/data/ + environment: + - executor_pool_uri: "executor-pool.86-119-35-40.nip.io" + - roster_uri: "roster.86-119-35-40.nip.io" labels: - "traefik.enable=true" - "traefik.http.routers.executor-computation.rule=Host(`executor-computation.${PUB_IP}.nip.io`)" @@ -103,7 +106,6 @@ services: - "traefik.http.routers.executor-computation.tls=true" - "traefik.http.routers.executor-computation.entryPoints=web,websecure" - "traefik.http.routers.executor-computation.tls.certresolver=le" - executor-robot: image: openjdk command: "java -jar /data/executor-robot-0.0.1-SNAPSHOT.jar" @@ -113,6 +115,9 @@ services: - roster volumes: - ./:/data/ + environment: + - executor_pool_uri: "executor-pool.86-119-35-40.nip.io" + - roster_uri: "roster.86-119-35-40.nip.io" labels: - "traefik.enable=true" - "traefik.http.routers.executor-robot.rule=Host(`executor-robot.${PUB_IP}.nip.io`)" diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/ExecutionFinishedEventAdapter.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/ExecutionFinishedEventAdapter.java index e618c79..4321f72 100644 --- a/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/ExecutionFinishedEventAdapter.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/ExecutionFinishedEventAdapter.java @@ -9,16 +9,15 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.json.JSONObject; -import org.springframework.beans.factory.annotation.Value; import ch.unisg.executorbase.executor.application.port.out.ExecutionFinishedEventPort; import ch.unisg.executorbase.executor.domain.ExecutionFinishedEvent; public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort { - // TODO url doesn't get mapped bc no autowiring - @Value("${roster.url}") - String server = "http://localhost:8082"; + String server = System.getenv("roster_uri") == null ? + "http://localhost:8082" : System.getenv("roster_uri"); + Logger logger = Logger.getLogger(ExecutionFinishedEventAdapter.class.getName()); diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/GetAssignmentAdapter.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/GetAssignmentAdapter.java index 92cea92..9d8013b 100644 --- a/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/GetAssignmentAdapter.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/GetAssignmentAdapter.java @@ -23,9 +23,8 @@ import org.json.JSONObject; @Primary public class GetAssignmentAdapter implements GetAssignmentPort { - // TODO Not working for now bc it doesn't get autowired - @Value("${roster.url}") - String server = "http://127.0.0.1:8082"; + String server = System.getenv("roster_uri") == null ? + "http://localhost:8082" : System.getenv("roster_uri"); Logger logger = Logger.getLogger(GetAssignmentAdapter.class.getName()); diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/NotifyExecutorPoolAdapter.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/NotifyExecutorPoolAdapter.java index abc0cf5..ebb6fc6 100644 --- a/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/NotifyExecutorPoolAdapter.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/adapter/out/web/NotifyExecutorPoolAdapter.java @@ -22,9 +22,8 @@ import ch.unisg.executorbase.executor.domain.ExecutorType; @Primary public class NotifyExecutorPoolAdapter implements NotifyExecutorPoolPort { - // TODO Not working for now bc it doesn't get autowired - @Value("${executor.pool.url}") - String server = "http://127.0.0.1:8083"; + String server = System.getenv("executor_pool_uri") == null ? + "http://localhost:8083" : System.getenv("executor_pool_uri"); Logger logger = Logger.getLogger(NotifyExecutorPoolAdapter.class.getName()); @@ -35,6 +34,8 @@ public class NotifyExecutorPoolAdapter implements NotifyExecutorPoolPort { @Override public boolean notifyExecutorPool(ExecutorURI executorURI, ExecutorType executorType) { + System.out.println(server); + String body = new JSONObject() .put("executorTaskType", executorType) .put("executorUri", executorURI.getValue()) diff --git a/tapas-auction-house/pom.xml b/tapas-auction-house/pom.xml index df44681..dd29302 100644 --- a/tapas-auction-house/pom.xml +++ b/tapas-auction-house/pom.xml @@ -46,7 +46,7 @@ org.eclipse.paho org.eclipse.paho.client.mqttv3 - 1.2.0 + 1.2.5 javax.transaction diff --git a/tapas-auction-house/src/main/java/ch/unisg/tapas/TapasAuctionHouseApplication.java b/tapas-auction-house/src/main/java/ch/unisg/tapas/TapasAuctionHouseApplication.java index 18c7631..9fe963e 100644 --- a/tapas-auction-house/src/main/java/ch/unisg/tapas/TapasAuctionHouseApplication.java +++ b/tapas-auction-house/src/main/java/ch/unisg/tapas/TapasAuctionHouseApplication.java @@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.core.env.ConfigurableEnvironment; import java.net.URI; import java.util.List; @@ -23,20 +24,19 @@ import java.util.List; public class TapasAuctionHouseApplication { private static final Logger LOGGER = LogManager.getLogger(TapasAuctionHouseApplication.class); - @Autowired - private ConfigProperties config; - public static String RESOURCE_DIRECTORY = "https://api.interactions.ics.unisg.ch/auction-houses/"; - public static String MQTT_BROKER = "tcp://broker.hivemq.com:1883"; + public static String DEFAULT_MQTT_BROKER = "tcp://broker.hivemq.com:1883"; + + private static ConfigurableEnvironment ENVIRONMENT; public static void main(String[] args) { SpringApplication tapasAuctioneerApp = new SpringApplication(TapasAuctionHouseApplication.class); + ENVIRONMENT = tapasAuctioneerApp.run(args).getEnvironment(); + // TODO Set start up of message services with config // We will use these bootstrap methods in Week 6: - bootstrapMarketplaceWithWebSub(); + // bootstrapMarketplaceWithWebSub(); bootstrapMarketplaceWithMqtt(); - - tapasAuctioneerApp.run(args); } /** * Discovers auction houses and subscribes to WebSub notifications @@ -57,8 +57,16 @@ public class TapasAuctionHouseApplication { */ private static void bootstrapMarketplaceWithMqtt() { try { + String broker = ENVIRONMENT.getProperty("mqtt.broker.uri"); + + if (broker == null) { + broker = DEFAULT_MQTT_BROKER; + LOGGER.info("No MQTT broker was set in application.propreties, going with default: " + + DEFAULT_MQTT_BROKER); + } + AuctionEventsMqttDispatcher dispatcher = new AuctionEventsMqttDispatcher(); - TapasMqttClient client = TapasMqttClient.getInstance(MQTT_BROKER, dispatcher); + TapasMqttClient client = TapasMqttClient.getInstance(broker, dispatcher); client.startReceivingMessages(); } catch (MqttException e) { LOGGER.error(e.getMessage(), e); diff --git a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/in/messaging/mqtt/ExternalAuctionStartedEventListenerMqttAdapter.java b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/in/messaging/mqtt/ExternalAuctionStartedEventListenerMqttAdapter.java index 13374cc..c47acad 100644 --- a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/in/messaging/mqtt/ExternalAuctionStartedEventListenerMqttAdapter.java +++ b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/in/messaging/mqtt/ExternalAuctionStartedEventListenerMqttAdapter.java @@ -38,6 +38,7 @@ public class ExternalAuctionStartedEventListenerMqttAdapter extends AuctionEvent // representation that makes sense in the context of your application. JsonNode data = new ObjectMapper().readTree(payload); + // TODO Sanitize URIs String auctionId = data.get("auctionId").asText(); String auctionHouseUri = data.get("auctionHouseUri").asText(); String taskUri = data.get("taskUri").asText(); @@ -72,8 +73,12 @@ public class ExternalAuctionStartedEventListenerMqttAdapter extends AuctionEvent LOGGER.error(e.getMessage(), e); return false; } catch (IOException e) { + + LOGGER.error(e.getMessage(), e); e.printStackTrace(); } catch (InterruptedException e) { + + LOGGER.error(e.getMessage(), e); e.printStackTrace(); } catch (Exception e){ LOGGER.error(e.getMessage(), e); diff --git a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/in/web/AddBidWebController.java b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/in/web/AddBidWebController.java index 3431c8d..41e65ff 100644 --- a/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/in/web/AddBidWebController.java +++ b/tapas-auction-house/src/main/java/ch/unisg/tapas/auctionhouse/adapter/in/web/AddBidWebController.java @@ -2,10 +2,13 @@ package ch.unisg.tapas.auctionhouse.adapter.in.web; import ch.unisg.tapas.auctionhouse.adapter.common.formats.AuctionJsonRepresentation; import ch.unisg.tapas.auctionhouse.adapter.common.formats.BidJsonRepresentation; +import ch.unisg.tapas.auctionhouse.adapter.in.messaging.mqtt.BidReceivedEventListenerMqttAdapter; import ch.unisg.tapas.auctionhouse.application.handler.BidReceivedHandler; import ch.unisg.tapas.auctionhouse.application.port.in.BidReceivedEvent; import ch.unisg.tapas.auctionhouse.domain.Auction; import ch.unisg.tapas.auctionhouse.domain.Bid; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -18,6 +21,8 @@ import java.net.URI; // TODO Fix structure due to MQTT @RestController public class AddBidWebController { + private static final Logger LOGGER = LogManager.getLogger(AddBidWebController.class); + @PostMapping(path = "/bid", consumes = BidJsonRepresentation.MEDIA_TYPE) public ResponseEntity addBid(@RequestBody BidJsonRepresentation payload) { BidReceivedEvent bidReceivedEvent = new BidReceivedEvent(new Bid( @@ -27,6 +32,8 @@ public class AddBidWebController { new Bid.BidderTaskListUri(URI.create(payload.getBidderTaskListUri())) )); + LOGGER.info("Bid received", payload); + BidReceivedHandler bidReceivedHandler = new BidReceivedHandler(); bidReceivedHandler.handleNewBidReceivedEvent(bidReceivedEvent); diff --git a/tapas-auction-house/src/main/resources/application.properties b/tapas-auction-house/src/main/resources/application.properties index 7f8ca02..e3900bd 100644 --- a/tapas-auction-house/src/main/resources/application.properties +++ b/tapas-auction-house/src/main/resources/application.properties @@ -10,4 +10,4 @@ tasks.list.uri=http://localhost:8081 application.environment=development auctionhouse.uri=http://localhost:8086 websub.hub.uri=http://localhost:3000 -mqtt.broker.uri=tcp://localhost:1883 +mqtt.broker.uri=tcp://broker.hivemq.com:1883 diff --git a/tapas-tasks/pom.xml b/tapas-tasks/pom.xml index 39e1e67..715b947 100644 --- a/tapas-tasks/pom.xml +++ b/tapas-tasks/pom.xml @@ -75,7 +75,7 @@ org.eclipse.paho org.eclipse.paho.client.mqttv3 - 1.2.0 + 1.2.5