From be941913a5bc4d40ef3a2a25a4c2d4b8e9c32e79 Mon Sep 17 00:00:00 2001
From: Oleg Stobbe <oleg@openslx.com>
Date: Tue, 21 Nov 2023 15:11:53 +0100
Subject: [PATCH 1/6] Add property "kind" to image-archive's bindings

---
 .../emucomp/api/ImageArchiveBinding.java      | 40 ++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/src/eaas/components/api/src/main/java/de/bwl/bwfla/emucomp/api/ImageArchiveBinding.java b/src/eaas/components/api/src/main/java/de/bwl/bwfla/emucomp/api/ImageArchiveBinding.java
index 6f575dee47..e3e9119bf9 100644
--- a/src/eaas/components/api/src/main/java/de/bwl/bwfla/emucomp/api/ImageArchiveBinding.java
+++ b/src/eaas/components/api/src/main/java/de/bwl/bwfla/emucomp/api/ImageArchiveBinding.java
@@ -8,6 +8,7 @@ import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
 import javax.xml.bind.annotation.XmlType;
 
 @JsonIgnoreProperties("urlPrefix")
@@ -29,6 +30,17 @@ public class ImageArchiveBinding extends Binding
 	@XmlElement(namespace = "http://bwfla.bwl.de/common/datatypes", required = false)
 	protected String fileSystemType;
 
+	@XmlTransient
+	protected Kind kind = null;
+
+	public enum Kind
+	{
+		CHECKPOINT,
+		EMULATOR,
+		IMAGE,
+		ROM,
+	}
+
 	public ImageArchiveBinding()
 	{
 		backendName = null;
@@ -49,7 +61,7 @@ public class ImageArchiveBinding extends Binding
 		this.type = type;
 		this.fileSystemType = fileSystemType;
 	}
-	
+
 	public void copy(ImageArchiveBinding b)
 	{
 		this.backendName = b.backendName;
@@ -77,6 +89,32 @@ public class ImageArchiveBinding extends Binding
 			this.fileSystemType = other.fileSystemType;
 	}
 
+	@Override
+	public void setId(String newid)
+	{
+		super.setId(newid);
+		this.updateKind();
+	}
+
+	private void updateKind()
+	{
+		if (id.equals("emucon-rootfs"))
+			kind = Kind.EMULATOR;
+		else if (id.startsWith("rom-"))
+			kind = Kind.ROM;
+		else if (id.equals("checkpoint"))
+			kind = Kind.CHECKPOINT;
+		else kind = Kind.IMAGE;
+	}
+
+	public Kind getKind()
+	{
+		if (kind == null)
+			this.updateKind();
+
+		return kind;
+	}
+
 	public String getBackendName() {
 		return backendName;
 	}
-- 
GitLab


From caeae46a7a6447534547db065779fc7a5401acef Mon Sep 17 00:00:00 2001
From: Oleg Stobbe <oleg@openslx.com>
Date: Tue, 21 Nov 2023 15:29:18 +0100
Subject: [PATCH 2/6] Add helpers for resolving image-archive's bindings

---
 .../openslx/eaas/resolver/DataResolvers.java  | 46 +++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/src/eaas/components/api/src/main/java/com/openslx/eaas/resolver/DataResolvers.java b/src/eaas/components/api/src/main/java/com/openslx/eaas/resolver/DataResolvers.java
index 38e5aa6c08..7c1242e189 100644
--- a/src/eaas/components/api/src/main/java/com/openslx/eaas/resolver/DataResolvers.java
+++ b/src/eaas/components/api/src/main/java/com/openslx/eaas/resolver/DataResolvers.java
@@ -18,6 +18,9 @@
 
 package com.openslx.eaas.resolver;
 
+import de.bwl.bwfla.common.services.security.UserContext;
+import de.bwl.bwfla.emucomp.api.ImageArchiveBinding;
+
 
 public class DataResolvers
 {
@@ -47,6 +50,49 @@ public class DataResolvers
 	}
 
 
