Skip to content

Commit

Permalink
Merge pull request #30 from CDOT-CV/develop
Browse files Browse the repository at this point in the history
Java Update
  • Loading branch information
dan-du-car authored Jan 30, 2024
2 parents a1263a0 + 6ff92bc commit 6abf213
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 60 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
maven-version: 3.8.2
- uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '21'
distribution: 'temurin'
- name: Build
run: |
Expand Down Expand Up @@ -48,11 +48,13 @@ jobs:
- name: Find jacoco.xml
shell: bash
run: |
find "$GITHUB_WORKSPACE" -name "jacoco.xml"
- name: Setup SonarScanner
uses: warchant/setup-sonar-scanner@v4
find "$GITHUB_WORKSPACE" -name "jacoco.xml"
- uses: actions/setup-java@v3
with:
version: 4.8.0.2856
distribution: 'temurin'
java-version: '21'
- name: Setup SonarScanner
uses: warchant/setup-sonar-scanner@v7
- name: Generate sonar properties file
run: |
cat <<EOF > /tmp/sonar-scanner.properties
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build container
FROM maven:3.5.4-jdk-8-alpine as builder
FROM maven:3.8-eclipse-temurin-21-alpine as builder
MAINTAINER [email protected]

WORKDIR /home
Expand All @@ -11,7 +11,7 @@ COPY ./src ./src
RUN mvn clean package -DskipTests

# Run container
FROM eclipse-temurin:11-jre-alpine
FROM eclipse-temurin:21-jre-alpine

WORKDIR /home
COPY --from=builder /home/target/jpo-sdw-depositor-1.3.0.jar /home
Expand Down
79 changes: 79 additions & 0 deletions docs/dockerhub.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# jpo-sdw-depositor

## GitHub Repository Link
https://github.com/usdot-jpo-ode/jpo-sdw-depositor

## Purpose
The purpose of the jpo-sdw-depositor program is to deposit messages to the SDX.

## How to pull the latest image
The latest image can be pulled using the following command:
> docker pull usdotjpoode/jpo-sdw-depositor:develop
## Required environment variables
- DOCKER_HOST_IP
- SDW_EMAIL_LIST
- SDW_EMAIL_FROM
- SDW_API_KEY

## Direct Dependencies
The SDWD will fail to start up if the following containers are not already present:
- Kafka
- Zookeeper (relied on by Kafka)

## Indirect Dependencies
The SDWD will not receive messages to process if the ODE is not running.

## Example docker-compose.yml with direct dependencies:
```
version: '2'
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: ${DOCKER_HOST_IP}
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_CREATE_TOPICS: "test:1:1"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
sdw_depositor:
image: usdotjpoode/jpo-sdw-depositor:release_q3
environment:
# required
DOCKER_HOST_IP: ${DOCKER_HOST_IP}
SDW_EMAIL_LIST: ${SDW_EMAIL_LIST}
SDW_EMAIL_FROM: ${SDW_EMAIL_FROM}
SDW_API_KEY: ${SDW_API_KEY}
# optional
SDW_DESTINATION_URL: ${SDW_DESTINATION_URL}
SPRING_MAIL_HOST: ${SPRING_MAIL_HOST}
SPRING_MAIL_PORT: ${SPRING_MAIL_PORT}
SDW_SUBSCRIPTION_TOPIC: ${SDW_SUBSCRIPTION_TOPIC}
logging:
options:
max-size: "10m"
max-file: "5"
```

