From 190d68aa75dde0b6c5535ddfbfb0b257ec9b210c Mon Sep 17 00:00:00 2001 From: ralph isenmann Date: Tue, 22 Jun 2021 17:32:59 +0200 Subject: [client] Set Container Image Type during creation, set text labes --- .../openslx/dozmod/gui/panel/ContainerPanel.java | 13 +++++- .../dozmod/gui/wizard/ImageCreationWizard.java | 49 +++++++++++++++++----- .../wizard/layout/ContainerUploadPageLayout.java | 16 ++++--- .../gui/wizard/layout/ImageMetaDataPageLayout.java | 23 ++++++++++ .../gui/wizard/page/ContainerUploadPage.java | 39 ++++------------- .../dozmod/gui/wizard/page/ImageMetaDataPage.java | 41 ++++++++++++++---- .../src/main/properties/i18n/panel.properties | 4 ++ .../main/properties/i18n/panel_de_DE.properties | 1 + 8 files changed, 127 insertions(+), 59 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 a3b5ee3b..621bdba2 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 @@ -63,7 +63,8 @@ public class ContainerPanel extends JPanel { grdContainerMeta.add(txtContainerRun, 2).fill(true, false).expand(true, false); grdContainerMeta.nextRow(); - QLabel lblContainerRunCommand = new QLabel("Container Run Command"); + QLabel lblContainerRunCommand = new QLabel( + I18n.PANEL.getString("ContainerPanel.ContainerRunCommand.label")); txtContainerRunCommand = new JTextField(); grdContainerMeta.add(lblContainerRunCommand); grdContainerMeta.add(txtContainerRunCommand, 2).fill(true, false).expand(true, false); @@ -161,6 +162,16 @@ public class ContainerPanel extends JPanel { private void initImageDetails() { + cboContainerImageType.setSelectedItem(containerDefinition.getContainerMeta().getImageType()); + if (containerDefinition.getContainerMeta().getImageType() == ContainerMeta.ContainerImageType.DATA) { + // do not allowed to change type if it is data + cboContainerImageType.setEnabled(false); + } + else { + // do not allow to switch type to data after creation + cboContainerImageType.removeItem(ContainerMeta.ContainerImageType.DATA); + } + // currently do not allow user to change the Image Repository or Dockerfile in the suite. txtContainerRecipe.setEnabled(false); 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 a51b2163..33ed8800 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,23 +10,24 @@ 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.sat.thrift.version.Feature; import org.openslx.thrifthelper.ThriftManager; import org.openslx.util.QuickTimer; import org.openslx.util.QuickTimer.Task; +import org.openslx.virtualization.configuration.VirtualizationConfigurationDocker; import javax.swing.*; import java.awt.*; +import java.io.IOException; +import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; -public class ImageCreationWizard extends Wizard - implements UiFeedback, QuitNotification { +public class ImageCreationWizard extends Wizard implements UiFeedback, QuitNotification { /** * Version for serialization. @@ -37,6 +38,8 @@ public class ImageCreationWizard extends Wizard private final UploadWizardState state = new UploadWizardState(); + private final ContainerDefinition containerDefinition = new ContainerDefinition(); + private List currentPages = new ArrayList<>(); private boolean baseWritten = false; @@ -53,8 +56,7 @@ public class ImageCreationWizard extends Wizard if (Session.hasFeature(Feature.DOCKER_CONTAINER)) { addPage(new ImageTypePage(this)); - } - else { + } else { doVmCreation(); } } @@ -81,8 +83,8 @@ public class ImageCreationWizard extends Wizard public void doDockerCreation() { cleanCurrent(); - currentPages.add(new ContainerUploadPage(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(); } @@ -105,6 +107,31 @@ public class ImageCreationWizard extends Wizard } @Override public boolean wantFinish() { + + // In order for settings for a container to be recorded in the ImageMetaDataPage for the ContainerDefinition, + // the UploadInitiator was only allowed to be created here. + // TODO maybe also for VM-Images this is suitable + if (state.virtualizationConfig instanceof VirtualizationConfigurationDocker) { + // 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, + ByteBuffer.wrap(state.virtualizationConfig.getConfigurationAsByteArray())); + } 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(); + } + // 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. @@ -228,8 +255,8 @@ public class ImageCreationWizard extends Wizard private ImageBaseWrite imageBaseWriteFromState() { // build imageBaseWrite return new ImageBaseWrite(state.name, state.description, state.selectedOs.getOsId(), - state.virtualizationConfig.getVirtualizer().getId(), state.isTemplate, state.defaultPermissions, - state.shareMode); + state.virtualizationConfig.getVirtualizer().getId(), state.isTemplate, + state.defaultPermissions, state.shareMode); } @Override protected final void doPrevious() { 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 0496261f..5e6769e8 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 @@ -42,9 +42,8 @@ public class ContainerUploadPageLayout extends WizardPage { 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")); + GridManager tmpGrid = new GridManager(imageRepoPanel, 2, true, new Insets(0, 5, 0, 5)); + QLabel lblImageRepo = new QLabel(I18n.PAGE_LAYOUT.getString("ContainerUploadPage.ImageRepo.label")); lblImageRepo.setToolTipText( I18n.PAGE_LAYOUT.getString("ContainerUploadPage.ImageRepository.ToolTipText")); txtImageRepo = new JTextField(); @@ -55,10 +54,9 @@ public class ContainerUploadPageLayout extends WizardPage { tmpGrid.add(txtImageRepo).fill(true, false).expand(true, false); tmpGrid.finish(false); - JPanel p1 = new JPanel(); p1.setVisible(false); - GridManager g1 = new GridManager(p1, 3, true, new Insets(5, 0, 5, 0)); + GridManager g1 = new GridManager(p1, 3, true, new Insets(0, 5, 0, 5)); QLabel imageFileCaption = new QLabel( I18n.PAGE_LAYOUT.getString("ContainerUploadPage.DockerFile.label")); txtImageFile = new JTextField(); @@ -72,7 +70,7 @@ public class ContainerUploadPageLayout extends WizardPage { JPanel p2 = new JPanel(); p2.setVisible(false); - GridManager g2 = new GridManager(p2, 2, true, new Insets(5, 0, 5, 0)); + GridManager g2 = new GridManager(p2, 2, true, new Insets(0, 5, 0, 5)); QLabel lblGitRepo = new QLabel(I18n.PAGE_LAYOUT.getString("ContainerUploadPage.GitRepository.label")); lblGitRepo.setToolTipText( I18n.PAGE_LAYOUT.getString("ContainerUploadPage.GitRepository.toolTipText")); @@ -91,6 +89,7 @@ public class ContainerUploadPageLayout extends WizardPage { tpInput.setSelectedIndex(2); grid.add(tpInput, 3).fill(true, false); + grid.nextRow(); lblImageName = new QLabel(I18n.PANEL.getString("ContainerPanel.Label.ImageName.text")); txtImageName = new JTextField(); @@ -105,12 +104,11 @@ public class ContainerUploadPageLayout extends WizardPage { txtContainerImageFile = new JTextField(); txtContainerImageFile.setEnabled(false); txtContainerImageFile.setToolTipText( - I18n.PAGE_LAYOUT.getString("ContainerUploadPage.ContainerImageFile.ToolTipText") - ); + I18n.PAGE_LAYOUT.getString("ContainerUploadPage.ContainerImageFile.ToolTipText")); grid.add(lblContainerImageFile); grid.add(txtContainerImageFile, 2).fill(true, false).expand(true, false); grid.nextRow(); - + grid.add(Box.createVerticalGlue(), 3).expand(true, true); txtInfoText = new JTextArea(); txtInfoText.setBorder(BorderFactory.createTitledBorder( 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 63089274..63b7f498 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 @@ -9,6 +9,7 @@ import org.openslx.dozmod.gui.helper.GridManager; import org.openslx.dozmod.gui.helper.I18n; import org.openslx.dozmod.gui.wizard.Wizard; import org.openslx.dozmod.gui.wizard.WizardPage; +import org.openslx.dozmod.model.ContainerMeta; import org.openslx.thrifthelper.Comparators; import javax.swing.*; @@ -26,6 +27,9 @@ public abstract class ImageMetaDataPageLayout extends WizardPage { protected final JCheckBox chkLicenseRestricted; protected final JCheckBox chkIsTemplate; + protected final QLabel lblContainerImageType; + protected final ComboBox cboContainerImageType; + /** * wizard page for entering image data at creating or editing an image * @@ -70,6 +74,25 @@ public abstract class ImageMetaDataPageLayout extends WizardPage { grid.add(chkLicenseRestricted, 2); grid.nextRow(); + lblContainerImageType = new QLabel("Container Image Type"); + cboContainerImageType = new ComboBox<>( + new ComboBox.ComboBoxRenderer() { + @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); + grid.add(lblContainerImageType); + grid.add(cboContainerImageType).fill(true, false).expand(true, false); + lblContainerImageType.setVisible(false); + cboContainerImageType.setVisible(false); + 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 466b26a0..7d6e4899 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,9 +4,7 @@ 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; @@ -16,9 +14,6 @@ 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.virtualization.configuration.VirtualizationConfigurationDocker; @@ -32,7 +27,6 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.io.File; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -50,7 +44,7 @@ public class ContainerUploadPage extends ContainerUploadPageLayout { private final UploadWizardState state; private final ImageDetailsRead existingImage; - private final ContainerDefinition containerDefinition; + private ContainerDefinition containerDefinition; /** * Page for uploading an Container Image @@ -99,6 +93,12 @@ public class ContainerUploadPage extends ContainerUploadPageLayout { init(); } + public ContainerUploadPage(Wizard wizard, UploadWizardState state, + ContainerDefinition containerDefinition) { + this(wizard, state); + this.containerDefinition = containerDefinition; + } + private void init() { this.txtImageFile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -266,7 +266,6 @@ public class ContainerUploadPage extends ContainerUploadPageLayout { containerMeta.setBuildContextMethod(getBuildContextMethod().ordinal()); containerMeta.setImageName(txtImageName.getText()); - File containerImageFile = new File(txtContainerImageFile.getText()); if (containerImageFile.exists()) state.diskFile = containerImageFile; @@ -301,16 +300,13 @@ public class ContainerUploadPage extends ContainerUploadPageLayout { * 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.virtualizationConfig = createVirtualizationConfig(); // -- create image to get uuid -- if (existingImage == null) { if (state.uuid == null) { state.uuid = ThriftActions.createImage(JOptionPane.getFrameForComponent(this), state.name); + state.name = txtImageName.getText(); if (state.uuid == null) return false; txtImageName.setEnabled(false); @@ -319,25 +315,8 @@ public class ContainerUploadPage extends ContainerUploadPageLayout { } } else { state.uuid = existingImage.getImageBaseId(); + state.name = existingImage.getImageName(); } - // 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, - ByteBuffer.wrap(state.virtualizationConfig.getConfigurationAsByteArray())); - } 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 e6fcc783..a604c167 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 @@ -7,6 +7,8 @@ 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.model.ContainerMeta; import org.openslx.dozmod.state.UploadWizardState; import org.openslx.dozmod.thrift.Session; import org.openslx.dozmod.thrift.cache.MetaDataCache; @@ -15,6 +17,8 @@ import org.openslx.util.QuickTimer; import org.openslx.util.QuickTimer.Task; import org.openslx.virtualization.configuration.VirtualizationConfigurationDocker; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.Collections; @@ -70,6 +74,32 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout { }); } + private ContainerDefinition containerDefinition; + + public ImageMetaDataPage(Wizard wizard, UploadWizardState state, + ContainerDefinition containerDefinition) { + this(wizard, state); + this.containerDefinition = containerDefinition; + + // 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); + + // meta attribute for container images + lblContainerImageType.setVisible(true); + cboContainerImageType.setVisible(true); + cboContainerImageType.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent actionEvent) { + reactToUserInput(); + } + }); + } + @Override protected void onPageEnter() { // Preselect OS if possible if (state.detectedOs != null) { @@ -114,14 +144,9 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout { } if (state.virtualizationConfig instanceof VirtualizationConfigurationDocker) { - // 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); + containerDefinition.getContainerMeta() + .setImageType((ContainerMeta.ContainerImageType) cboContainerImageType.getSelectedItem()); + state.virtualizationConfig = containerDefinition.createVirtualizationConfig(); } // evaluate description field diff --git a/dozentenmodul/src/main/properties/i18n/panel.properties b/dozentenmodul/src/main/properties/i18n/panel.properties index a8db9131..f78c5f36 100644 --- a/dozentenmodul/src/main/properties/i18n/panel.properties +++ b/dozentenmodul/src/main/properties/i18n/panel.properties @@ -5,6 +5,10 @@ ContainerPanel.Label.ImageName.text=Image Name ContainerPanel.Constraint.NoEmptyDockerfile.text=Empty Dockerfile not allowed! +ContainerPanel.ContainerRunCommand.label="Container Run Command" + # UNUSED ImageDetails.Constraint.NoEmptyName.text=Empty Name not allowed! ImageDetails.Constraint.NoEmptyRunOptions.text=No Container Run Options provided! + + diff --git a/dozentenmodul/src/main/properties/i18n/panel_de_DE.properties b/dozentenmodul/src/main/properties/i18n/panel_de_DE.properties index 832480bb..440978dd 100644 --- a/dozentenmodul/src/main/properties/i18n/panel_de_DE.properties +++ b/dozentenmodul/src/main/properties/i18n/panel_de_DE.properties @@ -8,3 +8,4 @@ ContainerPanel.Constraint.NoEmptyDockerfile.text=Es muss ein Dockerfile angegebe # UNUSED ImageDetails.Constraint.NoEmptyName.text=Es muss ein Name angegeben werden! ImageDetails.Constraint.NoEmptyRunOptions.text=Keine Container Start Optionen angegeben! +ContainerPanel.ContainerRunCommand.label="Container Run Befehl" -- cgit v1.2.3-55-g7522