diff options
author | ralph isenmann | 2021-02-15 11:42:17 +0100 |
---|---|---|
committer | ralph isenmann | 2021-02-15 11:42:17 +0100 |
commit | 793b25c3029250567454aa542b78cfe83745edc3 (patch) | |
tree | 8407d5dc0a14641ab985f19bc40bbbeb5a74672f /dozentenmodul/src/main | |
parent | [client] Add ContainerPanel in ImageDetails and LectureDetails (diff) | |
download | tutor-module-793b25c3029250567454aa542b78cfe83745edc3.tar.gz tutor-module-793b25c3029250567454aa542b78cfe83745edc3.tar.xz tutor-module-793b25c3029250567454aa542b78cfe83745edc3.zip |
[client] Update ImageCreation for Container Images workflow
Remove Container Runtime specific informations (Run and Mount Options). These Options can be defined in the LectureDetails Window.
Diffstat (limited to 'dozentenmodul/src/main')
5 files changed, 92 insertions, 126 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 cccabe00..1a972b46 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 @@ -10,18 +10,17 @@ 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.*; +import org.openslx.dozmod.thrift.Session; +import org.openslx.dozmod.thrift.ThriftActions; +import org.openslx.dozmod.thrift.ThriftError; 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; @@ -32,8 +31,6 @@ import java.util.List; private final UploadWizardState state = new UploadWizardState(); - private ContainerDefinition containerDefinition = new ContainerDefinition(); - private List<WizardPage> currentPages = new ArrayList<>(); private boolean baseWritten = false; @@ -59,7 +56,7 @@ import java.util.List; cleanCurrent(); state.imageUploadPage = new ImageUploadPage(this, state, null); currentPages.add(state.imageUploadPage); - currentPages.add(new ImageMetaDataPage(this, state, null)); + currentPages.add(new ImageMetaDataPage(this, state)); currentPages.add(new ImageCustomPermissionPage(this, state)); addPages(); @@ -73,8 +70,8 @@ import java.util.List; public void doDockerCreation() { cleanCurrent(); - currentPages.add(new ContainerUploadPage(this, state, containerDefinition)); - currentPages.add(new ImageMetaDataPage(this, state, containerDefinition)); + currentPages.add(new ContainerUploadPage(this, state)); + currentPages.add(new ImageMetaDataPage(this, state)); currentPages.add(new ImageCustomPermissionPage(this, state)); addPages(); } @@ -92,49 +89,11 @@ import java.util.List; } } - @Override - public String getWindowTitle() { + @Override public String getWindowTitle() { return I18n.WIZARD.getString("ImageCreation.Wizard.title"); } - /** - * 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, I18n.WIZARD.getString("ImageCreation.Message.error.UploadInitializationFailure"), 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. @@ -162,7 +121,8 @@ import java.util.List; try { ThriftActions.writeImagePermissions(state.uuid, state.permissionMap); } catch (TException e) { - Gui.showMessageBox(this, I18n.WIZARD.getString("ImageCreation.Message.error.permissionsNotWritten"), + Gui.showMessageBox(this, + I18n.WIZARD.getString("ImageCreation.Message.error.permissionsNotWritten"), MessageType.ERROR, null, null); ThriftActions.deleteImageBase(JOptionPane.getFrameForComponent(this), state.uuid); return false; @@ -261,8 +221,7 @@ import java.util.List; state.shareMode); } - @Override - protected final void doPrevious() { + @Override protected final void doPrevious() { if (outOfOrderPage != null) { outOfOrderPage = null; returnAfterOutOfOrderPage(state.imageUploadPage, state.conversionPage); @@ -271,8 +230,7 @@ import java.util.List; } } - @Override - public final void doNext() { + @Override public final void doNext() { if (outOfOrderPage != null) { outOfOrderPage = null; returnAfterOutOfOrderPage(state.imageUploadPage, state.conversionPage); @@ -281,11 +239,11 @@ import java.util.List; } } - @Override - protected boolean onCancelRequest() { + @Override protected boolean onCancelRequest() { if (state.uuid == null) return true; - boolean confirmed = Gui.showMessageBox(this, I18n.WIZARD.getString("ImageCreation.Message.yesNo.cancelRequest"), + boolean confirmed = Gui.showMessageBox(this, + I18n.WIZARD.getString("ImageCreation.Message.yesNo.cancelRequest"), MessageType.QUESTION_YESNO, null, null); if (confirmed) { QuickTimer.scheduleOnce(new Task() { 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 7d873264..57eed300 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 @@ -20,16 +20,11 @@ public class ContainerUploadPageLayout extends WizardPage { protected final QLabel lblImageName; protected final JTextArea txtInfoText; - protected final JTextField txtContainerRun; - protected final QLabel lblContainerRun; - protected final JTabbedPane tpInput; protected final JTextField txtGitRepo; - // TODO set proper Text labels - /** - * Page for uploading an imagefile + * Constructor to define the Layout */ public ContainerUploadPageLayout(Wizard wizard) { @@ -87,12 +82,12 @@ public class ContainerUploadPageLayout extends WizardPage { grid.add(chkLicenseRestricted, 2, 1).fill(false, false).expand(true, false); grid.nextRow(); - lblContainerRun = new QLabel(I18n.PAGE_LAYOUT.getString("ContainerUploadPage.ContainerStartOptions.label")); - lblContainerRun.setToolTipText(I18n.PAGE_LAYOUT.getString("ContainerUploadPage.ContainerStartOptions.tooltip")); - txtContainerRun = new JTextField(); - grid.add(lblContainerRun); - grid.add(txtContainerRun, 2, 1).fill(true, false).expand(true, false); - grid.nextRow(); +// lblContainerRun = new QLabel(I18n.PAGE_LAYOUT.getString("ContainerUploadPage.ContainerStartOptions.label")); +// lblContainerRun.setToolTipText(I18n.PAGE_LAYOUT.getString("ContainerUploadPage.ContainerStartOptions.tooltip")); +// txtContainerRun = new JTextField(); +// grid.add(lblContainerRun); +// grid.add(txtContainerRun, 2, 1).fill(true, false).expand(true, false); +// grid.nextRow(); grid.add(Box.createVerticalGlue(), 3).expand(true, true); txtInfoText = new JTextArea(); 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 8d53cba5..862712ea 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 @@ -1,15 +1,7 @@ package org.openslx.dozmod.gui.wizard.layout; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JEditorPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; - 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; @@ -32,8 +24,6 @@ import javax.swing.*; protected final JCheckBox chkLicenseRestricted; protected final JCheckBox chkIsTemplate; - protected final ContainerBindMountConfigurator bindMountConfigurator; - /** * wizard page for entering image data at creating or editing an image * @@ -46,14 +36,14 @@ import javax.swing.*; GridManager grid = new GridManager(this, 2, false); 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) { - if (item == null) - return null; - return item.getOsName(); - } - }); + cboOperatingSystem = new ComboBox<>(Comparators.operatingSystem, + new ComboBoxRenderer<OperatingSystem>() { + @Override public String renderItem(OperatingSystem item) { + if (item == null) + return null; + return item.getOsName(); + } + }); cboOperatingSystem.setEditable(false); grid.add(lblOperatingSystem); grid.add(cboOperatingSystem); @@ -71,9 +61,9 @@ import javax.swing.*; grid.add(startCommandPane).fill(true, false).expand(true, false); grid.nextRow(); - // description - QLabel descriptionCaption = new QLabel(I18n.PAGE_LAYOUT.getString("ImageMetaData.Label.description.text")); + QLabel descriptionCaption = new QLabel( + I18n.PAGE_LAYOUT.getString("ImageMetaData.Label.description.text")); txtDescription = new JEditorPane(); txtDescription.setMinimumSize(Gui.getScaledDimension(0, 70)); JScrollPane descPane = new JScrollPane(txtDescription, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, @@ -88,12 +78,6 @@ import javax.swing.*; grid.add(chkLicenseRestricted, 2); 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, 2); 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 f784d844..234e0a0e 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 @@ -4,7 +4,9 @@ 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.I18n; +import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.gui.helper.QFileChooser; import org.openslx.dozmod.gui.helper.TextChangeListener; import org.openslx.dozmod.gui.wizard.Wizard; @@ -13,6 +15,10 @@ 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.ThriftActions; +import org.openslx.dozmod.thrift.ThriftError; +import org.openslx.dozmod.thrift.UploadInitiator; +import org.openslx.dozmod.thrift.WrappedException; import org.openslx.dozmod.thrift.cache.MetaDataCache; import org.openslx.util.vm.DockerMetaDataDummy; @@ -43,10 +49,9 @@ public class ContainerUploadPage extends ContainerUploadPageLayout { private final ImageDetailsRead existingImage; private final ContainerDefinition containerDefinition; - public ContainerUploadPage(Wizard wizard, final UploadWizardState state, - ContainerDefinition containerDefinition) { + public ContainerUploadPage(Wizard wizard, final UploadWizardState state) { super(wizard); - this.containerDefinition = containerDefinition; + this.containerDefinition = new ContainerDefinition(); this.state = state; canComeBack = false; @@ -103,11 +108,6 @@ public class ContainerUploadPage extends ContainerUploadPageLayout { reactOnUserInput(); } }); - txtContainerRun.getDocument().addDocumentListener(new TextChangeListener() { - @Override public void changed() { - reactOnUserInput(); - } - }); tpInput.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { @@ -207,10 +207,10 @@ public class ContainerUploadPage extends ContainerUploadPageLayout { return false; } - if (txtContainerRun.getText() == null || txtContainerRun.getText().isEmpty()) { - setWarningMessage(I18n.PAGE.getString("ContainerUploadPage.Warning.NoRunOptions")); - return false; - } +// if (txtContainerRun.getText() == null || txtContainerRun.getText().isEmpty()) { +// setWarningMessage(I18n.PAGE.getString("ContainerUploadPage.Warning.NoRunOptions")); +// return false; +// } return true; } @@ -219,7 +219,6 @@ public class ContainerUploadPage extends ContainerUploadPageLayout { ContainerMeta containerMeta = containerDefinition.getContainerMeta(); containerMeta.setBuildContextMethod(getBuildContextMethod().ordinal()); containerMeta.setImageName(txtImageName.getText()); - containerMeta.setRunOptions(txtContainerRun.getText()); switch (containerDefinition.getBuildContextMethod()) { case FILE: containerDefinition.setContainerRecipe(state.descriptionFile); @@ -233,10 +232,57 @@ public class ContainerUploadPage extends ContainerUploadPageLayout { return containerDefinition.createVmMeta(); } + /** + * This function starts the image creation process. It is triggered by the + * "Next" button. + * + * Depending on the state, it will first try to get a UUID for the new image by + * calling createImage() of the thrift API. If a UUID is received, it will + * request an upload with requestImageVersionUpload(). If granted, it will + * finally start a thread for the UploadTask. + * + * Then a callback to the Gui is executed where we can process the upload state + * and give the user feedback about it. + * + */ @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, + I18n.PAGE.getString("ImageUpload.Message.error.uploadInitiatorFailed"), + MessageType.ERROR, LOGGER, e); + return false; + } + } + // Start the hash check now + state.upload.startHashing(); return true; } 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 f2010da1..a20ef8b6 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 @@ -1,10 +1,5 @@ package org.openslx.dozmod.gui.wizard.page; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.util.Collections; -import java.util.List; - import org.apache.log4j.Logger; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.ShareMode; @@ -13,7 +8,6 @@ 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; @@ -36,13 +30,10 @@ import java.util.List; private final static Logger LOGGER = Logger.getLogger(ImageMetaDataPage.class); private UploadWizardState state; - private final ContainerDefinition containerDefinition; - public ImageMetaDataPage(Wizard wizard, UploadWizardState uploadWizardState, - ContainerDefinition containerDefinition) { + public ImageMetaDataPage(Wizard wizard, UploadWizardState uploadWizardState) { super(wizard); this.state = uploadWizardState; - this.containerDefinition = containerDefinition; setPageComplete(false); // HACK set fixed uploadWizardState to test functions uploadWizardState.shareMode = ShareMode.LOCAL; @@ -78,9 +69,7 @@ import java.util.List; }); } - - @Override - protected void onPageEnter() { + @Override protected void onPageEnter() { // Preselect OS if possible if (state.detectedOs != null) { cboOperatingSystem.setSelectedItem(state.detectedOs); @@ -99,10 +88,6 @@ import java.util.List; 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; } @@ -134,8 +119,6 @@ import java.util.List; } 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); |