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.java65
1 files changed, 40 insertions, 25 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java b/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java
index 3ee624e..4fe2d61 100644
--- a/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java
+++ b/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java
@@ -9,6 +9,7 @@ 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;
@@ -19,7 +20,6 @@ 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;
@@ -34,17 +34,21 @@ public class FtpUploadWorker implements Runnable
// This List contains all Images in the Database that should be uploaded.
List<DbImage> imageList = DbImage.getAllMarkedForUpload();
log.info( "FtpUploadWorker: imageList Contains " + imageList.size() + " items." );
-
+
// Upload one Image after the other.
for ( DbImage image : imageList ) {
// TODO: still some fields for ImageData, which i can't fill with info from DbImage.
- ImageData imDat = new ImageData( image.guid, image.rid,
+// ImageData imDat = new ImageData( image.guid, image.rid,
+// image.name, System.currentTimeMillis(), System.currentTimeMillis(), image.creator, "anyThing",
+// true, false, "best", "theVeryBest", image.fileSize );
+
+ 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.
keystore = KeyStore.getInstance( "JKS" );
keystore.load( new FileInputStream( Globals.getPropertyString( PropString.FTPSKEYSTOREPATH ) ), passphrase );
@@ -55,33 +59,43 @@ public class FtpUploadWorker implements Runnable
context.init( null, trustManagers, null );
// uploadInfo and ThriftAuthentication
- UploadInfos upInfos = ThriftConnection.getUploadInfos( imDat );
+ String crcPath = image.path.concat( ".crc" );
+ UploadInfos upInfos = ThriftConnection.getUploadInfos( imDat, crcPath );
if ( upInfos == null ) {
log.error( "The UploadInfos returned by ThriftConnection Class are null" );
+ return;
}
-
+ 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 ), Globals.getPropertyInt( PropInt.FTPPORT ), context );
+ Uploader u = new Uploader( Globals.getPropertyString( PropString.FTPSERVERIP ), upInfos.port, context );
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 ) ) {
- u.sendRange( start, i );
- u.sendFile( image.path );
- start = i + 1;
- }
- if ( i == blocks.size() - 2 ) {
- u.sendRange( start, blocks.size() - 1 );
- u.sendFile( image.path );
- }
- }
- }
- upInfos = ThriftConnection.getUploadInfos( imDat );
+// 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 ) ) {
+// log.info( "Sending Blocks numbered from " + start + " up to " + i );
+// u.sendRange( start *16*1024*1024, i*16*1024*1024 );
+// u.sendFile( image.path );
+// log.info( "... DONE!" );
+// start = i + 1;
+// }
+// if ( i == blocks.size() - 2 ) {
+// log.info( "Sending Blocks numbered from " + start + " up to " + i );
+// u.sendRange( start*16*1024*1024, (blocks.size() - 1)*16*1024*1024 );
+// u.sendFile( image.path );
+// }
+// }
+// }
+// upInfos = ThriftConnection.getUploadInfos( imDat );
+ log.info("Using file:" + image.path );
+ u.sendRange( 254, 254 + 255 );
+ u.sendFile( image.path );
+
} catch ( NoSuchAlgorithmException e ) {
// TODO Auto-generated catch block
@@ -106,6 +120,7 @@ public class FtpUploadWorker implements Runnable
}
try {
Thread.sleep( 5 * 60 * 1000 );
+ // Thread.sleep( 1000 );
} catch ( InterruptedException e ) {
log.error( "FtpUploadWorker: Sleep interrupted" );
e.printStackTrace();