## Expected startup output
The latest logs should look something like this:
```
2023-11-09 17:40:31.082 INFO 1 --- [ main] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer-usdot.jpo.sdw-1, groupId=usdot.jpo.sdw] Discovered group coordinator 192.168.0.243:9092 (id: 2147482646 rack: null)
2023-11-09 17:40:31.089 INFO 1 --- [ main] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer-usdot.jpo.sdw-1, groupId=usdot.jpo.sdw] (Re-)joining group
2023-11-09 17:40:31.174 INFO 1 --- [ main] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer-usdot.jpo.sdw-1, groupId=usdot.jpo.sdw] (Re-)joining group
2023-11-09 17:40:31.227 INFO 1 --- [ main] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer-usdot.jpo.sdw-1, groupId=usdot.jpo.sdw] Successfully joined group with generation Generation{generationId=1, memberId='consumer-usdot.jpo.sdw-1-cd6afbec-5bfe-46e0-beb6-539d47426902', protocol='range'}
2023-11-09 17:40:31.233 INFO 1 --- [ main] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer-usdot.jpo.sdw-1, groupId=usdot.jpo.sdw] Finished assignment for group at generation 1: {consumer-usdot.jpo.sdw-1-cd6afbec-5bfe-46e0-beb6-539d47426902=Assignment(partitions=[topic.SDWDepositorInput-0])}
2023-11-09 17:40:31.369 INFO 1 --- [ main] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer-usdot.jpo.sdw-1, groupId=usdot.jpo.sdw] Successfully synced group in generation Generation{generationId=1, memberId='consumer-usdot.jpo.sdw-1-cd6afbec-5bfe-46e0-beb6-539d47426902', protocol='range'}
2023-11-09 17:40:31.370 INFO 1 --- [ main] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer-usdot.jpo.sdw-1, groupId=usdot.jpo.sdw] Notifying assignor about the new Assignment(partitions=[topic.SDWDepositorInput-0])
2023-11-09 17:40:31.378 INFO 1 --- [ main] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer-usdot.jpo.sdw-1, groupId=usdot.jpo.sdw] Adding newly assigned partitions: topic.SDWDepositorInput-0
2023-11-09 17:40:31.415 INFO 1 --- [ main] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer-usdot.jpo.sdw-1, groupId=usdot.jpo.sdw] Found no committed offset for partition topic.SDWDepositorInput-0
2023-11-09 17:40:31.454 INFO 1 --- [ main] o.a.k.c.c.internals.SubscriptionState : [Consumer clientId=consumer-usdot.jpo.sdw-1, groupId=usdot.jpo.sdw] Resetting offset for partition topic.SDWDepositorInput-0 to position FetchPosition{offset=0, offsetEpoch=Optional.empty, currentLeader=LeaderAndEpoch{leader=Optional[192.168.0.243:9092 (id: 1001 rack: null)], epoch=0}}.
```
105 changes: 55 additions & 50 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?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 http://maven.apache.org/maven-v4_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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
<version>3.1.3</version>
<relativePath />
<!-- lookup parent from repository -->
</parent>
Expand All @@ -16,16 +18,18 @@
<name>jpo-sdw-depositor</name>

<properties>
<jmockit.version>1.49</jmockit.version>
<argLine>-javaagent:${user.home}/.m2/repository/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar</argLine>
<sonar.organization>usdot-jpo-ode</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<!-- JaCoCo Properties -->
<jacoco.version>0.8.8</jacoco.version>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/target/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
<sonar.language>java</sonar.language>
<java.version>21</java.version>
<jmockit.version>1.49</jmockit.version>
<argLine>
-javaagent:${user.home}/.m2/repository/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar</argLine>
<sonar.organization>usdot-jpo-ode</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<!-- JaCoCo Properties -->
<jacoco.version>0.8.11</jacoco.version>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/target/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
<sonar.language>java</sonar.language>
</properties>

<dependencies>
Expand Down Expand Up @@ -83,55 +87,56 @@
<version>1.0.1.RELEASE</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<!-- <testFailureIgnore>true</testFailureIgnore> -->
<enableProcessChecker>all</enableProcessChecker>
<shutdown>exit</shutdown>
<systemPropertyVariables>
<loader.path>${loader.path}</loader.path>
<buildDirectory>${project.build.directory}</buildDirectory>
</systemPropertyVariables>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>3.0.0-M7</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<argLine>
-javaagent:${user.home}/.m2/repository/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar</argLine>
<!-- <testFailureIgnore>true</testFailureIgnore> -->
<enableProcessChecker>all</enableProcessChecker>
<shutdown>exit</shutdown>
<systemPropertyVariables>
<loader.path>${loader.path}</loader.path>
<buildDirectory>${project.build.directory}</buildDirectory>
</systemPropertyVariables>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>3.1.2</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</plugin>
</plugins>
</build>
</project>
2 changes: 1 addition & 1 deletion src/main/java/jpo/sdw/depositor/DepositorProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.regex.Pattern;

import javax.annotation.PostConstruct;
import jakarta.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.net.URI;
import java.net.URISyntaxException;

import javax.annotation.PostConstruct;
import jakarta.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/jpo/sdw/depositor/depositors/SDWDepositor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
Expand Down Expand Up @@ -37,7 +38,7 @@ public void deposit(String message) {
.toEntity(String.class);

clientResponse.subscribe( response -> {
HttpStatus statusCode = response.getStatusCode();
HttpStatusCode statusCode = response.getStatusCode();
String body = response.getBody();
if (statusCode != HttpStatus.OK) {
// There was an error with depositing data, email the team
Expand Down

0 comments on commit 6abf213

Please sign in to comment.