Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
alicela authored Jul 16, 2024
2 parents d9570e6 + 7823f6f commit 65d5e4c
Show file tree
Hide file tree
Showing 126 changed files with 2,897 additions and 1,076 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Changelog
## 3.0.0 [TODO] - DuckDB implementation for output and Kube deployment

## 3.0.0 [2024-07-16] - DuckDB implementation for output and Kubernetes support
### Added
- Launch treatment with command line
- S3/MinIO support : All file system calls goes through an interface with both OS file system and MinIO implementations
- DuckDB implementation for output
- Transfer Vtl datasets into DuckDB before output step
- SQL util class for SQL operations
- Can deploy in Kube or VM
- Health-check

### Changed
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Java 21
FROM gitlab-registry.insee.fr:443/kubernetes/images/run/jre:21.0.1_12-jre-jammy-rootless
COPY --chown=$JAVA_USER:$JAVA_USER Kraftwerk/kraftwerk-api/target/kraftwerk-api-*app-to-import.jar kraftwerk.jar
ARG VERSION_APPLICATION
COPY --chown=$JAVA_USER:$JAVA_USER Kraftwerk/kraftwerk-api/target/kraftwerk-api-$VERSION_APPLICATION.jar kraftwerk.jar

EXPOSE 8080

#Docker run without additionnal params to use REST API mode, add batch parameters to use batch mode
ENTRYPOINT ["java","-jar","/kraftwerk.jar"]
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ User documentation and functional tests are still in an [inhouse project](https:

Kraftwerk uses [Lombok](https://projectlombok.org/).

## Launch

If no argument is specified in the `java -jar` command, Kraftwerk will launch
as a REST API.
Otherwise, it will launch on batch mode and apply treatments on one campaign
with the specified arguments.
The required arguments for batch mode are as follows (in order) :
1. Service to use (`MAIN`,`FILEBYFILE`,`GENESIS`,`LUNATIC_ONLY`)
2. Archive at end of execution (`false` or `true`)
3. Integrate all reporting datas (`false` or `true`)
4. Campaign name

:fr:

Kraftwerk est une application Java Spring conçue pour valider et traiter des données provenant d'enquêtes multimodes, afin de générer des tableaux de données prêts à être utilisés à des fins statistiques.
Expand All @@ -37,3 +49,14 @@ La documentation utilisateur et les tests fonctionnels sont encore dans un [proj
* Maven 3.6 +

Kraftwerk utilise [Lombok](https://projectlombok.org/).

## Lancement

Si aucun paramètre n'est spécifié dans la commande `java -jar`, Kraftwerk se lancera
en tant qu'API REST.
Sinon, il va se lancer en mode batch et appliquer les traitements sur une campagne
avec les paramètres spécifiés. Les paramètres requis pour le mode batch sont les suivants (dans l'ordre) :
1. Service à utiliser (`MAIN`,`FILEBYFILE`,`GENESIS`,`LUNATIC_ONLY`)
2. Archiver à la fin de l'exécution (`false` ou `true`)
3. Integrate all reporting datas (`false` ou `true`)
4. Nom de la campagne
3 changes: 3 additions & 0 deletions kraftwerk-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>JAR</layout>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package fr.insee.kraftwerk.api;

import fr.insee.kraftwerk.api.configuration.MinioConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

@SpringBootApplication
@ConfigurationPropertiesScan
@EnableConfigurationProperties(MinioConfig.class)
public class KraftwerkApi extends SpringBootServletInitializer {


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package fr.insee.kraftwerk.api.batch;

import fr.insee.kraftwerk.api.configuration.ConfigProperties;
import fr.insee.kraftwerk.api.configuration.MinioConfig;
import fr.insee.kraftwerk.api.process.MainProcessing;
import fr.insee.kraftwerk.api.process.MainProcessingGenesis;
import fr.insee.kraftwerk.api.services.KraftwerkService;
import fr.insee.kraftwerk.core.utils.files.MinioImpl;
import io.minio.MinioClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class KraftwerkBatch implements CommandLineRunner {

ConfigProperties configProperties;
MinioConfig minioConfig;
MinioClient minioClient;

@Value("${fr.insee.postcollecte.files}")
protected String defaultDirectory;

@Value("${fr.insee.postcollecte.size-limit}")
protected long limitSize;

@Autowired
public KraftwerkBatch(ConfigProperties configProperties, MinioConfig minioConfig) {
this.configProperties = configProperties;
this.minioConfig = minioConfig;
if(minioConfig.isEnable()){
minioClient = MinioClient.builder().endpoint(minioConfig.getEndpoint()).credentials(minioConfig.getAccessKey(), minioConfig.getSecretKey()).build();
}
}

@Override
public void run(String... args) {
try {
//If .jar launched with cli args
if (args.length > 0) {
log.info("Launching Kraftwerk in CLI mode...");

//Check arguments
checkArgs(args);

//Parse arguments
//0. Service to use (MAIN,FILEBYFILE,GENESIS,LUNATIC_ONLY)
//1. Archive at end of execution (false or true)
//2. Integrate all reporting datas (false or true)
//3. Campaign name
KraftwerkServiceType kraftwerkServiceType = KraftwerkServiceType.valueOf(args[0]);
boolean archiveAtEnd = Boolean.parseBoolean(args[1]);
boolean withAllReportingData = Boolean.parseBoolean(args[2]);
String inDirectory = args[3];

//Kraftwerk service type related parameters
boolean fileByFile = kraftwerkServiceType == KraftwerkServiceType.FILE_BY_FILE;
boolean withDDI = kraftwerkServiceType != KraftwerkServiceType.LUNATIC_ONLY;
if (kraftwerkServiceType != KraftwerkServiceType.MAIN) {
withAllReportingData = false;
}
if (kraftwerkServiceType == KraftwerkServiceType.GENESIS) {
archiveAtEnd = false;
}


//Run kraftwerk
if (kraftwerkServiceType == KraftwerkServiceType.GENESIS) {
MainProcessingGenesis mainProcessingGenesis = new MainProcessingGenesis(configProperties, new MinioImpl(minioClient, minioConfig.getBucketName()));
mainProcessingGenesis.runMain(inDirectory);
} else {
MainProcessing mainProcessing = new MainProcessing(inDirectory, fileByFile, withAllReportingData, withDDI, defaultDirectory, limitSize, new MinioImpl(minioClient, minioConfig.getBucketName()));
mainProcessing.runMain();
}

//Archive
if (Boolean.TRUE.equals(archiveAtEnd)) {
KraftwerkService kraftwerkService = new KraftwerkService(minioConfig);
kraftwerkService.archive(inDirectory, new MinioImpl(minioClient, minioConfig.getBucketName()));
}
System.exit(0);
}
}catch(Exception e){
log.error(e.toString());
System.exit(1);
}
log.info("Launching Kraftwerk in API mode...");
}

/**
* Throws a IllegalArgumentException if the arguments are not valid (ex: unparseable boolean)
* KraftwerkServiceType is already checked by valueOf
* @param args list of CLI arguments
* @throws IllegalArgumentException if invalid argument
*/
private static void checkArgs(String[] args) throws IllegalArgumentException{
if(args.length != 4) {
throw new IllegalArgumentException("Invalid number of arguments ! Got %s instead of 4 !".formatted(args.length));
}
if(!args[1].equals("true") && !args[1].equals("false")){
throw new IllegalArgumentException("Invalid archiveAtEnd boolean argument ! : %s".formatted(args[1]));
}
if(!args[2].equals("true") && !args[2].equals("false")){
throw new IllegalArgumentException("Invalid withAllReportingData boolean argument ! %s".formatted(args[2]));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fr.insee.kraftwerk.api.batch;

import lombok.AllArgsConstructor;

@AllArgsConstructor
public enum KraftwerkServiceType {
MAIN,
LUNATIC_ONLY,
GENESIS,
FILE_BY_FILE;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fr.insee.kraftwerk.api.configuration;

import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties
@Getter
public class MinioConfig {
@Value("${fr.insee.postcollecte.minio.endpoint}")
private String endpoint;

@Value("${fr.insee.postcollecte.minio.access_key}")
private String accessKey;

@Value("${fr.insee.postcollecte.minio.secret_key}")
private String secretKey;

@Value("${fr.insee.postcollecte.minio.enable}")
private boolean enable;

@Value("${fr.insee.postcollecte.minio.bucket_name}")
private String bucketName;
}
Loading

0 comments on commit 65d5e4c

Please sign in to comment.