aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/main/java
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2019-01-22 12:55:57 -0500
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-01-24 18:21:11 -0500
commit7183dfbf1ee48fba7d31fc4bf2b1666951966a1c (patch)
tree25b609d43f3513e9aa6b389fb62e5d00dc3f5704 /mso-api-handlers/mso-api-handler-infra/src/main/java
parent303b11fd56f09afea5ae125ee0bdc69c6ceac141 (diff)
update all inprogress checks in apih handler
Added second mapper for error responses Removed method level ObjectMapper instantiation Fixed formatting of resource file Added db update if responsne from history lookup is empty Fixed url and added it to yaml file Removed space added to the end of line Removed unused test resource file Changed wording of exception message name Added more JUnit tests and fixed auth lookup Added path for checking process-instance history Added ContactCamundaException for camundaHistoryCheck Began adding auth header to send on request to camunda Added unit tests for completed and terminated requests Began adding test for camundaHistoryCheck Added HistoricProcessInstance object for camunda response Test commit, added comment to camundaHistoryCheck Began adding method for checking camundaHistory Change-Id: Ia9d94613fa5e78f2b8690874c39f032d60599e5e Issue-ID: SO-1414 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main/java')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java83
1 files changed, 76 insertions, 7 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
index 8c00eb06b4..66b04b6fdb 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
@@ -44,6 +44,7 @@ import org.onap.so.apihandler.common.ResponseHandler;
import org.onap.so.apihandlerinfra.exceptions.ApiException;
import org.onap.so.apihandlerinfra.exceptions.BPMNFailureException;
import org.onap.so.apihandlerinfra.exceptions.ClientConnectionException;
+import org.onap.so.apihandlerinfra.exceptions.ContactCamundaException;
import org.onap.so.apihandlerinfra.exceptions.DuplicateRequestException;
import org.onap.so.apihandlerinfra.exceptions.RecipeNotFoundException;
import org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException;
@@ -51,6 +52,7 @@ import org.onap.so.apihandlerinfra.exceptions.ValidateException;
import org.onap.so.apihandlerinfra.exceptions.VfModuleNotFoundException;
import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
import org.onap.so.db.catalog.beans.NetworkResource;
+import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
import org.onap.so.db.catalog.beans.Recipe;
import org.onap.so.db.catalog.beans.ServiceRecipe;
import org.onap.so.db.catalog.beans.VfModule;
@@ -82,8 +84,17 @@ import org.onap.so.serviceinstancebeans.Vnfs;
import org.onap.so.utils.UUIDChecker;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.env.Environment;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
+import org.springframework.web.client.HttpStatusCodeException;
+import org.springframework.web.client.RestTemplate;
+import org.camunda.bpm.engine.history.HistoricProcessInstance;
+import org.camunda.bpm.engine.impl.persistence.entity.HistoricProcessInstanceEntity;
import javax.transaction.Transactional;
import javax.ws.rs.Consumes;
@@ -135,6 +146,9 @@ public class ServiceInstances {
@Autowired
private MsoRequest msoRequest;
+ @Autowired
+ private RestTemplate restTemplate;
+
@POST
@Path("/{version:[vV][5-7]}/serviceInstances")
@Consumes(MediaType.APPLICATION_JSON)
@@ -718,11 +732,15 @@ public class ServiceInstances {
}
InfraActiveRequests dup = null;
-
+ boolean inProgress = false;
dup = duplicateCheck(action, instanceIdMap, startTime, msoRequest, instanceName,requestScope, currentActiveReq);
- if (dup != null) {
+ if(dup != null){
+ inProgress = camundaHistoryCheck(dup, currentActiveReq);
+ }
+
+ if (dup != null && inProgress) {
buildErrorOnDuplicateRecord(currentActiveReq, action, instanceIdMap, startTime, msoRequest, instanceName, requestScope, dup);
}
ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse();
@@ -881,8 +899,13 @@ public class ServiceInstances {
}
InfraActiveRequests dup = duplicateCheck(action, instanceIdMap, startTime, msoRequest, null, requestScope, currentActiveReq);
-
- if (dup != null) {
+ boolean inProgress = false;
+
+ if(dup != null){
+ inProgress = camundaHistoryCheck(dup, currentActiveReq);
+ }
+
+ if (dup != null && inProgress) {
buildErrorOnDuplicateRecord(currentActiveReq, action, instanceIdMap, startTime, msoRequest, null, requestScope, dup);
}
@@ -1149,6 +1172,42 @@ public class ServiceInstances {
}
return dup;
}
+ protected boolean camundaHistoryCheck(InfraActiveRequests duplicateRecord, InfraActiveRequests currentActiveReq) throws RequestDbFailureException, ContactCamundaException{
+ String requestId = duplicateRecord.getRequestId();
+ String path = env.getProperty("mso.camunda.rest.history.uri") + requestId;
+ String targetUrl = env.getProperty("mso.camundaURL") + path;
+ HttpHeaders headers = setHeaders(env.getProperty("mso.camundaAuth"));
+ HttpEntity<?> requestEntity = new HttpEntity<>(headers);
+ ResponseEntity<List<HistoricProcessInstanceEntity>> response = null;
+ try{
+ response = restTemplate.exchange(targetUrl, HttpMethod.GET, requestEntity, new ParameterizedTypeReference<List<HistoricProcessInstanceEntity>>(){});
+ }catch(HttpStatusCodeException e){
+ ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DUPLICATE_CHECK_EXC, MsoLogger.ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
+ ContactCamundaException contactCamundaException= new ContactCamundaException.Builder(requestId, e.toString(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e)
+ .errorInfo(errorLoggerInfo).build();
+ updateStatus(currentActiveReq, Status.FAILED, contactCamundaException.getMessage());
+ throw contactCamundaException;
+ }
+ if(response.getBody().isEmpty()){
+ updateStatus(duplicateRecord, Status.COMPLETE, "Request Completed");
+ }
+ for(HistoricProcessInstance instance : response.getBody()){
+ if(instance.getState().equals("ACTIVE")){
+ return true;
+ }else{
+ updateStatus(duplicateRecord, Status.COMPLETE, "Request Completed");
+ }
+ }
+ return false;
+ }
+ private HttpHeaders setHeaders(String auth) {
+ HttpHeaders headers = new HttpHeaders();
+ List<org.springframework.http.MediaType> acceptableMediaTypes = new ArrayList<>();
+ acceptableMediaTypes.add(org.springframework.http.MediaType.APPLICATION_JSON);
+ headers.setAccept(acceptableMediaTypes);
+ headers.add(HttpHeaders.AUTHORIZATION, auth);
+ return headers;
+ }
private ServiceInstancesRequest convertJsonToServiceInstanceRequest(String requestJSON, Actions action, long startTime,
ServiceInstancesRequest sir, MsoRequest msoRequest, String requestId, String requestUri) throws ApiException {
@@ -1672,7 +1731,9 @@ public class ServiceInstances {
Recipe recipe = null;
if(modelInfo.getModelCustomizationId()!=null){
- NetworkResource networkResource = catalogDbClient.getNetworkResourceCustomizationByModelCustomizationUUID(modelInfo.getModelCustomizationId()).getNetworkResource();
+ NetworkResourceCustomization networkResourceCustomization = catalogDbClient.getNetworkResourceCustomizationByModelCustomizationUUID(modelInfo.getModelCustomizationId());
+ if(networkResourceCustomization != null){
+ NetworkResource networkResource = networkResourceCustomization.getNetworkResource();
if(networkResource!=null){
if(modelInfo.getModelVersionId() == null) {
modelInfo.setModelVersionId(networkResource.getModelUUID());
@@ -1681,6 +1742,9 @@ public class ServiceInstances {
}else{
throw new ValidationException("no catalog entry found");
}
+ }else if(action != Action.deleteInstance){
+ throw new ValidationException("modelCustomizationId for networkResourceCustomization lookup", true);
+ }
}else{
//ok for version < 3 and action delete
if(modelName != null){
@@ -1733,6 +1797,7 @@ public class ServiceInstances {
String serviceInstanceId = (instanceIdMap ==null)? null:instanceIdMap.get("serviceInstanceId");
Boolean aLaCarte = null;
String apiVersion = version.substring(1);
+ boolean inProgress = false;
long startTime = System.currentTimeMillis ();
ServiceInstancesRequest sir = null;
@@ -1750,8 +1815,12 @@ public class ServiceInstances {
InfraActiveRequests dup = null;
dup = duplicateCheck(action, instanceIdMap, startTime, msoRequest, instanceName,requestScope, currentActiveReq);
+
+ if(dup != null){
+ inProgress = camundaHistoryCheck(dup, currentActiveReq);
+ }
- if (instanceIdMap != null && dup != null) {
+ if (instanceIdMap != null && dup != null && inProgress) {
buildErrorOnDuplicateRecord(currentActiveReq, action, instanceIdMap, startTime, msoRequest, instanceName, requestScope, dup);
}
@@ -1829,7 +1898,7 @@ public class ServiceInstances {
return postBPELRequest(currentActiveReq, requestClientParameter, orchestrationUri, requestScope);
}
- public String getRequestId(ContainerRequestContext requestContext) throws ValidateException {
+ public String getRequestId(ContainerRequestContext requestContext) throws ValidateException {
String requestId = null;
if (requestContext.getProperty("requestId") != null) {
requestId = requestContext.getProperty("requestId").toString();