diff options
author | Simon Rettberg | 2015-07-15 18:33:09 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-07-15 18:33:09 +0200 |
commit | f8e26464cf99ff402eda61d006308cd8adbcb0b0 (patch) | |
tree | b84e452af18f629668b918473003356ae04b4c0b /dozentenmodulserver/src/main/java/org | |
parent | [client] always retry thrift call automatically on first failure (diff) | |
download | tutor-module-f8e26464cf99ff402eda61d006308cd8adbcb0b0.tar.gz tutor-module-f8e26464cf99ff402eda61d006308cd8adbcb0b0.tar.xz tutor-module-f8e26464cf99ff402eda61d006308cd8adbcb0b0.zip |
[server] Fix SQL pooling issue, implement upload
Diffstat (limited to 'dozentenmodulserver/src/main/java/org')
5 files changed, 30 insertions, 12 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/MysqlConnection.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/MysqlConnection.java index 24aaf1e8..c17b7946 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/MysqlConnection.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/MysqlConnection.java @@ -51,11 +51,11 @@ public class MysqlConnection implements AutoCloseable { public void close() { if (hasPendingQueries) { LOGGER.warn("Mysql connection had uncommited queries on .close()"); - try { - rawConnection.rollback(); - } catch (SQLException e) { - LOGGER.warn("Rolling back uncommited queries failed!", e); - } + } + try { + rawConnection.rollback(); + } catch (SQLException e) { + LOGGER.warn("Rolling back uncommited queries failed!", e); } if (!openStatements.isEmpty()) { for (MysqlStatement statement : openStatements) { diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java index 3f392048..c46fc690 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java @@ -158,8 +158,12 @@ public class DbImage { stmt.setString("userid", user.userId); stmt.setString("imagebaseid", imageBaseId); ResultSet rs = stmt.executeQuery(); - if (!rs.next()) + if (!rs.next()) { + LOGGER.info("Image " + imageBaseId + " not found"); throw new TNotFoundException(); + } else { + LOGGER.info("Image " + imageBaseId + " found"); + } return resultSetToSummary(rs); } @@ -206,6 +210,7 @@ public class DbImage { stmt.setString("userid", user.userId); stmt.executeUpdate(); connection.commit(); + LOGGER.info("Created image '" + imageUuid + "'"); return imageUuid; } catch (SQLException e) { LOGGER.error("Query failed in DbImage.createImage()", e); 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 a2474587..ad2949aa 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 @@ -145,7 +145,7 @@ public class ActiveUpload { public void cancel() { // TODO Auto-generated method stub - + } /** diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java index c357c292..44746fe2 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java @@ -10,6 +10,7 @@ import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import org.apache.log4j.Logger; import org.openslx.bwlp.sat.util.Constants; import org.openslx.bwlp.sat.util.Formatter; import org.openslx.bwlp.thrift.iface.TTransferRejectedException; @@ -21,6 +22,8 @@ import org.openslx.filetransfer.Uploader; public class FileServer implements IncomingEvent { + private static final Logger LOGGER = Logger.getLogger(FileServer.class); + /** * Listener for incoming unencrypted connections */ @@ -69,7 +72,7 @@ public class FileServer implements IncomingEvent { } public String createNewUserUpload(UserInfo owner, long fileSize, List<ByteBuffer> sha1Sums) - throws TTransferRejectedException, FileNotFoundException { + throws TTransferRejectedException { Iterator<ActiveUpload> it = uploads.values().iterator(); int activeUploads = 0; while (it.hasNext()) { @@ -88,8 +91,15 @@ public class FileServer implements IncomingEvent { do { destinationFile = Formatter.getTempImageName(); } while (destinationFile.exists()); + destinationFile.getParentFile().mkdirs(); // TODO: Pass image - ActiveUpload upload = new ActiveUpload(owner, null, destinationFile, fileSize, sha1Sums); + ActiveUpload upload; + try { + upload = new ActiveUpload(owner, null, destinationFile, fileSize, sha1Sums); + } catch (FileNotFoundException e) { + LOGGER.error("Could not open destination file for writing", e); + throw new TTransferRejectedException("Destination file not writable!"); + } String key = UUID.randomUUID().toString(); uploads.put(key, upload); return key; diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java index 22a90de7..7f9f9bbc 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java @@ -68,9 +68,12 @@ public class ServerHandler implements SatelliteServer.Iface { @Override public TransferInformation requestImageVersionUpload(String userToken, String imageBaseId, long fileSize, - List<ByteBuffer> blockHashes) throws TTransferRejectedException, TAuthorizationException { - // TODO Auto-generated method stub - return null; + List<ByteBuffer> blockHashes) throws TTransferRejectedException, TAuthorizationException, + TInternalServerError, TNotFoundException { + UserInfo user = SessionManager.getOrFail(userToken); + User.canEditBaseImageOrFail(user, imageBaseId); + String transferId = fileServer.createNewUserUpload(user, fileSize, blockHashes); + return new TransferInformation(transferId, fileServer.getPlainPort(), fileServer.getSslPort()); } @Override |