summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/fileserv/ActiveUpload.java
diff options
context:
space:
mode:
authorSimon Rettberg2015-06-10 20:22:04 +0200
committerSimon Rettberg2015-06-10 20:22:04 +0200
commitd684cd4dbdadb11a0017556e802bdf3141336f2b (patch)
treed1f863957b2c0241b036fb9c82821e7f1df50023 /dozentenmodulserver/src/main/java/fileserv/ActiveUpload.java
parent[server] Compiling again, still lots of stubs (diff)
downloadtutor-module-d684cd4dbdadb11a0017556e802bdf3141336f2b.tar.gz
tutor-module-d684cd4dbdadb11a0017556e802bdf3141336f2b.tar.xz
tutor-module-d684cd4dbdadb11a0017556e802bdf3141336f2b.zip
[server] db stuff, new interface, ...
Diffstat (limited to 'dozentenmodulserver/src/main/java/fileserv/ActiveUpload.java')
-rw-r--r--dozentenmodulserver/src/main/java/fileserv/ActiveUpload.java60
1 files changed, 57 insertions, 3 deletions
diff --git a/dozentenmodulserver/src/main/java/fileserv/ActiveUpload.java b/dozentenmodulserver/src/main/java/fileserv/ActiveUpload.java
index 256f8b8d..334345f3 100644
--- a/dozentenmodulserver/src/main/java/fileserv/ActiveUpload.java
+++ b/dozentenmodulserver/src/main/java/fileserv/ActiveUpload.java
@@ -6,14 +6,21 @@ import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.util.List;
+import java.util.UUID;
import java.util.concurrent.ThreadPoolExecutor;
+import models.Configuration;
+
import org.apache.log4j.Logger;
+import org.openslx.bwlp.thrift.iface.ImageDetailsRead;
+import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.filetransfer.DataReceivedCallback;
import org.openslx.filetransfer.Downloader;
import org.openslx.filetransfer.FileRange;
import org.openslx.filetransfer.WantRangeCallback;
-import org.openslx.imagemaster.thrift.iface.UserInfo;
+
+import util.FileSystem;
+import util.Formatter;
public class ActiveUpload {
private static final Logger LOGGER = Logger.getLogger(ActiveUpload.class);
@@ -36,14 +43,20 @@ public class ActiveUpload {
*/
private final UserInfo owner;
+ /**
+ * Base image this upload is a new version for.
+ */
+ private final ImageDetailsRead image;
+
// TODO: Use HashList for verification
- public ActiveUpload(UserInfo owner, File destinationFile, long fileSize, List<ByteBuffer> sha1Sums)
- throws FileNotFoundException {
+ public ActiveUpload(UserInfo owner, ImageDetailsRead image, File destinationFile, long fileSize,
+ List<ByteBuffer> sha1Sums) throws FileNotFoundException {
this.destinationFile = destinationFile;
this.outFile = new RandomAccessFile(destinationFile, "rw");
this.chunks = new ChunkList(fileSize, sha1Sums);
this.owner = owner;
+ this.image = image;
this.fileSize = fileSize;
}
@@ -96,6 +109,47 @@ public class ActiveUpload {
return true;
}
+ private void finishUpload() {
+ File file = destinationFile;
+ // Ready to go. First step: Rename temp file to something usable
+ File destination = new File(file.getParent(), Formatter.vmName(owner, image.imageName));
+ // Sanity check: destination should be a sub directory of the vmStorePath
+ String relPath = FileSystem.getRelativePath(destination, Configuration.getVmStoreBasePath());
+ if (relPath == null) {
+ LOGGER.warn(destination.getAbsolutePath() + " is not a subdir of "
+ + Configuration.getVmStoreBasePath().getAbsolutePath());
+ // TODO: Update state to failed...
+ }
+
+ // Execute rename
+ boolean ret = false;
+ Exception renameException = null;
+ try {
+ ret = file.renameTo(destination);
+ } catch (Exception e) {
+ ret = false;
+ renameException = e;
+ }
+ if (!ret) {
+ // Rename failed :-(
+ LOGGER.warn(
+ "Could not rename '" + file.getAbsolutePath() + "' to '" + destination.getAbsolutePath()
+ + "'", renameException);
+ // TODO: Update state....
+ }
+
+ // Now insert meta data into DB
+
+ final String imageVersionId = UUID.randomUUID().toString();
+
+ // TODO: SQL magic, update state
+ }
+
+ public void cancel() {
+ // TODO Auto-generated method stub
+
+ }
+
/**
* Get user owning this upload. Can be null in special cases.
*