diff options
author | Simon Rettberg | 2024-05-14 20:48:11 +0200 |
---|---|---|
committer | Simon Rettberg | 2024-05-14 20:48:11 +0200 |
commit | 3c6b77e4a268f951b027b59da54f76415ec136d7 (patch) | |
tree | f3d072e2e3c7e38d3e111a6292bbcbe5150ba0f4 | |
parent | [server] DbLecture: Properly handle superadmin in getXml() (diff) | |
download | tutor-module-3c6b77e4a268f951b027b59da54f76415ec136d7.tar.gz tutor-module-3c6b77e4a268f951b027b59da54f76415ec136d7.tar.xz tutor-module-3c6b77e4a268f951b027b59da54f76415ec136d7.zip |
[server] Improve logging, remove redundant messages
4 files changed, 30 insertions, 24 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowFinalizer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowFinalizer.java index b305374a..8a219ce1 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowFinalizer.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowFinalizer.java @@ -156,7 +156,7 @@ public class CowFinalizer { User.canEditBaseImageOrFail(data.owner, data.imageBaseId); copy = false; } catch (Exception e) { - + LOGGER.info("Permission check for EDIT failed, falling back to COPY"); } } String baseId = data.imageBaseId; diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowSession.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowSession.java index f53cb2cc..cfe17a4e 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowSession.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowSession.java @@ -10,8 +10,12 @@ import java.util.List; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.openslx.bwlp.sat.permissions.User; import org.openslx.bwlp.sat.util.Configuration; import org.openslx.bwlp.sat.util.Formatter; +import org.openslx.bwlp.thrift.iface.TAuthorizationException; +import org.openslx.bwlp.thrift.iface.TInvocationException; +import org.openslx.bwlp.thrift.iface.TNotFoundException; import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.util.Json; import org.openslx.util.Util; @@ -70,13 +74,28 @@ public class CowSession { private CowFinalizer finalizer; public CowSession(String sourceFileName, byte[] machineDescription, String imageBaseId, String vmName, - boolean restricted, UserInfo owner, String sessionType) { + boolean restricted, UserInfo owner, String sessionType) throws RuntimeException { + if ("EDIT".equals(sessionType)) { + try { + User.canEditBaseImageOrFail(owner, imageBaseId); + } catch (TInvocationException | TNotFoundException | TAuthorizationException e) { + LOGGER.warn(Formatter.userFullName(owner) + " requested EDIT CoW session, but no permission", e); + throw new RuntimeException("EDIT permission denied"); + } + } RandomAccessFile srcFile; + long sfl = -1; try { srcFile = new RandomAccessFile(Configuration.getVmStoreBasePath() + "/" + sourceFileName, "r"); } catch (IOException e) { - setError("Cannot open source file for reading", e); - srcFile = null; + LOGGER.error("Cannot open source file for reading", e); + throw new RuntimeException("Cannot open source file for reading"); + } + try { + sfl = srcFile.length(); + } catch (IOException e) { + LOGGER.error("Cannot determine size of source file", e); + throw new RuntimeException("Cannot determine size of source file"); } // Create filenames File tmpFile = null; @@ -89,28 +108,19 @@ public class CowSession { Formatter.vmName(System.currentTimeMillis(), owner, vmName, ext)).getAbsoluteFile(); RandomAccessFile df = null; - long sfl = -1; try { df = new RandomAccessFile(tmpFile, "rw"); } catch (Exception e) { - setError("Cannot open destination file for writing", e); - } - if (srcFile != null) { - try { - sfl = srcFile.length(); - } catch (IOException e) { - setError("Cannot determine size of source file", e); - } + Util.safeClose(srcFile); + LOGGER.error("Cannot open destination file for writing", e); + throw new RuntimeException("Cannot open destination file for writing"); } this.sourceFileSize = sfl; - if (srcFile != null && df != null && sfl != -1) { - this.sourceFile = srcFile; - this.destinationFile = df; - } else { - Util.safeClose(srcFile, df); - } + this.sourceFile = srcFile; + this.destinationFile = df; this.data = new CowSessionData(imageBaseId, restricted, tmpFile, finalFile, owner, machineDescription, sessionType); + LOGGER.info("Started new " + sessionType + " CoW session for " + Formatter.userFullName(owner)); startCopying(); } @@ -135,6 +145,7 @@ public class CowSession { ret.tasks.add(new ProgressItem("Copying source file", (int) (fileCopyPosition * 100 / sourceFileSize), errorMessage)); } else { + ret.tasks.add(new ProgressItem("Copying source file", 100, null)); ret.tasks.add(new ProgressItem("Waiting for Upload to finish", status == Status.WAITING_FOR_UPLOAD_DONE ? -1 : 100, errorMessage)); } diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowSessionManager.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowSessionManager.java index 679e2551..197341fe 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowSessionManager.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowSessionManager.java @@ -67,8 +67,6 @@ public class CowSessionManager { /** * Create a new cow session for the given image. Returns an according session id. * On error, an exception is thrown, this will never return null. - * @param sessionType - * @throws RuntimeException */ public static String create(String cowid, LaunchData ld, String sessionType) throws RuntimeException { UserInfo user = SessionManager.get(cowid); diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java index eed9651c..29314db4 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java @@ -227,7 +227,6 @@ public class WebServer extends NanoHTTPD { } if (finalSize < 0 || finalSize > limit) return badRequest("Illegal final file size"); - LOGGER.info("Got upload finished for CoW session"); try { session.uploadFinished(finalSize); } catch (Exception e) { @@ -244,7 +243,6 @@ public class WebServer extends NanoHTTPD { CowSession session = CowSessionManager.get(sessionId); if (session == null) return notFound("Invalid session ID"); - LOGGER.info("User requested finalization for CoW session"); try { session.requestFinalization(); } catch (Exception e) { @@ -262,7 +260,6 @@ public class WebServer extends NanoHTTPD { CowSession session = CowSessionManager.get(sessionId); if (session == null) return notFound("Invalid session ID"); - LOGGER.info("User sent abort request for CoW session"); session.abort(); return new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, "text/plain; charset=utf-8", "OK"); } |