summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Petretti2014-07-15 14:24:38 +0200
committerMichael Petretti2014-07-15 14:24:38 +0200
commitafcdbf700dfdee503bd358f322c84e9114470f2e (patch)
tree3fc3522d709f41318bb4560f42095a5d92610080 /src
parentFixed a lot of TODOs and upload works. (diff)
downloadsatellite-daemon-afcdbf700dfdee503bd358f322c84e9114470f2e.tar.gz
satellite-daemon-afcdbf700dfdee503bd358f322c84e9114470f2e.tar.xz
satellite-daemon-afcdbf700dfdee503bd358f322c84e9114470f2e.zip
Rename and clean-up.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/openslx/satellitedaemon/App.java11
-rw-r--r--src/main/java/org/openslx/satellitedaemon/Globals.java63
-rw-r--r--src/main/java/org/openslx/satellitedaemon/filetransfer/FileDownloadWorker.java (renamed from src/main/java/org/openslx/satellitedaemon/ftp/FtpDownloadWorker.java)11
-rw-r--r--src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java85
-rw-r--r--src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java (renamed from src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java)105
-rw-r--r--src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java87
6 files changed, 173 insertions, 189 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/App.java b/src/main/java/org/openslx/satellitedaemon/App.java
index cd99ec0..1805d5a 100644
--- a/src/main/java/org/openslx/satellitedaemon/App.java
+++ b/src/main/java/org/openslx/satellitedaemon/App.java
@@ -4,10 +4,11 @@ import java.io.IOException;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
-import org.openslx.satellitedaemon.ftp.FtpDownloadWorker;
-import org.openslx.satellitedaemon.ftp.FtpUploadWorker;
+import org.openslx.satellitedaemon.filetransfer.FileDownloadWorker;
+import org.openslx.satellitedaemon.filetransfer.FileUploadWorker;
-/***********************************************************************************************
+/***********************************************************************************************/
+/**
* Main class for uploading images from the HS-Server to the Satellite Server.
*
*/
@@ -32,9 +33,9 @@ public class App
log.error( "Problem with initializing the SSLContext" );
System.exit( 1 );
}
- Thread uploadWorker = new Thread( new FtpUploadWorker() );
+ Thread uploadWorker = new Thread( new FileUploadWorker() );
uploadWorker.start();
- Thread downloadWorker = new Thread( new FtpDownloadWorker() );
+ Thread downloadWorker = new Thread( new FileDownloadWorker() );
downloadWorker.start();
}
}
diff --git a/src/main/java/org/openslx/satellitedaemon/Globals.java b/src/main/java/org/openslx/satellitedaemon/Globals.java
index afcb3c6..a62ee9e 100644
--- a/src/main/java/org/openslx/satellitedaemon/Globals.java
+++ b/src/main/java/org/openslx/satellitedaemon/Globals.java
@@ -24,26 +24,28 @@ public class Globals
private static boolean loadedProperties = false;
private static SSLContext context = null;
- /***********************************************************************************************
+ /***********************************************************************************************/
+ /**
* If there are more ints or Strings which should be added to config/global.properties,
* add to suiting enum, add a 'case' to getPropertyInt/String() and add checks to
* propertiesValid().
*
- * As an Example, if you want the value of the FTPSERVERIP you have to call
- * Globals.getPropertyString( PropString.FTPSERVERIP ) which returns a string.
+ * As an Example, if you want the value of the FILETRANSFERSERVERIP you have to call
+ * Globals.getPropertyString( PropString.FILETRANSFERSERVERIP ) which returns a string.
*/
public static enum PropInt
{
- FTPPORT, THRIFTPORT, BLOCKSIZE // More int's? Add them separated with ","
+ FILETRANSFERPORT, THRIFTPORT, BLOCKSIZE // More int's? Add them separated with ","
}
public static enum PropString
{ // More strings's? Add them separated with ","
- FTPSERVERIP, KEYSTORETYPE, FTPSKEYSTOREPATH, FTPSKEYSTOREPWD, THRIFTORGANIZATIONNAME,
+ FILETRANSFERSERVERIP, KEYSTORETYPE, FILETRANSFERSKEYSTOREPATH, FILETRANSFERSKEYSTOREPWD, THRIFTORGANIZATIONNAME,
RNDSTRINGENCRYPTALIAS, RNDSTRINGENCRYPTPASSWORD, RNDSTRINGENCRYPTPATH
}
- /***********************************************************************************************
+ /***********************************************************************************************/
+ /**
*
* @return
* @throws IOException
@@ -61,7 +63,8 @@ public class Globals
return true;
}
- /***********************************************************************************************
+ /***********************************************************************************************/
+ /**
*
* @param props
* @return
@@ -71,8 +74,8 @@ public class Globals
String result = null;
switch ( props ) {
- case FTPPORT:
- result = properties.getProperty( "ftp_port" );
+ case FILETRANSFERPORT:
+ result = properties.getProperty( "filetransfer_port" );
break;
case BLOCKSIZE:
result = properties.getProperty( "blockSize" );
@@ -90,7 +93,8 @@ public class Globals
return Integer.valueOf( result );
}
- /***********************************************************************************************
+ /***********************************************************************************************/
+ /**
*
* @param props
* @return
@@ -100,17 +104,17 @@ public class Globals
String result = null;
switch ( props ) {
- case FTPSERVERIP:
- result = properties.getProperty( "ftp_server_ip" );
+ case FILETRANSFERSERVERIP:
+ result = properties.getProperty( "filetransfer_server_ip" );
break;
case KEYSTORETYPE:
result = properties.getProperty( "keyStore_type" );
break;
- case FTPSKEYSTOREPATH:
- result = properties.getProperty( "path_to_ftps_keyStore" );
+ case FILETRANSFERSKEYSTOREPATH:
+ result = properties.getProperty( "path_to_filetransfer_keyStore" );
break;
- case FTPSKEYSTOREPWD:
- result = properties.getProperty( "ftps_keyStore_password" );
+ case FILETRANSFERSKEYSTOREPWD:
+ result = properties.getProperty( "filetransfer_keyStore_password" );
break;
case THRIFTORGANIZATIONNAME:
result = properties.getProperty( "organization_name" );
@@ -132,23 +136,24 @@ public class Globals
}
// TODO: add real checks
- /***********************************************************************************************
+ /***********************************************************************************************/
+ /**
*
* @return
*/
public static boolean propertiesValid()
{
- if ( Globals.getPropertyInt( PropInt.FTPPORT ) == 0
+ if ( Globals.getPropertyInt( PropInt.FILETRANSFERPORT ) == 0
|| Globals.getPropertyInt( PropInt.BLOCKSIZE ) == 0
|| Globals.getPropertyInt( PropInt.THRIFTPORT ) == 0
- || Globals.getPropertyString( PropString.FTPSERVERIP ).isEmpty()
- || Globals.getPropertyString( PropString.FTPSERVERIP ) == null
+ || Globals.getPropertyString( PropString.FILETRANSFERSERVERIP ).isEmpty()
+ || Globals.getPropertyString( PropString.FILETRANSFERSERVERIP ) == null
|| Globals.getPropertyString( PropString.KEYSTORETYPE ).isEmpty()
|| Globals.getPropertyString( PropString.KEYSTORETYPE ) == null
- || Globals.getPropertyString( PropString.FTPSKEYSTOREPATH ).isEmpty()
- || Globals.getPropertyString( PropString.FTPSKEYSTOREPATH ) == null
- || Globals.getPropertyString( PropString.FTPSKEYSTOREPWD ).isEmpty()
- || Globals.getPropertyString( PropString.FTPSKEYSTOREPWD ) == null
+ || Globals.getPropertyString( PropString.FILETRANSFERSKEYSTOREPATH ).isEmpty()
+ || Globals.getPropertyString( PropString.FILETRANSFERSKEYSTOREPATH ) == null
+ || Globals.getPropertyString( PropString.FILETRANSFERSKEYSTOREPWD ).isEmpty()
+ || Globals.getPropertyString( PropString.FILETRANSFERSKEYSTOREPWD ) == null
|| Globals.getPropertyString( PropString.THRIFTORGANIZATIONNAME ).isEmpty()
|| Globals.getPropertyString( PropString.THRIFTORGANIZATIONNAME ) == null
|| Globals.getPropertyString( PropString.RNDSTRINGENCRYPTALIAS ).isEmpty()
@@ -164,17 +169,18 @@ public class Globals
}
}
- /***********************************************************************************************
+ /***********************************************************************************************/
+ /**
*
* @return
*/
public static boolean masterServerSslContextInit()
{
- char[] passphrase = Globals.getPropertyString( PropString.FTPSKEYSTOREPWD ).toCharArray();
+ char[] passphrase = Globals.getPropertyString( PropString.FILETRANSFERSKEYSTOREPWD ).toCharArray();
KeyStore keystore;
try {
keystore = KeyStore.getInstance( "JKS" );
- keystore.load( new FileInputStream( Globals.getPropertyString( PropString.FTPSKEYSTOREPATH ) ), passphrase );
+ keystore.load( new FileInputStream( Globals.getPropertyString( PropString.FILETRANSFERSKEYSTOREPATH ) ), passphrase );
TrustManagerFactory tmf = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() );
tmf.init( keystore );
context = SSLContext.getInstance( "SSLv3" );
@@ -203,7 +209,8 @@ public class Globals
}
- /***********************************************************************************************
+ /***********************************************************************************************/
+ /**
*
* @return
*/
diff --git a/src/main/java/org/openslx/satellitedaemon/ftp/FtpDownloadWorker.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileDownloadWorker.java
index 73e0b03..e1ba7e9 100644
--- a/src/main/java/org/openslx/satellitedaemon/ftp/FtpDownloadWorker.java
+++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileDownloadWorker.java
@@ -1,4 +1,4 @@
-package org.openslx.satellitedaemon.ftp;
+package org.openslx.satellitedaemon.filetransfer;
import java.util.ArrayList;
import java.util.List;
@@ -12,16 +12,16 @@ import org.openslx.satellitedaemon.Globals.PropString;
import org.openslx.satellitedaemon.db.DbImage;
-public class FtpDownloadWorker implements Runnable
+public class FileDownloadWorker implements Runnable
{
- private static Logger log = Logger.getLogger( FtpUploadWorker.class );
+ private static Logger log = Logger.getLogger( FileUploadWorker.class );
@Override
public void run()
{
while ( true ) {
List<DbImage> imageList = DbImage.getAllMarkedForDownload();
- log.info( "FtpDownloadWorker: imageList Contains " + imageList.size() + " items." );
+ log.info( "FILTRANSFERDownloadWorker: imageList Contains " + imageList.size() + " items." );
for ( DbImage image : imageList ) {
List<Integer> range = new ArrayList<Integer>();
@@ -33,12 +33,11 @@ public class FtpDownloadWorker implements Runnable
log.error( "The DownloadInfos returned by ThriftConnection class are null" );
}
- Downloader d = new Downloader( Globals.getPropertyString( PropString.FTPSERVERIP ), downInfos.port, Globals.getMasterServerSslContext() );
+ Downloader d = new Downloader( Globals.getPropertyString( PropString.FILETRANSFERSERVERIP ), downInfos.port, Globals.getMasterServerSslContext() );
d.sendToken( downInfos.token );
d.setOutputFilename( "/home/michael/Downloads/tescht.whatever" );
while ( d.readMetaData() )
d.readBinary();
-
}
try {
Thread.sleep( 5 * 60 * 1000 );
diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java
new file mode 100644
index 0000000..8e66ea9
--- /dev/null
+++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java
@@ -0,0 +1,85 @@
+package org.openslx.satellitedaemon.filetransfer;
+
+import java.util.List;
+import java.util.UUID;
+
+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;
+
+public class FileUploadWorker implements Runnable
+{
+ private static Logger log = Logger.getLogger( FileUploadWorker.class );
+
+ @Override
+ public void run()
+ {
+ while ( true ) {
+ // This List contains all Images in the Database that should be uploaded.
+ List<DbImage> imageList = DbImage.getAllMarkedForUpload();
+ log.info( "FILTRANSFERUploadWorker: 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,
+ // 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 );
+
+ // uploadInfo and ThriftAuthentication
+ 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;
+
+ // FIXME: And then..? If you just continue, you'll run into a null pointer exception
+
+ }
+ 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.FILETRANSFERSERVERIP ), 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 ) ) {
+ u.sendRange( start * Globals.getPropertyInt( PropInt.BLOCKSIZE ), i * Globals.getPropertyInt( PropInt.BLOCKSIZE ) );
+ u.sendFile( image.path );
+ start = i + 1;
+ }
+ if ( i == blocks.size() - 2 ) {
+ u.sendRange( start * Globals.getPropertyInt( PropInt.BLOCKSIZE ), ( blocks.size() - 1 ) * Globals.getPropertyInt( PropInt.BLOCKSIZE ) );
+ u.sendFile( image.path );
+ }
+ }
+ upInfos = ThriftConnection.getUploadInfos( imDat );
+ }
+ u.close();
+ }
+ try {
+ Thread.sleep( 5 * 60 * 1000 );
+ // Thread.sleep( 1000 );
+ } catch ( InterruptedException e ) {
+ Thread.currentThread().interrupt();
+ return;
+ }
+ }
+
+ }
+}
diff --git a/src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
index 5d67635..b656a84 100644
--- a/src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java
+++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
@@ -1,4 +1,4 @@
-package org.openslx.satellitedaemon.ftp;
+package org.openslx.satellitedaemon.filetransfer;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -32,8 +32,9 @@ 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
+/***********************************************************************************************/
+/**
+ * Handles the authentication with the Satellite Server and sends the FILTRANSFERCredentials, which
* are necessary for the upload of the image.
*/
public class ThriftConnection
@@ -43,7 +44,8 @@ public class ThriftConnection
private static Logger log = Logger.getLogger( ThriftConnection.class );
private static CRCFile crc = null;
- /***********************************************************************************************
+ /***********************************************************************************************/
+ /**
* Method for getting UploadeInfos
*
* !! on the first Call !!
@@ -71,37 +73,29 @@ public class ThriftConnection
log.info( "Made CRCFile from " + filename );
return theClient.submitImage( sSD.sessionId, imDat, crc.getCrcSums() );
} catch ( TException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("TException");
} catch ( UnrecoverableKeyException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("UnrecoverableKeyException");
} catch ( InvalidKeyException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("InvalidKeyException");
} catch ( NoSuchAlgorithmException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("NoSuchAlgorithmException");
} catch ( CertificateException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("CertificateException");
} catch ( FileNotFoundException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("FileNotFoundException");
} catch ( KeyStoreException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("KeyStoreException");
} catch ( SignatureException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("SignatureException");
} catch ( IOException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("IOException");
}
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
@@ -122,37 +116,29 @@ public class ThriftConnection
// 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();
+ log.error("TException");
} catch ( UnrecoverableKeyException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("UnrecoverableKeyException");
} catch ( InvalidKeyException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("InvalidKeyException");
} catch ( NoSuchAlgorithmException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("NoSuchAlgorithmException");
} catch ( CertificateException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("CertificateException");
} catch ( FileNotFoundException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("FileNotFoundException");
} catch ( KeyStoreException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("KeyStoreException");
} catch ( SignatureException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("SignatureException");
} catch ( IOException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("IOException");
}
return null;
}
- /***********************************************************************************************
+ /***********************************************************************************************/
+ /**
* Method for getting DonwloadInfos. Calls getConnection if client was null.
* You need to spezifie all Blocks you want to have in an List.
*
@@ -170,37 +156,29 @@ public class ThriftConnection
return theClient.getImage( imDat.guid, sSD.sessionId, range );
} catch ( TException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("TException");
} catch ( UnrecoverableKeyException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("UnrecoverableKeyException");
} catch ( InvalidKeyException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("InvalidKeyException");
} catch ( NoSuchAlgorithmException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("NoSuchAlgorithmException");
} catch ( CertificateException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("CertificateException");
} catch ( FileNotFoundException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("FileNotFoundException");
} catch ( KeyStoreException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("KeyStoreException");
} catch ( SignatureException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("SignatureException");
} catch ( IOException e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("IOException");
}
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.
@@ -265,7 +243,8 @@ public class ThriftConnection
return theClient;
}
- /***********************************************************************************************
+ /***********************************************************************************************/
+ /**
*
* @return
*/
@@ -274,7 +253,7 @@ public class ThriftConnection
ImageServer.Client newClient = null;
try {
TTransport transport;
- transport = new TSocket( Globals.getPropertyString( PropString.FTPSERVERIP ), Globals.getPropertyInt( PropInt.THRIFTPORT ) );
+ transport = new TSocket( Globals.getPropertyString( PropString.FILETRANSFERSERVERIP ), Globals.getPropertyInt( PropInt.THRIFTPORT ) );
transport.open();
TProtocol protocol = new TBinaryProtocol( transport );
newClient = new ImageServer.Client( protocol );
diff --git a/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java b/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java
deleted file mode 100644
index 4445a2e..0000000
--- a/src/main/java/org/openslx/satellitedaemon/ftp/FtpUploadWorker.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package org.openslx.satellitedaemon.ftp;
-
-import java.util.List;
-import java.util.UUID;
-
-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;
-
-// TODO: Rename all this FTP* Stuff (also the constants in Globals) now that we're not using ftp anymore
-
-public class FtpUploadWorker implements Runnable
-{
- private static Logger log = Logger.getLogger( FtpUploadWorker.class );
-
- @Override
- public void run()
- {
- while ( true ) {
- // 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,
-// 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 );
-
- // uploadInfo and ThriftAuthentication
- 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;
-
- // FIXME: And then..? If you just continue, you'll run into a null pointer exception
-
- }
- 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, 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 ) ) {
- 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 * Globals.getPropertyInt( PropInt.BLOCKSIZE ), (blocks.size() - 1) * Globals.getPropertyInt( PropInt.BLOCKSIZE ) );
- u.sendFile( image.path );
- }
- }
- upInfos = ThriftConnection.getUploadInfos( imDat );
- }
- u.close();
- }
- try {
- Thread.sleep( 5 * 60 * 1000 );
- // Thread.sleep( 1000 );
- } catch ( InterruptedException e ) {
- Thread.currentThread().interrupt();
- return;
- }
- }
-
- }
-}