mirror of
https://github.com/HangarMC/Hangar.git
synced 2025-01-24 14:24:47 +08:00
added /statusz route
This commit is contained in:
parent
562ee62e0c
commit
ce21e8215a
@ -172,11 +172,6 @@ public class Apiv1Controller extends HangarController {
|
||||
return ResponseEntity.ok((ObjectNode) userObj);
|
||||
}
|
||||
|
||||
@RequestMapping("/statusz")
|
||||
public Object showStatusZ() {
|
||||
return null; // TODO implement showStatusZ request controller
|
||||
}
|
||||
|
||||
private ArrayNode writeUsers(List<UsersTable> usersTables) {
|
||||
ArrayNode usersArray = mapper.createArrayNode();
|
||||
List<Long> userIds = usersTables.stream().map(UsersTable::getId).collect(Collectors.toList());
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.papermc.hangar.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.papermc.hangar.controller.util.StatusZ;
|
||||
import io.papermc.hangar.db.customtypes.LoggedActionType;
|
||||
import io.papermc.hangar.db.customtypes.LoggedActionType.ProjectContext;
|
||||
import io.papermc.hangar.db.model.Stats;
|
||||
@ -29,12 +31,14 @@ import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
@ -60,11 +64,12 @@ public class ApplicationController extends HangarController {
|
||||
private final JobService jobService;
|
||||
private final SitemapService sitemapService;
|
||||
private final StatsService statsService;
|
||||
private final StatusZ statusZ;
|
||||
|
||||
private final HttpServletRequest request;
|
||||
|
||||
@Autowired
|
||||
public ApplicationController(UserService userService, ProjectService projectService, OrgService orgService, VersionService versionService, FlagService flagService, UserActionLogService userActionLogService, JobService jobService, SitemapService sitemapService, StatsService statsService, HttpServletRequest request) {
|
||||
public ApplicationController(UserService userService, ProjectService projectService, OrgService orgService, VersionService versionService, FlagService flagService, UserActionLogService userActionLogService, JobService jobService, SitemapService sitemapService, StatsService statsService, StatusZ statusZ, HttpServletRequest request) {
|
||||
this.userService = userService;
|
||||
this.projectService = projectService;
|
||||
this.orgService = orgService;
|
||||
@ -73,6 +78,7 @@ public class ApplicationController extends HangarController {
|
||||
this.versionService = versionService;
|
||||
this.jobService = jobService;
|
||||
this.sitemapService = sitemapService;
|
||||
this.statusZ = statusZ;
|
||||
this.request = request;
|
||||
this.statsService = statsService;
|
||||
}
|
||||
@ -84,6 +90,11 @@ public class ApplicationController extends HangarController {
|
||||
return fillModel(mav);
|
||||
}
|
||||
|
||||
@RequestMapping("/statusz")
|
||||
public ResponseEntity<ObjectNode> showStatusZ() {
|
||||
return ResponseEntity.ok(statusZ.getStatus());
|
||||
}
|
||||
|
||||
@Secured("ROLE_USER")
|
||||
@GetMapping("/admin/activities/{user}")
|
||||
public ModelAndView showActivities(@PathVariable String user) {
|
||||
|
42
src/main/java/io/papermc/hangar/controller/util/StatusZ.java
Normal file
42
src/main/java/io/papermc/hangar/controller/util/StatusZ.java
Normal file
@ -0,0 +1,42 @@
|
||||
package io.papermc.hangar.controller.util;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.papermc.hangar.config.hangar.HangarConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class StatusZ {
|
||||
|
||||
private final ObjectNode status;
|
||||
|
||||
private final String BUILD_NUM = "BUILD_NUMBER";
|
||||
private final String GIT_BRANCH = "GIT_BRANCH";
|
||||
private final String GIT_COMMIT = "GIT_COMMIT";
|
||||
private final String JOB_NAME = "JOB_NAME";
|
||||
private final String BUILD_TAG = "BUILD_TAG";
|
||||
private final String HANGAR_ENV = "HANGAR_ENV";
|
||||
private final String SERVICE = "SERVICE";
|
||||
|
||||
@Autowired
|
||||
public StatusZ(HangarConfig hangarConfig, ObjectMapper mapper) {
|
||||
status = mapper.createObjectNode();
|
||||
status.set(BUILD_NUM, mapper.valueToTree(getEnv(BUILD_NUM)));
|
||||
status.set(GIT_BRANCH, mapper.valueToTree(getEnv(GIT_BRANCH)));
|
||||
status.set(GIT_COMMIT, mapper.valueToTree(getEnv(GIT_COMMIT)));
|
||||
status.set(JOB_NAME, mapper.valueToTree(getEnv(JOB_NAME)));
|
||||
status.set(BUILD_TAG, mapper.valueToTree(getEnv(BUILD_TAG)));
|
||||
status.set(HANGAR_ENV, mapper.valueToTree(getEnv(HANGAR_ENV)));
|
||||
status.set(SERVICE, mapper.valueToTree(hangarConfig.getService()));
|
||||
|
||||
}
|
||||
|
||||
public ObjectNode getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
private String getEnv(String key) {
|
||||
return System.getenv().getOrDefault(key, "unknown");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user