Skip to content

Commit

Permalink
Design high-level system and create modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
hippalus committed Jul 16, 2023
1 parent bb7a456 commit cdba7c9
Show file tree
Hide file tree
Showing 32 changed files with 5,406 additions and 27 deletions.
Binary file added .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.3/apache-maven-3.9.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@ Outages.xml is the feed itself - it contains test data that needs to be processe
# Tips

- Choose your libraries right - if you get stuck with one, try another solution
- Parsing and producing correct JSON files is the most important, if you are running out of time, you can skip comparing your JSONs against the reference files
- Parsing and producing correct JSON files is the most important, if you are running out of time, you can skip comparing your
JSONs against the reference files
- If you have questions regarding the project or something is not clear you can let us know

# Disclaimer

This programming challenge is one step in a multiple step hiring process. It is a means to assess the competency of our candidates.
The work you will do - including writing code and/or designing software - is NOT going to be reused, copied or in any form replicated by us or any of our third parties.
This programming challenge is one step in a multiple step hiring process. It is a means to assess the competency of our
candidates.
The work you will do - including writing code and/or designing software - is NOT going to be reused, copied or in any form
replicated by us or any of our third parties.
If you have any concerns - related to what is stated above or the programming challenge itself - please contact us.

## Architecture and Design Choices

![system-design.png](docs%2Fsystem-design.png)
95 changes: 95 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
version: "3.8"

services:

kafka:
image: confluentinc/cp-kafka:7.3.1
hostname: kafka
container_name: kafka
ports:
- "9092:9092"
- "9101:9101"
environment:
KAFKA_BROKER_ID: 1
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: 'CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT'
KAFKA_ADVERTISED_LISTENERS: 'PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092'
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_JMX_PORT: 9101
KAFKA_JMX_HOSTNAME: localhost
KAFKA_PROCESS_ROLES: 'broker,controller'
KAFKA_NODE_ID: 1
KAFKA_CONTROLLER_QUORUM_VOTERS: '1@kafka:29093'
KAFKA_LISTENERS: 'PLAINTEXT://kafka:29092,CONTROLLER://kafka:29093,PLAINTEXT_HOST://0.0.0.0:9092'
KAFKA_INTER_BROKER_LISTENER_NAME: 'PLAINTEXT'
KAFKA_CONTROLLER_LISTENER_NAMES: 'CONTROLLER'
KAFKA_LOG_DIRS: '/tmp/kraft-combined-logs'
volumes:
- kafka-data:/var/lib/kafka/data
- ./scripts/update_run.sh:/tmp/update_run.sh
command: "bash -c 'if [ ! -f /tmp/update_run.sh ]; then echo \"ERROR: Did you forget the update_run.sh file that came with this docker-compose.yml file?\" && exit 1 ; else /tmp/update_run.sh && /etc/confluent/docker/run ; fi'"

kafka-connect:
image: confluentinc/cp-kafka-connect:7.3.1
hostname: kafka-connect
container_name: kafka-connect
depends_on:
- kafka
ports:
- "8083:8083"
environment:
# Kafka Connect configuration parameters
CONNECT_BOOTSTRAP_SERVERS: 'kafka:29092'
CONNECT_REST_PORT: 8083
CONNECT_GROUP_ID: 'connect-cluster'
CONNECT_CONFIG_STORAGE_TOPIC: '_connect_configs'
CONNECT_OFFSET_STORAGE_TOPIC: '_connect_offset'
CONNECT_STATUS_STORAGE_TOPIC: '_connect_status'
CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR: "1"
CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR: "1"
CONNECT_STATUS_STORAGE_REPLICATION_FACTOR: "1"
CONNECT_KEY_CONVERTER: 'org.apache.kafka.connect.json.JsonConverter'
CONNECT_VALUE_CONVERTER: 'org.apache.kafka.connect.json.JsonConverter'
CONNECT_KEY_CONVERTER_SCHEMAS_ENABLE: 'false'
CONNECT_VALUE_CONVERTER_SCHEMAS_ENABLE: 'false'
CONNECT_REST_ADVERTISED_HOST_NAME: 'kafka-connect'
CONNECT_LOG4J_LOGGERS: 'org.apache.kafka.connect.runtime.rest=WARN,org.reflections=ERROR'
CONNECT_INTERNAL_KEY_CONVERTER: 'org.apache.kafka.connect.json.JsonConverter'
CONNECT_INTERNAL_VALUE_CONVERTER: 'org.apache.kafka.connect.json.JsonConverter'
CONNECT_PLUGIN_PATH: "/usr/share/java,/usr/share/confluent-hub-components"
CONNECT_LISTENERS: "http://kafka-connect:8083"
volumes:
- ./connect/configs/jars:/etc/kafka-connect/jars

