Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/ois/simplify #2

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup java jdk
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'zulu'
java-version: '17 '

- name: Package & run tests with maven
run: mvn clean install --no-transfer-progress

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v1
Expand All @@ -41,7 +42,7 @@ jobs:

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v4
with:
context: ./
file: ./Dockerfile
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ target/
mvn*
.java-version

/src/main/resources/application-local.yml


### STS ###
.apt_generated
Expand Down
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
FROM openjdk:17-slim
FROM eclipse-temurin:17-jre-alpine

ENV TZ=Europe/Oslo
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

VOLUME /tmp
COPY /target/app.jar app.jar

CMD java -jar -XX:+UseZGC $JAVA_OPTS app.jar
CMD java -jar $JAVA_OPTS app.jar
2 changes: 2 additions & 0 deletions helm-sources/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ spec:
spec:
containers:
- env:
- name: SPRING_PROFILES_ACTIVE
value: prod
- name: CLIENT_ID
valueFrom:
secretKeyRef:
Expand Down
111 changes: 63 additions & 48 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
<?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">
<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 http://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>2.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
<version>3.1.1</version>
<relativePath/>
</parent>

<groupId>no.oyvindis</groupId>
<artifactId>kafka-producer-climate</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>kafka-producer-climate</name>
<description>Produce climate data</description>
<version>1.0.0</version>

<properties>
<java.version>17</java.version>
<kotlin.version>1.6.21</kotlin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<kotlin.version>1.8.22</kotlin.version>
<testcontainers.version>1.18.3</testcontainers.version>
</properties>

<dependencies>

<!-- Spring -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand All @@ -28,74 +36,67 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>7.4</version>
</dependency>

<!-- JSON -->
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.6</version>
</dependency>

<!-- Security -->
<!-- Kafka -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
</dependency>

<!-- Kotlin -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>

<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<groupId>org.mockito.kotlin</groupId>
<artifactId>mockito-kotlin</artifactId>
<version>5.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito.kotlin</groupId>
<artifactId>mockito-kotlin</artifactId>
<version>4.0.0</version>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand All @@ -107,26 +108,40 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<jvmTarget>${java.version}</jvmTarget>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
<args>
<arg>-Xjsr305=strict</arg>
</args>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-noarg</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
</plugin>

</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ClimateService(
@Value("\${kafka.topics.sensor}")
val topic: String,
) {
@Scheduled(fixedDelay = 900000)
@Scheduled(fixedDelay = 21600000)
fun postReadingFromAirthings() {
try {
logger.debug("postReadingFromAirthings")
Expand Down
17 changes: 17 additions & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
spring:

security:
oauth2:
client:
registration:
airthings:
clientId: ${CLIENT_ID}
clientSecret: ${CLIENT_SECRET}
clientAuthenticationMethod: client_secret_post
authorizationGrantType: client_credentials
scopes: read:device:current_values
clientName: ois-airthings
provider:
airthings:
authorizationUri: https://accounts.airthings.com/authorize
tokenUri: https://accounts-api.airthings.com/v1/token
17 changes: 17 additions & 0 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
spring:

security:
oauth2:
client:
registration:
airthings:
clientId: ${CLIENT_ID}
clientSecret: ${CLIENT_SECRET}
clientAuthenticationMethod: client_secret_post
authorizationGrantType: client_credentials
scopes: read:device:current_values
clientName: ois-airthings
provider:
airthings:
authorizationUri: https://accounts.airthings.com/authorize
tokenUri: https://accounts-api.airthings.com/v1/token
39 changes: 4 additions & 35 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,12 @@ logging:
org.springframework.web: WARN
org.apache.jena: ERROR

server:
port: 8080
kafka:
bootstrapAddress: ${KAFKA_BOOTSTRAP_HOST:10.0.0.22}:${KAFKA_BOOTSTRAP_PORT:31172}
topics:
sensor: sensor

spring:
security:
oauth2:
client:
registration:
airthings:
clientId: ${CLIENT_ID}
clientSecret: ${CLIENT_SECRET}
clientAuthenticationMethod: client_secret_post
authorizationGrantType: client_credentials
scopes: read:device:current_values
clientName: ois-airthings
provider:
airthings:
authorizationUri: https://accounts.airthings.com/authorize
tokenUri: https://accounts-api.airthings.com/v1/token
---
spring:
security:
oauth2:
client:
registration:
airthings:
clientId: ${CLIENT_ID}
clientSecret: ${CLIENT_SECRET}
clientAuthenticationMethod: client_secret_post
authorizationGrantType: client_credentials
scopes: read:device:current_values
clientName: ois-airthings
provider:
airthings:
authorizationUri: https://accounts.airthings.com/authorize
tokenUri: https://accounts-api.airthings.com/v1/token
config.activate.on-profile: develop

profiles:
default: local
Loading