Plugins tab caching to bungee

This commit is contained in:
Rsl1122 2017-09-16 18:57:50 +03:00
parent b14ed6fac2
commit 116675f8a6
5 changed files with 218 additions and 9 deletions

View File

@ -23,8 +23,11 @@ import main.java.com.djrapitops.plan.systems.webserver.response.InspectPageRespo
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
import main.java.com.djrapitops.plan.systems.webserver.theme.Theme;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager;
import main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit.RequestInspectPluginsTabBukkitWebAPI;
import main.java.com.djrapitops.plan.systems.webserver.webapi.bungee.IsCachedWebAPI;
import main.java.com.djrapitops.plan.systems.webserver.webapi.bungee.PostHtmlWebAPI;
import main.java.com.djrapitops.plan.systems.webserver.webapi.bungee.PostInspectPluginsTabWebAPI;
import main.java.com.djrapitops.plan.systems.webserver.webapi.bungee.RequestPluginsTabWebAPI;
import main.java.com.djrapitops.plan.systems.webserver.webapi.universal.PingWebAPI;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.analysis.Analysis;
@ -92,8 +95,16 @@ public class BukkitInformationManager extends InformationManager {
}
public void cacheInspectPluginsTab(UUID uuid) {
if (usingBungeeWebServer) {
// TODO plugin tab request on bungee
cacheInspectPluginsTab(uuid, this.getClass());
}
public void cacheInspectPluginsTab(UUID uuid, Class origin) {
if (usingBungeeWebServer && !origin.equals(RequestInspectPluginsTabBukkitWebAPI.class)) {
try {
getWebAPI().getAPI(RequestPluginsTabWebAPI.class).sendRequest(webServerAddress, uuid);
} catch (WebAPIException e) {
Log.toLog(this.getClass().getName(), e);
}
} else {
String serverName = plugin.getServerInfoManager().getServerName();
HookHandler hookHandler = plugin.getHookHandler();
@ -105,10 +116,18 @@ public class BukkitInformationManager extends InformationManager {
}
public void cacheInspectPluginsTab(UUID uuid, String contents) {
pluginsTabContents.put(uuid, contents);
Response inspectResponse = PageCache.loadPage("inspectPage: " + uuid);
if (inspectResponse != null) {
((InspectPageResponse) inspectResponse).setInspectPagePluginsTab(contents);
if (usingBungeeWebServer) {
try {
getWebAPI().getAPI(PostInspectPluginsTabWebAPI.class).sendPluginsTab(webServerAddress, uuid, contents);
} catch (WebAPIException e) {
Log.toLog(this.getClass().getName(), e);
}
} else {
pluginsTabContents.put(uuid, contents);
Response inspectResponse = PageCache.loadPage("inspectPage: " + uuid);
if (inspectResponse != null) {
((InspectPageResponse) inspectResponse).setInspectPagePluginsTab(contents);
}
}
}
@ -158,9 +177,6 @@ public class BukkitInformationManager extends InformationManager {
@Override
public String getPlayerHtml(UUID uuid) {
if (usingBungeeWebServer) {
// TODO Bungee request
}
try {
return Theme.replaceColors(new InspectPageParser(uuid, plugin).parse());
} catch (ParseException e) {

View File

@ -15,6 +15,7 @@ import main.java.com.djrapitops.plan.systems.webserver.response.InspectPageRespo
import main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit.AnalyzeWebAPI;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.function.Function;
@ -30,8 +31,11 @@ public class BungeeInformationManager extends InformationManager {
private PlanBungee plugin;
private Map<UUID, ServerInfo> bukkitServers;
private Map<UUID, Map<UUID, String>> pluginsTabContent;
public BungeeInformationManager(PlanBungee plugin) throws SQLException {
usingBungeeWebServer = true;
pluginsTabContent = new HashMap<>();
this.plugin = plugin;
refreshBukkitServerMap();
}
@ -104,4 +108,10 @@ public class BungeeInformationManager extends InformationManager {
public String getPluginsTabContent(UUID uuid) {
return null;
}
public void cachePluginsTabContent(UUID serverUUID, UUID uuid, String html) {
Map<UUID, String> perServerPluginsTab = pluginsTabContent.getOrDefault(uuid, new HashMap<>());
perServerPluginsTab.put(serverUUID, html);
pluginsTabContent.put(uuid, perServerPluginsTab);
}
}

View File

@ -0,0 +1,54 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit;
import com.djrapitops.plugin.utilities.Compatibility;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIException;
import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager;
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
import main.java.com.djrapitops.plan.systems.webserver.response.api.BadRequestResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.api.SuccessResponse;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPI;
import java.util.Map;
import java.util.UUID;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class RequestInspectPluginsTabBukkitWebAPI extends WebAPI {
@Override
public Response onResponse(IPlan plugin, Map<String, String> variables) {
if (!Compatibility.isBukkitAvailable()) {
String error = "Called a Bungee Server";
return PageCache.loadPage(error, () -> new BadRequestResponse(error));
}
String uuidS = variables.get("uuid");
if (uuidS == null) {
String error = "UUID not included";
return PageCache.loadPage(error, () -> new BadRequestResponse(error));
}
UUID uuid = UUID.fromString(uuidS);
((BukkitInformationManager) plugin.getInfoManager()).cacheInspectPluginsTab(uuid, this.getClass());
return PageCache.loadPage("success", SuccessResponse::new);
}
@Override
public void sendRequest(String address) throws WebAPIException {
throw new IllegalStateException("Wrong method call for this WebAPI, call sendRequest(String, UUID, UUID) instead.");
}
public void sendRequest(String address, UUID uuid) throws WebAPIException {
addVariable("uuid", uuid.toString());
super.sendRequest(address);
}
}

View File

@ -0,0 +1,54 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package main.java.com.djrapitops.plan.systems.webserver.webapi.bungee;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIException;
import main.java.com.djrapitops.plan.systems.info.BungeeInformationManager;
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
import main.java.com.djrapitops.plan.systems.webserver.response.api.BadRequestResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.api.SuccessResponse;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPI;
import java.util.Map;
import java.util.UUID;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class PostInspectPluginsTabWebAPI extends WebAPI {
@Override
public Response onResponse(IPlan plugin, Map<String, String> variables) {
String uuidS = variables.get("uuid");
String sender = variables.get("sender");
if (Verify.notNull(uuidS, sender)) {
String error = "uuid or sender not included";
return PageCache.loadPage(error, () -> new BadRequestResponse(error));
}
UUID uuid = UUID.fromString(uuidS);
UUID serverUUID = UUID.fromString(sender);
String html = variables.get("html");
((BungeeInformationManager) plugin.getInfoManager()).cachePluginsTabContent(serverUUID, uuid, html);
return PageCache.loadPage("success", SuccessResponse::new);
}
@Override
public void sendRequest(String address) throws WebAPIException {
throw new IllegalStateException("Wrong method call for this WebAPI, call sendRequest(String, UUID, UUID) instead.");
}
public void sendPluginsTab(String address, UUID uuid, String html) throws WebAPIException {
addVariable("uuid", uuid.toString());
addVariable("html", html);
super.sendRequest(address);
}
}

View File

@ -0,0 +1,75 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package main.java.com.djrapitops.plan.systems.webserver.webapi.bungee;
import com.djrapitops.plugin.utilities.Compatibility;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIException;
import main.java.com.djrapitops.plan.systems.info.server.ServerInfo;
import main.java.com.djrapitops.plan.systems.processing.Processor;
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
import main.java.com.djrapitops.plan.systems.webserver.response.api.BadRequestResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.api.SuccessResponse;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPI;
import main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit.RequestInspectPluginsTabBukkitWebAPI;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class RequestPluginsTabWebAPI extends WebAPI {
@Override
public Response onResponse(IPlan plugin, Map<String, String> variables) {
if (!Compatibility.isBungeeAvailable()) {
String error = "Called a Bukkit Server";
return PageCache.loadPage(error, () -> new BadRequestResponse(error));
}
String uuidS = variables.get("uuid");
if (uuidS == null) {
String error = "UUID not included";
return PageCache.loadPage(error, () -> new BadRequestResponse(error));
}
UUID uuid = UUID.fromString(uuidS);
plugin.addToProcessQueue(new Processor<UUID>(uuid) {
@Override
public void process() {
try {
List<ServerInfo> bukkitServers = plugin.getDB().getServerTable().getBukkitServers();
for (ServerInfo server : bukkitServers) {
String webAddress = server.getWebAddress();
try {
plugin.getWebServer().getWebAPI().getAPI(RequestInspectPluginsTabBukkitWebAPI.class).sendRequest(webAddress, uuid);
} catch (WebAPIException ignore) {
/* ignored */
}
}
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
}
}
});
return PageCache.loadPage("success", SuccessResponse::new);
}
@Override
public void sendRequest(String address) throws WebAPIException {
throw new IllegalStateException("Wrong method call for this WebAPI, call sendRequest(String, UUID, UUID) instead.");
}
public void sendRequest(String address, UUID uuid) throws WebAPIException {
addVariable("uuid", uuid.toString());
super.sendRequest(address);
}
}