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

io.quarkus.test.logging.KubernetesLoggingHandler Maven / Gradle / Ivy

There is a newer version: 1.6.0.Beta14
Show newest version
package io.quarkus.test.logging;

import java.util.Map;
import java.util.Map.Entry;

import io.quarkus.test.bootstrap.KubernetesExtensionBootstrap;
import io.quarkus.test.bootstrap.Service;
import io.quarkus.test.bootstrap.ServiceContext;
import io.quarkus.test.bootstrap.inject.KubectlClient;

public class KubernetesLoggingHandler extends ServiceLoggingHandler {

    private final KubectlClient client;
    private final Service service;

    private Map oldLogs;

    public KubernetesLoggingHandler(ServiceContext context) {
        super(context.getOwner());

        service = context.getOwner();
        client = context.get(KubernetesExtensionBootstrap.CLIENT);
    }

    @Override
    protected synchronized void handle() {
        Map newLogs = client.logs(service);
        for (Entry entry : newLogs.entrySet()) {
            onMapDifference(entry);
        }

        oldLogs = newLogs;
    }

    private void onMapDifference(Entry entry) {
        String newPodLogs = formatPodLogs(entry.getKey(), entry.getValue());

        if (oldLogs != null && oldLogs.containsKey(entry.getKey())) {
            String oldPodLogs = formatPodLogs(entry.getKey(), oldLogs.get(entry.getKey()));

            onStringDifference(newPodLogs, oldPodLogs);
        } else {
            onLines(newPodLogs);
        }
    }

    private String formatPodLogs(String podName, String log) {
        return String.format("[%s] %s", podName, log);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy