Added build fixes for ServerMonitor.java

Added redis fixes for ServerMonitor
Added ServerStatusManager fixes.
This commit is contained in:
Jonathan Williams 2014-08-14 04:10:11 -05:00
parent f524ffb093
commit 682735e994
6 changed files with 67 additions and 89 deletions

View File

@ -174,6 +174,10 @@
<include name="**/*.class"/>
</fileset>
<fileset dir="../Mineplex.ServerData/bin">
<include name="**/*.class"/>
</fileset>
<zipfileset src="../Libraries/mysql.zip" />
<manifest>
@ -188,6 +192,8 @@
<zipfileset src="../Libraries/gson-2.2.1.jar" />
<zipfileset src="../Libraries/commons-logging-1.1.1.jar" />
<zipfileset src="../Libraries/commons-codec-1.6.jar" />
<zipfileset src="../Libraries/jedis-2.4.2.jar" />
<zipfileset src="../Libraries/commons-pool2-2.2.jar" />
</jar>
<copy file="../bin/ServerMonitor.jar" todir="../../Testing/ServerMonitor/"/>
</target>

View File

@ -2,7 +2,6 @@ package mineplex.core.status;
import java.io.File;
import java.util.Collection;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
@ -30,7 +29,6 @@ public class ServerStatusManager extends MiniPlugin
private String _name;
private boolean _us;
private boolean _alternateSeconds;
private boolean _enabled = true;
public ServerStatusManager(JavaPlugin plugin, LagMeter lagMeter)
@ -41,20 +39,15 @@ public class ServerStatusManager extends MiniPlugin
if (new File("IgnoreUpdates.dat").exists())
_enabled = false;
ServerListPingEvent event = new ServerListPingEvent(null, plugin.getServer().getMotd(), plugin.getServer().getOnlinePlayers().length, plugin.getServer().getMaxPlayers());
GetPluginManager().callEvent(event);
setupConfigValues();
String address = Bukkit.getServer().getIp().isEmpty() ? "localhost" : Bukkit.getServer().getIp();
_name = plugin.getConfig().getString("serverstatus.name");
_us = plugin.getConfig().getBoolean("serverstatus.us");
Region region = _us ? Region.US : Region.EU;
_repository = ServerManager.getServerRepository(region);
saveServerStatus();
}
private void setupConfigValues()
@ -112,11 +105,6 @@ public class ServerStatusManager extends MiniPlugin
if (!_enabled)
return;
_alternateSeconds = !_alternateSeconds;
if (!_alternateSeconds)
return;
saveServerStatus();
}

View File

