package uk.ac.ebi.atlas.monitoring;

import com.google.common.collect.ImmutableMap;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import uk.ac.ebi.atlas.experimentimport.GxaExperimentDao;

import javax.inject.Inject;
import java.util.Arrays;

import static uk.ac.ebi.atlas.utils.GsonProvider.GSON;

@RestController
public final class HealthCheckController {

    private HealthCheckService healthCheckService;
    private GxaExperimentDao experimentDao;

    @Inject
    public HealthCheckController(HealthCheckService healthCheckService, GxaExperimentDao experimentDao) {
        this.healthCheckService = healthCheckService;
        this.experimentDao = experimentDao;
    }

    // This is the legacy endpoint that we will maintain until the settings on the load balancer can be adjusted
    @RequestMapping(
            value = "/json/dbsolr/status",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getHealthStatusLegacy(){
        return GSON.toJson(ImmutableMap.of(
                "Solr", healthCheckService.isSolrUp(Arrays.asList("analytics", "bioentities")) ? "UP" : "DOWN",
                "DB", healthCheckService.isDatabaseUp(experimentDao) ? "UP" : "DOWN"
        ));
    }

    @GetMapping(
            value = "/json/health",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getHealthStatus(){
        return GSON.toJson(ImmutableMap.of(
                "solr", healthCheckService.isSolrUp(Arrays.asList("analytics", "bioentities")) ? "UP" : "DOWN",
                "db", healthCheckService.isDatabaseUp(experimentDao) ? "UP" : "DOWN"
        ));
    }
}

@@ -1298,20 +1298,18 @@
        %22
-Solr
+DB
 %22, healt
@@ -1328,56 +1328,32 @@
 e.is
-SolrUp(Arrays.asList(%22analytics%22, %22bioentities%22)
+DatabaseUp(experimentDao
 ) ? 
@@ -1376,34 +1376,36 @@
                %22
-DB
+Solr
 %22, healthCheckSe
@@ -1416,32 +1416,56 @@
 e.is
-DatabaseUp(experimentDao
+SolrUp(Arrays.asList(%22analytics%22, %22bioentities%22)
 ) ? 

Swap Solr/DB fields (#151)