summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2019-11-04 14:30:56 +0200
committerIttay Stern <ittay.stern@att.com>2019-11-04 14:40:22 +0200
commit43b1593e3c2a250535bfadcc6829be9873a98259 (patch)
treee6d1e551d2a6f3846b836190b0630ea9c03e0069
parent95dc3ee8072b633982d7bcd18b726350f2f6dc06 (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>
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodeBuilder.java59
-rw-r--r--vid-automation/src/test/java/org/onap/vid/api/ServiceTreeApiTest.java12
2 files changed, 48 insertions, 23 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) {
diff --git a/vid-automation/src/test/java/org/onap/vid/api/ServiceTreeApiTest.java b/vid-automation/src/test/java/org/onap/vid/api/ServiceTreeApiTest.java
index 82cc72081..f8bdc97e2 100644
--- a/vid-automation/src/test/java/org/onap/vid/api/ServiceTreeApiTest.java
+++ b/vid-automation/src/test/java/org/onap/vid/api/ServiceTreeApiTest.java
@@ -179,8 +179,7 @@ public class ServiceTreeApiTest extends BaseApiTest {
.replace("VNF4_INSTANCE_TYPE", vnfPreset4.getInstanceType());
assertJsonEquals(response, expected);
- final String requestId = responseEntity.getHeaders().getFirst("X-ECOMP-RequestID-echo");
- LoggerFormatTest.assertHeadersAndMetricLogs(restTemplate, uri, requestId, "/network/generic-vnfs/generic-vnf/", 5);
+ LoggerFormatTest.assertHeadersAndMetricLogs(restTemplate, uri, echoedRequestId(responseEntity), "/network/generic-vnfs/generic-vnf/", 5);
}
@Test
@@ -292,9 +291,14 @@ public class ServiceTreeApiTest extends BaseApiTest {
.replace("NETWORK4_INSTANCE_NAME", l3NetworkPreset4.getInstanceName())
.replace("NETWORK4_INSTANCE_ID", l3NetworkPreset4.getInstanceId());
- String response = restTemplate.getForObject(buildUri(API_URL), String.class, "global-customer-id", "service-instance-type", "service-instance-id");
+ ResponseEntity<String> response = restTemplate.getForEntity(buildUri(API_URL), String.class, "global-customer-id", "service-instance-type", "service-instance-id");
- assertJsonEquals(response, expected);
+ assertJsonEquals(response.getBody(), expected);
+ LoggerFormatTest.assertHeadersAndMetricLogs(restTemplate, uri, echoedRequestId(response), "/vf-modules", 2);
+ }
+
+ private String echoedRequestId(ResponseEntity<?> response) {
+ return response.getHeaders().getFirst("X-ECOMP-RequestID-echo");
}
@Override