summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthieu Geerebaert <matthieu.geerebaert@orange.com>2018-05-16 13:37:27 +0000
committerGerrit Code Review <gerrit@onap.org>2018-05-16 13:37:27 +0000
commitf207a196a8c383f0108205c7af8efbd7afecef26 (patch)
treee3eabd5d102c393babd12eb975fcb1c877d65977
parent9d353deac4cbdeada20028515817314bfed02f0c (diff)
parent9d0bf45a33f37c7644a15d12e0c6eefa5124fd6c (diff)
Merge "infinite loop when so not responding"
-rw-r--r--src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java12
-rw-r--r--src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java39
-rw-r--r--src/test/java/org/onap/nbi/apis/ApiTest.java34
3 files changed, 54 insertions, 31 deletions
diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java b/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java
index ef4d8c3..e0daa23 100644
--- a/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java
+++ b/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java
@@ -125,11 +125,15 @@ public class SoClient {
}
private void logResponseGet(String url, ResponseEntity<GetRequestStatusResponse> response) {
- LOGGER.debug(RESPONSE_BODY + response.getBody().toString());
- LOGGER.info(RESPONSE_STATUS + response.getStatusCodeValue());
- if (!response.getStatusCode().equals(HttpStatus.OK)) {
- LOGGER.warn("HTTP call on " + url + RETURNS + response.getStatusCodeValue() + ", "
+ if(response!=null){
+ LOGGER.debug(RESPONSE_BODY + response.getBody().toString());
+ LOGGER.info(RESPONSE_STATUS + response.getStatusCodeValue());
+ if (!response.getStatusCode().equals(HttpStatus.OK)) {
+ LOGGER.warn("HTTP call on " + url + RETURNS + response.getStatusCodeValue() + ", "
+ response.getBody().toString());
+ }
+ } else {
+ LOGGER.info("no response calling url {}",url);
}
}
diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java
index d63de11..f453dc2 100644
--- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java
+++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java
@@ -76,13 +76,7 @@ public class SOTaskProcessor {
ResponseEntity<CreateServiceInstanceResponse> response = postServiceOrderItem(serviceOrderInfo,
serviceOrderItem);
-
- if (response == null) {
- LOGGER.warn("response=null for serviceOrderItem.id=" + serviceOrderItem.getId());
- serviceOrderItem.setState(StateType.FAILED);
- } else {
- updateServiceOrderItem(response, serviceOrderItem);
- }
+ updateServiceOrderItem(response, serviceOrderItem,serviceOrder);
}
if (executionTask.getNbRetries() > 0 && StateType.FAILED != serviceOrderItem.getState()
@@ -298,25 +292,32 @@ public class SOTaskProcessor {
/**
* Update ServiceOrderItem with SO response by using serviceOrderRepository with the serviceOrderId
- *
- * @param response
+ * @param response
* @param orderItem
+ * @param serviceOrder
*/
private void updateServiceOrderItem(ResponseEntity<CreateServiceInstanceResponse> response,
- ServiceOrderItem orderItem) {
+ ServiceOrderItem orderItem, ServiceOrder serviceOrder) {
- CreateServiceInstanceResponse createServiceInstanceResponse = response.getBody();
- if (createServiceInstanceResponse != null && !orderItem.getState().equals(StateType.FAILED)) {
- orderItem.getService().setId(createServiceInstanceResponse.getRequestReferences().getInstanceId());
- orderItem.setRequestId(createServiceInstanceResponse.getRequestReferences().getRequestId());
+ if (response == null) {
+ LOGGER.warn("response=null for serviceOrderItem.id=" + orderItem.getId());
+ orderItem.setState(StateType.FAILED);
}
+ else {
+ CreateServiceInstanceResponse createServiceInstanceResponse = response.getBody();
+ if (createServiceInstanceResponse != null && !orderItem.getState().equals(StateType.FAILED)) {
+ orderItem.getService().setId(createServiceInstanceResponse.getRequestReferences().getInstanceId());
+ orderItem.setRequestId(createServiceInstanceResponse.getRequestReferences().getRequestId());
+ }
- if (response.getStatusCode() != HttpStatus.CREATED || response.getBody() == null
- || response.getBody().getRequestReferences() == null) {
- orderItem.setState(StateType.FAILED);
- } else {
- orderItem.setState(StateType.INPROGRESS);
+ if (response.getStatusCode() != HttpStatus.CREATED || response.getBody() == null
+ || response.getBody().getRequestReferences() == null) {
+ orderItem.setState(StateType.FAILED);
+ } else {
+ orderItem.setState(StateType.INPROGRESS);
+ }
}
+ serviceOrderRepository.save(serviceOrder);
}
/**
diff --git a/src/test/java/org/onap/nbi/apis/ApiTest.java b/src/test/java/org/onap/nbi/apis/ApiTest.java
index ef285a4..a650ab5 100644
--- a/src/test/java/org/onap/nbi/apis/ApiTest.java
+++ b/src/test/java/org/onap/nbi/apis/ApiTest.java
@@ -622,8 +622,8 @@ public class ApiTest {
}
- executionTaskB = getExecutionTask("B");
- assertThat(executionTaskB).isNull();
+ assertThat(executionTaskRepository.count()).isEqualTo(0);
+
}
@@ -661,8 +661,8 @@ public class ApiTest {
}
- executionTaskB = getExecutionTask("B");
- assertThat(executionTaskB).isNull();
+ assertThat(executionTaskRepository.count()).isEqualTo(0);
+
}
@@ -702,8 +702,7 @@ public class ApiTest {
}
- ExecutionTask executionTaskB = executionTaskRepository.findOne(Long.parseLong("2"));
- assertThat(executionTaskB).isNull();
+ assertThat(executionTaskRepository.count()).isEqualTo(0);
}
@@ -727,11 +726,30 @@ public class ApiTest {
assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
}
- ExecutionTask executionTaskB = executionTaskRepository.findOne(Long.parseLong("2"));
- assertThat(executionTaskB).isNull();
+ assertThat(executionTaskRepository.count()).isEqualTo(0);
+
}
+ @Test
+ public void testExecutionTaskFailedNoSoAndStatusResponse() throws Exception {
+
+ ExecutionTask executionTaskA = ServiceOrderAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
+ executionTaskRepository, ActionType.ADD);
+
+ removeWireMockMapping("/ecomp/mso/infra/serviceInstances/v4");
+ removeWireMockMapping("/ecomp/mso/infra/orchestrationRequests/v4/requestId");
+
+ SoTaskProcessor.processOrderItem(executionTaskA);
+ ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
+ assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
+ }
+
+ assertThat(executionTaskRepository.count()).isEqualTo(0);
+
+ }
}