GUACAMOLE-102: Continue to work on the load balancing code.

This commit is contained in:
Nick Couchman
2017-03-20 10:50:33 -04:00
committed by Nick Couchman
parent 15869fef0d
commit d1259ef8df
2 changed files with 8 additions and 4 deletions

View File

@@ -175,8 +175,8 @@ public class ConnectionModel extends ChildObjectModel {
* Sets the connection weight. * Sets the connection weight.
* *
* @param connectionWeight * @param connectionWeight
* The weight of the connection. null is acceptable, -1 indicates the * The weight of the connection. null is acceptable, negative values
* connection should not be used. * indicate that the connection should not be used.
*/ */
public void setConnectionWeight(Integer connectionWeight) { public void setConnectionWeight(Integer connectionWeight) {
this.connectionWeight = connectionWeight; this.connectionWeight = connectionWeight;

View File

@@ -190,7 +190,11 @@ public class RestrictedGuacamoleTunnelService
logger.debug("Calculating weights for connections {} and {}.", a.getName(), b.getName()); logger.debug("Calculating weights for connections {} and {}.", a.getName(), b.getName());
int cw = 0; int cw = 0;
int weightA = a.getConnectionWeight(); int weightA = a.getConnectionWeight();
if (weightA == null)
weightA = 0;
int weightB = b.getConnectionWeight(); int weightB = b.getConnectionWeight();
if (weightB == null)
weightB = 0;
int connsA = getActiveConnections(a).size(); int connsA = getActiveConnections(a).size();
int connsB = getActiveConnections(b).size(); int connsB = getActiveConnections(b).size();
logger.debug("Connection {} has computed weight of {}.", a.getName(), connsA * 10000 / weightA); logger.debug("Connection {} has computed weight of {}.", a.getName(), connsA * 10000 / weightA);
@@ -208,8 +212,8 @@ public class RestrictedGuacamoleTunnelService
// Return the first unreserved connection // Return the first unreserved connection
for (ModeledConnection connection : sortedConnections) { for (ModeledConnection connection : sortedConnections) {
// If connection weight is negative, this host is disabled and should not be used. // If connection weight is zero or negative, this host is disabled and should not be used.
if (connection.getConnectionWeight() < 0) if (connection.getConnectionWeight() < 1)
continue; continue;
// Attempt to aquire connection according to per-user limits // Attempt to aquire connection according to per-user limits