summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ContainerBindMountTable.java11
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ContainerBindMountWindow.java19
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ContainerBindMountWindowLayout.java80
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java43
4 files changed, 126 insertions, 27 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ContainerBindMountTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ContainerBindMountTable.java
index 81c76303..28a5225f 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ContainerBindMountTable.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ContainerBindMountTable.java
@@ -1,6 +1,7 @@
package org.openslx.dozmod.gui.control.table;
import org.openslx.dozmod.gui.helper.I18n;
+import org.openslx.dozmod.util.ContainerUtils;
import org.openslx.virtualization.configuration.container.ContainerBindMount;
import java.util.ArrayList;
@@ -11,7 +12,7 @@ public class ContainerBindMountTable extends ListTable<ContainerBindMount> {
* Version for serialization.
*/
private static final long serialVersionUID = -2908607335582645909L;
-
+
public static final ListTableColumn COL_SOURCE = new ListTableColumn(
I18n.CONFIGURATOR.getString("ContainerBindMount.BindMountTable.col.src"));
public static final ListTableColumn COL_TARGET = new ListTableColumn(
@@ -27,7 +28,13 @@ public class ContainerBindMountTable extends ListTable<ContainerBindMount> {
@Override protected Object getValueAtInternal(ContainerBindMount item, ListTableColumn column) {
if (COL_SOURCE == column)
- return item.getSource();
+ switch (item.getMountType()){
+ case DEFAULT:
+ return item.getSource();
+ case CONTAINER_IMAGE:
+ return ContainerUtils.getImageNameByBaseId(item.getSource());
+ }
+
if (COL_TARGET == column)
return item.getTarget();
if (COL_OPTIONS == column)
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ContainerBindMountWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ContainerBindMountWindow.java
index fa3cf920..f4f946e6 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ContainerBindMountWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ContainerBindMountWindow.java
@@ -12,6 +12,7 @@ import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
public class ContainerBindMountWindow extends ContainerBindMountWindowLayout {
@@ -38,7 +39,7 @@ public class ContainerBindMountWindow extends ContainerBindMountWindowLayout {
dispose();
}
});
- this.cboSourceMountPoint.addItemListener(new ItemListener() {
+ this.cboSourceMount.addItemListener(new ItemListener() {
@Override public void itemStateChanged(ItemEvent e) {
isInputComplete();
}
@@ -54,7 +55,8 @@ public class ContainerBindMountWindow extends ContainerBindMountWindowLayout {
private boolean isInputComplete() {
btnSave.setEnabled(false);
- if (cboSourceMountPoint == null || cboSourceMountPoint.getSelectedIndex() == 0) {
+ if (cboSourceMount == null || Objects.equals(cboSourceMount.getSelectedItem(),
+ ContainerMountChoice.getEmptyChoice())) {
header.updateStatus("Source Path is Missing");
return false;
}
@@ -68,11 +70,14 @@ public class ContainerBindMountWindow extends ContainerBindMountWindowLayout {
}
private void saveEntry() {
- ContainerBindMount bindMount = new ContainerBindMount();
- bindMount.setSource(
- ContainerBindMountWindowLayout.SOURCE_MOUNT_POINTS[cboSourceMountPoint.getSelectedIndex()]);
- bindMount.setTarget(this.txtBmTarget.getText());
- bindMount.setOptions(this.txtBmOptions.getText());
+
+ ContainerMountChoice mountChoice = (ContainerMountChoice) this.cboSourceMount.getSelectedItem();
+
+ ContainerBindMount.ContainerMountType mountType = mountChoice.type;
+ String source = mountChoice.value;
+ String target = this.txtBmTarget.getText();
+ String option = this.txtBmOptions.getText();
+ ContainerBindMount bindMount = new ContainerBindMount(mountType, source, target, option);
List<ContainerBindMount> oldData = bindMountTable.getData();
List<ContainerBindMount> data = new ArrayList<>(oldData);
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ContainerBindMountWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ContainerBindMountWindowLayout.java
index 6f6a3cfe..3b542a10 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ContainerBindMountWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ContainerBindMountWindowLayout.java
@@ -1,13 +1,18 @@
package org.openslx.dozmod.gui.window.layout;
+import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.control.ComboBox;
import org.openslx.dozmod.gui.control.QLabel;
import org.openslx.dozmod.gui.helper.GridManager;
import org.openslx.dozmod.gui.helper.StatusHeader;
+import org.openslx.dozmod.util.ContainerUtils;
+import org.openslx.virtualization.configuration.container.ContainerBindMount;
import javax.swing.*;
import java.awt.*;
+import java.util.ArrayList;
+import java.util.List;
public class ContainerBindMountWindowLayout extends JDialog {
@@ -19,8 +24,7 @@ public class ContainerBindMountWindowLayout extends JDialog {
private static final String title = "Add Bind Mount";
protected final StatusHeader header;
- protected final QLabel lblBmSource;
- protected final JTextField txtBmSource;
+ // protected final QLabel lblBmSource;
protected final QLabel lblBmTarget;
protected final JTextField txtBmTarget;
protected final QLabel lblBmOptions;
@@ -33,14 +37,14 @@ public class ContainerBindMountWindowLayout extends JDialog {
protected static String[] SOURCE_MOUNT_POINTS = { EMPTY_MARKER, TAGS[0], TAGS[1], "D", "E", "F", "G", "H",
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
- protected final ComboBox<String> cboSourceMountPoint = new ComboBox<String>(
- new ComboBox.ComboBoxRenderer<String>() {
- @Override public String renderItem(String letter) {
- if (letter == null)
- return null;
- return letter;
+ protected final ComboBox<ContainerMountChoice> cboSourceMount = new ComboBox<>(
+ new ComboBox.ComboBoxRenderer<ContainerMountChoice>() {
+ @Override public String renderItem(ContainerMountChoice choice) {
+ if (choice == null)
+ return "";
+ return choice.name;
}
- }, String.class);
+ }, ContainerMountChoice.class);
public ContainerBindMountWindowLayout(Window modalParent) {
super(modalParent, title, ModalityType.APPLICATION_MODAL);
@@ -53,16 +57,17 @@ public class ContainerBindMountWindowLayout extends JDialog {
add(contentPanel, BorderLayout.CENTER);
GridManager grid = new GridManager(contentPanel, 2, true, new Insets(2, 2, 2, 2));
- lblBmSource = new QLabel("Source");
-
- txtBmSource = new JTextField();
- cboSourceMountPoint.setModel(new DefaultComboBoxModel<>(SOURCE_MOUNT_POINTS));
- cboSourceMountPoint.setSelectedItem(SOURCE_MOUNT_POINTS[0]);
-
- grid.add(lblBmSource);
- grid.add(cboSourceMountPoint).fill(true, false).expand(true, false);
+ cboSourceMount.setModel(
+ new DefaultComboBoxModel<>(generateMountChoices().toArray(new ContainerMountChoice[0])));
+ cboSourceMount.setSelectedIndex(0);
+ grid.add(new QLabel("Source"));
+ grid.add(cboSourceMount).fill(true, false).expand(true, false);
grid.nextRow();
+ // grid.add(lblBmSource);
+ // grid.add(cboSourceMountPoint).fill(true, false).expand(true, false);
+ // grid.nextRow();
+
lblBmTarget = new QLabel("Target");
txtBmTarget = new JTextField();
grid.add(lblBmTarget);
@@ -87,10 +92,49 @@ public class ContainerBindMountWindowLayout extends JDialog {
grid.add(buttonPane, 2).fill(true, false).expand(true, false);
grid.finish(false);
- setSize(350, 200);
+ setSize(350, 300);
setResizable(false);
if (modalParent != null) {
Gui.centerShellOverShell(modalParent, this);
}
}
+
+ private ArrayList<ContainerMountChoice> generateMountChoices() {
+ List<ImageSummaryRead> dataContainerImages = ContainerUtils.getDataContainerImages();
+ ArrayList<ContainerMountChoice> mountChoices = new ArrayList<>();
+ mountChoices.add(ContainerMountChoice.getEmptyChoice());
+
+ for (int i = 1; i < SOURCE_MOUNT_POINTS.length; i++) {
+ mountChoices.add(new ContainerMountChoice(ContainerBindMount.ContainerMountType.DEFAULT,
+ SOURCE_MOUNT_POINTS[i], SOURCE_MOUNT_POINTS[i]));
+ }
+
+ for (ImageSummaryRead image : dataContainerImages) {
+ mountChoices.add(new ContainerMountChoice(ContainerBindMount.ContainerMountType.CONTAINER_IMAGE,
+ image.imageName, image.imageBaseId));
+ }
+ return mountChoices;
+ }
+
+ protected static class ContainerMountChoice {
+
+ public final ContainerBindMount.ContainerMountType type;
+ public final String name;
+ public final String value;
+
+ private static ContainerMountChoice emptyMountChoice = null;
+
+ public ContainerMountChoice(ContainerBindMount.ContainerMountType type, String name, String value) {
+ this.type = type;
+ this.name = name;
+ this.value = value;
+ }
+
+ public static ContainerMountChoice getEmptyChoice() {
+ if (emptyMountChoice == null)
+ emptyMountChoice = new ContainerMountChoice(ContainerBindMount.ContainerMountType.DEFAULT,
+ "-", "-");
+ return emptyMountChoice;
+ }
+ }
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java
index 0e5a1d15..ca57a265 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java
@@ -1,15 +1,24 @@
package org.openslx.dozmod.util;
import org.apache.log4j.Logger;
+import org.apache.thrift.TException;
import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
import org.openslx.bwlp.thrift.iface.LectureSummary;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.helper.I18n;
import org.openslx.dozmod.gui.helper.MessageType;
+import org.openslx.dozmod.thrift.Session;
+import org.openslx.dozmod.thrift.cache.ImageCache;
import org.openslx.dozmod.thrift.cache.LectureCache;
import org.openslx.thrifthelper.TConst;
+import org.openslx.thrifthelper.ThriftManager;
+import org.openslx.util.ThriftUtil;
+import org.openslx.virtualization.configuration.container.ContainerDefinition;
+import org.openslx.virtualization.configuration.container.ContainerMeta;
import java.awt.*;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -36,8 +45,42 @@ public class ContainerUtils {
return false;
}
+ public static List<ImageSummaryRead> getDataContainerImages() {
+ String satelliteToken = Session.getSatelliteToken();
+ List<ImageSummaryRead> images = ImageCache.get(true);
+ List<ImageSummaryRead> dataContainerImages = new ArrayList<>();
+ for (ImageSummaryRead image: images) {
+ if (image.getVirtId().equals(TConst.VIRT_DOCKER))
+ {
+ try {
+ byte[] rawVirtConfig;
+ ByteBuffer byteBuffer = ThriftManager.getSatClient()
+ .getImageVersionVirtConfig(satelliteToken, image.getLatestVersionId());
+ rawVirtConfig = ThriftUtil.unwrapByteBuffer(byteBuffer);
+ ContainerDefinition containerDefinition = ContainerDefinition.fromByteArray(rawVirtConfig);
+ if (containerDefinition.getContainerMeta().getImageType() == ContainerMeta.ContainerImageType.DATA)
+ dataContainerImages.add(image);
+
+ } catch (TException e) {
+// LOGGER.error("Failed to retrieve virtualizer config for image version " + "'"
+// + image.getLatestVersionId() + ", see trace: ", e);
+ }
+ }
+ }
+ return dataContainerImages;
+ }
+
public static void showWarning(Component c, Logger logger) {
Gui.showMessageBox(c, I18n.WINDOW.getString("LectureDetails.Message.error.containerLinkedWithLecture"),
MessageType.WARNING, logger, null);
}
+
+ public static String getImageNameByBaseId(String imageBaseId) {
+ List<ImageSummaryRead> images = ImageCache.get(true);
+ for (ImageSummaryRead image: images) {
+ if (image.imageBaseId.equals(imageBaseId))
+ return image.getImageName();
+ }
+ return imageBaseId;
+ }
}