summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorralph isenmann2020-11-05 14:43:56 +0100
committerralph isenmann2020-11-05 14:52:51 +0100
commitb9c93240a820613df1fd93255d959effd94427c7 (patch)
treed1ca97d172d1524b3d249219a55f4fb61691ce25
parent[client] FIX image update (diff)
downloadtutor-module-b9c93240a820613df1fd93255d959effd94427c7.tar.gz
tutor-module-b9c93240a820613df1fd93255d959effd94427c7.tar.xz
tutor-module-b9c93240a820613df1fd93255d959effd94427c7.zip
[client] move BindMountConfigurator to ImageMetaDataPage
- move creation of UploadInitiator into ImageCreationWizard (initUpload).
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageCreationWizard.java113
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ContainerUploadPageLayout.java11
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java9
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java60
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java20
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerDefinition.java4
6 files changed, 119 insertions, 98 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 ea5a3c7a..135738d9 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;
@@ -15,22 +9,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;
-@SuppressWarnings("serial")
-public class ImageCreationWizard extends Wizard implements UiFeedback, QuitNotification {
+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 {
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;
@@ -38,8 +40,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);
@@ -55,7 +57,7 @@ public class ImageCreationWizard extends Wizard implements UiFeedback, QuitNotif
cleanCurrent();
currentPages.add(new ImageUploadPage(this, state, null));
- currentPages.add(new ImageMetaDataPage(this, state));
+ currentPages.add(new ImageMetaDataPage(this, state, null));
currentPages.add(new ImageCustomPermissionPage(this, state));
addPages();
}
@@ -66,32 +68,68 @@ public class ImageCreationWizard extends Wizard implements UiFeedback, QuitNotif
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();
}
private void addPages() {
- for (WizardPage i:currentPages) {
+ for (WizardPage i : currentPages) {
addPage(i);
}
}
private void cleanCurrent() {
- if( !currentPages.isEmpty()) {
+ if (!currentPages.isEmpty()) {
removePages(currentPages);
currentPages = new ArrayList<WizardPage>();
}
}
- @Override
- public String getWindowTitle() {
+ @Override public String getWindowTitle() {
return "Neue VM erzeugen";
}
- @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.
@@ -129,16 +167,15 @@ 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(), new ImageVersionWrite(
- state.isRestricted));
+ ThriftActions.updateImageVersion(state.upload.getToken(),
+ new ImageVersionWrite(state.isRestricted));
} catch (TException e) {
if (state.isRestricted) {
Gui.showMessageBox(null, "Unerwarteter Fehler beim Setzen der Option"
- + " 'Enthält lizenzpflichtige Software' für diese Virtuelle Maschine.",
+ + " 'Enthält lizenzpflichtige Software' für diese Virtuelle Maschine.",
MessageType.WARNING, LOGGER, e);
}
}
@@ -147,16 +184,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
@@ -220,16 +256,14 @@ public class ImageCreationWizard extends Wizard implements UiFeedback, QuitNotif
state.shareMode);
}
- @Override
- protected boolean onCancelRequest() {
+ @Override protected boolean onCancelRequest() {
if (state.uuid == null)
return true;
boolean confirmed = Gui.showMessageBox(this, "Möchten Sie den Vorgang wirklich abbrechen?",
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();
}
@@ -245,18 +279,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/layout/ContainerUploadPageLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ContainerUploadPageLayout.java
index e0efde7f..928c7c3f 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,6 +1,5 @@
package org.openslx.dozmod.gui.wizard.layout;
-import org.openslx.dozmod.gui.configurator.ContainerBindMountConfigurator;
import org.openslx.dozmod.gui.control.QLabel;
import org.openslx.dozmod.gui.helper.GridManager;
import org.openslx.dozmod.gui.wizard.Wizard;
@@ -26,8 +25,6 @@ public class ContainerUploadPageLayout extends WizardPage {
protected final JTabbedPane tpInput;
protected final JTextField txtGitRepo;
- protected ContainerBindMountConfigurator bindMountConfigurator;
-
// TODO set proper Text labels
/**
@@ -39,8 +36,6 @@ public class ContainerUploadPageLayout extends WizardPage {
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));
@@ -97,10 +92,6 @@ public class ContainerUploadPageLayout extends WizardPage {
grid.add(txtContainerRun, 2, 1).fill(true, false).expand(true, false);
grid.nextRow();
- bindMountConfigurator = new ContainerBindMountConfigurator();
- grid.add(bindMountConfigurator, 3).fill(true, true).expand(true, true);
- grid.nextRow();
-
//grid.add(Box.createVerticalGlue(), 3).expand(true, true);
txtInfoText = new JTextArea();
txtInfoText.setBorder(BorderFactory.createTitledBorder("Hinweis"));
@@ -109,7 +100,7 @@ public class ContainerUploadPageLayout extends WizardPage {
txtInfoText.setEditable(false);
txtInfoText.setFocusable(false);
txtInfoText.setOpaque(false);
- txtInfoText.setText("Container Info Text");
+ txtInfoText.setText("Container Info Text \n Container Info Text \n Container Info Text \n");
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 358fdd0d..fbec5bf4 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
@@ -7,6 +7,7 @@ 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;
@@ -26,6 +27,8 @@ public abstract class ImageMetaDataPageLayout extends WizardPage {
protected final JCheckBox chkLicenseRestricted;
protected final JCheckBox chkIsTemplate;
+ protected final ContainerBindMountConfigurator bindMountConfigurator;
+
/**
* wizard page for entering image data at creating or editing an image
*
@@ -79,6 +82,12 @@ public abstract class ImageMetaDataPageLayout extends WizardPage {
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("Vorlage erstellen");
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 9004a957..3ce75f37 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,8 +4,6 @@ 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.MessageType;
import org.openslx.dozmod.gui.helper.QFileChooser;
import org.openslx.dozmod.gui.helper.TextChangeListener;
import org.openslx.dozmod.gui.wizard.Wizard;
@@ -14,10 +12,6 @@ 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;
@@ -41,12 +35,15 @@ public class ContainerUploadPage extends ContainerUploadPageLayout {
*/
private final UploadWizardState state;
private final ImageDetailsRead existingImage;
+ private final ContainerDefinition containerDefinition;
- public ContainerUploadPage(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
@@ -55,6 +52,8 @@ public class ContainerUploadPage extends ContainerUploadPageLayout {
init();
}
+ // 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);
@@ -62,6 +61,9 @@ public class ContainerUploadPage extends ContainerUploadPageLayout {
state = uploadWizardState;
existingImage = imageDetailsRead;
+ // TODO fix this!
+ containerDefinition = null;
+
lblImageName.setEnabled(existingImage == null);
txtImageName.setEnabled(existingImage == null);
txtInfoText.setVisible(existingImage == null);
@@ -114,7 +116,6 @@ public class ContainerUploadPage extends ContainerUploadPageLayout {
});
btnBrowseForImage.requestFocus();
- txtInfoText.setText("Many Text");
}
private void browseFile() {
@@ -211,24 +212,21 @@ public class ContainerUploadPage 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(bindMountConfigurator.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() {
@@ -238,36 +236,6 @@ public class ContainerUploadPage extends ContainerUploadPageLayout {
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;
}
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 1ec57fce..785e3289 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
@@ -12,12 +12,14 @@ import org.openslx.dozmod.gui.Gui;
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;
/**
@@ -29,10 +31,12 @@ 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;
@@ -92,6 +96,11 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout {
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;
}
@@ -123,6 +132,15 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout {
startCommandPane.setVisible(true);
}
+ if (state.meta instanceof DockerMetaDataDummy) {
+ bindMountConfigurator.setVisible(true);
+
+ // 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()) {
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerDefinition.java b/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerDefinition.java
index a5c24534..872c734f 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerDefinition.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerDefinition.java
@@ -68,6 +68,10 @@ public class ContainerDefinition {
this.containerRecipe = containerRecipe;
}
+ public void setContainerRecipe(File containerRecipeFile) {
+ this.containerRecipe = readContainerRecipe(containerRecipeFile);
+ }
+
public void setContainerRecipe(byte[] rawContainerRecipe) {
this.containerRecipe = new String(rawContainerRecipe, StandardCharsets.UTF_8);
}