summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Hagemeister2014-09-22 18:09:39 +0200
committerBjörn Hagemeister2014-09-22 18:09:39 +0200
commitfc2fd4a903b4b2cc8869bfc113480d1bb5d744b2 (patch)
tree91ef47d1b17a53022ae7fd06d555090e60d20b2e
parentstep back to old but currently working code (diff)
downloadsatellite-daemon-fc2fd4a903b4b2cc8869bfc113480d1bb5d744b2.tar.gz
satellite-daemon-fc2fd4a903b4b2cc8869bfc113480d1bb5d744b2.tar.xz
satellite-daemon-fc2fd4a903b4b2cc8869bfc113480d1bb5d744b2.zip
Adapted files to new filetransfer.
-rw-r--r--src/main/java/org/openslx/satellitedaemon/filetransfer/FileDownloadWorker.java42
-rw-r--r--src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java57
-rw-r--r--src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java5
3 files changed, 66 insertions, 38 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/FileDownloadWorker.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileDownloadWorker.java
index f912698..9f7bc8c 100644
--- a/src/main/java/org/openslx/satellitedaemon/filetransfer/FileDownloadWorker.java
+++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileDownloadWorker.java
@@ -1,10 +1,13 @@
package org.openslx.satellitedaemon.filetransfer;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.openslx.filetransfer.Downloader;
+import org.openslx.filetransfer.FileRange;
+import org.openslx.filetransfer.WantRangeCallback;
import org.openslx.imagemaster.thrift.iface.DownloadInfos;
import org.openslx.satellitedaemon.Globals;
import org.openslx.satellitedaemon.db.DbImage;
@@ -17,27 +20,46 @@ public class FileDownloadWorker implements Runnable {
while (true) {
List<DbImage> imageList = DbImage.getAllMarkedForDownload();
log.info("imageList Contains " + imageList.size() + " items.");
- for (DbImage image : imageList) {
+ for (final DbImage image : imageList) {
List<Integer> range = new ArrayList<Integer>();
for (long i = 0; i < (image.fileSize / Globals.BLOCKSIZE); i++) {
range.add((int) i);
}
- DownloadInfos downInfos = ThriftConnection.getDownloadInfos(
- image, range);
+ DownloadInfos downInfos = ThriftConnection.getDownloadInfos(image);
if (downInfos == null) {
log.error("The DownloadInfos returned by ThriftConnection class are null");
continue;
}
+ // create new instance of Downloader.
Downloader d;
- d = new Downloader(Globals.getMasterserverHost(),
- downInfos.port, Globals.getMasterServerSslContext());
- d.sendToken(downInfos.token);
- d.setOutputFilename(Globals.getImageFolder() + "/" + image.name + ".vmdk"); // TODO: how should images be saved?
- while (d.readMetaData())
- // TODO: Request range...
- d.readBinary();
+ try {
+ d = new Downloader(Globals.getMasterserverHost(),
+ downInfos.port, Globals.getMasterServerSslContext(), downInfos.token);
+ } catch (IOException e) {
+ e.printStackTrace();
+ continue;
+ }
+
+ // start downloading process.
+ d.download(Globals.getImageFolder() + "/" + image.name + ".vmdk", new WantRangeCallback() {
+ long pos = 0;
+ long size = image.fileSize;
+
+ @Override
+ public FileRange get() {
+ // get start of range.
+ if (pos >= size)
+ return null;
+
+ long startOfRange = pos;
+ long endOfRange = Math.min(pos + Globals.BLOCKSIZE, image.fileSize);
+ FileRange range = new FileRange(startOfRange, endOfRange);
+ pos += Globals.BLOCKSIZE;
+ return range;
+ }
+ });
}
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
index 61d4072..415e0df 100644
--- a/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java
+++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java
@@ -1,6 +1,7 @@
package org.openslx.satellitedaemon.filetransfer;
import java.io.File;
+import java.io.IOException;
import java.util.List;
import java.util.UUID;
@@ -51,32 +52,38 @@ public class FileUploadWorker implements Runnable
// creating the uploader with the "context"-item.
Uploader u;
- u = new Uploader( Globals.getMasterserverHost(),
- upInfos.port, Globals.getMasterServerSslContext() );
- // Necessary authentication before upload.
- u.sendToken( upInfos.token );
-
- log.info( "upInfos.getMissingBlocks().size() = "
- + upInfos.getMissingBlocks().size() );
- long fileSize = new File( image.path ).length();
-
- // continue sending Blocks until getMissingBlocks is empty.
- while ( !upInfos.getMissingBlocks().isEmpty() ) {
- List<Integer> blocks = upInfos.getMissingBlocks();
- log.info( "Anzahl angeforderter Blöcke : " + blocks.size() );
- log.info( blocks );
- for ( int i = 0; i < blocks.size(); i++ ) {
- int startOffset = blocks.get( i ) * Globals.BLOCKSIZE; // TODO: long
- int endOffset = startOffset + Globals.BLOCKSIZE;
- if ( endOffset > fileSize )
- endOffset = (int)fileSize; // TODO: Long
- u.sendRange( startOffset, endOffset );
- u.sendFile( image.path );
- log.info( "Block number " + blocks.get( i ) + " uploaded." );
- }
- upInfos = ThriftConnection.getUploadInfos( imDat );
+ try {
+ u = new Uploader( Globals.getMasterserverHost(),
+ upInfos.port, Globals.getMasterServerSslContext(), upInfos.token );
+ } catch (IOException e) {
+ e.printStackTrace();
+ continue;
}
- u.close();
+ // Start upload process.
+ u.upload(image.path);
+
+
+// log.info( "upInfos.getMissingBlocks().size() = "
+// + upInfos.getMissingBlocks().size() );
+// long fileSize = new File( image.path ).length();
+//
+// // continue sending Blocks until getMissingBlocks is empty.
+// while ( !upInfos.getMissingBlocks().isEmpty() ) {
+// List<Integer> blocks = upInfos.getMissingBlocks();
+// log.info( "Anzahl angeforderter Blöcke : " + blocks.size() );
+// log.info( blocks );
+// for ( int i = 0; i < blocks.size(); i++ ) {
+// int startOffset = blocks.get( i ) * Globals.BLOCKSIZE; // TODO: long
+// int endOffset = startOffset + Globals.BLOCKSIZE;
+// if ( endOffset > fileSize )
+// endOffset = (int)fileSize; // TODO: Long
+// u.prepareSendRange( startOffset, endOffset );
+// u.sendFile( image.path );
+// log.info( "Block number " + blocks.get( i ) + " uploaded." );
+// }
+// upInfos = ThriftConnection.getUploadInfos( imDat );
+
+ u.close(null);
}
try {
Thread.sleep( 1 * 60 * 1000 );
diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
index 22f270a..a719c21 100644
--- a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
+++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
@@ -246,8 +246,7 @@ public class ThriftConnection {
*
* @return returns 'null' if there is a problem.
*/
- public static DownloadInfos getDownloadInfos(DbImage imDat,
- List<Integer> range) {
+ public static DownloadInfos getDownloadInfos(DbImage imDat) {
ImageServer.Client theClient = null;
try {
theClient = getConnection();
@@ -256,7 +255,7 @@ public class ThriftConnection {
return null;
}
- return theClient.getImage(imDat.guid, sSD.sessionId, range);
+ return theClient.getImage(imDat.guid, sSD.sessionId);
} catch (ImageDataException e) {
if (e.isSetNumber()
&& e.getNumber().equals(ImageDataError.INVALID_DATA)) {