diff options
author | Jonathan Bauer | 2015-09-09 17:41:14 +0200 |
---|---|---|
committer | Jonathan Bauer | 2015-09-09 17:41:14 +0200 |
commit | 13dcbae97eb2e7b2e64bf02d81e315c51311fb7c (patch) | |
tree | c3e062a35bd49018c2d2ad3428436e24c5abe4ba | |
parent | [client] reworked def/custom permissions handling in ImageDetailsWindow (diff) | |
parent | [client] Use new authentication RPC to master (diff) | |
download | tutor-module-13dcbae97eb2e7b2e64bf02d81e315c51311fb7c.tar.gz tutor-module-13dcbae97eb2e7b2e64bf02d81e315c51311fb7c.tar.xz tutor-module-13dcbae97eb2e7b2e64bf02d81e315c51311fb7c.zip |
Merge branch 'v1.1' of stp:openslx-ng/tutor-module into v1.1
9 files changed, 142 insertions, 39 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/TestAccountAuthenticator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/TestAccountAuthenticator.java index 5d254d85..5adeb394 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/TestAccountAuthenticator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/TestAccountAuthenticator.java @@ -1,13 +1,8 @@ package org.openslx.dozmod.authentication; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - import org.apache.log4j.Logger; import org.apache.thrift.TException; -import org.openslx.bwlp.thrift.iface.Satellite; -import org.openslx.bwlp.thrift.iface.SessionData; +import org.openslx.bwlp.thrift.iface.ClientSessionData; import org.openslx.bwlp.thrift.iface.TAuthorizationException; import org.openslx.dozmod.authentication.ShibbolethEcp.ReturnCode; import org.openslx.thrifthelper.ThriftManager; @@ -27,16 +22,13 @@ public class TestAccountAuthenticator implements Authenticator { public void login(String username, String password, AuthenticatorCallback callback) throws TAuthorizationException, TException { - SessionData authResult = null; - authResult = ThriftManager.getMasterClient().authenticate(username, password); + ClientSessionData authResult = null; + authResult = ThriftManager.getMasterClient().localAccountLogin(username, password); // handle answer from server if (authResult != null && authResult.authToken != null) { LOGGER.info(authResult); - List<Satellite> sats = new ArrayList<>(); - // TODO: Handle cert fingerprint - sats.add(new Satellite(Arrays.asList(new String[] { authResult.serverAddress }), "default", null)); - AuthenticationData data = new AuthenticationData(authResult.authToken, authResult.sessionId, sats); + AuthenticationData data = new AuthenticationData(authResult.authToken, authResult.sessionId, authResult.satellites); callback.postLogin(ReturnCode.NO_ERROR, data, null); } else { // it should then show a corresponding error message! diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java index f8932a15..a624fc1a 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java @@ -23,6 +23,7 @@ import org.openslx.bwlp.thrift.iface.LecturePermissions; import org.openslx.bwlp.thrift.iface.LectureRead; import org.openslx.bwlp.thrift.iface.LectureSummary; import org.openslx.bwlp.thrift.iface.LectureWrite; +import org.openslx.bwlp.thrift.iface.Satellite; import org.openslx.bwlp.thrift.iface.SatelliteServer.Client; import org.openslx.bwlp.thrift.iface.TAuthorizationException; import org.openslx.bwlp.thrift.iface.TInvocationException; @@ -96,8 +97,23 @@ public class ThriftActions { masterToken = session.masterToken; } else { // after login - // TODO sat adress selection popup!! - address = "132.230.8.113"; + if (data.satellites == null || data.satellites.isEmpty()) { + // TODO: Ask for manual IP address entry + Gui.asyncMessageBox( + "Login erfolgreich, aber für die gewählte Einrichtung ist kein Satellit registriert", + MessageType.ERROR, LOGGER, null); + return false; + } + // TODO: Show list if > 1 + Satellite sat = data.satellites.get(0); + if (sat.addressList == null || sat.addressList.isEmpty()) { + // TODO: Ask for manual IP address entry + Gui.asyncMessageBox( + "Login erfolgreich, aber für den Satelliten ist keine IP-Adresse hinterlegt", + MessageType.ERROR, LOGGER, null); + return false; + } + address = sat.addressList.get(0); satToken = data.satelliteToken; masterToken = data.masterToken; } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/VmWrapper.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/VmWrapper.java index acf6fd3a..36c64fdf 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/VmWrapper.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/VmWrapper.java @@ -38,7 +38,7 @@ public class VmWrapper { machineDescription.length); } // Append disk & NAT - if (!vmwareConfig.addEthernetNat() || !vmwareConfig.addHddTemplate(diskFile.getName())) { + if (!vmwareConfig.addDefaultNat() || !vmwareConfig.addHddTemplate(diskFile.getName())) { throw new MetaDataMissingException(); } // The guestOS should be in the vmx, but the user could have changed it by editing diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java index bbbb8c8d..bf79e88f 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java @@ -760,35 +760,40 @@ public class DbImage { * * @param connection mysql connection to use * @param imageBaseId base id of image in question - * @param latest image version that is to become the latest version, or + * @param newLatest image version that is to become the latest version, or * <code>null</code> if there is no valid version * @return true if changed to a different, non-null image * @throws SQLException */ private static boolean setLatestVersion(MysqlConnection connection, String imageBaseId, - LocalImageVersion latest) throws SQLException { - // Debug - MysqlStatement ds = connection.prepareStatement("SELECT latestversionid FROM imagebase WHERE imagebaseid = :imagebaseid"); - ds.setString("imagebaseid", imageBaseId); - ResultSet drs = ds.executeQuery(); - if (drs.next()) { - LOGGER.debug("set latest on " + imageBaseId + ": from " + drs.getString("latestversionid") - + " to " + (latest == null ? null : latest.imageVersionId)); - } else { - LOGGER.debug("set latest: could not determine old latest for " + imageBaseId); - } + LocalImageVersion newLatest) throws SQLException { + // Determine manually if anything changed, as executeQuery() always returns 1 for some reason + boolean latestVersionChanged = true; + do { + MysqlStatement ds = connection.prepareStatement("SELECT latestversionid FROM imagebase WHERE imagebaseid = :imagebaseid"); + ds.setString("imagebaseid", imageBaseId); + ResultSet drs = ds.executeQuery(); + if (drs.next()) { + String currentLatest = drs.getString("latestversionid"); + if (currentLatest == null && (newLatest == null || newLatest.imageVersionId == null)) { + latestVersionChanged = false; + } else if (currentLatest != null && newLatest != null + && currentLatest.equals(newLatest.imageVersionId)) { + latestVersionChanged = false; + } + } + } while (false); // Update latestversionid reference in imagebase table MysqlStatement latestStmt = connection.prepareStatement("UPDATE imagebase SET latestversionid = :newversionid" + " WHERE imagebaseid = :imagebaseid"); - latestStmt.setString("newversionid", latest == null ? null : latest.imageVersionId); + latestStmt.setString("newversionid", newLatest == null ? null : newLatest.imageVersionId); latestStmt.setString("imagebaseid", imageBaseId); // If nothing changed (because the deleted version was not the latest), bail out - int updateCount = latestStmt.executeUpdate(); - LOGGER.debug(updateCount + " rows affected"); - if (updateCount == 0) + latestStmt.executeUpdate(); + if (!latestVersionChanged) return false; // It there is no valid version, bail out as a shortcut - queries below wouldn't do anything - if (latest == null) + if (newLatest == null) return true; // Latest version changed - update expire dates of related versions // Set short expire date for versions that are NOT the latest version but are still marked valid @@ -796,7 +801,7 @@ public class DbImage { MysqlStatement oldStmt = connection.prepareStatement("UPDATE imageversion SET" + " expiretime = If(expiretime < :shortexpire, expiretime, :shortexpire)" + " WHERE imagebaseid = :imagebaseid AND imageversionid <> :imageversionid AND isvalid = 1"); - oldStmt.setString("imageversionid", latest.imageVersionId); + oldStmt.setString("imageversionid", newLatest.imageVersionId); oldStmt.setString("imagebaseid", imageBaseId); oldStmt.setLong("shortexpire", shortExpire); oldStmt.executeUpdate(); @@ -804,7 +809,7 @@ public class DbImage { MysqlStatement newStmt = connection.prepareStatement("UPDATE imageversion SET" + " expiretime = If(createtime + :maxvalid > expiretime, createtime + :maxvalid, expiretime)" + " WHERE imageversionid = :imageversionid"); - newStmt.setString("imageversionid", latest.imageVersionId); + newStmt.setString("imageversionid", newLatest.imageVersionId); newStmt.setLong("maxvalid", RuntimeConfig.getMaxImageValiditySeconds()); newStmt.executeUpdate(); return true; diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java index df34b97a..7f980b7f 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java @@ -29,6 +29,7 @@ import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.util.Json; import org.openslx.util.vm.VmMetaData; import org.openslx.util.vm.VmwareMetaData; +import org.openslx.util.vm.VmwareMetaData.EthernetType; import com.google.gson.JsonParseException; @@ -461,6 +462,7 @@ public class DbLecture { meta.setOs(rs.getString("virtoskeyword")); } meta.addHddTemplate("%VM_DISK_PATH%"); + meta.addEthernet(EthernetType.NAT); // TODO: Use config // Everything worked so far, update statistics counters MysqlStatement upStmt = connection.prepareStatement("UPDATE" + " lecture SET lastused = UNIX_TIMESTAMP(), usecount = usecount + 1" @@ -487,4 +489,23 @@ public class DbLecture { } } + public static List<LectureSummary> getLecturesUsingImageVersion(String imageVersionId) + throws SQLException { + try (MysqlConnection connection = Database.getConnection()) { + MysqlStatement stmt = connection.prepareStatement(summaryBaseSql + + " WHERE l.imageversionid = :imageversionid"); + stmt.setString("userid", "-"); + stmt.setString("imageversionid", imageVersionId); + ResultSet rs = stmt.executeQuery(); + List<LectureSummary> list = new ArrayList<>(); + while (rs.next()) { + list.add(fillSummary(null, rs)); + } + return list; + } catch (SQLException e) { + LOGGER.error("Query failed in DbLecture.getExpiringLectures()", e); + throw e; + } + } + } diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbOrganization.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbOrganization.java index dbc75944..f208f2c2 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbOrganization.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbOrganization.java @@ -111,4 +111,29 @@ public class DbOrganization { } } + /** + * Return list of known organizations. This is a backup solution for + * fetching the list form them aster server, as this one doesn't fill all + * fields. + * + * @return list of all known organizations + * @throws SQLException + */ + public static List<Organization> getAll() throws SQLException { + try (MysqlConnection connection = Database.getConnection()) { + MysqlStatement stmt = connection.prepareStatement("SELECT" + " o.organizationid, o.displayname" + + " FROM organization o"); + ResultSet rsOrg = stmt.executeQuery(); + List<Organization> list = new ArrayList<>(); + while (rsOrg.next()) { + list.add(new Organization(rsOrg.getString("organizationid"), rsOrg.getString("displayname"), + null, null)); + } + return list; + } catch (SQLException e) { + LOGGER.error("Query failed in DbOrganization.getAll()", e); + throw e; + } + } + } diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbOsVirt.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbOsVirt.java index a8e24894..c34e5d72 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbOsVirt.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbOsVirt.java @@ -84,7 +84,7 @@ public class DbOsVirt { + " ON DUPLICATE KEY UPDATE virtname = VALUES(virtname)"); for (Virtualizer virt : list) { stmt.setString("virtid", virt.virtId); - stmt.setString("displayname", virt.virtName); + stmt.setString("virtname", virt.virtName); stmt.executeUpdate(); } connection.commit(); diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailGenerator.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailGenerator.java index fd7b5a2b..aae515b4 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailGenerator.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/mail/MailGenerator.java @@ -13,6 +13,7 @@ import org.apache.log4j.Logger; import org.openslx.bwlp.sat.database.mappers.DbConfiguration; import org.openslx.bwlp.sat.database.mappers.DbImage; import org.openslx.bwlp.sat.database.mappers.DbImagePermissions; +import org.openslx.bwlp.sat.database.mappers.DbLecture; import org.openslx.bwlp.sat.database.mappers.DbLecturePermissions; import org.openslx.bwlp.sat.database.mappers.DbUser; import org.openslx.bwlp.sat.database.mappers.DbUser.User; @@ -151,8 +152,10 @@ public class MailGenerator { LOGGER.warn("Could not get image details for image version " + version.imageVersionId); return; } + boolean isCurrentlyLatest = image.latestVersionId == null + || image.latestVersionId.equals(version.imageVersionId); String message; - if (image.latestVersionId == null || image.latestVersionId.equals(version.imageVersionId)) { + if (isCurrentlyLatest) { message = "Die aktuellste Version der VM '" + image.imageName + "' läuft in " + days + " Tag(en) ab. Bitte aktualisieren Sie die VM, da verknüpfte" + " Veranstaltungen sonst deaktiviert werden."; @@ -163,9 +166,34 @@ public class MailGenerator { } else { return; } - List<UserInfo> relevantUsers = getUserToMail(image); + List<UserInfo> relevantUsers; + // Mail users responsible for this image + message = wordWrap(message); + relevantUsers = getUserToMail(image); for (UserInfo user : relevantUsers) { - MailQueue.queue(new Mail(user, wordWrap(message))); + MailQueue.queue(new Mail(user, message)); + } + // Mail users using this image for a lecture, but only if the image expires before the lecture ends + // And the image to delete is currently the newest image + if (!isCurrentlyLatest) + return; + List<LectureSummary> lectures; + try { + lectures = DbLecture.getLecturesUsingImageVersion(version.imageVersionId); + } catch (SQLException e) { + lectures = new ArrayList<>(0); + } + for (LectureSummary lecture : lectures) { + if (lecture.endTime < version.expireTime) + continue; + message = "Hinweis zur Veranstaltung '" + lecture.lectureName + "': Die verwendete VM '" + + image.imageName + "' läuft in " + days + " Tag(en) ab. Bitte aktualisieren" + + " oder wechseln Sie die VM."; + message = wordWrap(message); + relevantUsers = getUserToMail(lecture); + for (UserInfo user : relevantUsers) { + MailQueue.queue(new Mail(user, message)); + } } } diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OrganizationList.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OrganizationList.java index 4325b152..6d2ebda2 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OrganizationList.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OrganizationList.java @@ -3,7 +3,9 @@ package org.openslx.bwlp.sat.thrift.cache; import java.sql.SQLException; import java.util.List; +import org.apache.log4j.Logger; import org.apache.thrift.TException; +import org.apache.thrift.transport.TTransportException; import org.openslx.bwlp.sat.database.mappers.DbOrganization; import org.openslx.bwlp.thrift.iface.Organization; import org.openslx.thrifthelper.ThriftManager; @@ -15,6 +17,8 @@ import org.openslx.util.QuickTimer.Task; * the master server. */ public class OrganizationList extends CacheBase<List<Organization>> { + + private static final Logger LOGGER = Logger.getLogger(OrganizationList.class); private static final OrganizationList instance = new OrganizationList(); @@ -24,7 +28,19 @@ public class OrganizationList extends CacheBase<List<Organization>> { @Override protected List<Organization> getCallback() throws TException { - final List<Organization> organizations = ThriftManager.getMasterClient().getOrganizations(); + final List<Organization> organizations; + try { + organizations = ThriftManager.getMasterClient().getOrganizations(); + } catch (TException e1) { + LOGGER.warn("Could not fetch Organization list from master, using local data...", + e1 instanceof TTransportException ? null : e1); + try { + return DbOrganization.getAll(); + } catch (SQLException e) { + LOGGER.warn("Using local Organization list from database also failed.", e); + } + return null; + } // Also store the list in the local data base (asynchronous, in the timer thread) QuickTimer.scheduleOnce(new Task() { @Override |