diff options
author | Simon Rettberg | 2015-07-23 13:49:48 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-07-23 13:49:48 +0200 |
commit | 411eb5251e4d93e206f2b2847d856ded4240e84a (patch) | |
tree | 90f698a08cd5ced9256949a9176b4d0ebb93561c /dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java | |
parent | Merge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1 (diff) | |
download | tutor-module-411eb5251e4d93e206f2b2847d856ded4240e84a.tar.gz tutor-module-411eb5251e4d93e206f2b2847d856ded4240e84a.tar.xz tutor-module-411eb5251e4d93e206f2b2847d856ded4240e84a.zip |
[server] Adapt to RPC changes
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java')
-rw-r--r-- | dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java index 08d0d30f..92c2b2d7 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java @@ -8,6 +8,7 @@ import java.nio.ByteBuffer; import java.sql.SQLException; import java.util.List; import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.atomic.AtomicBoolean; import org.apache.log4j.Logger; import org.openslx.bwlp.sat.database.mappers.DbImage; @@ -68,10 +69,21 @@ public class ActiveUpload { */ private final String uploadId; + /** + * Description of this VM - binary dump of e.g. the *.vmx file (VMware) + */ + private final byte[] machineDescription; + + /** + * Indicated whether the version information was written to db already. + * Disallow setVersionData in that case. + */ + private final AtomicBoolean versionWrittenToDb = new AtomicBoolean(); + // TODO: Use HashList for verification public ActiveUpload(String uploadId, UserInfo owner, ImageDetailsRead image, File destinationFile, - long fileSize, List<ByteBuffer> sha1Sums) throws FileNotFoundException { + long fileSize, List<ByteBuffer> sha1Sums, byte[] machineDescription) throws FileNotFoundException { this.destinationFile = destinationFile; this.outFile = new RandomAccessFile(destinationFile, "rw"); this.chunks = new ChunkList(fileSize, sha1Sums); @@ -79,15 +91,27 @@ public class ActiveUpload { this.image = image; this.fileSize = fileSize; this.uploadId = uploadId; + this.machineDescription = machineDescription; } /** * Set meta data for this image version. * + * @param user + * * @param data */ - public synchronized void setVersionData(ImageVersionWrite data) { - versionSettings = data; + public boolean setVersionData(UserInfo user, ImageVersionWrite data) { + synchronized (versionWrittenToDb) { + if (versionWrittenToDb.get()) { + return false; + } + if (!user.userId.equals(owner.userId)) { + return false; + } + versionSettings = data; + return true; + } } /** @@ -155,9 +179,9 @@ public class ActiveUpload { * Called when the upload finished. */ private synchronized void finishUpload() { - if (state != TransferState.WORKING) - return; synchronized (outFile) { + if (state != TransferState.WORKING) + return; Util.safeClose(outFile); state = TransferState.FINISHED; } @@ -193,8 +217,11 @@ public class ActiveUpload { // Now insert meta data into DB try { - DbImage.createImageVersion(image.imageBaseId, uploadId, owner, fileSize, relPath, - versionSettings, chunks); + synchronized (versionWrittenToDb) { + DbImage.createImageVersion(image.imageBaseId, uploadId, owner, fileSize, relPath, + versionSettings, chunks, machineDescription); + versionWrittenToDb.set(true); + } } catch (SQLException e) { LOGGER.error("Error finishing upload: Inserting version to DB failed", e); state = TransferState.ERROR; @@ -271,10 +298,14 @@ public class ActiveUpload { } } - public TransferStatus getStatus() { + public synchronized TransferStatus getStatus() { return new TransferStatus(chunks.getStatusArray(), state); } + public String getId() { + return uploadId; + } + // TODO: Clean up old stale uploads } |