X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=rapp-manager-models%2Fsrc%2Fmain%2Fjava%2Fcom%2Foransc%2Frappmanager%2Fmodels%2Fcsar%2FRappCsarConfigurationHandler.java;h=be6fe8875457d851f17a442d09832f8a159bd148;hb=4a9eca242a06d57fb9dca16b1a59cab2d6250c7b;hp=e088463137c8fff2a88fc2ac0d917ac28921bbaa;hpb=307d0014124de40826d1af537c0e463a9dcf594d;p=nonrtric%2Fplt%2Frappmanager.git 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 e088463..be6fe88 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,12 +27,14 @@ 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 java.util.zip.ZipInputStream; +import org.apache.commons.compress.archivers.ArchiveEntry; +import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -45,11 +47,13 @@ public class RappCsarConfigurationHandler { private static final String ACM_COMPOSITION_JSON_LOCATION = "Files/Acm/definition/compositions.json"; private static final String ACM_DEFINITION_LOCATION = "Files/Acm/definition"; private static final String ACM_INSTANCES_LOCATION = "Files/Acm/instances"; - private static final String SME_PROVIDER_FUNCS_LOCATION = "Files/Sme/providers"; private static final String SME_SERVICE_APIS_LOCATION = "Files/Sme/serviceapis"; - private static final String SME_INVOKERS_LOCATION = "Files/Sme/invokers"; + private static final String DME_PRODUCER_INFO_TYPES_LOCATION = "Files/Dme/producerinfotypes"; + private static final String DME_CONSUMER_INFO_TYPES_LOCATION = "Files/Dme/consumerinfotypes"; + private static final String DME_INFO_PRODUCERS_LOCATION = "Files/Dme/infoproducers"; + private static final String DME_INFO_CONSUMERS_LOCATION = "Files/Dme/infoconsumers"; public boolean isValidRappPackage(MultipartFile multipartFile) { @@ -62,9 +66,9 @@ public class RappCsarConfigurationHandler { } boolean isFileExistsInCsar(MultipartFile multipartFile, String fileLocation) { - try (ZipInputStream zipInputStream = new ZipInputStream(multipartFile.getInputStream())) { - ZipEntry zipEntry; - while ((zipEntry = zipInputStream.getNextEntry()) != null) { + try (ZipArchiveInputStream zipArchiveInputStream = new ZipArchiveInputStream(multipartFile.getInputStream())) { + ArchiveEntry zipEntry; + while ((zipEntry = zipArchiveInputStream.getNextEntry()) != null) { if (zipEntry.getName().matches(fileLocation)) { return Boolean.TRUE; } @@ -86,7 +90,7 @@ public class RappCsarConfigurationHandler { } String getPayload(Rapp rapp, String location) { - logger.info("Getting payload for {} from {}", rapp.getRappId(), location); + logger.debug("Getting payload for {} from {}", rapp.getRappId(), location); File csarFile = getCsarFile(rapp); return getFileFromCsar(csarFile, location).toString(); } @@ -99,13 +103,13 @@ public class RappCsarConfigurationHandler { ByteArrayOutputStream getFileFromCsar(File csarFile, String fileLocation) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try (FileInputStream fileInputStream = new FileInputStream(csarFile); - ZipInputStream zipInputStream = new ZipInputStream(fileInputStream)) { - ZipEntry entry; - while ((entry = zipInputStream.getNextEntry()) != null) { + ZipArchiveInputStream zipArchiveInputStream = new ZipArchiveInputStream(fileInputStream)) { + ArchiveEntry entry; + while ((entry = zipArchiveInputStream.getNextEntry()) != null) { if (!entry.isDirectory() && entry.getName().equals(fileLocation)) { byte[] buffer = new byte[1024]; int bytesRead; - while ((bytesRead = zipInputStream.read(buffer)) != -1) { + while ((bytesRead = zipArchiveInputStream.read(buffer)) != -1) { byteArrayOutputStream.write(buffer, 0, bytesRead); } } @@ -134,6 +138,22 @@ public class RappCsarConfigurationHandler { getResourceUri(ACM_DEFINITION_LOCATION, rapp.getRappResources().getAcm().getCompositionDefinitions())); } + public String getDmeInfoProducerPayload(Rapp rapp, String producerIdentifier) { + return getPayload(rapp, getResourceUri(DME_INFO_PRODUCERS_LOCATION, producerIdentifier)); + } + + public String getDmeProducerInfoTypePayload(Rapp rapp, String infoTypeIdentifier) { + return getPayload(rapp, getResourceUri(DME_PRODUCER_INFO_TYPES_LOCATION, infoTypeIdentifier)); + } + + public String getDmeConsumerInfoTypePayload(Rapp rapp, String infoTypeIdentifier) { + return getPayload(rapp, getResourceUri(DME_CONSUMER_INFO_TYPES_LOCATION, infoTypeIdentifier)); + } + + public String getDmeInfoConsumerPayload(Rapp rapp, String infoConsumerIdentifier) { + return getPayload(rapp, getResourceUri(DME_INFO_CONSUMERS_LOCATION, infoConsumerIdentifier)); + } + String getResourceUri(String resourceLocation, String resource) { return resourceLocation + "/" + resource + ".json"; } @@ -144,14 +164,18 @@ 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_INSTANCES_LOCATION)) - .build()); - rappResources.setSme(RappResources.SMEResources.builder() - .providerFunctions(getFileListFromCsar(csarFile, - SME_PROVIDER_FUNCS_LOCATION)) + 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)) .serviceApis(getFileListFromCsar(csarFile, SME_SERVICE_APIS_LOCATION)) .invokers(getFileListFromCsar(csarFile, SME_INVOKERS_LOCATION)).build()); + rappResources.setDme(RappResources.DMEResources.builder().producerInfoTypes( + getFileListFromCsar(csarFile, DME_PRODUCER_INFO_TYPES_LOCATION)).consumerInfoTypes( + getFileListFromCsar(csarFile, DME_CONSUMER_INFO_TYPES_LOCATION)) + .infoProducers(getFileListFromCsar(csarFile, DME_INFO_PRODUCERS_LOCATION)) + .infoConsumers(getFileListFromCsar(csarFile, DME_INFO_CONSUMERS_LOCATION)) + .build()); } } catch (Exception e) { logger.warn("Error in getting the rapp resources", e); @@ -159,14 +183,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(); } }