Add info types for producer and consumer in rApp package 64/11864/1
authoraravind.est <aravindhan.a@est.tech>
Fri, 6 Oct 2023 14:14:49 +0000 (15:14 +0100)
committeraravind.est <aravindhan.a@est.tech>
Fri, 6 Oct 2023 14:22:21 +0000 (15:22 +0100)
Infotypes separated for producer and consumer in CSAR packaging.

Issue-ID: NONRTRIC-940
Signed-off-by: aravind.est <aravindhan.a@est.tech>
Change-Id: Ib5e3e8c7718dc7497dab4d876bf40e424a3f0888

13 files changed:
csar-generator/resources/Files/Dme/consumerinfotypes/json-file-data-from-filestore.json [moved from csar-generator/resources/Files/Dme/infotypes/json-file-data-from-filestore.json with 100% similarity]
csar-generator/resources/Files/Dme/consumerinfotypes/xml-file-data-from-filestore.json [moved from csar-generator/resources/Files/Dme/infotypes/xml-file-data-from-filestore.json with 100% similarity]
csar-generator/resources/Files/Dme/producerinfotypes/json-file-data-from-filestore.json [new file with mode: 0644]
csar-generator/resources/Files/Dme/producerinfotypes/xml-file-data-from-filestore.json [new file with mode: 0644]
rapp-manager-dme/src/main/java/com/oransc/rappmanager/dme/service/DmeDeployer.java
rapp-manager-dme/src/test/java/com/oransc/rappmanager/dme/service/DmeDeployerTest.java
rapp-manager-dme/src/test/java/com/oransc/rappmanager/models/rapp/RappDmeResourceBuilder.java
rapp-manager-dme/src/test/resources/valid-rapp-package-new-info-type.csar
rapp-manager-dme/src/test/resources/valid-rapp-package.csar
rapp-manager-models/src/main/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandler.java
rapp-manager-models/src/main/java/com/oransc/rappmanager/models/rapp/RappResources.java
rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/RappCsarConfigurationHandlerTest.java
rapp-manager-models/src/test/resources/valid-rapp-package.csar

