Skip to content

Commit

Permalink
Redirect logs outside of console (#79)
Browse files Browse the repository at this point in the history
* Redirect logs outside of console

* Log user log in and authorities.

* Re-implemented periodically executing a algorithm aggregator that was removed by accident.
For the time being we only allow exareme2 algorithms to the portalbackend.

* Minor refactoring to conversion of ExperimentExecutionDTO.AlgorithmExecutionDTO to Exareme2AlgorithmRequestDTO.
  • Loading branch information
KFilippopolitis authored Jul 24, 2024
1 parent 04c18a4 commit 4ff362a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 12 deletions.
24 changes: 24 additions & 0 deletions src/main/java/hbp/mip/algorithm/AlgorithmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@
import hbp.mip.utils.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import static hbp.mip.utils.InputStreamConverter.convertInputStreamToString;

@Service
@EnableScheduling
public class AlgorithmService {

private static final Gson gson = new Gson();
Expand Down Expand Up @@ -76,11 +82,29 @@ private List<Exareme2AlgorithmSpecificationDTO> getExareme2Algorithms(Logger log
return Collections.emptyList();
}

// Filter out algorithms with type "flower"
algorithms = algorithms.stream()
.filter(algorithm -> "exareme2".equals(algorithm.type()))
.collect(Collectors.toList());
logger.debug("Fetched " + algorithms.size() + " exareme2 algorithms.");
exareme2AlgorithmsSpecs.setAlgorithms(algorithms);
return algorithms;
}

@EnableAsync
public static class AlgorithmAggregator {

private final AlgorithmService algorithmService;

public AlgorithmAggregator(AlgorithmService algorithmService){
this.algorithmService = algorithmService;
}
@Async
@Scheduled(fixedDelayString = "${services.algorithmsUpdateInterval}000")
public void scheduleFixedRateTaskAsync() {
algorithmService.getExareme2Algorithms(new Logger("AlgorithmAggregator","(GET) /algorithms"));
}
}
/**
* Fetches the disabled algorithms from a .json file
*
Expand Down
39 changes: 29 additions & 10 deletions src/main/java/hbp/mip/algorithm/Exareme2AlgorithmRequestDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,33 @@ public record Exareme2AlgorithmRequestDTO(
String type
) {

public Exareme2AlgorithmRequestDTO(
public static Exareme2AlgorithmRequestDTO create(
UUID experimentUUID,
List<ExperimentExecutionDTO.AlgorithmExecutionDTO.AlgorithmParameterExecutionDTO> exaremeAlgorithmRequestParamDTOs,
List<ExperimentExecutionDTO.AlgorithmExecutionDTO.TransformerExecutionDTO> exaremeTransformers,
Exareme2AlgorithmSpecificationDTO exareme2AlgorithmSpecificationDTO) {
this(

// List of inputDataFields
List<String> inputDataFields = Arrays.asList("pathology", "dataset", "x", "y", "filter");

// Create lists to hold the separated DTOs
List<ExperimentExecutionDTO.AlgorithmExecutionDTO.AlgorithmParameterExecutionDTO> inputDataDTOs = new ArrayList<>();
List<ExperimentExecutionDTO.AlgorithmExecutionDTO.AlgorithmParameterExecutionDTO> parametersDTOs = new ArrayList<>();

// Split the DTOs into the respective lists
for (ExperimentExecutionDTO.AlgorithmExecutionDTO.AlgorithmParameterExecutionDTO dto : exaremeAlgorithmRequestParamDTOs) {
if (inputDataFields.contains(dto.name())) {
inputDataDTOs.add(dto);
} else {
parametersDTOs.add(dto);
}
}

// Call the constructor with the separated lists
return new Exareme2AlgorithmRequestDTO(
experimentUUID.toString(),
getInputData(exaremeAlgorithmRequestParamDTOs),
getParameters(exaremeAlgorithmRequestParamDTOs, exareme2AlgorithmSpecificationDTO),
getInputData(inputDataDTOs),
getParameters(parametersDTOs, exareme2AlgorithmSpecificationDTO),
getPreprocessing(exaremeTransformers, exareme2AlgorithmSpecificationDTO),
"exareme2"
);
Expand Down Expand Up @@ -73,15 +91,13 @@ private static Map<String, Object> getParameters(List<ExperimentExecutionDTO.Alg
return null;
}

// The input_data fields should be ignored and shouldn't be added in the parameters.
List<String> inputDataFields = Arrays.asList("pathology", "dataset", "x", "y", "filter");

HashMap<String, Object> exareme2Parameters = new HashMap<>();
exaremeAlgorithmRequestParamDTOs.forEach(parameter -> {
if (!inputDataFields.contains(parameter.name())){
Exareme2AlgorithmSpecificationDTO.Exareme2AlgorithmParameterSpecificationDTO paramSpecDto = exareme2AlgorithmSpecificationDTO.parameters().get(parameter.name());
exareme2Parameters.put(parameter.name(), convertStringToProperExareme2ParameterTypeAccordingToSpecs(parameter.value(), paramSpecDto));
Exareme2AlgorithmSpecificationDTO.Exareme2AlgorithmParameterSpecificationDTO paramSpecDto = exareme2AlgorithmSpecificationDTO.parameters().get(parameter.name());
if (paramSpecDto == null){
throw new InternalServerError("Parameter " + parameter.name() + " not found in algorithm:" + exareme2AlgorithmSpecificationDTO.name());
}
exareme2Parameters.put(parameter.name(), convertStringToProperExareme2ParameterTypeAccordingToSpecs(parameter.value(), paramSpecDto));
});
return exareme2Parameters;
}
Expand All @@ -103,6 +119,9 @@ private static Map<String, Object> getPreprocessing(List<ExperimentExecutionDTO.
if (transformerSpecificationDTO.isEmpty()) throw new InternalServerError("Missing the transformer: " + transformer_name);

Exareme2AlgorithmSpecificationDTO.Exareme2AlgorithmParameterSpecificationDTO paramSpecDto = transformerSpecificationDTO.get().parameters().get(param_name);
if (paramSpecDto == null){
throw new InternalServerError("Parameter " + parameter.name() + " not found in transformer:" + transformerSpecificationDTO.get().name());
}
transformerParameterDTOs.put(param_name, convertStringToProperExareme2ParameterTypeAccordingToSpecs(parameter.value(), paramSpecDto));
}
exareme2Preprocessing.put(transformer_name, transformerParameterDTOs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public record Exareme2AlgorithmSpecificationDTO(
String desc,
Exareme2AlgorithmInputdataSpecificationDTO inputdata,
Map<String, Exareme2AlgorithmParameterSpecificationDTO> parameters,
List<Exareme2TransformerSpecificationDTO> preprocessing
List<Exareme2TransformerSpecificationDTO> preprocessing,
String type
) {
@Override
public Map<String, Exareme2AlgorithmParameterSpecificationDTO> parameters() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hbp/mip/experiment/ExperimentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private ExperimentAlgorithmResultDTO runExaremeAlgorithm(UUID uuid, ExperimentEx
String algorithmName = experimentExecutionDTO.algorithm().name();
String algorithmEndpoint = exareme2AlgorithmsUrl + "/" + algorithmName;
Exareme2AlgorithmSpecificationDTO exareme2AlgorithmSpecificationDTO = getAlgorithmSpec(algorithmName);
var exareme2AlgorithmRequestDTO = new Exareme2AlgorithmRequestDTO(uuid, experimentExecutionDTO.algorithm().parameters(), experimentExecutionDTO.algorithm().preprocessing(), exareme2AlgorithmSpecificationDTO);
var exareme2AlgorithmRequestDTO = Exareme2AlgorithmRequestDTO.create(uuid, experimentExecutionDTO.algorithm().parameters(), experimentExecutionDTO.algorithm().preprocessing(), exareme2AlgorithmSpecificationDTO);
String algorithmBody = convertObjectToJsonString(exareme2AlgorithmRequestDTO);
logger.debug("Exareme2 algorithm request, endpoint: " + algorithmEndpoint);
logger.debug("Exareme2 algorithm request, body: " + algorithmBody);
Expand Down

0 comments on commit 4ff362a

Please sign in to comment.