aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/main/java/org/onap')
-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/AAIServiceTree.java18
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodesEnricher.java82
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/VidService.java3
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/VidServiceImpl.java20
5 files changed, 104 insertions, 20 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 219b65def..939684c58 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
@@ -88,6 +88,7 @@ public enum Features implements Feature {
FLAG_2006_USER_PERMISSIONS_BY_OWNING_ENTITY,
FLAG_2006_LIMIT_OWNING_ENTITY_SELECTION_BY_ROLES,
FLAG_2006_VFMODULE_TAKES_TENANT_AND_REGION_FROM_VNF,
+ FLAG_EXP_TOPOLOGY_TREE_VFMODULE_NAMES_FROM_OTHER_TOSCA_VERSIONS,
;
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AAIServiceTree.java b/vid-app-common/src/main/java/org/onap/vid/services/AAIServiceTree.java
index 579fd09cb..5bfcc5f13 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/AAIServiceTree.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AAIServiceTree.java
@@ -32,8 +32,6 @@ import java.util.stream.Stream;
import javax.inject.Inject;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.vid.aai.util.AAITreeConverter;
-import org.onap.vid.asdc.AsdcCatalogException;
-import org.onap.vid.exceptions.GenericUncheckedException;
import org.onap.vid.model.ServiceModel;
import org.onap.vid.model.aaiTree.AAITreeNode;
import org.onap.vid.model.aaiTree.NodeType;
@@ -122,11 +120,13 @@ public class AAIServiceTree {
//Populate nodes with model-name & model-version (from aai)
aaiTreeNodesEnricher.enrichNodesWithModelVersionAndModelName(nodesAccumulator);
- final ServiceModel serviceModel = getServiceModel(aaiTree.getModelVersionId());
+ final ServiceModel serviceModel = sdcService.getServiceModelOrThrow(aaiTree.getModelVersionId());
//Populate nodes with model-customization-name (from sdc model)
aaiTreeNodesEnricher.enrichNodesWithModelCustomizationName(nodesAccumulator, serviceModel);
+ aaiTreeNodesEnricher.enrichVfModulesWithModelCustomizationNameFromOtherVersions(nodesAccumulator, aaiTree.getModelInvariantId());
+
return aaiTreeConverter.convertTreeToUIModel(aaiTree, globalCustomerId, serviceType, getInstantiationType(serviceModel), getInstanceRole(serviceModel), getInstanceType(serviceModel));
}
@@ -163,18 +163,6 @@ public class AAIServiceTree {
}
}
- private ServiceModel getServiceModel(String modelVersionId) {
- try {
- final ServiceModel serviceModel = sdcService.getService(modelVersionId);
- if (serviceModel == null) {
- throw new GenericUncheckedException("Model version '" + modelVersionId + "' not found");
- }
- return serviceModel;
- } catch (AsdcCatalogException e) {
- throw new GenericUncheckedException("Exception while loading model version '" + modelVersionId + "'", e);
- }
- }
-
public static class AaiRelationship {
public final String type;
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodesEnricher.java b/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodesEnricher.java
index e1e35cbec..97bc42368 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodesEnricher.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodesEnricher.java
@@ -20,41 +20,58 @@
package org.onap.vid.services;
+import static java.util.Collections.emptyMap;
import static java.util.stream.Collectors.toSet;
+import static org.apache.commons.lang3.StringUtils.isAllEmpty;
import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.ImmutableList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
+import java.util.ListIterator;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.function.Predicate;
import javax.inject.Inject;
import javax.ws.rs.core.Response;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.vid.aai.AaiClientInterface;
+import org.onap.vid.aai.model.ModelVer;
import org.onap.vid.asdc.parser.ServiceModelInflator;
import org.onap.vid.asdc.parser.ServiceModelInflator.Names;
import org.onap.vid.model.ServiceModel;
import org.onap.vid.model.aaiTree.AAITreeNode;
+import org.onap.vid.model.aaiTree.NodeType;
+import org.onap.vid.properties.Features;
import org.springframework.stereotype.Component;
+import org.togglz.core.manager.FeatureManager;
@Component
public class AAITreeNodesEnricher {
private final AaiClientInterface aaiClient;
+ private final VidService sdcService;
+
private final ServiceModelInflator serviceModelInflator;
+ private final FeatureManager featureManager;
+
private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(AAITreeNodesEnricher.class);
@Inject
public AAITreeNodesEnricher(
AaiClientInterface aaiClient,
+ VidService sdcService,
+ FeatureManager featureManager,
ServiceModelInflator serviceModelInflator
) {
this.aaiClient = aaiClient;
+ this.sdcService = sdcService;
+ this.featureManager = featureManager;
this.serviceModelInflator = serviceModelInflator;
}
@@ -70,6 +87,71 @@ public class AAITreeNodesEnricher {
});
}
+ void enrichVfModulesWithModelCustomizationNameFromOtherVersions(Collection<AAITreeNode> nodes, String modelInvariantId) {
+ if (!featureManager.isActive(Features.FLAG_EXP_TOPOLOGY_TREE_VFMODULE_NAMES_FROM_OTHER_TOSCA_VERSIONS)) {
+ return;
+ }
+
+ if (nodes.stream().noneMatch(vfModuleWithMissingData())) {
+ return;
+ }
+
+ final List<ModelVer> allModelVersions = aaiClient.getSortedVersionsByInvariantId(modelInvariantId);
+
+ final ListIterator<ModelVer> modelVersionsIterator = allModelVersions.listIterator();
+ final Map<String, Names> namesByCustomizationId = new HashMap<>();
+
+ nodes.stream().filter(vfModuleWithMissingData()).forEach(node -> {
+ String modelCustomizationId = node.getModelCustomizationId();
+
+ fetchCustomizationIdsFromToscaModelsWhileNeeded(namesByCustomizationId, modelVersionsIterator, modelCustomizationId);
+
+ final Names names = namesByCustomizationId.get(modelCustomizationId);
+ if (names != null) {
+ node.setKeyInModel(names.getModelKey());
+ node.setModelCustomizationName(names.getModelCustomizationName());
+ }
+ });
+ }
+
+ private Predicate<AAITreeNode> vfModuleWithMissingData() {
+ final Predicate<AAITreeNode> isVfModule = node -> node.getType() == NodeType.VF_MODULE;
+
+ final Predicate<AAITreeNode> nodeWithMissingData =
+ node -> isAllEmpty(node.getKeyInModel(), node.getModelCustomizationName());
+
+ return isVfModule.and(nodeWithMissingData);
+ }
+
+ /**
+ * Loads inOutMutableNamesByCustomizationId with all customization IDs from the list of modelVersions. Will seize loading
+ * if yieldCustomizationId presents in inOutMutableNamesByCustomizationId.
+ * @param inOutMutableNamesByCustomizationId Mutable Map to fill-up
+ * @param modelVersions Iterable of model-version-ids to load
+ * @param yieldCustomizationId The key to stop loading on
+ */
+ private void fetchCustomizationIdsFromToscaModelsWhileNeeded(
+ Map<String, Names> inOutMutableNamesByCustomizationId, ListIterator<ModelVer> modelVersions, String yieldCustomizationId
+ ) {
+ while (modelVersions.hasNext() && !inOutMutableNamesByCustomizationId.containsKey(yieldCustomizationId)) {
+ inOutMutableNamesByCustomizationId.putAll(
+ fetchAllCustomizationIds(modelVersions.next().getModelVersionId())
+ );
+ }
+ }
+
+ private Map<String, Names> fetchAllCustomizationIds(String modelVersionId) {
+ try {
+ ServiceModel serviceModel = sdcService.getServiceModelOrThrow(modelVersionId);
+ return serviceModelInflator.toNamesByCustomizationId(serviceModel);
+ } catch (Exception e) {
+ // Ignore the failure: SDC may lack the historic model, but this is NOT a reason to fail the whole enrichment
+ LOGGER.debug(EELFLoggerDelegate.debugLogger,
+ "Could not get model customization ids from SCD where modelVersionId={}", modelVersionId, e);
+ return emptyMap();
+ }
+ }
+
public void enrichNodesWithModelVersionAndModelName(Collection<AAITreeNode> nodes) {
Collection<String> invariantIDs = getModelInvariantIds(nodes);
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/VidService.java b/vid-app-common/src/main/java/org/onap/vid/services/VidService.java
index f7bc1f275..30802f9c6 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/VidService.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/VidService.java
@@ -23,10 +23,13 @@ package org.onap.vid.services;
import org.onap.vid.asdc.AsdcCatalogException;
import org.onap.vid.model.ServiceModel;
+import org.springframework.lang.NonNull;
public interface VidService extends ProbeInterface {
ServiceModel getService(String uuid) throws AsdcCatalogException;
+ @NonNull ServiceModel getServiceModelOrThrow(String modelVersionId);
+
void invalidateServiceCache();
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/VidServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/VidServiceImpl.java
index a5988a156..ef62bf9f6 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/VidServiceImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/VidServiceImpl.java
@@ -52,6 +52,7 @@ import org.onap.vid.properties.VidProperties;
import org.onap.vid.utils.Logging;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
+import org.springframework.lang.NonNull;
import org.togglz.core.manager.FeatureManager;
/**
@@ -99,11 +100,6 @@ public class VidServiceImpl implements VidService {
});
}
- /*
- * (non-Javadoc)
- *
- * @see org.onap.vid.controller.VidService#getService(java.lang.String)
- */
@Override
public ServiceModel getService(String uuid) throws AsdcCatalogException {
if (featureManager.isActive(FLAG_SERVICE_MODEL_CACHE)) {
@@ -113,6 +109,20 @@ public class VidServiceImpl implements VidService {
}
}
+ @NonNull
+ @Override
+ public ServiceModel getServiceModelOrThrow(String modelVersionId) {
+ try {
+ final ServiceModel serviceModel = getService(modelVersionId);
+ if (serviceModel == null) {
+ throw new GenericUncheckedException("Model version '" + modelVersionId + "' not found");
+ }
+ return serviceModel;
+ } catch (AsdcCatalogException e) {
+ throw new GenericUncheckedException("Exception while loading model version '" + modelVersionId + "'", e);
+ }
+ }
+
private ServiceModel getServiceFromCache(String uuid) throws AsdcCatalogException {
try {
return serviceModelCache.get(uuid);