summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/util/ImageWrapper.java
diff options
context:
space:
mode:
authorralph isenmann2020-07-17 13:57:33 +0200
committerralph isenmann2020-09-15 13:45:40 +0200
commite836cb7b54716aab6e1e4d1771b5a729bc628b63 (patch)
tree57fc8ed2f3aec5f0b96fffebcb3deedab8ecf498 /dozentenmodul/src/main/java/org/openslx/dozmod/util/ImageWrapper.java
parent[Client] minor changes in DockerfileUpdatePage; use DockerMetaDataDummy (VmMe... (diff)
downloadtutor-module-e836cb7b54716aab6e1e4d1771b5a729bc628b63.tar.gz
tutor-module-e836cb7b54716aab6e1e4d1771b5a729bc628b63.tar.xz
tutor-module-e836cb7b54716aab6e1e4d1771b5a729bc628b63.zip
[client] Modify Image Download to handle Dockerfiles
rename after successful download the ".part" file to "dockerfile" Misunderstanding: The docker file is not a diskImage, but is downloaded as such. The docker file is rather a description file (~ .vmx ?)
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/util/ImageWrapper.java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/ImageWrapper.java101
1 files changed, 101 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ImageWrapper.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ImageWrapper.java
new file mode 100644
index 00000000..82e45472
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ImageWrapper.java
@@ -0,0 +1,101 @@
+package org.openslx.dozmod.util;
+
+import org.apache.log4j.Logger;
+import org.openslx.bwlp.thrift.iface.TransferInformation;
+import org.openslx.bwlp.thrift.iface.TransferState;
+import org.openslx.dozmod.Branding;
+import org.openslx.dozmod.filetransfer.TransferEvent;
+import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.gui.helper.MessageType;
+import org.openslx.thrifthelper.TConst;
+import org.openslx.util.vm.DiskImage;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
+
+public class ImageWrapper {
+
+ private static final Logger LOGGER = Logger.getLogger(ImageWrapper.class);
+
+
+ public static void unpack(TransferEvent event, String virtualizerId, File tmpDiskFile, String imageName,
+ File destDir, int osId, TransferInformation fTransInf) {
+
+ // after the whole image is downloaded and persisted as a .part file,
+ // this will be executed to unpack it.
+ // TODO Move into new Class (implements TransferEventListener)
+
+ /*
+ * It seems only the diskfile of UploadWizardState will be downloaded.
+ * In Context of Container this would be a Container Image.
+ *
+ */
+ if (event.state != TransferState.FINISHED)
+ return;
+ DiskImage diskImage = null;
+ String ext = virtualizerId;
+
+ // TODO: Currently when downloading a Docker Image, the dockerfile will be downloaded
+ // just rename the .part file to dockerfile
+
+ if (virtualizerId.equals(TConst.VIRT_DOCKER)) {
+ //
+ File destImage = new File(destDir.getAbsolutePath(),"dockerfile");
+
+ try {
+ // use move(..) because of platform independence
+ Files.move(tmpDiskFile.toPath(),
+ destImage.toPath(),
+ StandardCopyOption.REPLACE_EXISTING
+ );
+ } catch (IOException e) {
+ Gui.asyncMessageBox("Konnte dockerfile nicht an Ziel kopieren",
+ MessageType.WARNING, LOGGER, e);
+ }
+ return;
+ }
+ // TODO: Container images have currently no diskImage, prevent creating one
+ try {
+ diskImage = new DiskImage(tmpDiskFile);
+ } catch (IOException | DiskImage.UnknownImageFormatException e) {
+ LOGGER.warn("Could not open downloaded image for analyze step", e);
+ }
+
+ if (diskImage != null) {
+ if (diskImage.format != null) {
+ ext = diskImage.format.extension;
+ }
+ if (diskImage.isCompressed) {
+ String msg = "<html>Die heruntergeladene VM '" + imageName + "' ist ein komprimiertes "
+ + "Abbild.<br>Sie müssen das Abbild dekomprimieren, bevor Sie es verändern "
+ + "können.<br> Die VM wird lokal voraussichtlich nicht startfähig sein!"
+ + "<br><br>Bitte lesen Sie die Hinweise unter "
+ + "<a href=\"" + Branding.getServiceFAQWebsite() + "\">"
+ + "VMDK Disk Types</a>";
+
+ Gui.asyncMessageBox(msg, MessageType.WARNING, null,
+ null);
+ }
+ }
+ File destImage = new File(destDir.getAbsolutePath(), VmWrapper.generateFilename(
+ imageName, ext));
+
+ destImage.delete();
+
+ if (!tmpDiskFile.renameTo(destImage)) {
+ destImage = tmpDiskFile; // Must be Windows...
+ }
+ try {
+ VmWrapper.wrapVm(destImage, imageName, fTransInf.getMachineDescription(),
+ virtualizerId, osId, diskImage);
+
+ } catch (VmWrapper.MetaDataMissingException | IOException e) {
+ Gui.asyncMessageBox(
+ "Zur heruntergeladenen VM konnte keine vmx-Datei angelegt werden."
+ + "\nSie können versuchen, das Abbild manuell in den VMWare-Player zu importieren.",
+ MessageType.WARNING, LOGGER, e);
+ }
+ }
+}