summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page
diff options
context:
space:
mode:
authorStephan Schwär2020-12-15 07:13:33 +0100
committerStephan Schwär2020-12-15 07:13:33 +0100
commitfa10bc6f53eb554603b86798d7a6a4bf467d438c (patch)
tree106c8a0f4ef0c5755e436dc820b758eb60b86135 /dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page
parentMerge remote-tracking branch 'origin/feature/htmlEditorInDescrioptionText' in... (diff)
parent[client] Refactoring (diff)
downloadtutor-module-fa10bc6f53eb554603b86798d7a6a4bf467d438c.tar.gz
tutor-module-fa10bc6f53eb554603b86798d7a6a4bf467d438c.tar.xz
tutor-module-fa10bc6f53eb554603b86798d7a6a4bf467d438c.zip
Merge remote-tracking branch 'origin/feature/docker-integration-new' into feature-merge
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java (renamed from dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/DockerfileUploadPage.java)119
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java48
2 files changed, 70 insertions, 97 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/DockerfileUploadPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java
index 9eaf5cf6..874a2435 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/DockerfileUploadPage.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java
@@ -4,17 +4,14 @@ import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.ImageDetailsRead;
import org.openslx.dozmod.Config;
-import org.openslx.dozmod.gui.Gui;
-import org.openslx.dozmod.gui.helper.*;
-import org.openslx.dozmod.gui.window.ContainerBindMountWindow;
+import org.openslx.dozmod.gui.helper.QFileChooser;
+import org.openslx.dozmod.gui.helper.TextChangeListener;
import org.openslx.dozmod.gui.wizard.Wizard;
import org.openslx.dozmod.gui.wizard.layout.ContainerUploadPageLayout;
-import org.openslx.dozmod.model.ContainerBindMount;
import org.openslx.dozmod.model.ContainerBuildContextMethod;
import org.openslx.dozmod.model.ContainerDefinition;
import org.openslx.dozmod.model.ContainerMeta;
import org.openslx.dozmod.state.UploadWizardState;
-import org.openslx.dozmod.thrift.*;
import org.openslx.dozmod.thrift.cache.MetaDataCache;
import org.openslx.util.vm.DockerMetaDataDummy;
@@ -22,14 +19,19 @@ import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.filechooser.FileFilter;
-import java.awt.event.*;
-import java.io.*;
-import java.util.ArrayList;
-import java.util.List;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.IOException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
-public class DockerfileUploadPage extends ContainerUploadPageLayout {
+public class ContainerUploadPage extends ContainerUploadPageLayout {
- private final Logger LOGGER = Logger.getLogger(DockerfileUploadPage.class);
+ // TODO: Add a Instruction for the new Container-Feature in bwLehrpool.
+ // TODO: Add link to instructions for Docker-Intetragtion at https://www.bwlehrpool.de/doku.php
+
+ private final Logger LOGGER = Logger.getLogger(ContainerUploadPage.class);
/**
* Page for uploading an imagefile
@@ -38,12 +40,15 @@ public class DockerfileUploadPage extends ContainerUploadPageLayout {
*/
private final UploadWizardState state;
private final ImageDetailsRead existingImage;
+ private final ContainerDefinition containerDefinition;
- public DockerfileUploadPage(Wizard wizard, final UploadWizardState state_) {
+ public ContainerUploadPage(Wizard wizard, final UploadWizardState state,
+ ContainerDefinition containerDefinition) {
super(wizard);
+ this.containerDefinition = containerDefinition;
+ this.state = state;
canComeBack = false;
- state = state_;
existingImage = null;
// HACK set dummy os
@@ -52,13 +57,18 @@ public class DockerfileUploadPage extends ContainerUploadPageLayout {
init();
}
- public DockerfileUploadPage(Wizard wizard, UploadWizardState uploadWizardState,
+ // TODO this constructor is currently used in case if user wants do upload a new version.
+ // This makes no currently no sens in context of docker container and this is used.
+ public ContainerUploadPage(Wizard wizard, UploadWizardState uploadWizardState,
ImageDetailsRead imageDetailsRead) {
super(wizard);
state = uploadWizardState;
existingImage = imageDetailsRead;
+ // TODO fix this!
+ containerDefinition = null;
+
lblImageName.setEnabled(existingImage == null);
txtImageName.setEnabled(existingImage == null);
txtInfoText.setVisible(existingImage == null);
@@ -110,32 +120,7 @@ public class DockerfileUploadPage extends ContainerUploadPageLayout {
}
});
- btnAddBindMount.addActionListener(new ActionListener() {
- @Override public void actionPerformed(ActionEvent e) {
- addBindMount();
- }
- });
- btnDelBindMount.addActionListener(new ActionListener() {
- @Override public void actionPerformed(ActionEvent e) {
- btnDelBindMount();
- }
- });
-
btnBrowseForImage.requestFocus();
- txtInfoText.setText("Many Text");
- }
-
- private void addBindMount() {
- ContainerBindMountWindow.open(wizard, bindMountTable);
- }
-
- private void btnDelBindMount() {
- if (null == bindMountTable.getSelectedItem())
- return;
- List<ContainerBindMount> data = new ArrayList<>(bindMountTable.getData());
- if (data.remove(bindMountTable.getSelectedItem()))
- LOGGER.info("Bind Mount Entry Deleted");
- bindMountTable.setData(data, true);
}
private void browseFile() {
@@ -144,8 +129,6 @@ public class DockerfileUploadPage extends ContainerUploadPageLayout {
fc.setAcceptAllFileFilterUsed(false);
fc.addChoosableFileFilter(new DockerfileFilter());
- // TODO add Feature for MULTIPLE_HYPERVISORS
-
int action = fc.showOpenDialog(getDialog());
File file = fc.getSelectedFile();
@@ -232,63 +215,27 @@ public class DockerfileUploadPage extends ContainerUploadPageLayout {
private DockerMetaDataDummy createVmMeta() {
- ContainerDefinition cd = null;
- ContainerMeta containerMeta = new ContainerMeta();
+ ContainerMeta containerMeta = containerDefinition.getContainerMeta();
containerMeta.setBuildContextMethod(getBuildContextMethod().ordinal());
containerMeta.setImageName(txtImageName.getText());
containerMeta.setRunOptions(txtContainerRun.getText());
- containerMeta.setBindMountConfig(bindMountTable.getData());
- switch (getBuildContextMethod()) {
+ switch (containerDefinition.getBuildContextMethod()) {
case FILE:
- cd = new ContainerDefinition(state.descriptionFile, containerMeta);
+ containerDefinition.setContainerRecipe(state.descriptionFile);
break;
case GIT_REPOSITORY:
containerMeta.setBuildContextUrl(txtGitRepo.getText());
- cd = new ContainerDefinition(containerMeta);
state.diskFile = getDummyFile();
state.descriptionFile = getDummyFile();
break;
}
- return cd.createVmMeta();
+ return containerDefinition.createVmMeta();
}
@Override protected boolean wantNextOrFinish() {
- // are we creating a new image? then either:
- // get the image name either auto filled by VmwareMetaData or by user
- // get the image name from the image we are uploading a new version of
state.name = existingImage != null ? existingImage.getImageName() : txtImageName.getText();
state.meta = createVmMeta();
- // -- create image to get uuid --
- if (existingImage == null) {
- if (state.uuid == null) {
- state.uuid = ThriftActions.createImage(JOptionPane.getFrameForComponent(this), state.name);
- if (state.uuid == null)
- return false;
- txtImageName.setEnabled(false);
- btnBrowseForImage.setEnabled(false);
- txtImageFile.setEnabled(false);
- }
- } else {
- state.uuid = existingImage.getImageBaseId();
- }
- // Create upload initiator that will manage requesting a token, hashing the
- // file, connecting for upload...
- if (state.upload == null) {
- try {
- state.upload = new UploadInitiator(state.uuid, state.diskFile,
- state.meta.getFilteredDefinition());
- } catch (WrappedException e) {
- ThriftError.showMessage(this, LOGGER, e.exception, e.displayMessage);
- return false;
- } catch (IOException e) {
- Gui.showMessageBox(this, "Upload-Initialisierung fehlgeschlagen", MessageType.ERROR, LOGGER,
- e);
- return false;
- }
- }
- // Start the hash check now
- state.upload.startHashing();
return true;
}
@@ -296,9 +243,13 @@ public class DockerfileUploadPage extends ContainerUploadPageLayout {
@Override public boolean accept(File f) {
- boolean accept = true;
- if (f.isFile() && !f.getName().equals("dockerfile"))
- accept = false;
+
+ Pattern p = Pattern.compile("[Dd]ockerfile");
+ Matcher m = p.matcher(f.getName());
+
+ boolean accept = false;
+ if (f.isFile() && m.matches())
+ accept = true;
return accept;
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java
index c3fce45c..306359e8 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java
@@ -26,27 +26,36 @@ import org.openslx.dozmod.gui.helper.I18n;
import org.openslx.dozmod.gui.helper.TextChangeListener;
import org.openslx.dozmod.gui.wizard.Wizard;
import org.openslx.dozmod.gui.wizard.layout.ImageMetaDataPageLayout;
+import org.openslx.dozmod.model.ContainerDefinition;
import org.openslx.dozmod.state.UploadWizardState;
import org.openslx.dozmod.thrift.Session;
import org.openslx.dozmod.thrift.cache.MetaDataCache;
import org.openslx.thrifthelper.Comparators;
import org.openslx.util.QuickTimer;
import org.openslx.util.QuickTimer.Task;
+import org.openslx.util.vm.DockerMetaDataDummy;
import org.openslx.util.vm.QemuMetaData;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.util.Collections;
+import java.util.List;
+
/**
* Page for setting the details of an image.
*/
-@SuppressWarnings("serial")
-public class ImageMetaDataPage extends ImageMetaDataPageLayout {
+@SuppressWarnings("serial") public class ImageMetaDataPage extends ImageMetaDataPageLayout {
private final static Logger LOGGER = Logger.getLogger(ImageMetaDataPage.class);
private UploadWizardState state;
+ private final ContainerDefinition containerDefinition;
- public ImageMetaDataPage(Wizard wizard, UploadWizardState uploadWizardState) {
+ public ImageMetaDataPage(Wizard wizard, UploadWizardState uploadWizardState,
+ ContainerDefinition containerDefinition) {
super(wizard);
this.state = uploadWizardState;
+ this.containerDefinition = containerDefinition;
setPageComplete(false);
// HACK set fixed uploadWizardState to test functions
uploadWizardState.shareMode = ShareMode.LOCAL;
@@ -55,14 +64,12 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout {
QuickTimer.scheduleOnce(new Task() {
List<OperatingSystem> osList = null;
- @Override
- public void fire() {
+ @Override public void fire() {
osList = MetaDataCache.getOperatingSystems();
// now send the organizations back to the LoginWindow
// through populateIdpCombo()
Gui.asyncExec(new Runnable() {
- @Override
- public void run() {
+ @Override public void run() {
fillOsCombo(osList);
}
});
@@ -70,8 +77,7 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout {
});
cboOperatingSystem.addItemListener(new ItemListener() {
- @Override
- public void itemStateChanged(ItemEvent e) {
+ @Override public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
reactToUserInput();
}
@@ -79,8 +85,7 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout {
});
txtDescription.getDocument().addDocumentListener(new TextChangeListener() {
- @Override
- public void changed() {
+ @Override public void changed() {
reactToUserInput();
}
});
@@ -193,11 +198,15 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout {
reactToUserInput();
}
- @Override
- protected boolean wantNextOrFinish() {
+ @Override protected boolean wantNextOrFinish() {
state.selectedOs = (OperatingSystem) cboOperatingSystem.getSelectedItem();
state.isTemplate = chkIsTemplate.isSelected();
state.isRestricted = chkLicenseRestricted.isSelected();
+
+ if (state.meta instanceof DockerMetaDataDummy) {
+ containerDefinition.getContainerMeta().setBindMountConfig(bindMountConfigurator.getData());
+ state.meta = containerDefinition.createVmMeta();
+ }
return state.selectedOs != null && state.description != null;
}
@@ -228,6 +237,19 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout {
startCommandPane.setVisible(true);
}
+ if (state.meta instanceof DockerMetaDataDummy) {
+ bindMountConfigurator.setVisible(true);
+
+ // TODO we need Information about a OS in Container? Currently use "Other (32 Bit)" as default
+ lblOperatingSystem.setVisible(false);
+ cboOperatingSystem.setVisible(false);
+
+ // TODO do we need to check license restrictions in container?
+ chkLicenseRestricted.setVisible(false);
+ // TODO currently no Container Template!
+ chkIsTemplate.setVisible(false);
+ }
+
// evaluate description field
state.description = txtDescription.getText();
if (state.description == null || state.description.isEmpty()) {