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

de.otto.edison.status.controller.StatusController Maven / Gradle / Ivy

There is a newer version: 3.3.3
Show newest version
package de.otto.edison.status.controller;

import de.otto.edison.status.controller.StatusRepresentation.DependencyRepresentation;
import de.otto.edison.status.domain.Criticality;
import de.otto.edison.status.domain.ExternalDependency;
import de.otto.edison.status.indicator.ApplicationStatusAggregator;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;

import static de.otto.edison.status.controller.StatusRepresentation.statusRepresentationOf;
import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.toList;
import static org.springframework.web.bind.annotation.RequestMethod.GET;

@RestController
public class StatusController {

    @Autowired
    private ApplicationStatusAggregator aggregator;
    @Autowired
    private ExternalDependencies externalDependencies;
    @Autowired(required = false)
    private Criticality criticality;

    @RequestMapping(
            value = "${edison.application.management.base-path:/internal}/status",
            produces = {
                    "application/hal+json",
                    "application/vnd.otto.monitoring.status+json",
                    "application/json"},
            method = GET
    )
    public StatusRepresentation getStatusAsJson() {
        return statusRepresentationOf(
                aggregator.aggregatedStatus(),
                criticality,
                externalDependencies.getDependencies());
    }

    @RequestMapping(
            value = "${edison.application.management.base-path:/internal}/status",
            produces = "text/html",
            method = GET
    )
    public ModelAndView getStatusAsHtml() {
        return new ModelAndView("status", new HashMap() {{
            put("status", aggregator.aggregatedStatus());
            put("criticality", criticality);
            put("dependencies", externalDependencies.getDependencies()
                    .stream()
                    .sorted(comparing(ExternalDependency::getType).thenComparing(ExternalDependency::getName))
                    .map(DependencyRepresentation::new)
                    .collect(toList()));
        }});
    }

}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy