diff options
author | Einat Vinouze <einat.vinouze@intl.att.com> | 2019-11-04 11:20:29 +0200 |
---|---|---|
committer | Einat Vinouze <einat.vinouze@intl.att.com> | 2019-11-04 11:20:29 +0200 |
commit | 3ae52e57505549227bd30fbbd5cd45239858cfe7 (patch) | |
tree | e2440d710a8300f29da9020f2276d367fff8a379 /vid-app-common/src | |
parent | 46d7ba49211c86e9208d6634461afc6ebac70f8d (diff) |
fix - when retrieve topology we are using threadPool and the MDC values are not updated
Issue-ID: VID-253
Signed-off-by: Einat Vinouze <einat.vinouze@intl.att.com>
Change-Id: I275d1768f17764efc1bde36baf53439922b534ab
Signed-off-by: Einat Vinouze <einat.vinouze@intl.att.com>
Diffstat (limited to 'vid-app-common/src')
-rw-r--r-- | vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodeBuilder.java | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodeBuilder.java b/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodeBuilder.java index d53eba8d3..9a5e7484f 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodeBuilder.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodeBuilder.java @@ -42,6 +42,7 @@ import org.onap.vid.properties.VidProperties; import org.onap.vid.utils.Streams; import org.onap.vid.utils.Tree; import org.onap.vid.utils.Unchecked; +import org.slf4j.MDC; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Component; @@ -256,24 +257,33 @@ public class AAITreeNodeBuilder { if (!relationships.isEmpty()) { List<Callable<List<AAITreeNode>>> tasks = relationships.stream() - .map(relationship -> - (Callable<List<AAITreeNode>>) () -> - getChildNode(threadPool, nodesAccumulator, relationship.getRelatedTo(), - relationship.getRelatedLink(), pathsTree)) - .collect(Collectors.toList()); + .map(relationship -> + withCopyOfMDC(() -> getChildNode(threadPool, nodesAccumulator, relationship.getRelatedTo(), + relationship.getRelatedLink(), pathsTree))) + .collect(Collectors.toList()); try { int depth = pathsTree.getChildrenDepth(); threadPool.invokeAll(tasks, timeout * depth, TimeUnit.SECONDS) - .forEach(future -> - addChildren(node, future) - ); + .forEach(future -> + addChildren(node, future) + ); } catch (Exception e) { throw new GenericUncheckedException(e); } } } + private <V> Callable<V> withCopyOfMDC(Callable<V> callable) { + //in order to be able to write the correct data while creating the node on a new thread + // save a copy of the current thread's context map, with keys and values of type String. + final Map<String, String> copyOfParentMDC = MDC.getCopyOfContextMap(); + return () -> { + MDC.setContextMap(copyOfParentMDC); + return callable.call(); + }; + } + private List<AAITreeNode> getChildNode(ExecutorService threadPool, ConcurrentSkipListSet<AAITreeNode> nodesAccumulator, String childNodeType, String childNodeUrl, Tree<AAIServiceTree.AaiRelationship> pathsTree) { |