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
--- /dev/null
+{
+ "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
--- /dev/null
+{
+ "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
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;
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());
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;
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));
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());
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));
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());
@Test
void testCreateInfoTypeFailureInvalidInfoType() {
Rapp rapp = getRapp(Optional.empty());
- assertFalse(dmeDeployer.createInfoTypes(rapp, null));
+ assertFalse(dmeDeployer.createProducerInfoTypes(rapp, null));
+ assertFalse(dmeDeployer.createConsumerInfoTypes(rapp, null));
}
@Test
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);
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;
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";
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) {
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);
@Builder
public static class DMEResources {
- Set<String> infoTypes;
+ Set<String> producerInfoTypes;
+ Set<String> consumerInfoTypes;
Set<String> infoProducers;
Set<String> infoConsumers;
}
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);
}
}
@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();