From 74195c1d3784f010ce8a2de8c3400ff2921849d0 Mon Sep 17 00:00:00 2001 From: elopezcastro <82950460+elopezcastro@users.noreply.github.com> Date: Tue, 10 Oct 2023 13:13:21 +0200 Subject: [PATCH] make info endpoint a singlenton --- .../services/serverInfo/InfoService.java | 38 ++++--------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/legend-depot-core-data-services/src/main/java/org/finos/legend/depot/services/serverInfo/InfoService.java b/legend-depot-core-data-services/src/main/java/org/finos/legend/depot/services/serverInfo/InfoService.java index cb02ab048..b9a5e8940 100644 --- a/legend-depot-core-data-services/src/main/java/org/finos/legend/depot/services/serverInfo/InfoService.java +++ b/legend-depot-core-data-services/src/main/java/org/finos/legend/depot/services/serverInfo/InfoService.java @@ -33,19 +33,18 @@ public class InfoService private static final Logger LOGGER = LoggerFactory.getLogger(InfoService.class); private static final String PLATFORM_VERSION_FILE = "version.json"; private static final ObjectMapper JSON = new ObjectMapper(); - private static final long MEGABYTE = 1024L * 1024L; - private ServerInfo serverInfo; + private final ServerInfo serverInfo; + - @Inject public InfoService() { - String hostName = tryGetValue(InfoService::getLocalHostName); - InfoService.PlatformVersionInfo platformVersionInfo = tryGetValue(InfoService::getPlatformVersionInfo); + String hostName = tryGetValue(() -> getLocalHostName()); + InfoService.PlatformVersionInfo platformVersionInfo = tryGetValue(() -> getPlatformVersionInfo()); this.serverInfo = new InfoService.ServerInfo(hostName, platformVersionInfo); } - private static T tryGetValue(InfoService.SupplierWithException supplier) + private T tryGetValue(InfoService.SupplierWithException supplier) { try { @@ -58,12 +57,12 @@ private static T tryGetValue(InfoService.SupplierWithException supplier) } } - private static String getLocalHostName() throws UnknownHostException + private String getLocalHostName() throws UnknownHostException { return InetAddress.getLocalHost().getHostName(); } - private static InfoService.PlatformVersionInfo getPlatformVersionInfo() throws IOException + private InfoService.PlatformVersionInfo getPlatformVersionInfo() throws IOException { URL url = InfoService.class.getClassLoader().getResource(PLATFORM_VERSION_FILE); return url == null ? null : JSON.readValue(url, PlatformVersionInfo.class); @@ -124,12 +123,9 @@ public String getBuildRevision() } } - public class ServerInfo + public static class ServerInfo { private final String hostName; - private final long totalMemory; - private final long maxMemory; - private final long usedMemory; private final String serverTimeZone; private final InfoService.ServerPlatformInfo platform; @@ -137,9 +133,6 @@ private ServerInfo(String hostName, InfoService.PlatformVersionInfo platformVers { this.hostName = hostName; this.platform = platformVersionInfo == null ? new InfoService.ServerPlatformInfo() : new InfoService.ServerPlatformInfo(platformVersionInfo.version, platformVersionInfo.buildTime, platformVersionInfo.gitRevision); - this.totalMemory = Runtime.getRuntime().totalMemory() / MEGABYTE; - this.maxMemory = Runtime.getRuntime().maxMemory() / MEGABYTE; - this.usedMemory = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / MEGABYTE; this.serverTimeZone = DatesHandler.ZONE_ID.getId(); } @@ -148,21 +141,6 @@ public String getHostName() return this.hostName; } - public long getMaxMemory() - { - return maxMemory; - } - - public long getUsedMemory() - { - return usedMemory; - } - - public long getTotalMemory() - { - return totalMemory; - } - public InfoService.ServerPlatformInfo getPlatform() { return this.platform;