if (StringUtils.isEmpty(serviceSpecId) && StringUtils.isEmpty(serviceSpecName)) {
throw new BackendFunctionalException(HttpStatus.NOT_FOUND,
- "serviceSpecName or serviceSpecId must be provided");
+ "serviceSpecName or serviceSpecId must be provided","serviceSpecName or serviceSpecId must be provided");
}
String customerId = getCustomerId(clientId);
addRelatedPartyId(customerId, serviceInventoryResponse);
return serviceInventoryResponse;
} else {
- throw new BackendFunctionalException(HttpStatus.NOT_FOUND, "no catalog service found");
+ throw new BackendFunctionalException(HttpStatus.NOT_FOUND, "no catalog service found","no catalog service found");
}
}
} catch (BackendFunctionalException e) {
LOGGER.error("error on calling " + url + " ," + e);
- return new ResponseEntity<>(e.getHttpStatus());
+ return new ResponseEntity(e.getBodyResponse(),e.getHttpStatus());
} catch (ResourceAccessException e) {
LOGGER.error("error on calling " + url + " ," + e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (BackendFunctionalException e) {
LOGGER.error("error on calling " + url + " ," + e);
- return new ResponseEntity<>(e.getHttpStatus());
+ return new ResponseEntity(e.getBodyResponse(),e.getHttpStatus());
} catch (ResourceAccessException e) {
LOGGER.error("error on calling " + url + " ," + e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
ServiceOrder serviceOrder = serviceOrderService.findServiceOrderById(serviceOrderInfo.getServiceOrderId());
ServiceOrderItem serviceOrderItem = getServiceOrderItem(executionTask, serviceOrder);
boolean e2eService = E2EServiceUtils.isE2EService(serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId()));
-
+
if (StateType.ACKNOWLEDGED == serviceOrderItem.getState()) {
if (e2eService) {
ResponseEntity<CreateE2EServiceInstanceResponse> response = postE2EServiceOrderItem(serviceOrderInfo,
pollE2ESoRequestStatus(serviceOrder, serviceOrderItem);
else
pollSoRequestStatus(serviceOrder, serviceOrderItem);
-
+
if (serviceOrderItem.getState().equals(StateType.COMPLETED)) {
updateSuccessTask(executionTask);
} else {
}
return response;
}
-
+
private ServiceOrderItem getServiceOrderItem(ExecutionTask executionTask, ServiceOrder serviceOrder) {
for (ServiceOrderItem item : serviceOrder.getOrderItem()) {
if (item.getId().equals(executionTask.getOrderItemId())) {
default:
break;
}
- if(response!=null && response.getStatusCode()== HttpStatus.INTERNAL_SERVER_ERROR) {
- serviceOrderService.addOrderMessage(serviceOrder, "502");
- }
+ buildOrderMessageIfNeeded(serviceOrderItem, serviceOrder, response);
return response;
}
+ private void buildOrderMessageIfNeeded(ServiceOrderItem serviceOrderItem, ServiceOrder serviceOrder,
+ ResponseEntity<?> response) {
+ if(response!=null)
+ {
+ if(response.getStatusCode()== HttpStatus.INTERNAL_SERVER_ERROR) {
+ serviceOrderService.addOrderMessage(serviceOrder, "502");
+ }
+ if(response.getStatusCode()== HttpStatus.BAD_REQUEST) {
+ ResponseEntity<?> messageError=response;
+ if(messageError.getBody().toString().toLowerCase().contains("serviceinstance already exists")){
+ serviceOrderService.addOrderItemMessage(serviceOrder, serviceOrderItem, "105");
+ }
+ }
+ }
+ }
+
private ResponseEntity<CreateE2EServiceInstanceResponse> postE2ESORequest(ServiceOrderItem serviceOrderItem,
ServiceOrderInfo serviceOrderInfo, ServiceOrder serviceOrder) {
ServiceModel service = buildE2ESoRequest(serviceOrderItem, serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId()).getCatalogResponse(), serviceOrderInfo.getSubscriberInfo(), serviceOrder);
default:
break;
}
- if(response!=null && response.getStatusCode()== HttpStatus.INTERNAL_SERVER_ERROR) {
- serviceOrderService.addOrderMessage(serviceOrder, "502");
- }
+ buildOrderMessageIfNeeded(serviceOrderItem, serviceOrder, response);
return response;
}
-
+
private void updateServiceOrder(ServiceOrder serviceOrder) {
boolean atLeastOneCompleted = false;
boolean atLeastOneNotFinished = false;
}
}
}
-
+
/**
* Build SO CREATE request from the ServiceOrder and catalog informations from SDC
*
return requestDetails;
}
-
+
/**
* Build E2E SO CREATE request from the ServiceOrder and catalog informations from SDC
*
}
}
}
-
+
/**
* Update an executionTask in database when it's process with a success
*
*/
package org.onap.nbi.exceptions;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import org.apache.commons.io.IOUtils;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.ResponseErrorHandler;
-import java.io.IOException;
public class BackendErrorHandler implements ResponseErrorHandler {
@Override
public void handleError(ClientHttpResponse response) throws IOException {
if (response.getStatusCode() != null) {
- throw new BackendFunctionalException(response.getStatusCode(), response.getStatusText());
+ String body=null;
+ if(response.getBody()!=null) {
+ body = IOUtils.toString(response.getBody(), StandardCharsets.UTF_8.name());
+ }
+
+ throw new BackendFunctionalException(response.getStatusCode(), response.getStatusText(),body);
}
}
}
private final HttpStatus httpStatus;
- public BackendFunctionalException(HttpStatus httpStatus, String message) {
+ private final String bodyResponse;
+
+ public BackendFunctionalException(HttpStatus httpStatus, String message, String bodyResponse) {
super(message);
this.httpStatus = httpStatus;
+ this.bodyResponse = bodyResponse;
}
public HttpStatus getHttpStatus() {
return httpStatus;
}
+ public String getBodyResponse() {
+ return bodyResponse;
+ }
+
}
import static org.assertj.core.api.Assertions.assertThat;
+
+import com.github.tomakehurst.wiremock.http.ResponseDefinition;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
if (mapping.getRequest().getUrl().equals(s)) {
mappingToDelete = mapping;
}
+
+
}
+
wireMockServer.removeStubMapping(mappingToDelete);
}
+ private void changeWireMockResponse(String s,int statusCode, String bodyContent) {
+ ListStubMappingsResult listStubMappingsResult = wireMockServer.listAllStubMappings();
+ ResponseDefinition responseDefinition = new ResponseDefinition(statusCode,bodyContent);
+ List<StubMapping> mappings = listStubMappingsResult.getMappings();
+ for (StubMapping mapping : mappings) {
+ if (mapping.getRequest().getUrl().equals(s)) {
+ mapping.setResponse(responseDefinition);
+ }
+ }
+ }
+
+
+
+
// serviceCatalog
assertThat(executionTaskRepository.count()).isEqualTo(0);
}
+
+
+ @Test
+ public void testExecutionTaskFailedBadRequestSo() throws Exception {
+
+ ExecutionTask executionTaskA = ServiceOrderAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
+ executionTaskRepository, ActionType.ADD);
+
+
+ changeWireMockResponse("/ecomp/mso/infra/serviceInstances/v6",400,"\"serviceException\": {\n"
+ + " \"messageId\": \"SVC0002\",\n"
+ + " \"text\": \"Error parsing request. org.openecomp.mso.apihandler.common.ValidationException: serviceInstance already existsd\"\n"
+ + " }");
+
+
+ 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);
+
+ for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
+ if(serviceOrderItem.getId().equals("A")) {
+ assertThat(serviceOrderItem.getOrderItemMessage().size()).isEqualTo(1);
+ assertThat(serviceOrderItem.getOrderItemMessage().get(0).getCode()).isEqualTo("105");
+ assertThat(serviceOrderItem.getOrderItemMessage().get(0).getField()).isEqualTo("service.name");
+ }
+ }
+
+ }
+
+
}