diff options
author | Ittay Stern <ittay.stern@att.com> | 2019-11-04 14:30:56 +0200 |
---|---|---|
committer | Ittay Stern <ittay.stern@att.com> | 2019-11-04 14:40:22 +0200 |
commit | 43b1593e3c2a250535bfadcc6829be9873a98259 (patch) | |
tree | e6d1e551d2a6f3846b836190b0630ea9c03e0069 /vid-app-common/src/main/java/org/onap | |
parent | 95dc3ee8072b633982d7bcd18b726350f2f6dc06 (diff) |
fix - when retrieve topology we are using threadPool and the MDC values are not updated
This time for vf-modules parallel request.
Issue-ID: VID-253
Change-Id: Ib32c29b231e16ccc1b4fbbad022c8d9ad058b74a
Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/onap')
-rw-r--r-- | vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodeBuilder.java | 59 |
1 files changed, 40 insertions, 19 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 9a5e7484f..c8434609e 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 @@ -20,8 +20,28 @@ package org.onap.vid.services; +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toMap; +import static java.util.stream.Collectors.toSet; +import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER; +import static org.onap.vid.utils.Streams.not; + import com.fasterxml.jackson.databind.JsonNode; import com.google.common.collect.ImmutableList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentSkipListSet; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import javax.inject.Inject; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; @@ -46,16 +66,6 @@ import org.slf4j.MDC; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Component; -import javax.inject.Inject; -import java.util.*; -import java.util.concurrent.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static java.util.stream.Collectors.*; -import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER; -import static org.onap.vid.utils.Streams.not; - @Component public class AAITreeNodeBuilder { @@ -206,7 +216,7 @@ public class AAITreeNodeBuilder { directly fetching a resource URI. */ - threadPool.execute(() -> { + Future<?> vfModulesTask = threadPool.submit(withCopyOfMDC(() -> { // the response is an array of vf-modules final JsonNode jsonNode; try { @@ -215,29 +225,40 @@ public class AAITreeNodeBuilder { if (e.getHttpCode().equals(404)) { // it's ok, as we're just optimistically fetching // the /vf-modules uri; 404 says this time it was a bad guess - return; + return true; } else { throw e; } } if (isArray(jsonNode, NodeType.VF_MODULE)) { - //create list of AAITreeNode represent the VfModules from AAI result List<AAITreeNode> vfModules = Streams.fromIterable(jsonNode.get(NodeType.VF_MODULE.getType())) - .map(vfModuleNode -> createAaiNode(NodeType.VF_MODULE, vfModuleNode, nodesAccumulator)) - .collect(toList()); + .map(vfModuleNode -> createAaiNode(NodeType.VF_MODULE, vfModuleNode, nodesAccumulator)) + .collect(toList()); //enrich each of the VfModule with placement info - vfModules.forEach(vfModule-> enrichPlacementDataUsingTenantInfo( - vfModule, - AAITreeNodeUtils.findFirstRelationshipByRelatedTo(vfModule.getRelationshipList(), "vserver") + vfModules.forEach(vfModule -> enrichPlacementDataUsingTenantInfo( + vfModule, + AAITreeNodeUtils.findFirstRelationshipByRelatedTo(vfModule.getRelationshipList(), "vserver") )); //add all VfModules to children list of parent node parentNode.getChildren().addAll(vfModules); } else { LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to get vf-modules for vnf " + parentNode.getId()); } - }); + + return true; // the Callable<> contract requires a return value + })); + + waitForCompletion(vfModulesTask); + } + + private void waitForCompletion(Future<?> future) { + try { + future.get(); + } catch (Exception e) { + throw new GenericUncheckedException(e); + } } List<Relationship> getFilteredRelationships(JsonNode json, Tree<AAIServiceTree.AaiRelationship> pathsTree) { |