summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java
diff options
context:
space:
mode:
authorJonathan Bauer2016-08-31 16:54:59 +0200
committerJonathan Bauer2016-08-31 16:54:59 +0200
commit26cd5699373dbe35ee24700189e8a3e580ae6243 (patch)
tree0389541c704fbfe05aeb514365e4643f84bbfa20 /dozentenmodulserver/src/main/java
parent[client] Reset filter when hiding lecture list if filtered by linked image (diff)
downloadtutor-module-26cd5699373dbe35ee24700189e8a3e580ae6243.tar.gz
tutor-module-26cd5699373dbe35ee24700189e8a3e580ae6243.tar.xz
tutor-module-26cd5699373dbe35ee24700189e8a3e580ae6243.zip
[client] vm-config editor finished, accessible from the popup menu of image's versions
Diffstat (limited to 'dozentenmodulserver/src/main/java')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java34
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/ServerHandler.java34
2 files changed, 68 insertions, 0 deletions
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 e445721a..eb5bebff 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
@@ -892,6 +892,40 @@ public class DbImage {
}
}
+ public static byte[] getVirtualizerConfig(String imageVersionId) throws SQLException,
+ TNotFoundException {
+ try (MysqlConnection connection = Database.getConnection()) {
+ MysqlStatement stmt = connection.prepareStatement("SELECT"
+ + " virtualizerconfig FROM imageversion"
+ + " WHERE imageversionid = :imageversionid");
+ stmt.setString("imageversionid", imageVersionId);
+ ResultSet rs = stmt.executeQuery();
+ if (!rs.next())
+ throw new TNotFoundException();
+ return rs.getBytes("virtualizerconfig");
+ } catch (SQLException e) {
+ LOGGER.error("Query failed in DbImage.getVirtualizerConfig()", e);
+ throw e;
+ }
+ }
+
+ public static void setVirtualizerConfig(String imageVersionId, byte[] machineDescription) throws SQLException,
+ TNotFoundException {
+ if (imageVersionId == null || machineDescription == null || machineDescription.length == 0)
+ return;
+ try (MysqlConnection connection = Database.getConnection()) {
+ MysqlStatement stmt = connection.prepareStatement("UPDATE imageversion SET virtualizerconfig = :virtualizerconfig"
+ + " WHERE imageversionid = :imageversionid");
+ stmt.setString("imageversionid", imageVersionId);
+ stmt.setBinary("virtualizerconfig", machineDescription);
+ stmt.executeUpdate();
+ connection.commit();
+ } catch (SQLException e) {
+ LOGGER.error("Query failed in DbImage.setVersionDetails()", e);
+ throw e;
+ }
+ }
+
public enum DeleteState {
KEEP,
SHOULD_DELETE,
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 a76382ba..d6f6ce74 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
@@ -724,4 +724,38 @@ public class ServerHandler implements SatelliteServer.Iface {
}
}
+ @Override
+ public ByteBuffer getImageVersionVirtConfig(String userToken,
+ String imageVersionId) throws TAuthorizationException,
+ TNotFoundException, TInvocationException, TException {
+ UserInfo user = SessionManager.getOrFail(userToken);
+ User.canSeeImageDetailsOrFail(user);
+ byte[] machineDescription = null;
+ try {
+ machineDescription = DbImage.getVirtualizerConfig(imageVersionId);
+ } catch (SQLException e) {
+ throw new TInvocationException(InvocationError.INTERNAL_SERVER_ERROR,
+ "Database failure when retrieving the virtualizer config for '" + imageVersionId + "'.");
+ }
+ if (machineDescription == null)
+ return null;
+ return ByteBuffer.wrap(machineDescription);
+ }
+
+ @Override
+ public ByteBuffer setImageVersionVirtConfig(String userToken, String imageVersionId,
+ ByteBuffer machineDescription) throws TAuthorizationException,
+ TNotFoundException, TInvocationException, TException {
+ SessionManager.getOrFail(userToken);
+ UserInfo user = SessionManager.getOrFail(userToken);
+ User.canEditImageVersionOrFail(user, imageVersionId);
+ byte[] mdBytes = ThriftUtil.unwrapByteBuffer(machineDescription);
+ try {
+ DbImage.setVirtualizerConfig(imageVersionId, mdBytes);
+ } catch (SQLException e) {
+ throw new TInvocationException(InvocationError.INTERNAL_SERVER_ERROR,
+ "Database failure when setting the virtualizer config for '" + imageVersionId + "'.");
+ }
+ return ByteBuffer.wrap(mdBytes);
+ }
}