From 26cd5699373dbe35ee24700189e8a3e580ae6243 Mon Sep 17 00:00:00 2001
From: Jonathan Bauer
Date: Wed, 31 Aug 2016 16:54:59 +0200
Subject: [client] vm-config editor finished, accessible from the popup menu of
image's versions
---
.../dozmod/gui/window/ImageDetailsWindow.java | 99 +++++++++++++---------
.../dozmod/gui/window/VirtConfigEditorWindow.java | 80 +++++++++++++++++
.../openslx/dozmod/gui/window/VmxEditorWindow.java | 67 ---------------
.../window/layout/ImageDetailsWindowLayout.java | 3 -
.../layout/VirtConfigEditorWindowLayout.java | 61 +++++++++++++
.../gui/window/layout/VmxEditorWindowLayout.java | 51 -----------
.../openslx/dozmod/thrift/ImageDetailsActions.java | 1 +
.../dozmod/thrift/ImageLocalDetailsActions.java | 31 +++++++
.../thrift/ImagePublishedDetailsActions.java | 6 ++
.../openslx/bwlp/sat/database/mappers/DbImage.java | 34 ++++++++
.../org/openslx/bwlp/sat/thrift/ServerHandler.java | 34 ++++++++
11 files changed, 308 insertions(+), 159 deletions(-)
create mode 100644 dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtConfigEditorWindow.java
delete mode 100644 dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VmxEditorWindow.java
create mode 100644 dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtConfigEditorWindowLayout.java
delete mode 100644 dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VmxEditorWindowLayout.java
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java
index e2d55f29..47022be9 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java
@@ -11,6 +11,9 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@@ -32,7 +35,6 @@ import org.apache.thrift.TException;
import org.openslx.bwlp.thrift.iface.ImageBaseWrite;
import org.openslx.bwlp.thrift.iface.ImageDetailsRead;
import org.openslx.bwlp.thrift.iface.ImagePermissions;
-import org.openslx.bwlp.thrift.iface.ImagePublishData;
import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
import org.openslx.bwlp.thrift.iface.ImageVersionDetails;
import org.openslx.bwlp.thrift.iface.LectureSummary;
@@ -47,7 +49,7 @@ import org.openslx.dozmod.gui.helper.PopupMenu;
import org.openslx.dozmod.gui.helper.TextChangeListener;
import org.openslx.dozmod.gui.helper.UiFeedback;
import org.openslx.dozmod.gui.window.UserListWindow.UserAddedCallback;
-import org.openslx.dozmod.gui.window.VmxEditorWindow.VmxChangedCallback;
+import org.openslx.dozmod.gui.window.VirtConfigEditorWindow.VirtConfigChanged;
import org.openslx.dozmod.gui.window.layout.ImageDetailsWindowLayout;
import org.openslx.dozmod.gui.wizard.ImageUpdateWizard;
import org.openslx.dozmod.gui.wizard.LectureWizard;
@@ -66,7 +68,9 @@ import org.openslx.dozmod.util.MapHelper;
import org.openslx.thrifthelper.ThriftManager;
import org.openslx.util.QuickTimer;
import org.openslx.util.QuickTimer.Task;
+import org.openslx.util.ThriftUtil;
import org.openslx.util.Util;
+import org.openslx.util.vm.VmwareConfig;
/**
* Window for displaying and editing the details of an image.
@@ -124,6 +128,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe
*/
private final JMenuItem mnuNewLecture = new JMenuItem("Neue Veranstaltung");
private final JMenuItem mnuDownload = new JMenuItem("Download");
+ private final JMenuItem mnuVmConfig = new JMenuItem("VM-Konfiguration");
private final JMenuItem mnuDelete = new JMenuItem("Löschen");
private final JMenuItem mnuExtendExpiryDate = new JMenuItem(
"Ablaufzeitpunk vom aktuellen Datum ausgehend neu berechnen");
@@ -208,42 +213,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe
}, "Besitzer festlegen", image.ownerId);
}
});
- btnEditVmx.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- QuickTimer.scheduleOnce(new Task() {
- ImagePublishData data = null;
- @Override
- public void fire() {
- data = ThriftActions.getImageData(image.imageBaseId);
- Gui.asyncExec(new Runnable() {
- @Override
- public void run() {
- if (data == null) {
- // TODO warn user about failure
- return;
- }
- // open basic vmx editor
- byte[] bytes;
- if(data.machineDescription.hasArray()) {
- bytes = data.machineDescription.array();
- } else {
- bytes = new byte[data.machineDescription.remaining()];
- data.machineDescription.get(bytes);
- }
- String dataString = new String(bytes, java.nio.charset.StandardCharsets.UTF_8);
- VmxEditorWindow.open(me, new VmxChangedCallback() {
- @Override
- public void vmxChanged(String newVmx) {
- // TODO save it
- }
- }, dataString);
- }
- });
- }
- });
- }
- });
+
btnPermissions.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
@@ -280,6 +250,9 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe
if (e.getSource().equals(mnuDelete)) {
deleteVersions(tblVersions.getSelectedItems());
}
+ if (e.getSource().equals(mnuVmConfig)) {
+ editVmConfig(selected);
+ }
if (e.getSource().equals(mnuExtendExpiryDate)) {
extendVersionExpiry(tblVersions.getSelectedItems());
}
@@ -288,6 +261,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe
});
pop.addMenuItem(mnuNewLecture);
pop.addMenuItem(mnuDownload);
+ pop.addMenuItem(mnuVmConfig);
pop.addSeparator();
pop.addMenuItem(mnuDelete);
if (Session.canExtendImageExpiry()) {
@@ -346,6 +320,8 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe
&& ImagePerms.canLink(image));
mnuDownload.setEnabled(!multiSelection && tblVersions.getSelectedItem().isValid
&& ImagePerms.canDownload(image));
+ mnuVmConfig.setEnabled(!multiSelection && tblVersions.getSelectedItem().isValid
+ && ImagePerms.canEdit(image));
mnuDelete.setEnabled(ImagePerms.canEdit(image));
mnuExtendExpiryDate.setEnabled(multiSelection
|| tblVersions.getSelectedItem().isValid);
@@ -400,6 +376,51 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe
cboShareMode.setEnabled(false);
}
+ private void editVmConfig(final ImageVersionDetails selected) {
+ QuickTimer.scheduleOnce(new Task() {
+ ByteBuffer machineDescription = null;
+ @Override
+ public void fire() {
+ try {
+ machineDescription = ThriftManager.getSatClient().getImageVersionVirtConfig(Session.getSatelliteToken(), selected.versionId);
+ } catch (TException e) {
+ LOGGER.error("Failed to retrieve virtualizer config for image version "
+ + "'" + image.latestVersionId + ", see trace: ", e);
+ }
+ Gui.asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (machineDescription == null) {
+ Gui.showMessageBox("Konnte VM-Konfiguration nicht abrufen.", MessageType.ERROR, LOGGER, null);
+ return;
+ }
+ byte[] bytes = ThriftUtil.unwrapByteBuffer(machineDescription);
+ BufferedReader reader;
+ StringBuffer content = new StringBuffer("");
+ try {
+ reader = VmwareConfig.getVmxReader(bytes, bytes.length);
+ String line="";
+ while ((line=reader.readLine()) != null) {
+ content.append(line + "\n");
+ }
+ reader.close();
+ } catch (IOException e) {
+ LOGGER.error("Could not get a reader for byte[] !?");
+ }
+ VirtConfigEditorWindow.open(me, new VirtConfigChanged() {
+ @Override
+ public void virtConfigChanged(String newMachineDescription) {
+ if (newMachineDescription == null || newMachineDescription.isEmpty())
+ return;
+ actionHandler.setVirtualizerConfig(selected.versionId, newMachineDescription);
+ }
+ }, content.toString());
+ }
+ });
+ }
+ });
+ }
+
/********************************************************************************
*
* Helper triggering the actual thrift calls
@@ -623,6 +644,8 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe
refresh(true);
}
}
+
+
/********************************************************************************
*
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtConfigEditorWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtConfigEditorWindow.java
new file mode 100644
index 00000000..4a10e776
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtConfigEditorWindow.java
@@ -0,0 +1,80 @@
+package org.openslx.dozmod.gui.window;
+
+import java.awt.Window;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import org.apache.log4j.Logger;
+import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.gui.helper.MessageType;
+import org.openslx.dozmod.gui.helper.TextChangeListener;
+import org.openslx.dozmod.gui.helper.UiFeedback;
+import org.openslx.dozmod.gui.window.layout.VirtConfigEditorWindowLayout;
+
+
+@SuppressWarnings("serial")
+public class VirtConfigEditorWindow extends VirtConfigEditorWindowLayout implements UiFeedback {
+
+ private final static Logger LOGGER = Logger.getLogger(VirtConfigEditorWindow.class);
+
+ public interface VirtConfigChanged {
+ public void virtConfigChanged(String newVmx);
+ }
+ private final String originalMachineDescription;
+ private final VirtConfigEditorWindow me = this;
+
+ protected VirtConfigEditorWindow(Window modalParent, final VirtConfigChanged cb, final String machineDescription) {
+ super(modalParent);
+ originalMachineDescription = machineDescription;
+
+ // listener for the text fields
+ pnlEditor.getDocument().addDocumentListener(new TextChangeListener() {
+ @Override
+ public void changed() {
+ btnSave.setEnabled(!originalMachineDescription.equals(pnlEditor.getText()));;
+ }
+ });
+
+ btnSave.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ cb.virtConfigChanged(pnlEditor.getText());
+ // above command throws exception
+ dispose();
+ }
+ });
+
+ btnCancel.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ safeClose();
+ }
+ });
+ // finally set the editor's content to the vmx
+ pnlEditor.setText(machineDescription);
+ pnlEditor.setCaretPosition(0);
+ }
+
+ public static void open(Window modalParent, final VirtConfigChanged cb, final String machineDescription) {
+ VirtConfigEditorWindow win = new VirtConfigEditorWindow(modalParent, cb, machineDescription);
+ win.setVisible(true);
+ }
+
+ private void safeClose() {
+ if (originalMachineDescription.equals(pnlEditor.getText()) ||
+ Gui.showMessageBox(me, "Ihre Änderungen werden verloren gehen, wollen Sie trotzdem abbrechen?", MessageType.QUESTION_YESNO,
+ LOGGER, null))
+ dispose();
+ }
+
+ @Override
+ public boolean wantConfirmQuit() {
+ return !originalMachineDescription.equals(pnlEditor.getText());
+ }
+
+ @Override
+ public void escapePressed() {
+ safeClose();
+ }
+
+}
\ No newline at end of file
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VmxEditorWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VmxEditorWindow.java
deleted file mode 100644
index a1502356..00000000
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VmxEditorWindow.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package org.openslx.dozmod.gui.window;
-
-import java.awt.Window;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-
-import org.apache.log4j.Logger;
-import org.openslx.dozmod.gui.Gui;
-import org.openslx.dozmod.gui.helper.MessageType;
-import org.openslx.dozmod.gui.helper.UiFeedback;
-import org.openslx.dozmod.gui.window.layout.VmxEditorWindowLayout;
-
-
-@SuppressWarnings("serial")
-public class VmxEditorWindow extends VmxEditorWindowLayout implements UiFeedback {
-
- private final static Logger LOGGER = Logger.getLogger(VmxEditorWindow.class);
-
- public interface VmxChangedCallback {
- public void vmxChanged(String newVmx);
- }
- private final String originalVmx;
- private final VmxEditorWindow me = this;
-
- protected VmxEditorWindow(Window modalParent, final VmxChangedCallback cb, String vmx) {
- super(modalParent, vmx);
- originalVmx = vmx;
- btnSave.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- // TODO callback to the main window to save the contents
- cb.vmxChanged(pnlEditor.getText());
- }
- });
-
- btnCancel.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String newData = pnlEditor.getText();
- if (newData == null) {
- LOGGER.debug("Error while getting the text from the editor...");
- return;
- }
- if (originalVmx != pnlEditor.getText()) {
- if (Gui.showMessageBox(me, "Ihre Änderungen werden verloren gehen, wollen Sie trotzdem fortfahren?", MessageType.QUESTION_YESNO,
- LOGGER, null))
- dispose();
- }
- }
- });
- }
-
- public static void open(Window modalParent, final VmxChangedCallback cb, String vmx) {
- VmxEditorWindow win = new VmxEditorWindow(modalParent, cb, vmx);
- win.setVisible(true);
- }
-
- @Override
- public boolean wantConfirmQuit() {
- return false;
- }
-
- @Override
- public void escapePressed() {
- dispose();
- }
-}
\ No newline at end of file
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java
index 311f8f47..43904c42 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java
@@ -64,7 +64,6 @@ public abstract class ImageDetailsWindowLayout extends JDialog {
protected final JButton btnUploadToMaster;
protected final JButton btnClose;
- protected final JButton btnEditVmx;
protected final JButton btnShowLinkingLectures;
protected final QLabel lblLinkedLectureCount;
@@ -179,10 +178,8 @@ public abstract class ImageDetailsWindowLayout extends JDialog {
// virtualizer
lblVirtualizer = new QLabel();
- btnEditVmx = new JButton("VMX Editieren");
grid.add(new QLabel("Virtualisierer"));
grid.add(lblVirtualizer, 2).expand(true, false).fill(true, false);
- //grid.add(btnEditVmx);
grid.nextRow();
btnPermissions = new JButton("Berechtigungen");
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtConfigEditorWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtConfigEditorWindowLayout.java
new file mode 100644
index 00000000..7611f870
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtConfigEditorWindowLayout.java
@@ -0,0 +1,61 @@
+package org.openslx.dozmod.gui.window.layout;
+
+import java.awt.Dimension;
+import java.awt.Insets;
+import java.awt.Window;
+
+import javax.swing.BorderFactory;
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JEditorPane;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+
+import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.gui.helper.GridManager;
+
+@SuppressWarnings("serial")
+public class VirtConfigEditorWindowLayout extends JDialog {
+
+ private static String title = "VM-Konfiguration Editor";
+ protected final JScrollPane pnlScrollPane;
+ protected final JEditorPane pnlEditor;
+ protected final JButton btnSave;
+ protected final JButton btnCancel;
+
+ protected VirtConfigEditorWindowLayout(Window modalParent) {
+ super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL
+ : ModalityType.MODELESS);
+
+ GridManager grid = new GridManager(this, 1, true, new Insets(2, 2, 2, 2));
+ JPanel pnlWarning = new JPanel();
+ pnlWarning.setBorder(BorderFactory.createTitledBorder("WARNUNG"));
+ pnlWarning.add(new JLabel("Änderungen an der VM-Konfiguration können zu Funktionsstörungen führen.
Benutzung auf eigene Gefahr!"));
+ pnlEditor = new JEditorPane("text/plain", null);
+ pnlScrollPane = new JScrollPane(pnlEditor, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+ JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+ grid.add(pnlWarning).fill(true, false).expand(true, false);
+ grid.nextRow();
+ grid.add(pnlScrollPane).expand(true, true).fill(true, true);
+ grid.nextRow();
+
+ JPanel buttonPane = new JPanel();
+ buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
+ buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
+ buttonPane.add(Box.createHorizontalGlue());
+ btnCancel = new JButton("Abbrechen");
+ buttonPane.add(btnCancel);
+ buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
+ btnSave = new JButton("Speichern");
+ buttonPane.add(btnSave);
+ grid.add(buttonPane).fill(true, false).expand(true, false);;
+ grid.finish(false);
+
+ setPreferredSize(Gui.getScaledDimension(650, 750));
+ setMinimumSize(Gui.getScaledDimension(550, 650));
+ Gui.centerShellOverShell(modalParent, this);
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VmxEditorWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VmxEditorWindowLayout.java
deleted file mode 100644
index 4b502d16..00000000
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VmxEditorWindowLayout.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package org.openslx.dozmod.gui.window.layout;
-
-import java.awt.Dimension;
-import java.awt.Window;
-
-import javax.swing.BorderFactory;
-import javax.swing.Box;
-import javax.swing.BoxLayout;
-import javax.swing.JButton;
-import javax.swing.JDialog;
-import javax.swing.JEditorPane;
-import javax.swing.JPanel;
-
-import org.openslx.dozmod.gui.Gui;
-import org.openslx.dozmod.gui.helper.GridManager;
-
-@SuppressWarnings("serial")
-public class VmxEditorWindowLayout extends JDialog {
-
- private static String title = "VMX Editor (nur für erfahrene Anwender!)";
- protected final JEditorPane pnlEditor;
- protected final JButton btnSave;
- protected final JButton btnCancel;
-
- protected VmxEditorWindowLayout(Window modalParent, String vmx) {
- super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL
- : ModalityType.MODELESS);
-
- GridManager grid = new GridManager(this, 1);
-
- pnlEditor = new JEditorPane("text/plain", vmx);
- grid.add(pnlEditor).expand(true, true).fill(true, true);
- grid.nextRow();
-
- JPanel buttonPane = new JPanel();
- buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
- buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
- buttonPane.add(Box.createHorizontalGlue());
- btnCancel = new JButton("Abbrechen");
- buttonPane.add(btnCancel);
- buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
- btnSave = new JButton("Übernehmen");
- buttonPane.add(btnSave);
- grid.add(buttonPane).fill(true, false).expand(true, false);;
- grid.finish(false);
-
- setPreferredSize(Gui.getScaledDimension(500, 400));
- setMinimumSize(Gui.getScaledDimension(350, 300));
- Gui.centerShellOverShell(modalParent, this);
- }
-}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageDetailsActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageDetailsActions.java
index a2183b23..8d10abab 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageDetailsActions.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageDetailsActions.java
@@ -17,6 +17,7 @@ public interface ImageDetailsActions {
public void getImageDetails(final String imageBaseId, final ImageMetaCallback callback);
public boolean setImageOwner(final String imageBaseId, final UserInfo user);
public void updateImageBase(final String imageBaseId, final ImageBaseWrite data) throws TException, TAuthorizationException, TNotFoundException, TInvocationException;
+ public void setVirtualizerConfig(final String imageVersionId, final String machineDescription);
public void writeImagePermissions(final String imageBaseId, Map customPermissions) throws TException, TAuthorizationException, TNotFoundException, TInvocationException;
public void deleteImageVersion(final ImageVersionDetails version, final DeleteCallback callback);
public boolean isImagePublishSupported();
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageLocalDetailsActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageLocalDetailsActions.java
index a1662fbd..1070017d 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageLocalDetailsActions.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageLocalDetailsActions.java
@@ -1,6 +1,8 @@
package org.openslx.dozmod.thrift;
import java.awt.Frame;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.Map;
import org.apache.log4j.Logger;
@@ -14,8 +16,10 @@ import org.openslx.bwlp.thrift.iface.TInvocationException;
import org.openslx.bwlp.thrift.iface.TNotFoundException;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.dozmod.thrift.ThriftActions.DeleteCallback;
import org.openslx.dozmod.thrift.ThriftActions.ImageMetaCallback;
+import org.openslx.thrifthelper.ThriftManager;
import org.openslx.util.QuickTimer;
import org.openslx.util.QuickTimer.Task;
@@ -93,4 +97,31 @@ public class ImageLocalDetailsActions implements ImageDetailsActions {
return Session.isImagePublishSupported();
}
+ @Override
+ public void setVirtualizerConfig(final String imageVersionId, final String machineDescription) {
+ final ByteBuffer bufferToSave;
+ bufferToSave = ByteBuffer.wrap(machineDescription.getBytes(StandardCharsets.ISO_8859_1));
+ QuickTimer.scheduleOnce(new Task() {
+ ByteBuffer bufferSaved = null;
+ @Override
+ public void fire() {
+ try {
+ bufferSaved = ThriftManager.getSatClient().setImageVersionVirtConfig(Session.getSatelliteToken(), imageVersionId, bufferToSave);
+ } catch (TException e) {
+ ThriftError.showMessage(parent, LOGGER, e, "Fehler beim Speichern der VM-Konfiguration!");
+ }
+ Gui.asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ // check the returned bytebuffer to check if the transfer worked as intended
+ if (!bufferSaved.equals(bufferToSave)) // tested this, seems to works good enough...
+ Gui.showMessageBox("Unvorhergesehener Fehler! Bitte wenden Sie sich an dem Support.",
+ MessageType.ERROR , LOGGER, null);
+ // else we're good.
+ }
+ });
+ }
+ });
+ }
+
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImagePublishedDetailsActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImagePublishedDetailsActions.java
index 9cdda519..99ebf107 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImagePublishedDetailsActions.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImagePublishedDetailsActions.java
@@ -66,4 +66,10 @@ public class ImagePublishedDetailsActions implements ImageDetailsActions {
public boolean isImagePublishSupported() {
return false;
}
+
+ @Override
+ public void setVirtualizerConfig(String imageVersionId,
+ String machineDescription) {
+ return;
+ }
}
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);
+ }
}
--
cgit v1.2.3-55-g7522