summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java
diff options
context:
space:
mode:
authorralph isenmann2021-05-11 09:17:52 +0200
committerralph isenmann2021-05-11 09:17:52 +0200
commit568506424ab62dbc42198940451fb73d46407ff1 (patch)
tree6da72faf7b39e85d6284a696a86fcf4abd34a9c6 /dozentenmodul/src/main/java
parent[server] Fix NPE (diff)
downloadtutor-module-568506424ab62dbc42198940451fb73d46407ff1.tar.gz
tutor-module-568506424ab62dbc42198940451fb73d46407ff1.tar.xz
tutor-module-568506424ab62dbc42198940451fb73d46407ff1.zip
[client] Allow user to define container with Repository Image (directly from hub.docker)
Diffstat (limited to 'dozentenmodul/src/main/java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/panel/ContainerPanel.java20
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ContainerUploadPageLayout.java27
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java9
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerBuildContextMethod.java2
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerMeta.java14
5 files changed, 59 insertions, 13 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..028b9878 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
@@ -103,12 +103,21 @@ 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;
}
if (context.equals(IMAGE_CONTEXT)) {
@@ -118,12 +127,11 @@ 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);
lblContainerRunOpt.setVisible(false);
txtContainerRun.setVisible(false);
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 b16a9785..7ff19882 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
@@ -232,6 +232,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"));
@@ -270,6 +276,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();
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerBuildContextMethod.java b/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerBuildContextMethod.java
index 6ed42ba8..54b7bd39 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerBuildContextMethod.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerBuildContextMethod.java
@@ -2,7 +2,7 @@ package org.openslx.dozmod.model;
public enum ContainerBuildContextMethod {
- FILE, GIT_REPOSITORY;
+ FILE, GIT_REPOSITORY,IMAGE_REPO;
public static ContainerBuildContextMethod fromInt(int index) {
return values()[index];
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 32818acf..ccdb0762 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerMeta.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerMeta.java
@@ -7,10 +7,16 @@ import java.util.Objects;
/**
* ContainerMeta is used to store container specific information.
* An object of this class will be serialized with gson to a json file.
+ *
+ * TODO remove build_context_method
+ * no need to distinguish beettween methods
+ * TODO rename build_context_url to build_context
*/
public class ContainerMeta {
+
private int build_context_method;
+ private String image_repo;
private String build_context_url;
private String image_name;
private String run_options;
@@ -18,6 +24,7 @@ public class ContainerMeta {
public ContainerMeta() {
+ image_repo = "";
build_context_method = ContainerBuildContextMethod.FILE.ordinal();
build_context_url = "";
image_name = "";
@@ -30,6 +37,7 @@ public class ContainerMeta {
build_context_url = containerMeta.build_context_url;
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()));
@@ -75,6 +83,10 @@ public class ContainerMeta {
this.bind_mount_config = bindMountConfig;
}
+ public String getImageRepo() { return image_repo; }
+
+ public void setImageRepo(String from_image) { this.image_repo = from_image; }
+
@Override public boolean equals(Object o) {
if (this == o)
return true;
@@ -83,7 +95,7 @@ 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);
+ bind_mount_config, that.bind_mount_config) && Objects.equals(image_repo,that.image_repo) ;
}
@Override public int hashCode() {