Merge pull request #72 from SCS-ASSE-FS21-Group1/dev

Bugfixes + Security fixes
This commit is contained in:
reynisson 2021-11-17 18:29:37 +01:00 committed by GitHub
commit 1e917ec3e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 46 additions and 22 deletions

View File

@ -95,6 +95,9 @@ services:
- roster - roster
volumes: volumes:
- ./:/data/ - ./:/data/
environment:
- executor_pool_uri: "executor-pool.86-119-35-40.nip.io"
- roster_uri: "roster.86-119-35-40.nip.io"
labels: labels:
- "traefik.enable=true" - "traefik.enable=true"
- "traefik.http.routers.executor-computation.rule=Host(`executor-computation.${PUB_IP}.nip.io`)" - "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.tls=true"
- "traefik.http.routers.executor-computation.entryPoints=web,websecure" - "traefik.http.routers.executor-computation.entryPoints=web,websecure"
- "traefik.http.routers.executor-computation.tls.certresolver=le" - "traefik.http.routers.executor-computation.tls.certresolver=le"
executor-robot: executor-robot:
image: openjdk image: openjdk
command: "java -jar /data/executor-robot-0.0.1-SNAPSHOT.jar" command: "java -jar /data/executor-robot-0.0.1-SNAPSHOT.jar"
@ -113,6 +115,9 @@ services:
- roster - roster
volumes: volumes:
- ./:/data/ - ./:/data/
environment:
- executor_pool_uri: "executor-pool.86-119-35-40.nip.io"
- roster_uri: "roster.86-119-35-40.nip.io"
labels: labels:
- "traefik.enable=true" - "traefik.enable=true"
- "traefik.http.routers.executor-robot.rule=Host(`executor-robot.${PUB_IP}.nip.io`)" - "traefik.http.routers.executor-robot.rule=Host(`executor-robot.${PUB_IP}.nip.io`)"

View File

