aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhillip Leigh <phillip.leigh@amdocs.com>2018-08-24 14:50:18 -0400
committerPhillip Leigh <phillip.leigh@amdocs.com>2018-08-27 11:47:49 -0400
commit11624e0f91daddf9bf65d139436b5ffaeeccdc3e (patch)
treeb20360f9c75a84c17e9ab56d36035a505626a12e
parent70b95e441017c1cc89c106c7167da2ef99da8748 (diff)
BugFix:resourceType mismatch btw SrvDecomp &CtxBud
Issue-ID: SDNC-317 Change-Id: Idc34aae969027dc6a5144d981686b6d512b2acbf Signed-off-by: Phillip Leigh <phillip.leigh@amdocs.com>
-rw-r--r--config/application.properties5
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/NdctxbConfiguration.java42
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringServiceImpl.java10
3 files changed, 56 insertions, 1 deletions
diff --git a/config/application.properties b/config/application.properties
index 556c240..6a40904 100644
--- a/config/application.properties
+++ b/config/application.properties
@@ -24,6 +24,11 @@ networkDiscoveryCtxBuilder.userId=admin
networkDiscoveryCtxBuilder.password=OBF:1u2a1toa1w8v1tok1u30
networkDiscoveryCtxBuilder.resourceList=vnfcs,vservers,l3-networks
+# Resource Type mapping from ServiceDecomposition type to CtxBuilder type
+networkDiscoveryCtxBuilder.resourceTypeMapping.vnfcs=vnfc
+networkDiscoveryCtxBuilder.resourceTypeMapping.vservers=vserver
+networkDiscoveryCtxBuilder.resourceTypeMapping.l3-networks=l3-network
+
# Service Decomposition REST Client Configuration
serviceDecomposition.httpProtocol=http
serviceDecomposition.host=10.147.112.136
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<String, String> getResourceTypeMapping() {
+ Map<String, String> 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::<String>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<String, String> 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