summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java')
-rw-r--r--src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java72
1 files changed, 7 insertions, 65 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java b/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java
index aa750f2..4445a2e 100644
--- a/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java
+++ b/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java
@@ -1,25 +1,14 @@
package org.openslx.satellitedaemon.ftp;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.security.KeyManagementException;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.cert.CertificateException;
import java.util.List;
import java.util.UUID;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.TrustManagerFactory;
-
import org.apache.log4j.Logger;
import org.openslx.filetransfer.Uploader;
import org.openslx.imagemaster.thrift.iface.ImageData;
import org.openslx.imagemaster.thrift.iface.UploadInfos;
import org.openslx.satellitedaemon.Globals;
+import org.openslx.satellitedaemon.Globals.PropInt;
import org.openslx.satellitedaemon.Globals.PropString;
import org.openslx.satellitedaemon.db.DbImage;
@@ -47,20 +36,6 @@ public class FtpUploadWorker implements Runnable
ImageData imDat = new ImageData( UUID.randomUUID().toString(), image.rid,
image.name, System.currentTimeMillis(), System.currentTimeMillis(), image.creator, "anyThing",
true, false, "best", "theVeryBest", image.fileSize );
- char[] passphrase = Globals.getPropertyString( PropString.FTPSKEYSTOREPWD ).toCharArray();
- KeyStore keystore;
- try {
-
- // All the necessary KeyStore handling for the "context"-item.
- // TODO: Don't do this again and again for every image, but once before the loop (or in the constructor)
- // Or better yet in a central spot, as the downloadworker needs the context too. Maybe something like Globals.getMasterServerSslContext()
- keystore = KeyStore.getInstance( "JKS" );
- keystore.load( new FileInputStream( Globals.getPropertyString( PropString.FTPSKEYSTOREPATH ) ), passphrase );
- TrustManagerFactory tmf = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() );
- tmf.init( keystore );
- SSLContext context = SSLContext.getInstance( "SSLv3" );
- TrustManager[] trustManagers = tmf.getTrustManagers();
- context.init( null, trustManagers, null );
// uploadInfo and ThriftAuthentication
String crcPath = image.path.concat( ".crc" );
@@ -76,61 +51,28 @@ public class FtpUploadWorker implements Runnable
log.info( "Got upInfos. Trying to create Uploader with token: " + upInfos.token );
// creating the uploader with the "context"-item.
- Uploader u = new Uploader( Globals.getPropertyString( PropString.FTPSERVERIP ), upInfos.port, context );
+ Uploader u = new Uploader( Globals.getPropertyString( PropString.FTPSERVERIP ), upInfos.port, Globals.getMasterServerSslContext() );
u.sendToken( upInfos.token );
// continue sending Blocks until getMissingBlocks is empty.
-
-
-
while ( !upInfos.getMissingBlocks().isEmpty() ) {
// Send all Blocks from upInfos.getMissingBlocks() in ranges.
List<Integer> blocks = upInfos.getMissingBlocks();
int start = 0;
for ( int i = 0; i < blocks.size() - 1; i++ ) {
- if ( blocks.get( i ) != ( blocks.get( i + 1 ) - 1 ) ) { // TODO: !? u.sendRange expects byte values, upInfos contains block indexes (16MiB)
- u.sendRange( start, i );
+ if ( blocks.get( i ) != ( blocks.get( i + 1 ) - 1 ) ) {
+ u.sendRange( start * Globals.getPropertyInt( PropInt.BLOCKSIZE ), i * Globals.getPropertyInt( PropInt.BLOCKSIZE ));
u.sendFile( image.path );
start = i + 1;
}
if ( i == blocks.size() - 2 ) { // TODO: !=
- u.sendRange( start, blocks.size() - 1 );
+ u.sendRange( start * Globals.getPropertyInt( PropInt.BLOCKSIZE ), (blocks.size() - 1) * Globals.getPropertyInt( PropInt.BLOCKSIZE ) );
u.sendFile( image.path );
}
}
+ upInfos = ThriftConnection.getUploadInfos( imDat );
}
- // FIXME: Should be inside loop, otherwise you'll only ever upload the first 20 blocks
- upInfos = ThriftConnection.getUploadInfos( imDat );
-
-
- // TODO: Use more local try/catch-blocks, not a big one around everything, so you know what exactly caused the exception
- // and can handle it properly. There are roughly 3 types of error/exception you can encounter:
- // 1) Expected exception: Something you expect to go wrong, so you handle it in the catch block and let the code flow continue
- // 2) Minor exception: Something went wrong and you can't continue trying to upload that image. Try to clean things up that
- // you already did (like opening a file, opening a network connection) and then continue with the next image
- // 3) Major messup: Something went wrong that will prevent the whole application from continuing to work. Try to finish or cancel
- // any operation going on in your application and then exit (and don't forget to log meaningful information about the error)
- // Basically all those empty catch blocks below should be moved up and filled with logic.
- } 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 ( IOException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch ( KeyStoreException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch ( KeyManagementException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
+ u.close();
}
try {
Thread.sleep( 5 * 60 * 1000 );