Skip to content

Commit

Permalink
feat: Healthz-controller (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolagospagopa authored Jun 4, 2022
1 parent ed0fbdf commit ed8bb76
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
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.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.HttpStatus;


@RestController
Expand Down Expand Up @@ -42,25 +40,4 @@ public Map<String, String> envs()
});
return map;
}

/*
* Liveness & Readiness
*/
@GetMapping(path = "/live", produces=MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public Map<String, Boolean> live()
{
HashMap<String, Boolean> map = new HashMap<>();
map.put("live", true);
return map;
}

@GetMapping(path = "/ready", produces=MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public Map<String, Boolean> ready()
{
HashMap<String, Boolean> map = new HashMap<>();
map.put("ready", true);
return map;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package it.pagopa.devops.springbootshowcase;

import java.util.HashMap;
import java.util.Map;

import org.springframework.http.HttpStatus;
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.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/healthz")
public class HealthzController {

@GetMapping(path = "", produces=MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public Map<String, String> mainHealthz()
{
return root();
}

@GetMapping(path = "/", produces=MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public Map<String, String> root()
{
HashMap<String, String> map = new HashMap<>();
map.put("healthz", "ok");
return map;
}

/*
* Liveness & Readiness
*/
@GetMapping(path = "/live", produces=MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public Map<String, Boolean> live()
{
HashMap<String, Boolean> map = new HashMap<>();
map.put("live", true);
return map;
}

@GetMapping(path = "/ready", produces=MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public Map<String, Boolean> ready()
{
HashMap<String, Boolean> map = new HashMap<>();
map.put("ready", true);
return map;
}
}

0 comments on commit ed8bb76

Please sign in to comment.