All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.farao_community.farao.gridcapa.job_launcher.RaoLogsDispatcherService Maven / Gradle / Ivy

Go to download

Service responsible of dispatching logs coming from rao runner's pool to the concerned calling application.

The newest version!
/*
 * Copyright (c) 2022, RTE (http://www.rte-france.com)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package com.farao_community.farao.gridcapa.job_launcher;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import java.util.function.Function;

import com.farao_community.farao.gridcapa.task_manager.api.TaskLogEventUpdate;
import reactor.core.publisher.Flux;

/**
 * @author Mohamed Benrejeb {@literal }
 */
@Service
public class RaoLogsDispatcherService {

    private static final Logger LOGGER = LoggerFactory.getLogger(RaoLogsDispatcherService.class);

    ObjectMapper objectMapper = new ObjectMapper();

    @Value("${client.name}")
    private String clientName;

    @Bean
    public Function, Flux> dispatchRaoEvents() {
        return f -> f
            .onErrorContinue((t, r) -> LOGGER.error("Error while processing message: \"" + r + "\". Error message is: " + t.getMessage(), t))
            .map(this::parseLog)
            .filter(raoRunnerLogsModel -> clientName.equals(raoRunnerLogsModel.getClientAppId()))
            .map(log -> new TaskLogEventUpdate(log.getGridcapaTaskId(), log.getTimestamp(), log.getLevel(), log.getMessage(), log.getServiceName(), log.getEventPrefix()));
    }

    RaoRunnerLogsModel parseLog(String logEventString) {
        try {
            return objectMapper.readValue(logEventString, RaoRunnerLogsModel.class);
        } catch (JsonProcessingException e) {
            LOGGER.error("parsing exception occurred while reading log event '{}', event will be ignored", logEventString);
            return new RaoRunnerLogsModel("", "", "", "", "", "", "", "");
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy