diff options
author | Manuel Bentele | 2021-05-19 11:46:36 +0200 |
---|---|---|
committer | Manuel Bentele | 2021-05-19 11:46:36 +0200 |
commit | aad75f084c9635878a11e701163ad66e034023ba (patch) | |
tree | e18aef591ccd4616687ed53e0b407d58014d9785 /dozentenmodul/src/main/java/org/openslx/dozmod/gui | |
parent | [client,server] Rename 'vm.disk' package to 'virtualization.disk' (diff) | |
parent | [client] Allow user to set a container type for container images (diff) | |
download | tutor-module-aad75f084c9635878a11e701163ad66e034023ba.tar.gz tutor-module-aad75f084c9635878a11e701163ad66e034023ba.tar.xz tutor-module-aad75f084c9635878a11e701163ad66e034023ba.zip |
Merge branch 'feature/docker'
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui')
4 files changed, 87 insertions, 14 deletions
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 37008e78..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<ContainerMeta.ContainerImageType> 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<ContainerMeta.ContainerImageType>() { + @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); @@ -103,14 +123,25 @@ public class ContainerPanel extends JPanel { txtContainerImageName.setText(image.imageName); txtContainerImageName.setEnabled(false); - // TODO simplify this mess. ContainerBuildContextMethod is to complex - if (containerDefinition.getBuildContextMethod() == ContainerBuildContextMethod.FILE) { + // TODO simplify this mess. ContainerBuildContextMethod is to complex or useless + switch (containerDefinition.getBuildContextMethod()) + { + case FILE: txtContainerRecipe.setText(containerDefinition.getContainerRecipe()); - } else if (containerDefinition.getBuildContextMethod() - == ContainerBuildContextMethod.GIT_REPOSITORY) { + break; + case IMAGE_REPO: + txtContainerRecipe.setText(containerDefinition.getContainerMeta().getImageRepo()); + break; + case GIT_REPOSITORY: txtContainerRecipe.setText(containerDefinition.getContainerMeta().getBuildContextUrl()); + break; + default: + LOGGER.error("Unknown Build Context"); + break; } + cboContainerImageType.setSelectedItem(containerDefinition.getContainerMeta().getImageType()); + if (context.equals(IMAGE_CONTEXT)) { initImageDetails(); } else if (context.equals(CONTAINER_CONTEXT)) { @@ -118,13 +149,14 @@ public class ContainerPanel extends JPanel { } else { LOGGER.error("Container Panel init failed: Please use proper context"); } - } private void initImageDetails() { - // currently do not allow user to change the Dockerfile in the suite. + // 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); @@ -133,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()); } @@ -144,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; } } @@ -159,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 a847082f..3fc632b8 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/gui/wizard/layout/ContainerUploadPageLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ContainerUploadPageLayout.java index 5fcc6dcd..0496261f 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ContainerUploadPageLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ContainerUploadPageLayout.java @@ -24,6 +24,8 @@ public class ContainerUploadPageLayout extends WizardPage { protected final QLabel lblImageName; protected final JTextArea txtInfoText; + protected final JTextField txtImageRepo; + protected final JTabbedPane tpInput; protected final JTextField txtGitRepo; @@ -38,8 +40,24 @@ public class ContainerUploadPageLayout extends WizardPage { setDescription(I18n.PAGE_LAYOUT.getString("ContainerUploadPage.description")); GridManager grid = new GridManager(this, 3, false); + JPanel imageRepoPanel = new JPanel(); + imageRepoPanel.setVisible(true); + GridManager tmpGrid = new GridManager(imageRepoPanel, 2, true, new Insets(5, 0, 5, 0)); + QLabel lblImageRepo = new QLabel( + I18n.PAGE_LAYOUT.getString("ContainerUploadPage.DockerFile.label")); + lblImageRepo.setToolTipText( + I18n.PAGE_LAYOUT.getString("ContainerUploadPage.ImageRepository.ToolTipText")); + txtImageRepo = new JTextField(); + txtImageRepo.setEditable(true); + txtImageRepo.setToolTipText( + I18n.PAGE_LAYOUT.getString("ContainerUploadPage.ImageRepository.ToolTipText")); + tmpGrid.add(lblImageRepo); + tmpGrid.add(txtImageRepo).fill(true, false).expand(true, false); + tmpGrid.finish(false); + + JPanel p1 = new JPanel(); - p1.setVisible(true); + p1.setVisible(false); GridManager g1 = new GridManager(p1, 3, true, new Insets(5, 0, 5, 0)); QLabel imageFileCaption = new QLabel( I18n.PAGE_LAYOUT.getString("ContainerUploadPage.DockerFile.label")); @@ -68,13 +86,12 @@ public class ContainerUploadPageLayout extends WizardPage { tpInput = new JTabbedPane(); tpInput.addTab("Dockerfile", p1); tpInput.addTab("Git Repository", p2); - tpInput.setSelectedIndex(ContainerBuildContextMethod.FILE.ordinal()); + tpInput.addTab("Image Repository", imageRepoPanel); + // set "Image Repository" as selected + tpInput.setSelectedIndex(2); grid.add(tpInput, 3).fill(true, false); - // Start as with Dockerfile as input! - tpInput.setSelectedIndex(0); - lblImageName = new QLabel(I18n.PANEL.getString("ContainerPanel.Label.ImageName.text")); txtImageName = new JTextField(); grid.add(lblImageName); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java index c2db8554..466b26a0 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java @@ -233,6 +233,12 @@ public class ContainerUploadPage extends ContainerUploadPageLayout { ContainerBuildContextMethod method = getBuildContextMethod(); switch (method) { + case IMAGE_REPO: + if (txtImageRepo.getText() == null || txtImageRepo.getText().isEmpty()) { + setWarningMessage(I18n.PAGE.getString("ContainerUploadPage.Warning.NoImageRepo")); + return false; + } + break; case FILE: if (txtImageFile.getText() == null || txtImageFile.getText().isEmpty()) { setWarningMessage(I18n.PAGE.getString("ContainerUploadPage.Warning.NoReceipt")); @@ -271,6 +277,9 @@ public class ContainerUploadPage extends ContainerUploadPageLayout { case FILE: containerDefinition.setContainerRecipe(state.descriptionFile); break; + case IMAGE_REPO: + containerMeta.setImageRepo(txtImageRepo.getText()); + state.descriptionFile = getDummyFile(); case GIT_REPOSITORY: containerMeta.setBuildContextUrl(txtGitRepo.getText()); state.descriptionFile = getDummyFile(); |