diff options
Diffstat (limited to 'src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java')
-rw-r--r-- | src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java b/src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java index c831435..cacd6c8 100644 --- a/src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java +++ b/src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java @@ -16,6 +16,7 @@ import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.transport.TSocket; import org.apache.thrift.transport.TTransport; +import org.openslx.imagemaster.crcchecker.CRCFile; import org.openslx.imagemaster.thrift.iface.DownloadInfos; import org.openslx.imagemaster.thrift.iface.ImageData; import org.openslx.imagemaster.thrift.iface.ImageServer; @@ -39,14 +40,73 @@ public class ThriftConnection private static ImageServer.Client client = null; private static ServerSessionData sSD = null; private static Logger log = Logger.getLogger( ThriftConnection.class ); + private static CRCFile crc = null; - /** + * Method for getting UploadeInfos + * + * !! 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 returns ftpCredential. + * and to get the ServerSessionData. If connection is ok, it calls + * submitImage with CRCsum in List<Integer>. * * @return returns 'null' if there is a problem. */ + public static UploadInfos getUploadInfos( ImageData imDat, String filename ) + { + ImageServer.Client theClient = null; + try { + theClient = getConnection(); + if ( theClient == null ) { + log.error( "Client was null!" ); + return null; + } + // .submitImage needs the List<Integer> 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 ); + return theClient.submitImage( sSD.sessionId, imDat, crc.getCrcSums() ); + } catch ( TException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch ( UnrecoverableKeyException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch ( InvalidKeyException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch ( NoSuchAlgorithmException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch ( CertificateException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch ( FileNotFoundException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch ( KeyStoreException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch ( SignatureException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch ( IOException e ) { + // TODO Auto-generated catch block + 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; @@ -56,8 +116,9 @@ public class ThriftConnection log.error( "Client was null!" ); return null; } - - return theClient.submitImage( sSD.sessionId, imDat ); + // .submitImage needs the List<Integer> from CRCFile.getCRCs() only + // on the first time called. null afterwards. + return theClient.submitImage( sSD.sessionId, imDat, crc.getCrcSums()); } catch ( TException e ) { // TODO Auto-generated catch block e.printStackTrace(); |