From 11624e0f91daddf9bf65d139436b5ffaeeccdc3e Mon Sep 17 00:00:00 2001 From: Phillip Leigh Date: Fri, 24 Aug 2018 14:50:18 -0400 Subject: BugFix:resourceType mismatch btw SrvDecomp &CtxBud Issue-ID: SDNC-317 Change-Id: Idc34aae969027dc6a5144d981686b6d512b2acbf Signed-off-by: Phillip Leigh --- .../networkdiscovery/NdctxbConfiguration.java | 42 ++++++++++++++++++++++ .../service/SpringServiceImpl.java | 10 +++++- 2 files changed, 51 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/NdctxbConfiguration.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/NdctxbConfiguration.java index ec5fb8d..a8f6f7f 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/NdctxbConfiguration.java +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/NdctxbConfiguration.java @@ -19,18 +19,30 @@ package org.onap.pomba.contextbuilder.networkdiscovery; import java.net.InetAddress; +import java.util.Arrays; import java.util.Base64; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.StreamSupport; + import org.eclipse.jetty.util.security.Password; import org.onap.pomba.contextbuilder.networkdiscovery.exception.DiscoveryException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; +import org.springframework.core.env.AbstractEnvironment; +import org.springframework.core.env.EnumerablePropertySource; +import org.springframework.core.env.Environment; +import org.springframework.core.env.MutablePropertySources; import org.springframework.stereotype.Component; @Component public class NdctxbConfiguration { private static Logger log = LoggerFactory.getLogger(NdctxbConfiguration.class); + private final String prefixResourceType = "networkDiscoveryCtxBuilder.resourceTypeMapping."; + private final String whiteSpace = "\\s"; // Network Discovery Context Builder Configuration values @@ -161,4 +173,34 @@ public class NdctxbConfiguration { return ("Basic " + Base64.getEncoder().encodeToString(auth.getBytes())); } + @Autowired + private Environment env; + + // This method builds a map between Service Decomposition resource type and Network Discovery + // Context Builder resource type using dynamic mapping technique. + // It scans the contents of the configuration file "application.properties", + // searching for the string "networkDiscoveryCtxBuilder.resourceTypeMapping.", and if found, + // anything from the remaining string will be used as the key (Service Decomposition resource Type) + // to match to the value of assignment (network discovery context builder resource type). + // For example,"networkDiscoveryCtxBuilder.resourceTypeMapping.BBB = bbb", + // Service Decomposition resource type BBB matches to context builder resource type bbb + @Bean(name = "networkDiscoveryCtxBuilderResourceTypeMapping") + public Map getResourceTypeMapping() { + Map props = new HashMap<>(); + MutablePropertySources propSrcs = ((AbstractEnvironment) this.env).getPropertySources(); + StreamSupport.stream(propSrcs.spliterator(), false) + .filter(ps -> ps instanceof EnumerablePropertySource) + .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()) + .flatMap(Arrays::stream) + .forEach(propName -> { + if (propName.startsWith(prefixResourceType)) { + String myKey = propName.substring(prefixResourceType.length()).replaceAll(whiteSpace,""); + String myValue = this.env.getProperty(propName).replaceAll(whiteSpace, ""); + props.put( myKey , myValue); + } + }); + + log.info(props.toString()); + return props; + } } diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringServiceImpl.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringServiceImpl.java index 89b07f8..7dbb1a9 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringServiceImpl.java +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringServiceImpl.java @@ -154,6 +154,9 @@ public class SpringServiceImpl implements SpringService { @Autowired private Client jerseyClient; + @javax.annotation.Resource + private Map networkDiscoveryCtxBuilderResourceTypeMapping; + private static final ReentrantLock lock = new ReentrantLock(); @Override @@ -436,7 +439,12 @@ public class SpringServiceImpl implements SpringService { for (Resource resource : resourceList) { String resourceId = resource.getResourceId(); - String resourceType = resource.getResourceType(); + String origResourceType = resource.getResourceType(); + String resourceType = networkDiscoveryCtxBuilderResourceTypeMapping.get(origResourceType); + if (resourceType == null) { + log.error("Unable to find " + origResourceType + " from networkDiscoveryCtxBuilderResourceTypeMapping"); + continue; + } // The old_requestId is inherited from ServiceDecomposition. // Before we send a -- cgit 1.2.3-korg