summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/main')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/properties/Features.java1
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodeBuilder.java85
-rw-r--r--vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties3
3 files changed, 61 insertions, 28 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/properties/Features.java b/vid-app-common/src/main/java/org/onap/vid/properties/Features.java
index a3343d36b..abee30025 100644
--- a/vid-app-common/src/main/java/org/onap/vid/properties/Features.java
+++ b/vid-app-common/src/main/java/org/onap/vid/properties/Features.java
@@ -80,6 +80,7 @@ public enum Features implements Feature {
FLAG_FLASH_MORE_ACTIONS_BUTTON_IN_OLD_VIEW_EDIT,
FLAG_FLASH_CLOUD_REGION_AND_NF_ROLE_OPTIONAL_SEARCH,
FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE,
+ FLAG_1911_INSTANTIATION_ORDER_BUTTON_IN_ASYNC_ALACARTE
;
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..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;
@@ -42,19 +62,10 @@ 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;
-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 {
@@ -205,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 {
@@ -214,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) {
@@ -256,24 +278,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) {
diff --git a/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties b/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties
index d4910bf25..6ed0c7bcd 100644
--- a/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties
+++ b/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties
@@ -36,4 +36,5 @@ FLAG_DISABLE_HOMING = true
FLAG_FLASH_CLOUD_REGION_AND_NF_ROLE_OPTIONAL_SEARCH=false
FLAG_FLASH_REDUCED_RESPONSE_CHANGEMG = false
FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE = false
-FLAG_SHOW_ORCHESTRATION_TYPE = false
+FLAG_SHOW_ORCHESTRATION_TYPE = false,
+FLAG_1911_INSTANTIATION_ORDER_BUTTON_IN_ASYNC_ALACARTE = false