diff --git a/csar-generator/resources/Files/Dme/producerinfotypes/json-file-data-from-filestore.json b/csar-generator/resources/Files/Dme/producerinfotypes/json-file-data-from-filestore.json
new file mode 100644 (file)
index 0000000..a5f9d02
--- /dev/null
@@ -0,0 +1,8 @@
+{
+  "info_job_data_schema": {
+    "schema": "http://json-schema.org/draft-07/schema#",
+    "title": "json-file-data-from-filestore",
+    "description": "json-file-data-from-filestore",
+    "type": "object"
+  }
+}
\ No newline at end of file
diff --git a/csar-generator/resources/Files/Dme/producerinfotypes/xml-file-data-from-filestore.json b/csar-generator/resources/Files/Dme/producerinfotypes/xml-file-data-from-filestore.json
new file mode 100644 (file)
index 0000000..3585603
--- /dev/null
@@ -0,0 +1,8 @@
+{
+  "info_job_data_schema": {
+    "schema": "http://json-schema.org/draft-07/schema#",
+    "title": "xml-file-data-to-filestore",
+    "description": "xml-file-data-to-filestore",
+    "type": "object"
+  }
+}
\ No newline at end of file
index 329841f..a57f9b4 100755 (executable)
@@ -34,6 +34,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.function.BiFunction;
 import lombok.RequiredArgsConstructor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -60,16 +61,12 @@ public class DmeDeployer implements RappDeployer {
     public boolean deployRappInstance(Rapp rapp, RappInstance rappInstance) {
         logger.debug("Deploying DME functions for RappInstance {}", rappInstance.getRappInstanceId());
         boolean deployState = true;
-        if (rappInstance.getDme().getInfoTypesProducer() != null
-                    || rappInstance.getDme().getInfoTypeConsumer() != null) {
-            Set<String> infoTypes = new HashSet<>();
-            if (rappInstance.getDme().getInfoTypesProducer() != null) {
-                infoTypes.addAll(rappInstance.getDme().getInfoTypesProducer());
-            }
-            if (rappInstance.getDme().getInfoTypeConsumer() != null) {
-                infoTypes.add(rappInstance.getDme().getInfoTypeConsumer());
-            }
-            deployState = createInfoTypes(rapp, infoTypes);
+        if (rappInstance.getDme().getInfoTypesProducer() != null) {
+            deployState = createProducerInfoTypes(rapp, rappInstance.getDme().getInfoTypesProducer());
+        }
+        if (rappInstance.getDme().getInfoTypeConsumer() != null) {
+            deployState =
+                    deployState && createConsumerInfoTypes(rapp, Set.of(rappInstance.getDme().getInfoTypeConsumer()));
         }
         if (rappInstance.getDme().getInfoProducer() != null) {
             deployState = deployState && createInfoProducer(rapp, rappInstance.getDme().getInfoProducer());
@@ -123,14 +120,15 @@ public class DmeDeployer implements RappDeployer {
                 ConsumerJob consumerJob = objectMapper.readValue(consumerPayload, ConsumerJob.class);
                 requiredInfoTypes.add(consumerJob.getInfoTypeId());
             }
-            Set<String> allInfoTypes = new HashSet<>(rapp.getRappResources().getDme().getInfoTypes());
+            Set<String> allInfoTypes = new HashSet<>(rapp.getRappResources().getDme().getProducerInfoTypes());
+            allInfoTypes.addAll(rapp.getRappResources().getDme().getConsumerInfoTypes());
             requiredInfoTypes.removeAll(allInfoTypes);
             if (!requiredInfoTypes.isEmpty()) {
                 allInfoTypes.addAll(dataProducerRegistrationApiClient.getInfoTypdentifiers());
                 requiredInfoTypes.removeAll(allInfoTypes);
                 if (!requiredInfoTypes.isEmpty()) {
                     rapp.setReason(String.format("Invalid rapp package as the following info types cannot be found %s",
-                                    requiredInfoTypes));
+                            requiredInfoTypes));
                 }
             }
             return true;
@@ -147,12 +145,21 @@ public class DmeDeployer implements RappDeployer {
         return true;
     }
 
-    boolean createInfoTypes(Rapp rApp, Set<String> infoTypes) {
-        logger.debug("Creating DME info types {} for rApp {}", infoTypes, rApp.getRappId());
+    boolean createProducerInfoTypes(Rapp rApp, Set<String> infoTypes) {
+        logger.debug("Creating DME producer info types {} for rApp {}", infoTypes, rApp.getRappId());
+        return createInfoTypes(rApp, infoTypes, rappCsarConfigurationHandler::getDmeProducerInfoTypePayload);
+    }
+
+    boolean createConsumerInfoTypes(Rapp rApp, Set<String> infoTypes) {
+        logger.debug("Creating DME consumer info types {} for rApp {}", infoTypes, rApp.getRappId());
+        return createInfoTypes(rApp, infoTypes, rappCsarConfigurationHandler::getDmeConsumerInfoTypePayload);
+    }
+
+    boolean createInfoTypes(Rapp rApp, Set<String> infoTypes, BiFunction<Rapp, String, String> payloadReader) {
         try {
             Map<String, ProducerInfoTypeInfo> producerInfoTypeInfoMap = new HashMap<>();
             for (String infoType : infoTypes) {
-                String infoTypePayload = rappCsarConfigurationHandler.getDmeInfoTypePayload(rApp, infoType);
+                String infoTypePayload = payloadReader.apply(rApp, infoType);
                 if (infoTypePayload != null && !infoTypePayload.isEmpty()) {
                     producerInfoTypeInfoMap.put(infoType,
                             objectMapper.readValue(infoTypePayload, ProducerInfoTypeInfo.class));
index d5fb291..e85fbe3 100755 (executable)
@@ -173,6 +173,7 @@ class DmeDeployerTest {
         Rapp rapp = getRapp(Optional.empty());
         RappInstance rappInstance = rappDmeResourceBuilder.getRappInstance();
         getMockServerClientCreateInfoType(rappInstance.getDme().getInfoTypesProducer().toArray()[0].toString(), true);
+        getMockServerClientCreateInfoType(rappInstance.getDme().getInfoTypeConsumer(), true);
         getMockServerClientCreateInfoProducer(rappInstance.getDme().getInfoProducer(), true);
         getMockServerClientCreateInfoConsumer(rappInstance.getDme().getInfoConsumer(), true);
         rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
@@ -221,6 +222,7 @@ class DmeDeployerTest {
         Rapp rapp = getRapp(Optional.empty());
         RappInstance rappInstance = rappDmeResourceBuilder.getRappInstance();
         getMockServerClientCreateInfoType(rappInstance.getDme().getInfoTypesProducer().toArray()[0].toString(), true);
+        getMockServerClientCreateInfoType(rappInstance.getDme().getInfoTypeConsumer(), true);
         getMockServerClientCreateInfoProducer(rappInstance.getDme().getInfoProducer(), false);
         rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
         assertFalse(dmeDeployer.deployRappInstance(rapp, rappInstance));
@@ -232,6 +234,7 @@ class DmeDeployerTest {
         Rapp rapp = getRapp(Optional.empty());
         RappInstance rappInstance = rappDmeResourceBuilder.getRappInstance();
         getMockServerClientCreateInfoType(rappInstance.getDme().getInfoTypesProducer().toArray()[0].toString(), true);
+        getMockServerClientCreateInfoType(rappInstance.getDme().getInfoTypeConsumer(), true);
         getMockServerClientCreateInfoProducer(rappInstance.getDme().getInfoProducer(), true);
         getMockServerClientCreateInfoConsumer(rappInstance.getDme().getInfoConsumer(), false);
         rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
@@ -278,7 +281,8 @@ class DmeDeployerTest {
     @Test
     void testCreateInfoTypeFailureInvalidInfoType() {
         Rapp rapp = getRapp(Optional.empty());
-        assertFalse(dmeDeployer.createInfoTypes(rapp, null));
+        assertFalse(dmeDeployer.createProducerInfoTypes(rapp, null));
+        assertFalse(dmeDeployer.createConsumerInfoTypes(rapp, null));
     }
 
     @Test
index c12d981..e20be29 100755 (executable)
@@ -27,7 +27,8 @@ public class RappDmeResourceBuilder {
     public RappResources getResources() {
         RappResources rappResources = new RappResources();
         RappResources.DMEResources dmeResources =
-                new RappResources.DMEResources(Set.of("json-file-data-from-filestore", "xml-file-data-from-filestore"),
+                new RappResources.DMEResources(Set.of("json-file-data-from-filestore"),
+                        Set.of("xml-file-data-from-filestore"),
                         Set.of("json-file-data-producer", "xml-file-data-producer"),
                         Set.of("json-file-consumer", "xml-file-consumer"));
         rappResources.setDme(dmeResources);
@@ -39,7 +40,7 @@ public class RappDmeResourceBuilder {
         RappDMEInstance rappDMEInstance = new RappDMEInstance();
         rappDMEInstance.setInfoTypesProducer(Set.of("json-file-data-from-filestore"));
         rappDMEInstance.setInfoProducer("json-file-data-producer");
-        rappDMEInstance.setInfoTypeConsumer("json-file-data-from-filestore");
+        rappDMEInstance.setInfoTypeConsumer("xml-file-data-from-filestore");
         rappDMEInstance.setInfoConsumer("json-file-consumer");
         rappInstance.setDme(rappDMEInstance);
         return rappInstance;
index 67ae27c..d858a67 100755 (executable)
Binary files a/rapp-manager-dme/src/test/resources/valid-rapp-package-new-info-type.csar and b/rapp-manager-dme/src/test/resources/valid-rapp-package-new-info-type.csar differ
index b3d75b2..7400891 100755 (executable)
Binary files a/rapp-manager-dme/src/test/resources/valid-rapp-package.csar and b/rapp-manager-dme/src/test/resources/valid-rapp-package.csar differ
index 05bf056..be6fe88 100755 (executable)
@@ -50,7 +50,8 @@ public class RappCsarConfigurationHandler {
     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_INFO_TYPES_LOCATION = "Files/Dme/infotypes";
+    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";
 
@@ -141,8 +142,12 @@ public class RappCsarConfigurationHandler {
         return getPayload(rapp, getResourceUri(DME_INFO_PRODUCERS_LOCATION, producerIdentifier));
     }
 
-    public String getDmeInfoTypePayload(Rapp rapp, String infoTypeIdentifier) {
-        return getPayload(rapp, getResourceUri(DME_INFO_TYPES_LOCATION, infoTypeIdentifier));
+    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) {
@@ -165,10 +170,12 @@ public class RappCsarConfigurationHandler {
                                 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()
-                                             .infoTypes(getFileListFromCsar(csarFile, DME_INFO_TYPES_LOCATION))
+                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());
+                                             .infoConsumers(getFileListFromCsar(csarFile, DME_INFO_CONSUMERS_LOCATION))
+                                             .build());
             }
         } catch (Exception e) {
             logger.warn("Error in getting the rapp resources", e);
index d9344e4..826fd25 100755 (executable)
@@ -50,7 +50,8 @@ public class RappResources {
     @Builder
     public static class DMEResources {
 
-        Set<String> infoTypes;
+        Set<String> producerInfoTypes;
+        Set<String> consumerInfoTypes;
         Set<String> infoProducers;
         Set<String> infoConsumers;
     }
index d5e8d42..8c416ee 100755 (executable)
@@ -134,7 +134,8 @@ class RappCsarConfigurationHandlerTest {
         assertThat(rappResources.getSme().getProviderFunctions()).hasSize(4);
         assertThat(rappResources.getSme().getServiceApis()).hasSize(2);
         assertThat(rappResources.getSme().getInvokers()).hasSize(2);
-        assertThat(rappResources.getDme().getInfoTypes()).hasSize(2);
+        assertThat(rappResources.getDme().getProducerInfoTypes()).hasSize(2);
+        assertThat(rappResources.getDme().getConsumerInfoTypes()).hasSize(2);
         assertThat(rappResources.getDme().getInfoProducers()).hasSize(2);
         assertThat(rappResources.getDme().getInfoConsumers()).hasSize(2);
     }
@@ -214,18 +215,31 @@ class RappCsarConfigurationHandlerTest {
     }
 
     @Test
-    void testGetDmeInfoTypePayload() {
+    void testGetDmeProducerInfoTypePayload() {
         UUID rappId = UUID.randomUUID();
         RappDMEInstance rappDMEInstance = new RappDMEInstance();
         rappDMEInstance.setInfoTypesProducer(Set.of("json-file-data-from-filestore"));
         Rapp rapp =
                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
                         .build();
-        String dmeInfoTypePayload = rappCsarConfigurationHandler.getDmeInfoTypePayload(rapp,
+        String dmeInfoTypePayload = rappCsarConfigurationHandler.getDmeProducerInfoTypePayload(rapp,
                 rappDMEInstance.getInfoTypesProducer().iterator().next());
         assertNotNull(dmeInfoTypePayload);
     }
 
+    @Test
+    void testGetDmeConsumerInfoTypePayload() {
+        UUID rappId = UUID.randomUUID();
+        RappDMEInstance rappDMEInstance = new RappDMEInstance();
+        rappDMEInstance.setInfoTypeConsumer("json-file-data-from-filestore");
+        Rapp rapp =
+                Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
+                        .build();
+        String dmeInfoTypePayload =
+                rappCsarConfigurationHandler.getDmeConsumerInfoTypePayload(rapp, rappDMEInstance.getInfoTypeConsumer());
+        assertNotNull(dmeInfoTypePayload);
+    }
+
     @Test
     void testGetDmeInfoProducerPayload() {
         UUID rappId = UUID.randomUUID();
index b3d75b2..7400891 100755 (executable)
Binary files a/rapp-manager-models/src/test/resources/valid-rapp-package.csar and b/rapp-manager-models/src/test/resources/valid-rapp-package.csar differ