From 864b6c21ae73788ce4dcaecb7ef2d386561cb20d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 16 Mar 2022 12:07:46 +0100 Subject: [client] Better log cancel/failure reason for uploads --- .../org/openslx/dozmod/thrift/UploadInitiator.java | 28 ++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/thrift/UploadInitiator.java') diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/UploadInitiator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/UploadInitiator.java index 777cfcc7..efa65bab 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/UploadInitiator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/UploadInitiator.java @@ -113,19 +113,19 @@ public class UploadInitiator { Session.getSatelliteToken(), imageBaseId, fileSize, null, // TODO remove deprecated parameter machineDescription); } catch (TAuthorizationException e) { - cancelWithErrorMessage("Upload vom Server verweigert"); + cancelWithGuiErrorMessage("Upload vom Server verweigert"); this.cancel(); return; } catch (TTransferRejectedException e) { if (e.message != null && e.message.startsWith("Server busy")) { initState = UploadInitState.WAITING_FOR_SLOT; } else { - cancelWithErrorMessage("Upload-Anfrage gescheitert (" + e.message + ")"); + cancelWithGuiErrorMessage("Upload-Anfrage gescheitert (" + e.message + ")"); this.cancel(); } return; } catch (TException e) { - cancelWithErrorMessage("Upload-Anfrage gescheitert!"); + cancelWithGuiErrorMessage("Upload-Anfrage gescheitert!"); this.cancel(); return; } @@ -157,6 +157,7 @@ public class UploadInitiator { public void fire() { LOGGER.debug("launch upload task"); if (initState != UploadInitState.UPLOAD_STARTING) { + LOGGER.info("Huh. Upload state is " + initState + ". Stopping init watchdog."); this.cancel(); return; } @@ -167,7 +168,7 @@ public class UploadInitiator { uploadTask = new UploadTask(Session.getSatelliteAddress(), transferInformation.getPlainPort(), transferInformation.getToken(), diskFile); } catch (FileNotFoundException e) { - cancelWithErrorMessage("Kann VM nicht hochladen: Datei nicht gefunden\n\n" + cancelWithGuiErrorMessage("Kann VM nicht hochladen: Datei nicht gefunden\n\n" + diskFile.getAbsolutePath()); this.cancel(); return; @@ -185,22 +186,24 @@ public class UploadInitiator { } if (!uploadTask.isComplete() && uploadTask.getTransferCount() == 0) { // Init failed - cancelWithErrorMessage("Aufbau der Verbindung zum Hochladen fehlgeschlagen"); + cancelWithGuiErrorMessage("Aufbau der Verbindung zum Hochladen fehlgeschlagen"); this.cancel(); return; } // Init succeeded initState = UploadInitState.UPLOAD_STARTED; + LOGGER.info("Upload initiated"); this.cancel(); } }; /** - * Set state to cancelled and clean up + * Set state to cancelled and clean up. Given reason goes to log only. */ - public synchronized void cancelError() { + public synchronized void cancelError(String reason) { if (initState == UploadInitState.ERROR) return; + LOGGER.info("Upload was cancelled while in state " + initState + ": " + reason); initState = UploadInitState.ERROR; if (hashGen != null) { hashGen.cancel(); @@ -224,12 +227,13 @@ public class UploadInitiator { return errorMessage; } - public void cancelWithErrorMessage(String errorMessage) { - if (!errorMessage.equals(this.errorMessage)) { - LOGGER.warn(errorMessage); - } + /** + * Cancel upload, show given error message in GUI transfer activity. + * @param errorMessage + */ + public void cancelWithGuiErrorMessage(String errorMessage) { this.errorMessage = errorMessage; - cancelError(); + cancelError("cancelWithErrorMessage: " + errorMessage); } public AsyncHashGenerator getHasher() { -- cgit v1.2.3-55-g7522