+	// ===== Utilities ====================
+
+	public static String resolve(String componentId, ImageArchiveBinding binding)
+	{
+		switch (binding.getKind()) {
+			case EMULATOR:
+				return DataResolvers.emulators()
+						.resolve(binding);
+			case IMAGE:
+				return DataResolvers.images()
+						.resolve(componentId, binding);
+			case CHECKPOINT:
+				return DataResolvers.checkpoints()
+						.resolve(componentId, binding);
+			case ROM:
+				return DataResolvers.roms()
+					.resolve(componentId, binding);
+		}
+
+		throw new IllegalArgumentException("Unknown image-kind: " + binding.getKind());
+	}
+
+	public static String resolve(ImageArchiveBinding binding, UserContext userctx)
+	{
+		switch (binding.getKind()) {
+			case EMULATOR:
+				return DataResolvers.emulators()
+						.resolve(binding);
+			case IMAGE:
+				return DataResolvers.images()
+						.resolve(binding, userctx);
+			case CHECKPOINT:
+				return DataResolvers.checkpoints()
+						.resolve(binding, userctx);
+			case ROM:
+				return DataResolvers.roms()
+						.resolve(binding, userctx);
+		}
+
+		throw new IllegalArgumentException("Unknown image-kind: " + binding.getKind());
+	}
+
+
 	// ===== Internal Helpers ====================
 
 	private static final ImageDataResolver IMAGES = new ImageDataResolver();
-- 
GitLab


From eefbb7f2687810c5bbc4a780092f6b71ec2b6d02 Mon Sep 17 00:00:00 2001
From: Oleg Stobbe <oleg@openslx.com>
Date: Tue, 21 Nov 2023 15:48:24 +0100
Subject: [PATCH 3/6] Simplify resolving of image-archive's bindings in
 bindings-manager

---
 .../emucomp/components/BindingsManager.java   | 20 ++-----------------
 1 file changed, 2 insertions(+), 18 deletions(-)

diff --git a/src/eaas/components/impl/src/main/java/de/bwl/bwfla/emucomp/components/BindingsManager.java b/src/eaas/components/impl/src/main/java/de/bwl/bwfla/emucomp/components/BindingsManager.java
index 3f6b6314a9..aabbb65218 100644
--- a/src/eaas/components/impl/src/main/java/de/bwl/bwfla/emucomp/components/BindingsManager.java
+++ b/src/eaas/components/impl/src/main/java/de/bwl/bwfla/emucomp/components/BindingsManager.java
@@ -169,24 +169,8 @@ public class BindingsManager
 		 */
 		if (resource instanceof ImageArchiveBinding)
 		{
-			final String location;
-			if ("emucon-rootfs".equals(resource.getId())) {
-				location = DataResolvers.emulators()
-						.resolve((ImageArchiveBinding) resource);
-			}
-			else if (resource.getId().startsWith("rom-")) {
-				location = DataResolvers.roms()
-						.resolve(componentId, (ImageArchiveBinding) resource);
-			}
-			else if (resource.getId().equals("checkpoint")) {
-				location = DataResolvers.checkpoints()
-						.resolve(componentId, (ImageArchiveBinding) resource);
-			}
-			else {
-				location = DataResolvers.images()
-						.resolve(componentId, (ImageArchiveBinding) resource);
-			}
-
+			final var binding = (ImageArchiveBinding) resource;
+			final var location = DataResolvers.resolve(componentId, binding);
 			resource.setUrl(location);
 		}
 
-- 
GitLab


From c66ab1a6ce7b1e90e4fbb3325d90357d44feb440 Mon Sep 17 00:00:00 2001
From: Oleg Stobbe <oleg@openslx.com>
Date: Tue, 21 Nov 2023 17:17:16 +0100
Subject: [PATCH 4/6] Fix replication of environments with ROMs and checkpoints

---
 .../eaas/imagearchive/client/endpoint/v2/EnvironmentsV2.java  | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/image-archive/client/src/main/java/com/openslx/eaas/imagearchive/client/endpoint/v2/EnvironmentsV2.java b/src/image-archive/client/src/main/java/com/openslx/eaas/imagearchive/client/endpoint/v2/EnvironmentsV2.java
