summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx
diff options
context:
space:
mode:
authorStephan Schwär2020-10-12 07:34:27 +0200
committerStephan Schwär2020-10-12 07:34:27 +0200
commitddae30a541a5bf6546c77bbea8bad29bb7aeebf0 (patch)
tree4ebcc0112606601c83ae85ab524041029b3478c8 /dozentenmodul/src/main/java/org/openslx
parent[client] Resttructure layout of OvfConversion page (diff)
downloadtutor-module-ddae30a541a5bf6546c77bbea8bad29bb7aeebf0.tar.gz
tutor-module-ddae30a541a5bf6546c77bbea8bad29bb7aeebf0.tar.xz
tutor-module-ddae30a541a5bf6546c77bbea8bad29bb7aeebf0.zip
[client] Call external ovftool to convert ovf to vmx
Doesn't use different thread than the Gui yet and the output of the ovftool is only being shown in the console. Feature: #3771
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageOvfConversionPage.java73
1 files changed, 63 insertions, 10 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageOvfConversionPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageOvfConversionPage.java
index 3b9cd69d..21d96fe7 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageOvfConversionPage.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageOvfConversionPage.java
@@ -2,13 +2,21 @@ package org.openslx.dozmod.gui.wizard.page;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.io.BufferedReader;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.IOException;
-import java.util.List;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.file.Files;
+import javax.swing.JOptionPane;
+
+import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
+import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.dozmod.gui.wizard.Wizard;
+import org.openslx.dozmod.gui.wizard.WizardPage;
import org.openslx.dozmod.gui.wizard.layout.ImageOvfConversionPageLayout;
import org.openslx.dozmod.state.UploadWizardState;
@@ -17,13 +25,14 @@ public class ImageOvfConversionPage extends ImageOvfConversionPageLayout {
private final static Logger LOGGER = Logger.getLogger(ImageOvfConversionPage.class);
private UploadWizardState state;
- private String lastDetectedName = null;
+ private WizardPage page;
public ImageOvfConversionPage(Wizard wizard, UploadWizardState uploadWizardState) {
super(wizard);
setPageComplete(false);
this.canComeBack = false;
this.state = uploadWizardState;
+ page = this;
txtInfoText.setVisible(true);
@@ -31,20 +40,64 @@ public class ImageOvfConversionPage extends ImageOvfConversionPageLayout {
btnStartConversion.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- convertOvfToVmx();
+ try {
+ convertOvfToVmx(state.descriptionFile);
+ } catch (Exception error) {
+ Gui.showMessageBox(page, "Conversion failed:", MessageType.ERROR, LOGGER, error);
+ }
+
}
});
}
- private void convertOvfToVmx() {
- LOGGER.debug("Conversion button clicked");
+ // Check if the directory we want to create for the converted virtual machine exists and create it
+ private void convertOvfToVmx(File file) throws IOException {
+ File directoryFile = new File(file.getParent() + "/converted_vm");
+ LOGGER.debug("Directory for converted VM:" + directoryFile.getAbsolutePath());
+ if (directoryFile.exists()) {
+ int dialogButton = JOptionPane.YES_NO_OPTION;
+ int dialogResult = JOptionPane.showConfirmDialog(this,
+ "Das Verzeichnis, in welcher das konvertierte Image gespeichert werden soll existiert bereits. \n"
+ + "Soll dieses ersetzt und die darin enthaltenen Dateien gelöscht werden?",
+ "Teststring", dialogButton);
+ if (dialogResult == 0) {
+ FileUtils.deleteDirectory(directoryFile);
+ } else {
+ return;
+ }
+
+ }
+ Files.createDirectories(directoryFile.toPath());
+
+ Process process = null;
+ try {
+ process = new ProcessBuilder("ovftool", file.getAbsolutePath(),
+ directoryFile.getPath() + "/" + file.getName()).start();
+ } catch (IOException e) {
+ Gui.showMessageBox(page, "Conversion failed:", MessageType.ERROR, LOGGER, e);
+ return;
+ }
+ InputStream is = process.getInputStream();
+ InputStreamReader isr = new InputStreamReader(is);
+ BufferedReader br = new BufferedReader(isr);
+ String line;
+
+ System.out.println("Running OVFTool");
+
+ try {
+ while ((line = br.readLine()) != null) {
+ System.out.println(line);
+ }
+ } catch (IOException e) {
+ System.out.println("Error reading output or OVFTool.");
+ }
}
/**
- *
- */
- @Override
- protected boolean wantNextOrFinish() {
+ *
+ */
+ @Override
+ protected boolean wantNextOrFinish() {
return false;
}
}