summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormpriyank <priyank.maheshwari@est.tech>2023-12-04 18:01:07 +0000
committermpriyank <priyank.maheshwari@est.tech>2023-12-06 12:21:39 +0000
commit41727e5dd167c71a63fb8b8f4e3136867b0e65b3 (patch)
tree5c5b6dc6a6f46185e20aa9bc9e4d604d314f48aa
parent4d1b233782d28789ede02b1bad5cda1923a8f650 (diff)
[BUG] Dminame to valid topic suffix
- dmi name can be in the form of URL , and we are using dmi-name as topic suffix , which results in the invalid topic name. - fix to extract out domain name excluding port from the url - test case for the same - updated the documentation - fix only supports ipv4 addresses at the moment Issue-ID: CPS-1979 Change-Id: I9c6ea113afae816f727b45a30c94070af013a16d Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpInEventForwarder.java19
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpInEventForwarderSpec.groovy16
-rwxr-xr-xdocs/release-notes.rst1
3 files changed, 34 insertions, 2 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpInEventForwarder.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpInEventForwarder.java
index 5f26db335..e8086b117 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpInEventForwarder.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpInEventForwarder.java
@@ -31,6 +31,8 @@ import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -56,6 +58,9 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor
public class CmSubscriptionNcmpInEventForwarder {
+ private static final Pattern REGEX_TO_EXTRACT_DOMAIN_FROM_URL_EXCLUDING_PORT =
+ Pattern.compile("http[s]?:\\/\\/(?:www\\.)?([^\\/:]+):{0,1}[0-9]{0,5}");
+
private final InventoryPersistence inventoryPersistence;
private final EventsPublisher<CloudEvent> eventsPublisher;
private final IMap<String, Set<String>> forwardedSubscriptionEventCache;
@@ -153,8 +158,9 @@ public class CmSubscriptionNcmpInEventForwarder {
}).collect(Collectors.toList());
cmSubscriptionDmiInEvent.getData().getPredicates().setTargets(cmHandleTargets);
- final String eventKey = createEventKey(cmSubscriptionDmiInEvent, dmiName);
- final String dmiAvcSubscriptionTopic = dmiAvcSubscriptionTopicPrefix + dmiName;
+ final String dmiNameSuffix = toValidTopicSuffix(dmiName);
+ final String eventKey = createEventKey(cmSubscriptionDmiInEvent, dmiNameSuffix);
+ final String dmiAvcSubscriptionTopic = dmiAvcSubscriptionTopicPrefix + dmiNameSuffix;
final CloudEvent cmSubscriptionDmiInCloudEvent =
cmSubscriptionEventCloudMapper.toCloudEvent(cmSubscriptionDmiInEvent, eventKey, eventType);
@@ -186,4 +192,13 @@ public class CmSubscriptionNcmpInEventForwarder {
SubscriptionStatus.REJECTED, "Targets not found"))
.collect(Collectors.toList());
}
+
+ /*
+ CPS-1979 : DmiName can be a URL , which is not a valid topic name.
+ Hence just taking the domain name(excluding port) information to be part of the topic name.
+ */
+ private String toValidTopicSuffix(final String dmiName) {
+ final Matcher matcher = REGEX_TO_EXTRACT_DOMAIN_FROM_URL_EXCLUDING_PORT.matcher(dmiName);
+ return matcher.find() ? matcher.group(1) : dmiName;
+ }
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpInEventForwarderSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpInEventForwarderSpec.groovy
index 1edfa58f9..ce117eef5 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpInEventForwarderSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpInEventForwarderSpec.groovy
@@ -179,6 +179,22 @@ class CmSubscriptionNcmpInEventForwarderSpec extends MessagingBaseSpec {
1 * mockCmSubscriptionNcmpOutEventPublisher.sendResponse(_, 'subscriptionCreatedStatus')
}
+ def 'Extract domain name from URL for #scenario'() {
+ when: 'a valid dmi name is provided'
+ def domainName = objectUnderTest.toValidTopicSuffix(dmiName)
+ then: 'domain name is as expected with no port information'
+ assert domainName == expectedDomainName
+ where: ''
+ scenario | dmiName || expectedDomainName
+ 'insecure http url with port' | 'http://www.onap-dmi:8080/xyz=123' || 'onap-dmi'
+ 'insecure http url without port' | 'http://www.onap-dmi/xyz=123' || 'onap-dmi'
+ 'secure https url with port' | 'https://127.0.0.1:8080/xyz=123' || '127.0.0.1'
+ 'secure https url without port' | 'https://127.0.0.1/xyz=123' || '127.0.0.1'
+ 'servername without protocol and port' | 'dminame1' || 'dminame1'
+ 'servername without protocol' | 'www.onap-dmi:8080/xyz=123' || 'www.onap-dmi:8080/xyz=123'
+
+ }
+
static def createYangModelCmHandleWithDmiProperty(id, dmiId, propertyName, propertyValue) {
return new YangModelCmHandle(id: "CMHandle" + id, dmiDataServiceName: "DMIName" + dmiId, dmiProperties: [new YangModelCmHandle.Property(propertyName, propertyValue)])
}
diff --git a/docs/release-notes.rst b/docs/release-notes.rst
index 8bdc3fc9a..63a877d81 100755
--- a/docs/release-notes.rst
+++ b/docs/release-notes.rst
@@ -38,6 +38,7 @@ Release Data
Bug Fixes
---------
+ - `CPS-1979 <https://jira.onap.org/browse/CPS-1979>`_ Bug fix for Invalid topic name suffix.
Features
--------