summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorralph isenmann2021-10-14 18:19:05 +0200
committerralph isenmann2021-10-15 08:53:31 +0200
commitebb258c64ce55d59142a3dd94b3e076730a8c234 (patch)
treeceedf4fd3a9120265bc9ccf625653166f81481ef
parent[client] update input methods for container images (diff)
downloadtutor-module-ebb258c64ce55d59142a3dd94b3e076730a8c234.tar.gz
tutor-module-ebb258c64ce55d59142a3dd94b3e076730a8c234.tar.xz
tutor-module-ebb258c64ce55d59142a3dd94b3e076730a8c234.zip
[client] allow users to upload new versions of container images.
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/panel/ContainerPanel.java3
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java1
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageCreationWizard.java1
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java36
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerDefinition.java26
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java20
6 files changed, 80 insertions, 7 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/panel/ContainerPanel.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/panel/ContainerPanel.java
index 1cb861ee..2ef10a48 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/panel/ContainerPanel.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/panel/ContainerPanel.java
@@ -135,6 +135,9 @@ public class ContainerPanel extends JPanel {
case GIT_REPOSITORY:
txtContainerRecipe.setText(containerDefinition.getContainerMeta().getBuildContextUrl());
break;
+ case DOCKER_TAR:
+ txtContainerRecipe.setText(containerDefinition.getContainerMeta().getImageName());
+ break;
default:
LOGGER.error("Unknown Build Context");
break;
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 3fc632b8..8d31798f 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
@@ -827,7 +827,6 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout
showContainerTab();
// TODO Currently, do not allow user to upload a new version or share an Container Image.
- btnUpdateImage.setEnabled(false);
btnUploadToMaster.setEnabled(false);
}
}
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 33ed8800..885e40f7 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
@@ -108,6 +108,7 @@ public class ImageCreationWizard extends Wizard implements UiFeedback, QuitNotif
@Override public boolean wantFinish() {
+ // TODO copy/paste from ContainerUploadPage.wantNextOrFinish()
// In order for settings for a container to be recorded in the ImageMetaDataPage for the ContainerDefinition,
// the UploadInitiator was only allowed to be created here.
// TODO maybe also for VM-Images this is suitable
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java
index c7e85d22..907c1c3b 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ContainerUploadPage.java
@@ -4,14 +4,16 @@ import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.ImageDetailsRead;
import org.openslx.dozmod.Config;
+import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.helper.I18n;
+import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.dozmod.gui.helper.QFileChooser;
import org.openslx.dozmod.gui.helper.TextChangeListener;
import org.openslx.dozmod.gui.wizard.Wizard;
import org.openslx.dozmod.gui.wizard.layout.ContainerUploadPageLayout;
import org.openslx.dozmod.model.ContainerDefinition;
import org.openslx.dozmod.state.UploadWizardState;
-import org.openslx.dozmod.thrift.ThriftActions;
+import org.openslx.dozmod.thrift.*;
import org.openslx.dozmod.thrift.cache.MetaDataCache;
import org.openslx.dozmod.util.ContainerUtils;
import org.openslx.virtualization.configuration.VirtualizationConfigurationDocker;
@@ -24,6 +26,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
+import java.nio.ByteBuffer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -63,7 +66,6 @@ public class ContainerUploadPage extends ContainerUploadPageLayout {
}
// This constructor is used in case the user wants do upload a new version.
- // TODO currently unused
public ContainerUploadPage(Wizard wizard, UploadWizardState uploadWizardState,
ImageDetailsRead imageDetailsRead) {
super(wizard);
@@ -71,13 +73,16 @@ public class ContainerUploadPage extends ContainerUploadPageLayout {
state = uploadWizardState;
existingImage = imageDetailsRead;
- // TODO fix this!
- containerDefinition = null;
+ containerDefinition = ContainerUtils.getContainerDefinition(
+ Session.getSatelliteToken(),
+ imageDetailsRead.getLatestVersionId());
lblImageName.setEnabled(existingImage == null);
txtImageName.setEnabled(existingImage == null);
+ txtImageName.setText(existingImage.getImageName());
txtInfoText.setVisible(existingImage == null);
+
state.name = imageDetailsRead.imageName;
state.defaultPermissions = imageDetailsRead.getDefaultPermissions();
state.description = imageDetailsRead.getDescription();
@@ -311,6 +316,29 @@ public class ContainerUploadPage extends ContainerUploadPageLayout {
state.uuid = existingImage.getImageBaseId();
state.name = existingImage.getImageName();
}
+
+ // TODO copy/paste from ImageCreationWizard.wantFinish()
+ // Do this only if the user wants to upload a new image version!
+ if (existingImage != null) {
+ // 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,
+ ByteBuffer.wrap(state.virtualizationConfig.getConfigurationAsByteArray()));
+ } catch (WrappedException e) {
+ ThriftError.showMessage(this, LOGGER, e.exception, e.displayMessage);
+ return false;
+ } catch (IOException e) {
+ Gui.showMessageBox(this,
+ I18n.PAGE.getString("ImageUpload.Message.error.uploadInitiatorFailed"),
+ MessageType.ERROR, LOGGER, e);
+ return false;
+ }
+ }
+ // Start the hash check now
+ state.upload.startHashing();
+ }
return true;
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerDefinition.java b/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerDefinition.java
index 99d73c23..9724ce61 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerDefinition.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/model/ContainerDefinition.java
@@ -3,9 +3,9 @@ package org.openslx.dozmod.model;
import org.openslx.dozmod.thrift.cache.MetaDataCache;
import org.openslx.virtualization.configuration.VirtualizationConfigurationDocker;
import org.openslx.virtualization.configuration.VirtualizationConfigurationException;
+import org.openslx.virtualization.configuration.container.ContainerMeta;
-import java.io.File;
-import java.io.FileNotFoundException;
+import java.io.*;
import java.util.Scanner;
public class ContainerDefinition extends
@@ -31,6 +31,28 @@ public class ContainerDefinition extends
return null;
}
+ private void setContainerMeta(ContainerMeta containerMeta){
+ this.containerMeta = containerMeta;
+ }
+
+ /**
+ * Masks the fromByteArray Method in org.openslx.virtualization.configuration.container.ContainerDefinition.
+ * Prevents ClassCastExceptions while casting from parent to child!
+ * @param rawTarData
+ * @return
+ */
+ public static ContainerDefinition fromByteArray(byte[] rawTarData) {
+
+ ContainerDefinition conDef = new ContainerDefinition();
+
+ org.openslx.virtualization.configuration.container.ContainerDefinition pConDef = org.openslx.virtualization.configuration.container.ContainerDefinition.fromByteArray(rawTarData);
+
+ conDef.setContainerRecipe(pConDef.getContainerRecipe());
+ conDef.setContainerMeta(pConDef.getContainerMeta());
+
+ return conDef;
+ }
+
public static boolean isValidDockerfile(String dockerfile) {
try {
File file = new File(dockerfile);
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java
index 62e5dd0d..571b9c44 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ContainerUtils.java
@@ -3,6 +3,7 @@ package org.openslx.dozmod.util;
import com.google.gson.JsonArray;
import com.google.gson.JsonParser;
import org.apache.log4j.Logger;
+import org.apache.thrift.TException;
import org.kamranzafar.jtar.TarEntry;
import org.kamranzafar.jtar.TarHeader;
import org.kamranzafar.jtar.TarInputStream;
@@ -11,11 +12,16 @@ import org.openslx.bwlp.thrift.iface.LectureSummary;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.helper.I18n;
import org.openslx.dozmod.gui.helper.MessageType;
+import org.openslx.dozmod.model.ContainerDefinition;
import org.openslx.dozmod.thrift.cache.LectureCache;
import org.openslx.thrifthelper.TConst;
+import org.openslx.thrifthelper.ThriftManager;
+import org.openslx.util.ThriftUtil;
+
import java.awt.*;
import java.io.*;
+import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
@@ -50,6 +56,20 @@ public class ContainerUtils {
MessageType.WARNING, logger, null);
}
+ public static ContainerDefinition getContainerDefinition(String satelliteToken, String latestVersionId) {
+ byte[] rawVirtConfig = null;
+ try {
+ ByteBuffer byteBuffer = ThriftManager.getSatClient()
+ .getImageVersionVirtConfig(satelliteToken, latestVersionId);
+ rawVirtConfig = ThriftUtil.unwrapByteBuffer(byteBuffer);
+ } catch (TException e) {
+ LOGGER.error("Failed to retrieve virtualizer config for image version " + "'"
+ + latestVersionId + ", see trace: ", e);
+ return null;
+ }
+ return ContainerDefinition.fromByteArray(rawVirtConfig);
+ }
+
/**
* Check if a provided tar file contains information about a single docker image.
* To check the validity of the file, the existence of two JSON files is checked