index 3f75ca2588..4bc7cb4b0b 100644
--- a/src/image-archive/client/src/main/java/com/openslx/eaas/imagearchive/client/endpoint/v2/EnvironmentsV2.java
+++ b/src/image-archive/client/src/main/java/com/openslx/eaas/imagearchive/client/endpoint/v2/EnvironmentsV2.java
@@ -313,9 +313,7 @@ public class EnvironmentsV2
 					final var binding = (ImageArchiveBinding) adr;
 					if (binding.getUrl() == null) {
 						// FIXME: assume, that we replicate from local archive for now
-						final var location = DataResolvers.images()
-								.resolve(binding, userctxt);
-
+						final var location = DataResolvers.resolve(binding, userctxt);
 						binding.setUrl(location);
 					}
 
-- 
GitLab


From 07bb0a01800eef625140c92a497d2595fe5d2de0 Mon Sep 17 00:00:00 2001
From: Oleg Stobbe <oleg@openslx.com>
Date: Tue, 21 Nov 2023 17:25:12 +0100
Subject: [PATCH 5/6] Fix storage destination of replicated image-archive
 resources

---
 .../client/endpoint/v2/EnvironmentsV2.java     | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/image-archive/client/src/main/java/com/openslx/eaas/imagearchive/client/endpoint/v2/EnvironmentsV2.java b/src/image-archive/client/src/main/java/com/openslx/eaas/imagearchive/client/endpoint/v2/EnvironmentsV2.java
index 4bc7cb4b0b..192b6615c2 100644
--- a/src/image-archive/client/src/main/java/com/openslx/eaas/imagearchive/client/endpoint/v2/EnvironmentsV2.java
+++ b/src/image-archive/client/src/main/java/com/openslx/eaas/imagearchive/client/endpoint/v2/EnvironmentsV2.java
@@ -322,7 +322,7 @@ public class EnvironmentsV2
 							.setUrl(binding.getUrl());
 
 					request.target()
-							.setKind(ImportTargetV2.Kind.IMAGE)
+							.setKind(EnvironmentsV2.convert(binding.getKind()))
 							.setName(binding.getImageId());
 
 					if (options != null) {
@@ -491,4 +491,20 @@ public class EnvironmentsV2
 		return archive.imports()
 				.await(request, 1, TimeUnit.HOURS);
 	}
+
+	private static ImportTargetV2.Kind convert(ImageArchiveBinding.Kind kind)
+	{
+		switch (kind) {
+			case CHECKPOINT:
+				return ImportTargetV2.Kind.CHECKPOINT;
+			case EMULATOR:
+				return ImportTargetV2.Kind.EMULATOR;
+			case IMAGE:
+				return ImportTargetV2.Kind.IMAGE;
+			case ROM:
+				return ImportTargetV2.Kind.ROM;
+			default:
+				throw new IllegalArgumentException("Unknown kind: " + kind);
+		}
+	}
 }
-- 
GitLab


From cf5a327503c40e07ebc82b7a6217a74264126578 Mon Sep 17 00:00:00 2001
From: Oleg Stobbe <oleg@openslx.com>
Date: Tue, 21 Nov 2023 18:01:32 +0100
Subject: [PATCH 6/6] Add missing location check when looking up blobs in
 import-service

---
 .../eaas/imagearchive/service/impl/ImportService.java     | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/image-archive/impl/src/main/java/com/openslx/eaas/imagearchive/service/impl/ImportService.java b/src/image-archive/impl/src/main/java/com/openslx/eaas/imagearchive/service/impl/ImportService.java
index 5b9ff0a15f..2991cb9a62 100644
--- a/src/image-archive/impl/src/main/java/com/openslx/eaas/imagearchive/service/impl/ImportService.java
+++ b/src/image-archive/impl/src/main/java/com/openslx/eaas/imagearchive/service/impl/ImportService.java
@@ -625,7 +625,13 @@ public class ImportService implements AutoCloseable
 					.lookup(target.kind());
 
 			// does the target blob already exist?
-			return service.lookup(name) != null;
+			final var descriptor = service.lookup(name);
+			if (descriptor == null)
+				return false;
+
+			// check if target location matches too
+			final var location = target.location();
+			return (location == null) || location.equals(descriptor.location());
 		}
 	}
 
-- 
GitLab