summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNils Schwabe2014-07-07 14:54:12 +0200
committerNils Schwabe2014-07-07 14:54:12 +0200
commit6da180fb0f2e5470959b532eab25148d3f3d2437 (patch)
tree3c1092856d4b702b8c57571c58a89a74e2e3ff00 /src
parentAdd port to up- and download thingis (diff)
downloadmasterserver-6da180fb0f2e5470959b532eab25148d3f3d2437.tar.gz
masterserver-6da180fb0f2e5470959b532eab25148d3f3d2437.tar.xz
masterserver-6da180fb0f2e5470959b532eab25148d3f3d2437.zip
Add argument to send crc sums over thrift
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/openslx/imagemaster/server/ApiServer.java4
-rw-r--r--src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java1
-rw-r--r--src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java14
-rw-r--r--src/main/java/org/openslx/imagemaster/thrift/server/ImageServerHandler.java4
4 files changed, 16 insertions, 7 deletions
diff --git a/src/main/java/org/openslx/imagemaster/server/ApiServer.java b/src/main/java/org/openslx/imagemaster/server/ApiServer.java
index 2d50160..1c9f7fd 100644
--- a/src/main/java/org/openslx/imagemaster/server/ApiServer.java
+++ b/src/main/java/org/openslx/imagemaster/server/ApiServer.java
@@ -118,14 +118,14 @@ public class ApiServer
// return ftpCredentials;
// }
- public static UploadInfos submitImage( String serverSessionId, ImageData imageDescription ) throws AuthorizationException, ImageDataException, UploadException
+ public static UploadInfos submitImage( String serverSessionId, ImageData imageDescription, List<Integer> crcSums ) throws AuthorizationException, ImageDataException, UploadException
{
// first check session of server
if ( ServerSessionManager.getSession( serverSessionId ) == null ) {
throw new AuthorizationException( AuthorizationError.NOT_AUTHENTICATED, "No valid serverSessioId" );
}
// then let the image processor decide what to do
- return ImageProcessor.getUploadInfos(serverSessionId, imageDescription);
+ return ImageProcessor.getUploadInfos(serverSessionId, imageDescription, crcSums);
}
public static DownloadInfos getImage( String uuid, String serverSessionId, List<Integer> requestedBlocks ) throws AuthorizationException, ImageDataException
diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java b/src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java
index 1c12e70..2f41fcd 100644
--- a/src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java
+++ b/src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java
@@ -129,6 +129,7 @@ public class ConnectionHandler implements IncomingEvent
// try to read meta data
while ( uploader.readMetaData() ) {
String token = uploader.getToken();
+ log.debug( "Got token :'" + token + "'");
// check token to identify the client
if ( !activeListeners.containsKey( token )) {
uploader.sendErrorCode( "Token not accepted." );
diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java b/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java
index 94d55ed..ec043fa 100644
--- a/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java
+++ b/src/main/java/org/openslx/imagemaster/serverconnection/ImageProcessor.java
@@ -1,5 +1,6 @@
package org.openslx.imagemaster.serverconnection;
+import java.io.IOException;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Iterator;
@@ -8,6 +9,7 @@ import java.util.List;
import org.apache.log4j.Logger;
import org.openslx.imagemaster.Globals;
+import org.openslx.imagemaster.crcchecker.CRCFile;
import org.openslx.imagemaster.db.DbImage;
import org.openslx.imagemaster.thrift.iface.DownloadInfos;
import org.openslx.imagemaster.thrift.iface.ImageData;
@@ -54,7 +56,7 @@ public class ImageProcessor
* @param imageData The data of the image
* @return
*/
- public static UploadInfos getUploadInfos( String serverSessionId, ImageData imageData )
+ public static UploadInfos getUploadInfos( String serverSessionId, ImageData imageData, List<Integer> crcSums)
{
// check image data
// TODO: do security checks
@@ -75,6 +77,12 @@ public class ImageProcessor
// insert new image and start listener
synchronized ( uploadingImages ) {
+ String crcPath = Globals.getImageDir() + "/" + uuid + ".crc";
+ try {
+ CRCFile crcFile = new CRCFile( crcSums, crcPath);
+ } catch (IOException e) {
+ return null; // TODO: what to do if we can not write the crc file to disk?
+ }
int nBlocks = (int)Math.ceil( imageData.fileSize / Globals.blockSize );
List<Integer> allBlocks = new LinkedList<>();
for ( int i = 0; i < nBlocks; i++ ) { // fill empty list with all block numbers
@@ -86,7 +94,7 @@ public class ImageProcessor
// TODO: proper synchronization, interface is multi threaded.
// should synchronize operations on the map (use concurrent map) and then synchronize on the uploading image
// when handing the missing blocks etc...
- uploadingImages.put( uuid, new UploadingImageInfos( token, port, allBlocks, serverSessionId, new Timestamp( System.currentTimeMillis() ), uuid, filepath, "CRCFILE" ) );
+ uploadingImages.put( uuid, new UploadingImageInfos( token, port, allBlocks, serverSessionId, new Timestamp( System.currentTimeMillis() ), uuid, filepath, crcPath ) );
DbImage.insert( imageData, System.currentTimeMillis(), token, allBlocks, serverSessionId, filepath );
imagesToCheck.add( uuid );
@@ -224,7 +232,7 @@ public class ImageProcessor
for ( DbImage image : list ) {
String token = image.token;
int port = ConnectionHandler.addConnection( token, image.imagePath, ConnectionData.UPLOADING );
- UploadingImageInfos infos = new UploadingImageInfos( token, port, image.missingBlocks, image.serverSessionId, image.timestamp, image.uuid, image.imagePath, "CRCFILE" );
+ UploadingImageInfos infos = new UploadingImageInfos( token, port, image.missingBlocks, image.serverSessionId, image.timestamp, image.uuid, image.imagePath, Globals.getImageDir() + "/" + image.uuid + ".crc" );
uploadingImages.put( image.uuid, infos );
}
log.info( "Added " + list.size() + " pending upload(s) to process list again." );
diff --git a/src/main/java/org/openslx/imagemaster/thrift/server/ImageServerHandler.java b/src/main/java/org/openslx/imagemaster/thrift/server/ImageServerHandler.java
index 3e9e2eb..bef8191 100644
--- a/src/main/java/org/openslx/imagemaster/thrift/server/ImageServerHandler.java
+++ b/src/main/java/org/openslx/imagemaster/thrift/server/ImageServerHandler.java
@@ -63,9 +63,9 @@ public class ImageServerHandler implements ImageServer.Iface
}
@Override
- public UploadInfos submitImage( String serverSessionId, ImageData imageDescription ) throws AuthorizationException, ImageDataException, UploadException, TException
+ public UploadInfos submitImage( String serverSessionId, ImageData imageDescription, List<Integer> crcSums ) throws AuthorizationException, ImageDataException, UploadException, TException
{
- return ApiServer.submitImage( serverSessionId, imageDescription );
+ return ApiServer.submitImage( serverSessionId, imageDescription, crcSums );
}
@Override