GUAC-830: Add concurrency limitations to connection and connection group model objects.

This commit is contained in:
Michael Jumper
2015-08-21 12:57:03 -07:00
parent 4940f8e25e
commit 622f0852e2
3 changed files with 160 additions and 7 deletions

View File

@@ -41,7 +41,21 @@ public class ConnectionModel extends GroupedObjectModel {
* The name of the protocol to use when connecting to this connection. * The name of the protocol to use when connecting to this connection.
*/ */
private String protocol; private String protocol;
/**
* The maximum number of connections that can be established to this
* connection concurrently, zero if no restriction applies, or null if the
* default restrictions should be applied.
*/
private Integer maxConnections;
/**
* The maximum number of connections that can be established to this
* connection concurrently by any one user, zero if no restriction applies,
* or null if the default restrictions should be applied.
*/
private Integer maxConnectionsPerUser;
/** /**
* Creates a new, empty connection. * Creates a new, empty connection.
*/ */
@@ -89,6 +103,58 @@ public class ConnectionModel extends GroupedObjectModel {
this.protocol = protocol; this.protocol = protocol;
} }
/**
* Returns the maximum number of connections that can be established to
* this connection concurrently.
*
* @return
* The maximum number of connections that can be established to this
* connection concurrently, zero if no restriction applies, or null if
* the default restrictions should be applied.
*/
public Integer getMaxConnections() {
return maxConnections;
}
/**
* Sets the maximum number of connections that can be established to this
* connection concurrently.
*
* @param maxConnections
* The maximum number of connections that can be established to this
* connection concurrently, zero if no restriction applies, or null if
* the default restrictions should be applied.
*/
public void setMaxConnections(Integer maxConnections) {
this.maxConnections = maxConnections;
}
/**
* Returns the maximum number of connections that can be established to
* this connection concurrently by any one user.
*
* @return
* The maximum number of connections that can be established to this
* connection concurrently by any one user, zero if no restriction
* applies, or null if the default restrictions should be applied.
*/
public Integer getMaxConnectionsPerUser() {
return maxConnectionsPerUser;
}
/**
* Sets the maximum number of connections that can be established to this
* connection concurrently by any one user.
*
* @param maxConnectionsPerUser
* The maximum number of connections that can be established to this
* connection concurrently by any one user, zero if no restriction
* applies, or null if the default restrictions should be applied.
*/
public void setMaxConnectionsPerUser(Integer maxConnectionsPerUser) {
this.maxConnectionsPerUser = maxConnectionsPerUser;
}
@Override @Override
public String getIdentifier() { public String getIdentifier() {

View File

@@ -42,7 +42,21 @@ public class ConnectionGroupModel extends GroupedObjectModel {
* The type of this connection group, such as organizational or balancing. * The type of this connection group, such as organizational or balancing.
*/ */
private ConnectionGroup.Type type; private ConnectionGroup.Type type;
/**
* The maximum number of connections that can be established to this
* connection group concurrently, zero if no restriction applies, or
* null if the default restrictions should be applied.
*/
private Integer maxConnections;
/**
* The maximum number of connections that can be established to this
* connection group concurrently by any one user, zero if no restriction
* applies, or null if the default restrictions should be applied.
*/
private Integer maxConnectionsPerUser;
/** /**
* Creates a new, empty connection group. * Creates a new, empty connection group.
*/ */
@@ -91,6 +105,60 @@ public class ConnectionGroupModel extends GroupedObjectModel {
this.type = type; this.type = type;
} }
/**
* Returns the maximum number of connections that can be established to
* this connection group concurrently.
*
* @return
* The maximum number of connections that can be established to this
* connection group concurrently, zero if no restriction applies, or
* null if the default restrictions should be applied.
*/
public Integer getMaxConnections() {
return maxConnections;
}
/**
* Sets the maximum number of connections that can be established to this
* connection group concurrently.
*
* @param maxConnections
* The maximum number of connections that can be established to this
* connection group concurrently, zero if no restriction applies, or
* null if the default restrictions should be applied.
*/
public void setMaxConnections(Integer maxConnections) {
this.maxConnections = maxConnections;
}
/**
* Returns the maximum number of connections that can be established to
* this connection group concurrently by any one user.
*
* @return
* The maximum number of connections that can be established to this
* connection group concurrently by any one user, zero if no
* restriction applies, or null if the default restrictions should be
* applied.
*/
public Integer getMaxConnectionsPerUser() {
return maxConnectionsPerUser;
}
/**
* Sets the maximum number of connections that can be established to this
* connection group concurrently by any one user.
*
* @param maxConnectionsPerUser
* The maximum number of connections that can be established to this
* connection group concurrently by any one user, zero if no
* restriction applies, or null if the default restrictions should be
* applied.
*/
public void setMaxConnectionsPerUser(Integer maxConnectionsPerUser) {
this.maxConnectionsPerUser = maxConnectionsPerUser;
}
@Override @Override
public String getIdentifier() { public String getIdentifier() {

View File

@@ -200,14 +200,23 @@ public class ConfigurableGuacamoleTunnelService
// Return the first unreserved connection // Return the first unreserved connection
for (ModeledConnection connection : sortedConnections) { for (ModeledConnection connection : sortedConnections) {
// Determine per-user limits on this connection
Integer connectionMaxConnectionsPerUser = connection.getModel().getMaxConnectionsPerUser();
if (connectionMaxConnectionsPerUser == null)
connectionMaxConnectionsPerUser = connectionDefaultMaxConnectionsPerUser;
// Determine overall limits on this connection
Integer connectionMaxConnections = connection.getModel().getMaxConnections();
if (connectionMaxConnections == null)
connectionMaxConnections = connectionDefaultMaxConnections;
// Attempt to aquire connection according to per-user limits // Attempt to aquire connection according to per-user limits
Seat seat = new Seat(username, connection.getIdentifier()); Seat seat = new Seat(username, connection.getIdentifier());
if (tryAdd(activeSeats, seat, if (tryAdd(activeSeats, seat, connectionMaxConnectionsPerUser)) {
connectionDefaultMaxConnectionsPerUser)) {
// Attempt to aquire connection according to overall limits // Attempt to aquire connection according to overall limits
if (tryAdd(activeConnections, connection.getIdentifier(), if (tryAdd(activeConnections, connection.getIdentifier(),
connectionDefaultMaxConnections)) connectionMaxConnections))
return connection; return connection;
// Acquire failed - retry with next connection // Acquire failed - retry with next connection
@@ -243,14 +252,24 @@ public class ConfigurableGuacamoleTunnelService
// Get username // Get username
String username = user.getUser().getIdentifier(); String username = user.getUser().getIdentifier();
// Determine per-user limits on this connection group
Integer connectionGroupMaxConnectionsPerUser = connectionGroup.getModel().getMaxConnectionsPerUser();
if (connectionGroupMaxConnectionsPerUser == null)
connectionGroupMaxConnectionsPerUser = connectionGroupDefaultMaxConnectionsPerUser;
// Determine overall limits on this connection group
Integer connectionGroupMaxConnections = connectionGroup.getModel().getMaxConnections();
if (connectionGroupMaxConnections == null)
connectionGroupMaxConnections = connectionGroupDefaultMaxConnections;
// Attempt to aquire connection group according to per-user limits // Attempt to aquire connection group according to per-user limits
Seat seat = new Seat(username, connectionGroup.getIdentifier()); Seat seat = new Seat(username, connectionGroup.getIdentifier());
if (tryAdd(activeGroupSeats, seat, if (tryAdd(activeGroupSeats, seat,
connectionGroupDefaultMaxConnectionsPerUser)) { connectionGroupMaxConnectionsPerUser)) {
// Attempt to aquire connection group according to overall limits // Attempt to aquire connection group according to overall limits
if (tryAdd(activeGroups, connectionGroup.getIdentifier(), if (tryAdd(activeGroups, connectionGroup.getIdentifier(),
connectionGroupDefaultMaxConnections)) connectionGroupMaxConnections))
return; return;
// Acquire failed // Acquire failed