@ -15,9 +15,6 @@ import redis.clients.jedis.Pipeline;
import redis.clients.jedis.Response;
import redis.clients.jedis.Transaction;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
/**
* RedisServerRepository offers a Redis-based implementation of {@link ServerRepository}
* using a mixture of hash and JSON encoded storage.
@ -138,7 +135,7 @@ public class RedisServerRepository implements ServerRepository
String dataKey = concatenate(setKey, serverName);
Transaction transaction = jedis.multi();
transaction.set(dataKey, null);
transaction.del(dataKey);
transaction.zrem(setKey, serverName);
transaction.exec();
}
@ -204,7 +201,7 @@ public class RedisServerRepository implements ServerRepository
{
for (MinecraftServer minecraftServer : getServerStatuses())
{
if (serverGroups.containsKey(minecraftServer.getGroup()))
if (serverGroups.containsKey(minecraftServer.getGroup()) && minecraftServer.getPublicAddress().equalsIgnoreCase(server.getPrivateAddress()))
{
ServerGroup serverGroup = serverGroups.get(minecraftServer.getGroup());
server.incrementServerCount(serverGroup);
@ -241,32 +238,6 @@ public class RedisServerRepository implements ServerRepository
return servers;
}
@Override
public int clean()
{
Jedis jedis = _jedisPool.getResource();
try
{
String setKey = concatenate("serverstatus", "minecraft", _region.toString());
for (String deadName : getDeadNames(setKey))
{
String dataKey = concatenate(setKey, deadName);
Transaction transaction = jedis.multi();
transaction.del(dataKey);
transaction.zrem(setKey, deadName);
transaction.exec();
}
}
finally
{
_jedisPool.returnResource(jedis);
}
return 0;
}
/**
* @param key - the key where the sorted set of server sessions is stored
* @return the {@link Set} of active server names stored at {@code key} for non-expired
@ -291,29 +262,6 @@ public class RedisServerRepository implements ServerRepository
return names;
}
/**
* @param key - the key where the sorted set of server sessions is stored
* @return the {@link Set} of dead (expired) server names stored at {@code key}.
*/
protected Set<String> getDeadNames(String key)
{
Set<String> names = new HashSet<String>();
Jedis jedis = _jedisPool.getResource();
try
{
String min = "-inf";
String max = System.currentTimeMillis() + "";
names = jedis.zrangeByScore(key, min, max);
}
finally
{
_jedisPool.returnResource(jedis);
}
return names;
}
/**
* @param elements - the elements to concatenate together
* @return the concatenated form of all {@code elements}
@ -324,6 +272,42 @@ public class RedisServerRepository implements ServerRepository
return Utility.concatenate(KEY_DELIMITER, elements);
}
@Override
public Collection<MinecraftServer> getDeadServers()
{
Set<MinecraftServer> servers = new HashSet<MinecraftServer>();
Jedis jedis = _jedisPool.getResource();
try
{
Pipeline pipeline = jedis.pipelined();
String setKey = concatenate("serverstatus", "minecraft", _region.toString());
String min = "-inf";
String max = System.currentTimeMillis() + "";
List<Response<String>> responses = new ArrayList<Response<String>>();
for (String serverName : jedis.zrangeByScore(setKey, min, max))
{
String dataKey = concatenate(setKey, serverName);
responses.add(pipeline.get(dataKey));
}
pipeline.sync();
for (Response<String> response : responses)
{
String serializedData = response.get();
servers.add(Utility.deserialize(serializedData, MinecraftServer.class));
}
}
finally
{
_jedisPool.returnResource(jedis);
}
return servers;
}
/*
* <region> = "US" or "EU"
* serverstatus.minecraft.<region>.<name> stores the JSON encoded information of an active MinecraftServer instance.

View File

@ -51,13 +51,13 @@ public class ServerGroup
public boolean getArcadeGroup() { return _arcadeGroup; }
private String _worldZip;
public String getWorldZip() { return _serverType; }
public String getWorldZip() { return _worldZip; }
private String _plugin;
public String getPlugin() { return _serverType; }
public String getPlugin() { return _plugin; }
private String _configPath;
public String getConfigPath() { return _serverType; }
public String getConfigPath() { return _configPath; }
private int _minPlayers;
public int getMinPlayers() { return _minPlayers; }
@ -208,7 +208,7 @@ public class ServerGroup
for (MinecraftServer server : repository.getServerStatuses())
{
if (_name.equals(server.getGroup()))
if (_name.equalsIgnoreCase(server.getGroup()))
{
servers.add(server);
}
@ -218,9 +218,9 @@ public class ServerGroup
/**
* @return a unique server name suffix id, unique to any servers in this ServerGroup.
*/
public int generateUniqueId()
public int generateUniqueId(int startId)
{
int id = 0;
int id = startId;
while (true)
{

View File

@ -1,6 +1,7 @@
package mineplex.serverdata;
import java.util.Collection;
import java.util.Set;
/**
* The ServerRepository is used for storing/retrieving active sessions
@ -60,12 +61,6 @@ public interface ServerRepository
* currently active {@link ServerGroup}s in the repository.
*/
public Collection<ServerGroup> getServerGroups();
/**
* Clean the repository by removing all expired server statuses that have
* passed their timeout period.
* @return the number of expired server statuses removed/cleared.
*/
public int clean();
Collection<MinecraftServer> getDeadServers();
}

View File

@ -73,8 +73,12 @@ public class ServerMonitor
while (true)
{
Collection<ServerGroup> serverGroups = _repository.getServerGroups();
_repository.clean(); // Clean out old expired server entries
for (MinecraftServer deadServer : _repository.getDeadServers())
{
killServer(deadServer.getName(), deadServer.getPublicAddress(), true);
}
List<DedicatedServer> dedicatedServers = new ArrayList<DedicatedServer>(_repository.getDedicatedServers());
if (_count % 15 == 0)
@ -82,7 +86,7 @@ public class ServerMonitor
_badServers.clear();
for (DedicatedServer serverData : dedicatedServers)
{
{
if (isServerOffline(serverData))
{
System.out.println("------=[OFFLINE]=------=[" + serverData.getName() + ":" + serverData.getPublicAddress() + "]=------=[OFFLINE]=------");
@ -123,7 +127,7 @@ public class ServerMonitor
if (System.currentTimeMillis() - entry.getValue().getValue() > 15000)
{
System.out.println("-=[SERVER STARTUP TOO SLOW]=- " + entry.getKey());
System.out.println("-=[SERVER STARTUP TOO SLOW]=- " + entry.getKey() + " timeDiff : " + (System.currentTimeMillis() - entry.getValue().getValue()));
String serverName = entry.getKey();
String serverAddress = entry.getValue().getKey();
@ -203,7 +207,7 @@ public class ServerMonitor
private static void handleGroupChanges(List<DedicatedServer> dedicatedServers, HashMap<String, Entry<String, Long>> serverTracker, ServerGroup serverGroup, boolean free)
{
int serverNum = serverGroup.generateUniqueId();
int serverNum = 0;
//GroupStatusData groupStatus = groupStatusList.get(serverGroup.Name);
int requiredTotal = serverGroup.getRequiredTotalServers();
int requiredJoinable = serverGroup.getRequiredJoinableServers();
@ -221,6 +225,7 @@ public class ServerMonitor
while (serversToAdd > 0)
{
serverNum = serverGroup.generateUniqueId(serverNum + 1);
Collections.sort(dedicatedServers, new DedicatedServerSorter());
DedicatedServer bestServer = getBestDedicatedServer(dedicatedServers, serverGroup);
@ -244,7 +249,7 @@ public class ServerMonitor
while (serversToKill > 0)
{
List<MinecraftServer> emptyServers = new ArrayList<MinecraftServer>(serverGroup.getEmptyServers());
MinecraftServer emptyServer = emptyServers.get(0);
MinecraftServer emptyServer = emptyServers.get(serversToKill - 1);
System.out.println("[" + emptyServer.getName() + ":" + emptyServer.getPublicAddress() + "] Killing " + serverGroup.getName() + " Req Total: " + serverGroup.getRequiredTotalServers() + " Req Joinable: " + serverGroup.getRequiredJoinableServers() + " | Actual Total: " + serverGroup.getServerCount() + " Actual Joinable: " + serverGroup.getJoinableCount());
killServer(emptyServer);
serversToKill--;
@ -357,12 +362,12 @@ public class ServerMonitor
private static void startServer(final DedicatedServer serverSpace, final ServerGroup serverGroup, final int serverNum, final boolean free)
{
String cmd = "/home/mineplex/easyRemoteStartServer.sh";
String cmd = "/home/mineplex/easyRemoteStartServerCustom.sh";
final String groupPrefix = serverGroup.getPrefix();
final String serverName = serverSpace.getName();
final String serverAddress = serverSpace.getPublicAddress();
ProcessRunner pr = new ProcessRunner(new String[] {"/bin/sh", cmd, serverAddress, serverSpace.getPrivateAddress(), serverGroup.getPortSection() + serverNum + "", serverGroup.getRequiredRam() + "", serverGroup.getWorldZip(), serverGroup.getPlugin(), serverGroup.getConfigPath(), serverGroup.getName(), serverGroup.getPrefix() + "-" + serverNum, serverGroup.getMinPlayers() + "", serverGroup.getMaxPlayers() + "", serverGroup.getPvp() + "", serverGroup.getTournament() + "", free + "", serverSpace.isUsRegion() ? "true" : "false", serverGroup.getArcadeGroup() + "", serverGroup.getGames(), serverGroup.getServerType(), serverGroup.getAddNoCheat() + ""});
ProcessRunner pr = new ProcessRunner(new String[] {"/bin/sh", cmd, serverAddress, serverSpace.getPrivateAddress(), (serverGroup.getPortSection() + serverNum) + "", serverGroup.getRequiredRam() + "", serverGroup.getWorldZip(), serverGroup.getPlugin(), serverGroup.getConfigPath(), serverGroup.getName(), serverGroup.getPrefix() + "-" + serverNum, serverGroup.getMinPlayers() + "", serverGroup.getMaxPlayers() + "", serverGroup.getPvp() + "", serverGroup.getTournament() + "", free + "", serverSpace.isUsRegion() ? "true" : "false", serverGroup.getArcadeGroup() + "", serverGroup.getGames(), serverGroup.getServerType(), serverGroup.getAddNoCheat() + ""});
pr.start(new GenericRunnable<Boolean>()
{
public void run(Boolean error)