aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/job/command/CommandUtilsTest.java89
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/job/impl/AsyncInstantiationIntegrationTest.java21
4 files changed, 90 insertions, 82 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 {
diff --git a/vid-app-common/src/test/java/org/onap/vid/job/command/CommandUtilsTest.java b/vid-app-common/src/test/java/org/onap/vid/job/command/CommandUtilsTest.java
index ee43d1f72..d1d9b5e4f 100644
--- a/vid-app-common/src/test/java/org/onap/vid/job/command/CommandUtilsTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/job/command/CommandUtilsTest.java
@@ -20,29 +20,30 @@
package org.onap.vid.job.command;
-import com.google.common.collect.ImmutableMap;
+import static java.util.Collections.emptyMap;
+import static java.util.Collections.singletonMap;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.when;
+import static org.onap.vid.testUtils.TestUtils.setStringsInStringFields;
+
+import java.util.UUID;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.onap.vid.asdc.AsdcCatalogException;
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.VidService;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
-import java.util.Collections;
-import java.util.Map;
-import java.util.UUID;
-
-import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
-import static org.mockito.Mockito.*;
-
public class CommandUtilsTest {
@InjectMocks
@@ -62,47 +63,57 @@ public class CommandUtilsTest {
}
@DataProvider
- public static Object[][] trueAndFalse() {
- return new Object[][]{ {true}, {false} };
- }
+ public static Object[][] vfModuleModelInfos() {
+ ModelInfo modelInfoMatchByUuid = setStringsInStringFields(new ModelInfo());
+ modelInfoMatchByUuid.setModelCustomizationId("toscaCustomizationUuid");
- @Test(dataProvider="trueAndFalse")
- void testIsVfModelIsBaseModule(boolean isBase) throws AsdcCatalogException {
- final String serviceModelUuid = UUID.randomUUID().toString();
- final String vfModuleUuid = UUID.randomUUID().toString();
+ ModelInfo modelInfoMatchByName = setStringsInStringFields(new ModelInfo());
+ modelInfoMatchByName.setModelCustomizationName("toscaCustomizationName");
- ServiceModel mockedServiceModel = mock(ServiceModel.class);
- VfModule mockedVfModule = mock(VfModule.class);
- GroupProperties mockedGroupProperties = mock(GroupProperties.class);
- Map<String, VfModule> vfModulesMap = ImmutableMap.of(randomAlphanumeric(10), mockedVfModule);
+ ModelInfo modelInfoDontMatch = setStringsInStringFields(new ModelInfo());
+
+ return new Object[][]{
+ {true, modelInfoMatchByUuid, true},
+ {false, modelInfoMatchByUuid, false},
- when(vidService.getService(serviceModelUuid)).thenReturn(mockedServiceModel);
- when(mockedServiceModel.getVfModules()).thenReturn(vfModulesMap);
- when(mockedVfModule.getUuid()).thenReturn(vfModuleUuid);
- when(mockedVfModule.getProperties()).thenReturn(mockedGroupProperties);
- when(mockedGroupProperties.getBaseModule()).thenReturn(isBase);
+ {true, modelInfoMatchByName, true},
+ {false, modelInfoMatchByName, false},
- assertThat(commandUtils.isVfModuleBaseModule(serviceModelUuid, vfModuleUuid), equalTo(isBase));
+ {true, modelInfoDontMatch, false},
+ {false, modelInfoDontMatch, false},
+ };
}
- @Test(expectedExceptions = AsdcCatalogException.class)
- void whenCantFindModelInSdc_thenExceptionIsThrown() throws AsdcCatalogException {
+ @Test(dataProvider="vfModuleModelInfos")
+ void isVfModuleBaseModule_vfModuleIsMatchedByEitherNameOrUuid(boolean isBaseInTosca, ModelInfo instanceModelInfo, boolean expected) {
+ GroupProperties mockedGroupProperties = mock(GroupProperties.class);
+ when(mockedGroupProperties.getBaseModule()).thenReturn(isBaseInTosca);
+
+ VfModule toscaVfModuleModelInfo = mock(VfModule.class);
+ when(toscaVfModuleModelInfo.getCustomizationUuid()).thenReturn("toscaCustomizationUuid");
+ when(toscaVfModuleModelInfo.getModelCustomizationName()).thenReturn("toscaCustomizationName");
+ when(toscaVfModuleModelInfo.getProperties()).thenReturn(mockedGroupProperties);
+
+
+ ServiceModel mockedServiceModel = mock(ServiceModel.class);
+ when(mockedServiceModel.getVfModules()).thenReturn(singletonMap("some-name", toscaVfModuleModelInfo));
+
String serviceModelUuid = UUID.randomUUID().toString();
- when(vidService.getService(serviceModelUuid)).thenReturn(null);
- commandUtils.isVfModuleBaseModule(serviceModelUuid, "abc");
- }
+ when(vidService.getServiceModelOrThrow(serviceModelUuid)).thenReturn(mockedServiceModel);
- @Test(expectedExceptions = AsdcCatalogException.class)
- void whenCantFindVfModuleInModel_thenExceptionIsThrown() throws AsdcCatalogException {
+ assertThat(commandUtils.isVfModuleBaseModule(serviceModelUuid, instanceModelInfo), equalTo(expected));
+ }
+ @Test
+ void isVfModuleBaseModule_whenCantFindVfModulesInModel_resultIsFalse() {
String serviceModelUuid = UUID.randomUUID().toString();
ServiceModel mockedServiceModel = mock(ServiceModel.class);
- Map<String, VfModule> emptyMap = Collections.emptyMap();
- when(vidService.getService(serviceModelUuid)).thenReturn(mockedServiceModel);
- when(mockedServiceModel.getVfModules()).thenReturn(emptyMap);
+ when(vidService.getServiceModelOrThrow(serviceModelUuid)).thenReturn(mockedServiceModel);
+ when(mockedServiceModel.getVfModules()).thenReturn(emptyMap());
- commandUtils.isVfModuleBaseModule(serviceModelUuid, "abc");
+ assertThat(
+ commandUtils.isVfModuleBaseModule(serviceModelUuid, mock(ModelInfo.class)), is(false));
}
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/job/impl/AsyncInstantiationIntegrationTest.java b/vid-app-common/src/test/java/org/onap/vid/job/impl/AsyncInstantiationIntegrationTest.java
index 642adb307..6b15c879f 100644
--- a/vid-app-common/src/test/java/org/onap/vid/job/impl/AsyncInstantiationIntegrationTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/job/impl/AsyncInstantiationIntegrationTest.java
@@ -67,7 +67,6 @@ import static org.testng.AssertJUnit.assertTrue;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
@@ -458,13 +457,11 @@ public class AsyncInstantiationIntegrationTest extends AsyncInstantiationBaseTes
when(restMso.GetForObject(endsWith(VNF_REQUEST_ID), eq(AsyncRequestStatus.class))).
thenReturn(asyncRequestStatusResponseAsRestObject(COMPLETE_STR));
- try {
- reset(commandUtils);
- when(commandUtils.isVfModuleBaseModule(SERVICE_MODEL_VERSION_ID, VF_MODULE_0_MODEL_VERSION_ID)).thenReturn(true);
- when(commandUtils.isVfModuleBaseModule(SERVICE_MODEL_VERSION_ID, VF_MODULE_1_MODEL_VERSION_ID)).thenReturn(false);
- } catch (AsdcCatalogException e) {
-
- }
+ reset(commandUtils);
+ when(commandUtils.isVfModuleBaseModule(eq(SERVICE_MODEL_VERSION_ID),
+ argThat(it -> it.getModelCustomizationId().equals(VF_MODULE_0_MODEL_CUSTOMIZATION_NAME)))).thenReturn(true);
+ when(commandUtils.isVfModuleBaseModule(eq(SERVICE_MODEL_VERSION_ID),
+ argThat(it -> it.getModelCustomizationId().equals(VF_MODULE_1_MODEL_CUSTOMIZATION_NAME)))).thenReturn(false);
/*---------- vf Module without volume group name (base) -----------*/
@@ -1015,10 +1012,12 @@ public class AsyncInstantiationIntegrationTest extends AsyncInstantiationBaseTes
RestObject<AsyncRequestStatus> createStatusResponse,
RestObject<AsyncRequestStatus> deleteStatusResponse,
JobStatus expectedJobStatus,
- int getStatusCounter) throws IOException, AsdcCatalogException {
+ int getStatusCounter) {
- when(commandUtils.isVfModuleBaseModule("6b528779-44a3-4472-bdff-9cd15ec93450", "f8360508-3f17-4414-a2ed-6bc71161e8db")).thenReturn(true);
- when(commandUtils.isVfModuleBaseModule("6b528779-44a3-4472-bdff-9cd15ec93450", "25284168-24bb-4698-8cb4-3f509146eca5")).thenReturn(false);
+ when(commandUtils.isVfModuleBaseModule(eq("6b528779-44a3-4472-bdff-9cd15ec93450"),
+ argThat(it -> it.getModelCustomizationName().equals("2017488PasqualeVpe..PASQUALE_base_vPE_BV..module-0")))).thenReturn(true);
+ when(commandUtils.isVfModuleBaseModule(eq("6b528779-44a3-4472-bdff-9cd15ec93450"),
+ argThat(it -> it.getModelCustomizationName().equals("2017488PasqualeVpe..PASQUALE_vRE_BV..module-1")))).thenReturn(false);
createAndDeleteIntegrationTest("/payload_jsons/vfModuleDelete1Create1None1Request.json",
"/serviceInstantiation/v7/serviceInstances/f8791436-8d55-4fde-b4d5-72dd2cf13cfb/vnfs/VNF_INSTANCE_ID/vfModules",