diff options
12 files changed, 267 insertions, 111 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/TransferPanel.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/TransferPanel.java index 7a3582df..d6ba952d 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/TransferPanel.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/TransferPanel.java @@ -165,7 +165,8 @@ public abstract class TransferPanel extends ActivityPanel implements TransferEve transfer.removeListener(panel); lblRemaining.setText("-"); btnClose.setText("Schließen"); - lblFilename.setText(lblFilename.getText().replaceFirst("\\.img\\.part$", ".vmdk")); + //TODO find a way to differentiate between .vmdk and .vdi + lblFilename.setText(lblFilename.getText().replaceFirst("\\.img\\.part$", "")); footer.setVisible(false); progressWrapper.setVisible(false); } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java index 517d324d..cfcad22b 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java @@ -67,6 +67,7 @@ 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.util.ThriftUtil; import org.openslx.util.Util; /** @@ -383,6 +384,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } catch (TException e) { LOGGER.error("Failed to retrieve virtualizer config for image version " + "'" + image.latestVersionId + ", see trace: ", e); + return; } Gui.asyncExec(new Runnable() { @Override @@ -391,7 +393,16 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe Gui.showMessageBox("Konnte VM-Konfiguration nicht abrufen.", MessageType.ERROR, LOGGER, null); return; } - VirtDropDownConfigEditorWindow.open(me, actionHandler, selected.versionId, machineDescription); + + //TODO is this a hack? + String tmp = ThriftUtil.byteBufferToString(machineDescription); + if (tmp.startsWith("qemu")) { + VirtConfigEditorWindow.open(me, actionHandler, selected.versionId, + machineDescription, tmp); + } else { + VirtDropDownConfigEditorWindow.open(me, actionHandler, selected.versionId, + machineDescription); + } } }); } @@ -481,7 +492,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe return; } } - + } // let the user confirm or abort if (!Gui.showMessageBox("Wollen Sie diese VM wirklich landesweit veröffentlichen?", @@ -646,7 +657,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe refresh(true); } } - + /******************************************************************************** diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtConfigEditorWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtConfigEditorWindow.java index 301b068f..349bf9b1 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtConfigEditorWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtConfigEditorWindow.java @@ -3,6 +3,7 @@ package org.openslx.dozmod.gui.window; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.IOException; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -21,8 +22,8 @@ import org.openslx.dozmod.thrift.ImageDetailsActions; import org.openslx.dozmod.thrift.ImageDetailsActions.VirtConfCallback; import org.openslx.dozmod.thrift.cache.MetaDataCache; import org.openslx.util.ThriftUtil; +import org.openslx.util.vm.VmMetaData; import org.openslx.util.vm.VmwareConfig; -import org.openslx.util.vm.VmwareMetaData; @SuppressWarnings("serial") public class VirtConfigEditorWindow extends VirtConfigEditorWindowLayout implements UiFeedback { @@ -84,10 +85,19 @@ public class VirtConfigEditorWindow extends VirtConfigEditorWindowLayout impleme Charset cs = VmwareConfig.getCharset(uiBytes, uiBytes.length); // cs is now either the detected encoding, or latin1 as a default uiBytes = userInput.getBytes(cs); - // now we should have the correct bytes.... - VmwareMetaData meta = new VmwareMetaData(MetaDataCache.getOperatingSystems(), uiBytes, - uiBytes.length); - byte[] uiBytesFiltered = meta.getDefinitionArray(); + // now we should have the correct bytes... + VmMetaData<?,?,?,?> metaCandidate = null; + try { + metaCandidate = VmMetaData.getInstance(MetaDataCache.getOperatingSystems(), uiBytes, + uiBytes.length); + } catch (IOException e) { + e.printStackTrace(); + } + if ( metaCandidate == null ) { + dispose(); + } + + byte[] uiBytesFiltered = metaCandidate.getDefinitionArray(); final String userInputFiltered = new String(uiBytesFiltered, cs); // So here we have: // - uiBytes is the unfiltered user input diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtDropDownConfigEditorWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtDropDownConfigEditorWindow.java index b68a575d..c151f505 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtDropDownConfigEditorWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtDropDownConfigEditorWindow.java @@ -3,6 +3,7 @@ package org.openslx.dozmod.gui.window; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.IOException; import java.nio.ByteBuffer; import org.openslx.dozmod.gui.Gui; @@ -13,15 +14,15 @@ import org.openslx.dozmod.thrift.ImageDetailsActions; import org.openslx.dozmod.thrift.ImageDetailsActions.VirtConfCallback; import org.openslx.dozmod.thrift.cache.MetaDataCache; import org.openslx.util.ThriftUtil; -import org.openslx.util.vm.VmwareMetaData; -import org.openslx.util.vm.VmwareMetaData.DDAcceleration; -import org.openslx.util.vm.VmwareMetaData.EthernetDevType; -import org.openslx.util.vm.VmwareMetaData.HWVersion; -import org.openslx.util.vm.VmwareMetaData.SoundCardType; +import org.openslx.util.vm.VmMetaData; +import org.openslx.util.vm.VmMetaData.DDAcceleration; +import org.openslx.util.vm.VmMetaData.EthernetDevType; +import org.openslx.util.vm.VmMetaData.HWVersion; +import org.openslx.util.vm.VmMetaData.SoundCardType; @SuppressWarnings("serial") -public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWindowLayout - implements UiFeedback { +public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWindowLayout implements + UiFeedback { public interface VirtConfigChanged { public void virtConfigChanged(String newVmx); @@ -30,7 +31,7 @@ public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWind private final String imageVersionId; private final String originalMachineDescription; private final VirtDropDownConfigEditorWindow me = this; - private final VmwareMetaData meta; + private final VmMetaData<?, ?, ?, ?> meta; private final ImageDetailsActions actionHandler; protected VirtDropDownConfigEditorWindow(Window modalParent, final ImageDetailsActions actionHandler, @@ -41,8 +42,23 @@ public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWind this.imageVersionId = imageVersionId; // and now for the meta data + VmMetaData<?, ?, ?, ?> metaCandidate = null; byte[] machineData = ThriftUtil.unwrapByteBuffer(machineDescription); - meta = new VmwareMetaData(MetaDataCache.getOperatingSystems(), machineData, machineData.length); + try { + metaCandidate = VmMetaData.getInstance(MetaDataCache.getOperatingSystems(), machineData, + machineData.length); + } catch (IOException e1) { + e1.printStackTrace(); + } + if (metaCandidate == null) { + dispose(); + } + meta = metaCandidate; + + initializeSoundBox(meta.getSupportedSoundCards()); + initializeDDABox(meta.getSupportedDDAccs()); + initializeHWVersBox(meta.getSupportedHWVersions()); + initializeEDTBox(meta.getSupportedEthernetDevices()); //set the initial state of the buttons setTheBoxes(meta); @@ -118,6 +134,11 @@ public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWind this.originalMachineDescription = ThriftUtil.byteBufferToString(machineDescription); btnSave.setEnabled(false); + //TODO sort this hack out...and make it work + /* + if ( meta instanceof QemuMetaData) { + this.btnMore.doClick(); + } */ } protected void checkForChange() { @@ -133,15 +154,22 @@ public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWind /* setting the boxes to their initial value...value is read from the given metaData * @param: given VmwareMetaData */ - private void setTheBoxes(VmwareMetaData m) { - SoundCardType SCT = m.getSoundCard(); - cboSound.setSelectedItem(SCT); - DDAcceleration DDA = m.getDDAcceleration(); - cbo3DAcceleration.setSelectedItem(DDA); - HWVersion HWV = m.getHWVersion(); - cboHWVersion.setSelectedItem(HWV); - EthernetDevType E0VD = m.getEthernetDevType(0); - cboE0VirtDev.setSelectedItem(E0VD); + private void setTheBoxes(VmMetaData<?, ?, ?, ?> m) { + try { + SoundCardType SCT = m.getSoundCard(); + cboSound.setSelectedItem(SCT); + DDAcceleration DDA = m.getDDAcceleration(); + cbo3DAcceleration.setSelectedItem(DDA); + HWVersion HWV = m.getHWVersion(); + cboHWVersion.setSelectedItem(HWV); + EthernetDevType E0VD = m.getEthernetDevType(0); + cboE0VirtDev.setSelectedItem(E0VD); + } catch (IllegalArgumentException e) { + // TODO improve user message + Gui.showMessageBox("Sie haben beim letzten Konfigurieren \n" + + "einen falschen Eintrag eingespeichert. \n" + "Die VM wird nicht starten!", + MessageType.WARNING, null, e); + } } private void saveClicked() { @@ -184,4 +212,4 @@ public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWind public void escapePressed() { safeClose(); } -}
\ No newline at end of file +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtDropDownConfigEditorWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtDropDownConfigEditorWindowLayout.java index db79f7d0..28dd5e4e 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtDropDownConfigEditorWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtDropDownConfigEditorWindowLayout.java @@ -4,6 +4,7 @@ import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Insets; import java.awt.Window; +import java.util.List; import javax.swing.BorderFactory; import javax.swing.Box; @@ -21,10 +22,10 @@ import org.openslx.dozmod.gui.control.ComboBox; import org.openslx.dozmod.gui.control.ComboBox.ComboBoxRenderer; import org.openslx.dozmod.gui.control.WordWrapLabel; import org.openslx.dozmod.gui.helper.GridManager; -import org.openslx.util.vm.VmwareMetaData.DDAcceleration; -import org.openslx.util.vm.VmwareMetaData.EthernetDevType; -import org.openslx.util.vm.VmwareMetaData.HWVersion; -import org.openslx.util.vm.VmwareMetaData.SoundCardType; +import org.openslx.util.vm.VmMetaData.DDAcceleration; +import org.openslx.util.vm.VmMetaData.EthernetDevType; +import org.openslx.util.vm.VmMetaData.HWVersion; +import org.openslx.util.vm.VmMetaData.SoundCardType; @SuppressWarnings("serial") public class VirtDropDownConfigEditorWindowLayout extends JDialog { @@ -64,7 +65,6 @@ public class VirtDropDownConfigEditorWindowLayout extends JDialog { * ComboBoxes - one for each device */ - // SoundBox cboSound = new ComboBox<>(new ComboBoxRenderer<SoundCardType>() { @Override public String renderItem(SoundCardType item) { @@ -72,10 +72,6 @@ public class VirtDropDownConfigEditorWindowLayout extends JDialog { } }); - for (SoundCardType i : SoundCardType.values()) { - cboSound.addItem(i); - } - // 3D accelerationBox cbo3DAcceleration = new ComboBox<>(new ComboBoxRenderer<DDAcceleration>() { @Override @@ -84,10 +80,6 @@ public class VirtDropDownConfigEditorWindowLayout extends JDialog { } }); - for (DDAcceleration i : DDAcceleration.values()) { - cbo3DAcceleration.addItem(i); - } - // HardwareVersioBox cboHWVersion = new ComboBox<>(new ComboBoxRenderer<HWVersion>() { @Override @@ -96,10 +88,6 @@ public class VirtDropDownConfigEditorWindowLayout extends JDialog { } }); - for (HWVersion i : HWVersion.values()) { - cboHWVersion.addItem(i); - } - // HardwareVersioBox cboE0VirtDev = new ComboBox<>(new ComboBoxRenderer<EthernetDevType>() { @Override @@ -108,10 +96,6 @@ public class VirtDropDownConfigEditorWindowLayout extends JDialog { } }); - for (EthernetDevType i : EthernetDevType.values()) { - cboE0VirtDev.addItem(i); - } - pnlEditor = new JEditorPane("text/plain", null); pnlScrollPane = new JScrollPane(pnlEditor, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); @@ -130,10 +114,10 @@ public class VirtDropDownConfigEditorWindowLayout extends JDialog { grid.add(new JLabel("Netzwerkkarte")).fill(true, false).expand(false, false); grid.add(cboE0VirtDev).fill(true, false).expand(true, false); grid.nextRow(); - + grid.add(Box.createVerticalGlue(), 2).expand(true, true); grid.nextRow(); - + JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); @@ -149,10 +133,36 @@ public class VirtDropDownConfigEditorWindowLayout extends JDialog { grid.add(buttonPane, 2).fill(true, false).expand(true, false); grid.finish(false); - Dimension size = Gui.getScaledDimension(550, 300); - setMinimumSize(size); - setMaximumSize(size); - setSize(size); + setPreferredSize(Gui.getScaledDimension(600, 400)); + setMinimumSize(Gui.getScaledDimension(450, 350)); Gui.centerShellOverShell(modalParent, this); } + + // SoundBox + public void initializeSoundBox(List<SoundCardType> list) { + for (SoundCardType i : list) { + cboSound.addItem(i); + } + } + + // 3 D acceleration + public void initializeDDABox(List<DDAcceleration> list) { + for (DDAcceleration i : list) { + cbo3DAcceleration.addItem(i); + } + } + + // Hardware version + public void initializeHWVersBox(List<HWVersion> list) { + for (HWVersion i : list) { + cboHWVersion.addItem(i); + } + } + + // Ethernet Device type + public void initializeEDTBox(List<EthernetDevType> list) { + for (EthernetDevType i : list) { + cboE0VirtDev.addItem(i); + } + } } 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 abd554a4..358fdd0d 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 @@ -20,6 +20,9 @@ public abstract class ImageMetaDataPageLayout extends WizardPage { protected final JComboBox<OperatingSystem> cboOperatingSystem; protected final JTextArea txtDescription; + protected final JTextArea startCommand; + protected final QLabel sCommandCaption; + protected final JScrollPane startCommandPane; protected final JCheckBox chkLicenseRestricted; protected final JCheckBox chkIsTemplate; @@ -47,7 +50,19 @@ public abstract class ImageMetaDataPageLayout extends WizardPage { grid.add(osCaption); grid.add(cboOperatingSystem); - QLabel descriptionCation = new QLabel("Beschreibung"); + sCommandCaption = new QLabel("Startbefehl"); + startCommand = new JTextArea(1, 50); + startCommand.setMinimumSize(Gui.getScaledDimension(0, 35)); + startCommand.setLineWrap(true); + startCommand.setWrapStyleWord(true); + startCommandPane = new JScrollPane(startCommand, JScrollPane.VERTICAL_SCROLLBAR_NEVER, + JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + startCommandPane.setMinimumSize(startCommand.getMinimumSize()); + grid.add(sCommandCaption); + grid.add(startCommandPane).fill(true, false).expand(true, false); + grid.nextRow(); + + QLabel descriptionCaption = new QLabel("Beschreibung"); txtDescription = new JTextArea(5, 50); txtDescription.setMinimumSize(Gui.getScaledDimension(0, 70)); txtDescription.setLineWrap(true); @@ -55,7 +70,7 @@ public abstract class ImageMetaDataPageLayout extends WizardPage { JScrollPane descPane = new JScrollPane(txtDescription, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); descPane.setMinimumSize(txtDescription.getMinimumSize()); - grid.add(descriptionCation); + grid.add(descriptionCaption); grid.add(descPane).fill(true, false).expand(true, false); grid.nextRow(); @@ -75,5 +90,4 @@ public abstract class ImageMetaDataPageLayout extends WizardPage { public String getImageDescription() { return txtDescription.getText(); } - } 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 da572a02..1ec57fce 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 @@ -18,6 +18,7 @@ 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.QemuMetaData; /** * Page for setting the details of an image. @@ -79,6 +80,8 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout { } else if (state.selectedOs == null) { cboOperatingSystem.setSelectedItem(null); } + sCommandCaption.setVisible(false); + startCommandPane.setVisible(false); chkIsTemplate.setSelected(state.isTemplate); chkLicenseRestricted.setSelected(state.isRestricted); reactToUserInput(); @@ -114,6 +117,12 @@ public class ImageMetaDataPage extends ImageMetaDataPageLayout { setPageComplete(false); return; } + + if (state.meta instanceof QemuMetaData) { + sCommandCaption.setVisible(true); + startCommandPane.setVisible(true); + } + // evaluate description field state.description = txtDescription.getText(); if (state.description == null || state.description.isEmpty()) { 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 f5a10b44..ec501234 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 @@ -29,6 +29,9 @@ import org.openslx.dozmod.thrift.WrappedException; import org.openslx.dozmod.thrift.cache.MetaDataCache; import org.openslx.util.vm.DiskImage; import org.openslx.util.vm.DiskImage.UnknownImageFormatException; +import org.openslx.util.vm.QemuMetaData; +import org.openslx.util.vm.VboxMetaData; +import org.openslx.util.vm.VmMetaData; import org.openslx.util.vm.VmMetaData.HardDisk; import org.openslx.util.vm.VmwareMetaData; @@ -44,6 +47,15 @@ public class ImageUploadPage extends ImageUploadPageLayout { private String lastDetectedName = null; private ImageDetailsRead existingImage = null; + private final FileNameExtensionFilter allSupportedFilter = new FileNameExtensionFilter("All Supported", + "vmx", "vbox", "qcow", "qcow2"); + private final FileNameExtensionFilter vmxFilter = new FileNameExtensionFilter("VMware Virtual Machine", + "vmx"); + private final FileNameExtensionFilter vboxFilter = new FileNameExtensionFilter( + "VirtualBox Virtual Machine", "vbox"); + private final FileNameExtensionFilter qemuFilter = new FileNameExtensionFilter("Qemu Virtual Machine", + "qcow2", "qcow"); + public ImageUploadPage(Wizard wizard, UploadWizardState uploadWizardState, final ImageDetailsRead existingImage) { super(wizard); @@ -55,7 +67,7 @@ public class ImageUploadPage extends ImageUploadPageLayout { lblImageName.setVisible(existingImage == null); txtImageName.setVisible(existingImage == null); txtInfoText.setVisible(existingImage == null); - // show the licenced software checkbox since we are uploading new version + // show the licensed software checkbox since we are uploading new version chkLicenseRestricted.setVisible(existingImage != null); chkLicenseRestricted.setSelected(existingImage != null); // TODO selected by default? @@ -80,44 +92,71 @@ public class ImageUploadPage extends ImageUploadPageLayout { private void browseForVm() { QFileChooser fc = new QFileChooser(Config.getUploadPath(), false); - FileNameExtensionFilter filter = new FileNameExtensionFilter("VMware Virtual Machine", "vmx"); - fc.setFileFilter(filter); + fc.setAcceptAllFileFilterUsed(false); + fc.addChoosableFileFilter(vmxFilter); + fc.addChoosableFileFilter(vboxFilter); + fc.addChoosableFileFilter(qemuFilter); + fc.addChoosableFileFilter(allSupportedFilter); + // differentiate between existing and new VMs + if (existingImage != null) { + if (existingImage.virtId.equals("vmware")) { + fc.setFileFilter(vmxFilter); + } else if (existingImage.virtId.equals("vbox")) { + fc.setFileFilter(vboxFilter); + } + } else { + fc.setFileFilter(allSupportedFilter); + } int action = fc.showOpenDialog(getDialog()); File file = fc.getSelectedFile(); + if (action != JFileChooser.APPROVE_OPTION || file == null) return; - vmxSelected(file.getAbsoluteFile()); + vmSelected(file.getAbsoluteFile()); } - private void vmxSelected(File file) { + private void vmSelected(File file) { Config.setUploadPath(file.getParent()); txtImageFile.setText(""); txtImageName.setText(""); try { - state.meta = new VmwareMetaData(MetaDataCache.getOperatingSystems(), file); + // gets the metadata object of the selected VM depending on its type + state.meta = VmMetaData.getInstance(MetaDataCache.getOperatingSystems(), file); } catch (IOException e) { Gui.showMessageBox(this, "Konnte " + file.getPath() + " nicht lesen", MessageType.ERROR, LOGGER, e); setPageComplete(false); return; } + + String fileformat = "Konfigurations"; + if (state.meta instanceof VmwareMetaData) { + fileformat = "vmx"; + } else if (state.meta instanceof VboxMetaData) { + fileformat = "vbox"; + } else if (state.meta instanceof QemuMetaData) { + fileformat = "qcow"; + } + + // TODO too much header? if (state.meta == null || state.meta.getDisplayName() == null) { - setErrorMessage("Ungültige vmx-Datei ausgewählt!"); + setErrorMessage("Ungültige " + fileformat + "-Datei ausgewählt!"); setPageComplete(false); return; } List<HardDisk> hdds = state.meta.getHdds(); if (hdds.size() == 0 || hdds.get(0).diskImage == null) { - setErrorMessage("Die gewählte vmx-Datei enthält keine virtuelle Festplatte!"); + setErrorMessage("Die gewählte " + fileformat + "-Datei enthält keine virtuelle Festplatte!"); setPageComplete(false); return; } if (hdds.size() > 1) { - setErrorMessage("Die gewählte vmx-Datei enthält mehr als eine virtuelle Festplatte!"); + setErrorMessage("Die gewählte " + fileformat + + "-Datei enthält mehr als eine virtuelle Festplatte!"); setPageComplete(false); return; - // Allow to continue!? + // Allow to continue!? } // now check the disk files @@ -125,8 +164,8 @@ public class ImageUploadPage extends ImageUploadPageLayout { File vmDiskFileInfo = new File(hdds.get(0).diskImage); if (!vmDiskFileInfo.isAbsolute()) { // it's relative, compose path using the vmx location - File vmxBaseDirectory = file.getParentFile(); - vmDiskFileInfo = new File(vmxBaseDirectory, hdds.get(0).diskImage); + File vmBaseDirectory = file.getParentFile(); + vmDiskFileInfo = new File(vmBaseDirectory, hdds.get(0).diskImage); } DiskImage diskImage; try { @@ -141,6 +180,7 @@ public class ImageUploadPage extends ImageUploadPageLayout { return; } catch (UnknownImageFormatException e) { setErrorMessage("'" + vmDiskFileInfo.getName() + "' hat unbekanntes Dateiformat!"); + LOGGER.debug("Selected disk file has unknown format.", e); setPageComplete(false); return; } @@ -156,10 +196,10 @@ public class ImageUploadPage extends ImageUploadPageLayout { return; } if (!diskImage.isStandalone) { - Gui.showMessageBox( - "Die zu dieser VM gehörige VMDK (Virtuelle Festplatte) ist im Format '" + diskImage.subFormat + "'.\n" - + "Dieses Format wird von bwLehrpool nicht unterstützt. Bitte konvertieren Sie die VM\n" - + "in das Format 'monolithicSparse'.", MessageType.WARNING, null, null); + Gui.showMessageBox("Die zu dieser VM gehörige Virtuelle Festplatte ist im Format '" + + diskImage.subFormat + "'.\n" + + "Dieses Format wird von bwLehrpool nicht unterstützt. Bitte konvertieren Sie die VM\n" + + "in das Format 'monolithicSparse'.", MessageType.WARNING, null, null); setErrorMessage("Die VMDK Datei der VM hat ein inkompatibles Format"); setPageComplete(false); return; @@ -234,7 +274,6 @@ public class ImageUploadPage extends ImageUploadPageLayout { state.uuid = ThriftActions.createImage(JOptionPane.getFrameForComponent(this), state.name); if (state.uuid == null) return false; - txtImageName.setEnabled(false); btnBrowseForImage.setEnabled(false); txtImageFile.setEnabled(false); @@ -242,7 +281,8 @@ public class ImageUploadPage extends ImageUploadPageLayout { } else { state.uuid = existingImage.getImageBaseId(); } - // Create upload initiator that will manage requesting a token, hashing the file, connecting for upload... + // 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, diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java index 7873b8ca..47683c34 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java @@ -512,6 +512,7 @@ public class ThriftActions { Gui.asyncExec(new Runnable() { @Override public void run() { + // TODO somehow pass type of file to DownloadWindow... MainWindow.addDownload(imageName, tmpDiskFile.getName(), dlTask); } }); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/VmWrapper.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/VmWrapper.java index 035c6ad4..ff82b86d 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/VmWrapper.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/VmWrapper.java @@ -24,6 +24,9 @@ import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.thrift.cache.MetaDataCache; import org.openslx.util.vm.DiskImage; +import org.openslx.util.vm.QemuMetaData; +import org.openslx.util.vm.VboxMetaData; +import org.openslx.util.vm.VmMetaData; import org.openslx.util.vm.VmwareMetaData; public class VmWrapper { @@ -33,36 +36,39 @@ public class VmWrapper { public static void wrapVm(File diskFile, String imageName, byte[] machineDescription, String virtualizerId, int osId, DiskImage diskImageInfo) throws MetaDataMissingException, IOException { - // TODO This is very vmware specific, but should support others too some day if (!diskFile.exists()) throw new FileNotFoundException("Disk file " + diskFile.getAbsolutePath() + " does not exist"); - // Handle machine description to generate *.vmx - VmwareMetaData vmwareConfig = null; + if (machineDescription == null || machineDescription.length < 10) { machineDescription = getFallbackVmx(diskImageInfo); } - vmwareConfig = new VmwareMetaData(MetaDataCache.getOperatingSystems(), machineDescription, - machineDescription.length); + // Handle machine description to generate configuration file + VmMetaData<?, ?, ?, ?> vmMeta = VmMetaData.getInstance(MetaDataCache.getOperatingSystems(), + machineDescription, machineDescription.length); + // Append disk & NAT - if (!vmwareConfig.addDefaultNat() || !vmwareConfig.addHddTemplate(diskFile.getName(), null, null)) { + if (!vmMeta.addDefaultNat() || !vmMeta.addHddTemplate(diskFile, null, null)) { throw new MetaDataMissingException(); } - // The guestOS should be in the vmx, but the user could have changed it by editing - // the image via the GUI. Those changes are not written back to the stored vmx + + // The guestOS should be in the vmx, but the user could have changed it + // by editing + // the image via the GUI. Those changes are not written back to the + // stored vmx int osMaxMemMb = 0; if (virtualizerId != null && osId != 0) { OperatingSystem os = MetaDataCache.getOsById(osId); if (os != null && os.virtualizerOsId != null) { String virtOsId = os.virtualizerOsId.get(virtualizerId); if (virtOsId != null) { - vmwareConfig.setOs(virtOsId); + vmMeta.setOs(virtOsId); } if (os.maxMemMb > 0) { osMaxMemMb = os.maxMemMb; } } } - vmwareConfig.addDisplayName(imageName); + vmMeta.addDisplayName(imageName); int mem = getMainMemoryMb() / 2; if (mem < 1024) { mem = 1024; @@ -70,31 +76,49 @@ public class VmWrapper { if (osMaxMemMb > 0 && mem > osMaxMemMb) { mem = osMaxMemMb; } - vmwareConfig.addRam((mem / 4) * 4); - vmwareConfig.addFloppy(0, null, true); - vmwareConfig.addFloppy(1, null, true); - vmwareConfig.addCdrom(""); // ISO-Based with no disk in drive - vmwareConfig.addCdrom(null); // Autodetect real drive - vmwareConfig.enableUsb(true); - vmwareConfig.applySettingsForLocalEdit(); - // Copy BIOS with both floppies enabled - try (FileOutputStream output = new FileOutputStream(new File(diskFile.getAbsoluteFile() - .getParentFile(), "nvram")); InputStream input = ResourceLoader.getStream("/data/nvram")) { - IOUtils.copy(input, output); - } catch (Exception e) { - Gui.asyncMessageBox("Konnte das BIOS für die VM nicht kopieren", MessageType.ERROR, LOGGER, e); - } - // Output vmx + vmMeta.addCpuCoreCount(1); + vmMeta.addRam((mem / 4) * 4); + vmMeta.addFloppy(0, null, true); + vmMeta.addFloppy(1, null, true); + vmMeta.addCdrom(""); // ISO-Based with no disk in drive + vmMeta.addCdrom(null); // Autodetect real drive + vmMeta.enableUsb(true); + vmMeta.applySettingsForLocalEdit(); + + // Output vm String base = diskFile.getAbsolutePath(); int dot = base.lastIndexOf('.'); if (dot > 0) { base = base.substring(0, dot); } - File vmxFile = new File(base + ".vmx"); - vmxFile.delete(); - FileUtils.writeByteArrayToFile(vmxFile, vmwareConfig.getFilteredDefinitionArray()); + + String fileType = null; + if (vmMeta instanceof VmwareMetaData) { + fileType = ".vmx"; + // Copy BIOS with both floppies enabled + try (FileOutputStream output = new FileOutputStream(new File(diskFile.getAbsoluteFile() + .getParentFile(), "nvram")); InputStream input = ResourceLoader.getStream("/data/nvram")) { + IOUtils.copy(input, output); + } catch (Exception e) { + Gui.asyncMessageBox("Konnte das BIOS für die VM nicht kopieren", MessageType.ERROR, LOGGER, e); + } + + } else if (vmMeta instanceof VboxMetaData) { + fileType = ".vbox"; + } else if (vmMeta instanceof QemuMetaData) { + fileType = "_startCommand.txt"; + } + if (fileType == null) { + LOGGER.warn("file type somehow unclear; application could stop working here!"); + } + + File vmFile = new File(base + fileType); + vmFile.delete(); + // actually write vmx to disk + FileUtils.writeByteArrayToFile(vmFile, vmMeta.getFilteredDefinitionArray()); } + // TODO - Simon fragen fallback VBox ?? private static byte[] getFallbackVmx(DiskImage diskImageInfo) throws IOException { String vmx = ResourceLoader.getTextFile("/txt/vmx_template"); return vmx.replace("%VM_HW_VERSION%", Integer.toString(diskImageInfo.hwVersion)).getBytes( diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java index 58c7bdb2..e7a1299c 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java @@ -28,9 +28,8 @@ import org.openslx.bwlp.thrift.iface.NetShare; import org.openslx.bwlp.thrift.iface.TNotFoundException; import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.util.Json; +import org.openslx.util.vm.UnsupportedVirtualizerFormatException; import org.openslx.util.vm.VmMetaData; -import org.openslx.util.vm.VmwareMetaData; -import org.openslx.util.vm.VmwareMetaData.EthernetType; import com.google.gson.JsonParseException; @@ -518,7 +517,8 @@ public class DbLecture { } } - public static VmMetaData getClientLaunchData(String lectureId) throws SQLException, TNotFoundException { + public static VmMetaData<?, ?, ?, ?> getClientLaunchData(String lectureId) throws SQLException, + TNotFoundException, UnsupportedVirtualizerFormatException { byte[] config; String lectureName; String osKeyword; @@ -557,13 +557,19 @@ public class DbLecture { if (config == null) { return null; } - VmwareMetaData meta = new VmwareMetaData(OperatingSystemList.get(), config, config.length); + VmMetaData<?, ?, ?, ?> meta = null; + try { + meta = VmMetaData.getInstance(OperatingSystemList.get(), config, config.length); + } catch (Exception e) { + LOGGER.error("meta could not be initialized", e); + return null; + } meta.addDisplayName(lectureName); if (osKeyword != null) { meta.setOs(osKeyword); } meta.addHddTemplate("%VM_DISK_PATH%", "%VM_DISK_MODE%", "%VM_DISK_REDOLOGDIR%"); - meta.addEthernet(EthernetType.NAT); // TODO: Use config + meta.addEthernet(VmMetaData.EtherType.NAT); // TODO: Use config meta.enableUsb(usbAccess); meta.disableSuspend(); return meta; @@ -580,7 +586,7 @@ public class DbLecture { throw e; } } - + public static List<LectureSummary> getLecturesUsingImageVersion(MysqlConnection connection, String imageVersionId) throws SQLException { MysqlStatement stmt = connection.prepareStatement(summaryBaseSql diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java index a4338dce..f528d95b 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java @@ -17,6 +17,7 @@ import org.openslx.bwlp.thrift.iface.NetShare; import org.openslx.bwlp.thrift.iface.NetShareAuth; import org.openslx.bwlp.thrift.iface.TNotFoundException; import org.openslx.util.Json; +import org.openslx.util.vm.UnsupportedVirtualizerFormatException; import org.openslx.util.vm.VmMetaData; import org.simpleframework.xml.Serializer; import org.simpleframework.xml.core.Persister; @@ -136,7 +137,8 @@ public class WebServer extends NanoHTTPD { VmMetaData meta; try { meta = DbLecture.getClientLaunchData(lectureId); - } catch (TNotFoundException e) { + } catch (UnsupportedVirtualizerFormatException | TNotFoundException e) { + // TODO better virt error handling return notFound(); } catch (SQLException e) { return internalServerError(); |
