aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmichai Hemli <amichai.hemli@intl.att.com>2020-03-08 15:27:26 +0000
committerGerrit Code Review <gerrit@onap.org>2020-03-08 15:27:26 +0000
commitd46b13b53c422a4f3c01fb02012c3315aff6bde6 (patch)
tree205cd5f299d5159cfeb337d43f8125960b14be3b
parent742d6d369b761220e565f39f2fa09413141ad93f (diff)
parent455f47766ce554ed9354d707992353353753745e (diff)
Merge changes Ibbc7da3a,I8efee06f
* changes: Don't use EELFLoggerDelegate.errorLogger in Async jobs isVfModuleBaseModule() will not throw on model mismatch
-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/InProgressStatusService.java16
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/MacroServiceCommand.kt4
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/MsoRequestBuilder.kt2
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt6
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/RootServiceCommand.kt4
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/VfmoduleCommand.kt2
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/VnfCommand.kt6
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/impl/DeleteOldJobsSchedulerInitializer.java2
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/impl/JobSchedulerInitializer.java19
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/impl/JobWorker.java10
-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
13 files changed, 125 insertions, 115 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/InProgressStatusService.java b/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusService.java
index 3d1d78f8b..91bf5de1e 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusService.java
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusService.java
@@ -20,6 +20,11 @@
package org.onap.vid.job.command;
+import static org.onap.vid.utils.TimeUtils.parseZonedDateTime;
+
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeParseException;
+import java.util.UUID;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.vid.job.Job;
import org.onap.vid.job.impl.JobSharedData;
@@ -33,12 +38,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.togglz.core.manager.FeatureManager;
-import java.time.ZonedDateTime;
-import java.time.format.DateTimeParseException;
-import java.util.UUID;
-
-import static org.onap.vid.utils.TimeUtils.parseZonedDateTime;
-
@Service
public class InProgressStatusService {
@@ -86,8 +85,7 @@ public class InProgressStatusService {
public void handleFailedMsoResponse(UUID jobUUID, String requestId, RestObject<AsyncRequestStatus> msoResponse) {
auditService.setFailedAuditStatusFromMso(jobUUID, requestId, msoResponse.getStatusCode(), msoResponse.getRaw());
- LOGGER.error(EELFLoggerDelegate.errorLogger,
- "Failed to get orchestration status for {}. Status code: {}, Body: {}",
+ LOGGER.error("Failed to get orchestration status for {}. Status code: {}, Body: {}",
requestId, msoResponse.getStatusCode(), msoResponse.getRaw());
}
@@ -108,7 +106,7 @@ public class InProgressStatusService {
try {
jobStartTime = parseZonedDateTime(asyncRequestStatusResponse.get().request.startTime);
} catch (DateTimeParseException | NullPointerException e) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to parse start time for {}, body: {}. Current time will be used", requestId, asyncRequestStatusResponse.getRaw(), e);
+ LOGGER.error("Failed to parse start time for {}, body: {}. Current time will be used", requestId, asyncRequestStatusResponse.getRaw(), e);
jobStartTime = ZonedDateTime.now();
}
return jobStartTime;
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/MacroServiceCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/MacroServiceCommand.kt
index 2fdd19100..8ce73d713 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/MacroServiceCommand.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/MacroServiceCommand.kt
@@ -62,13 +62,13 @@ class MacroServiceCommand @Autowired constructor(
//Aai return bad response while checking names uniqueness
catch (exception : ExceptionWithRequestInfo) {
- Logger.error(EELFLoggerDelegate.errorLogger, "Failed to check name uniqueness in AAI. VID will try again later", exception)
+ Logger.error("Failed to check name uniqueness in AAI. VID will try again later", exception)
throw TryAgainException(exception);
}
//Vid reached to max retries while trying to find unique name in AAI
catch (exception : MaxRetriesException) {
- Logger.error(EELFLoggerDelegate.errorLogger, "Failed to find unused name in AAI", exception)
+ Logger.error("Failed to find unused name in AAI", exception)
throw AbortingException(exception);
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/MsoRequestBuilder.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/MsoRequestBuilder.kt
index 063ef6e53..c3fdcdaeb 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/MsoRequestBuilder.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/MsoRequestBuilder.kt
@@ -210,7 +210,7 @@ class MsoRequestBuilder
try {
asyncInstantiationBL.updateServiceInfo(jobId) { x -> x.serviceInstanceName = serviceInstanceName }
} catch (e: Exception) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed updating service name {} in serviceInfo", serviceInstanceName, e)
+ LOGGER.error("Failed updating service name {} in serviceInfo", serviceInstanceName, e)
}
return serviceInstanceName
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt
index 4477a9f24..2b5ec0127 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt
@@ -153,7 +153,7 @@ abstract class ResourceCommand(
JobStatus.IN_PROGRESS
}
catch (exception: AbortingException) {
- Logger.error(EELFLoggerDelegate.errorLogger, "caught AbortingException. Set job status to FAILED")
+ Logger.error("caught AbortingException. Set job status to FAILED")
JobStatus.FAILED;
}
}
@@ -330,13 +330,13 @@ abstract class ResourceCommand(
handleInProgressStatus(jobStatus)
} catch (e: javax.ws.rs.ProcessingException) {
// Retry when we can't connect MSO during getStatus
- Logger.error(EELFLoggerDelegate.errorLogger, "Cannot get orchestration status for {}, will retry: {}", requestId, e, e)
+ Logger.error("Cannot get orchestration status for {}, will retry: {}", requestId, e, e)
JobStatus.IN_PROGRESS;
} catch (e: InProgressStatusService.BadResponseFromMso) {
inProgressStatusService.handleFailedMsoResponse(sharedData.jobUuid, requestId, e.msoResponse)
JobStatus.IN_PROGRESS
} catch (e: RuntimeException) {
- Logger.error(EELFLoggerDelegate.errorLogger, "Cannot get orchestration status for {}, stopping: {}", requestId, e, e)
+ Logger.error("Cannot get orchestration status for {}, stopping: {}", requestId, e, e)
JobStatus.STOPPED
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/RootServiceCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/RootServiceCommand.kt
index 875de66d6..c4680b2bd 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/RootServiceCommand.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/RootServiceCommand.kt
@@ -71,13 +71,13 @@ abstract class RootServiceCommand @Autowired constructor(
try {
val requests = auditService.retrieveRequestsFromMsoByServiceIdAndRequestTypeAndScope(serviceInstanceId, requestType, scope)
if (requests.isEmpty() || requests[0].requestId == null) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to retrieve requestId with type: $type, scope: $scope for service instanceId $serviceInstanceId ")
+ LOGGER.error("Failed to retrieve requestId with type: $type, scope: $scope for service instanceId $serviceInstanceId ")
return Job.JobStatus.FAILED
}
val createMyselfCommand = planResumeMyselfRestCall(requests[0].requestId, sharedData.userId)
return executeAndHandleMsoInstanceRequest(createMyselfCommand)
} catch (exception: Exception) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to resume instanceId $serviceInstanceId ", exception)
+ LOGGER.error("Failed to resume instanceId $serviceInstanceId ", exception)
return Job.JobStatus.FAILED
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/VfmoduleCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/VfmoduleCommand.kt
index 68c9f53e1..29d7001e2 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/VfmoduleCommand.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/VfmoduleCommand.kt
@@ -193,7 +193,7 @@ class VfmoduleCommand @Autowired constructor(
val replaceMyselfCommand = planReplaceMyselfRestCall(commandParentData)
return executeAndHandleMsoInstanceRequest(replaceMyselfCommand)
} catch (exception: Exception) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to replace instanceId ${getRequest().instanceId} ", exception)
+ LOGGER.error("Failed to replace instanceId ${getRequest().instanceId} ", exception)
return Job.JobStatus.FAILED
}
}
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..9023682f6 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
@@ -61,8 +61,7 @@ class VnfCommand @Autowired constructor(
try {
childJobs = pushChildrenJobsToBroker(vfModulesForChildrenJobs(vfModules), dataForChild, JobType.VolumeGroupInstantiation)
} catch (e: AsdcCatalogException) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to retrieve service definitions from SDC, for VfModule is BaseModule.. Error: " + e.message, e)
- //return Job.JobStatus.FAILED
+ LOGGER.error("Failed to retrieve service definitions from SDC, for VfModule is BaseModule.. Error: " + e.message, e)
throw e;
}
}
@@ -92,8 +91,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/main/java/org/onap/vid/job/impl/DeleteOldJobsSchedulerInitializer.java b/vid-app-common/src/main/java/org/onap/vid/job/impl/DeleteOldJobsSchedulerInitializer.java
index 114c20105..981bdeaa7 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/impl/DeleteOldJobsSchedulerInitializer.java
+++ b/vid-app-common/src/main/java/org/onap/vid/job/impl/DeleteOldJobsSchedulerInitializer.java
@@ -64,7 +64,7 @@ public class DeleteOldJobsSchedulerInitializer {
Trigger deleteOldJobsTrigger = createTrigger();
schedulerFactoryBean.getScheduler().scheduleJob(jobDetail, deleteOldJobsTrigger);
} catch (SchedulerException e) {
- logger.error(EELFLoggerDelegate.errorLogger, "Failed to schedule trigger for delete old jobs: {}", e.getMessage());
+ logger.error("Failed to schedule trigger for delete old jobs: {}", e.getMessage());
throw new GenericUncheckedException(e);
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobSchedulerInitializer.java b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobSchedulerInitializer.java
index b5c2dd74b..bd82ffa7a 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobSchedulerInitializer.java
+++ b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobSchedulerInitializer.java
@@ -20,24 +20,29 @@
package org.onap.vid.job.impl;
+import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
+
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import java.util.List;
+import javax.annotation.PostConstruct;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.vid.exceptions.GenericUncheckedException;
import org.onap.vid.job.Job;
import org.onap.vid.job.JobsBrokerService;
import org.onap.vid.job.command.JobCommandFactory;
-import org.quartz.*;
+import org.quartz.JobBuilder;
+import org.quartz.JobDataMap;
+import org.quartz.JobDetail;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.Trigger;
+import org.quartz.TriggerBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Component;
import org.togglz.core.manager.FeatureManager;
-import javax.annotation.PostConstruct;
-import java.util.List;
-
-import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
-
@Component
public class JobSchedulerInitializer {
@@ -94,7 +99,7 @@ public class JobSchedulerInitializer {
try {
scheduler.scheduleJob(jobDetail, asyncWorkerTrigger);
} catch (SchedulerException e) {
- logger.error(EELFLoggerDelegate.errorLogger, "Failed to schedule trigger for async worker jobs: {}", e.getMessage());
+ logger.error("Failed to schedule trigger for async worker jobs: {}", e.getMessage());
throw new GenericUncheckedException(e);
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobWorker.java b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobWorker.java
index c629a665c..c0e006e22 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobWorker.java
+++ b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobWorker.java
@@ -69,7 +69,7 @@ public class JobWorker extends QuartzJobBean {
try {
return jobsBrokerService.pull(topic, UUID.randomUUID().toString());
} catch (Exception e) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "failed to pull job from queue, breaking: {}", e, e);
+ LOGGER.error("failed to pull job from queue, breaking: {}", e, e);
tryMutingJobFromException(e);
return Optional.empty();
@@ -80,7 +80,7 @@ public class JobWorker extends QuartzJobBean {
try {
jobsBrokerService.pushBack(nextJob);
} catch (Exception e) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "failed pushing back job to queue: {}", e, e);
+ LOGGER.error("failed pushing back job to queue: {}", e, e);
}
}
@@ -114,7 +114,7 @@ public class JobWorker extends QuartzJobBean {
final JobCommand jobCommand = jobCommandFactory.toCommand(job);
nextCommand = jobCommand.call();
} catch (Exception e) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "error while executing job from queue: {}", e);
+ LOGGER.error("error while executing job from queue: {}", e, e);
nextCommand = new NextCommand(FAILED);
}
@@ -153,10 +153,10 @@ public class JobWorker extends QuartzJobBean {
LOGGER.info(EELFLoggerDelegate.debugLogger, "muting job: {} ({})", jobException.getJobUuid(), jobException.toString());
final boolean success = jobsBrokerService.mute(jobException.getJobUuid());
if (!success) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "failed to mute job {}", jobException.getJobUuid());
+ LOGGER.error("failed to mute job {}", jobException.getJobUuid());
}
} catch (Exception e1) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "failed to mute job: {}", e1, e1);
+ LOGGER.error("failed to mute job: {}", e1, e1);
}
}
}
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",