kafka-ui:
image: provectuslabs/kafka-ui:latest
hostname: kafka-ui
container_name: kafka-ui
ports:
- "8084:8080"
depends_on:
- kafka
environment:
KAFKA_CLUSTERS_0_NAME: local
KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:29092
KAFKA_CLUSTERS_0_KAFKACONNECT_0_NAME: local
KAFKA_CLUSTERS_0_KAFKACONNECT_0_ADDRESS: http://kafka-connect:8083

feed-simulator:
build:
context: ./feed-simulator
dockerfile: Dockerfile
target: production
labels:
container-name: feed-simulator
hostname: feed-simulator
container_name: feed-simulator
ports:
- "8090:8090"
volumes:
- ../:/production

volumes:
kafka-data:
Binary file added docs/system-design.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions feed-simulator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
34 changes: 34 additions & 0 deletions feed-simulator/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM maven:3.8.5-openjdk-17 as module-build

WORKDIR /module/app

COPY . .

RUN mvn clean install -DskipTests=true


FROM openjdk:17.0.2-jdk-slim as production

USER root

RUN apt-get update -y && apt-get install -y jq curl

USER 1000

WORKDIR /app

COPY --from=module-build --chown=1000:1000 /module/app/target/feed-simulator-0.0.1-SNAPSHOT.jar ./feed-simulator-0.0.1-SNAPSHOT.jar

ENTRYPOINT ["java", "-jar", "feed-simulator-0.0.1-SNAPSHOT.jar"]

FROM production as development

USER root

COPY --from=module-build /usr/share/maven /usr/share/maven
COPY --from=module-build --chown=1000:1000 /module/app /development
COPY --from=module-build --chown=1000:1000 /root/.m2 /opt/jboss/.m2

RUN ln -s /usr/share/maven/bin/mvn /usr/bin/mvn

USER 1000
70 changes: 70 additions & 0 deletions feed-simulator/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.kpn.rss</groupId>
<artifactId>feed-simulator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>feed-simulator</name>
<description>feed-simulator</description>

<properties>
<java.version>17</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.kpn.rss.feedsimulator;

import lombok.RequiredArgsConstructor;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequiredArgsConstructor
@RequestMapping("/rss")
public class RssFeedController {

private final ResourceLoader resourceLoader;

@GetMapping(value = "/outages.xml", produces = MediaType.APPLICATION_XML_VALUE)
public ResponseEntity<byte[]> outages() throws IOException {
final Resource resource = this.resourceLoader.getResource("classpath:outages.xml");
final byte[] outagesBytes = resource.getInputStream().readAllBytes();
return ResponseEntity.ok().body(outagesBytes);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.kpn.rss.feedsimulator;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class RssFeedSimulatorApplication {

public static void main(final String[] args) {
SpringApplication.run(RssFeedSimulatorApplication.class, args);
}

}
2 changes: 2 additions & 0 deletions feed-simulator/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server.port=8090
spring.mvc.problemdetails.enabled=true
Loading

0 comments on commit cdba7c9

Please sign in to comment.