Skip to content

Commit

Permalink
Merge pull request #129 from abes-esr/develop
Browse files Browse the repository at this point in the history
Merge develop dans main
  • Loading branch information
SamuelQuetin authored Oct 4, 2024
2 parents 38ec765 + 8c928bb commit a3dba34
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 51 deletions.
36 changes: 16 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
###
# Image pour la compilation
FROM maven:3-eclipse-temurin-17 as build-image
WORKDIR /build/
# Installation et configuration de la locale FR
RUN apt update && DEBIAN_FRONTEND=noninteractive apt -y install locales
RUN sed -i '/fr_FR.UTF-8/s/^# //g' /etc/locale.gen && \
locale-gen
ENV LANG fr_FR.UTF-8
ENV LANGUAGE fr_FR:fr
ENV LC_ALL fr_FR.UTF-8


# On lance la compilation Java
# On débute par une mise en cache docker des dépendances Java
# cf https://www.baeldung.com/ops/docker-cache-maven-dependencies
Expand All @@ -25,25 +15,31 @@ RUN mvn --batch-mode \
-Duser.language=fr \
package spring-boot:repackage

FROM maven:3-eclipse-temurin-17 as kbart2kafka-builder
WORKDIR application
ARG JAR_FILE=build/target/kbart2kafka.jar
COPY --from=build-image ${JAR_FILE} kbart2kafka.jar
RUN java -Djarmode=layertools -jar kbart2kafka.jar extract

###
# Image pour le module API
#FROM tomcat:9-jdk17 as api-image
#COPY --from=build-image /build/web/target/*.war /usr/local/tomcat/webapps/ROOT.war
#CMD [ "catalina.sh", "run" ]
FROM eclipse-temurin:17-jdk as kbart2kafka-image
RUN apt-get update
RUN apt-get install -y locales locales-all
ENV LC_ALL fr_FR.UTF-8
ENV LANG fr_FR.UTF-8
ENV LANGUAGE fr_FR.UTF-8
ENV TZ=Europe/Paris
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
WORKDIR /app/
COPY --from=build-image /build/target/kbart2kafka.jar /app/kbart2kafka.jar
RUN mkdir /app/run
RUN cp /app/*.jar /app/run
RUN chmod 777 /app/run/*
WORKDIR /app/run/

COPY --from=kbart2kafka-builder application/dependencies/ ./
COPY --from=kbart2kafka-builder application/spring-boot-loader/ ./
COPY --from=kbart2kafka-builder application/snapshot-dependencies/ ./
COPY --from=kbart2kafka-builder application/application/ ./
COPY --from=kbart2kafka-builder application/*.jar ./kbart2kafka.jar
RUN chmod +x /app/run/kbart2kafka.jar
RUN touch app.log
RUN chmod 777 app.log
ENV TZ=Europe/Paris
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ENTRYPOINT ["tail","-f","app.log"]

32 changes: 5 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<version>2.14.0</version>
</dependency>

<!-- === Test === -->
Expand Down Expand Up @@ -211,32 +211,6 @@

<!-- Pour que maven se charge de générer les releases -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<archive>
<manifest>
<mainClass>fr.abes.kbart2kafka.Kbart2kafkaApplication</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>${jarName}</finalName>
<resources>
<resource>
Expand Down Expand Up @@ -277,6 +251,10 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.5.RELEASE</version>
<configuration>
<layers>
<enabled>true</enabled>
<includeLayerTools>true</includeLayerTools>
</layers>
<mainClass>fr.abes.kbart2kafka.Kbart2kafkaApplication</mainClass>
</configuration>
<executions>
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/fr/abes/kbart2kafka/service/FileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,22 @@ private void executeMultiThread(File fichier) {
List<String> kbartsToSend = new ArrayList<>();
Integer nbLignesFichier = fileContent.size() - 1;
log.debug("Début d'envoi de " + nbLignesFichier + " lignes du fichier");
AtomicInteger cpt = new AtomicInteger(0);
AtomicInteger cpt = new AtomicInteger(1);
List<String> errorsList = new ArrayList<>();
fileContent.stream().skip(1).forEach(ligneKbart -> {
String[] tsvElementsOnOneLine = ligneKbart.split("\t");
try {
kbartsToSend.add(mapper.writeValueAsString(constructDto(tsvElementsOnOneLine, cpt.incrementAndGet(), nbLignesFichier)));
} catch (IllegalDateException | IllegalFileFormatException | JsonProcessingException e) {
errorsList.add("Erreur dans le fichier en entrée à la ligne " + cpt.get());
errorsList.add("Erreur dans le fichier en entrée à la ligne " + cpt.get() + " : " + e.getMessage());
}
});
if (errorsList.isEmpty()) {
cpt.set(1);
kbartsToSend.forEach(kbart -> {
executor.execute(() -> {
cpt.incrementAndGet();
String key = fichier.getName()+"_"+cpt.get();
String key = fichier.getName() + "_" + cpt.get();
ThreadContext.put("package", fichier.getName());
ProducerRecord<String, String> record = new ProducerRecord<>(topicKbart, calculatePartition(nbThread), key, kbart);
CompletableFuture<SendResult<String, String>> result = kafkaTemplate.send(record);
Expand Down Expand Up @@ -126,7 +126,7 @@ private void sendErrorToKafka(String errorMessage, String key) {
*/
private LigneKbartDto constructDto(String[] line, Integer ligneCourante, Integer nbLignesFichier) throws IllegalFileFormatException, IllegalDateException {
if ((line.length > 26) || (line.length < 25)) {
throw new IllegalFileFormatException("La ligne n°" + ligneCourante + " ne comporte pas le bon nombre de colonnes");
throw new IllegalFileFormatException("nombre de colonnes incorrect");
}
LigneKbartDto kbartLineInDtoObject = new LigneKbartDto();
kbartLineInDtoObject.setNbCurrentLines(ligneCourante);
Expand Down Expand Up @@ -161,5 +161,6 @@ private LigneKbartDto constructDto(String[] line, Integer ligneCourante, Integer
kbartLineInDtoObject.setBestPpn(line[25]);
}
return kbartLineInDtoObject;

}
}

0 comments on commit a3dba34

Please sign in to comment.