summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/IncomingDataTransfer.java
diff options
context:
space:
mode:
authorSimon Rettberg2016-04-25 18:32:37 +0200
committerSimon Rettberg2016-04-25 18:32:37 +0200
commitb1fe628e16cc2e62d94a9356c26b1356b48dcd1b (patch)
treed7fa758f56662d634585992e607d8c0ff675639f /dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/IncomingDataTransfer.java
parent[client] Add handling for master<->sat transfers (diff)
downloadtutor-module-b1fe628e16cc2e62d94a9356c26b1356b48dcd1b.tar.gz
tutor-module-b1fe628e16cc2e62d94a9356c26b1356b48dcd1b.tar.xz
tutor-module-b1fe628e16cc2e62d94a9356c26b1356b48dcd1b.zip
[server] Fix upload handling if image already exists
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/IncomingDataTransfer.java')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/IncomingDataTransfer.java57
1 files changed, 49 insertions, 8 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/IncomingDataTransfer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/IncomingDataTransfer.java
index 5c7621a9..8bda7cab 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/IncomingDataTransfer.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/IncomingDataTransfer.java
@@ -13,6 +13,7 @@ import javax.net.ssl.SSLContext;
import org.apache.log4j.Logger;
import org.openslx.bwlp.sat.database.mappers.DbImage;
+import org.openslx.bwlp.sat.database.mappers.DbImageBlock;
import org.openslx.bwlp.sat.util.Configuration;
import org.openslx.bwlp.sat.util.Constants;
import org.openslx.bwlp.sat.util.FileSystem;
@@ -20,10 +21,12 @@ import org.openslx.bwlp.sat.util.Formatter;
import org.openslx.bwlp.thrift.iface.ImageDetailsRead;
import org.openslx.bwlp.thrift.iface.ImagePublishData;
import org.openslx.bwlp.thrift.iface.ImageVersionWrite;
+import org.openslx.bwlp.thrift.iface.TNotFoundException;
import org.openslx.bwlp.thrift.iface.TransferInformation;
import org.openslx.bwlp.thrift.iface.TransferState;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.filetransfer.Downloader;
+import org.openslx.filetransfer.util.ChunkStatus;
import org.openslx.filetransfer.util.FileChunk;
import org.openslx.filetransfer.util.IncomingTransferBase;
import org.openslx.util.ThriftUtil;
@@ -68,17 +71,18 @@ public class IncomingDataTransfer extends IncomingTransferBase {
private final TransferInformation masterTransferInfo;
public IncomingDataTransfer(String uploadId, UserInfo owner, ImageDetailsRead image,
- File destinationFile, long fileSize, List<byte[]> sha1Sums, byte[] machineDescription)
- throws FileNotFoundException {
+ File destinationFile, long fileSize, List<byte[]> sha1Sums, byte[] machineDescription,
+ boolean repairUpload) throws FileNotFoundException {
super(uploadId, destinationFile, fileSize, sha1Sums);
- this.owner = owner;
+ this.owner = repairUpload ? null : owner;
this.image = image;
this.machineDescription = machineDescription;
this.masterTransferInfo = null;
+ initRepairUpload();
}
- public IncomingDataTransfer(ImagePublishData publishData, File tmpFile, TransferInformation transferInfo)
- throws FileNotFoundException {
+ public IncomingDataTransfer(ImagePublishData publishData, File tmpFile, TransferInformation transferInfo,
+ boolean repairUpload) throws FileNotFoundException {
super(UUID.randomUUID().toString(), tmpFile, publishData.fileSize,
ThriftUtil.unwrapByteBufferList(transferInfo.blockHashes));
ImageDetailsRead idr = new ImageDetailsRead();
@@ -94,11 +98,29 @@ public class IncomingDataTransfer extends IncomingTransferBase {
idr.setUpdaterId(publishData.uploader.userId);
idr.setUpdateTime(publishData.createTime);
idr.setVirtId(publishData.virtId);
- this.owner = publishData.uploader;
+ this.owner = repairUpload ? null : publishData.uploader;
this.image = idr;
this.machineDescription = ThriftUtil.unwrapByteBuffer(transferInfo.machineDescription);
this.masterTransferInfo = transferInfo;
this.versionSettings = new ImageVersionWrite(false);
+ initRepairUpload();
+ }
+
+ private void initRepairUpload() {
+ if (!isRepairUpload())
+ return;
+ if (getTmpFileName().exists() && getTmpFileName().length() > 0) {
+ try {
+ List<Boolean> statusList = DbImageBlock.getMissingStatusList(getVersionId());
+ if (!statusList.isEmpty()) {
+ getChunks().resumeFromStatusList(statusList, getTmpFileName().length());
+ for (int i = 0; i < 3; ++i) {
+ queueUnhashedChunk(false);
+ }
+ }
+ } catch (SQLException e) {
+ }
+ }
}
/**
@@ -148,6 +170,8 @@ public class IncomingDataTransfer extends IncomingTransferBase {
* @param data
*/
public boolean setVersionData(UserInfo user, ImageVersionWrite data) {
+ if (isRepairUpload())
+ return false;
synchronized (versionWrittenToDb) {
if (versionWrittenToDb.get()) {
return false;
@@ -170,8 +194,17 @@ public class IncomingDataTransfer extends IncomingTransferBase {
potentialFinishTime.set(System.currentTimeMillis());
// If owner is not set, this was a repair-transfer, which downloads directly to the existing target file.
// Nothing more to do in that case.
- if (isRepairUpload())
+ if (isRepairUpload()) {
+ try {
+ DbImage.markValid(true, false, DbImage.getLocalImageData(getVersionId()));
+ } catch (TNotFoundException e) {
+ LOGGER.warn("Apparently, the image " + getVersionId()
+ + " that was just repaired doesn't exist...");
+ } catch (SQLException e) {
+ }
return true;
+ }
+ // It's a fresh upload
LOGGER.info("Finalizing uploaded image " + image.imageName);
// Ready to go. First step: Rename temp file to something usable
String ext = "img";
@@ -291,7 +324,15 @@ public class IncomingDataTransfer extends IncomingTransferBase {
@Override
protected void chunkStatusChanged(FileChunk chunk) {
- // TODO Update in DB in case this is a repair upload
+ if (!isRepairUpload())
+ return;
+ ChunkStatus status = chunk.getStatus();
+ if (status == ChunkStatus.MISSING || status == ChunkStatus.COMPLETE) {
+ try {
+ DbImageBlock.asyncUpdate(getVersionId(), chunk);
+ } catch (InterruptedException e) {
+ }
+ }
}
}