summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2014-07-07 15:12:47 +0200
committerSimon Rettberg2014-07-07 15:12:47 +0200
commit4d116e1a05a8e5ae342209131ef8905ea52136f0 (patch)
treeabb9122e81009d71eb9f3061302762b1efc1ae01
parentmore TODOs (diff)
parentAdd argument to send crc sums over thrift (diff)
downloadmasterserver-4d116e1a05a8e5ae342209131ef8905ea52136f0.tar.gz
masterserver-4d116e1a05a8e5ae342209131ef8905ea52136f0.tar.xz
masterserver-4d116e1a05a8e5ae342209131ef8905ea52136f0.zip
Merge branch 'master' of openslx.org:bwlp/masterserver
-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 ac1ab85..237789d 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 61edf86..0d400db 100644
--- a/src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java
+++ b/src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java
@@ -130,6 +130,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