diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/BukkitInfoSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/BukkitInfoSystem.java index c588fb8c8..3818e46b8 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/BukkitInfoSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/BukkitInfoSystem.java @@ -4,6 +4,7 @@ */ package com.djrapitops.plan.system.info; +import com.djrapitops.plan.api.exceptions.connection.NoServersException; import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.system.info.connection.BukkitConnectionSystem; import com.djrapitops.plan.system.info.request.CacheNetworkPageContentRequest; @@ -26,7 +27,7 @@ public class BukkitInfoSystem extends InfoSystem { @Override public void runLocally(InfoRequest infoRequest) throws WebException { if (infoRequest instanceof SetupRequest) { - return; + throw new NoServersException("Set-up requests can not be run locally."); } infoRequest.runLocally(); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/BungeeInfoSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/BungeeInfoSystem.java index 22b93e5fc..be6018541 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/BungeeInfoSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/BungeeInfoSystem.java @@ -30,7 +30,7 @@ public class BungeeInfoSystem extends InfoSystem { @Override public void runLocally(InfoRequest infoRequest) throws WebException { // runLocally is called when ConnectionSystem has no servers. - throw new NoServersException("No servers were available to process this request."); + throw new NoServersException("No servers were available to process this request (Local attempt): " + infoRequest.getClass().getSimpleName()); } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java index 626e140f7..14524d6fd 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java @@ -66,10 +66,16 @@ public abstract class InfoSystem implements SubSystem { try { if (!connectionSystem.isServerAvailable()) { runLocally(infoRequest); + return; } connectionSystem.sendInfoRequest(infoRequest); - } catch (NoServersException e) { - runLocally(infoRequest); + } catch (WebException original) { + try { + // Attempt to run locally. + runLocally(infoRequest); + } catch (NoServersException e2) { + throw original; + } } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BukkitConnectionSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BukkitConnectionSystem.java index 0c15fee69..1f35f877b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BukkitConnectionSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BukkitConnectionSystem.java @@ -17,8 +17,6 @@ import com.djrapitops.plan.system.webserver.WebServerSystem; import com.djrapitops.plan.utilities.MiscUtils; import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.api.utility.log.Log; -import com.djrapitops.plugin.task.AbsRunnable; -import com.djrapitops.plugin.task.RunnableFactory; import java.util.Optional; import java.util.UUID; @@ -39,7 +37,7 @@ public class BukkitConnectionSystem extends ConnectionSystem { } private void refreshServerMap() { - if (latestServerMapRefresh < MiscUtils.getTime() - TimeAmount.MINUTE.ms() * 2L) { + if (latestServerMapRefresh < MiscUtils.getTime() - TimeAmount.SECOND.ms() * 15L) { try { Database database = Database.getActive(); Optional bungeeInformation = database.fetch().getBungeeInformation(); @@ -57,7 +55,7 @@ public class BukkitConnectionSystem extends ConnectionSystem { refreshServerMap(); if (mainServer == null && bukkitServers.isEmpty()) { - throw new NoServersException("No Servers available to process requests."); + throw new NoServersException("Zero servers available to process requests."); } Server server = null; @@ -81,7 +79,7 @@ public class BukkitConnectionSystem extends ConnectionSystem { @Override public void sendWideInfoRequest(WideRequest infoRequest) throws NoServersException { if (bukkitServers.isEmpty()) { - throw new NoServersException("No Servers Available to make process request."); + throw new NoServersException("No Servers available to make wide-request: " + infoRequest.getClass().getSimpleName()); } for (Server server : bukkitServers.values()) { WebExceptionLogger.logIfOccurs(this.getClass(), () -> sendInfoRequest(infoRequest, server)); @@ -90,7 +88,7 @@ public class BukkitConnectionSystem extends ConnectionSystem { @Override public boolean isServerAvailable() { - return ConnectionLog.hasConnectionSucceeded(mainServer); + return mainServer != null && Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.isFalse(); } @Override @@ -102,12 +100,6 @@ public class BukkitConnectionSystem extends ConnectionSystem { @Override public void enable() { refreshServerMap(); - RunnableFactory.createNew("Server List Update Task", new AbsRunnable() { - @Override - public void run() { - refreshServerMap(); - } - }).runTaskTimerAsynchronously(TimeAmount.SECOND.ticks() * 30L, TimeAmount.MINUTE.ticks() * 5L); boolean usingBungeeWebServer = ConnectionSystem.getInstance().isServerAvailable(); boolean usingAlternativeIP = Settings.SHOW_ALTERNATIVE_IP.isTrue(); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java index 5a08412de..019d49dbf 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java @@ -9,13 +9,10 @@ import com.djrapitops.plan.api.exceptions.database.DBException; import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.info.request.*; import com.djrapitops.plan.system.info.server.Server; -import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.webserver.WebServerSystem; import com.djrapitops.plan.utilities.MiscUtils; import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.api.utility.log.Log; -import com.djrapitops.plugin.task.AbsRunnable; -import com.djrapitops.plugin.task.RunnableFactory; import java.util.Optional; import java.util.UUID; @@ -34,7 +31,7 @@ public class BungeeConnectionSystem extends ConnectionSystem { } private void refreshServerMap() { - if (latestServerMapRefresh < MiscUtils.getTime() - TimeAmount.MINUTE.ms() * 2L) { + if (latestServerMapRefresh < MiscUtils.getTime() - TimeAmount.SECOND.ms() * 15L) { try { bukkitServers = Database.getActive().fetch().getBukkitServers(); latestServerMapRefresh = MiscUtils.getTime(); @@ -46,6 +43,7 @@ public class BungeeConnectionSystem extends ConnectionSystem { @Override protected Server selectServerForRequest(InfoRequest infoRequest) throws NoServersException { + refreshServerMap(); Server server = null; if (infoRequest instanceof CacheRequest) { throw new NoServersException("Bungee should not send Cache requests."); @@ -55,7 +53,7 @@ public class BungeeConnectionSystem extends ConnectionSystem { } else if (infoRequest instanceof GenerateInspectPageRequest) { Optional serverUUID = getServerWherePlayerIsOnline((GenerateInspectPageRequest) infoRequest); if (serverUUID.isPresent()) { - server = bukkitServers.getOrDefault(serverUUID.get(), ServerInfo.getServer()); + server = bukkitServers.getOrDefault(serverUUID.get(), getOneBukkitServer()); } } if (server == null) { @@ -64,10 +62,16 @@ public class BungeeConnectionSystem extends ConnectionSystem { return server; } + private Server getOneBukkitServer() { + Optional first = bukkitServers.values().stream().findAny(); + return first.orElse(null); + } + @Override public void sendWideInfoRequest(WideRequest infoRequest) throws NoServersException { + refreshServerMap(); if (bukkitServers.isEmpty()) { - throw new NoServersException("No Servers Available to make process request."); + throw new NoServersException("No Servers available to make wide-request: " + infoRequest.getClass().getSimpleName()); } for (Server server : bukkitServers.values()) { WebExceptionLogger.logIfOccurs(this.getClass(), () -> sendInfoRequest(infoRequest, server)); @@ -87,12 +91,6 @@ public class BungeeConnectionSystem extends ConnectionSystem { @Override public void enable() { refreshServerMap(); - RunnableFactory.createNew("Server List Update Task", new AbsRunnable() { - @Override - public void run() { - refreshServerMap(); - } - }).runTaskTimerAsynchronously(TimeAmount.SECOND.ticks() * 30L, TimeAmount.MINUTE.ticks() * 5L); } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionLog.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionLog.java index 8e35a2d81..aaaae7085 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionLog.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionLog.java @@ -7,7 +7,6 @@ package com.djrapitops.plan.system.info.connection; import com.djrapitops.plan.system.info.request.InfoRequest; import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.utilities.MiscUtils; -import com.djrapitops.plugin.utilities.Verify; import java.util.HashMap; import java.util.Map; @@ -37,35 +36,6 @@ public class ConnectionLog { log.put(toServer, requestMap); } - public static boolean isConnectionPlausible(Server server) { - if (server == null) { - return false; - } - - Map serverLog = getInstance().getLog().get(server); - return Verify.isEmpty(serverLog) || hasConnectionSucceeded(serverLog); - - } - - public static boolean hasConnectionSucceeded(Server server) { - if (server == null) { - return false; - } - Map serverLog = getInstance().getLog().get(server); - return !Verify.isEmpty(serverLog) - && hasConnectionSucceeded(serverLog); - - } - - private static boolean hasConnectionSucceeded(Map serverLog) { - for (Entry entry : serverLog.values()) { - if (entry.responseCode == 200) { - return true; - } - } - return false; - } - private static ConnectionLog getInstance() { return ConnectionSystem.getInstance().getConnectionLog(); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java index 49c56831a..a2f4ce5dc 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java @@ -17,10 +17,7 @@ import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.utilities.NullCheck; import com.djrapitops.plugin.api.utility.log.Log; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; +import java.util.*; /** * ConnectionSystem manages out- and inbound InfoRequest connections. @@ -121,4 +118,8 @@ public abstract class ConnectionSystem implements SubSystem { putRequest(requests, SendDBSettingsRequest.createHandler()); return requests; } + + public List getBukkitServers() { + return new ArrayList<>(bukkitServers.values()); + } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/ResponseHandler.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/ResponseHandler.java index c6c72a1d5..d9f4d5ffa 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/ResponseHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/ResponseHandler.java @@ -87,10 +87,10 @@ public class ResponseHandler extends TreePageHandler { } try { return getResponse(request, targetString, target); + } catch (NoServersException | NotFoundException e) { + return new NotFoundResponse(e.getMessage()); } catch (WebUserAuthException e) { return PromptAuthorizationResponse.getBasicAuthResponse(e); - } catch (NotFoundException e) { - return new NotFoundResponse(e.getMessage()); } catch (ForbiddenException e) { return new ForbiddenResponse(e.getMessage()); } catch (BadRequestException e) { diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/AnalysisPageResponse.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/AnalysisPageResponse.java index 6e6d49aa4..4c03db5ec 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/AnalysisPageResponse.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/AnalysisPageResponse.java @@ -2,11 +2,14 @@ package com.djrapitops.plan.system.webserver.response.pages; import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.system.info.InfoSystem; +import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.processing.Processor; import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.errors.ErrorResponse; import com.djrapitops.plugin.api.utility.log.Log; +import java.util.UUID; + /** * @author Rsl1122 * @since 3.5.2 @@ -14,9 +17,13 @@ import com.djrapitops.plugin.api.utility.log.Log; public class AnalysisPageResponse extends Response { public static AnalysisPageResponse refreshNow() { + return refreshNow(ServerInfo.getServerUUID()); + } + + public static AnalysisPageResponse refreshNow(UUID serverUUID) { Processor.queue(() -> { try { - InfoSystem.getInstance().generateAnalysisPageOfThisServer(); + InfoSystem.getInstance().generateAnalysisPage(serverUUID); } catch (WebException e) { // TODO Exception handling Log.toLog(AnalysisPageResponse.class, e); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/DebugPageResponse.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/DebugPageResponse.java index 4e6fa77eb..856c1ffc7 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/DebugPageResponse.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/DebugPageResponse.java @@ -8,6 +8,7 @@ import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.sql.SQLDB; import com.djrapitops.plan.system.info.connection.ConnectionLog; +import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerProperties; @@ -66,8 +67,8 @@ public class DebugPageResponse extends ErrorResponse { try { Map> logEntries = ConnectionLog.getLogEntries(); - content.append("
");
-            content.append("Server Address | Request Type | Sent | Response
") + content.append("
**Connection Log:**
"); + content.append("Server Address | Request Type | Response | Sent
") .append("-- | -- | -- | --
"); for (Map.Entry> entry : logEntries.entrySet()) { Server server = entry.getKey(); @@ -85,6 +86,17 @@ public class DebugPageResponse extends ErrorResponse { } content.append("
"); + content.append("
**Servers:**
"); + List servers = ConnectionSystem.getInstance().getBukkitServers(); + content.append("Server Name | Address | UUID
") + .append("-- | -- | --
"); + for (Server server : servers) { + content.append(server.getName()).append(" | ") + .append(server.getWebAddress()).append(" | ") + .append(server.getUuid()).append(" | ").append("
"); + } + content.append("
"); + } catch (Exception e) { Log.toLog(this.getClass(), e); }