From b6488fa36f2036d717388b42494f13c703e63336 Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 16 Nov 2021 21:17:10 +0100 Subject: [PATCH 1/4] added environment variables for uri's --- .deployment/docker-compose.yml | 7 ++++++- .../adapter/out/web/ExecutionFinishedEventAdapter.java | 7 +++---- .../executor/adapter/out/web/GetAssignmentAdapter.java | 5 ++--- .../adapter/out/web/NotifyExecutorPoolAdapter.java | 7 ++++--- 4 files changed, 15 insertions(+), 11 deletions(-) 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()) -- 2.45.1 From add257fd5e08d734a648902d250296222865398e Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 16 Nov 2021 21:20:26 +0100 Subject: [PATCH 2/4] updated dependencies to remove security issues --- tapas-auction-house/pom.xml | 2 +- tapas-tasks/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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-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 -- 2.45.1 From 01b5056671f8b0690b533ecebe7b696b9b80f523 Mon Sep 17 00:00:00 2001 From: reynisson Date: Wed, 17 Nov 2021 18:25:49 +0100 Subject: [PATCH 3/4] Testing out getting Environment variables from main --- .../tapas/TapasAuctionHouseApplication.java | 24 ++++++++++++------- ...uctionStartedEventListenerMqttAdapter.java | 5 ++++ .../src/main/resources/application.properties | 2 +- 3 files changed, 22 insertions(+), 9 deletions(-) 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/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 -- 2.45.1 From 9d8e6cf2160c06eeccde80a25930b08df1979ed6 Mon Sep 17 00:00:00 2001 From: reynisson Date: Wed, 17 Nov 2021 18:29:08 +0100 Subject: [PATCH 4/4] Logging bids received --- .../auctionhouse/adapter/in/web/AddBidWebController.java | 7 +++++++ 1 file changed, 7 insertions(+) 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); -- 2.45.1