diff options
Diffstat (limited to 'mso-api-handlers')
7 files changed, 70 insertions, 99 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java index 554c794e3e..15572f2b39 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java @@ -216,7 +216,7 @@ public class InstanceManagement { try { recipeLookupResult = getCustomWorkflowUri(workflowUuid); - } catch (IOException e) { + } catch (Exception e) { ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError) .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); @@ -243,7 +243,7 @@ public class InstanceManagement { return recipeLookupResult; } - private RecipeLookupResult getCustomWorkflowUri(String workflowUuid) throws IOException { + private RecipeLookupResult getCustomWorkflowUri(String workflowUuid) { String recipeUri = null; Workflow workflow = catalogDbClient.findWorkflowByArtifactUUID(workflowUuid); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/TasksHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/TasksHandler.java index 7bd7f95286..3c4c90cc37 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/TasksHandler.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/TasksHandler.java @@ -91,7 +91,7 @@ public class TasksHandler { @QueryParam("originalRequestDate") String originalRequestDate, @QueryParam("originalRequestorId") String originalRequestorId, @PathParam("version") String version) throws ApiException { - Response responseBack = null; + String apiVersion = version.substring(1); // Prepare the query string to /task interface @@ -159,60 +159,49 @@ public class TasksHandler { ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError) .build(); + throw new ValidateException.Builder("Mapping of request to JSON object failed : " + e.getMessage(), + HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo) + .build(); - - ValidateException validateException = - new ValidateException.Builder("Mapping of request to JSON object failed : " + e.getMessage(), - HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e) - .errorInfo(errorLoggerInfo).build(); - - throw validateException; } catch (IOException e) { ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, ErrorCode.AvailabilityError) .build(); - BPMNFailureException bpmnFailureException = - new BPMNFailureException.Builder(String.valueOf(HttpStatus.SC_BAD_GATEWAY), - HttpStatus.SC_BAD_GATEWAY, ErrorNumbers.SVC_NO_SERVER_RESOURCES).build(); - throw bpmnFailureException; + throw new BPMNFailureException.Builder(String.valueOf(HttpStatus.SC_BAD_GATEWAY), HttpStatus.SC_BAD_GATEWAY, + ErrorNumbers.SVC_NO_SERVER_RESOURCES).cause(e).errorInfo(errorLoggerInfo).build(); } TasksGetResponse trr = new TasksGetResponse(); List<TaskList> taskList = new ArrayList<>(); ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType()); int bpelStatus = respHandler.getStatus(); - if (bpelStatus == HttpStatus.SC_NO_CONTENT || bpelStatus == HttpStatus.SC_ACCEPTED) { - String respBody = respHandler.getResponseBody(); - if (respBody != null) { - JSONArray data = new JSONArray(respBody); + String respBody = respHandler.getResponseBody(); + if ((bpelStatus == HttpStatus.SC_NO_CONTENT || bpelStatus == HttpStatus.SC_ACCEPTED) && (null != respBody)) { - for (int i = 0; i < data.length(); i++) { - JSONObject taskEntry = data.getJSONObject(i); - String id = taskEntry.getString("id"); - if (taskId != null && !taskId.equals(id)) { - continue; - } - // Get variables info for each task ID - TaskList taskListEntry = null; - taskListEntry = getTaskInfo(id); - - taskList.add(taskListEntry); + JSONArray data = new JSONArray(respBody); + for (int i = 0; i < data.length(); i++) { + JSONObject taskEntry = data.getJSONObject(i); + String id = taskEntry.getString("id"); + if (taskId != null && !taskId.equals(id)) { + continue; } - trr.setTaskList(taskList); + // Get variables info for each task ID + TaskList taskListEntry = null; + taskListEntry = getTaskInfo(id); + + taskList.add(taskListEntry); + } + trr.setTaskList(taskList); } else { ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.BusinessProcesssError) .build(); - - - BPMNFailureException bpmnFailureException = new BPMNFailureException.Builder(String.valueOf(bpelStatus), - bpelStatus, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build(); - - throw bpmnFailureException; + throw new BPMNFailureException.Builder(String.valueOf(bpelStatus), bpelStatus, + ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build(); } String jsonResponse = null; @@ -223,14 +212,10 @@ public class TasksHandler { ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError) .build(); + throw new ValidateException.Builder("Mapping of request to JSON object failed : " + e.getMessage(), + HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo) + .build(); - - ValidateException validateException = - new ValidateException.Builder("Mapping of request to JSON object failed : " + e.getMessage(), - HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e) - .errorInfo(errorLoggerInfo).build(); - - throw validateException; } return builder.buildResponse(HttpStatus.SC_ACCEPTED, "", jsonResponse, apiVersion); @@ -250,10 +235,8 @@ public class TasksHandler { ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, ErrorCode.AvailabilityError) .build(); - BPMNFailureException validateException = - new BPMNFailureException.Builder(String.valueOf(HttpStatus.SC_BAD_GATEWAY), - HttpStatus.SC_BAD_GATEWAY, ErrorNumbers.SVC_NO_SERVER_RESOURCES).build(); - throw validateException; + throw new BPMNFailureException.Builder(String.valueOf(HttpStatus.SC_BAD_GATEWAY), HttpStatus.SC_BAD_GATEWAY, + ErrorNumbers.SVC_NO_SERVER_RESOURCES).cause(e).errorInfo(errorLoggerInfo).build(); } ResponseHandler respHandler = new ResponseHandler(getResponse, requestClient.getType()); int bpelStatus = respHandler.getStatus(); @@ -264,14 +247,10 @@ public class TasksHandler { } else { ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, ErrorCode.AvailabilityError).build(); + throw new BPMNFailureException.Builder(String.valueOf(HttpStatus.SC_BAD_GATEWAY), + HttpStatus.SC_BAD_GATEWAY, ErrorNumbers.SVC_NO_SERVER_RESOURCES).errorInfo(errorLoggerInfo) + .build(); - - - BPMNFailureException bpmnFailureException = - new BPMNFailureException.Builder(String.valueOf(HttpStatus.SC_BAD_GATEWAY), - HttpStatus.SC_BAD_GATEWAY, ErrorNumbers.SVC_NO_SERVER_RESOURCES).build(); - - throw bpmnFailureException; } } else { @@ -279,20 +258,15 @@ public class TasksHandler { new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, ErrorCode.AvailabilityError) .build(); - - - BPMNFailureException bpmnFailureException = new BPMNFailureException.Builder(String.valueOf(bpelStatus), - bpelStatus, ErrorNumbers.SVC_NO_SERVER_RESOURCES).build(); - - - throw bpmnFailureException; + throw new BPMNFailureException.Builder(String.valueOf(bpelStatus), bpelStatus, + ErrorNumbers.SVC_NO_SERVER_RESOURCES).errorInfo(errorLoggerInfo).build(); } return taskList; } - private TaskList buildTaskList(String taskId, String respBody) throws JSONException { + private TaskList buildTaskList(String taskId, String respBody) { TaskList taskList = new TaskList(); JSONObject variables = new JSONObject(respBody); @@ -317,7 +291,7 @@ public class TasksHandler { return taskList; } - private String getOptVariableValue(JSONObject variables, String name) throws JSONException { + private String getOptVariableValue(JSONObject variables, String name) { String variableEntry = variables.optString(name); String value = ""; if (!variableEntry.isEmpty()) { diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandler.java index b5b548a266..e11732ddc4 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandler.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandler.java @@ -23,7 +23,7 @@ package org.onap.so.apihandlerinfra.infra.rest.handler; import java.io.IOException; import java.net.URL; import java.sql.Timestamp; -import java.util.HashMap; +import java.util.Map; import java.util.Optional; import javax.ws.rs.container.ContainerRequestContext; import org.apache.http.HttpStatus; @@ -63,7 +63,7 @@ public abstract class AbstractRestHandler { private static final Logger logger = LoggerFactory.getLogger(AbstractRestHandler.class); - public static final String conflictFailMessage = "Error: Locked instance - This %s (%s) " + public static final String CONFLICT_FAIL_MESSAGE = "Error: Locked instance - This %s (%s) " + "already has a request being worked with a status of %s (RequestId - %s). The existing request must finish or be cleaned up before proceeding."; @@ -95,22 +95,19 @@ public abstract class AbstractRestHandler { ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError) .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); - ValidateException validateException = - new ValidateException.Builder("Request Id " + requestId + " is not a valid UUID", - HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER) - .errorInfo(errorLoggerInfo).build(); - - throw validateException; + throw new ValidateException.Builder("Request Id " + requestId + " is not a valid UUID", + HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo) + .build(); } } - public InfraActiveRequests duplicateCheck(Actions action, HashMap<String, String> instanceIdMap, long startTime, + public InfraActiveRequests duplicateCheck(Actions action, Map<String, String> instanceIdMap, long startTime, MsoRequest msoRequest, String instanceName, String requestScope, InfraActiveRequests currentActiveReq) throws ApiException { return duplicateCheck(action, instanceIdMap, startTime, instanceName, requestScope, currentActiveReq); } - public InfraActiveRequests duplicateCheck(Actions action, HashMap<String, String> instanceIdMap, long startTime, + public InfraActiveRequests duplicateCheck(Actions action, Map<String, String> instanceIdMap, long startTime, String instanceName, String requestScope, InfraActiveRequests currentActiveReq) throws ApiException { InfraActiveRequests dup = null; try { @@ -134,19 +131,19 @@ public abstract class AbstractRestHandler { public void updateStatus(InfraActiveRequests aq, Status status, String errorMessage) throws RequestDbFailureException { - if (aq != null) { - if ((status == Status.FAILED) || (status == Status.COMPLETE)) { - aq.setStatusMessage(errorMessage); - aq.setProgress(100L); - aq.setRequestStatus(status.toString()); - Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis()); - aq.setEndTime(endTimeStamp); - try { - infraActiveRequestsClient.updateInfraActiveRequests(aq); - } catch (Exception e) { - logger.error("Error updating status", e); - } + if ((aq != null) && ((status == Status.FAILED) || (status == Status.COMPLETE))) { + + aq.setStatusMessage(errorMessage); + aq.setProgress(100L); + aq.setRequestStatus(status.toString()); + Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis()); + aq.setEndTime(endTimeStamp); + try { + infraActiveRequestsClient.updateInfraActiveRequests(aq); + } catch (Exception e) { + logger.error("Error updating status", e); } + } } @@ -178,15 +175,15 @@ public abstract class AbstractRestHandler { selfLinkUrl = Optional.of(new URL(aUrl.getProtocol(), aUrl.getHost(), aUrl.getPort(), selfLinkPath)); } catch (Exception e) { selfLinkUrl = Optional.empty(); // ignore - logger.info(e.getMessage()); + logger.error(e.getMessage()); } return selfLinkUrl; } /** - * @param vfmoduleInstanceId + * @param instanceId * @param requestId - * @param response + * @param requestContext */ public ServiceInstancesResponse createResponse(String instanceId, String requestId, ContainerRequestContext requestContext) { @@ -202,13 +199,13 @@ public abstract class AbstractRestHandler { return response; } - public void checkDuplicateRequest(HashMap<String, String> instanceIdMap, ModelType modelType, String instanceName, + public void checkDuplicateRequest(Map<String, String> instanceIdMap, ModelType modelType, String instanceName, String requestId) throws RequestConflictedException { InfraActiveRequests conflictedRequest = infraActiveRequestsClient.checkInstanceNameDuplicate(instanceIdMap, instanceName, modelType.toString()); if (conflictedRequest != null && !conflictedRequest.getRequestId().equals(requestId)) { - throw new RequestConflictedException(String.format(conflictFailMessage, modelType.toString(), instanceName, - conflictedRequest.getRequestStatus(), conflictedRequest.getRequestId())); + throw new RequestConflictedException(String.format(CONFLICT_FAIL_MESSAGE, modelType.toString(), + instanceName, conflictedRequest.getRequestStatus(), conflictedRequest.getRequestId())); } } diff --git a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryCustom.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryCustom.java index 47f8c6b50e..5a8e2e2f6c 100644 --- a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryCustom.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryCustom.java @@ -33,7 +33,7 @@ public interface InfraActiveRequestsRepositoryCustom { public InfraActiveRequests getRequestFromInfraActive(String requestId); - public InfraActiveRequests checkInstanceNameDuplicate(HashMap<String, String> instanceIdMap, String instanceName, + public InfraActiveRequests checkInstanceNameDuplicate(Map<String, String> instanceIdMap, String instanceName, String requestScope); public List<InfraActiveRequests> getOrchestrationFiltersFromInfraActive(Map<String, List<String>> orchestrationMap); diff --git a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java index d8c7c8f971..13ca33c2cf 100644 --- a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java @@ -152,7 +152,7 @@ public class InfraActiveRequestsRepositoryImpl implements InfraActiveRequestsRep * java.lang.String, java.lang.String) */ @Override - public InfraActiveRequests checkInstanceNameDuplicate(final HashMap<String, String> instanceIdMap, + public InfraActiveRequests checkInstanceNameDuplicate(final Map<String, String> instanceIdMap, final String instanceName, final String requestScope) { final List<Predicate> predicates = new LinkedList<>(); diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java index 4d16d9c272..9be92ad93a 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java @@ -217,7 +217,7 @@ public class RequestsDbClient { return restTemplate.exchange(uri, HttpMethod.GET, entity, InfraActiveRequests.class).getBody(); } - public InfraActiveRequests checkInstanceNameDuplicate(HashMap<String, String> instanceIdMap, String instanceName, + public InfraActiveRequests checkInstanceNameDuplicate(Map<String, String> instanceIdMap, String instanceName, String requestScope) { HttpHeaders headers = getHttpHeaders(); URI uri = getUri(checkInstanceNameDuplicate); diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/controller/InstanceNameDuplicateCheckRequest.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/controller/InstanceNameDuplicateCheckRequest.java index 548bc25815..169d2353ec 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/controller/InstanceNameDuplicateCheckRequest.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/controller/InstanceNameDuplicateCheckRequest.java @@ -20,28 +20,28 @@ package org.onap.so.db.request.data.controller; -import java.util.HashMap; +import java.util.Map; public class InstanceNameDuplicateCheckRequest { - private HashMap<String, String> instanceIdMap; + private Map<String, String> instanceIdMap; private String instanceName; private String requestScope; public InstanceNameDuplicateCheckRequest() {} - public InstanceNameDuplicateCheckRequest(HashMap<String, String> instanceIdMap, String instanceName, + public InstanceNameDuplicateCheckRequest(Map<String, String> instanceIdMap, String instanceName, String requestScope) { this.instanceIdMap = instanceIdMap; this.instanceName = instanceName; this.requestScope = requestScope; } - public HashMap<String, String> getInstanceIdMap() { + public Map<String, String> getInstanceIdMap() { return instanceIdMap; } - public void setInstanceIdMap(HashMap<String, String> instanceIdMap) { + public void setInstanceIdMap(Map<String, String> instanceIdMap) { this.instanceIdMap = instanceIdMap; } |