Reverted Free/Premium split in Server Monitor.
This commit is contained in:
parent
cb1a466a5b
commit
7408afa697
@ -10,23 +10,16 @@ public class GroupStatusData
|
||||
private int _totalCount = 0;
|
||||
private int _joinableCount = 0;
|
||||
|
||||
private int _freeServerNum = 0;
|
||||
private int _freeTotalCount = 0;
|
||||
private int _freeJoinableCount = 0;
|
||||
|
||||
public int Players;
|
||||
public int MaxPlayers;
|
||||
|
||||
public List<ServerStatusData> EmptyServers = new ArrayList<ServerStatusData>();
|
||||
public List<ServerStatusData> KillServers = new ArrayList<ServerStatusData>();
|
||||
public HashMap<Integer, ServerStatusData> Servers = new HashMap<Integer, ServerStatusData>();
|
||||
public HashMap<Integer, ServerStatusData> FreeServers = new HashMap<Integer, ServerStatusData>();
|
||||
|
||||
public void addServer(ServerStatusData serverStatusData)
|
||||
{
|
||||
boolean free = serverStatusData.Name.contains("FREE");
|
||||
|
||||
checkForDuplicate(free ? FreeServers : Servers, serverStatusData, free);
|
||||
checkForDuplicate(Servers, serverStatusData);
|
||||
|
||||
Players += serverStatusData.Players;
|
||||
MaxPlayers += serverStatusData.MaxPlayers;
|
||||
@ -40,43 +33,27 @@ public class GroupStatusData
|
||||
{
|
||||
if (serverStatusData.MaxPlayers - serverStatusData.Players > 20)
|
||||
{
|
||||
if (free)
|
||||
_freeJoinableCount++;
|
||||
else
|
||||
_joinableCount++;
|
||||
_joinableCount++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (free)
|
||||
_freeJoinableCount++;
|
||||
else
|
||||
_joinableCount++;
|
||||
_joinableCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (free)
|
||||
_freeTotalCount++;
|
||||
else
|
||||
_totalCount++;
|
||||
_totalCount++;
|
||||
|
||||
if (serverStatusData.Empty)
|
||||
{
|
||||
EmptyServers.add(serverStatusData);
|
||||
}
|
||||
|
||||
if (free)
|
||||
{
|
||||
FreeServers.put(Integer.parseInt(serverStatusData.Name.split("-")[1]), serverStatusData);
|
||||
}
|
||||
else
|
||||
{
|
||||
Servers.put(Integer.parseInt(serverStatusData.Name.split("-")[1]), serverStatusData);
|
||||
}
|
||||
Servers.put(Integer.parseInt(serverStatusData.Name.split("-")[1]), serverStatusData);
|
||||
}
|
||||
|
||||
private boolean checkForDuplicate(HashMap<Integer, ServerStatusData> serverMap, ServerStatusData serverStatusData, boolean free)
|
||||
private boolean checkForDuplicate(HashMap<Integer, ServerStatusData> serverMap, ServerStatusData serverStatusData)
|
||||
{
|
||||
if (serverMap.containsKey(Integer.parseInt(serverStatusData.Name.split("-")[1])))
|
||||
{
|
||||
@ -104,18 +81,12 @@ public class GroupStatusData
|
||||
{
|
||||
if (serverStatusData.MaxPlayers - serverStatusData.Players > 20)
|
||||
{
|
||||
if (free)
|
||||
_freeJoinableCount--;
|
||||
else
|
||||
_joinableCount--;
|
||||
_joinableCount--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (free)
|
||||
_freeJoinableCount--;
|
||||
else
|
||||
_joinableCount--;
|
||||
_joinableCount--;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -125,45 +96,28 @@ public class GroupStatusData
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getTotalServers(boolean free)
|
||||
public int getTotalServers()
|
||||
{
|
||||
return free ? _freeTotalCount : _totalCount;
|
||||
return _totalCount;
|
||||
}
|
||||
|
||||
public int getJoinableCount(boolean free)
|
||||
public int getJoinableCount()
|
||||
{
|
||||
return free ? _freeJoinableCount : _joinableCount;
|
||||
return _joinableCount;
|
||||
}
|
||||
|
||||
public int getNextServerNumber(boolean free)
|
||||
public int getNextServerNumber()
|
||||
{
|
||||
if (free)
|
||||
_freeServerNum++;
|
||||
else
|
||||
_serverNum++;
|
||||
_serverNum++;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (free)
|
||||
{
|
||||
if (!FreeServers.containsKey(_freeServerNum))
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Servers.containsKey(_serverNum))
|
||||
break;
|
||||
}
|
||||
if (!Servers.containsKey(_serverNum))
|
||||
break;
|
||||
|
||||
if (free)
|
||||
_freeServerNum++;
|
||||
else
|
||||
_serverNum++;
|
||||
_serverNum++;
|
||||
}
|
||||
|
||||
if (free)
|
||||
return _freeServerNum;
|
||||
else
|
||||
return _serverNum;
|
||||
return _serverNum;
|
||||
}
|
||||
}
|
||||
|
@ -111,12 +111,6 @@ public class ServerMonitor
|
||||
if (serverTracker.containsKey(serverToKill.Name))
|
||||
serverTracker.remove(serverToKill.Name);
|
||||
}
|
||||
|
||||
for (ServerStatusData serverToKill : groupStatus.FreeServers.values())
|
||||
{
|
||||
if (serverTracker.containsKey(serverToKill.Name))
|
||||
serverTracker.remove(serverToKill.Name);
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<Entry<String, Entry<String, Long>>> iterator = serverTracker.entrySet().iterator(); iterator.hasNext();)
|
||||
@ -147,12 +141,7 @@ public class ServerMonitor
|
||||
|
||||
GroupStatusData groupStatus = groupStatusList.get(serverGroup.Name);
|
||||
|
||||
handleGroupChanges(dynamicServers, serverTracker, serverGroup, groupStatus, false);
|
||||
|
||||
if (serverGroup.GenerateFreeVersions && _count % 6 == 0)
|
||||
{
|
||||
handleGroupChanges(dynamicServers, serverTracker, serverGroup, groupStatus, true);
|
||||
}
|
||||
handleGroupChanges(dynamicServers, serverTracker, serverGroup, groupStatus);
|
||||
}
|
||||
|
||||
int processWaits = 0;
|
||||
@ -219,13 +208,10 @@ public class ServerMonitor
|
||||
}
|
||||
}
|
||||
|
||||
private static void handleGroupChanges(List<DynamicServerData> dynamicServers, HashMap<String, Entry<String, Long>> serverTracker, ServerGroupData serverGroup, GroupStatusData groupStatus, boolean free)
|
||||
private static void handleGroupChanges(List<DynamicServerData> dynamicServers, HashMap<String, Entry<String, Long>> serverTracker, ServerGroupData serverGroup, GroupStatusData groupStatus)
|
||||
{
|
||||
int serversToAdd = Math.max(serverGroup.RequiredTotalServers - groupStatus.getTotalServers(free), serverGroup.RequiredJoinableServers - groupStatus.getJoinableCount(free));
|
||||
int serversToKill = (groupStatus.getTotalServers(free) > serverGroup.RequiredTotalServers && groupStatus.getJoinableCount(free) > serverGroup.RequiredJoinableServers) ? Math.min(groupStatus.getJoinableCount(free) - serverGroup.RequiredJoinableServers, groupStatus.EmptyServers.size()) : 0;
|
||||
|
||||
if (free)
|
||||
serversToAdd = Math.min(1, serversToAdd);
|
||||
int serversToAdd = Math.max(serverGroup.RequiredTotalServers - groupStatus.getTotalServers(), serverGroup.RequiredJoinableServers - groupStatus.getJoinableCount());
|
||||
int serversToKill = (groupStatus.getTotalServers() > serverGroup.RequiredTotalServers && groupStatus.getJoinableCount() > serverGroup.RequiredJoinableServers) ? Math.min(groupStatus.getJoinableCount() - serverGroup.RequiredJoinableServers, groupStatus.EmptyServers.size()) : 0;
|
||||
|
||||
// Minimum 1500 slot bufferzone
|
||||
if (serverGroup.Name.equalsIgnoreCase("Lobby"))
|
||||
@ -236,7 +222,7 @@ public class ServerMonitor
|
||||
|
||||
while (serversToAdd > 0)
|
||||
{
|
||||
int serverNum = groupStatus.getNextServerNumber(free);
|
||||
int serverNum = groupStatus.getNextServerNumber();
|
||||
Collections.sort(dynamicServers, new DynamicServerSorter());
|
||||
DynamicServerData bestServer = getBestDynamicServer(dynamicServers, serverGroup);
|
||||
|
||||
@ -246,12 +232,12 @@ public class ServerMonitor
|
||||
break;
|
||||
}
|
||||
|
||||
if (serverTracker.containsKey(serverGroup.Prefix + "-" + serverNum + (free ? "-FREE" : "")))
|
||||
if (serverTracker.containsKey(serverGroup.Prefix + "-" + serverNum))
|
||||
System.out.println("[WAITING] On " + serverGroup.Prefix + "-" + serverNum + " to finish starting...");
|
||||
else
|
||||
{
|
||||
startServer(bestServer, serverGroup, serverNum, free);
|
||||
serverTracker.put(serverGroup.Prefix + "-" + serverNum + (free ? "-FREE" : ""), new AbstractMap.SimpleEntry<String, Long>(bestServer.Address, System.currentTimeMillis()));
|
||||
startServer(bestServer, serverGroup, serverNum);
|
||||
serverTracker.put(serverGroup.Prefix + "-" + serverNum, new AbstractMap.SimpleEntry<String, Long>(bestServer.Address, System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
serversToAdd--;
|
||||
@ -259,7 +245,7 @@ public class ServerMonitor
|
||||
|
||||
while (serversToKill > 0)
|
||||
{
|
||||
System.out.println("[" + groupStatus.EmptyServers.get(0).Name + ":" + groupStatus.EmptyServers.get(0).Address + "] Killing " + serverGroup.Name + " " + (free ? "FREE" : "PREMIUM") + " Req Total: " + serverGroup.RequiredTotalServers + " Req Joinable: " + serverGroup.RequiredJoinableServers + " | Actual Total: " + groupStatus.getTotalServers(free) + " Actual Joinable: " + groupStatus.getJoinableCount(free));
|
||||
System.out.println("[" + groupStatus.EmptyServers.get(0).Name + ":" + groupStatus.EmptyServers.get(0).Address + "] Killing " + serverGroup.Name + " Req Total: " + serverGroup.RequiredTotalServers + " Req Joinable: " + serverGroup.RequiredJoinableServers + " | Actual Total: " + groupStatus.getTotalServers() + " Actual Joinable: " + groupStatus.getJoinableCount());
|
||||
log("Excess server " + groupStatus.EmptyServers.get(0).Name + ":" + groupStatus.EmptyServers.get(0).Address + " is being killed.");
|
||||
killServer(groupStatus.EmptyServers.remove(0));
|
||||
serversToKill--;
|
||||
@ -364,53 +350,24 @@ public class ServerMonitor
|
||||
return bestServer;
|
||||
}
|
||||
|
||||
private static void restartServer(final ServerStatusData serverToKill)
|
||||
{
|
||||
String cmd = "/home/mineplex/restartServer.sh";
|
||||
|
||||
ProcessRunner pr = new ProcessRunner(new String[] {"/bin/sh", cmd, serverToKill.Address, serverToKill.Name});
|
||||
pr.start(new GenericRunnable<Boolean>()
|
||||
{
|
||||
public void run(Boolean error)
|
||||
{
|
||||
if (error)
|
||||
System.out.println("Restart command to " + serverToKill.Address + " for " + serverToKill.Name + " failed");
|
||||
else
|
||||
System.out.println("Restart command to " + serverToKill.Address + " for " + serverToKill.Name + " completed");
|
||||
}
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
pr.join(500);
|
||||
}
|
||||
catch (InterruptedException e1)
|
||||
{
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
if (!pr.isDone())
|
||||
_processes.add(pr);
|
||||
}
|
||||
|
||||
private static void killServer(final ServerStatusData serverToKill)
|
||||
{
|
||||
killServer(serverToKill, true);
|
||||
}
|
||||
|
||||
private static void startServer(final DynamicServerData serverSpace, final ServerGroupData serverGroup, final int serverNum, final boolean free)
|
||||
private static void startServer(final DynamicServerData serverSpace, final ServerGroupData serverGroup, final int serverNum)
|
||||
{
|
||||
String cmd = "/home/mineplex/easyRemoteStartServerCustom.sh";
|
||||
|
||||
ProcessRunner pr = new ProcessRunner(new String[] {"/bin/sh", cmd, serverSpace.Address, serverSpace.PrivateAddress, serverGroup.PortSection + serverNum + "", serverGroup.RequiredRAM + "", serverGroup.WorldZip, serverGroup.Plugin, serverGroup.ConfigPath, serverGroup.Name, serverGroup.Prefix + "-" + serverNum, serverGroup.MinPlayers + "", serverGroup.MaxPlayers + "", serverGroup.Pvp + "", serverGroup.Tournament + "", free + "", serverSpace.US ? "true" : "false", serverGroup.ArcadeGroup + "", serverGroup.Games, serverGroup.ServerType, serverGroup.AddNoCheat + ""});
|
||||
ProcessRunner pr = new ProcessRunner(new String[] {"/bin/sh", cmd, serverSpace.Address, serverSpace.PrivateAddress, serverGroup.PortSection + serverNum + "", serverGroup.RequiredRAM + "", serverGroup.WorldZip, serverGroup.Plugin, serverGroup.ConfigPath, serverGroup.Name, serverGroup.Prefix + "-" + serverNum, serverGroup.MinPlayers + "", serverGroup.MaxPlayers + "", serverGroup.Pvp + "", serverGroup.Tournament + "", "false", serverSpace.US ? "true" : "false", serverGroup.ArcadeGroup + "", serverGroup.Games, serverGroup.ServerType, serverGroup.AddNoCheat + ""});
|
||||
pr.start(new GenericRunnable<Boolean>()
|
||||
{
|
||||
public void run(Boolean error)
|
||||
{
|
||||
if (error)
|
||||
System.out.println("[" + serverSpace.Name + ":" + serverSpace.Address + "] Errored " + serverGroup.Name + "(" + serverGroup.Prefix + "-" + serverNum + (free ? "-FREE" : "") + ")");
|
||||
System.out.println("[" + serverSpace.Name + ":" + serverSpace.Address + "] Errored " + serverGroup.Name + "(" + serverGroup.Prefix + "-" + serverNum + ")");
|
||||
else
|
||||
System.out.println("[" + serverSpace.Name + ":" + serverSpace.Address + "] Added " + serverGroup.Name + "(" + serverGroup.Prefix + "-" + serverNum + (free ? "-FREE" : "") + ")");
|
||||
System.out.println("[" + serverSpace.Name + ":" + serverSpace.Address + "] Added " + serverGroup.Name + "(" + serverGroup.Prefix + "-" + serverNum + ")");
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user