summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Hagemeister2014-09-30 18:29:37 +0200
committerBjörn Hagemeister2014-09-30 18:29:37 +0200
commitab0b4c2d75ed93724c7bb9e3932cf79f7b1b26d7 (patch)
tree6231e6594358b9e6f8db7d466ff8545c251f7d0a
parentInserted key handling with private key and public key for handshake and switc... (diff)
downloadsatellite-daemon-ab0b4c2d75ed93724c7bb9e3932cf79f7b1b26d7.tar.gz
satellite-daemon-ab0b4c2d75ed93724c7bb9e3932cf79f7b1b26d7.tar.xz
satellite-daemon-ab0b4c2d75ed93724c7bb9e3932cf79f7b1b26d7.zip
Handling case, if no *.crc file is available plus adding upload complete message if done.
-rw-r--r--src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java17
-rw-r--r--src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java32
2 files changed, 31 insertions, 18 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java
index f8a0578..09e412a 100644
--- a/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java
+++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java
@@ -11,6 +11,7 @@ import org.openslx.imagemaster.thrift.iface.ImageData;
import org.openslx.imagemaster.thrift.iface.UploadData;
import org.openslx.satellitedaemon.Globals;
import org.openslx.satellitedaemon.db.DbImage;
+import org.openslx.satellitedaemon.db.DbImage.Status;
public class FileUploadWorker implements Runnable
{
@@ -36,14 +37,14 @@ public class FileUploadWorker implements Runnable
// Only for testing because a random UUID is used. Later the method above should be used.
ImageData imDat = new ImageData(
UUID.randomUUID().toString(), image.rid,
- image.name, System.currentTimeMillis(),
- System.currentTimeMillis(), image.creator, "anyThing",
+ image.name, (System.currentTimeMillis() / 1000),
+ (System.currentTimeMillis() / 1000), image.creator, "anyThing",
true, false, "best", "theVeryBest", image.fileSize );
- String crcPath = image.path.concat( ".crc" );
+ String path = Globals.getImageFolder() + "/" + image.path;
// ThriftConnection.getUploadInfos returns uploadInfo and handles ThriftAuthentication
- UploadData upInfos = ThriftConnection.getUploadInfos( imDat, crcPath );
+ UploadData upInfos = ThriftConnection.getUploadInfos( imDat, path );
if ( upInfos == null ) {
log.error( "The UploadInfos returned by ThriftConnection Class are null" );
continue;
@@ -62,8 +63,12 @@ public class FileUploadWorker implements Runnable
}
// Start upload process.
- u.upload(image.path);
- u.close(null);
+ if (u.upload(path)) {
+ u.close(null);
+ log.info("Uploaded image successfuly.");
+ image.updateStatus(Status.successfully_published);
+ }
+
}
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 673be05..614fb24 100644
--- a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
+++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
@@ -62,24 +62,32 @@ public class ThriftConnection {
*
* @return returns 'null' if there is a problem.
*/
- public static UploadData getUploadInfos(ImageData imDat, String filename) {
+ public static UploadData getUploadInfos(ImageData imDat, String path) {
ImageServer.Client theClient = null;
+ String crcPath = path.concat(".crc");
try {
theClient = getConnection();
if (theClient == null) {
log.error("Client was null!");
return null;
}
-
- crc = new CrcFile(filename);
- log.info("Made CRCFile from " + filename);
- log.info("crc.getCrcSums( ).size = " + crc.getCrcSums().size());
- // log.info( "crc.getMasterSum() : " + crc.getMasterSum() );
- // for ( int i = 0; i < crc.getCrcSums().size() - 1; i++ ) {
- // log.info( "crc.getCRCSum() : " + crc.getCRCSum( i ) );
- // }
- return theClient
- .submitImage(sSD.sessionId, imDat, crc.getCrcSums());
+ List<Integer> crcSums = null;
+ try {
+ crc = new CrcFile(crcPath);
+ log.info("Made CRCFile from " + crcPath);
+ log.info("crc.getCrcSums( ).size = " + crc.getCrcSums().size());
+ // log.info( "crc.getMasterSum() : " + crc.getMasterSum() );
+ // for ( int i = 0; i < crc.getCrcSums().size() - 1; i++ ) {
+ // log.info( "crc.getCRCSum() : " + crc.getCRCSum( i ) );
+ // }
+ crcSums = crc.getCrcSums();
+ return theClient
+ .submitImage(sSD.sessionId, imDat, crcSums);
+ } catch (FileNotFoundException e) {
+ log.debug("crcFile " + crcPath + " not found.");
+ return theClient
+ .submitImage(sSD.sessionId, imDat, crcSums);
+ }
} catch (ImageDataException e) {
if (e.isSetNumber()
&& e.getNumber().equals(ImageDataError.INVALID_DATA)) {
@@ -97,7 +105,7 @@ public class ThriftConnection {
} else if (e.getNumber().equals(UploadError.INVALID_CRC)) {
// The CRC sum contained errors
try {
- crc = new CrcFile(filename);
+ crc = new CrcFile(crcPath);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();