diff options
5 files changed, 102 insertions, 29 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java index a75117c9..a022c92f 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java @@ -10,7 +10,6 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.window.Window; import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.SelectionAdapter; diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java index 4fb439b6..0fd41d46 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java @@ -7,7 +7,6 @@ import org.openslx.bwlp.thrift.iface.ImageBaseWrite; import org.openslx.bwlp.thrift.iface.ImageDetailsRead; import org.openslx.dozmod.gui.MainWindow; import org.openslx.dozmod.gui.helper.MessageType; -import org.openslx.dozmod.gui.wizard.page.ImageCustomPermissionPage; import org.openslx.dozmod.gui.wizard.page.ImageMetaDataPage; import org.openslx.dozmod.gui.wizard.page.ImageUploadPage; import org.openslx.dozmod.state.UploadWizardState; @@ -96,9 +95,11 @@ public class ImageWizard extends Wizard { // it did work :) LOGGER.debug(imageDetailsRead.toString()); MainWindow.showMessageBox("Creation of image worked :)", MessageType.INFO, LOGGER, null); - } else + return true; + } else { MainWindow.showMessageBox("Creation of image failed :(", MessageType.ERROR, LOGGER, null); - return true; + return false; + } } private boolean isStateValid() { 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 ae8f394f..98739897 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,6 +1,5 @@ package org.openslx.dozmod.gui.wizard.page; -import java.util.HashMap; import java.util.List; import org.apache.log4j.Logger; @@ -29,15 +28,12 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout { super(); this.uploadWizardState = uploadWizardState; setPageComplete(false); - + setMessage("Bitte wählen Sie das Betriebssystem aus und fügen Sie eine Beschreibung hinzu."); // HACK set fixed uploadWizardState to test functions - uploadWizardState.diskFile = uploadWizardState.descriptionFile; uploadWizardState.isTemplate = false; uploadWizardState.permissions = new ImagePermissions(true, false, true, false); uploadWizardState.shareMode = ShareMode.LOCAL; uploadWizardState.virtualizer = MetaDataCache.getVirtualizers().get(0); - uploadWizardState.operatingSystem = MetaDataCache.getOperatingSystems().get(0); - uploadWizardState.operatingSystem.putToVirtualizerOsId(uploadWizardState.virtualizer.getVirtName(), uploadWizardState.virtualizer.getVirtId()); } @Override @@ -63,18 +59,22 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout { }); osCombo.addSelectionListener(new SelectionAdapter() { - @SuppressWarnings("serial") @Override public void widgetSelected(SelectionEvent e) { - int selectionIndex = osCombo.getSelectionIndex(); - if (osCombo.getSelectionIndex() != -1) { + final int selectionIndex = osCombo.getSelectionIndex(); + if (selectionIndex != -1) { uploadWizardState.operatingSystem = (OperatingSystem) osCombo.getData(osCombo.getItem(selectionIndex)); LOGGER.debug(uploadWizardState.operatingSystem.toString()); - uploadWizardState.virtualizer = MetaDataCache.getVirtualizers().get(0); - uploadWizardState.operatingSystem.virtualizerOsId = new HashMap<String , String>() {{ - put(uploadWizardState.virtualizer.getVirtName(), uploadWizardState.virtualizer.getVirtId()); - }}; + + // complete if the description was filled + if (!descriptionText.getText().isEmpty()) { + setMessage("Alles fertig, clicken Sie 'Finish'."); + setPageComplete(true); + } else { + setMessage("Fügen Sie eine Beschreibung hinzu."); + setPageComplete(false); + } } } }); @@ -88,7 +88,18 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout { public void keyReleased(KeyEvent e) { if (!descriptionText.getText().isEmpty()) { uploadWizardState.description = descriptionText.getText(); - setPageComplete(true); + // complete if the OS was selected + if (osCombo.getSelectionIndex() != 1) { + setMessage("Alles fertig, clicken Sie 'Finish'."); + setPageComplete(true); + } else { + setMessage("Wählen Sie das Betriebssystem aus."); + setPageComplete(false); + } + } else { + // no description text + setMessage("Fügen Sie eine Beschreibung hinzu."); + setPageComplete(false); } } }); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java index f9ea580f..380856a1 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java @@ -3,7 +3,6 @@ package org.openslx.dozmod.gui.wizard.page; import java.io.File; import java.io.IOException; import java.util.List; -import java.util.UUID; import org.apache.log4j.Logger; import org.eclipse.swt.SWT; @@ -13,9 +12,9 @@ import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.FileDialog; -import org.openslx.bwlp.thrift.iface.ImageBaseWrite; -import org.openslx.bwlp.thrift.iface.TransferInformation; +import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.dozmod.Config; +import org.openslx.dozmod.filetransfer.UploadTask; import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.MainWindow; import org.openslx.dozmod.gui.helper.MessageType; @@ -41,6 +40,7 @@ public class ImageUploadPage extends ImageUploadPageLayout { setPageComplete(false); this.editExistingImage = editExistingImage; this.uploadWizardState = uploadWizardState; + setMessage("Bitte wählen Sie eine virtuelle Maschine zum Hochladen aus."); } @Override @@ -55,7 +55,9 @@ public class ImageUploadPage extends ImageUploadPageLayout { @Override public void keyReleased(KeyEvent e) { if (!imageNameTextField.getText().isEmpty()) { - setPageComplete(uploadWizardState.descriptionFile != null); + setPageComplete(uploadWizardState.descriptionFile != null + && uploadWizardState.uuid != null + && uploadWizardState.transferInformation != null); } else setPageComplete(false); } @@ -122,6 +124,16 @@ public class ImageUploadPage extends ImageUploadPageLayout { return; // Allow to continue!? } + // OS parsed? + OperatingSystem os = meta.getOs(); + if (os == null || os.getOsName() == null) { + LOGGER.error("The selected VMX's OS cannot be determined! Setting default for now."); + // dont return here, since we let the user the chance to set it in the next page + } else { + // add the OS to the state + uploadWizardState.operatingSystem = os; + } + // vmx ok, set it as our description file uploadWizardState.descriptionFile = file; // now check the disk files @@ -146,8 +158,9 @@ public class ImageUploadPage extends ImageUploadPageLayout { } uploadWizardState.operatingSystem = meta.getOs(); imageFileTextField.setText(file.getAbsolutePath()); + // let the user know the upload is ready + setMessage("Sie können jetzt den Upload starten!"); startUploadButton.setEnabled(true); -// setPageComplete(!imageNameTextField.getText().isEmpty()); } /* Override setVisible() to inject some code when this page is set visible @@ -182,10 +195,10 @@ public class ImageUploadPage extends ImageUploadPageLayout { Session.getSatelliteToken(), uploadWizardState.name); } catch (Exception e) { LOGGER.error("Error while creating image: ", e); - return; } } - if (uploadWizardState.transferInformation == null) { + if (uploadWizardState.transferInformation == null + && uploadWizardState.uuid != null) { // -- request upload -- LOGGER.debug("Requesting upload..."); try { @@ -193,7 +206,21 @@ public class ImageUploadPage extends ImageUploadPageLayout { Session.getSatelliteToken(), uploadWizardState.uuid, uploadWizardState.diskFile.length(), null); } catch (Exception e) { LOGGER.error("Error while requesting download for: " + uploadWizardState.uuid, e); - return; + } + } + if (uploadWizardState.transferInformation != null + && uploadWizardState.uuid != null) { + // do actually start the upload now + LOGGER.debug("Starting upload for : " + uploadWizardState.diskFile.toPath()); + final Thread t = new Thread(new UploadTask( + Session.getSatelliteAddress(), + uploadWizardState.transferInformation.getPlainPort(), + uploadWizardState.transferInformation.getToken(), + uploadWizardState.diskFile)); + t.start(); + if (!t.isAlive()) { + // thread existed already, something is going wrong + LOGGER.error("Thread already died, upload seems to have failed?"); } } Gui.display.asyncExec(new Runnable() { @@ -206,8 +233,17 @@ public class ImageUploadPage extends ImageUploadPageLayout { }); } + /** + * Callback for the QuickTimer executing the thrift calls (see createAndUploadImage()) + * + * createAndUploadImage() starts the image upload process by creating the image, + * requesting upload transfer, starting the upload task and finally query the upload + * status to check if the upload is actually running. + * + * Each step will update the UploadWizardState which we will evaluate here to + * know which step failed and handle the error accordingly. + */ public void createAndUploadImageCallback() { - LOGGER.debug("callback"); // always disable "Browse" and "Image Name" field imageNameTextField.setEnabled(false); imageFileBrowseButton.setEnabled(false); @@ -216,17 +252,41 @@ public class ImageUploadPage extends ImageUploadPageLayout { // we just created the image, remember uuid LOGGER.debug("Received UUID from satellite: " + uploadWizardState.uuid); uploadWizardState.uuid = uploadWizardState.uuid; + setMessage("Image auf dem Satelliten erstellt. Sende Anfrage für Upload..."); } else { - LOGGER.debug("null uuid"); + LOGGER.debug("No UUID in upload state!"); + setErrorMessage("Konnte das Image nicht auf dem Satelliten erstellen!"); } // -- check request upload -- if (uploadWizardState.transferInformation != null) { // request "granted" LOGGER.debug("Transfer request granted."); uploadWizardState.transferInformation = uploadWizardState.transferInformation; + setMessage("Upload läuft! Sie können fortfahren."); } else { - LOGGER.debug("null ti"); + LOGGER.debug("No transfer information in upload state!"); + setErrorMessage("Fehler bei der Upload-Anfrage!"); } + // TODO + // -- periodically check upload status -- +// QuickTimer.scheduleAtFixedRate(new Task() { +// @Override +// public void fire() { +// try { +// uploadWizardState.transferStatus = +// ThriftManager.getSatClient() +// .queryUploadStatus(uploadWizardState.transferInformation.getToken()); +// } catch (Exception e) { +// LOGGER.error("Error while requesting upload status for: " + uploadWizardState.uuid, e); +// } +// Gui.display.asyncExec(new Runnable() { +// @Override +// public void run() { +// LOGGER.debug("Status: " + uploadWizardState.transferStatus.toString()); +// } +// }); +// } +// }, 0, 1000); setPageComplete(uploadWizardState.uuid != null && uploadWizardState.transferInformation != null); } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/state/UploadWizardState.java b/dozentenmodul/src/main/java/org/openslx/dozmod/state/UploadWizardState.java index c257251d..d22e26c8 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/state/UploadWizardState.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/state/UploadWizardState.java @@ -1,12 +1,12 @@ package org.openslx.dozmod.state; import java.io.File; -import java.util.UUID; import org.openslx.bwlp.thrift.iface.ImagePermissions; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.ShareMode; import org.openslx.bwlp.thrift.iface.TransferInformation; +import org.openslx.bwlp.thrift.iface.TransferStatus; import org.openslx.bwlp.thrift.iface.Virtualizer; public class UploadWizardState { @@ -36,4 +36,6 @@ public class UploadWizardState { public String uuid = null; // transfer information for upload received if the upload request was granted public TransferInformation transferInformation = null; + // transfer status for the current upload + public TransferStatus transferStatus = null; } |
