Change the dmi address source from dmi-service-name to dmi-data-service-name for writeDataJob
-Change implementation to convert datanode to yang model
-Change to resolve service name consistent with other implementations
Issue-ID: CPS-2455
Change-Id: I9cbe494b8c37eb963c42abee1ac5f04a3f695d07
Signed-off-by: egernug <gerard.nugent@est.tech>
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminer.java
index 70d08dc..e13d3c2 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminer.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminer.java
@@ -32,6 +32,7 @@
import org.onap.cps.ncmp.api.datajobs.models.ProducerKey;
import org.onap.cps.ncmp.api.datajobs.models.WriteOperation;
import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle;
+import org.onap.cps.ncmp.impl.models.RequiredDmiService;
import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher;
import org.onap.cps.ncmp.impl.utils.YangDataConverter;
import org.onap.cps.spi.model.DataNode;
@@ -69,9 +70,11 @@
final DataNode dataNode = alternateIdMatcher
.getCmHandleDataNodeByLongestMatchingAlternateId(writeOperation.path(), PATH_SEPARATOR);
- final DmiWriteOperation dmiWriteOperation = createDmiWriteOperation(writeOperation, dataNode);
+ final YangModelCmHandle yangModelCmHandle = YangDataConverter.toYangModelCmHandle(dataNode);
- final ProducerKey producerKey = createProducerKey(dataNode);
+ final DmiWriteOperation dmiWriteOperation = createDmiWriteOperation(writeOperation, yangModelCmHandle);
+
+ final ProducerKey producerKey = createProducerKey(yangModelCmHandle);
final List<DmiWriteOperation> dmiWriteOperations;
if (dmiWriteOperationsPerProducerKey.containsKey(producerKey)) {
dmiWriteOperations = dmiWriteOperationsPerProducerKey.get(producerKey);
@@ -82,24 +85,23 @@
dmiWriteOperations.add(dmiWriteOperation);
}
- private ProducerKey createProducerKey(final DataNode dataNode) {
- return new ProducerKey((String) dataNode.getLeaves().get("dmi-service-name"),
- (String) dataNode.getLeaves().get("data-producer-identifier"));
+ private ProducerKey createProducerKey(final YangModelCmHandle yangModelCmHandle) {
+ return new ProducerKey(yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA),
+ yangModelCmHandle.getDataProducerIdentifier());
}
private DmiWriteOperation createDmiWriteOperation(final WriteOperation writeOperation,
- final DataNode dataNode) {
+ final YangModelCmHandle yangModelCmHandle) {
return new DmiWriteOperation(
writeOperation.path(),
writeOperation.op(),
- (String) dataNode.getLeaves().get("module-set-tag"),
+ yangModelCmHandle.getModuleSetTag(),
writeOperation.value(),
writeOperation.operationId(),
- getPrivatePropertiesFromDataNode(dataNode));
+ getPrivatePropertiesFromDataNode(yangModelCmHandle));
}
- private Map<String, String> getPrivatePropertiesFromDataNode(final DataNode dataNode) {
- final YangModelCmHandle yangModelCmHandle = YangDataConverter.toYangModelCmHandle(dataNode);
+ private Map<String, String> getPrivatePropertiesFromDataNode(final YangModelCmHandle yangModelCmHandle) {
final Map<String, String> cmHandleDmiProperties = new LinkedHashMap<>();
yangModelCmHandle.getDmiProperties()
.forEach(dmiProperty -> cmHandleDmiProperties.put(dmiProperty.getName(), dmiProperty.getValue()));
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminerSpec.groovy
index 84eb78b..47b5766 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminerSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminerSpec.groovy
@@ -3,6 +3,8 @@
import org.onap.cps.ncmp.api.datajobs.models.DataJobWriteRequest
import org.onap.cps.ncmp.api.datajobs.models.WriteOperation
+import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle
+import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle
import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher
import org.onap.cps.spi.model.DataNode
import spock.lang.Specification
@@ -60,4 +62,18 @@
then: 'we get the operation ids in the expected order.'
assert dmiWriteOperations.operationId == ['1', '2', '3']
}
+
+ def 'Validate the creation of a ProducerKey with correct dmiservicename.'() {
+ given: 'yangModelCmHandles with service name: "#dmiServiceName" and data service name: "#dataServiceName"'
+ def yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(dmiServiceName, dataServiceName, '', new NcmpServiceCmHandle(cmHandleId: 'cm-handle-id-1'), '', '', 'dpi1')
+ when: 'the ProducerKey is created'
+ def result = objectUnderTest.createProducerKey(yangModelCmHandle).toString()
+ then: 'we get the ProducerKey with the correct service name'
+ assert result == expectedProducerKey
+ where: 'the following services are registered'
+ dmiServiceName | dataServiceName || expectedProducerKey
+ 'dmi-service-name' | '' || 'dmi-service-name#dpi1'
+ '' | 'dmi-data-service-name' || 'dmi-data-service-name#dpi1'
+ 'dmi-service-name' | 'dmi-data-service-name' || 'dmi-service-name#dpi1'
+ }
}