diff options
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra')
6 files changed, 168 insertions, 134 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java index ee50d920fe..e8a6beb278 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java @@ -56,10 +56,8 @@ import org.onap.so.apihandlerinfra.exceptions.ValidateException; import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo; import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.ServiceRecipe; -import org.onap.so.db.catalog.data.repository.ServiceRecipeRepository; -import org.onap.so.db.catalog.data.repository.ServiceRepository; +import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.beans.OperationStatus; -import org.onap.so.db.request.data.repository.OperationStatusRepository; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoAlarmLogger; import org.onap.so.logger.MsoLogger; @@ -84,14 +82,12 @@ import com.wordnik.swagger.annotations.ApiOperation; public class E2EServiceInstances { private HashMap<String, String> instanceIdMap = new HashMap<>(); - private static MsoLogger msoLogger = MsoLogger + private static final MsoLogger msoLogger = MsoLogger .getMsoLogger(MsoLogger.Catalog.APIH, E2EServiceInstances.class); - private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger(); - public static final String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA"; + private static final MsoAlarmLogger alarmLogger = new MsoAlarmLogger(); + private static final String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA"; - public static final String END_OF_THE_TRANSACTION = "End of the transaction, the final response is: "; - public static final String EXCEPTION_CREATING_DB_RECORD = "Exception while creating record in DB"; - public static final String EXCEPTION_COMMUNICATE_BPMN_ENGINE = "Exception while communicate with BPMN engine"; + private static final String END_OF_THE_TRANSACTION = "End of the transaction, the final response is: "; @Autowired private MsoRequest msoRequest; @@ -100,13 +96,10 @@ public class E2EServiceInstances { private RequestClientFactory requestClientFactory; @Autowired - private OperationStatusRepository osRepo; + private RequestsDbClient requestsDbClient; @Autowired - private ServiceRepository serviceRepo; - - @Autowired - private ServiceRecipeRepository sRecipeRepo; + private CatalogDbClient catalogDbClient; @Autowired private ResponseBuilder builder; @@ -224,7 +217,7 @@ public class E2EServiceInstances { long startTime = System.currentTimeMillis(); msoLogger.debug("requestId is: " + requestId); - CompareModelsRequest e2eCompareModelReq = null; + CompareModelsRequest e2eCompareModelReq; ObjectMapper mapper = new ObjectMapper(); try { @@ -256,8 +249,8 @@ public class E2EServiceInstances { String workflowUrl = "/mso/async/services/CompareModelofE2EServiceInstance"; int recipeTimeout = 180; - RequestClient requestClient = null; - HttpResponse response = null; + RequestClient requestClient; + HttpResponse response; long subStartTime = System.currentTimeMillis(); @@ -327,12 +320,11 @@ public class E2EServiceInstances { long startTime = System.currentTimeMillis(); - OperationStatus operationStatus = null; + OperationStatus operationStatus; try { - operationStatus = osRepo.findOneByServiceIdAndOperationId(serviceId, + operationStatus = requestsDbClient.getOneByServiceIdAndOperationId(serviceId, operationId); - } catch (Exception e) { msoLogger .error(MessageEnum.APIH_DB_ACCESS_EXC, @@ -353,7 +345,7 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.DBAccessError, "Exception while communciate with Request DB"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) response.getEntity()); + + response.getEntity()); return response; } @@ -371,7 +363,7 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.DataNotFound, "Null response from RequestDB when searching by serviceId"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) resp.getEntity()); + + resp.getEntity()); return resp; } @@ -387,7 +379,7 @@ public class E2EServiceInstances { String requestId = UUIDChecker.generateUUID(msoLogger); long startTime = System.currentTimeMillis(); msoLogger.debug("requestId is: " + requestId); - E2EServiceInstanceDeleteRequest e2eDelReq = null; + E2EServiceInstanceDeleteRequest e2eDelReq; ObjectMapper mapper = new ObjectMapper(); try { @@ -410,11 +402,11 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.SchemaError, "Mapping of request to JSON object failed"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) response.getEntity()); + + response.getEntity()); return response; } - RecipeLookupResult recipeLookupResult = null; + RecipeLookupResult recipeLookupResult; try { //TODO Get the service template model version uuid from AAI. recipeLookupResult = getServiceInstanceOrchestrationURI(null, action); @@ -436,7 +428,7 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.DBAccessError, "Exception while communciate with DB"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) response.getEntity()); + + response.getEntity()); return response; } if (recipeLookupResult == null) { @@ -454,12 +446,12 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.DataNotFound, "No recipe found in DB"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) response.getEntity()); + + response.getEntity()); return response; } - RequestClient requestClient = null; - HttpResponse response = null; + RequestClient requestClient; + HttpResponse response; long subStartTime = System.currentTimeMillis(); try { @@ -514,7 +506,7 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine"); msoLogger.debug("End of the transaction, the final response is: " - + (String) resp.getEntity()); + + resp.getEntity()); return resp; } @@ -530,7 +522,7 @@ public class E2EServiceInstances { msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, "Null response from BPMN"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + resp.getEntity()); return resp; } @@ -548,7 +540,7 @@ public class E2EServiceInstances { String requestId = UUIDChecker.generateUUID(msoLogger); long startTime = System.currentTimeMillis(); msoLogger.debug("requestId is: " + requestId); - E2EServiceInstanceRequest e2eSir = null; + E2EServiceInstanceRequest e2eSir; String serviceId = instanceIdMap.get("serviceId"); ObjectMapper mapper = new ObjectMapper(); @@ -565,7 +557,7 @@ public class E2EServiceInstances { MsoLogger.ErrorCode.SchemaError, requestJSON, e); msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, "Mapping of request to JSON object failed"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -585,11 +577,11 @@ public class E2EServiceInstances { MsoLogger.ErrorCode.SchemaError, requestJSON, e); msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, "Validation of the input request failed"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } - RecipeLookupResult recipeLookupResult = null; + RecipeLookupResult recipeLookupResult; try { recipeLookupResult = getServiceInstanceOrchestrationURI(e2eSir.getService().getServiceUuid(), action); } catch (Exception e) { @@ -603,7 +595,7 @@ public class E2EServiceInstances { msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, "Exception while communciate with DB"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -617,15 +609,15 @@ public class E2EServiceInstances { msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, "No recipe found in DB"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } String serviceInstanceType = e2eSir.getService().getServiceType(); - RequestClient requestClient = null; - HttpResponse response = null; + RequestClient requestClient; + HttpResponse response; long subStartTime = System.currentTimeMillis(); String sirRequestJson = convertToString(sir); @@ -665,7 +657,7 @@ public class E2EServiceInstances { MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine"); msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) getBPMNResp.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + getBPMNResp.getEntity()); return getBPMNResp; } @@ -677,7 +669,7 @@ public class E2EServiceInstances { MsoLogger.ErrorCode.BusinessProcesssError, "Null response from BPEL"); msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, "Null response from BPMN"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) getBPMNResp.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + getBPMNResp.getEntity()); return getBPMNResp; } @@ -694,7 +686,7 @@ public class E2EServiceInstances { String requestId = UUIDChecker.generateUUID(msoLogger); long startTime = System.currentTimeMillis(); msoLogger.debug("requestId is: " + requestId); - E2EServiceInstanceRequest e2eSir = null; + E2EServiceInstanceRequest e2eSir; MsoRequest msoRequest = new MsoRequest(); ObjectMapper mapper = new ObjectMapper(); @@ -711,7 +703,7 @@ public class E2EServiceInstances { MsoLogger.ErrorCode.SchemaError, requestJSON, e); msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, "Mapping of request to JSON object failed"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -731,11 +723,11 @@ public class E2EServiceInstances { MsoLogger.ErrorCode.SchemaError, requestJSON, e); msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, "Validation of the input request failed"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } - RecipeLookupResult recipeLookupResult = null; + RecipeLookupResult recipeLookupResult; try { recipeLookupResult = getServiceInstanceOrchestrationURI(e2eSir.getService().getServiceUuid(), action); } catch (Exception e) { @@ -749,7 +741,7 @@ public class E2EServiceInstances { msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, "Exception while communciate with DB"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -762,15 +754,15 @@ public class E2EServiceInstances { msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, "No recipe found in DB"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } String serviceInstanceType = e2eSir.getService().getServiceType(); String serviceId = ""; - RequestClient requestClient = null; - HttpResponse response = null; + RequestClient requestClient; + HttpResponse response; long subStartTime = System.currentTimeMillis(); String sirRequestJson = convertToString(sir); @@ -809,7 +801,7 @@ public class E2EServiceInstances { MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine"); msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + resp.getEntity()); return resp; } @@ -820,7 +812,7 @@ public class E2EServiceInstances { MsoLogger.ErrorCode.BusinessProcesssError, "Null response from BPEL"); msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, "Null response from BPMN"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + resp.getEntity()); return resp; } @@ -837,7 +829,7 @@ public class E2EServiceInstances { String requestId = UUIDChecker.generateUUID(msoLogger); long startTime = System.currentTimeMillis(); msoLogger.debug("requestId is: " + requestId); - E2EServiceInstanceScaleRequest e2eScaleReq = null; + E2EServiceInstanceScaleRequest e2eScaleReq; ObjectMapper mapper = new ObjectMapper(); try { @@ -860,11 +852,11 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.SchemaError, "Mapping of request to JSON object failed"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) response.getEntity()); + + response.getEntity()); return response; } - RecipeLookupResult recipeLookupResult = null; + RecipeLookupResult recipeLookupResult; try { //TODO Get the service template model version uuid from AAI. recipeLookupResult = getServiceInstanceOrchestrationURI(null, action); @@ -886,7 +878,7 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.DBAccessError, "Exception while communciate with DB"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) response.getEntity()); + + response.getEntity()); return response; } if (recipeLookupResult == null) { @@ -903,12 +895,12 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.DataNotFound, "No recipe found in DB"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) response.getEntity()); + + response.getEntity()); return response; } - RequestClient requestClient = null; - HttpResponse response = null; + RequestClient requestClient; + HttpResponse response; long subStartTime = System.currentTimeMillis(); try { @@ -963,7 +955,7 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) resp.getEntity()); + + resp.getEntity()); return resp; } @@ -979,7 +971,7 @@ public class E2EServiceInstances { msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, "Null response from BPMN"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + resp.getEntity()); return resp; } @@ -1028,7 +1020,7 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.InternalError, "Response from BPMN engine is failed"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) resp.getEntity()); + + resp.getEntity()); return resp; } else { Response resp = msoRequest @@ -1047,7 +1039,7 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.InternalError, "Response from BPEL engine is empty"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) resp.getEntity()); + + resp.getEntity()); return resp; } } @@ -1056,7 +1048,6 @@ public class E2EServiceInstances { /** * Getting recipes from catalogDb * - * @param db the catalog db * @param serviceModelUUID the service model version uuid * @param action the action for the service * @return the service recipe result @@ -1079,7 +1070,6 @@ public class E2EServiceInstances { /** * Getting recipes from catalogDb * If Service recipe is not set, use default recipe, if set , use special recipe. - * @param db the catalog db * @param serviceModelUUID the service version uuid * @param action the action of the service. * @return the service recipe result. @@ -1088,13 +1078,12 @@ public class E2EServiceInstances { String defaultServiceModelName = "UUI_DEFAULT"; - Service defaultServiceRecord = serviceRepo.findFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName); - ServiceRecipe defaultRecipe = sRecipeRepo.findFirstByServiceModelUUIDAndAction(defaultServiceRecord.getModelUUID(), action.name()); + Service defaultServiceRecord = catalogDbClient.getFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName); //set recipe as default generic recipe - ServiceRecipe recipe = defaultRecipe; + ServiceRecipe recipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(defaultServiceRecord.getModelUUID(), action.name()); //check the service special recipe if(null != serviceModelUUID && ! serviceModelUUID.isEmpty()){ - ServiceRecipe serviceSpecialRecipe = sRecipeRepo.findFirstByServiceModelUUIDAndAction( + ServiceRecipe serviceSpecialRecipe = catalogDbClient.getFirstByServiceModelUUIDAndAction( serviceModelUUID, action.name()); if(null != serviceSpecialRecipe){ //set service special recipe. diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java index a93feb6cd9..38b3dd6054 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java @@ -95,7 +95,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class MsoRequest { @Autowired - private InfraActiveRequestsRepository iarRepo; + private RequestsDbClient requestsDbClient; @Autowired private ResponseBuilder builder; @@ -426,7 +426,7 @@ public class MsoRequest { request.setRequestBody(requestJSON); Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis()); request.setEndTime(endTimeStamp); - iarRepo.save(request); + requestsDbClient.save(request); } catch (Exception e) { msoLogger.error(MessageEnum.APIH_DB_UPDATE_EXC, e.getMessage(), "", "", MsoLogger.ErrorCode.DataError, "Exception when updating record in DB"); msoLogger.debug ("Exception: ", e); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestsDbClient.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestsDbClient.java index 466de0aa0e..380ee2c6ad 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestsDbClient.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestsDbClient.java @@ -22,6 +22,7 @@ package org.onap.so.apihandlerinfra; import org.apache.http.HttpStatus; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.beans.OperationStatus; import org.onap.so.db.request.data.controller.InstanceNameDuplicateCheckRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -30,10 +31,6 @@ import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; -import org.springframework.http.HttpRequest; -import org.springframework.http.client.ClientHttpRequestExecution; -import org.springframework.http.client.ClientHttpRequestInterceptor; -import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.stereotype.Component; import org.springframework.web.client.HttpClientErrorException; @@ -41,10 +38,9 @@ import org.springframework.web.client.RestTemplate; import uk.co.blackpepper.bowman.Client; import uk.co.blackpepper.bowman.ClientFactory; import uk.co.blackpepper.bowman.Configuration; -import uk.co.blackpepper.bowman.RestTemplateConfigurer; import javax.annotation.PostConstruct; -import java.io.IOException; +import javax.ws.rs.core.UriBuilder; import java.net.URI; import java.util.HashMap; import java.util.List; @@ -53,7 +49,11 @@ import java.util.Map; @Component("RequestDbClient") public class RequestsDbClient { + private static final String SERVICE_ID = "SERVICE_ID"; + private static final String OPERATION_ID = "OPERATION_ID"; + private Client<InfraActiveRequests> infraActiveRequestClient; + private Client<OperationStatus> operationStatusClient; @Value("${mso.adapters.requestDb.endpoint}") private String endpoint; @@ -62,12 +62,15 @@ public class RequestsDbClient { private String msoAdaptersAuth; private String getOrchestrationFilterURI = "/infraActiveRequests/getOrchestrationFiltersFromInfraActive/"; + private static final String OPERATION_STATUS_REPOSITORY_SEARCH = "/operationStatusRepository/search"; private String checkVnfIdStatus = "/infraActiveRequests/checkVnfIdStatus/"; private String infraActiveRequestURI = "/infraActiveRequests/"; private String checkInstanceNameDuplicate = "/infraActiveRequests/checkInstanceNameDuplicate"; + + private String findOneByServiceIdAndOperationIdURI = "/findOneByServiceIdAndOperationId"; private String cloudOrchestrationFiltersFromInfraActive = "/infraActiveRequests/getCloudOrchestrationFiltersFromInfraActive"; @@ -83,27 +86,18 @@ public class RequestsDbClient { checkVnfIdStatus = endpoint + checkVnfIdStatus; checkInstanceNameDuplicate = endpoint + checkInstanceNameDuplicate; cloudOrchestrationFiltersFromInfraActive = endpoint + cloudOrchestrationFiltersFromInfraActive; + findOneByServiceIdAndOperationIdURI = endpoint + OPERATION_STATUS_REPOSITORY_SEARCH + findOneByServiceIdAndOperationIdURI; headers = new HttpHeaders(); headers.set("Authorization", msoAdaptersAuth); } public RequestsDbClient() { - ClientFactory clientFactory = Configuration.builder().setRestTemplateConfigurer(new RestTemplateConfigurer() { - - public void configure(RestTemplate restTemplate) { - - restTemplate.getInterceptors().add(new ClientHttpRequestInterceptor() { - - public ClientHttpResponse intercept(HttpRequest request, byte[] body, - ClientHttpRequestExecution execution) throws IOException { - - request.getHeaders().add("Authorization", msoAdaptersAuth); - return execution.execute(request, body); - } - }); - } - }).build().buildClientFactory(); + ClientFactory clientFactory = Configuration.builder().setRestTemplateConfigurer(restTemplate -> restTemplate.getInterceptors().add((request, body, execution) -> { + request.getHeaders().add("Authorization", msoAdaptersAuth); + return execution.execute(request, body); + })).build().buildClientFactory(); infraActiveRequestClient = clientFactory.create(InfraActiveRequests.class); + operationStatusClient = clientFactory.create(OperationStatus.class); } public List<InfraActiveRequests> getCloudOrchestrationFiltersFromInfraActive(Map<String, String> orchestrationMap){ @@ -145,6 +139,13 @@ public class RequestsDbClient { } } + + public OperationStatus getOneByServiceIdAndOperationId(String serviceId, String operationId){ + return this.getSingleOperationStatus(UriBuilder.fromUri(findOneByServiceIdAndOperationIdURI) + .queryParam(SERVICE_ID,serviceId) + .queryParam(OPERATION_ID,operationId) + .build()); + } public void save(InfraActiveRequests infraActiveRequests) { URI uri = getUri(infraActiveRequestURI); @@ -159,6 +160,10 @@ public class RequestsDbClient { public void updateInfraActiveRequests(InfraActiveRequests request) { infraActiveRequestClient.put(request); } + + public OperationStatus getSingleOperationStatus(URI uri){ + return operationStatusClient.get(uri); + } protected URI getUri(String uri) { return URI.create(uri); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/resources/application-local.yaml b/mso-api-handlers/mso-api-handler-infra/src/main/resources/application-local.yaml index 3252146bfa..226814f278 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/resources/application-local.yaml +++ b/mso-api-handlers/mso-api-handler-infra/src/main/resources/application-local.yaml @@ -17,6 +17,10 @@ camunda-nodehealthcheck-urn: /mso/nodehealthcheck mso: + adapters: + requestDb: + auth: Basic YnBlbDptc28tZGItMTUwNyE= + endpoint: http://localhost:8081 logPath: logs site-name: mtanj catalog: diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java index 2baa54fdec..a63b778a1f 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java @@ -20,10 +20,7 @@ package org.onap.so.apihandlerinfra; -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.client.WireMock.*; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; @@ -33,11 +30,17 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.junit.Ignore; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.apache.http.HttpStatus; +import org.junit.Before; import org.junit.Test; +import org.onap.so.db.catalog.beans.Service; +import org.onap.so.db.catalog.beans.ServiceRecipe; +import org.onap.so.db.request.beans.OperationStatus; import org.onap.so.serviceinstancebeans.RequestError; import org.onap.so.serviceinstancebeans.ServiceException; import org.springframework.http.HttpEntity; @@ -45,43 +48,65 @@ import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.util.UriComponentsBuilder; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.tomakehurst.wiremock.http.Fault; public class E2EServiceInstancesTest extends BaseTest { -private ObjectMapper mapper = new ObjectMapper(); +private final ObjectMapper mapper = new ObjectMapper(); private final String e2eServInstancesUri = "/e2eServiceInstances/"; + + @Before + public void init() throws JsonProcessingException { + stubFor(post(urlPathEqualTo("/testOrchestrationUri")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withStatus(HttpStatus.SC_OK))); + stubFor(post(urlPathEqualTo("/infraActiveRequests/")).withRequestBody(equalToJson("{\"clientRequestId\":null,\"action\":null,\"requestStatus\":\"FAILED\",\"statusMessage\":\"Error parsing request: No valid requestorId is specified\",\"progress\":100,\"startTime\":1533541051247,\"endTime\":1533541051247,\"source\":null,\"vnfId\":null,\"vnfName\":null,\"vnfType\":null,\"serviceType\":null,\"aicNodeClli\":null,\"tenantId\":null,\"provStatus\":null,\"vnfParams\":null,\"vnfOutputs\":null,\"requestBody\":\"{\\r\\n \\\"service\\\":{\\r\\n \\\"name\\\":\\\"so_test4\\\",\\r\\n \\\"description\\\":\\\"so_test2\\\",\\r\\n \\\"serviceInvariantUuid\\\":\\\"60c3e96e-0970-4871-b6e0-3b6de7561519\\\",\\r\\n \\\"serviceUuid\\\":\\\"592f9437-a9c0-4303-b9f6-c445bb7e9814\\\",\\r\\n \\\"globalSubscriberId\\\":\\\"123457\\\",\\r\\n \\\"serviceType\\\":\\\"voLTE\\\",\\r\\n \\\"parameters\\\":{\\r\\n \\\"resources\\\":[\\r\\n {\\r\\n \\\"resourceName\\\":\\\"vIMS\\\",\\r\\n \\\"resourceInvariantUuid\\\":\\\"60c3e96e-0970-4871-b6e0-3b6de7561516\\\",\\r\\n \\\"resourceUuid\\\":\\\"60c3e96e-0970-4871-b6e0-3b6de7561512\\\",\\r\\n \\\"parameters\\\":{\\r\\n \\\"locationConstraints\\\":[\\r\\n {\\r\\n \\\"vnfProfileId\\\":\\\"zte-vBAS-1.0\\\",\\r\\n \\\"locationConstraints\\\":{\\r\\n \\\"vimId\\\":\\\"4050083f-465f-4838-af1e-47a545222ad0\\\"\\r\\n }\\r\\n },\\r\\n {\\r\\n \\\"vnfProfileId\\\":\\\"zte-vMME-1.0\\\",\\r\\n \\\"locationConstraints\\\":{\\r\\n \\\"vimId\\\":\\\"4050083f-465f-4838-af1e-47a545222ad0\\\"\\r\\n }\\r\\n }\\r\\n ]\\r\\n }\\r\\n },\\r\\n {\\r\\n \\\"resourceName\\\":\\\"vEPC\\\",\\r\\n \\\"resourceInvariantUuid\\\":\\\"61c3e96e-0970-4871-b6e0-3b6de7561516\\\",\\r\\n \\\"resourceUuid\\\":\\\"62c3e96e-0970-4871-b6e0-3b6de7561512\\\",\\r\\n \\\"parameters\\\":{\\r\\n \\\"locationConstraints\\\":[\\r\\n {\\r\\n \\\"vnfProfileId\\\":\\\"zte-CSCF-1.0\\\",\\r\\n \\\"locationConstraints\\\":{\\r\\n \\\"vimId\\\":\\\"4050083f-465f-4838-af1e-47a545222ad1\\\"\\r\\n }\\r\\n }\\r\\n ]\\r\\n }\\r\\n },\\r\\n {\\r\\n \\\"resourceName\\\":\\\"underlayvpn\\\",\\r\\n \\\"resourceInvariantUuid\\\":\\\"60c3e96e-0970-4871-b6e0-3b6de7561513\\\",\\r\\n \\\"resourceUuid\\\":\\\"60c3e96e-0970-4871-b6e0-3b6de7561514\\\",\\r\\n \\\"parameters\\\":{\\r\\n \\\"locationConstraints\\\":[\\r\\n\\r\\n ]\\r\\n }\\r\\n },\\r\\n {\\r\\n \\\"resourceName\\\":\\\"overlayvpn\\\",\\r\\n \\\"resourceInvariantUuid\\\":\\\"60c3e96e-0970-4871-b6e0-3b6de7561517\\\",\\r\\n \\\"resourceUuid\\\":\\\"60c3e96e-0970-4871-b6e0-3b6de7561518\\\",\\r\\n \\\"parameters\\\":{\\r\\n \\\"locationConstraints\\\":[\\r\\n\\r\\n ]\\r\\n }\\r\\n }\\r\\n ],\\r\\n \\\"requestInputs\\\":{\\r\\n \\\"externalDataNetworkName\\\":\\\"Flow_out_net\\\",\\r\\n \\\"m6000_mng_ip\\\":\\\"181.18.20.2\\\",\\r\\n \\\"externalCompanyFtpDataNetworkName\\\":\\\"Flow_out_net\\\",\\r\\n \\\"externalPluginManageNetworkName\\\":\\\"plugin_net_2014\\\",\\r\\n \\\"externalManageNetworkName\\\":\\\"mng_net_2017\\\",\\r\\n \\\"sfc_data_network\\\":\\\"sfc_data_net_2016\\\",\\r\\n \\\"NatIpRange\\\":\\\"210.1.1.10-210.1.1.20\\\",\\r\\n \\\"location\\\":\\\"4050083f-465f-4838-af1e-47a545222ad0\\\",\\r\\n \\\"sdncontroller\\\":\\\"9b9f02c0-298b-458a-bc9c-be3692e4f35e\\\"\\r\\n }\\r\\n }\\r\\n\\r\\n }\\r\\n\\r\\n}\",\"responseBody\":null,\"lastModifiedBy\":\"APIH\",\"modifyTime\":null,\"requestType\":null,\"volumeGroupId\":null,\"volumeGroupName\":null,\"vfModuleId\":null,\"vfModuleName\":null,\"vfModuleModelName\":null,\"aaiServiceId\":null,\"aicCloudRegion\":null,\"callBackUrl\":null,\"correlator\":null,\"serviceInstanceId\":null,\"serviceInstanceName\":null,\"requestScope\":\"service\",\"requestAction\":\"createInstance\",\"networkId\":null,\"networkName\":null,\"networkType\":null,\"requestorId\":null,\"configurationId\":null,\"configurationName\":null,\"operationalEnvId\":null,\"operationalEnvName\":null,\"requestURI\":\"d167c9d0-1785-4e93-b319-996ebbcc3272\"}")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withStatus(HttpStatus.SC_OK))); + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setServiceModelUUID(defaultService.getModelUUID()); + serviceRecipe.setAction(Action.scaleInstance.name()); + serviceRecipe.setRecipeTimeout(180); + serviceRecipe.setOrchestrationUri("/testOrchestrationUri"); + + stubFor(get(urlPathEqualTo("/service/search/findFirstByModelNameOrderByModelVersionDesc")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlPathEqualTo("/serviceRecipe/search/findFirstByServiceModelUUIDAndAction")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(serviceRecipe)) + .withStatus(HttpStatus.SC_OK))); + + } public String inputStream(String JsonInput)throws IOException{ JsonInput = "src/test/resources/E2EServiceInstancesTest" + JsonInput; - String input = new String(Files.readAllBytes(Paths.get(JsonInput))); - return input; + return new String(Files.readAllBytes(Paths.get(JsonInput))); } public ResponseEntity<String> sendRequest(String requestJson, String uriPath, HttpMethod reqMethod){ headers.set("Accept", MediaType.APPLICATION_JSON); headers.set("Content-Type",MediaType.APPLICATION_JSON); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(uriPath)); - HttpEntity<String> request = new HttpEntity<String>(requestJson, headers); - ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), + HttpEntity<String> request = new HttpEntity<>(requestJson, headers); + + return restTemplate.exchange(builder.toUriString(), reqMethod, request, String.class); - - return response; } - //Currently returning a 500 response - @Ignore + @Test - public void createE2EServiceInstanceNoRequestInfo() throws JsonParseException, JsonMappingException, IOException{ - String uri = e2eServInstancesUri + "v5"; + public void createE2EServiceInstanceNoRequestInfo() throws IOException{ + String uri = e2eServInstancesUri + "v3"; ResponseEntity<String> response = sendRequest(inputStream("/Request.json"), uri, HttpMethod.POST); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); } @Test - public void updateE2EServiceInstanceJSONMappingError() throws JsonParseException, JsonMappingException, IOException{ + public void updateE2EServiceInstanceJSONMappingError() throws IOException{ String uri = e2eServInstancesUri + "v5/9b9f02c0-298b-458a-bc9c-be3692e4f35e"; ResponseEntity<String> response = sendRequest(inputStream("/CompareModelRequest.json"), uri, HttpMethod.PUT); @@ -90,7 +115,7 @@ private ObjectMapper mapper = new ObjectMapper(); assertTrue(realResponse.getServiceException().getText().contains("Mapping of request to JSON object failed")); } @Test - public void updateE2EServiceInstanceNoRequestorId() throws JsonParseException, JsonMappingException, IOException{ + public void updateE2EServiceInstanceNoRequestorId() throws IOException{ RequestError expectedResponse = new RequestError(); ServiceException exception = new ServiceException(); exception.setMessageId("SVC0002"); @@ -105,7 +130,7 @@ private ObjectMapper mapper = new ObjectMapper(); assertThat(realResponse, sameBeanAs(expectedResponse)); } @Test - public void deleteE2EServiceInstanceNoRecipe() throws JsonParseException, JsonMappingException, IOException{ + public void deleteE2EServiceInstance() throws IOException{ RequestError expectedResponse = new RequestError(); ServiceException exception = new ServiceException(); exception.setMessageId("SVC1000"); @@ -115,12 +140,10 @@ private ObjectMapper mapper = new ObjectMapper(); String uri = e2eServInstancesUri + "v5/9b9f02c0-298b-458a-bc9c-be3692e4f35e"; ResponseEntity<String> response = sendRequest(inputStream("/DeleteRequest.json"), uri, HttpMethod.DELETE); - assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value()); - RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); - assertThat(realResponse, sameBeanAs(expectedResponse)); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); } @Test - public void deleteE2EServiceInstanceNotValid() throws JsonParseException, JsonMappingException, IOException{ + public void deleteE2EServiceInstanceNotValid() throws IOException{ String uri = e2eServInstancesUri + "v5/9b9f02c0-298b-458a-bc9c-be3692e4f35e"; ResponseEntity<String> response = sendRequest(inputStream("/Request.json"), uri, HttpMethod.DELETE); @@ -129,14 +152,14 @@ private ObjectMapper mapper = new ObjectMapper(); assertTrue(realResponse.getServiceException().getText().contains("Mapping of request to JSON object failed")); } @Test - public void getE2EServiceInstanceNullOperationalStatus() throws JsonParseException, JsonMappingException, IOException{ + public void getE2EServiceInstanceNullOperationalStatus() throws IOException{ String uri = e2eServInstancesUri + "v5/9b9f02c0-298b-458a-bc9c-be3692e4f35e/operations/9b9f02c0-298b-458a-bc9c-be3692e4f35e"; ResponseEntity<String> response = sendRequest(inputStream("/Request.json"), uri, HttpMethod.GET); assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatusCode().value()); } @Test - public void scaleE2EServiceInstanceMappingError() throws JsonParseException, JsonMappingException, IOException{ + public void scaleE2EServiceInstanceMappingError() throws IOException{ String uri = e2eServInstancesUri + "v5/9b9f02c0-298b-458a-bc9c-be3692e4f35e/scale"; ResponseEntity<String> response = sendRequest(inputStream("/Request.json"), uri, HttpMethod.POST); @@ -145,22 +168,35 @@ private ObjectMapper mapper = new ObjectMapper(); assertTrue(realResponse.getServiceException().getText().contains("Mapping of request to JSON object failed")); } @Test - public void scaleE2EServiceInstance() throws JsonParseException, JsonMappingException, IOException{ - RequestError expectedResponse = new RequestError(); - ServiceException exception = new ServiceException(); - exception.setMessageId("SVC1000"); - exception.setText("No communication to catalog DB null"); - expectedResponse.setServiceException(exception); - + public void scaleE2EServiceInstance() throws IOException{ String uri = e2eServInstancesUri + "v5/9b9f02c0-298b-458a-bc9c-be3692e4f35e/scale"; ResponseEntity<String> response = sendRequest(inputStream("/ScaleRequest.json"), uri, HttpMethod.POST); - assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value()); - RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); - assertThat(realResponse, sameBeanAs(expectedResponse)); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); + } + + @Test + public void updateE2EServiceInstance() throws IOException{ + String uri = e2eServInstancesUri + "v3/9b9f02c0-298b-458a-bc9c-be3692e4f35e"; + ResponseEntity<String> response = sendRequest(inputStream("/Request.json"), uri, HttpMethod.PUT); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); + } + + @Test + public void getE2EServiceInstance() throws IOException{ + OperationStatus status = new OperationStatus(); + status.setOperationId("operationId"); + status.setServiceId("9b9f02c0-298b-458a-bc9c-be3692e4f35e"); + stubFor(get(urlPathEqualTo("/operationStatusRepository/search/findOneByServiceIdAndOperationId")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(status)) + .withStatus(HttpStatus.SC_OK))); + String uri = e2eServInstancesUri + "v3/9b9f02c0-298b-458a-bc9c-be3692e4f35e/operations/operationId"; + ResponseEntity<String> response = sendRequest("", uri, HttpMethod.GET); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); } @Test - public void compareModelWithTargetVersionBadRequest() throws JsonParseException, JsonMappingException, IOException{ + public void compareModelWithTargetVersionBadRequest() throws IOException{ String uri = e2eServInstancesUri + "v5/9b9f02c0-298b-458a-bc9c-be3692e4f35e/modeldifferences"; ResponseEntity<String> response = sendRequest(inputStream("/Request.json"), uri, HttpMethod.POST); @@ -169,7 +205,7 @@ private ObjectMapper mapper = new ObjectMapper(); assertTrue(realResponse.getServiceException().getText().contains("Mapping of request to JSON object failed")); } @Test - public void compareModelWithTargetVersion() throws JsonParseException, JsonMappingException, IOException{ + public void compareModelWithTargetVersion() throws IOException{ stubFor(post(urlPathEqualTo("/mso/async/services/CompareModelofE2EServiceInstance")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBodyFile("Camunda/SuccessfulResponse.json").withStatus(org.apache.http.HttpStatus.SC_ACCEPTED))); @@ -183,7 +219,7 @@ private ObjectMapper mapper = new ObjectMapper(); assertEquals(expectedResponse, actualResponse); } @Test - public void compareModelWithTargetVersionEmptyResponse() throws JsonParseException, JsonMappingException, IOException{ + public void compareModelWithTargetVersionEmptyResponse() throws IOException{ stubFor(post(urlPathEqualTo("/mso/async/services/CompareModelofE2EServiceInstance")) .willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE))); @@ -201,7 +237,7 @@ private ObjectMapper mapper = new ObjectMapper(); assertThat(realResponse, sameBeanAs(expectedResponse)); } @Test - public void compareModelWithTargetVersionBadBpelResponse() throws JsonParseException, JsonMappingException, IOException{ + public void compareModelWithTargetVersionBadBpelResponse() throws IOException{ stubFor(post(urlPathEqualTo("/mso/async/services/CompareModelofE2EServiceInstance")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_BAD_GATEWAY))); @@ -214,7 +250,7 @@ private ObjectMapper mapper = new ObjectMapper(); assertTrue(realResponse.getServiceException().getText().contains("Request Failed due to BPEL error with HTTP Status")); } @Test - public void compareModelWithTargetVersionNoBPELResponse() throws JsonParseException, JsonMappingException, IOException{ + public void compareModelWithTargetVersionNoBPELResponse() throws IOException{ stubFor(post(urlPathEqualTo("/mso/async/services/CompareModelofE2EServiceInstance")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody("{}").withStatus(org.apache.http.HttpStatus.SC_BAD_GATEWAY))); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml b/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml index c5b3b70723..b7b6a8c1cb 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml @@ -29,7 +29,7 @@ mso: catalog: db: spring: - endpoint: "http://localhost:" + endpoint: http://localhost:${wiremock.server.port} db: auth: Basic YnBlbDptc28tZGItMTUwNyE= config: |