diff options
author | Stephan Schwär | 2020-12-15 07:13:33 +0100 |
---|---|---|
committer | Stephan Schwär | 2020-12-15 07:13:33 +0100 |
commit | fa10bc6f53eb554603b86798d7a6a4bf467d438c (patch) | |
tree | 106c8a0f4ef0c5755e436dc820b758eb60b86135 /dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard | |
parent | Merge remote-tracking branch 'origin/feature/htmlEditorInDescrioptionText' in... (diff) | |
parent | [client] Refactoring (diff) | |
download | tutor-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')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageCreationWizard.java | 96 | ||||
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageUpdateWizard.java | 4 | ||||
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ContainerUploadPageLayout.java | 37 | ||||
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java | 23 | ||||
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageTypePageLayout.java | 20 | ||||
-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.java | 48 |
7 files changed, 166 insertions, 181 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageCreationWizard.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageCreationWizard.java index 7256dd69..71a70b0e 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageCreationWizard.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageCreationWizard.java @@ -1,11 +1,5 @@ package org.openslx.dozmod.gui.wizard; -import java.awt.Window; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JOptionPane; - import org.apache.log4j.Logger; import org.apache.thrift.TException; import org.openslx.bwlp.thrift.iface.ImageBaseWrite; @@ -16,22 +10,30 @@ import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.gui.helper.QuitNotification; import org.openslx.dozmod.gui.helper.UiFeedback; import org.openslx.dozmod.gui.wizard.page.*; +import org.openslx.dozmod.model.ContainerDefinition; import org.openslx.dozmod.state.UploadWizardState; -import org.openslx.dozmod.thrift.Session; -import org.openslx.dozmod.thrift.ThriftActions; -import org.openslx.dozmod.thrift.ThriftError; +import org.openslx.dozmod.thrift.*; import org.openslx.dozmod.thrift.UploadInitiator.GotUploadTokenCallback; import org.openslx.thrifthelper.ThriftManager; import org.openslx.util.QuickTimer; import org.openslx.util.QuickTimer.Task; +import org.openslx.util.vm.DockerMetaDataDummy; + +import javax.swing.*; +import java.awt.*; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; -@SuppressWarnings("serial") -public class ImageCreationWizard extends Wizard implements UiFeedback, QuitNotification { +@SuppressWarnings("serial") public class ImageCreationWizard extends Wizard + implements UiFeedback, QuitNotification { private final static Logger LOGGER = Logger.getLogger(ImageCreationWizard.class); private final UploadWizardState state = new UploadWizardState(); + private ContainerDefinition containerDefinition = new ContainerDefinition(); + private List<WizardPage> currentPages = new ArrayList<>(); private boolean baseWritten = false; @@ -39,8 +41,8 @@ public class ImageCreationWizard extends Wizard implements UiFeedback, QuitNotif /** * Wizard for creating or editing an image - * - * @param editExistingImage whether to create new or edit existing image + * + * @param parent whether to create new or edit existing image */ public ImageCreationWizard(Window parent) { super(parent); @@ -57,7 +59,7 @@ public class ImageCreationWizard extends Wizard implements UiFeedback, QuitNotif cleanCurrent(); state.imageUploadPage = new ImageUploadPage(this, state, null); currentPages.add(state.imageUploadPage); - currentPages.add(new ImageMetaDataPage(this, state)); + currentPages.add(new ImageMetaDataPage(this, state, null)); currentPages.add(new ImageCustomPermissionPage(this, state)); addPages(); @@ -71,8 +73,8 @@ public class ImageCreationWizard extends Wizard implements UiFeedback, QuitNotif public void doDockerCreation() { cleanCurrent(); - currentPages.add(new DockerfileUploadPage(this, state)); - currentPages.add(new ImageMetaDataPage(this, state)); + currentPages.add(new ContainerUploadPage(this, state, containerDefinition)); + currentPages.add(new ImageMetaDataPage(this, state, containerDefinition)); currentPages.add(new ImageCustomPermissionPage(this, state)); addPages(); } @@ -95,8 +97,44 @@ public class ImageCreationWizard extends Wizard implements UiFeedback, QuitNotif return I18n.WIZARD.getString("ImageCreation.Wizard.title"); } - @Override - public boolean wantFinish() { + /** + * initUpload will be called after a user finish the creation of a new ContainerDefinition. + * It creates the UploadInitiator with the collected information. + */ + private void initUpload() { + + if (state.uuid == null) { + state.uuid = ThriftActions.createImage(JOptionPane.getFrameForComponent(this), state.name); + if (state.uuid == null) { + // return false; + LOGGER.error("initUpload Failed: Count not get uuid!"); + return; + } + } + + // 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(); + } + + @Override public boolean wantFinish() { + + if (state.meta instanceof DockerMetaDataDummy) + initUpload(); // since we only started the upload and created a "blank" image entry // we can here do all the sanity checks on the fields of UploadWizardState // and react accordingly. @@ -134,8 +172,7 @@ public class ImageCreationWizard extends Wizard implements UiFeedback, QuitNotif } state.upload.startUpload(new GotUploadTokenCallback() { - @Override - public void fire() { + @Override public void fire() { // push version data try { ThriftActions.updateImageVersion(state.upload.getToken(), @@ -152,16 +189,15 @@ public class ImageCreationWizard extends Wizard implements UiFeedback, QuitNotif return true; } - @Override - public WizardPage performFinish() { + @Override public WizardPage performFinish() { return new ImageUploadSummaryPage(this, state, true); } /** * Checks the validity of the state - * + * * @return true if we have all the needed information in the state, false - * otherwise + * otherwise */ private boolean isStateValid() { // debug purposes @@ -253,8 +289,7 @@ public class ImageCreationWizard extends Wizard implements UiFeedback, QuitNotif MessageType.QUESTION_YESNO, null, null); if (confirmed) { QuickTimer.scheduleOnce(new Task() { - @Override - public void fire() { + @Override public void fire() { if (state.upload != null) { state.upload.cancelError(); } @@ -270,18 +305,15 @@ public class ImageCreationWizard extends Wizard implements UiFeedback, QuitNotif return confirmed; } - @Override - public boolean wantConfirmQuit() { + @Override public boolean wantConfirmQuit() { return state.uuid != null; } - @Override - public void escapePressed() { + @Override public void escapePressed() { doCancel(); } - @Override - public void onApplicationQuit() { + @Override public void onApplicationQuit() { if (state != null && state.upload != null) { state.upload.cancelError(); } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageUpdateWizard.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageUpdateWizard.java index 6f911894..56624820 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageUpdateWizard.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageUpdateWizard.java @@ -11,8 +11,8 @@ import org.openslx.dozmod.gui.helper.I18n; import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.gui.helper.QuitNotification; import org.openslx.dozmod.gui.helper.UiFeedback; -import org.openslx.dozmod.gui.wizard.page.DockerfileUploadPage; import org.openslx.dozmod.gui.wizard.page.ImageOvfConversionPage; +import org.openslx.dozmod.gui.wizard.page.ContainerUploadPage; import org.openslx.dozmod.gui.wizard.page.ImageUploadPage; import org.openslx.dozmod.gui.wizard.page.ImageUploadSummaryPage; import org.openslx.dozmod.state.UploadWizardState; @@ -36,7 +36,7 @@ public class ImageUpdateWizard extends Wizard implements UiFeedback, QuitNotific // TODO allow user to update the plain dockerfile switch (image.virtId){ case TConst.VIRT_DOCKER: - addPage(new DockerfileUploadPage(this,state, image)); + addPage(new ContainerUploadPage(this,state, image)); break; case TConst.VIRT_QEMU: case TConst.VIRT_VIRTUALBOX: 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 df9e99fc..291bc7fa 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 @@ -1,8 +1,6 @@ package org.openslx.dozmod.gui.wizard.layout; import org.openslx.dozmod.gui.control.QLabel; -import org.openslx.dozmod.gui.control.table.ContainerBindMountTable; -import org.openslx.dozmod.gui.control.table.QScrollPane; import org.openslx.dozmod.gui.helper.GridManager; import org.openslx.dozmod.gui.wizard.Wizard; import org.openslx.dozmod.gui.wizard.WizardPage; @@ -10,7 +8,7 @@ import org.openslx.dozmod.model.ContainerBuildContextMethod; import javax.swing.*; import java.awt.*; -import java.awt.event.*; +import java.awt.event.KeyEvent; public class ContainerUploadPageLayout extends WizardPage { @@ -27,12 +25,6 @@ public class ContainerUploadPageLayout extends WizardPage { protected final JTabbedPane tpInput; protected final JTextField txtGitRepo; - protected final ContainerBindMountTable bindMountTable; - protected final JButton btnAddBindMount; - protected final JButton btnDelBindMount; - - - // TODO set proper Text labels /** @@ -40,12 +32,10 @@ public class ContainerUploadPageLayout extends WizardPage { */ public ContainerUploadPageLayout(Wizard wizard) { - super(wizard, "Neue VM anlegen"); + super(wizard, "Define a new Container Image"); setDescription("Please provide an Input for a Docker Image"); GridManager grid = new GridManager(this, 3, false); - // -- Browse for VM -- - JPanel p1 = new JPanel(); p1.setVisible(true); GridManager g1 = new GridManager(p1, 3, true, new Insets(5, 0, 5, 0)); @@ -72,17 +62,9 @@ public class ContainerUploadPageLayout extends WizardPage { g2.add(txtGitRepo).fill(true, false).expand(true, false); g2.finish(false); - JPanel p3 = new JPanel(); - p3.setVisible(false); - GridManager g3 = new GridManager(p3, 3, true, new Insets(5, 0, 5, 0)); - QLabel tmp = new QLabel("DUMMY"); - g3.add(tmp).fill(true, false).expand(true, false); - g3.finish(false); - tpInput = new JTabbedPane(); tpInput.addTab("Dockerfile", p1); tpInput.addTab("Git Repository", p2); - // tpInput.addTab("Simple Input", p3); tpInput.setSelectedIndex(ContainerBuildContextMethod.FILE.ordinal()); grid.add(tpInput, 3).fill(true, false); @@ -110,17 +92,7 @@ public class ContainerUploadPageLayout extends WizardPage { grid.add(txtContainerRun, 2, 1).fill(true, false).expand(true, false); grid.nextRow(); - bindMountTable = new ContainerBindMountTable(); - QScrollPane jsp = new QScrollPane(bindMountTable); - grid.add(jsp, 3).fill(true, true).expand(true, true); - grid.nextRow(); - btnAddBindMount = new JButton("Add Bind Mount"); - btnDelBindMount = new JButton("Remove Bind Mount"); - grid.add(Box.createHorizontalBox(), 1).fill(true, false).expand(true, false); - grid.add(btnAddBindMount); - grid.add(btnDelBindMount); - - //grid.add(Box.createVerticalGlue(), 3).expand(true, true); + grid.add(Box.createVerticalGlue(), 3).expand(true, true); txtInfoText = new JTextArea(); txtInfoText.setBorder(BorderFactory.createTitledBorder("Hinweis")); txtInfoText.setLineWrap(true); @@ -128,7 +100,8 @@ public class ContainerUploadPageLayout extends WizardPage { txtInfoText.setEditable(false); txtInfoText.setFocusable(false); txtInfoText.setOpaque(false); - txtInfoText.setText("Container Info Text"); + txtInfoText.setText("In dieser Maske sind alle Infromationen zur Definition eines Container Images anzugeben. "); + grid.add(txtInfoText, 3).fill(true, false).expand(true, false); grid.nextRow(); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java index 4e6257e3..68b680c8 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java @@ -14,6 +14,7 @@ import javax.swing.text.html.HTMLEditorKit; import java.awt.Dimension; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.configurator.ContainerBindMountConfigurator; import org.openslx.dozmod.gui.control.ComboBox; import org.openslx.dozmod.gui.control.ComboBox.ComboBoxRenderer; import org.openslx.dozmod.gui.control.QLabel; @@ -23,9 +24,11 @@ import org.openslx.dozmod.gui.wizard.Wizard; import org.openslx.dozmod.gui.wizard.WizardPage; import org.openslx.thrifthelper.Comparators; -@SuppressWarnings("serial") -public abstract class ImageMetaDataPageLayout extends WizardPage { +import javax.swing.*; +@SuppressWarnings("serial") public abstract class ImageMetaDataPageLayout extends WizardPage { + + protected final QLabel lblOperatingSystem; protected final JComboBox<OperatingSystem> cboOperatingSystem; protected final JEditorPane txtDescription; protected final JTextArea startCommand; @@ -44,10 +47,12 @@ public abstract class ImageMetaDataPageLayout extends WizardPage { protected final HTMLEditorKit kit; + protected final ContainerBindMountConfigurator bindMountConfigurator; + /** * wizard page for entering image data at creating or editing an image - * - * @param wizard + * + * @param wizard The Wizard-object, which this extended {@link WizardPage} belongs to. */ public ImageMetaDataPageLayout(Wizard wizard) { super(wizard, I18n.PAGE_LAYOUT.getString("ImageMetaData.WizardPage.title")); @@ -55,7 +60,7 @@ public abstract class ImageMetaDataPageLayout extends WizardPage { GridManager grid = new GridManager(this, 3, false); - QLabel osCaption = new QLabel(I18n.PAGE_LAYOUT.getString("ImageMetaData.Label.OS.text")); + lblOperatingSystem = new QLabel(I18n.PAGE_LAYOUT.getString("ImageMetaData.Label.OS.text")); cboOperatingSystem = new ComboBox<>(Comparators.operatingSystem, new ComboBoxRenderer<OperatingSystem>() { @Override public String renderItem(OperatingSystem item) { @@ -65,7 +70,7 @@ public abstract class ImageMetaDataPageLayout extends WizardPage { } }); cboOperatingSystem.setEditable(false); - grid.add(osCaption); + grid.add(lblOperatingSystem); grid.add(cboOperatingSystem, 2); grid.nextRow(); @@ -137,6 +142,12 @@ public abstract class ImageMetaDataPageLayout extends WizardPage { grid.add(chkLicenseRestricted, 3); grid.nextRow(); + bindMountConfigurator = new ContainerBindMountConfigurator(); + bindMountConfigurator.setVisible(false); // only visible in container context + + grid.add(bindMountConfigurator, 2).fill(true, true).expand(true, true); + grid.nextRow(); + // -- end permissions group -- chkIsTemplate = new JCheckBox(I18n.PAGE_LAYOUT.getString("ImageMetaData.CheckBox.isTemplate.text")); grid.add(chkIsTemplate, 3); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageTypePageLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageTypePageLayout.java index c92784b9..7dac1103 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageTypePageLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageTypePageLayout.java @@ -29,26 +29,22 @@ public abstract class ImageTypePageLayout extends WizardPage { txtInfoText.setEditable(false); txtInfoText.setFocusable(false); txtInfoText.setOpaque(false); - txtInfoText.setText("Haben Sie noch keine eigene Virtuelle Maschine erstellt," - + " können Sie sich in der Übersicht eine Virtuelle Maschine als Vorlage herunterladen," - + " diese an Ihre Bedürfnisse anpassen und anschließend über diesen Assistenten hochladen." - + "\n\nWenn Sie die VM einer bestehenden Veranstaltung aktualisieren möchten," - + " öffnen Sie die Detailansicht der bestehenden VM und wählen Sie 'Neue VM-Version hochladen'." - + " Dadurch bleiben bestehende Berechtigungen, sowie Verknüpfungen zu Veranstaltungen erhalten."); + txtInfoText.setText("Hier haben Sie die Möglichkeit ein neues Image als VM oder Container (Docker) " + + "zu definieren.\n\n" + + "Sie besitzen derzeit eine Entwicklungsstand der bwLehrpool Suite, in der sämtliche " + + "Funktionalitäten zur Erstellung und Verwaltung von Container Images in Entwicklung sind. " + + "Diese Funktionen können sich in späteren Versionen ändern und somit ihre erstellten Images " + + "inkompatibel machen."); grid.add(txtInfoText, 4).fill(true, false).expand(true, false); grid.nextRow(); grid.nextRow(); // -- New VM Pick-- btnNewVmImage = new JButton("New VM"); - grid.add(btnNewVmImage,2,2) - .fill(true,true) - .expand(true,true); + grid.add(btnNewVmImage, 2, 2).fill(true, true).expand(true, true); // -- New Docker-Image Pick-- btnNewDockerImage = new JButton("new Docker-Image"); - grid.add(btnNewDockerImage,2,2) - .fill(true,true) - .expand(true,true); + grid.add(btnNewDockerImage, 2, 2).fill(true, true).expand(true, true); grid.finish(false); 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()) { |