diff options
Diffstat (limited to 'vid-app-common/src/main')
-rw-r--r-- | vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java | 59 | ||||
-rw-r--r-- | vid-app-common/src/main/java/org/onap/vid/job/command/VnfCommand.kt | 3 |
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 { |