From 025f77d1c40547abafa3a5ed18f341804883493b Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Sun, 19 Mar 2017 11:57:28 -0400 Subject: [PATCH 01/27] GUACAMOLE-102: Initial addition of connection weight to JDBC authentication extension --- .../guacamole/auth/jdbc/JDBCEnvironment.java | 11 ++++++ .../auth/jdbc/connection/ConnectionModel.java | 30 ++++++++++++++++ .../jdbc/connection/ModeledConnection.java | 34 +++++++++++++++++++ .../RestrictedGuacamoleTunnelService.java | 17 +++++++++- .../schema/001-create-schema.sql | 5 ++- .../schema/upgrade/upgrade-pre-0.9.12.sql | 25 ++++++++++++++ .../auth/mysql/MySQLEnvironment.java | 13 +++++++ .../auth/mysql/MySQLGuacamoleProperties.java | 12 +++++++ .../postgresql/PostgreSQLEnvironment.java | 13 +++++++ .../PostgreSQLGuacamoleProperties.java | 9 +++++ .../auth/jdbc/connection/ConnectionMapper.xml | 19 +++++++---- 11 files changed, 180 insertions(+), 8 deletions(-) create mode 100644 extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/upgrade/upgrade-pre-0.9.12.sql diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCEnvironment.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCEnvironment.java index dfbf0e9b5..64f2449fe 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCEnvironment.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCEnvironment.java @@ -81,6 +81,17 @@ public abstract class JDBCEnvironment extends LocalEnvironment { * If an error occurs while retrieving the property. */ public abstract int getDefaultMaxConnections() throws GuacamoleException; + + /** + * Returns the connection weight for the purpose of WRR calculation + * + * @return + * The weight of the connection. + * + * @throws GuacamoleException + * If an error occurs while retrieving the property. + */ + public abstract int getConnectionWeight() throws GuacamoleException; /** * Returns the default maximum number of concurrent connections to allow to diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java index 44f4b3b69..91dd42c43 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java @@ -54,6 +54,13 @@ public class ConnectionModel extends ChildObjectModel { */ private Integer maxConnectionsPerUser; + /** + * The weight of the connection for the purposes of calculating + * WRR algorithm. null indicates nothing has been set, -1 indicates + * the system is unavailable. + */ + private Integer connectionWeight; + /** * The identifiers of all readable sharing profiles associated with this * connection. @@ -164,6 +171,29 @@ public class ConnectionModel extends ChildObjectModel { return maxConnectionsPerUser; } + /** + * Sets the connection weight. + * + * @param connectionWeight + * The weight of the connection. null is acceptable, -1 indicates the + * connection should not be used. + */ + public void setConnectionWeight(Integer connectionWeight) { + this.connectionWeight = connectionWeight; + } + + /** + * Returns the connection weight used in calculating the + * WRR algorithm. + * + * @return + * The connection weight. Null indicates no weight has been set, + * -1 indicates that the system is unavailable. + */ + public Integer getConnectionWeight() { + return connectionWeight; + } + /** * Sets the maximum number of connections that can be established to this * connection concurrently by any one user. diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java index bcd7b117e..93a7329ca 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java @@ -116,6 +116,11 @@ public class ModeledConnection extends ModeledChildDirectoryObject connections) throws GuacamoleException { + logger.trace("Attempting to acquire a connection..."); // Do not acquire connection unless within overall limits if (!tryIncrement(totalActiveConnections, environment.getAbsoluteMaxConnections())) throw new GuacamoleResourceConflictException("Cannot connect. Overall maximum connections reached."); // Get username String username = user.getIdentifier(); + logger.trace("Username is: {}", username); + logger.trace("Sorting {} connections.", connections.size()); // Sort connections in ascending order of usage ModeledConnection[] sortedConnections = connections.toArray(new ModeledConnection[connections.size()]); Arrays.sort(sortedConnections, new Comparator() { @Override public int compare(ModeledConnection a, ModeledConnection b) { - + + logger.trace("Comparing {} to {}.", a.getName(), b.getName()); return getActiveConnections(a).size() - getActiveConnections(b).size(); @@ -194,15 +205,18 @@ public class RestrictedGuacamoleTunnelService for (ModeledConnection connection : sortedConnections) { // Attempt to aquire connection according to per-user limits + logger.trace("Trying to grab a seat on this train: {}", connection.getName()); Seat seat = new Seat(username, connection.getIdentifier()); if (tryAdd(activeSeats, seat, connection.getMaxConnectionsPerUser())) { + logger.trace("Got a seat, trying to get the connection..."); // Attempt to aquire connection according to overall limits if (tryAdd(activeConnections, connection.getIdentifier(), connection.getMaxConnections())) return connection; + logger.trace("Uh-oh, failed to get the connection..."); // Acquire failed - retry with next connection activeSeats.remove(seat); @@ -213,6 +227,7 @@ public class RestrictedGuacamoleTunnelService } + logger.trace("Well, we failed to get a seat at all..."); // Acquire failed totalActiveConnections.decrementAndGet(); diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/001-create-schema.sql b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/001-create-schema.sql index 519d5ca7b..2f0aa7303 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/001-create-schema.sql +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/001-create-schema.sql @@ -34,7 +34,6 @@ CREATE TABLE `guacamole_connection_group` ( `max_connections_per_user` int(11), `enable_session_affinity` boolean NOT NULL DEFAULT 0, - PRIMARY KEY (`connection_group_id`), UNIQUE KEY `connection_group_name_parent` (`connection_group_name`, `parent_id`), @@ -65,6 +64,10 @@ CREATE TABLE `guacamole_connection` ( -- Concurrency limits `max_connections` int(11), `max_connections_per_user` int(11), + + -- Connection weight + `connection_weight` int(11), + PRIMARY KEY (`connection_id`), UNIQUE KEY `connection_name_parent` (`connection_name`, `parent_id`), diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/upgrade/upgrade-pre-0.9.12.sql b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/upgrade/upgrade-pre-0.9.12.sql new file mode 100644 index 000000000..48e2dd1ae --- /dev/null +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/upgrade/upgrade-pre-0.9.12.sql @@ -0,0 +1,25 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, +-- software distributed under the License is distributed on an +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +-- KIND, either express or implied. See the License for the +-- specific language governing permissions and limitations +-- under the License. +-- + +-- +-- Add per-user password set date +-- + +ALTER TABLE guacamole_connection + ADD COLUMN connection_weight int(11); diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLEnvironment.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLEnvironment.java index 19a8ef448..63d4ae316 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLEnvironment.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLEnvironment.java @@ -87,6 +87,11 @@ public class MySQLEnvironment extends JDBCEnvironment { */ private int DEFAULT_MAX_CONNECTIONS = 0; + /** + * The default value for the connection weight for a connection in + * a balancing group. + private int DEFAULT_CONNECTION_WEIGHT = 0; + /** * The default value for the default maximum number of connections to be * allowed to any one connection group. Note that, as long as the legacy @@ -194,6 +199,14 @@ public class MySQLEnvironment extends JDBCEnvironment { ); } + @Override + public int getDefaultConnectionWeight() throws GuacamoleException { + return getProperty( + MySQLGuacamoleProperties.MYSQL_DEFAULT_CONNECTION_WEIGHT, + DEFAULT_CONNECTION_WEIGHT + ); + } + @Override public int getDefaultMaxGroupConnections() throws GuacamoleException { return getProperty( diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLGuacamoleProperties.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLGuacamoleProperties.java index 9039c029b..79f3e7fd5 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLGuacamoleProperties.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLGuacamoleProperties.java @@ -174,6 +174,18 @@ public class MySQLGuacamoleProperties { }; + /** + * The connection weight for connections in balancing groups. + */ + public static final IntegerGuacamoleProperty + MYSQL_DEFAULT_CONNECTION_WEIGHT = + new IntegerGuacamoleProperty() { + + @Overide + public String getName() { return "mysql-default-connection-weight"; } + + }; + /** * The maximum number of concurrent connections to allow to any one * connection group by an individual user. Zero denotes diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLEnvironment.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLEnvironment.java index e0ee75ff1..539941773 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLEnvironment.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLEnvironment.java @@ -87,6 +87,11 @@ public class PostgreSQLEnvironment extends JDBCEnvironment { */ private int DEFAULT_MAX_CONNECTIONS = 0; + /** + * The default value for the connection weight for a connection in + * a balancing group. + private int DEFAULT_CONNECTION_WEIGHT = 0; + /** * The default value for the default maximum number of connections to be * allowed to any one connection group. Note that, as long as the legacy @@ -194,6 +199,14 @@ public class PostgreSQLEnvironment extends JDBCEnvironment { ); } + @Override + public int getDefaultConnectionWeight() throws GuacamoleException { + return getProperty( + PostgreSQLGuacamoleProperties.POSTGRESQL_DEFAULT_CONNECTION_WEIGHT, + DEFAULT_CONNECTION_WEIGHT + ); + } + @Override public int getDefaultMaxGroupConnections() throws GuacamoleException { return getProperty( diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLGuacamoleProperties.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLGuacamoleProperties.java index 3da972fe7..3ae83ab21 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLGuacamoleProperties.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLGuacamoleProperties.java @@ -157,6 +157,15 @@ public class PostgreSQLGuacamoleProperties { }; + public static final IntegerGuacamoleProperty + POSTGRESQL_DEFAULT_CONNECTION_WEIGHT = + new IntegerGuacamoleProperty() { + + @Override + public String getName() { return "postgresql-default-connection-weight"; } + + }; + /** * The maximum number of concurrent connections to allow to any one * connection group. Zero denotes unlimited. diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml index 44828fa29..f53e43948 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml @@ -37,6 +37,7 @@ + parent_id = #{parentIdentifier,jdbcType=INTEGER}::integer @@ -189,7 +193,8 @@ max_connections_per_user, proxy_hostname, proxy_port, - proxy_encryption_method + proxy_encryption_method, + connection_weight ) VALUES ( #{object.name,jdbcType=VARCHAR}, @@ -199,7 +204,8 @@ #{object.maxConnectionsPerUser,jdbcType=INTEGER}, #{object.proxyHostname,jdbcType=VARCHAR}, #{object.proxyPort,jdbcType=INTEGER}, - #{object.proxyEncryptionMethod,jdbcType=VARCHAR}::guacamole_proxy_encryption_method + #{object.proxyEncryptionMethod,jdbcType=VARCHAR}::guacamole_proxy_encryption_method, + #{object.connectionWeight,jdbcType=INTEGER} ) @@ -214,7 +220,8 @@ max_connections_per_user = #{object.maxConnectionsPerUser,jdbcType=INTEGER}, proxy_hostname = #{object.proxyHostname,jdbcType=VARCHAR}, proxy_port = #{object.proxyPort,jdbcType=INTEGER}, - proxy_encryption_method = #{object.proxyEncryptionMethod,jdbcType=VARCHAR}::guacamole_proxy_encryption_method + proxy_encryption_method = #{object.proxyEncryptionMethod,jdbcType=VARCHAR}::guacamole_proxy_encryption_method, + connection_weight = #{object.connectionWeight,jdbcType=INTEGER} WHERE connection_id = #{object.objectID,jdbcType=INTEGER}::integer From 4aff2c1bb871545f5853f58760058e0d5b787d3f Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Sun, 19 Mar 2017 16:24:56 -0400 Subject: [PATCH 02/27] GUACAMOLE-102: Finish adding connection weight attribute. --- .../guacamole/auth/jdbc/JDBCEnvironment.java | 2 +- .../jdbc/connection/ModeledConnection.java | 5 ++-- .../src/main/resources/translations/en.json | 1 + .../auth/mysql/MySQLEnvironment.java | 1 + .../auth/mysql/MySQLGuacamoleProperties.java | 2 +- .../schema/001-create-schema.sql | 3 +++ .../schema/upgrade/upgrade-pre-0.9.12.sql | 25 +++++++++++++++++++ .../postgresql/PostgreSQLEnvironment.java | 1 + 8 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/upgrade/upgrade-pre-0.9.12.sql diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCEnvironment.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCEnvironment.java index 64f2449fe..a856d2ae0 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCEnvironment.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCEnvironment.java @@ -91,7 +91,7 @@ public abstract class JDBCEnvironment extends LocalEnvironment { * @throws GuacamoleException * If an error occurs while retrieving the property. */ - public abstract int getConnectionWeight() throws GuacamoleException; + public abstract int getDefaultConnectionWeight() throws GuacamoleException; /** * Returns the default maximum number of concurrent connections to allow to diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java index 93a7329ca..aa79ba435 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java @@ -119,7 +119,7 @@ public class ModeledConnection extends ModeledChildDirectoryObjectasList( new NumericField(MAX_CONNECTIONS_NAME), - new NumericField(MAX_CONNECTIONS_PER_USER_NAME) + new NumericField(MAX_CONNECTIONS_PER_USER_NAME), + new NumericField(CONNECTION_WEIGHT) )); /** diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/resources/translations/en.json b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/resources/translations/en.json index bf73c35d8..c154d8b8b 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/resources/translations/en.json +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/resources/translations/en.json @@ -19,6 +19,7 @@ "FIELD_HEADER_MAX_CONNECTIONS" : "Maximum number of connections:", "FIELD_HEADER_MAX_CONNECTIONS_PER_USER" : "Maximum number of connections per user:", + "FIELD_HEADER_WEIGHT" : "Connection Weight for Load Balancing:", "FIELD_HEADER_GUACD_HOSTNAME" : "Hostname:", "FIELD_HEADER_GUACD_ENCRYPTION" : "Encryption:", diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLEnvironment.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLEnvironment.java index 63d4ae316..6495fcc6f 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLEnvironment.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLEnvironment.java @@ -90,6 +90,7 @@ public class MySQLEnvironment extends JDBCEnvironment { /** * The default value for the connection weight for a connection in * a balancing group. + */ private int DEFAULT_CONNECTION_WEIGHT = 0; /** diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLGuacamoleProperties.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLGuacamoleProperties.java index 79f3e7fd5..3c88a59fb 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLGuacamoleProperties.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLGuacamoleProperties.java @@ -181,7 +181,7 @@ public class MySQLGuacamoleProperties { MYSQL_DEFAULT_CONNECTION_WEIGHT = new IntegerGuacamoleProperty() { - @Overide + @Override public String getName() { return "mysql-default-connection-weight"; } }; diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/001-create-schema.sql b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/001-create-schema.sql index e018617ba..7b9081ee6 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/001-create-schema.sql +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/001-create-schema.sql @@ -106,6 +106,9 @@ CREATE TABLE guacamole_connection ( max_connections integer, max_connections_per_user integer, + -- Connection Weight + connection_weight integer, + -- Guacamole proxy (guacd) overrides proxy_port integer, proxy_hostname varchar(512), diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/upgrade/upgrade-pre-0.9.12.sql b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/upgrade/upgrade-pre-0.9.12.sql new file mode 100644 index 000000000..1f085a49d --- /dev/null +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/upgrade/upgrade-pre-0.9.12.sql @@ -0,0 +1,25 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, +-- software distributed under the License is distributed on an +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +-- KIND, either express or implied. See the License for the +-- specific language governing permissions and limitations +-- under the License. +-- + +-- +-- Add per-user password set date +-- + +ALTER TABLE guacamole_connection + ADD COLUMN connection_weight int; diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLEnvironment.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLEnvironment.java index 539941773..e0ad4ec30 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLEnvironment.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLEnvironment.java @@ -90,6 +90,7 @@ public class PostgreSQLEnvironment extends JDBCEnvironment { /** * The default value for the connection weight for a connection in * a balancing group. + */ private int DEFAULT_CONNECTION_WEIGHT = 0; /** From d0647ad6a44d1a0785f29f40bd30412f8592e291 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Mon, 20 Mar 2017 06:49:10 -0400 Subject: [PATCH 03/27] GUACAMOLE-102: Initial stab at a WLC algorithm. --- .../RestrictedGuacamoleTunnelService.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java index 9c0191763..92cdfc6b1 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java @@ -191,9 +191,22 @@ public class RestrictedGuacamoleTunnelService public int compare(ModeledConnection a, ModeledConnection b) { logger.trace("Comparing {} to {}.", a.getName(), b.getName()); - return getActiveConnections(a).size() - - getActiveConnections(b).size(); + int cw = 0; + try { + if(a.getConnectionWeight() > 0 && b.getConnectionWeight() > 0) + cw = (int)(a.getConnectionWeight()/getActiveConnections(a).size() - b.getConnectionWeight()/getActiveConnections(b).size()); + else + cw = getActiveConnections(a).size() - getActiveConnections(b).size(); + + } + catch (GuacamoleException e) { + logger.error("Could not compare connections.", e.getMessage()); + logger.debug("Could not compare connections.", e); + } + + return cw; + } }); From 83a8e8223e9453f3928963f0cf1d901de182ac44 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Mon, 20 Mar 2017 09:06:04 -0400 Subject: [PATCH 04/27] GUACAMOLE-102: Tweak algorithm for computing the WLC vlaues. --- .../jdbc/connection/ModeledConnection.java | 13 +++---------- .../RestrictedGuacamoleTunnelService.java | 18 +++++------------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java index aa79ba435..1044a6202 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java @@ -416,19 +416,12 @@ public class ModeledConnection extends ModeledChildDirectoryObject 0 && b.getConnectionWeight() > 0) - cw = (int)(a.getConnectionWeight()/getActiveConnections(a).size() - b.getConnectionWeight()/getActiveConnections(b).size()); - else - cw = getActiveConnections(a).size() - getActiveConnections(b).size(); + return (connsA * 10000 / weightA) - (connsB * 10000 / weightB); - } - catch (GuacamoleException e) { - logger.error("Could not compare connections.", e.getMessage()); - logger.debug("Could not compare connections.", e); - } - - return cw; - } }); From 15869fef0d300c8a48e9ac91e6862a9d3c9fb837 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Mon, 20 Mar 2017 09:55:41 -0400 Subject: [PATCH 05/27] GUACAMOLE-102: Remove some extra debugging code, and continue to tweak the WLC algorithm. --- .../tunnel/RestrictedGuacamoleTunnelService.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java index ae7a059dd..8cc660545 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java @@ -173,16 +173,13 @@ public class RestrictedGuacamoleTunnelService protected ModeledConnection acquire(RemoteAuthenticatedUser user, List connections) throws GuacamoleException { - logger.trace("Attempting to acquire a connection..."); // Do not acquire connection unless within overall limits if (!tryIncrement(totalActiveConnections, environment.getAbsoluteMaxConnections())) throw new GuacamoleResourceConflictException("Cannot connect. Overall maximum connections reached."); // Get username String username = user.getIdentifier(); - logger.trace("Username is: {}", username); - logger.trace("Sorting {} connections.", connections.size()); // Sort connections in ascending order of usage ModeledConnection[] sortedConnections = connections.toArray(new ModeledConnection[connections.size()]); Arrays.sort(sortedConnections, new Comparator() { @@ -190,12 +187,14 @@ public class RestrictedGuacamoleTunnelService @Override public int compare(ModeledConnection a, ModeledConnection b) { - logger.trace("Comparing {} to {}.", a.getName(), b.getName()); + logger.debug("Calculating weights for connections {} and {}.", a.getName(), b.getName()); int cw = 0; int weightA = a.getConnectionWeight(); int weightB = b.getConnectionWeight(); int connsA = getActiveConnections(a).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 {}.", b.getName(), connsB * 10000 / weightB); return (connsA * 10000 / weightA) - (connsB * 10000 / weightB); @@ -209,19 +208,20 @@ public class RestrictedGuacamoleTunnelService // Return the first unreserved connection for (ModeledConnection connection : sortedConnections) { + // If connection weight is negative, this host is disabled and should not be used. + if (connection.getConnectionWeight() < 0) + continue; + // Attempt to aquire connection according to per-user limits - logger.trace("Trying to grab a seat on this train: {}", connection.getName()); Seat seat = new Seat(username, connection.getIdentifier()); if (tryAdd(activeSeats, seat, connection.getMaxConnectionsPerUser())) { - logger.trace("Got a seat, trying to get the connection..."); // Attempt to aquire connection according to overall limits if (tryAdd(activeConnections, connection.getIdentifier(), connection.getMaxConnections())) return connection; - logger.trace("Uh-oh, failed to get the connection..."); // Acquire failed - retry with next connection activeSeats.remove(seat); @@ -232,7 +232,6 @@ public class RestrictedGuacamoleTunnelService } - logger.trace("Well, we failed to get a seat at all..."); // Acquire failed totalActiveConnections.decrementAndGet(); From d1259ef8dfe9cb7c65b3f3ff152b12820bf80134 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Mon, 20 Mar 2017 10:50:33 -0400 Subject: [PATCH 06/27] GUACAMOLE-102: Continue to work on the load balancing code. --- .../guacamole/auth/jdbc/connection/ConnectionModel.java | 4 ++-- .../jdbc/tunnel/RestrictedGuacamoleTunnelService.java | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java index 91dd42c43..56cf4ac46 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java @@ -175,8 +175,8 @@ public class ConnectionModel extends ChildObjectModel { * Sets the connection weight. * * @param connectionWeight - * The weight of the connection. null is acceptable, -1 indicates the - * connection should not be used. + * The weight of the connection. null is acceptable, negative values + * indicate that the connection should not be used. */ public void setConnectionWeight(Integer connectionWeight) { this.connectionWeight = connectionWeight; diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java index 8cc660545..3db47c660 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java @@ -190,7 +190,11 @@ public class RestrictedGuacamoleTunnelService logger.debug("Calculating weights for connections {} and {}.", a.getName(), b.getName()); int cw = 0; int weightA = a.getConnectionWeight(); + if (weightA == null) + weightA = 0; int weightB = b.getConnectionWeight(); + if (weightB == null) + weightB = 0; int connsA = getActiveConnections(a).size(); int connsB = getActiveConnections(b).size(); logger.debug("Connection {} has computed weight of {}.", a.getName(), connsA * 10000 / weightA); @@ -208,8 +212,8 @@ public class RestrictedGuacamoleTunnelService // Return the first unreserved connection for (ModeledConnection connection : sortedConnections) { - // If connection weight is negative, this host is disabled and should not be used. - if (connection.getConnectionWeight() < 0) + // If connection weight is zero or negative, this host is disabled and should not be used. + if (connection.getConnectionWeight() < 1) continue; // Attempt to aquire connection according to per-user limits From 2363c63e6418d52d665ea79bec2f597145ee5021 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Mon, 20 Mar 2017 14:55:35 -0400 Subject: [PATCH 07/27] GUACAMOLE-102: Adding some commentary for changes in the RestrictedGuacamoleTunnelService class. --- .../auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java index 3db47c660..b41ec91bc 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java @@ -190,11 +190,15 @@ public class RestrictedGuacamoleTunnelService logger.debug("Calculating weights for connections {} and {}.", a.getName(), b.getName()); int cw = 0; int weightA = a.getConnectionWeight(); + // If the weight is null, we go ahead and sort, anyway if (weightA == null) weightA = 0; + + // If the weight is null, we go ahead and sort, anyway int weightB = b.getConnectionWeight(); if (weightB == null) weightB = 0; + int connsA = getActiveConnections(a).size(); int connsB = getActiveConnections(b).size(); logger.debug("Connection {} has computed weight of {}.", a.getName(), connsA * 10000 / weightA); From 075e880acc7aa115f0a4b27fed3f182f8108affa Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Wed, 31 May 2017 15:22:31 -0400 Subject: [PATCH 08/27] GUACAMOLE-102: Deal with weights of 0, and properly dispose of connections with negative weights. --- .../jdbc/connection/ModeledConnection.java | 3 +- .../RestrictedGuacamoleTunnelService.java | 41 ++++++++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java index 1044a6202..414a8a43f 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java @@ -409,6 +409,7 @@ public class ModeledConnection extends ModeledChildDirectoryObject i = connections.iterator(); + while(i.hasNext()) { + Integer weight = i.next().getConnectionWeight(); + if (weight != null && weight.intValue() < 0) + i.remove(); + } + // Sort connections in ascending order of usage ModeledConnection[] sortedConnections = connections.toArray(new ModeledConnection[connections.size()]); Arrays.sort(sortedConnections, new Comparator() { @@ -187,22 +191,21 @@ public class RestrictedGuacamoleTunnelService @Override public int compare(ModeledConnection a, ModeledConnection b) { - logger.debug("Calculating weights for connections {} and {}.", a.getName(), b.getName()); - int cw = 0; - int weightA = a.getConnectionWeight(); - // If the weight is null, we go ahead and sort, anyway - if (weightA == null) - weightA = 0; + int weightA, weightB; + // Check if weight of a is null, assign 1 if it is. + if (a.getConnectionWeight() == null) + weightA = 1; + else + weightA = a.getConnectionWeight().intValue() + 1; - // If the weight is null, we go ahead and sort, anyway - int weightB = b.getConnectionWeight(); - if (weightB == null) - weightB = 0; + // Check if weight of b is null, assign 1 if it is. + if (b.getConnectionWeight() == null) + weightB = 1; + else + weightB = b.getConnectionWeight().intValue() + 1; - int connsA = getActiveConnections(a).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 {}.", b.getName(), connsB * 10000 / weightB); + int connsA = getActiveConnections(a).size() + 1; + int connsB = getActiveConnections(b).size() + 1; return (connsA * 10000 / weightA) - (connsB * 10000 / weightB); From 56f6c4bb2ff93e3af4538d3f8011a89716f292e3 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Wed, 31 May 2017 20:18:25 -0400 Subject: [PATCH 09/27] GUACAMOLE-102: Remove redundant iterations through connections. --- .../RestrictedGuacamoleTunnelService.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java index 49af081d0..590648cb7 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java @@ -47,6 +47,11 @@ import org.slf4j.LoggerFactory; public class RestrictedGuacamoleTunnelService extends AbstractGuacamoleTunnelService { + /** + * Logger for this class. + */ + private static final Logger logger = LoggerFactory.getLogger(RestrictedGuacamoleTunnelService.class); + /** * The environment of the Guacamole server. */ @@ -176,14 +181,6 @@ public class RestrictedGuacamoleTunnelService // Get username String username = user.getIdentifier(); - // Remove connections where weight < 0 - Iterator i = connections.iterator(); - while(i.hasNext()) { - Integer weight = i.next().getConnectionWeight(); - if (weight != null && weight.intValue() < 0) - i.remove(); - } - // Sort connections in ascending order of usage ModeledConnection[] sortedConnections = connections.toArray(new ModeledConnection[connections.size()]); Arrays.sort(sortedConnections, new Comparator() { @@ -195,12 +192,22 @@ public class RestrictedGuacamoleTunnelService // Check if weight of a is null, assign 1 if it is. if (a.getConnectionWeight() == null) weightA = 1; + // If weight is less than 1, host will be disabled + // but for sorting we set it to 1 to avoid divide + // by 0. + else if (a.getConnectionWeight().intValue() < 1) + weightA = 1; else weightA = a.getConnectionWeight().intValue() + 1; // Check if weight of b is null, assign 1 if it is. if (b.getConnectionWeight() == null) weightB = 1; + // If weight is less than 1, host will be disabled, + // but for sorting we set it to 1 to avoid divide + // by 0. + else if (b.getConnectionWeight().intValue() < 1) + weightB = 1; else weightB = b.getConnectionWeight().intValue() + 1; @@ -220,8 +227,10 @@ public class RestrictedGuacamoleTunnelService for (ModeledConnection connection : sortedConnections) { // If connection weight is zero or negative, this host is disabled and should not be used. - if (connection.getConnectionWeight() < 1) + if (connection.getConnectionWeight() != null && connection.getConnectionWeight().intValue() < 1) { + logger.warn("Weight for {} is non-null and < 1, connection will be skipped.", connection.getName()); continue; + } // Attempt to aquire connection according to per-user limits Seat seat = new Seat(username, connection.getIdentifier()); From f22852721c12d38716aec8aad001f0986b31223c Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Wed, 31 May 2017 21:39:16 -0400 Subject: [PATCH 10/27] GUACAMOLE-102: Clean up and simplify WLC sorting code. --- .../RestrictedGuacamoleTunnelService.java | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java index 590648cb7..744d2e8e9 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java @@ -189,28 +189,21 @@ public class RestrictedGuacamoleTunnelService public int compare(ModeledConnection a, ModeledConnection b) { int weightA, weightB; - // Check if weight of a is null, assign 1 if it is. - if (a.getConnectionWeight() == null) - weightA = 1; - // If weight is less than 1, host will be disabled - // but for sorting we set it to 1 to avoid divide - // by 0. - else if (a.getConnectionWeight().intValue() < 1) - weightA = 1; + // Check if weight of a is non-null and retrieve it. + if (a.getConnectionWeight() != null && a.getConnectionWeight().intValue() > 0) + weightA = a.getConnectionWeight().intValue(); + // In all other cases assign 1 for sorting. else - weightA = a.getConnectionWeight().intValue() + 1; + weightA = 1; // Check if weight of b is null, assign 1 if it is. - if (b.getConnectionWeight() == null) - weightB = 1; - // If weight is less than 1, host will be disabled, - // but for sorting we set it to 1 to avoid divide - // by 0. - else if (b.getConnectionWeight().intValue() < 1) - weightB = 1; + if (b.getConnectionWeight() != null && b.getConnectionWeight().intValue() > 0) + weightB = b.getConnectionWeight().intValue(); + // In all other cases assign 1 for sorting. else - weightB = b.getConnectionWeight().intValue() + 1; + weightB = 1; + // Get current active connections, add 1 to both to avoid calculations with 0. int connsA = getActiveConnections(a).size() + 1; int connsB = getActiveConnections(b).size() + 1; From 4033e097c7dcc976af84d3b8684794be7f184786 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Fri, 2 Jun 2017 14:43:11 -0400 Subject: [PATCH 11/27] GUACAMOLE-102: Get rid of arbitary constant in compare method for WLC algorithm. --- .../auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java index 744d2e8e9..71d4f7f37 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java @@ -207,7 +207,7 @@ public class RestrictedGuacamoleTunnelService int connsA = getActiveConnections(a).size() + 1; int connsB = getActiveConnections(b).size() + 1; - return (connsA * 10000 / weightA) - (connsB * 10000 / weightB); + return (connsA * weightB) - (connsB * weightA); } From 58637818ca0c6e88bcd2fcd55f786bee509f5bdc Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Fri, 2 Jun 2017 14:47:15 -0400 Subject: [PATCH 12/27] GUACAMOLE-102: Move null check for connection weight to the connection model. --- .../guacamole/auth/jdbc/connection/ConnectionModel.java | 2 ++ .../auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java index 56cf4ac46..69ef4c311 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java @@ -191,6 +191,8 @@ public class ConnectionModel extends ChildObjectModel { * -1 indicates that the system is unavailable. */ public Integer getConnectionWeight() { + if (connectionWeight == null) + return 1; return connectionWeight; } diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java index 71d4f7f37..d1b491296 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java @@ -190,14 +190,14 @@ public class RestrictedGuacamoleTunnelService int weightA, weightB; // Check if weight of a is non-null and retrieve it. - if (a.getConnectionWeight() != null && a.getConnectionWeight().intValue() > 0) + if (a.getConnectionWeight().intValue() > 0) weightA = a.getConnectionWeight().intValue(); // In all other cases assign 1 for sorting. else weightA = 1; // Check if weight of b is null, assign 1 if it is. - if (b.getConnectionWeight() != null && b.getConnectionWeight().intValue() > 0) + if (b.getConnectionWeight().intValue() > 0) weightB = b.getConnectionWeight().intValue(); // In all other cases assign 1 for sorting. else From aa4c13492251a4dfd7e8449435f5eebd2eac7e40 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Fri, 2 Jun 2017 14:51:27 -0400 Subject: [PATCH 13/27] GUACAMOLE-102: Remove unnecessary checks for weight value in the compare function. --- .../RestrictedGuacamoleTunnelService.java | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java index d1b491296..56d2f5bac 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java @@ -187,21 +187,10 @@ public class RestrictedGuacamoleTunnelService @Override public int compare(ModeledConnection a, ModeledConnection b) { - - int weightA, weightB; - // Check if weight of a is non-null and retrieve it. - if (a.getConnectionWeight().intValue() > 0) - weightA = a.getConnectionWeight().intValue(); - // In all other cases assign 1 for sorting. - else - weightA = 1; - // Check if weight of b is null, assign 1 if it is. - if (b.getConnectionWeight().intValue() > 0) - weightB = b.getConnectionWeight().intValue(); - // In all other cases assign 1 for sorting. - else - weightB = 1; + // Get connection weight for the two systems being compared. + int weightA = a.getConnectionWeight().intValue(); + int weightB = b.getConnectionWeight().intValue(); // Get current active connections, add 1 to both to avoid calculations with 0. int connsA = getActiveConnections(a).size() + 1; From f77c50730d09e4d02eff887d82a01ab84fd3ff09 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Fri, 2 Jun 2017 20:05:15 -0400 Subject: [PATCH 14/27] GUACAMOLE-102: Make getConnectionWeight return int, clean up compare code. --- .../auth/jdbc/connection/ConnectionModel.java | 12 +++++++----- .../auth/jdbc/connection/ModeledConnection.java | 2 +- .../tunnel/RestrictedGuacamoleTunnelService.java | 16 ++++------------ 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java index 69ef4c311..2da37a763 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java @@ -184,16 +184,18 @@ public class ConnectionModel extends ChildObjectModel { /** * Returns the connection weight used in calculating the - * WRR algorithm. + * weighted algorithms. * * @return - * The connection weight. Null indicates no weight has been set, - * -1 indicates that the system is unavailable. + * The connection weight as an int. If the weight is + * null a default weight of 1 is returned. Zero and + * negative numbers are used to indicate the system is + * unavailable. */ - public Integer getConnectionWeight() { + public int getConnectionWeight() { if (connectionWeight == null) return 1; - return connectionWeight; + return connectionWeight.intValue(); } /** diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java index 414a8a43f..67bd7933c 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java @@ -418,7 +418,7 @@ public class ModeledConnection extends ModeledChildDirectoryObject Date: Mon, 5 Jun 2017 14:53:21 -0400 Subject: [PATCH 15/27] GUACAMOLE-102: Move null checking logic to ModeledConnection. --- .../guacamole/auth/jdbc/connection/ConnectionModel.java | 6 ++---- .../auth/jdbc/connection/ModeledConnection.java | 9 ++++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java index 2da37a763..f208b5ac8 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java @@ -192,10 +192,8 @@ public class ConnectionModel extends ChildObjectModel { * negative numbers are used to indicate the system is * unavailable. */ - public int getConnectionWeight() { - if (connectionWeight == null) - return 1; - return connectionWeight.intValue(); + public Integer getConnectionWeight() { + return connectionWeight; } /** diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java index 67bd7933c..7e11a762b 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java @@ -412,7 +412,8 @@ public class ModeledConnection extends ModeledChildDirectoryObject Date: Mon, 5 Jun 2017 15:13:19 -0400 Subject: [PATCH 16/27] GUACAMOLE-102: Clean up code style issues, remove the unnecessary getDefaultConnectionWeight method. --- .../apache/guacamole/auth/jdbc/JDBCEnvironment.java | 11 ----------- .../auth/jdbc/connection/ModeledConnection.java | 3 +-- .../jdbc/tunnel/RestrictedGuacamoleTunnelService.java | 4 ++-- .../apache/guacamole/auth/mysql/MySQLEnvironment.java | 8 -------- .../auth/postgresql/PostgreSQLEnvironment.java | 8 -------- 5 files changed, 3 insertions(+), 31 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCEnvironment.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCEnvironment.java index a856d2ae0..53935e62f 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCEnvironment.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/JDBCEnvironment.java @@ -82,17 +82,6 @@ public abstract class JDBCEnvironment extends LocalEnvironment { */ public abstract int getDefaultMaxConnections() throws GuacamoleException; - /** - * Returns the connection weight for the purpose of WRR calculation - * - * @return - * The weight of the connection. - * - * @throws GuacamoleException - * If an error occurs while retrieving the property. - */ - public abstract int getDefaultConnectionWeight() throws GuacamoleException; - /** * Returns the default maximum number of concurrent connections to allow to * any one connection group, unless specified differently on an individual diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java index 7e11a762b..29a8b6f7c 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java @@ -417,12 +417,11 @@ public class ModeledConnection extends ModeledChildDirectoryObject Date: Mon, 5 Jun 2017 15:20:24 -0400 Subject: [PATCH 17/27] GUACAMOLE-102: Clean up unused constants; minor comment corrections. --- .../guacamole/auth/jdbc/connection/ModeledConnection.java | 2 +- .../org/apache/guacamole/auth/mysql/MySQLEnvironment.java | 6 ------ .../guacamole/auth/postgresql/PostgreSQLEnvironment.java | 6 ------ 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java index 29a8b6f7c..ad525b84e 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java @@ -117,7 +117,7 @@ public class ModeledConnection extends ModeledChildDirectoryObject Date: Mon, 5 Jun 2017 15:37:13 -0400 Subject: [PATCH 18/27] GUACAMOLE-102: Correct versions for database schema upgrade scripts --- .../upgrade/{upgrade-pre-0.9.12.sql => upgrade-pre-0.9.14.sql} | 2 +- .../upgrade/{upgrade-pre-0.9.12.sql => upgrade-pre-0.9.14.sql} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/upgrade/{upgrade-pre-0.9.12.sql => upgrade-pre-0.9.14.sql} (96%) rename extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/upgrade/{upgrade-pre-0.9.12.sql => upgrade-pre-0.9.14.sql} (96%) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/upgrade/upgrade-pre-0.9.12.sql b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/upgrade/upgrade-pre-0.9.14.sql similarity index 96% rename from extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/upgrade/upgrade-pre-0.9.12.sql rename to extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/upgrade/upgrade-pre-0.9.14.sql index 48e2dd1ae..2b14e27f3 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/upgrade/upgrade-pre-0.9.12.sql +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/upgrade/upgrade-pre-0.9.14.sql @@ -18,7 +18,7 @@ -- -- --- Add per-user password set date +-- Add per-connection weight -- ALTER TABLE guacamole_connection diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/upgrade/upgrade-pre-0.9.12.sql b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/upgrade/upgrade-pre-0.9.14.sql similarity index 96% rename from extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/upgrade/upgrade-pre-0.9.12.sql rename to extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/upgrade/upgrade-pre-0.9.14.sql index 1f085a49d..6388b445f 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/upgrade/upgrade-pre-0.9.12.sql +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/upgrade/upgrade-pre-0.9.14.sql @@ -18,7 +18,7 @@ -- -- --- Add per-user password set date +-- Add per-connection weight -- ALTER TABLE guacamole_connection From 25493a8355862abb22c128ab7b611bae4f7d830f Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Mon, 5 Jun 2017 16:45:01 -0400 Subject: [PATCH 19/27] GUACAMOLE-102: Woops...add MySQL module ConnectionMapper.xml updates. --- .../auth/jdbc/connection/ConnectionMapper.xml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml index 46f8f1039..2f778fa5f 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/resources/org/apache/guacamole/auth/jdbc/connection/ConnectionMapper.xml @@ -37,6 +37,7 @@ + parent_id = #{parentIdentifier,jdbcType=VARCHAR} @@ -189,7 +193,8 @@ max_connections_per_user, proxy_hostname, proxy_port, - proxy_encryption_method + proxy_encryption_method, + connection_weight ) VALUES ( #{object.name,jdbcType=VARCHAR}, @@ -199,7 +204,8 @@ #{object.maxConnectionsPerUser,jdbcType=INTEGER}, #{object.proxyHostname,jdbcType=VARCHAR}, #{object.proxyPort,jdbcType=INTEGER}, - #{object.proxyEncryptionMethod,jdbcType=VARCHAR} + #{object.proxyEncryptionMethod,jdbcType=VARCHAR}, + #{object.connectionWeight,jdbcType=INTEGER} ) @@ -214,7 +220,8 @@ max_connections_per_user = #{object.maxConnectionsPerUser,jdbcType=INTEGER}, proxy_hostname = #{object.proxyHostname,jdbcType=VARCHAR}, proxy_port = #{object.proxyPort,jdbcType=INTEGER}, - proxy_encryption_method = #{object.proxyEncryptionMethod,jdbcType=VARCHAR} + proxy_encryption_method = #{object.proxyEncryptionMethod,jdbcType=VARCHAR}, + connection_weight = #{object.connectionWeight,jdbcType=INTEGER} WHERE connection_id = #{object.objectID,jdbcType=INTEGER} From 874b29bae309e198db991035604082eda1f78768 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Mon, 5 Jun 2017 21:34:50 -0400 Subject: [PATCH 20/27] GUACAMOLE-102: Correction to WLC algorithm to try to keep ratio no higher than configure weights. --- .../RestrictedGuacamoleTunnelService.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java index d4ab8aa79..6480ec752 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java @@ -187,8 +187,24 @@ public class RestrictedGuacamoleTunnelService @Override public int compare(ModeledConnection a, ModeledConnection b) { - return ((getActiveConnections(a).size() + 1) * b.getConnectionWeight() - - (getActiveConnections(b).size() + 1) * a.getConnectionWeight()); + // Active connections + int Ca = getActiveConnections(a).size(); + int Cb = getActiveConnections(b).size(); + + // Assigned weight + int Wa = a.getConnectionWeight(); + int Wb = b.getConnectionWeight(); + + // Net weight of connections + int NWa = Ca * Wb; + int NWb = Cb * Wa; + + // If net weights are equal, return difference in weight + if (NWa == NWb) + return (Wa - Wb); + + // Return different in net weights + return (NWa - NWb); } From 91f7a3e8e9e4e125f2002b1d2527d5d0f8e829a4 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Mon, 5 Jun 2017 22:29:28 -0400 Subject: [PATCH 21/27] GUACAMOLE-102: Corrections to comments in ConnectionModel class. --- .../guacamole/auth/jdbc/connection/ConnectionModel.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java index f208b5ac8..4d2810195 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java @@ -56,8 +56,8 @@ public class ConnectionModel extends ChildObjectModel { /** * The weight of the connection for the purposes of calculating - * WRR algorithm. null indicates nothing has been set, -1 indicates - * the system is unavailable. + * WLC algorithm. null indicates nothing has been set, and anything less + * than 1 eliminates the system from being used for connections. */ private Integer connectionWeight; @@ -187,10 +187,7 @@ public class ConnectionModel extends ChildObjectModel { * weighted algorithms. * * @return - * The connection weight as an int. If the weight is - * null a default weight of 1 is returned. Zero and - * negative numbers are used to indicate the system is - * unavailable. + * The connection weight as an Integer. */ public Integer getConnectionWeight() { return connectionWeight; From 955d5fb11f861f0476741a950cbb064150ae9bd4 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Mon, 5 Jun 2017 22:37:49 -0400 Subject: [PATCH 22/27] GUACAMOLE-102: Clarification for comments on weights less than 1. --- .../guacamole/auth/jdbc/connection/ConnectionModel.java | 4 ++-- .../auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java index 4d2810195..92ee91d91 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java @@ -175,8 +175,8 @@ public class ConnectionModel extends ChildObjectModel { * Sets the connection weight. * * @param connectionWeight - * The weight of the connection. null is acceptable, negative values - * indicate that the connection should not be used. + * The weight of the connection. null is acceptable, and anything + * less than one will prevent the connection from being used. */ public void setConnectionWeight(Integer connectionWeight) { this.connectionWeight = connectionWeight; diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java index 6480ec752..c9999abe4 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java @@ -216,7 +216,7 @@ public class RestrictedGuacamoleTunnelService // Return the first unreserved connection for (ModeledConnection connection : sortedConnections) { - // If connection weight is zero or negative, this host is disabled and should not be used. + // If connection weight is less than 1 this host is disabled and should not be used. if (connection.getConnectionWeight() < 1) { logger.debug("Weight for {} is < 1, connection will be skipped.", connection.getName()); continue; From 06e27d30ff2823468707309b24a230d9175714d4 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Tue, 6 Jun 2017 08:39:02 -0400 Subject: [PATCH 23/27] GUACAMOLE-102: Improve commentary around connection weight methods and variables. --- .../auth/jdbc/connection/ConnectionModel.java | 15 +++++++++------ .../auth/jdbc/connection/ModeledConnection.java | 10 ++++++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java index 92ee91d91..78cc885b4 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ConnectionModel.java @@ -172,22 +172,25 @@ public class ConnectionModel extends ChildObjectModel { } /** - * Sets the connection weight. + * Sets the connection weight for load balancing. * * @param connectionWeight - * The weight of the connection. null is acceptable, and anything - * less than one will prevent the connection from being used. + * The weight of the connection used in load balancing. + * The value is not required for the connection (null), and + * values less than 1 will prevent the connection from being + * used. */ public void setConnectionWeight(Integer connectionWeight) { this.connectionWeight = connectionWeight; } /** - * Returns the connection weight used in calculating the - * weighted algorithms. + * Returns the connection weight used in applying weighted + * load balancing algorithms. * * @return - * The connection weight as an Integer. + * The connection weight used in applying weighted + * load balancing aglorithms. */ public Integer getConnectionWeight() { return connectionWeight; diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java index ad525b84e..db8c815cf 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java @@ -117,7 +117,7 @@ public class ModeledConnection extends ModeledChildDirectoryObject Date: Tue, 6 Jun 2017 08:49:48 -0400 Subject: [PATCH 24/27] GUACAMOLE-102: Code cleanup - remove unused default parameters; improve commentary and use more standard variable names. --- .../RestrictedGuacamoleTunnelService.java | 24 +++++++++---------- .../auth/mysql/MySQLGuacamoleProperties.java | 12 ---------- .../PostgreSQLGuacamoleProperties.java | 9 ------- 3 files changed, 12 insertions(+), 33 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java index c9999abe4..fa2c99f23 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/tunnel/RestrictedGuacamoleTunnelService.java @@ -188,23 +188,23 @@ public class RestrictedGuacamoleTunnelService public int compare(ModeledConnection a, ModeledConnection b) { // Active connections - int Ca = getActiveConnections(a).size(); - int Cb = getActiveConnections(b).size(); + int connA = getActiveConnections(a).size(); + int connB = getActiveConnections(b).size(); // Assigned weight - int Wa = a.getConnectionWeight(); - int Wb = b.getConnectionWeight(); + int weightA = a.getConnectionWeight(); + int weightB = b.getConnectionWeight(); - // Net weight of connections - int NWa = Ca * Wb; - int NWb = Cb * Wa; + // Calculated weight of connections + int calcWeightA = connA * weightB; + int calcWeightB = connB * weightA; - // If net weights are equal, return difference in weight - if (NWa == NWb) - return (Wa - Wb); + // If calculated weights are equal, return difference in assigned weight + if (calcWeightA == calcWeightB) + return (weightA - weightB); - // Return different in net weights - return (NWa - NWb); + // Return different in calculated weights + return (calcWeightA - calcWeightB); } diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLGuacamoleProperties.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLGuacamoleProperties.java index 3c88a59fb..9039c029b 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLGuacamoleProperties.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/src/main/java/org/apache/guacamole/auth/mysql/MySQLGuacamoleProperties.java @@ -174,18 +174,6 @@ public class MySQLGuacamoleProperties { }; - /** - * The connection weight for connections in balancing groups. - */ - public static final IntegerGuacamoleProperty - MYSQL_DEFAULT_CONNECTION_WEIGHT = - new IntegerGuacamoleProperty() { - - @Override - public String getName() { return "mysql-default-connection-weight"; } - - }; - /** * The maximum number of concurrent connections to allow to any one * connection group by an individual user. Zero denotes diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLGuacamoleProperties.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLGuacamoleProperties.java index 3ae83ab21..3da972fe7 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLGuacamoleProperties.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLGuacamoleProperties.java @@ -157,15 +157,6 @@ public class PostgreSQLGuacamoleProperties { }; - public static final IntegerGuacamoleProperty - POSTGRESQL_DEFAULT_CONNECTION_WEIGHT = - new IntegerGuacamoleProperty() { - - @Override - public String getName() { return "postgresql-default-connection-weight"; } - - }; - /** * The maximum number of concurrent connections to allow to any one * connection group. Zero denotes unlimited. From 166c7ccaedc5c1701ef338bac6472f4685199fb9 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Tue, 6 Jun 2017 08:55:11 -0400 Subject: [PATCH 25/27] GUACAMOLE-102: Make field header consistent; add section header for new load balancing section. --- .../src/main/resources/translations/en.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/resources/translations/en.json b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/resources/translations/en.json index c154d8b8b..93e95d58a 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/resources/translations/en.json +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/resources/translations/en.json @@ -19,7 +19,8 @@ "FIELD_HEADER_MAX_CONNECTIONS" : "Maximum number of connections:", "FIELD_HEADER_MAX_CONNECTIONS_PER_USER" : "Maximum number of connections per user:", - "FIELD_HEADER_WEIGHT" : "Connection Weight for Load Balancing:", + + "FIELD_HEADER_WEIGHT" : "Connection weight for load balancing:", "FIELD_HEADER_GUACD_HOSTNAME" : "Hostname:", "FIELD_HEADER_GUACD_ENCRYPTION" : "Encryption:", @@ -29,8 +30,9 @@ "FIELD_OPTION_GUACD_ENCRYPTION_NONE" : "None (unencrypted)", "FIELD_OPTION_GUACD_ENCRYPTION_SSL" : "SSL / TLS", - "SECTION_HEADER_CONCURRENCY" : "Concurrency Limits", - "SECTION_HEADER_GUACD" : "Guacamole Proxy Parameters (guacd)" + "SECTION_HEADER_CONCURRENCY" : "Concurrency Limits", + "SECTION_HEADER_LOAD_BALANCING" : "Load Balancing", + "SECTION_HEADER_GUACD" : "Guacamole Proxy Parameters (guacd)" }, From 5532819abfcb1bbf6774f1275e0aa5685dcb7a96 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Tue, 6 Jun 2017 09:10:49 -0400 Subject: [PATCH 26/27] GUACAMOLE-102: Split out load balancing into a separate section/form. --- .../auth/jdbc/connection/ModeledConnection.java | 9 ++++++++- .../src/main/resources/translations/en.json | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java index db8c815cf..3c85f37c6 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java @@ -127,7 +127,13 @@ public class ModeledConnection extends ModeledChildDirectoryObjectasList( new NumericField(MAX_CONNECTIONS_NAME), - new NumericField(MAX_CONNECTIONS_PER_USER_NAME), + new NumericField(MAX_CONNECTIONS_PER_USER_NAME) + )); + + /** + * All attributes related to to load balancing in a logical form. + */ + public static final Form LOAD_BALANCING = new Form("load-balancing", Arrays.asList( new NumericField(CONNECTION_WEIGHT) )); @@ -137,6 +143,7 @@ public class ModeledConnection extends ModeledChildDirectoryObject ATTRIBUTES = Collections.unmodifiableCollection(Arrays.asList( CONCURRENCY_LIMITS, + LOAD_BALANCING, GUACD_PARAMETERS )); diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/resources/translations/en.json b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/resources/translations/en.json index 93e95d58a..0bc2db375 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/resources/translations/en.json +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/resources/translations/en.json @@ -20,7 +20,7 @@ "FIELD_HEADER_MAX_CONNECTIONS" : "Maximum number of connections:", "FIELD_HEADER_MAX_CONNECTIONS_PER_USER" : "Maximum number of connections per user:", - "FIELD_HEADER_WEIGHT" : "Connection weight for load balancing:", + "FIELD_HEADER_WEIGHT" : "Connection weight:", "FIELD_HEADER_GUACD_HOSTNAME" : "Hostname:", "FIELD_HEADER_GUACD_ENCRYPTION" : "Encryption:", From d8ba0f83ef725761631049a143d1c9686c276c98 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Tue, 6 Jun 2017 19:59:53 -0400 Subject: [PATCH 27/27] GUACAMOLE-102: Cleaning up comment, because apparently tu-tus don't go with Guacamole! --- .../guacamole/auth/jdbc/connection/ModeledConnection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java index 3c85f37c6..3d6e625b0 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/java/org/apache/guacamole/auth/jdbc/connection/ModeledConnection.java @@ -131,7 +131,7 @@ public class ModeledConnection extends ModeledChildDirectoryObjectasList( new NumericField(CONNECTION_WEIGHT)