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/ImageCreationWizard.java | |
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/ImageCreationWizard.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageCreationWizard.java | 96 |
1 files changed, 64 insertions, 32 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(); } |