From d684cd4dbdadb11a0017556e802bdf3141336f2b Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 10 Jun 2015 20:22:04 +0200 Subject: [server] db stuff, new interface, ... --- .../src/main/java/fileserv/ActiveUpload.java | 60 ++++++++++++++++++++-- 1 file changed, 57 insertions(+), 3 deletions(-) (limited to 'dozentenmodulserver/src/main/java/fileserv/ActiveUpload.java') 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 sha1Sums) - throws FileNotFoundException { + public ActiveUpload(UserInfo owner, ImageDetailsRead image, File destinationFile, long fileSize, + List 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. * -- cgit v1.2.3-55-g7522