summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Hagemeister2014-10-22 16:37:32 +0200
committerBjörn Hagemeister2014-10-22 16:37:32 +0200
commitd12670ce84bd74feeb82e3d9c7a3f9a944bfed9e (patch)
tree9720a0c0714f97e7270af51ca48d41379d8aa63f
parentAdded usage info in case of invalid given arguments. (diff)
downloadsatellite-daemon-d12670ce84bd74feeb82e3d9c7a3f9a944bfed9e.tar.gz
satellite-daemon-d12670ce84bd74feeb82e3d9c7a3f9a944bfed9e.tar.xz
satellite-daemon-d12670ce84bd74feeb82e3d9c7a3f9a944bfed9e.zip
Fixed several things for successful up and download of images after using all arguments of database.
-rw-r--r--src/main/java/org/openslx/satellitedaemon/db/DbImage.java15
-rw-r--r--src/main/java/org/openslx/satellitedaemon/db/DbUser.java4
-rw-r--r--src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java22
-rw-r--r--src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java11
4 files changed, 38 insertions, 14 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/db/DbImage.java b/src/main/java/org/openslx/satellitedaemon/db/DbImage.java
index e34a2ca..c35fd5d 100644
--- a/src/main/java/org/openslx/satellitedaemon/db/DbImage.java
+++ b/src/main/java/org/openslx/satellitedaemon/db/DbImage.java
@@ -35,6 +35,17 @@ public class DbImage
rid = -1;
if ( fileSize == null )
fileSize = (long) -1;
+ if (createTime == null)
+ createTime = (long) 0;
+ if (changeTime == null)
+ changeTime = (long) 0;
+ if (contentOperatingSystem == null)
+ contentOperatingSystem = 0;
+ if (isValid == null)
+ isValid = true;
+ if (isDeleted == null)
+ isDeleted = false;
+
this.guid = guid;
this.name = name;
this.rid = rid;
@@ -44,8 +55,8 @@ public class DbImage
this.createTime = createTime;
this.changeTime = changeTime;
this.contentOperatingSystem = contentOperatingSystem;
- this.isValid = isValid;
- this.isDeleted = isDeleted;
+ this.isValid = true;
+ this.isDeleted = false;
}
/**
diff --git a/src/main/java/org/openslx/satellitedaemon/db/DbUser.java b/src/main/java/org/openslx/satellitedaemon/db/DbUser.java
index deebd66..3aa57d2 100644
--- a/src/main/java/org/openslx/satellitedaemon/db/DbUser.java
+++ b/src/main/java/org/openslx/satellitedaemon/db/DbUser.java
@@ -24,8 +24,8 @@ public class DbUser
*/
public static DbUser getUserById(String userId) {
return MySQL.findUniqueOrNull( DbUser.class, "SELECT user.userID, user.Vorname AS firstName, " +
- "user.Nachname AS lastName, user.mail AS email, user.institution" +
- "FROM m_user user" +
+ "user.Nachname AS lastName, user.mail AS email, user.institution " +
+ "FROM m_user user " +
"WHERE userID = ?", userId );
}
}
diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java
index 156414d..4876e6c 100644
--- a/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java
+++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java
@@ -6,6 +6,7 @@ import java.util.List;
import org.apache.log4j.Logger;
import org.openslx.filetransfer.Uploader;
import org.openslx.imagemaster.thrift.iface.ImageData;
+import org.openslx.imagemaster.thrift.iface.ImageDataException;
import org.openslx.imagemaster.thrift.iface.UploadData;
import org.openslx.imagemaster.thrift.iface.UserInfo;
import org.openslx.satellitedaemon.Globals;
@@ -36,11 +37,26 @@ public class FileUploadWorker implements Runnable
String path = Globals.getImageFolder() + "/" + image.path;
+ log.info( imDat.toString() );
// ThriftConnection.getUploadInfos returns uploadInfo and handles ThriftAuthentication
DbUser dbUser = DbUser.getUserById( imDat.ownerLogin );
- UserInfo userInfo = new UserInfo( dbUser.userId, dbUser.firstName, dbUser.lastName, dbUser.email, null );
- ThriftConnection.publishUser( userInfo );
- UploadData upInfos = ThriftConnection.getUploadInfos( imDat, path );
+ if (dbUser == null) {
+ image.updateStatus( Status.only_local );
+ log.warn( "Unknown user from database." );
+ } else {
+ UserInfo userInfo = new UserInfo( dbUser.userId, dbUser.firstName, dbUser.lastName, dbUser.email, dbUser.institution );
+ ThriftConnection.publishUser( userInfo );
+ }
+
+ UploadData upInfos;
+ try {
+ upInfos = ThriftConnection.getUploadInfos( imDat, path );
+ } catch ( ImageDataException e1 ) {
+ log.error( "Invalid image data. Not known by master.", e1 );
+ // mark image as only_local, that this image will be skipped next time.
+ image.updateStatus( Status.only_local );
+ continue;
+ }
if ( upInfos == null ) {
log.error( "The UploadInfos returned by ThriftConnection Class are null" );
continue;
diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
index c52b45b..7b41e20 100644
--- a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
+++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java
@@ -54,8 +54,9 @@ public class ThriftConnection
* connection is ok, it calls submitImage with CRCsum in List<Integer>.
*
* @return returns 'null' if there is a problem.
+ * @throws ImageDataException
*/
- public static UploadData getUploadInfos( ImageData imDat, String path )
+ public static UploadData getUploadInfos( ImageData imDat, String path ) throws ImageDataException
{
ImageServer.Client theClient = null;
String crcPath = path.concat( ".crc" );
@@ -87,12 +88,7 @@ public class ThriftConnection
log.warn( "Unknown authorization error.", e );
}
} catch ( ImageDataException e ) {
- if ( e.number == ImageDataError.INVALID_DATA ) {
- log.warn( "Data for image not valid", e );
- // TODO: add e.message into DB;
- } else {
- log.warn( "ImageDataException", e );
- }
+ throw e;
} catch ( UploadException e ) {
if ( e.number == UploadError.BROKEN_BLOCK ) {
// A Block was transmitted 20 times unsuccessfully.
@@ -269,6 +265,7 @@ public class ThriftConnection
return false;
}
try {
+ log.info( sSD.toString() );
return theClient.publishUser( sSD.sessionId, userInfo );
} catch ( AuthorizationException e ) {
log.error( "AutorizationException", e );