-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
126 changed files
with
2,897 additions
and
1,076 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
kraftwerk-api/src/main/java/fr/insee/kraftwerk/api/KraftwerkApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
kraftwerk-api/src/main/java/fr/insee/kraftwerk/api/batch/KraftwerkBatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
kraftwerk-api/src/main/java/fr/insee/kraftwerk/api/batch/KraftwerkServiceType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
24 changes: 24 additions & 0 deletions
24
kraftwerk-api/src/main/java/fr/insee/kraftwerk/api/configuration/MinioConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.