From ab0b4c2d75ed93724c7bb9e3932cf79f7b1b26d7 Mon Sep 17 00:00:00 2001 From: Björn Hagemeister Date: Tue, 30 Sep 2014 18:29:37 +0200 Subject: Handling case, if no *.crc file is available plus adding upload complete message if done. --- .../filetransfer/FileUploadWorker.java | 17 ++++++++---- .../filetransfer/ThriftConnection.java | 32 ++++++++++++++-------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java index f8a0578..09e412a 100644 --- a/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java +++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java @@ -11,6 +11,7 @@ import org.openslx.imagemaster.thrift.iface.ImageData; import org.openslx.imagemaster.thrift.iface.UploadData; import org.openslx.satellitedaemon.Globals; import org.openslx.satellitedaemon.db.DbImage; +import org.openslx.satellitedaemon.db.DbImage.Status; public class FileUploadWorker implements Runnable { @@ -36,14 +37,14 @@ public class FileUploadWorker implements Runnable // Only for testing because a random UUID is used. Later the method above should be used. ImageData imDat = new ImageData( UUID.randomUUID().toString(), image.rid, - image.name, System.currentTimeMillis(), - System.currentTimeMillis(), image.creator, "anyThing", + image.name, (System.currentTimeMillis() / 1000), + (System.currentTimeMillis() / 1000), image.creator, "anyThing", true, false, "best", "theVeryBest", image.fileSize ); - String crcPath = image.path.concat( ".crc" ); + String path = Globals.getImageFolder() + "/" + image.path; // ThriftConnection.getUploadInfos returns uploadInfo and handles ThriftAuthentication - UploadData upInfos = ThriftConnection.getUploadInfos( imDat, crcPath ); + UploadData upInfos = ThriftConnection.getUploadInfos( imDat, path ); if ( upInfos == null ) { log.error( "The UploadInfos returned by ThriftConnection Class are null" ); continue; @@ -62,8 +63,12 @@ public class FileUploadWorker implements Runnable } // Start upload process. - u.upload(image.path); - u.close(null); + if (u.upload(path)) { + u.close(null); + log.info("Uploaded image successfuly."); + image.updateStatus(Status.successfully_published); + } + } try { Thread.sleep( 1 * 60 * 1000 ); diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java index 673be05..614fb24 100644 --- a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java +++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java @@ -62,24 +62,32 @@ public class ThriftConnection { * * @return returns 'null' if there is a problem. */ - public static UploadData getUploadInfos(ImageData imDat, String filename) { + public static UploadData getUploadInfos(ImageData imDat, String path) { ImageServer.Client theClient = null; + String crcPath = path.concat(".crc"); try { theClient = getConnection(); if (theClient == null) { log.error("Client was null!"); return null; } - - crc = new CrcFile(filename); - log.info("Made CRCFile from " + filename); - log.info("crc.getCrcSums( ).size = " + crc.getCrcSums().size()); - // log.info( "crc.getMasterSum() : " + crc.getMasterSum() ); - // for ( int i = 0; i < crc.getCrcSums().size() - 1; i++ ) { - // log.info( "crc.getCRCSum() : " + crc.getCRCSum( i ) ); - // } - return theClient - .submitImage(sSD.sessionId, imDat, crc.getCrcSums()); + List crcSums = null; + try { + crc = new CrcFile(crcPath); + log.info("Made CRCFile from " + crcPath); + log.info("crc.getCrcSums( ).size = " + crc.getCrcSums().size()); + // log.info( "crc.getMasterSum() : " + crc.getMasterSum() ); + // for ( int i = 0; i < crc.getCrcSums().size() - 1; i++ ) { + // log.info( "crc.getCRCSum() : " + crc.getCRCSum( i ) ); + // } + crcSums = crc.getCrcSums(); + return theClient + .submitImage(sSD.sessionId, imDat, crcSums); + } catch (FileNotFoundException e) { + log.debug("crcFile " + crcPath + " not found."); + return theClient + .submitImage(sSD.sessionId, imDat, crcSums); + } } catch (ImageDataException e) { if (e.isSetNumber() && e.getNumber().equals(ImageDataError.INVALID_DATA)) { @@ -97,7 +105,7 @@ public class ThriftConnection { } else if (e.getNumber().equals(UploadError.INVALID_CRC)) { // The CRC sum contained errors try { - crc = new CrcFile(filename); + crc = new CrcFile(crcPath); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); -- cgit v1.2.3-55-g7522