From 927d1d5b61a339f9074beb30a080f569d4d0258e Mon Sep 17 00:00:00 2001 From: Björn Hagemeister Date: Tue, 23 Sep 2014 16:28:07 +0200 Subject: Removed some out-commented code and merged getUploadInfos(ImageData, filename) and getUploadInfos(ImageData) into one method. --- .../java/org/openslx/satellitedaemon/Globals.java | 2 +- .../java/org/openslx/satellitedaemon/db/MySQL.java | 3 +- .../filetransfer/FileDownloadWorker.java | 4 +- .../filetransfer/FileUploadWorker.java | 24 +-- .../filetransfer/ThriftConnection.java | 220 +++++++++++---------- 5 files changed, 126 insertions(+), 127 deletions(-) diff --git a/src/main/java/org/openslx/satellitedaemon/Globals.java b/src/main/java/org/openslx/satellitedaemon/Globals.java index 72cd423..2cf594c 100644 --- a/src/main/java/org/openslx/satellitedaemon/Globals.java +++ b/src/main/java/org/openslx/satellitedaemon/Globals.java @@ -84,7 +84,7 @@ public class Globals { try { // Load all entries of the config file into properties BufferedInputStream stream = new BufferedInputStream( - new FileInputStream("config/global.properties")); + new FileInputStream("config/global.properties.example")); properties.load(stream); stream.close(); } catch (IOException e) { diff --git a/src/main/java/org/openslx/satellitedaemon/db/MySQL.java b/src/main/java/org/openslx/satellitedaemon/db/MySQL.java index 599cdb1..b4adaf6 100644 --- a/src/main/java/org/openslx/satellitedaemon/db/MySQL.java +++ b/src/main/java/org/openslx/satellitedaemon/db/MySQL.java @@ -35,7 +35,8 @@ class MySQL // Load connection info from class (TODO: Make pretty) Properties properties = new Properties(); try { - final BufferedInputStream stream = new BufferedInputStream( new FileInputStream( "config/mysql.properties" ) ); + // using "mysql.properties.example" for testing + final BufferedInputStream stream = new BufferedInputStream( new FileInputStream( "config/mysql.properties.example" ) ); properties.load( stream ); stream.close(); } catch ( FileNotFoundException e ) { diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/FileDownloadWorker.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileDownloadWorker.java index 9f7bc8c..2e92215 100644 --- a/src/main/java/org/openslx/satellitedaemon/filetransfer/FileDownloadWorker.java +++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileDownloadWorker.java @@ -13,7 +13,7 @@ import org.openslx.satellitedaemon.Globals; import org.openslx.satellitedaemon.db.DbImage; public class FileDownloadWorker implements Runnable { - private static Logger log = Logger.getLogger(FileUploadWorker.class); + private static Logger log = Logger.getLogger(FileDownloadWorker.class); @Override public void run() { @@ -43,7 +43,7 @@ public class FileDownloadWorker implements Runnable { } // start downloading process. - d.download(Globals.getImageFolder() + "/" + image.name + ".vmdk", new WantRangeCallback() { + d.download(Globals.getImageFolder() + "/" + image.path, new WantRangeCallback() { long pos = 0; long size = image.fileSize; diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java index 415e0df..aec589a 100644 --- a/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java +++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java @@ -41,6 +41,7 @@ public class FileUploadWorker implements Runnable true, false, "best", "theVeryBest", image.fileSize ); String crcPath = image.path.concat( ".crc" ); + // ThriftConnection.getUploadInfos returns uploadInfo and handles ThriftAuthentication UploadInfos upInfos = ThriftConnection.getUploadInfos( imDat, crcPath ); if ( upInfos == null ) { @@ -59,30 +60,9 @@ public class FileUploadWorker implements Runnable e.printStackTrace(); continue; } + // Start upload process. u.upload(image.path); - - -// log.info( "upInfos.getMissingBlocks().size() = " -// + upInfos.getMissingBlocks().size() ); -// long fileSize = new File( image.path ).length(); -// -// // continue sending Blocks until getMissingBlocks is empty. -// while ( !upInfos.getMissingBlocks().isEmpty() ) { -// List blocks = upInfos.getMissingBlocks(); -// log.info( "Anzahl angeforderter Blöcke : " + blocks.size() ); -// log.info( blocks ); -// for ( int i = 0; i < blocks.size(); i++ ) { -// int startOffset = blocks.get( i ) * Globals.BLOCKSIZE; // TODO: long -// int endOffset = startOffset + Globals.BLOCKSIZE; -// if ( endOffset > fileSize ) -// endOffset = (int)fileSize; // TODO: Long -// u.prepareSendRange( startOffset, endOffset ); -// u.sendFile( image.path ); -// log.info( "Block number " + blocks.get( i ) + " uploaded." ); -// } -// upInfos = ThriftConnection.getUploadInfos( imDat ); - u.close(null); } try { diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java index a719c21..de8d3f9 100644 --- a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java +++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java @@ -47,6 +47,9 @@ public class ThriftConnection { private static ServerSessionData sSD = null; private static Logger log = Logger.getLogger(ThriftConnection.class); private static CrcFile crc = null; + + // counter for counting how often getUploadInfos was called. + private static int counter = 0; /***********************************************************************************************/ /** @@ -68,18 +71,33 @@ public class ThriftConnection { log.error("Client was null!"); return null; } - // .submitImage needs the List from CRCFile.getCRCs() only - // on the first time called. null afterwards. - log.info("First call of submitImage following..."); - 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()); + + if (counter == 0) { + // method called for the first time. + // .submitImage needs the List from CRCFile.getCRCs() only + // on the first time called. null afterwards. + log.info("First call of submitImage following..."); + 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 ) ); + // } + + // increment counter. + counter++; + return theClient + .submitImage(sSD.sessionId, imDat, crc.getCrcSums()); + } else { + // method not called for the first time. + // .submitImage needs the List from CRCFile.getCRCs() only + // on the first time called. null afterwards. --Was the plan. So far + // not working I guess. + counter++; + return theClient + .submitImage(sSD.sessionId, imDat, null); + } } catch (ImageDataException e) { if (e.isSetNumber() && e.getNumber().equals(ImageDataError.INVALID_DATA)) { @@ -150,95 +168,95 @@ public class ThriftConnection { return null; } - /***********************************************************************************************/ - /** - * Method for getting UploadeInfos when CRCsum was already transfered on - * first call. The method calls getConnection() to check if the connection - * is ok and to get the ServerSessionData. If connection is ok, it calls - * submitImage with sSD.sessionId, imDat and !!null!! - * - * @return returns 'null' if there is a problem. - */ - public static UploadInfos getUploadInfos(ImageData imDat) { - ImageServer.Client theClient = null; - try { - theClient = getConnection(); - if (theClient == null) { - log.error("Client was null!"); - return null; - } - // .submitImage needs the List from CRCFile.getCRCs() only - // on the first time called. null afterwards. --Was the plan. So far - // not working I guess. - return theClient - .submitImage(sSD.sessionId, imDat, crc.getCrcSums()); - } catch (ImageDataException e) { - if (e.isSetNumber() - && e.getNumber().equals(ImageDataError.INVALID_DATA)) { - // Data in the db is not valid - // TODO: add e.message into DB; - } else { - e.printStackTrace(); - } - } catch (UploadException e) { - if (e.isSetNumber() - && e.getNumber().equals(UploadError.BROKEN_BLOCK)) { - // A Block was transmitted 20 times unsuccessfully. - // TODO: Mark the Image as corrupted. - } else if (e.getNumber().equals(UploadError.INVALID_CRC)) { - // The CRC sum contained errors - try { - if (!crc.isValid()) { - // TODO: Mark CRC-file as corrupted. - } - } catch (IOException e1) { - log.error("IOERROR, while reading from CRC File"); - } - } else { - e.printStackTrace(); - } - } catch (AuthorizationException e) { - if (e.isSetNumber() - && e.getNumber().equals( - AuthorizationError.NOT_AUTHENTICATED)) { - // SessionID is not valid - // TODO: Code for new SSID - } else if (e.getNumber().equals(AuthorizationError.NO_PERMISSION)) { - - } else { - e.printStackTrace(); - } - } catch (UnrecoverableKeyException e) { - log.error("UnrecoverableKeyException"); - e.printStackTrace(); - } catch (InvalidKeyException e) { - log.error("InvalidKeyException"); - e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - log.error("NoSuchAlgorithmException"); - e.printStackTrace(); - } catch (CertificateException e) { - log.error("CertificateException"); - e.printStackTrace(); - } catch (FileNotFoundException e) { - log.error("FileNotFoundException"); - e.printStackTrace(); - } catch (KeyStoreException e) { - log.error("KeyStoreException"); - e.printStackTrace(); - } catch (SignatureException e) { - log.error("SignatureException"); - e.printStackTrace(); - } catch (IOException e) { - log.error("IOException"); - e.printStackTrace(); - } catch (TException e) { - log.error("TException"); - e.printStackTrace(); - } - return null; - } - +// /***********************************************************************************************/ +// /** +// * Method for getting UploadeInfos when CRCsum was already transfered on +// * first call. The method calls getConnection() to check if the connection +// * is ok and to get the ServerSessionData. If connection is ok, it calls +// * submitImage with sSD.sessionId, imDat and !!null!! +// * +// * @return returns 'null' if there is a problem. +// */ +// public static UploadInfos getUploadInfos(ImageData imDat) { +// ImageServer.Client theClient = null; +// try { +// theClient = getConnection(); +// if (theClient == null) { +// log.error("Client was null!"); +// return null; +// } +// // .submitImage needs the List from CRCFile.getCRCs() only +// // on the first time called. null afterwards. --Was the plan. So far +// // not working I guess. +// return theClient +// .submitImage(sSD.sessionId, imDat, crc.getCrcSums()); +// } catch (ImageDataException e) { +// if (e.isSetNumber() +// && e.getNumber().equals(ImageDataError.INVALID_DATA)) { +// // Data in the db is not valid +// // TODO: add e.message into DB; +// } else { +// e.printStackTrace(); +// } +// } catch (UploadException e) { +// if (e.isSetNumber() +// && e.getNumber().equals(UploadError.BROKEN_BLOCK)) { +// // A Block was transmitted 20 times unsuccessfully. +// // TODO: Mark the Image as corrupted. +// } else if (e.getNumber().equals(UploadError.INVALID_CRC)) { +// // The CRC sum contained errors +// try { +// if (!crc.isValid()) { +// // TODO: Mark CRC-file as corrupted. +// } +// } catch (IOException e1) { +// log.error("IOERROR, while reading from CRC File"); +// } +// } else { +// e.printStackTrace(); +// } +// } catch (AuthorizationException e) { +// if (e.isSetNumber() +// && e.getNumber().equals( +// AuthorizationError.NOT_AUTHENTICATED)) { +// // SessionID is not valid +// // TODO: Code for new SSID +// } else if (e.getNumber().equals(AuthorizationError.NO_PERMISSION)) { +// +// } else { +// e.printStackTrace(); +// } +// } catch (UnrecoverableKeyException e) { +// log.error("UnrecoverableKeyException"); +// e.printStackTrace(); +// } catch (InvalidKeyException e) { +// log.error("InvalidKeyException"); +// e.printStackTrace(); +// } catch (NoSuchAlgorithmException e) { +// log.error("NoSuchAlgorithmException"); +// e.printStackTrace(); +// } catch (CertificateException e) { +// log.error("CertificateException"); +// e.printStackTrace(); +// } catch (FileNotFoundException e) { +// log.error("FileNotFoundException"); +// e.printStackTrace(); +// } catch (KeyStoreException e) { +// log.error("KeyStoreException"); +// e.printStackTrace(); +// } catch (SignatureException e) { +// log.error("SignatureException"); +// e.printStackTrace(); +// } catch (IOException e) { +// log.error("IOException"); +// e.printStackTrace(); +// } catch (TException e) { +// log.error("TException"); +// e.printStackTrace(); +// } +// return null; +// } +// /***********************************************************************************************/ /** * Method for getting DonwloadInfos. Calls getConnection if client was null. -- cgit v1.2.3-55-g7522