From c4b51e6fd2b7e0fc3531cb43064f64e9d0d0b74e Mon Sep 17 00:00:00 2001 From: Michael Petretti Date: Thu, 10 Jul 2014 16:48:49 +0200 Subject: Fixed a lot of TODOs and upload works. --- .../satellitedaemon/ftp/ThriftConnection.java | 54 ++++++++++++---------- 1 file changed, 29 insertions(+), 25 deletions(-) (limited to 'src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java') diff --git a/src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java b/src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java index cacd6c8..5d67635 100644 --- a/src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java +++ b/src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java @@ -9,6 +9,7 @@ import java.security.NoSuchAlgorithmException; import java.security.SignatureException; import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; +import java.util.List; import org.apache.log4j.Logger; import org.apache.thrift.TException; @@ -31,7 +32,7 @@ import org.openslx.satellitedaemon.util.EncryptWithServerIdPublicKey; // TODO: Handle all the auto-generated catch blocks in a meaningful way -/** +/*********************************************************************************************** * Handles the authentication with the Satellite Server and sends the FtpCredentials, which * are necessary for the upload of the image. */ @@ -42,14 +43,14 @@ public class ThriftConnection private static Logger log = Logger.getLogger( ThriftConnection.class ); private static CRCFile crc = null; - /** - * Method for getting UploadeInfos + /*********************************************************************************************** + * Method for getting UploadeInfos * - * !! on the first Call !! + * !! on the first Call !! * * when the CRCsum need to be transfered. - * The method calls getConnection() to check if the connection is ok - * and to get the ServerSessionData. If connection is ok, it calls + * The method calls getConnection() to check if the connection is ok + * and to get the ServerSessionData. If connection is ok, it calls * submitImage with CRCsum in List. * * @return returns 'null' if there is a problem. @@ -66,7 +67,7 @@ public class ThriftConnection // .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); + crc = new CRCFile( filename ); log.info( "Made CRCFile from " + filename ); return theClient.submitImage( sSD.sessionId, imDat, crc.getCrcSums() ); } catch ( TException e ) { @@ -99,12 +100,13 @@ 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 + * 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 ) @@ -118,7 +120,7 @@ public class ThriftConnection } // .submitImage needs the List from CRCFile.getCRCs() only // on the first time called. null afterwards. - return theClient.submitImage( sSD.sessionId, imDat, crc.getCrcSums()); + return theClient.submitImage( sSD.sessionId, imDat, crc.getCrcSums() ); } catch ( TException e ) { // TODO Auto-generated catch block e.printStackTrace(); @@ -149,14 +151,14 @@ public class ThriftConnection } return null; } - - /** - * The method calls getConnection() to check if the connection is ok - * and to get the DownloadeInfos. If connection is ok, it returns ftpCredential. + + /*********************************************************************************************** + * Method for getting DonwloadInfos. Calls getConnection if client was null. + * You need to spezifie all Blocks you want to have in an List. * * @return returns 'null' if there is a problem. */ - public static DownloadInfos getDownloadInfos( DbImage imDat ) + public static DownloadInfos getDownloadInfos( DbImage imDat, List range ) { ImageServer.Client theClient = null; try { @@ -166,7 +168,7 @@ public class ThriftConnection return null; } - return theClient.getImage( imDat.guid, sSD.sessionId ); + return theClient.getImage( imDat.guid, sSD.sessionId, range ); } catch ( TException e ) { // TODO Auto-generated catch block e.printStackTrace(); @@ -198,9 +200,7 @@ public class ThriftConnection return null; } - - - /** + /*********************************************************************************************** * This method checks if there is already a working connection. If not, * newClient() establishes one. Also it does the Authentication if not done * yet. @@ -209,7 +209,7 @@ public class ThriftConnection */ private static ImageServer.Client getConnection() throws UnrecoverableKeyException, NoSuchAlgorithmException, CertificateException, - FileNotFoundException, KeyStoreException, IOException, InvalidKeyException, SignatureException + FileNotFoundException, KeyStoreException, IOException, InvalidKeyException, SignatureException { ImageServer.Client theClient = null; boolean isAuthenticated = false; @@ -241,14 +241,14 @@ public class ThriftConnection return null; } try { - toEncrypt = theClient.startServerAuthentication( Globals.getPropertyString( PropString.THRIFTORGANIZATIONNAME) ); + toEncrypt = theClient.startServerAuthentication( Globals.getPropertyString( PropString.THRIFTORGANIZATIONNAME ) ); log.info( "The random String we want to encrypt: " + toEncrypt ); EncryptWithServerIdPublicKey rse = new EncryptWithServerIdPublicKey( Globals.getPropertyString( PropString.RNDSTRINGENCRYPTALIAS ), Globals.getPropertyString( PropString.RNDSTRINGENCRYPTPASSWORD ), Globals.getPropertyString( PropString.RNDSTRINGENCRYPTPATH ) ); byte[] byteArray = rse.encryptString( toEncrypt ); sSD = theClient.serverAuthenticate( - Globals.getPropertyString( PropString.THRIFTORGANIZATIONNAME), ByteBuffer.wrap( byteArray ) ); + Globals.getPropertyString( PropString.THRIFTORGANIZATIONNAME ), ByteBuffer.wrap( byteArray ) ); } catch ( ServerAuthenticationException e ) { log.error( "ThriftConnection: ServerAuthenticationException: Server Authetication was not sucessful." ); e.printStackTrace(); @@ -265,11 +265,15 @@ public class ThriftConnection return theClient; } + /*********************************************************************************************** + * + * @return + */ private static ImageServer.Client newClient() { ImageServer.Client newClient = null; try { - TTransport transport; + TTransport transport; transport = new TSocket( Globals.getPropertyString( PropString.FTPSERVERIP ), Globals.getPropertyInt( PropInt.THRIFTPORT ) ); transport.open(); TProtocol protocol = new TBinaryProtocol( transport ); -- cgit v1.2.3-55-g7522