diff options
author | 2023-12-11 10:10:58 +0000 | |
---|---|---|
committer | 2023-12-11 10:10:58 +0000 | |
commit | 5b213f912d028e486b305f2502100bf693937469 (patch) | |
tree | 13d88d1ffbf7d6bd4c1e747ecd59c2294e231004 /cps-ncmp-service/src/main/java/org/onap | |
parent | 5fc0b52702b598b3d5b343092f0c3c3a8ad5e00c (diff) | |
parent | 41727e5dd167c71a63fb8b8f4e3136867b0e65b3 (diff) |
Merge "[BUG] Dminame to valid topic suffix"
Diffstat (limited to 'cps-ncmp-service/src/main/java/org/onap')
-rw-r--r-- | cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpInEventForwarder.java | 19 |
1 files changed, 17 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; + } } |