Dynamic server tinkering again.
This commit is contained in:
parent
cae10fe7b4
commit
ef0d233512
@ -7,7 +7,7 @@ public class DynamicServerData
|
||||
public String Name;
|
||||
public String Address;
|
||||
public int AvailableCPU = 32;
|
||||
public int AvailableRAM = 26624;
|
||||
public int AvailableRAM = 14000;
|
||||
|
||||
public HashMap<String, Integer> ServerGroupCount = new HashMap<String, Integer>();
|
||||
public boolean US;
|
||||
|
@ -20,7 +20,7 @@ public class Repository
|
||||
private static String RETRIEVE_OLD_SERVER_STATUSES = "SELECT ServerStatus.serverName, ServerStatus.address, motd, players, maxPlayers FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address LIKE CONCAT(DynamicServers.address, '%') WHERE DynamicServers.US = false AND TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) > 10;";
|
||||
|
||||
private static String CREATE_DYNAMIC_TABLE = "CREATE TABLE IF NOT EXISTS DynamicServers (id INT NOT NULL AUTO_INCREMENT, serverName VARCHAR(256), address VARCHAR(256), US BOOLEAN NOT NULL DEFAULT 'true', PRIMARY KEY (id));";
|
||||
private static String RETRIEVE_AVAILABLE_SERVERS = "SELECT DynamicServers.serverName, DynamicServers.address, DynamicServers.US, ServerStatus.serverGroup, COUNT(*) As serverCount FROM DynamicServers LEFT JOIN ServerStatus ON ServerStatus.address LIKE CONCAT(DynamicServers.address, '%') WHERE DynamicServers.US = false GROUP BY DynamicServers.address, ServerStatus.serverGroup;";
|
||||
private static String RETRIEVE_AVAILABLE_SERVERS = "SELECT DynamicServers.serverName, DynamicServers.address, DynamicServers.US, DynamicServers.availableCpu, DynamicServers.availableRam, ServerStatus.serverGroup, COUNT(*) As serverCount FROM DynamicServers LEFT JOIN ServerStatus ON ServerStatus.address LIKE CONCAT(DynamicServers.address, '%') WHERE DynamicServers.US = false GROUP BY DynamicServers.address, ServerStatus.serverGroup;";
|
||||
private static String RETRIEVE_SERVERGROUP_STATUSES = "SELECT ServerStatus.serverName, serverGroup, motd, ServerStatus.address, players, maxPlayers, case when TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.lastTimeWithPlayers)) > 300 then 1 else 0 end as empty FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address LIKE CONCAT(DynamicServers.address, '%') WHERE DynamicServers.US = false AND TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) <= 10";
|
||||
private static String RETRIEVE_SERVER_GROUP_DATA = "SELECT groupName, prefix, scriptName, requiredRam, cpuRequired, requiredTotal, requiredJoinable FROM ServerGroups;";
|
||||
private static String DELETE_SERVER_STATUS = "DELETE FROM ServerStatus WHERE address = ? AND serverName = ?;";
|
||||
@ -318,13 +318,15 @@ public class Repository
|
||||
dynamicServer.Name = resultSet.getString(1);
|
||||
dynamicServer.Address = resultSet.getString(2);
|
||||
dynamicServer.US = resultSet.getBoolean(3);
|
||||
dynamicServer.AvailableCPU = resultSet.getInt(4);
|
||||
dynamicServer.AvailableRAM = resultSet.getInt(5);
|
||||
|
||||
if (!serverMap.containsKey(dynamicServer.Name))
|
||||
serverMap.put(dynamicServer.Name, dynamicServer);
|
||||
|
||||
String serverGroupName = resultSet.getString(4);
|
||||
String serverGroupName = resultSet.getString(6);
|
||||
if (serverGroupMap.containsKey(serverGroupName))
|
||||
serverMap.get(dynamicServer.Name).setServerGroupCount(serverGroupMap.get(serverGroupName), resultSet.getInt(5));
|
||||
serverMap.get(dynamicServer.Name).setServerGroupCount(serverGroupMap.get(serverGroupName), resultSet.getInt(7));
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
|
@ -92,6 +92,8 @@ public class ServerMonitor
|
||||
|
||||
for (DynamicServerData serverData : dynamicServers)
|
||||
{
|
||||
System.out.println("Checking " + serverData.Name + " Cpu:" + serverData.AvailableCPU + " Ram:" + serverData.AvailableRAM);
|
||||
|
||||
if (serverData.AvailableRAM > serverGroup.RequiredRAM && serverData.AvailableCPU > serverGroup.RequiredCPU)
|
||||
{
|
||||
if (bestServer == null)
|
||||
@ -119,7 +121,7 @@ public class ServerMonitor
|
||||
|
||||
try
|
||||
{
|
||||
process = new ProcessBuilder(new String[] {"/bin/sh", "-x", cmd, serverToKill.Address, serverToKill.Name}).start();
|
||||
process = new ProcessBuilder(new String[] {"/bin/sh", cmd, serverToKill.Address, serverToKill.Name}).start();
|
||||
process.waitFor();
|
||||
BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
String line = reader.readLine();
|
||||
@ -177,6 +179,6 @@ public class ServerMonitor
|
||||
}
|
||||
|
||||
serverSpace.setServerGroupCount(serverGroup, serverSpace.ServerGroupCount.containsKey(serverGroup.Name) ? (serverSpace.ServerGroupCount.get(serverGroup.Name) + 1) : 1);
|
||||
System.out.println("Sent start command to " + serverSpace.Name + " for " + serverGroup.Prefix + "-" + serverNum);
|
||||
System.out.println("Sent start command (" + serverSpace.Address + "," + serverGroup.ScriptName + "," + serverGroup.Prefix + "-" + serverNum + ", 1," + (serverSpace.US ? "us" : "eu") + ")");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user