From e8c9e8e4dbc13d86d96589f0b4ccc0ad83cc3946 Mon Sep 17 00:00:00 2001 From: Nils Schwabe Date: Tue, 29 Jul 2014 15:00:06 +0200 Subject: Add error handling when CRCScheduler cannot read from crcfile on disk --- .../imagemaster/serverconnection/CRCScheduler.java | 23 ++++++++++++++++------ .../serverconnection/ImageProcessor.java | 13 +++++++++++- .../serverconnection/UploadingImage.java | 2 +- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/CRCScheduler.java b/src/main/java/org/openslx/imagemaster/serverconnection/CRCScheduler.java index cf8939a..f990f4e 100644 --- a/src/main/java/org/openslx/imagemaster/serverconnection/CRCScheduler.java +++ b/src/main/java/org/openslx/imagemaster/serverconnection/CRCScheduler.java @@ -29,25 +29,36 @@ public class CRCScheduler extends TimerTask log.debug( "Checking blocks of " + image.getDbImage().imageName ); CRCChecker crcChecker = new CRCChecker( image.getImageFile(), image.getCrcFile() ); log.debug( "CRCFile is valid: " + crcChecker.hasValidCrcFile() ); + if ( !crcChecker.hasValidCrcFile() ) { + image.setCrcFile( null ); // set crc file to null, so that the image processor will try to write it again. + crcChecker.done(); + continue; + } for ( int block = 0; block < image.getNumberOfBlocks(); block++ ) { if ( image.needsCheck( block ) ) { try { if ( crcChecker.checkBlock( block ) ) { image.setValid( block ); - log.debug( block + " was valid" ); + log.debug( block + " was valid" ); } else { image.setNeedsRequest( block ); log.debug( block + " was NOT valid" ); } } catch ( IOException e ) { - // TODO: Handle that crc file or image file could not be read. - // CRC file read error: tell client to resend? - // image file read error: tell server admin to check file permissions - log.debug( "Error: " + e.getMessage() ); + if ( e.getMessage().equalsIgnoreCase( "crc" ) ) { + image.setCrcFile( null ); // set crc file to null, so that the imageprocessor will try to write it again. + image.updateDb(); + crcChecker.done(); + break; + } else { + // could not read image file + log.error( "Could not read from image file on disk. Pleas contact the server administrator. Image: '" + image.getImageFile().toString() + "'" ); + } } } } - image.updateDb(); + image.updateDb(); // writes valid blocks to database + crcChecker.done(); // closes image file } log.debug( "... done" ); } diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java b/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java index d93ffa3..f73f019 100644 --- a/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java +++ b/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java @@ -71,7 +71,7 @@ public class ImageProcessor // check image data if ( imageData.imageName == null || imageData.imageName.isEmpty() ) { throw new ImageDataException( ImageDataError.INVALID_DATA, "Image name not set." ); - } else if ( imageData.imageName == null || imageData.imageOwner.isEmpty() ) { + } else if ( imageData.imageOwner == null || imageData.imageOwner.isEmpty() ) { throw new ImageDataException( ImageDataError.INVALID_DATA, "Image owner not set." ); } else if ( imageData.contentOperatingSystem == null || imageData.contentOperatingSystem.isEmpty() ) { throw new ImageDataException( ImageDataError.INVALID_DATA, "Content operating system not set." ); @@ -93,6 +93,17 @@ public class ImageProcessor synchronized ( uploadingImages ) { // check if image is already uploading if ( ( image = uploadingImages.get( uuid ) ) != null ) { + if (image.getCrcFile() == null) { + CRCFile crcFile; + try { + // try to write crc file ... + crcFile = CRCFile.writeCrcFile( crcSums, Globals.getImageDir() + "/" + uuid + ".crc" ); + } catch ( IOException e ) { + // ... and keep it in ram if it fails + crcFile = new CRCFile( crcSums ); + } + image.setCrcFile( crcFile ); + } List missing = getNMissingBlocks( image, AMOUNT ); if ( missing.isEmpty() && image.allBlocksValid() ) { uploadDone( uuid ); diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java b/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java index 7c491f6..f67da43 100644 --- a/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java +++ b/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java @@ -34,7 +34,7 @@ public class UploadingImage private DbImage dbImage = null; // the DB representation of this image private String uuid; private String filename; - private ImageFile imageFile; + private ImageFile imageFile = null; private CRCFile crcFile = null; protected UploadingImage(String token, int[] initialBlockStatus, long timestamp, String uuid, String filename) -- cgit v1.2.3-55-g7522