From a742b83003743218efab443a34519bf0fde07438 Mon Sep 17 00:00:00 2001 From: ralph isenmann Date: Mon, 17 May 2021 10:57:33 +0200 Subject: [client] Allow user to set a container type for container images User can set for a container image the types: lecture, batch, data. The first two can be used in lectures, the second can also be used in by job system. The "data" type is used to mark a container which only transport data (for ml). --- .../openslx/dozmod/gui/panel/ContainerPanel.java | 37 +++++++++++++-- .../dozmod/gui/window/ImageDetailsWindow.java | 8 ++++ .../org/openslx/dozmod/model/ContainerMeta.java | 54 +++++++++++++++++++++- .../org/openslx/dozmod/util/ContainerUtils.java | 3 +- 4 files changed, 96 insertions(+), 6 deletions(-) (limited to 'dozentenmodul/src') diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/panel/ContainerPanel.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/panel/ContainerPanel.java index 028b9878..8b79d064 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/panel/ContainerPanel.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/panel/ContainerPanel.java @@ -6,11 +6,12 @@ import org.openslx.bwlp.thrift.iface.ImageDetailsRead; import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.changemonitor.DialogChangeMonitor; import org.openslx.dozmod.gui.configurator.ContainerBindMountConfigurator; +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.I18n; -import org.openslx.dozmod.model.ContainerBuildContextMethod; import org.openslx.dozmod.model.ContainerDefinition; +import org.openslx.dozmod.model.ContainerMeta; import org.openslx.thrifthelper.ThriftManager; import org.openslx.util.ThriftUtil; @@ -32,7 +33,9 @@ public class ContainerPanel extends JPanel { private final Logger LOGGER = Logger.getLogger(ContainerBindMountConfigurator.class); private final QLabel lblContainerRunOpt; - private final QLabel lblContainerImageName; + + private final QLabel lblContainerImageType; + private final ComboBox cboContainerImageType; private final JTextArea txtContainerRecipe; private final JTextField txtContainerRun; @@ -63,7 +66,7 @@ public class ContainerPanel extends JPanel { GridManager grdContainer = new GridManager(this, 2, false, new Insets(8, 2, 8, 2)); - lblContainerImageName = new QLabel( + QLabel lblContainerImageName = new QLabel( I18n.PANEL.getString("ContainerPanel.Label.ImageName.text")); grdContainer.add(lblContainerImageName); txtContainerImageName = new JTextField(); @@ -75,6 +78,23 @@ public class ContainerPanel extends JPanel { scrollableTextArea.setMinimumSize(Gui.getScaledDimension(0, 200)); scrollableTextArea.setPreferredSize(Gui.getScaledDimension(0, 200)); grdContainer.add(scrollableTextArea, 2).fill(true, true).expand(true, true); + + + lblContainerImageType = new QLabel("Container Image Type"); + cboContainerImageType = new ComboBox<>(new ComboBox.ComboBoxRenderer() { + @Override public String renderItem(ContainerMeta.ContainerImageType item) { + if (item == null) + return "null"; + return item.name(); + } + }, ContainerMeta.ContainerImageType.class); + for (ContainerMeta.ContainerImageType type:ContainerMeta.ContainerImageType.values()) { + cboContainerImageType.addItem(type); + } + cboContainerImageType.setSelectedItem(ContainerMeta.ContainerImageType.LECTURE); + grdContainer.add(lblContainerImageType); + grdContainer.add(cboContainerImageType).fill(true,false).expand(true,false); + grdContainer.add(pnlContainerMeta, 2).fill(true, true).expand(true, true); grdContainer.finish(true); @@ -120,6 +140,8 @@ public class ContainerPanel extends JPanel { break; } + cboContainerImageType.setSelectedItem(containerDefinition.getContainerMeta().getImageType()); + if (context.equals(IMAGE_CONTEXT)) { initImageDetails(); } else if (context.equals(CONTAINER_CONTEXT)) { @@ -133,6 +155,8 @@ public class ContainerPanel extends JPanel { // currently do not allow user to change the Image Repository or Dockerfile in the suite. txtContainerRecipe.setEnabled(false); + + // do not show container specific input options lblContainerRunOpt.setVisible(false); txtContainerRun.setVisible(false); bindMountConfigurator.setVisible(false); @@ -141,6 +165,9 @@ public class ContainerPanel extends JPanel { private void initContainerDetails() { txtContainerRecipe.setEnabled(false); + lblContainerImageType.setVisible(false); + cboContainerImageType.setEditable(false); + cboContainerImageType.setVisible(false); txtContainerRun.setText(containerDefinition.getContainerMeta().getRunOptions()); bindMountConfigurator.setData(containerDefinition.getContainerMeta().getBindMountConfig()); } @@ -152,6 +179,7 @@ public class ContainerPanel extends JPanel { I18n.PANEL.getString("ContainerPanel.Constraint.NoEmptyDockerfile.text"))); changeMonitor.add(txtContainerRun); changeMonitor.add(bindMountConfigurator); + changeMonitor.addFixedCombo(cboContainerImageType,null); isFirstTime = false; } } @@ -167,11 +195,14 @@ public class ContainerPanel extends JPanel { ContainerDefinition newConDev = new ContainerDefinition(containerDefinition); + newConDev.getContainerMeta().setImageType( + (ContainerMeta.ContainerImageType) cboContainerImageType.getSelectedItem()); newConDev.getContainerMeta().setRunOptions(txtContainerRun.getText()); newConDev.getContainerMeta().setBindMountConfig(bindMountConfigurator.getData()); // TODO do I really need this check? Maybe just get every setting and upload it. if (!newConDev.equals(containerDefinition)) { + LOGGER.info("Update Container Definition"); try { ThriftManager.getSatClient() .setImageVersionVirtConfig(satelliteToken, image.getLatestVersionId(), 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 bad9cea0..6aef01d5 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 @@ -576,6 +576,14 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout } } + // TODO maybe there could be a nicer way to distinguish between image and containerImage + if (image != null && image.getVirtId().equals(TConst.VIRT_DOCKER) ) { + if(!pnlTabContainer.saveChanges(Session.getSatelliteToken(),image)) + return false; + } else { + LOGGER.error("No Image: Could not save Container Settings!"); + } + changeMonitor.reset(); return true; } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerMeta.java b/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerMeta.java index ccdb0762..0306d0ee 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerMeta.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerMeta.java @@ -14,12 +14,47 @@ import java.util.Objects; */ public class ContainerMeta { + public enum ContainerImageType implements org.apache.thrift.TEnum { + LECTURE("lecture"), + BATCH("batch"), + DATA("data"); + + private final String name; + + ContainerImageType(String name){ + this.name = name; + } + + public boolean equalNames(String other){ + return name.equals(other); + } + public static ContainerImageType getByName(String name){ + for (ContainerImageType item : ContainerImageType.values()){ + if (item.name.equals(name)) + return item; + } + // name is not an enum, return lecture as default + return LECTURE; + } + + + + @Override public String toString() { + return this.name; + } + + @Override public int getValue() { + return this.ordinal(); + } + } + private int build_context_method; private String image_repo; private String build_context_url; private String image_name; private String run_options; + private String image_type; private List bind_mount_config = new ArrayList<>(); public ContainerMeta() { @@ -29,6 +64,7 @@ public class ContainerMeta { build_context_url = ""; image_name = ""; run_options = ""; + image_type = ContainerImageType.LECTURE.toString(); bind_mount_config = new ArrayList<>(); } @@ -38,6 +74,7 @@ public class ContainerMeta { image_name = containerMeta.image_name; run_options = containerMeta.run_options; image_repo = containerMeta.image_repo; + for (ContainerBindMount bm : containerMeta.bind_mount_config) bind_mount_config.add(new ContainerBindMount(bm.getSource(), bm.getTarget(), bm.getOptions())); @@ -87,6 +124,17 @@ public class ContainerMeta { public void setImageRepo(String from_image) { this.image_repo = from_image; } + public ContainerImageType getImageType() { + if (image_type == null || image_type.length() == 0) + return ContainerImageType.LECTURE; + + return ContainerImageType.getByName(image_type); + } + + public void setImageType(ContainerImageType image_type) { + this.image_type = image_type.toString(); + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -95,10 +143,12 @@ public class ContainerMeta { ContainerMeta that = (ContainerMeta) o; return Objects.equals(build_context_url, that.build_context_url) && Objects.equals(image_name, that.image_name) && Objects.equals(run_options, that.run_options) && Objects.equals( - bind_mount_config, that.bind_mount_config) && Objects.equals(image_repo,that.image_repo) ; + bind_mount_config, that.bind_mount_config) && Objects.equals(image_repo,that.image_repo) + && Objects.equals(image_type,that.image_type); } @Override public int hashCode() { - return Objects.hash(build_context_url, image_name, run_options); + return Objects.hash(build_context_url, image_name, run_options, + bind_mount_config, image_repo, image_type); } } 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 eeaae891..0e5a1d15 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java @@ -27,7 +27,8 @@ public class ContainerUtils { if (image != null && image.getVirtId().equals(TConst.VIRT_DOCKER)) { List lectureSummaries = LectureCache.get(true); for (LectureSummary lecture : lectureSummaries) { - if (lecture.imageBaseId.equals(image.imageBaseId)) { + // lecture.imageBaseId is null when no image linked to it -> NullPointer on equals + if (image.imageBaseId.equals(lecture.imageBaseId)) { return true; } } -- cgit v1.2.3-55-g7522