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

Kubernetes support #132

Merged
merged 59 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
3da70f8
Create Deployment.yaml
alexisszmundy May 6, 2024
39aff08
Add k8s manifests
alexisszmundy May 7, 2024
7a08240
Removed app-to-import jar from dockerfile
alexisszmundy May 7, 2024
21b39d5
Update Dockerfile
alexisszmundy May 7, 2024
1455609
Update Dockerfile
alexisszmundy May 7, 2024
69db7f7
Update Dockerfile
alexisszmundy May 7, 2024
d49117d
Add actuators + add config map
alexisszmundy May 13, 2024
29557c3
Merge branch 'main' into devKubernetes
alexisszmundy May 13, 2024
1adcc70
Functionnal pod, only one
alexisszmundy May 13, 2024
96136a0
Removed manifests (moved to argocd repo)
alexisszmundy May 13, 2024
751b9f5
Merge branch 'main' into devKubernetes
alexisszmundy May 16, 2024
408c7db
Add cli launch
alexisszmundy Jun 14, 2024
823a756
Create batch dockerfile
alexisszmundy Jun 14, 2024
cddc8f3
Revert "Create batch dockerfile"
alexisszmundy Jun 14, 2024
dbc0663
Update Dockerfile
alexisszmundy Jun 14, 2024
48f19be
Merge branch 'main' into devKubernetes
alexisszmundy Jun 14, 2024
6ebf8d6
Merge branch 'devBatchExecution' into devKubernetes
alexisszmundy Jun 14, 2024
feb421c
File utils to interface
alexisszmundy Jun 19, 2024
22b5a55
Add minio implementation + remove Files calls to use interface + move…
alexisszmundy Jun 20, 2024
a7534c0
Added TODOS to remove Files methods to use interface instead
alexisszmundy Jun 21, 2024
3a9c412
Merge branch 'devParquetDuckdb' into devKubernetes
alexisszmundy Jun 21, 2024
027abcb
Fixes after merge
alexisszmundy Jun 21, 2024
cde44aa
Changed file system I/O to use FileUtilsInterface
alexisszmundy Jun 21, 2024
7ea617d
Removed more file system calls + unused imports + moved XML utils to …
alexisszmundy Jun 24, 2024
dd3d869
Adapted Xml Splitter and CSV/Parquet output to be able to use minio
alexisszmundy Jun 24, 2024
acad2b7
Refactos and interface reorder
alexisszmundy Jun 24, 2024
8a18b4d
Update CHANGELOG.md
alexisszmundy Jun 24, 2024
b202b60
Merge branch 'main' into devKubernetes
alexisszmundy Jun 24, 2024
f6e88bb
Begin file interface and implementations tests
alexisszmundy Jun 24, 2024
268497a
Create directories method into interface
alexisszmundy Jun 24, 2024
417b9ae
File system tests + moved common methods to interface
alexisszmundy Jun 24, 2024
8a2c9a4
Fixes MinIO after manual tests
alexisszmundy Jun 26, 2024
edc802f
Removed unused
alexisszmundy Jun 26, 2024
aa7a18c
Fix http URL case
alexisszmundy Jun 26, 2024
4c9d5df
Update FileSystemImplTest.java
alexisszmundy Jun 26, 2024
6edb6d8
Update KraftwerkBatch.java
alexisszmundy Jun 26, 2024
b785fea
Merge branch 'main' into devKubernetes
alexisszmundy Jun 26, 2024
832f06e
Overwrite default directory if MinIO enabled
alexisszmundy Jun 26, 2024
eb27d6f
Overwrite default directory if using MinIO (in services)
alexisszmundy Jun 26, 2024
726c578
Revert "Overwrite default directory if using MinIO (in services)"
alexisszmundy Jun 27, 2024
38b4104
Revert "Overwrite default directory if MinIO enabled"
alexisszmundy Jun 27, 2024
53dfbe5
Update MinioImpl.java
alexisszmundy Jun 28, 2024
0825b3e
fix Genesis endpoint batch
alexisszmundy Jul 2, 2024
5b2125b
Merge branch 'main' into devKubernetes
alexisszmundy Jul 2, 2024
0154af1
Fix API mode not launching
alexisszmundy Jul 5, 2024
4a972c0
Merge branch 'main' into devKubernetes
alexisszmundy Jul 5, 2024
115910e
Merge branch 'devParquetDuckdb' into devKubernetes
alexisszmundy Jul 8, 2024
c924510
Merge branch 'main' into devKubernetes
alexisszmundy Jul 8, 2024
ebc0f86
Merge branch 'main' into devKubernetes
alexisszmundy Jul 11, 2024
47c8138
Fixes after conflicts
alexisszmundy Jul 11, 2024
43f2231
fixes
alexisszmundy Jul 11, 2024
900f39e
refacto try catch batch
alexisszmundy Jul 11, 2024
4b56be2
Added unit tests to increase coverage
alexisszmundy Jul 12, 2024
2ac3b78
Update README.md
alexisszmundy Jul 12, 2024
305845b
Update Dockerfile
alexisszmundy Jul 12, 2024
da58c6a
Added args in comments
alexisszmundy Jul 15, 2024
40e197f
Merge branch 'main' into devKubernetes
alicela Jul 16, 2024
57ad159
Fix missing import
alicela Jul 16, 2024
476beb4
Update HealthcheckService.java
alicela Jul 16, 2024
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
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
## 2.2.0 [TODO] - DuckDB implementation for output
## 3.0.0 [TODO] - 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

Expand All @@ -10,7 +14,7 @@

### Removed
- Avro
-

## 2.1.0 [2024-06-11] - Change Lunatic reader
### Changed
- Refactor of Lunatic reader
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
Loading