Skip to content

Commit

Permalink
Merge pull request #138 from InseeFr/devHealthCheck
Browse files Browse the repository at this point in the history
Dev health check
  • Loading branch information
alicela authored Jul 16, 2024
2 parents 9ddc524 + b0c39b1 commit 265bed4
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public GenesisClient(RestTemplateBuilder restTemplateBuilder, ConfigProperties c
this.configProperties = configProperties;
}

public String pingGenesis(){
String url = String.format("%s/health-check", configProperties.getGenesisUrl());
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, null, String.class);
return response.getBody() != null ? response.getBody() : null;
}

public List<SurveyUnitId> getSurveyUnitIds(String idQuestionnaire) {
String url = String.format("%s/response/get-idUEs/by-questionnaire?idQuestionnaire=%s", configProperties.getGenesisUrl(), idQuestionnaire);
ResponseEntity<SurveyUnitId[]> response = restTemplate.exchange(url, HttpMethod.GET, null, SurveyUnitId[].class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package fr.insee.kraftwerk.api.services;


import fr.insee.kraftwerk.api.client.GenesisClient;
import fr.insee.kraftwerk.api.configuration.ConfigProperties;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.nio.file.Files;
import java.nio.file.Paths;


@RestController
@Tag(name = "${tag.health-check}")
public class HealthcheckService extends KraftwerkService {

public static final String OK = "OK";
public static final String KO = "FAILURE";


@Value("${fr.insee.kraftwerk.version}")
private String projectVersion;

private final GenesisClient client;

ConfigProperties configProperties;

@Autowired
public HealthcheckService(ConfigProperties configProperties) {
this.configProperties = configProperties;
this.client = new GenesisClient(new RestTemplateBuilder(), configProperties);

}


@GetMapping("health-check")
public ResponseEntity<String> healthcheck() {
String status = OK;
String fileStorageStatus = fileStorageExists();
if (!OK.equals(fileStorageStatus)){status = KO;}

return ResponseEntity.ok(
"""
%s
Version %s
Genesis health-check %s
File storage %s : %s
"""
.formatted(
status,
projectVersion,
client.pingGenesis().split("\n")[0],
configProperties.getSpecDirectory(),
fileStorageStatus
));
}

private String fileStorageExists() {
try{
Files.exists(Paths.get(configProperties.getSpecDirectory()));
}catch (Exception e){
return "Disconnected " +e.getMessage();
}
return OK;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
tag.main= 1- Main services
tag.stepbystep= 2- Step by step services
tag.splitter= 3- XML file splitter service
tag.health-check= 4- Healthcheck service

summary.main=Main service : call all steps
description.main=This service does : \n - buildVtlBindings \n - unimodalProcessing \n - multimodalProcessing \n - Separate the different information's levels and export
Expand Down
4 changes: 2 additions & 2 deletions kraftwerk-api/src/main/resources/i18n/messages_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
tag.main= 1- Services principaux
tag.stepbystep= 2- Services par étapes
tag.splitter= 3- Service de découpage de fichier XML

tag.health-check= 4- Santé du service

summary.main=Service principal : ce service appelle toutes les étapes successivement
description.main=Ce service enchaîne les traitements : \n - buildVtlBindings : construction des jeux de données au format VTL \n - unimodalProcessing : traitement unimodal pour chaque mode de collecte disponible \n - multimodalProcessing : Réconciliation des différents modes et traitements multimodal \n - Séparation en tables par niveau d'information (boucles) et export CSV
Expand Down Expand Up @@ -38,4 +38,4 @@ param.inDirectory=Nom ou chemin vers le dossier contenant les fichiers d'entr
param.idCampaign=Identifiant de l'enquête
param.archiveAtEnd=Booléen, true si on souhaite archiver à la fin du traitement. Par défaut, la valeur est false (pas d'archivage)
param.withAllReportingData=Booléen, true si on souhaite récupérer les lignes de reportingData non associées à un questionnaire (non répondant). Par défaut, la valeur est true.
param.dataMode=Mode de collecte (datamode)
param.dataMode=Mode de collecte (datamode)
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public String outputFileName(String datasetName) {
/**
* Method to write output tables from datasets that are in the bindings.
*/
public void writeOutputTables(Map<String, MetadataModel> metadataModels) throws KraftwerkException {
public void writeOutputTables() throws KraftwerkException {
// implemented in subclasses
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public CsvOutputFiles(Path outDirectory, VtlBindings vtlBindings, KraftwerkExecu
* Method to write CSV output tables from datasets that are in the bindings.
*/
@Override
public void writeOutputTables(Map<String, MetadataModel> metadataModels) throws KraftwerkException {
public void writeOutputTables() throws KraftwerkException {
for (String datasetName : getDatasetToCreate()) {
File outputFile = getOutputFolder().resolve(outputFileName(datasetName)).toFile();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.nio.file.Path;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -44,7 +43,7 @@ public ParquetOutputFiles(Path outDirectory, VtlBindings vtlBindings, List<Strin
* Method to write output tables from datasets that are in the bindings.
*/
@Override
public void writeOutputTables(Map<String, MetadataModel> metadataModels) throws KraftwerkException {
public void writeOutputTables() throws KraftwerkException {
for (String datasetName : getDatasetToCreate()) {
File outputFile = getOutputFolder().resolve(outputFileName(datasetName)).toFile();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private void writeCsvFiles(Path outDirectory, VtlBindings vtlBindings, Map<Strin
/* Step 5.1 : write csv output tables */
OutputFiles csvOutputFiles = new CsvOutputFiles(outDirectory, vtlBindings, kraftwerkExecutionLog,
new ArrayList<>(modeInputsMap.keySet()), databaseConnection);
csvOutputFiles.writeOutputTables(metadataModels);
csvOutputFiles.writeOutputTables();

/* Step 5.2 : write scripts to import csv tables in several languages */
csvOutputFiles.writeImportScripts(metadataModels, errors);
Expand All @@ -53,7 +53,7 @@ private void writeParquetFiles(Path outDirectory, VtlBindings vtlBindings, Map<S
/* Step 5.3 : write parquet output tables */
OutputFiles parquetOutputFiles = new ParquetOutputFiles(outDirectory, vtlBindings,
new ArrayList<>(modeInputsMap.keySet()), databaseConnection);
parquetOutputFiles.writeOutputTables(metadataModels);
parquetOutputFiles.writeOutputTables();
parquetOutputFiles.writeImportScripts(metadataModels, errors);
}
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
package fr.insee.kraftwerk.core.outputs;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import fr.insee.kraftwerk.core.Constants;
import fr.insee.kraftwerk.core.TestConstants;
import fr.insee.kraftwerk.core.exceptions.KraftwerkException;
import fr.insee.kraftwerk.core.inputs.UserInputsFile;
import fr.insee.kraftwerk.core.metadata.Group;
import fr.insee.kraftwerk.core.metadata.MetadataModel;
import fr.insee.kraftwerk.core.metadata.Variable;
import fr.insee.kraftwerk.core.metadata.VariableType;
import fr.insee.kraftwerk.core.outputs.csv.CsvOutputFiles;
import fr.insee.kraftwerk.core.utils.FileUtils;
import fr.insee.kraftwerk.core.utils.SqlUtils;
import fr.insee.kraftwerk.core.vtl.VtlBindings;
import fr.insee.vtl.model.Dataset;
import fr.insee.vtl.model.InMemoryDataset;
import fr.insee.vtl.model.Structured;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import fr.insee.kraftwerk.core.Constants;
import fr.insee.kraftwerk.core.TestConstants;
import fr.insee.kraftwerk.core.inputs.UserInputsFile;
import fr.insee.kraftwerk.core.outputs.csv.CsvOutputFiles;
import fr.insee.kraftwerk.core.vtl.VtlBindings;
import fr.insee.vtl.model.Dataset;
import fr.insee.vtl.model.InMemoryDataset;
import fr.insee.vtl.model.Structured;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

@TestMethodOrder(OrderAnnotation.class)
class CsvOutputFilesTest {
Expand Down Expand Up @@ -99,7 +98,7 @@ void testWriteCsv() throws KraftwerkException, SQLException {
metMod.getVariables().putVariable(new Variable("FOO_NUM",group, VariableType.NUMBER));
metaModels.put("test",metMod);

outputFiles.writeOutputTables(metaModels);
outputFiles.writeOutputTables();

Path racinePath = Path.of(outputFiles.getOutputFolder().toString(), outputFiles.outputFileName("RACINE"));
racinePath = racinePath.resolveSibling(racinePath.getFileName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void writeParquetFromDatasetTest() throws KraftwerkException {
metMod.getVariables().putVariable(new Variable("FOO_NUM",group, VariableType.NUMBER));
metaModels.put("test",metMod);

outputFiles.writeOutputTables(metaModels);
outputFiles.writeOutputTables();
Path racinePath = Path.of(outputFiles.getOutputFolder().toString(), outputFiles.getAllOutputFileNames("RACINE").getFirst());
racinePath = racinePath.resolveSibling(racinePath.getFileName()+".parquet");
File f = racinePath.toFile();
Expand Down

0 comments on commit 265bed4

Please sign in to comment.