From: aravind.est Date: Mon, 18 Sep 2023 13:32:40 +0000 (+0100) Subject: Use unique handling for the rApp resources X-Git-Tag: 0.0.1~40 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F96%2F11796%2F1;p=nonrtric%2Fplt%2Frappmanager.git Use unique handling for the rApp resources Each rApp resources are unique and it's handled using Set. Issue-ID: NONRTRIC-913 Signed-off-by: aravind.est Change-Id: I1f64280c8bb3b5a41b08a4ab69d1c862b18ca135 --- diff --git a/rapp-manager-acm/src/test/java/com/oransc/rappmanager/models/rapp/RappResourceBuilder.java b/rapp-manager-acm/src/test/java/com/oransc/rappmanager/models/rapp/RappResourceBuilder.java index f939ccc..9aa2107 100755 --- a/rapp-manager-acm/src/test/java/com/oransc/rappmanager/models/rapp/RappResourceBuilder.java +++ b/rapp-manager-acm/src/test/java/com/oransc/rappmanager/models/rapp/RappResourceBuilder.java @@ -2,14 +2,14 @@ package com.oransc.rappmanager.models.rapp; import com.oransc.rappmanager.models.rappinstance.RappACMInstance; import com.oransc.rappmanager.models.rappinstance.RappInstance; -import java.util.List; +import java.util.Set; public class RappResourceBuilder { public RappResources getResources() { RappResources rappResources = new RappResources(); - RappResources.ACMResources acmResources = new RappResources.ACMResources("compositions", List.of()); - acmResources.setCompositionInstances(List.of("kserve-instance")); + RappResources.ACMResources acmResources = new RappResources.ACMResources("compositions", Set.of()); + acmResources.setCompositionInstances(Set.of("kserve-instance")); rappResources.setAcm(acmResources); return rappResources; } diff --git a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandler.java b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandler.java index fdc860c..73c644e 100755 --- a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandler.java +++ b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandler.java @@ -27,9 +27,10 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.file.Path; -import java.util.List; +import java.util.Set; import java.util.UUID; import java.util.function.Predicate; +import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import org.apache.commons.compress.archivers.ArchiveEntry; @@ -145,7 +146,7 @@ public class RappCsarConfigurationHandler { File csarFile = getCsarFile(rapp); if (csarFile.exists()) { rappResources.setAcm(RappResources.ACMResources.builder().compositionDefinitions( - getFileListFromCsar(csarFile, ACM_DEFINITION_LOCATION).get(0)).compositionInstances( + getFileListFromCsar(csarFile, ACM_DEFINITION_LOCATION).iterator().next()).compositionInstances( getFileListFromCsar(csarFile, ACM_INSTANCES_LOCATION)).build()); rappResources.setSme(RappResources.SMEResources.builder().providerFunctions( getFileListFromCsar(csarFile, SME_PROVIDER_FUNCS_LOCATION)) @@ -158,14 +159,15 @@ public class RappCsarConfigurationHandler { return rappResources; } - List getFileListFromCsar(File csarFile, String dirLocation) { + Set getFileListFromCsar(File csarFile, String dirLocation) { try (ZipFile zipFile = new ZipFile(csarFile)) { return zipFile.stream().filter(Predicate.not(ZipEntry::isDirectory)).map(ZipEntry::getName) .filter(name -> name.startsWith(dirLocation)) - .map(name -> name.substring(name.lastIndexOf("/") + 1, name.lastIndexOf("."))).toList(); + .map(name -> name.substring(name.lastIndexOf("/") + 1, name.lastIndexOf("."))) + .collect(Collectors.toSet()); } catch (IOException e) { logger.warn("Error in listing the files from csar", e); } - return List.of(); + return Set.of(); } } diff --git a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/RappResources.java b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/RappResources.java index f9bf932..a3033e2 100755 --- a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/RappResources.java +++ b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/RappResources.java @@ -18,7 +18,7 @@ package com.oransc.rappmanager.models.rapp; -import java.util.List; +import java.util.Set; import lombok.Builder; import lombok.Data; @@ -33,15 +33,15 @@ public class RappResources { public static class ACMResources { String compositionDefinitions; - List compositionInstances; + Set compositionInstances; } @Data @Builder public static class SMEResources { - List providerFunctions; - List serviceApis; - List invokers; + Set providerFunctions; + Set serviceApis; + Set invokers; } } diff --git a/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandlerTest.java b/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandlerTest.java index b4c00a7..0a18ec4 100755 --- a/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandlerTest.java +++ b/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandlerTest.java @@ -30,7 +30,7 @@ import com.oransc.rappmanager.models.rappinstance.RappSMEInstance; import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.util.List; +import java.util.Set; import java.util.UUID; import org.apache.http.entity.ContentType; import org.json.JSONException; @@ -88,15 +88,14 @@ class RappCsarConfigurationHandlerTest { @Test void testFileListing() { File file = new File(validCsarFileLocation + validRappFile); - List fileListFromCsar = - rappCsarConfigurationHandler.getFileListFromCsar(file, "Files/Sme/serviceapis/"); + Set fileListFromCsar = rappCsarConfigurationHandler.getFileListFromCsar(file, "Files/Sme/serviceapis/"); assertThat(fileListFromCsar).hasSize(2); } @Test void testInvalidFileListing() { File file = new File(validCsarFileLocation); - List fileListFromCsar = rappCsarConfigurationHandler.getFileListFromCsar(file, null); + Set fileListFromCsar = rappCsarConfigurationHandler.getFileListFromCsar(file, null); assertThat(fileListFromCsar).isEmpty(); } @@ -130,7 +129,7 @@ class RappCsarConfigurationHandlerTest { UUID rappId = UUID.randomUUID(); RappResources rappResources = new RappResources(); rappResources.setAcm(RappResources.ACMResources.builder().compositionDefinitions("compositions") - .compositionInstances(List.of()).build()); + .compositionInstances(Set.of()).build()); Rapp rapp = Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation) .rappResources(rappResources).build(); @@ -143,7 +142,7 @@ class RappCsarConfigurationHandlerTest { UUID rappId = UUID.randomUUID(); RappResources rappResources = new RappResources(); rappResources.setAcm(RappResources.ACMResources.builder().compositionDefinitions("invalidcomposition") - .compositionInstances(List.of()).build()); + .compositionInstances(Set.of()).build()); Rapp rapp = Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation) .rappResources(rappResources).build();