@ -9,16 +9,15 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.json.JSONObject; 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.application.port.out.ExecutionFinishedEventPort;
import ch.unisg.executorbase.executor.domain.ExecutionFinishedEvent; import ch.unisg.executorbase.executor.domain.ExecutionFinishedEvent;
public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort { public class ExecutionFinishedEventAdapter implements ExecutionFinishedEventPort {
// TODO url doesn't get mapped bc no autowiring String server = System.getenv("roster_uri") == null ?
@Value("${roster.url}") "http://localhost:8082" : System.getenv("roster_uri");
String server = "http://localhost:8082";
Logger logger = Logger.getLogger(ExecutionFinishedEventAdapter.class.getName()); Logger logger = Logger.getLogger(ExecutionFinishedEventAdapter.class.getName());

View File

@ -23,9 +23,8 @@ import org.json.JSONObject;
@Primary @Primary
public class GetAssignmentAdapter implements GetAssignmentPort { public class GetAssignmentAdapter implements GetAssignmentPort {
// TODO Not working for now bc it doesn't get autowired String server = System.getenv("roster_uri") == null ?
@Value("${roster.url}") "http://localhost:8082" : System.getenv("roster_uri");
String server = "http://127.0.0.1:8082";
Logger logger = Logger.getLogger(GetAssignmentAdapter.class.getName()); Logger logger = Logger.getLogger(GetAssignmentAdapter.class.getName());

View File

@ -22,9 +22,8 @@ import ch.unisg.executorbase.executor.domain.ExecutorType;
@Primary @Primary
public class NotifyExecutorPoolAdapter implements NotifyExecutorPoolPort { public class NotifyExecutorPoolAdapter implements NotifyExecutorPoolPort {
// TODO Not working for now bc it doesn't get autowired String server = System.getenv("executor_pool_uri") == null ?
@Value("${executor.pool.url}") "http://localhost:8083" : System.getenv("executor_pool_uri");
String server = "http://127.0.0.1:8083";
Logger logger = Logger.getLogger(NotifyExecutorPoolAdapter.class.getName()); Logger logger = Logger.getLogger(NotifyExecutorPoolAdapter.class.getName());
@ -35,6 +34,8 @@ public class NotifyExecutorPoolAdapter implements NotifyExecutorPoolPort {
@Override @Override
public boolean notifyExecutorPool(ExecutorURI executorURI, ExecutorType executorType) { public boolean notifyExecutorPool(ExecutorURI executorURI, ExecutorType executorType) {
System.out.println(server);
String body = new JSONObject() String body = new JSONObject()
.put("executorTaskType", executorType) .put("executorTaskType", executorType)
.put("executorUri", executorURI.getValue()) .put("executorUri", executorURI.getValue())

View File

@ -46,7 +46,7 @@
<dependency> <dependency>
<groupId>org.eclipse.paho</groupId> <groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId> <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.0</version> <version>1.2.5</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.transaction</groupId> <groupId>javax.transaction</groupId>

View File

@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.ConfigurableEnvironment;
import java.net.URI; import java.net.URI;
import java.util.List; import java.util.List;
@ -23,20 +24,19 @@ import java.util.List;
public class TapasAuctionHouseApplication { public class TapasAuctionHouseApplication {
private static final Logger LOGGER = LogManager.getLogger(TapasAuctionHouseApplication.class); 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 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) { public static void main(String[] args) {
SpringApplication tapasAuctioneerApp = new SpringApplication(TapasAuctionHouseApplication.class); 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: // We will use these bootstrap methods in Week 6:
bootstrapMarketplaceWithWebSub(); // bootstrapMarketplaceWithWebSub();
bootstrapMarketplaceWithMqtt(); bootstrapMarketplaceWithMqtt();
tapasAuctioneerApp.run(args);
} }
/** /**
* Discovers auction houses and subscribes to WebSub notifications * Discovers auction houses and subscribes to WebSub notifications
@ -57,8 +57,16 @@ public class TapasAuctionHouseApplication {
*/ */
private static void bootstrapMarketplaceWithMqtt() { private static void bootstrapMarketplaceWithMqtt() {
try { 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(); AuctionEventsMqttDispatcher dispatcher = new AuctionEventsMqttDispatcher();
TapasMqttClient client = TapasMqttClient.getInstance(MQTT_BROKER, dispatcher); TapasMqttClient client = TapasMqttClient.getInstance(broker, dispatcher);
client.startReceivingMessages(); client.startReceivingMessages();
} catch (MqttException e) { } catch (MqttException e) {
LOGGER.error(e.getMessage(), e); LOGGER.error(e.getMessage(), e);

View File

@ -38,6 +38,7 @@ public class ExternalAuctionStartedEventListenerMqttAdapter extends AuctionEvent
// representation that makes sense in the context of your application. // representation that makes sense in the context of your application.
JsonNode data = new ObjectMapper().readTree(payload); JsonNode data = new ObjectMapper().readTree(payload);
// TODO Sanitize URIs
String auctionId = data.get("auctionId").asText(); String auctionId = data.get("auctionId").asText();
String auctionHouseUri = data.get("auctionHouseUri").asText(); String auctionHouseUri = data.get("auctionHouseUri").asText();
String taskUri = data.get("taskUri").asText(); String taskUri = data.get("taskUri").asText();
@ -72,8 +73,12 @@ public class ExternalAuctionStartedEventListenerMqttAdapter extends AuctionEvent
LOGGER.error(e.getMessage(), e); LOGGER.error(e.getMessage(), e);
return false; return false;
} catch (IOException e) { } catch (IOException e) {
LOGGER.error(e.getMessage(), e);
e.printStackTrace(); e.printStackTrace();
} catch (InterruptedException e) { } catch (InterruptedException e) {
LOGGER.error(e.getMessage(), e);
e.printStackTrace(); e.printStackTrace();
} catch (Exception e){ } catch (Exception e){
LOGGER.error(e.getMessage(), e); LOGGER.error(e.getMessage(), e);

View File

@ -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.AuctionJsonRepresentation;
import ch.unisg.tapas.auctionhouse.adapter.common.formats.BidJsonRepresentation; 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.handler.BidReceivedHandler;
import ch.unisg.tapas.auctionhouse.application.port.in.BidReceivedEvent; import ch.unisg.tapas.auctionhouse.application.port.in.BidReceivedEvent;
import ch.unisg.tapas.auctionhouse.domain.Auction; import ch.unisg.tapas.auctionhouse.domain.Auction;
import ch.unisg.tapas.auctionhouse.domain.Bid; 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.HttpHeaders;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -18,6 +21,8 @@ import java.net.URI;
// TODO Fix structure due to MQTT // TODO Fix structure due to MQTT
@RestController @RestController
public class AddBidWebController { public class AddBidWebController {
private static final Logger LOGGER = LogManager.getLogger(AddBidWebController.class);
@PostMapping(path = "/bid", consumes = BidJsonRepresentation.MEDIA_TYPE) @PostMapping(path = "/bid", consumes = BidJsonRepresentation.MEDIA_TYPE)
public ResponseEntity<String> addBid(@RequestBody BidJsonRepresentation payload) { public ResponseEntity<String> addBid(@RequestBody BidJsonRepresentation payload) {
BidReceivedEvent bidReceivedEvent = new BidReceivedEvent(new Bid( BidReceivedEvent bidReceivedEvent = new BidReceivedEvent(new Bid(
@ -27,6 +32,8 @@ public class AddBidWebController {
new Bid.BidderTaskListUri(URI.create(payload.getBidderTaskListUri())) new Bid.BidderTaskListUri(URI.create(payload.getBidderTaskListUri()))
)); ));
LOGGER.info("Bid received", payload);
BidReceivedHandler bidReceivedHandler = new BidReceivedHandler(); BidReceivedHandler bidReceivedHandler = new BidReceivedHandler();
bidReceivedHandler.handleNewBidReceivedEvent(bidReceivedEvent); bidReceivedHandler.handleNewBidReceivedEvent(bidReceivedEvent);

View File

@ -10,4 +10,4 @@ tasks.list.uri=http://localhost:8081
application.environment=development application.environment=development
auctionhouse.uri=http://localhost:8086 auctionhouse.uri=http://localhost:8086
websub.hub.uri=http://localhost:3000 websub.hub.uri=http://localhost:3000
mqtt.broker.uri=tcp://localhost:1883 mqtt.broker.uri=tcp://broker.hivemq.com:1883

View File

@ -75,7 +75,7 @@
<dependency> <dependency>
<groupId>org.eclipse.paho</groupId> <groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId> <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.0</version> <version>1.2.5</version>
</dependency> </dependency>
<dependency> <dependency>