From e5a3a1d737e88c89a4ba3fbc8d277745093139b1 Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Wed, 13 May 2020 14:04:52 +0200 Subject: Add some debug logs. Rename the 'virtual' locations to groups. --- .../de/bwlehrpool/bwlp_guac/ConnectionManager.java | 76 ++++++++++++---------- 1 file changed, 41 insertions(+), 35 deletions(-) (limited to 'src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java') diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java b/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java index eacb347..00ec284 100644 --- a/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java +++ b/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java @@ -42,15 +42,15 @@ public class ConnectionManager { private static final LinkedHashMap clientPool = new LinkedHashMap(); - private static final LinkedHashMap locationPool = new LinkedHashMap(); + private static final LinkedHashMap groupPool = new LinkedHashMap(); - public static LinkedHashMap getLocationPool() { return locationPool; } + public static LinkedHashMap getGroupPool() { return groupPool; } /** * Pass plain user name, get existing connection (if any), or a fresh one * @param user (LDAP) user name */ - public static WrappedConnection getForUser(String user, int locationid) + public static WrappedConnection getForUser(String user, int groupid) throws GuacamoleCredentialsException { if (SOURCE_URL == null) { LOGGER.warn("Don't have a source URL for client machines!"); @@ -64,25 +64,26 @@ public class ConnectionManager { freeClient = null; synchronized (clientPool) { Collection clients; - if (locationid == 0) { + if (groupid == 0) { clients = new HashSet(); - for (JsonLocation loc : locationPool.values()) { - if (!loc.hasPassword()) clients.addAll(loc.clientList); + for (JsonGroup group : groupPool.values()) { + if (!group.hasPassword()) clients.addAll(group.clientList); } } else { - JsonLocation location = locationPool.get(locationid); - if (location == null) { - // Request the user to select a location + JsonGroup group = groupPool.get(groupid); + if (group == null) { + // Request the user to select a group throw new GuacamoleInsufficientCredentialsException( "Select Location", new CredentialsInfo( - Collections.singletonList(new LocationField()) + Collections.singletonList(new GroupField()) )); } - clients = location.clientList; + clients = group.clientList; } for (AvailableClient ac : clients) { if (ac.isInUseBy(user)) { + LOGGER.info("Client " + ac + " is in use by " + user); freeClient = ac; break; } @@ -90,6 +91,7 @@ public class ConnectionManager { if (freeClient == null) { for (AvailableClient ac : clients) { if (ac.claim(user)) { + LOGGER.info("Claiming client " + ac + " for " + user); freeClient = ac; break; } @@ -97,16 +99,18 @@ public class ConnectionManager { } } if (freeClient == null) { - // Request the user to select another location + // Request the user to select another Group throw new GuacamoleCredentialsException( - "No free client. Select another location.", new CredentialsInfo( - Collections.singletonList(new LocationField()) + "No free client. Select another Location.", new CredentialsInfo( + Collections.singletonList(new GroupField()) )); } // Found free or existing client, check if connection is (still) possible if (freeClient.checkConnection(0)) { LOGGER.info("Establishing mapping for user " + user + " to " + freeClient); return freeClient.getConnection(user); + } else { + LOGGER.info("Failed to establish mapping for user " + user + " to " + freeClient + ". Trying to find a new one."); } // Connection check failed - release and loop again freeClient.releaseConnection(user); @@ -174,23 +178,25 @@ public class ConnectionManager { return; } + // Temporary + JsonGroup[] groups = root.locations; - if (root.locations == null) { - LOGGER.info("Location list null"); + if (groups == null) { + LOGGER.info("Group list null"); } - synchronized (locationPool) { - for (JsonLocation lnew : root.locations) { - JsonLocation existing = locationPool.get(lnew.id); + synchronized (groupPool) { + for (JsonGroup gnew : groups) { + JsonGroup existing = groupPool.get(gnew.id); boolean redoClientMapping = false; if (existing == null) { - locationPool.put(lnew.id, lnew); - existing = lnew; + groupPool.put(gnew.id, gnew); + existing = gnew; redoClientMapping = true; } else { - if (existing.locationids != lnew.locationids) redoClientMapping = true; - existing.locationids = lnew.locationids; - existing.name = lnew.name; - existing.password = lnew.password; + if (existing.locationids != gnew.locationids) redoClientMapping = true; + existing.locationids = gnew.locationids; + existing.name = gnew.name; + existing.password = gnew.password; } if (redoClientMapping) { existing.clientList = new ArrayList(); @@ -205,11 +211,11 @@ public class ConnectionManager { } } existing.checked = true; - LOGGER.info("Location " + lnew.name + " with pw " + lnew.password); + LOGGER.info("Group " + gnew.name + " with pw " + gnew.password); } - for (JsonLocation loc : locationPool.values()) { - if (loc.checked) loc.checked = false; - else locationPool.remove(loc.id); + for (JsonGroup group : groupPool.values()) { + if (group.checked) group.checked = false; + else groupPool.remove(group.id); } } @@ -226,11 +232,11 @@ public class ConnectionManager { AvailableClient newClient = new AvailableClient(cnew); clientPool.put(cnew.clientip, newClient); - for (JsonLocation loc : locationPool.values()) { - for (int id : loc.locationids) { + for (JsonGroup group : groupPool.values()) { + for (int id : group.locationids) { if (id == cnew.locationid) { - loc.clientList.add(newClient); - newClient.locationList.add(loc); + group.clientList.add(newClient); + newClient.groupList.add(group); break; } } @@ -245,8 +251,8 @@ public class ConnectionManager { AvailableClient c = it.next(); if (c.isTimeout(NOW)) { LOGGER.info("Removing client " + c + " from list"); - for (JsonLocation loc : c.locationList) { - loc.clientList.remove(c); + for (JsonGroup group : c.groupList) { + group.clientList.remove(c); } it.remove(); } -- cgit v1.2.3-55-g7522