aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2020-01-13 12:07:45 +0200
committerEylon Malin <eylon.malin@intl.att.com>2020-01-13 14:16:52 +0200
commit6876eba3d0b43b01eb303a0d530fe45712f33d74 (patch)
tree7f6808357cc2d89405f6003cd5bd8dbe78d6c741
parent9d0eee5eee868aaee3cf169a4a6716dc1530e4e3 (diff)
clear isFailed and statusMessage when get it from frontend request
Issue-ID: VID-724 Change-Id: I1bc33513250b220a063742233592388c7a108958 Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java28
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java36
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/job/impl/AsyncInstantiationIntegrationTest.java45
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java35
4 files changed, 131 insertions, 13 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
index 2cc76492f..07c2d1593 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
@@ -170,7 +170,9 @@ public class AsyncInstantiationBusinessLogicImpl implements
int bulkSize = request.getBulkSize();
UUID templateId = UUID.randomUUID();
for (int i = 0; i < bulkSize; i++) {
- ServiceInstantiation requestPerJob = prepareServiceToBeUnique(request);
+ ServiceInstantiation clonedServiceInstantiation = cloneServiceInstantiation(request);
+ ServiceInstantiation requestPerJob = prepareServiceToBeUnique(clonedServiceInstantiation);
+ requestPerJob = clearStatusFromRequest(requestPerJob);
ServiceInfo.ServiceAction serviceAction = getAction(requestPerJob);
JobType jobType = getJobType(requestPerJob);
final String optimisticUniqueServiceInstanceName = bulkSize>1 ? //only bulk with more than 1 service need to get multiple names
@@ -561,20 +563,28 @@ public class AsyncInstantiationBusinessLogicImpl implements
@Override
public ServiceInstantiation prepareServiceToBeUnique(ServiceInstantiation serviceInstantiation) {
+ serviceInstantiation.setBulkSize(1);
+ return replaceAllTrackById(serviceInstantiation);
+ }
+ private<T extends BaseResource> T replaceAllTrackById(T resource) {
+ resource.setTrackById(UUID.randomUUID().toString());
+ resource.getChildren().forEach(this::replaceAllTrackById);
+ return resource;
+ }
+
+ private ServiceInstantiation cloneServiceInstantiation(ServiceInstantiation serviceInstantiation) {
try {
- ServiceInstantiation clonedServiceInstantiation = JACKSON_OBJECT_MAPPER.readValue(
- JACKSON_OBJECT_MAPPER.writeValueAsBytes(serviceInstantiation), ServiceInstantiation.class);
- clonedServiceInstantiation.setBulkSize(1);
- return replaceAllTrackById(clonedServiceInstantiation);
+ return JACKSON_OBJECT_MAPPER.readValue(
+ JACKSON_OBJECT_MAPPER.writeValueAsBytes(serviceInstantiation), ServiceInstantiation.class);
} catch (IOException e) {
throw new GenericUncheckedException(e);
}
-
}
- private<T extends BaseResource> T replaceAllTrackById(T resource) {
- resource.setTrackById(UUID.randomUUID().toString());
- resource.getChildren().forEach(this::replaceAllTrackById);
+ <T extends BaseResource> T clearStatusFromRequest(T resource) {
+ resource.setIsFailed(false);
+ resource.setStatusMessage(null);
+ resource.getChildren().forEach(this::clearStatusFromRequest);
return resource;
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java b/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java
index c4f788689..3f2bf7318 100644
--- a/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java
+++ b/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java
@@ -31,12 +31,32 @@ import org.onap.vid.aai.util.SystemPropertyHelper;
import org.onap.vid.dal.AsyncInstantiationRepository;
import org.onap.vid.job.JobAdapter;
import org.onap.vid.job.JobsBrokerService;
-import org.onap.vid.job.command.*;
+import org.onap.vid.job.command.ALaCarteServiceCommand;
+import org.onap.vid.job.command.CommandUtils;
+import org.onap.vid.job.command.InProgressStatusService;
+import org.onap.vid.job.command.InstanceGroupCommand;
+import org.onap.vid.job.command.InstanceGroupMemberCommand;
+import org.onap.vid.job.command.JobCommandFactory;
+import org.onap.vid.job.command.MacroServiceCommand;
+import org.onap.vid.job.command.MsoRequestBuilder;
+import org.onap.vid.job.command.MsoResultHandlerService;
+import org.onap.vid.job.command.NetworkCommand;
+import org.onap.vid.job.command.VfmoduleCommand;
+import org.onap.vid.job.command.VnfCommand;
+import org.onap.vid.job.command.VolumeGroupCommand;
+import org.onap.vid.job.command.WatchChildrenJobsBL;
import org.onap.vid.job.impl.JobAdapterImpl;
import org.onap.vid.job.impl.JobWorker;
import org.onap.vid.job.impl.JobsBrokerServiceInDatabaseImpl;
+import org.onap.vid.model.ModelUtil;
import org.onap.vid.mso.RestMsoImplementation;
-import org.onap.vid.services.*;
+import org.onap.vid.services.AsyncInstantiationBusinessLogic;
+import org.onap.vid.services.AsyncInstantiationBusinessLogicImpl;
+import org.onap.vid.services.AuditService;
+import org.onap.vid.services.AuditServiceImpl;
+import org.onap.vid.services.CloudOwnerService;
+import org.onap.vid.services.InstantiationTemplatesService;
+import org.onap.vid.services.VersionService;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -130,6 +150,18 @@ public class JobCommandsConfigWithMockedMso {
return new AsyncInstantiationBusinessLogicImpl(jobAdapter, jobsBrokerService, sessionFactory, aaiClient, featureManager, cloudOwnerService, asyncInstantiationRepository, auditService);
}
+ @Bean
+ public ModelUtil modelUtil() {return new ModelUtil();}
+
+ @Bean
+ public InstantiationTemplatesService instantiationTemplatesService(
+ ModelUtil modelUtil,
+ AsyncInstantiationRepository asyncInstantiationRepository,
+ FeatureManager featureManager
+ ) {
+ return new InstantiationTemplatesService(modelUtil, asyncInstantiationRepository, featureManager);
+ };
+
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
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 cd4045b8d..fe6cfafb4 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
@@ -59,6 +59,7 @@ import static org.onap.vid.job.Job.JobStatus.STOPPED;
import static org.onap.vid.job.impl.JobSchedulerInitializer.WORKERS_TOPICS;
import static org.onap.vid.model.JobAuditStatus.SourceStatus.VID;
import static org.onap.vid.testUtils.TestUtils.readJsonResourceFileAsObject;
+import static org.testng.Assert.assertNull;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
@@ -119,6 +120,7 @@ import org.onap.vid.properties.Features;
import org.onap.vid.services.AsyncInstantiationBaseTest;
import org.onap.vid.services.AsyncInstantiationBusinessLogic;
import org.onap.vid.services.AuditService;
+import org.onap.vid.services.InstantiationTemplatesService;
import org.onap.vid.services.VersionService;
import org.onap.vid.testUtils.TestUtils;
import org.onap.vid.utils.DaoUtils;
@@ -172,6 +174,9 @@ public class AsyncInstantiationIntegrationTest extends AsyncInstantiationBaseTes
@Inject
private CommandUtils commandUtils;
+ @Inject
+ private InstantiationTemplatesService instantiationTemplates;
+
@BeforeClass
void initServicesInfoService() {
createInstanceParamsMaps();
@@ -1309,4 +1314,44 @@ public class AsyncInstantiationIntegrationTest extends AsyncInstantiationBaseTes
return readJsonResourceFileAsObject("/payload_jsons/vfmodule/upgrade_vfmodule_e2e__fe_input_cypress.json", ServiceInstantiation.class);
}
+ @Test
+ public void deployService_failIt_retryDeploy_getRetryAsTemplate_makeSureFalsyIsFailedInTemplate() {
+
+ final String SERVICE_REQUEST_ID = UUID.randomUUID().toString();
+ when(featureManager.isActive(Features.FLAG_ASYNC_ALACARTE_VNF)).thenReturn(true);
+ when(featureManager.isActive(Features.FLAG_ASYNC_ALACARTE_VFMODULE)).thenReturn(true);
+
+ //push alacarte with 1 vnf, verify STATUS pending
+ UUID uuid = pushALaCarteWithVnf();
+ singleServicesAndAssertStatus(JobStatus.PENDING, uuid);
+
+ reset(restMso);
+ //mock mso to answer 200 of create service instance request, verify STATUS in progress
+ when(restMso.restCall(eq(HttpMethod.POST), eq(RequestReferencesContainer.class), any(), endsWith("serviceInstances"), any())).thenReturn(
+ createResponse(200, SERVICE_INSTANCE_ID, SERVICE_REQUEST_ID));
+
+ //mock mso to answer FAILED for service instance create
+ final RestObject<AsyncRequestStatus> failedResponse = asyncRequestStatusResponseAsRestObject(FAILED_STR);
+ final String failureDescription = "Some deep failure";
+ failedResponse.get().request.requestStatus.setStatusMessage(failureDescription);
+ when(restMso.GetForObject(endsWith(SERVICE_REQUEST_ID), eq(AsyncRequestStatus.class))).
+ thenReturn(failedResponse);
+
+ //Wait till job failed
+ processJobsCountTimesAndAssertStatus(uuid, 3, FAILED);
+
+ //make sure retry request jas isFailed = true, and status message is with failureDescription
+ ServiceInstantiation retryRequest = asyncInstantiationBL.getBulkForRetry(uuid);
+ assertTrue(retryRequest.getIsFailed());
+ assertEquals(failureDescription, retryRequest.getStatusMessage());
+
+ //deploy retry job and it's template
+ UUID retryUuid = asyncInstantiationBL.pushBulkJob(retryRequest, USER_ID).get(0);
+ ServiceInstantiation templateOfRetry = instantiationTemplates.getJobRequestAsTemplate(retryUuid);
+
+ //make sure the template request has isFailed = false, and no status message
+ assertFalse(templateOfRetry.getIsFailed());
+ assertNull(templateOfRetry.getStatusMessage());
+ }
+
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
index 7a6b94a1a..0749aaf82 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
@@ -23,8 +23,10 @@ package org.onap.vid.services;
import static net.javacrumbs.jsonunit.JsonAssert.assertJsonEquals;
import static net.javacrumbs.jsonunit.JsonAssert.whenIgnoringPaths;
import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
+import static net.javacrumbs.jsonunit.JsonMatchers.jsonPartEquals;
import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasItem;
@@ -59,12 +61,14 @@ import static org.onap.vid.job.Job.JobStatus.PAUSE;
import static org.onap.vid.job.Job.JobStatus.PENDING;
import static org.onap.vid.job.Job.JobStatus.STOPPED;
import static org.onap.vid.testUtils.TestUtils.generateRandomAlphaNumeric;
+import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -150,8 +154,6 @@ import org.testng.annotations.Test;
@ContextConfiguration(classes = {DataSourceConfig.class, SystemProperties.class, MockedAaiClientAndFeatureManagerConfig.class})
public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseTest {
-
-
@Mock
private JobAdapter jobAdapterMock;
@@ -1391,7 +1393,36 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
{
String path = asyncInstantiationBL.getVfModuleReplacePath("myService", "myVNF", "myVFModule");
assertThat(path, equalTo("/serviceInstantiation/v7/serviceInstances/myService/vnfs/myVNF/vfModules/myVFModule/replace"));
+ }
+ @Test
+ public void whenCallClearStatusFromRequest_isFailedAndStatusAreRemoved() throws JsonProcessingException {
+ ServiceInstantiation serviceInstantiation = JACKSON_OBJECT_MAPPER.readValue(
+ "{"
+ + " \"modelInfo\": {"
+ + " \"modelType\": \"service\""
+ + " },"
+ + " \"isFailed\": true,"
+ + " \"statusMessage\": \"some status\","
+ + " \"vnfs\": {"
+ + " \"vProbe_NC_VNF\": {"
+ + " \"modelInfo\": {"
+ + " \"modelType\": \"vnf\""
+ + " },"
+ + " \"isFailed\": true,"
+ + " \"statusMessage\": \"other status\""
+ + " }"
+ + " }"
+ + "}",
+ ServiceInstantiation.class);
+ asyncInstantiationBL.clearStatusFromRequest(serviceInstantiation);
+ assertThat(serviceInstantiation, allOf(
+ jsonPartEquals("isFailed", false),
+ jsonPartEquals("statusMessage", null),
+ jsonPartEquals("vnfs.vProbe_NC_VNF.isFailed", false),
+ jsonPartEquals("vnfs.vProbe_NC_VNF.statusMessage", null)
+ ));
}
+
}