summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver
diff options
context:
space:
mode:
authorSimon Rettberg2015-08-27 18:08:48 +0200
committerSimon Rettberg2015-08-27 18:08:48 +0200
commitac15c2a1cfe0fc0519b5577e7478c25500fe45c3 (patch)
treecdc93ee180fe17220c8a193fff73238e9ddcc651 /dozentenmodulserver
parentMerge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1 (diff)
downloadtutor-module-ac15c2a1cfe0fc0519b5577e7478c25500fe45c3.tar.gz
tutor-module-ac15c2a1cfe0fc0519b5577e7478c25500fe45c3.tar.xz
tutor-module-ac15c2a1cfe0fc0519b5577e7478c25500fe45c3.zip
[*] Thrift API changes
Diffstat (limited to 'dozentenmodulserver')
-rw-r--r--dozentenmodulserver/setup/sat-01-schema.sql1
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbUser.java19
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/models/LocalUser.java8
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/permissions/User.java50
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java140
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/SessionManager.java22
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/FileSystem.java22
7 files changed, 167 insertions, 95 deletions
diff --git a/dozentenmodulserver/setup/sat-01-schema.sql b/dozentenmodulserver/setup/sat-01-schema.sql
index 6c517530..dab97282 100644
--- a/dozentenmodulserver/setup/sat-01-schema.sql
+++ b/dozentenmodulserver/setup/sat-01-schema.sql
@@ -173,6 +173,7 @@ CREATE TABLE IF NOT EXISTS `user` (
`lastlogin` bigint(20) DEFAULT NULL,
`canlogin` tinyint(1) NOT NULL DEFAULT '0',
`issuperuser` tinyint(1) NOT NULL DEFAULT '0',
+ `emailnotifications` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`userid`),
KEY `fk_user_1_idx` (`organizationid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbUser.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbUser.java
index 4552a1d7..c0e96296 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbUser.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbUser.java
@@ -13,6 +13,7 @@ import org.openslx.bwlp.sat.database.MysqlConnection;
import org.openslx.bwlp.sat.database.MysqlStatement;
import org.openslx.bwlp.sat.database.Paginator;
import org.openslx.bwlp.sat.database.models.LocalUser;
+import org.openslx.bwlp.thrift.iface.SatelliteUserConfig;
import org.openslx.bwlp.thrift.iface.TNotFoundException;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.util.TimeoutHashMap;
@@ -85,20 +86,34 @@ public class DbUser {
*/
public static LocalUser getLocalData(UserInfo user) throws SQLException {
try (MysqlConnection connection = Database.getConnection()) {
- MysqlStatement stmt = connection.prepareStatement("SELECT lastlogin, canlogin, issuperuser"
+ MysqlStatement stmt = connection.prepareStatement("SELECT lastlogin, canlogin, issuperuser, emailnotifications"
+ " FROM user WHERE userid = :userid LIMIT 1");
stmt.setString("userid", user.userId);
ResultSet rs = stmt.executeQuery();
if (!rs.next())
return null;
return new LocalUser(rs.getLong("lastlogin"), rs.getBoolean("canlogin"),
- rs.getBoolean("issuperuser"));
+ rs.getBoolean("issuperuser"), rs.getBoolean("emailnotifications"));
} catch (SQLException e) {
LOGGER.error("Query failed in DbUser.getLocalData()", e);
throw e;
}
}
+ public static void writeUserConfig(UserInfo user, SatelliteUserConfig config) throws SQLException {
+ try (MysqlConnection connection = Database.getConnection()) {
+ MysqlStatement stmt = connection.prepareStatement("UPDATE user SET"
+ + " emailnotifications = :emailnotifications WHERE userid = :userid");
+ stmt.setString("userid", user.userId);
+ stmt.setBoolean("emailnotifications", config.emailNotifications);
+ stmt.executeUpdate();
+ connection.commit();
+ } catch (SQLException e) {
+ LOGGER.error("Query failed in DbUser.writeUserConfig()", e);
+ throw e;
+ }
+ }
+
/**
* Insert given user into db (if not already existent), otherwise just
* update the "lastlogin" field.
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/models/LocalUser.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/models/LocalUser.java
index e0040a96..e0ea342e 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/models/LocalUser.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/models/LocalUser.java
@@ -1,15 +1,17 @@
package org.openslx.bwlp.sat.database.models;
public class LocalUser {
-
+
public final long lastLogin;
public final boolean canLogin;
public final boolean isSuperUser;
-
- public LocalUser(long lastLogin, boolean canLogin, boolean isSuperUser) {
+ public final boolean emailNotifications;
+
+ public LocalUser(long lastLogin, boolean canLogin, boolean isSuperUser, boolean emailNotifications) {
this.lastLogin = lastLogin;
this.canLogin = canLogin;
this.isSuperUser = isSuperUser;
+ this.emailNotifications = emailNotifications;
}
}
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/permissions/User.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/permissions/User.java
index e2c86d80..29fa5613 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/permissions/User.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/permissions/User.java
@@ -18,7 +18,7 @@ import org.openslx.bwlp.thrift.iface.LectureSummary;
import org.openslx.bwlp.thrift.iface.Role;
import org.openslx.bwlp.thrift.iface.ShareMode;
import org.openslx.bwlp.thrift.iface.TAuthorizationException;
-import org.openslx.bwlp.thrift.iface.TInternalServerError;
+import org.openslx.bwlp.thrift.iface.TInvocationException;
import org.openslx.bwlp.thrift.iface.TNotFoundException;
import org.openslx.bwlp.thrift.iface.UserInfo;
@@ -103,10 +103,10 @@ public class User {
* @param user
* @param imageBaseId
* @throws TNotFoundException
- * @throws TInternalServerError
+ * @throws TInvocationException
* @throws TAuthorizationException
*/
- public static void canEditBaseImageOrFail(UserInfo user, String imageBaseId) throws TInternalServerError,
+ public static void canEditBaseImageOrFail(UserInfo user, String imageBaseId) throws TInvocationException,
TNotFoundException, TAuthorizationException {
ImageSummaryRead image = getImageFromBaseId(user, imageBaseId);
if (!image.userPermissions.edit) {
@@ -123,15 +123,15 @@ public class User {
* @param user
* @param imageVersionId
* @throws TNotFoundException
- * @throws TInternalServerError
+ * @throws TInvocationException
* @throws TAuthorizationException
*/
public static void canEditImageVersionOrFail(UserInfo user, String imageVersionId)
- throws TInternalServerError, TNotFoundException, TAuthorizationException {
+ throws TInvocationException, TNotFoundException, TAuthorizationException {
try {
canEditBaseImageOrFail(user, DbImage.getBaseIdForVersionId(imageVersionId));
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@@ -144,15 +144,15 @@ public class User {
* @param imageVersionId
* @throws TAuthorizationException
* @throws TNotFoundException
- * @throws TInternalServerError
+ * @throws TInvocationException
*/
public static void canDeleteImageVersionOrFail(UserInfo user, String imageVersionId)
- throws TInternalServerError, TNotFoundException, TAuthorizationException {
+ throws TInvocationException, TNotFoundException, TAuthorizationException {
ImageDetailsRead imageDetails;
try {
imageDetails = DbImage.getImageDetails(user, DbImage.getBaseIdForVersionId(imageVersionId));
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
// Do not allow deleting remote images if share mode is set to "auto download" and
// the version to delete is the latest
@@ -184,12 +184,12 @@ public class User {
}
public static void canDownloadImageVersionOrFail(UserInfo user, String imageVersionId)
- throws TAuthorizationException, TNotFoundException, TInternalServerError {
+ throws TAuthorizationException, TNotFoundException, TInvocationException {
ImageDetailsRead image;
try {
image = DbImage.getImageDetails(user, DbImage.getBaseIdForVersionId(imageVersionId));
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
if (image.userPermissions.download) {
if (isTutor(user))
@@ -223,11 +223,11 @@ public class User {
* @param user
* @param imageBaseId
* @return
- * @throws TInternalServerError
+ * @throws TInvocationException
* @throws TNotFoundException
*/
public static boolean canEditImagePermissions(UserInfo user, String imageBaseId)
- throws TInternalServerError, TNotFoundException {
+ throws TInvocationException, TNotFoundException {
ImageSummaryRead image = getImageFromBaseId(user, imageBaseId);
return image.userPermissions.admin;
}
@@ -238,19 +238,19 @@ public class User {
*
* @param user
* @param imageBaseId
- * @throws TInternalServerError
+ * @throws TInvocationException
* @throws TNotFoundException
* @throws TAuthorizationException if permission is not granted.
*/
public static void canEditImagePermissionsOrFail(UserInfo user, String imageBaseId)
- throws TAuthorizationException, TInternalServerError, TNotFoundException {
+ throws TAuthorizationException, TInvocationException, TNotFoundException {
if (!canEditImagePermissions(user, imageBaseId))
throw new TAuthorizationException(AuthorizationError.NO_PERMISSION,
"No permission to edit this image's permissions");
}
public static void canChangeImageOwnerOrFail(UserInfo user, String imageBaseId)
- throws TAuthorizationException, TInternalServerError, TNotFoundException {
+ throws TAuthorizationException, TInvocationException, TNotFoundException {
// TODO: Who should be allowed to change the owner? Any admin, or just the owner?
// Currently it's every admin, but this is open for discussion
ImageSummaryRead image = getImageFromBaseId(user, imageBaseId);
@@ -260,7 +260,7 @@ public class User {
}
}
- public static void canEditLectureOrFail(UserInfo user, String lectureId) throws TInternalServerError,
+ public static void canEditLectureOrFail(UserInfo user, String lectureId) throws TInvocationException,
TNotFoundException, TAuthorizationException {
LectureSummary lecture = getLectureFromId(user, lectureId);
if (!lecture.userPermissions.edit) {
@@ -270,13 +270,13 @@ public class User {
}
public static boolean canEditLecturePermissions(UserInfo user, String lectureId)
- throws TNotFoundException, TInternalServerError {
+ throws TNotFoundException, TInvocationException {
LectureSummary lecture = getLectureFromId(user, lectureId);
return lecture.userPermissions.admin;
}
public static void canEditLecturePermissionsOrFail(UserInfo user, String lectureId)
- throws TAuthorizationException, TNotFoundException, TInternalServerError {
+ throws TAuthorizationException, TNotFoundException, TInvocationException {
if (!canEditLecturePermissions(user, lectureId)) {
throw new TAuthorizationException(AuthorizationError.NO_PERMISSION,
"No permission to edit permissions");
@@ -284,7 +284,7 @@ public class User {
}
public static void canChangeLectureOwnerOrFail(UserInfo user, String lectureId)
- throws TAuthorizationException, TNotFoundException, TInternalServerError {
+ throws TAuthorizationException, TNotFoundException, TInvocationException {
// TODO: Who should be allowed to change the owner? Any admin, or just the owner?
// Currently it's every admin, but this is open for discussion
LectureSummary lecture = getLectureFromId(user, lectureId);
@@ -317,7 +317,7 @@ public class User {
}
public static void canDeleteLectureOrFail(UserInfo user, String lectureId)
- throws TAuthorizationException, TInternalServerError, TNotFoundException {
+ throws TAuthorizationException, TInvocationException, TNotFoundException {
LectureSummary lecture = getLectureFromId(user, lectureId);
if (!lecture.userPermissions.admin) {
throw new TAuthorizationException(AuthorizationError.NO_PERMISSION,
@@ -427,20 +427,20 @@ public class User {
}
private static ImageSummaryRead getImageFromBaseId(UserInfo user, String imageBaseId)
- throws TNotFoundException, TInternalServerError {
+ throws TNotFoundException, TInvocationException {
try {
return DbImage.getImageSummary(user, imageBaseId);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
private static LectureSummary getLectureFromId(UserInfo user, String lectureId)
- throws TNotFoundException, TInternalServerError {
+ throws TNotFoundException, TInvocationException {
try {
return DbLecture.getLectureSummary(user, lectureId);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
}
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 4656519e..8fe48f9f 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
@@ -14,6 +14,7 @@ import org.openslx.bwlp.sat.database.mappers.DbImagePermissions;
import org.openslx.bwlp.sat.database.mappers.DbLecture;
import org.openslx.bwlp.sat.database.mappers.DbLecturePermissions;
import org.openslx.bwlp.sat.database.mappers.DbUser;
+import org.openslx.bwlp.sat.database.models.LocalUser;
import org.openslx.bwlp.sat.fileserv.ActiveDownload;
import org.openslx.bwlp.sat.fileserv.ActiveUpload;
import org.openslx.bwlp.sat.fileserv.FileServer;
@@ -21,16 +22,17 @@ import org.openslx.bwlp.sat.permissions.User;
import org.openslx.bwlp.sat.thrift.cache.OperatingSystemList;
import org.openslx.bwlp.sat.thrift.cache.OrganizationList;
import org.openslx.bwlp.sat.thrift.cache.VirtualizerList;
+import org.openslx.bwlp.sat.util.FileSystem;
import org.openslx.bwlp.sat.util.Sanitizer;
import org.openslx.bwlp.sat.util.Util;
import org.openslx.bwlp.thrift.iface.AuthorizationError;
import org.openslx.bwlp.thrift.iface.ImageBaseWrite;
-import org.openslx.bwlp.thrift.iface.ImageDataError;
import org.openslx.bwlp.thrift.iface.ImageDetailsRead;
import org.openslx.bwlp.thrift.iface.ImagePermissions;
import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
import org.openslx.bwlp.thrift.iface.ImageVersionDetails;
import org.openslx.bwlp.thrift.iface.ImageVersionWrite;
+import org.openslx.bwlp.thrift.iface.InvocationError;
import org.openslx.bwlp.thrift.iface.LecturePermissions;
import org.openslx.bwlp.thrift.iface.LectureRead;
import org.openslx.bwlp.thrift.iface.LectureSummary;
@@ -39,12 +41,13 @@ import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.bwlp.thrift.iface.Organization;
import org.openslx.bwlp.thrift.iface.SatelliteConfig;
import org.openslx.bwlp.thrift.iface.SatelliteServer;
+import org.openslx.bwlp.thrift.iface.SatelliteStatus;
+import org.openslx.bwlp.thrift.iface.SatelliteUserConfig;
import org.openslx.bwlp.thrift.iface.ShareMode;
import org.openslx.bwlp.thrift.iface.TAuthorizationException;
-import org.openslx.bwlp.thrift.iface.TImageDataException;
-import org.openslx.bwlp.thrift.iface.TInternalServerError;
import org.openslx.bwlp.thrift.iface.TInvalidDateParam;
import org.openslx.bwlp.thrift.iface.TInvalidTokenException;
+import org.openslx.bwlp.thrift.iface.TInvocationException;
import org.openslx.bwlp.thrift.iface.TNotFoundException;
import org.openslx.bwlp.thrift.iface.TTransferRejectedException;
import org.openslx.bwlp.thrift.iface.TransferInformation;
@@ -89,14 +92,14 @@ public class ServerHandler implements SatelliteServer.Iface {
@Override
public TransferInformation requestImageVersionUpload(String userToken, String imageBaseId, long fileSize,
List<ByteBuffer> blockHashes, ByteBuffer machineDescription) throws TTransferRejectedException,
- TAuthorizationException, TInternalServerError, TNotFoundException, TException {
+ TAuthorizationException, TInvocationException, TNotFoundException, TException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canEditBaseImageOrFail(user, imageBaseId);
ImageDetailsRead image;
try {
image = DbImage.getImageDetails(user, imageBaseId);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
// Unwrap machine description
byte[] mDesc = null;
@@ -122,7 +125,7 @@ public class ServerHandler implements SatelliteServer.Iface {
@Override
public ByteBuffer getMachineDescription(String userToken, String imageVersionId)
- throws TAuthorizationException, TInternalServerError, TNotFoundException, TException {
+ throws TAuthorizationException, TInvocationException, TNotFoundException, TException {
// TODO Auto-generated method stub
return null;
}
@@ -145,7 +148,7 @@ public class ServerHandler implements SatelliteServer.Iface {
@Override
public TransferInformation requestDownload(String userToken, String imageVersionId)
- throws TAuthorizationException, TInternalServerError, TNotFoundException,
+ throws TAuthorizationException, TInvocationException, TNotFoundException,
TTransferRejectedException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canDownloadImageVersionOrFail(user, imageVersionId);
@@ -153,7 +156,7 @@ public class ServerHandler implements SatelliteServer.Iface {
try {
transfer = fileServer.createNewUserDownload(DbImage.getLocalImageData(imageVersionId));
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
return new TransferInformation(transfer.getId(), fileServer.getPlainPort(), fileServer.getSslPort());
}
@@ -170,12 +173,12 @@ public class ServerHandler implements SatelliteServer.Iface {
*/
@Override
- public void isAuthenticated(String userToken) throws TAuthorizationException, TInternalServerError {
+ public void isAuthenticated(String userToken) throws TAuthorizationException, TInvocationException {
SessionManager.ensureAuthenticated(userToken);
}
@Override
- public WhoamiInfo whoami(String userToken) throws TAuthorizationException, TInternalServerError {
+ public WhoamiInfo whoami(String userToken) throws TAuthorizationException, TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
return new WhoamiInfo(user, User.isSuperUser(user), User.canListImages(user));
}
@@ -204,62 +207,91 @@ public class ServerHandler implements SatelliteServer.Iface {
return OrganizationList.get();
}
+ @Override
+ public SatelliteStatus getStatus() {
+ return new SatelliteStatus(FileSystem.getAvailableStorageBytes(), Util.unixTime());
+ }
+
/*
* Everything below required at least a valid session
*/
@Override
+ public SatelliteUserConfig getUserConfig(String userToken) throws TAuthorizationException,
+ TInvocationException {
+ UserInfo user = SessionManager.getOrFail(userToken);
+ LocalUser localData;
+ try {
+ localData = DbUser.getLocalData(user);
+ } catch (SQLException e) {
+ throw new TInvocationException();
+ }
+ return new SatelliteUserConfig(localData != null && localData.emailNotifications);
+ }
+
+ @Override
+ public void setUserConfig(String userToken, SatelliteUserConfig config) throws TAuthorizationException,
+ TInvocationException {
+ UserInfo user = SessionManager.getOrFail(userToken);
+ try {
+ DbUser.writeUserConfig(user, config);
+ } catch (SQLException e) {
+ throw new TInvocationException();
+ }
+ }
+
+ @Override
public List<ImageSummaryRead> getImageList(String userToken, List<String> tagSearch, int page)
- throws TAuthorizationException, TInternalServerError {
+ throws TAuthorizationException, TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canListImagesOrFail(user);
try {
return DbImage.getAllVisible(user, tagSearch, page);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public ImageDetailsRead getImageDetails(String userToken, String imageBaseId)
- throws TAuthorizationException, TNotFoundException, TInternalServerError {
+ throws TAuthorizationException, TNotFoundException, TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canSeeImageDetailsOrFail(user);
try {
return DbImage.getImageDetails(user, imageBaseId);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public String createImage(String userToken, String imageName) throws TAuthorizationException,
- TImageDataException, TInternalServerError {
+ TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canCreateImageOrFail(user);
if (!Util.isPrintable(imageName) || Util.isEmptyString(imageName))
- throw new TImageDataException(ImageDataError.INVALID_DATA, "Invalid or empty name");
+ throw new TInvocationException(InvocationError.INVALID_DATA, "Invalid or empty name");
try {
return DbImage.createImage(user, imageName);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void updateImageBase(String userToken, String imageBaseId, ImageBaseWrite newData)
- throws TAuthorizationException, TInternalServerError, TNotFoundException, TImageDataException {
+ throws TAuthorizationException, TInvocationException, TNotFoundException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canEditBaseImageOrFail(user, imageBaseId);
// Check image name for invalid characters
if (!Util.isPrintable(newData.imageName) || Util.isEmptyString(newData.imageName))
- throw new TImageDataException(ImageDataError.INVALID_DATA, "Invalid or empty name");
+ throw new TInvocationException(InvocationError.INVALID_DATA, "Invalid or empty name");
// Check if image is marked for replication. If so, only allow changing the syncmode to FROZEN/DOWNLOAD
try {
ImageSummaryRead imageSummary = DbImage.getImageSummary(user, imageBaseId);
if (imageSummary.shareMode == ShareMode.DOWNLOAD || imageSummary.shareMode == ShareMode.FROZEN) {
if (newData.shareMode != ShareMode.DOWNLOAD && newData.shareMode != ShareMode.FROZEN) {
- throw new TImageDataException(ImageDataError.INVALID_SHARE_MODE,
+ throw new TInvocationException(InvocationError.INVALID_SHARE_MODE,
"Cannot change share mode from remote to local");
} else {
// Share mode is valid and changed, but ignore all other fields
@@ -269,7 +301,7 @@ public class ServerHandler implements SatelliteServer.Iface {
} else {
// Likewise, if share mode is local or publish, don't allow changing to FROZEN/DOWNLOAD
if (newData.shareMode != ShareMode.LOCAL && newData.shareMode != ShareMode.PUBLISH) {
- throw new TImageDataException(ImageDataError.INVALID_SHARE_MODE,
+ throw new TInvocationException(InvocationError.INVALID_SHARE_MODE,
"Cannot change share mode from local to remote");
}
}
@@ -278,13 +310,13 @@ public class ServerHandler implements SatelliteServer.Iface {
// The update routine will make sure only the super user can change the template flag
DbImage.updateImageMetadata(user, imageBaseId, newData);
} catch (SQLException e1) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void updateImageVersion(String userToken, String imageVersionId, ImageVersionWrite image)
- throws TAuthorizationException, TInternalServerError, TNotFoundException {
+ throws TAuthorizationException, TInvocationException, TNotFoundException {
UserInfo user = SessionManager.getOrFail(userToken);
// Special case: Version is still being uploaded, so there's no entry yet - remember for later
ActiveUpload upload = fileServer.getUploadByToken(imageVersionId);
@@ -303,31 +335,31 @@ public class ServerHandler implements SatelliteServer.Iface {
}
DbImage.updateImageVersion(user, imageVersionId, image);
} catch (SQLException e1) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void deleteImageVersion(String userToken, String imageVersionId) throws TAuthorizationException,
- TNotFoundException, TInternalServerError {
+ TNotFoundException, TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canDeleteImageVersionOrFail(user, imageVersionId);
try {
DbImage.markForDeletion(imageVersionId);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void deleteImageBase(String userToken, String imageBaseId) throws TAuthorizationException,
- TNotFoundException, TInternalServerError {
+ TNotFoundException, TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
ImageDetailsRead imageDetails;
try {
imageDetails = DbImage.getImageDetails(user, imageBaseId);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
User.canDeleteImageOrFail(imageDetails);
String[] ids = new String[imageDetails.versions.size()];
@@ -345,31 +377,31 @@ public class ServerHandler implements SatelliteServer.Iface {
@Override
public void writeImagePermissions(String userToken, String imageBaseId,
Map<String, ImagePermissions> permissions) throws TAuthorizationException, TNotFoundException,
- TInternalServerError {
+ TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canEditImagePermissionsOrFail(user, imageBaseId);
try {
DbImagePermissions.writeForImageBase(imageBaseId, permissions);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public Map<String, ImagePermissions> getImagePermissions(String userToken, String imageBaseId)
- throws TAuthorizationException, TNotFoundException, TInternalServerError {
+ throws TAuthorizationException, TNotFoundException, TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
boolean adminOnly = !User.canEditImagePermissions(user, imageBaseId);
try {
return DbImagePermissions.getForImageBase(imageBaseId, adminOnly);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void setImageOwner(String userToken, String imageBaseId, String newOwnerId)
- throws TAuthorizationException, TNotFoundException, TInternalServerError, TException {
+ throws TAuthorizationException, TNotFoundException, TInvocationException, TException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canChangeImageOwnerOrFail(user, imageBaseId);
try {
@@ -380,13 +412,13 @@ public class ServerHandler implements SatelliteServer.Iface {
}
DbImage.setImageOwner(imageBaseId, newOwnerId, user);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void setImageVersionExpiry(String userToken, String imageBaseId, long expireTime)
- throws TAuthorizationException, TNotFoundException, TInternalServerError, TInvalidDateParam,
+ throws TAuthorizationException, TNotFoundException, TInvocationException, TInvalidDateParam,
TException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canChangeImageExpireDateOrFail(user);
@@ -394,113 +426,113 @@ public class ServerHandler implements SatelliteServer.Iface {
@Override
public String createLecture(String userToken, LectureWrite lecture) throws TAuthorizationException,
- TInternalServerError, TInvalidDateParam {
+ TInvocationException, TInvalidDateParam {
if (lecture == null || lecture.defaultPermissions == null)
- throw new TInternalServerError(); // TODO Own exception for this
+ throw new TInvocationException(); // TODO Own exception for this
UserInfo user = SessionManager.getOrFail(userToken);
User.canCreateLectureOrFail(user);
Sanitizer.handleLectureDates(lecture);
try {
return DbLecture.create(user, lecture);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void updateLecture(String userToken, String lectureId, LectureWrite lecture)
- throws TAuthorizationException, TNotFoundException, TInternalServerError, TInvalidDateParam {
+ throws TAuthorizationException, TNotFoundException, TInvocationException, TInvalidDateParam {
UserInfo user = SessionManager.getOrFail(userToken);
User.canEditLectureOrFail(user, lectureId);
Sanitizer.handleLectureDates(lecture);
try {
DbLecture.update(user, lectureId, lecture);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public List<LectureSummary> getLectureList(String userToken, int page) throws TAuthorizationException,
- TInternalServerError {
+ TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
try {
// If user is student, getAll() will only return lectures where the current linked image is not restricted
return DbLecture.getAll(user, page);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public LectureRead getLectureDetails(String userToken, String lectureId) throws TAuthorizationException,
- TNotFoundException, TInternalServerError {
+ TNotFoundException, TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canSeeLectureDetailsOrFail(user);
try {
return DbLecture.getLectureDetails(user, lectureId);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void deleteLecture(String userToken, String lectureId) throws TAuthorizationException,
- TNotFoundException, TInternalServerError {
+ TNotFoundException, TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canDeleteLectureOrFail(user, lectureId);
try {
if (!DbLecture.delete(lectureId))
throw new TNotFoundException();
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void writeLecturePermissions(String userToken, String lectureId,
Map<String, LecturePermissions> permissions) throws TAuthorizationException, TNotFoundException,
- TInternalServerError {
+ TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canEditLecturePermissionsOrFail(user, lectureId);
try {
DbLecturePermissions.writeForLecture(lectureId, permissions);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public Map<String, LecturePermissions> getLecturePermissions(String userToken, String lectureId)
- throws TAuthorizationException, TNotFoundException, TInternalServerError {
+ throws TAuthorizationException, TNotFoundException, TInvocationException {
UserInfo user = SessionManager.getOrFail(userToken);
boolean adminOnly = !User.canEditLecturePermissions(user, lectureId);
try {
return DbLecturePermissions.getForLecture(lectureId, adminOnly);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public void setLectureOwner(String userToken, String lectureId, String newOwnerId)
- throws TAuthorizationException, TNotFoundException, TInternalServerError, TException {
+ throws TAuthorizationException, TNotFoundException, TInvocationException, TException {
UserInfo user = SessionManager.getOrFail(userToken);
User.canChangeLectureOwnerOrFail(user, lectureId);
try {
DbLecture.setOwner(user, lectureId, newOwnerId);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
@Override
public List<UserInfo> getUserList(String userToken, int page) throws TAuthorizationException,
- TInternalServerError {
+ TInvocationException {
try {
return DbUser.getAll(page);
} catch (SQLException e) {
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/SessionManager.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/SessionManager.java
index 48876233..f9175e98 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/SessionManager.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/SessionManager.java
@@ -12,8 +12,8 @@ import org.openslx.bwlp.sat.permissions.User;
import org.openslx.bwlp.thrift.iface.AuthorizationError;
import org.openslx.bwlp.thrift.iface.Role;
import org.openslx.bwlp.thrift.iface.TAuthorizationException;
-import org.openslx.bwlp.thrift.iface.TInternalServerError;
import org.openslx.bwlp.thrift.iface.TInvalidTokenException;
+import org.openslx.bwlp.thrift.iface.TInvocationException;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.thrifthelper.ThriftManager;
import org.openslx.util.QuickTimer;
@@ -71,9 +71,9 @@ public class SessionManager {
* @return UserInfo for the matching user
* @throws TAuthorizationException if the token is not known or the session
* expired
- * @throws TInternalServerError
+ * @throws TInvocationException
*/
- public static UserInfo getOrFail(String token) throws TAuthorizationException, TInternalServerError {
+ public static UserInfo getOrFail(String token) throws TAuthorizationException, TInvocationException {
UserInfo ui = getInternal(token);
if (ui != null)
return ui;
@@ -87,9 +87,9 @@ public class SessionManager {
*
* @param token Token in question
* @throws TAuthorizationException
- * @throws TInternalServerError
+ * @throws TInvocationException
*/
- public static void ensureAuthenticated(String token) throws TAuthorizationException, TInternalServerError {
+ public static void ensureAuthenticated(String token) throws TAuthorizationException, TInvocationException {
getInternal(token);
}
@@ -103,12 +103,12 @@ public class SessionManager {
public static UserInfo get(String token) {
try {
return getInternal(token);
- } catch (TAuthorizationException | TInternalServerError e) {
+ } catch (TAuthorizationException | TInvocationException e) {
return null;
}
}
- private static UserInfo getInternal(String token) throws TAuthorizationException, TInternalServerError {
+ private static UserInfo getInternal(String token) throws TAuthorizationException, TInvocationException {
Entry e = tokenManager.get(token);
if (e == null) {
LOGGER.info("Cache miss for token " + token + ", asking master");
@@ -140,9 +140,9 @@ public class SessionManager {
* @return
* @throws TAuthorizationException if user is not allowed to use this
* satellite, this exception contains the reason
- * @throws TInternalServerError if something unexpected fails
+ * @throws TInvocationException if something unexpected fails
*/
- private static UserInfo getRemote(String token) throws TAuthorizationException, TInternalServerError {
+ private static UserInfo getRemote(String token) throws TAuthorizationException, TInvocationException {
UserInfo ui = null;
try {
ui = ThriftManager.getMasterClient().getUserFromToken(token);
@@ -153,7 +153,7 @@ public class SessionManager {
} catch (Exception e) {
LOGGER.warn("Could not reach master server to query for user token (" + token + ") of a client!",
e);
- throw new TInternalServerError();
+ throw new TInvocationException();
}
LOGGER.info("Got user " + ui.userId + " for token " + token);
// TODO XXX HACK: Remove this once master server supplies role
@@ -194,7 +194,7 @@ public class SessionManager {
DbUser.writeUserOnLogin(ui);
} catch (SQLException e) {
LOGGER.info("User " + ui.userId + " cannot be written to DB - rejecting.");
- throw new TInternalServerError();
+ throw new TInvocationException();
}
}
tokenManager.put(token, new Entry(ui));
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/FileSystem.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/FileSystem.java
index 42f1056c..443b44b4 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/FileSystem.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/FileSystem.java
@@ -132,4 +132,26 @@ public class FileSystem {
return new File(Configuration.getVmStoreBasePath(), rel);
}
+ private static long lastStorageFailLog = 0;
+
+ /**
+ * Query how much space is left in the vmstore directory.
+ *
+ * @return free space in vmstore directory, in bytes, or -1 on error
+ */
+ public static long getAvailableStorageBytes() {
+ if (!isStorageMounted())
+ return -1;
+ try {
+ return Configuration.getVmStoreProdPath().getUsableSpace();
+ } catch (Exception e) {
+ long now = System.currentTimeMillis();
+ if (now - lastStorageFailLog > 60000) {
+ lastStorageFailLog = now;
+ LOGGER.warn("Could not determine free space of vmstore", e);
+ }
+ return -1;
+ }
+ }
+
}