summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2020-03-05 17:25:34 +0200
committerIttay Stern <ittay.stern@att.com>2020-03-08 09:49:29 +0200
commit17b63f0c432f9edf407e4c9f465a295bfd870485 (patch)
treee6109422808147976bb4a1930f68c1eef3dfad08 /vid-app-common/src/main
parentf7c41b1c4aeea09e67c8bb88f39d15e02cd1708f (diff)
isVfModuleBaseModule() will not throw on model mismatch
In addition, the model-info comparision is by customization id or customization name instead of the version id. Issue-ID: VID-603 Change-Id: I8efee06f470e5d5681c264de01ed1315ee1f8cc6 Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/main')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java59
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/VnfCommand.kt3
2 files changed, 30 insertions, 32 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java b/vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java
index 2b6b57ade..fd8f04ce6 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java
@@ -20,10 +20,16 @@
package org.onap.vid.job.command;
+import static org.apache.commons.collections4.MapUtils.emptyIfNull;
+
import org.apache.commons.lang3.StringUtils;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.vid.aai.model.ModelVer;
-import org.onap.vid.asdc.AsdcCatalogException;
+import org.onap.vid.model.Group;
+import org.onap.vid.model.GroupProperties;
import org.onap.vid.model.ServiceModel;
+import org.onap.vid.model.VfModule;
+import org.onap.vid.mso.model.ModelInfo;
import org.onap.vid.services.AaiService;
import org.onap.vid.services.VidService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,6 +38,8 @@ import org.springframework.stereotype.Component;
@Component
public class CommandUtils {
+ private static final EELFLoggerDelegate Logger = EELFLoggerDelegate.getLogger(CommandUtils.class);
+
private final VidService vidService;
private final AaiService aaiService;
@@ -41,43 +49,34 @@ public class CommandUtils {
this.aaiService = aaiService;
}
- public boolean isVfModuleBaseModule(String serviceModelUuid, String vfModuleModelUUID) throws AsdcCatalogException{
- ServiceModel serviceModel = getServiceModel(serviceModelUuid);
+ public boolean isVfModuleBaseModule(String serviceModelUuid, ModelInfo vfModuleModelInfo) {
+ ServiceModel serviceModel = getServiceModel(serviceModelUuid);
- if (serviceModel.getVfModules() == null) {
- throw createAsdcCatalogVfModuleModelUUIDNotFoundException(serviceModelUuid, vfModuleModelUUID);
- }
-
- return serviceModel.getVfModules()
- .values()
- .stream()
- .filter(vfModule -> StringUtils.equals(vfModule.getUuid(), vfModuleModelUUID))
- .findFirst()
- .orElseThrow(() -> createAsdcCatalogVfModuleModelUUIDNotFoundException(serviceModelUuid, vfModuleModelUUID))
- .getProperties()
- .getBaseModule();
+ return emptyIfNull(serviceModel.getVfModules())
+ .values().stream()
+ .filter(toscaModelInfo -> modelsMatch(vfModuleModelInfo, toscaModelInfo))
+ .map(Group::getProperties)
+ .map(GroupProperties::getBaseModule)
+ .findAny().orElseGet(() -> {
+ Logger.debug(EELFLoggerDelegate.debugLogger,
+ "Could not find vfModule in model with uuid {}, assuming not base module ({})",
+ serviceModelUuid, vfModuleModelInfo);
+ return false;
+ });
}
- public ServiceModel getServiceModel(String serviceModelUuid) throws AsdcCatalogException{
- ServiceModel serviceModel = vidService.getService(serviceModelUuid);
-
- if (serviceModel==null) {
- throw new AsdcCatalogException("Failed to retrieve model with uuid "+serviceModelUuid +" from SDC");
- }
+ private boolean modelsMatch(ModelInfo instanceModelInfo, VfModule toscaModelInfo) {
+ return StringUtils.equals(toscaModelInfo.getCustomizationUuid(), instanceModelInfo.getModelCustomizationId())
+ || StringUtils.equals(toscaModelInfo.getModelCustomizationName(), instanceModelInfo.getModelCustomizationName());
+ }
- return serviceModel;
+ public ServiceModel getServiceModel(String serviceModelUuid) {
+ return vidService.getServiceModelOrThrow(serviceModelUuid);
}
- public String getNewestModelUuid(String serviceModelInvariantId)
- {
+ public String getNewestModelUuid(String serviceModelInvariantId) {
ModelVer serviceModelLatestVersion = aaiService.getNewestModelVersionByInvariantId(serviceModelInvariantId);
-
return serviceModelLatestVersion.getModelVersionId();
}
- private AsdcCatalogException createAsdcCatalogVfModuleModelUUIDNotFoundException(String serviceModelUuid, String vfModuleModelUUID) {
- return new AsdcCatalogException("Failed to find vfModuleModelUUID: " + vfModuleModelUUID +
- "in model with uuid: " + serviceModelUuid);
- }
-
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/VnfCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/VnfCommand.kt
index cada6055d..c947bc0d5 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/VnfCommand.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/VnfCommand.kt
@@ -92,8 +92,7 @@ class VnfCommand @Autowired constructor(
private fun filterModuleByNeedToCreateBase(vfModule: VfModule): Boolean {
return needToCreateBaseModule ==
commandUtils.isVfModuleBaseModule(
- serviceModelInfoFromRequest().modelVersionId,
- vfModule.modelInfo.modelVersionId)
+ serviceModelInfoFromRequest().modelVersionId, vfModule.modelInfo)
}
override fun planCreateMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String, testApi: String?): MsoRestCallPlan {