From 62cd6aaaf74aa91ee0037c0e155c8e7284f07567 Mon Sep 17 00:00:00 2001 From: Arthur Martella Date: Fri, 8 Sep 2017 13:27:46 -0400 Subject: 1710 Rebase - Second Attempt This commit rebases changes from openecomp-mso/internal-staging-1710 up to and including this codecloud commit: 54483fc6606ddb1591a2e9da61bff8712325f924 Wed Sep 6 18:12:56 2017 -0400 Rebasing was done on a branch on top of this commit in so/master in ONAP: 93fbdfbe46104f8859d4754040f979cb7997c157 Thu Sep 7 16:42:59 2017 +0000 Change-Id: I4ad9abf40da32bf5bdca43e868b8fa2dbcd9dc59 Issue-id: SO-107 Signed-off-by: Arthur Martella --- .../mso/apihandlerinfra/TasksHandler.java | 328 +++++++++++++++++++++ 1 file changed, 328 insertions(+) create mode 100644 mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/TasksHandler.java (limited to 'mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/TasksHandler.java') diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/TasksHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/TasksHandler.java new file mode 100644 index 0000000000..b191a3d767 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/TasksHandler.java @@ -0,0 +1,328 @@ +/*- + * #%L + * MSO + * %% + * Copyright (C) 2016 OPENECOMP - MSO + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +package org.openecomp.mso.apihandlerinfra; + +import org.openecomp.mso.apihandlerinfra.tasksbeans.*; + +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; + +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.json.JSONArray; +import org.json.JSONObject; +import org.codehaus.jackson.map.ObjectMapper; + +import org.openecomp.mso.apihandler.common.ErrorNumbers; +import org.openecomp.mso.apihandler.common.RequestClient; +import org.openecomp.mso.apihandler.common.RequestClientFactory; +import org.openecomp.mso.apihandler.common.ResponseHandler; +import org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.logger.MsoAlarmLogger; +import org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.utils.UUIDChecker; + +import com.wordnik.swagger.annotations.Api; +import com.wordnik.swagger.annotations.ApiOperation; + +@Path("/tasks") +@Api(value="/tasks/{version: [vV]1}",description="Queries of Manual Tasks") +public class TasksHandler { + + private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger (); + private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH); + public final static String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA"; + public final static String requestUrl = "mso/task/"; + + @Path("/{version:[vV]1}") + @GET + @ApiOperation(value="Finds Manual Tasks",response=Response.class) + public Response queryFilters (@QueryParam("taskId") String taskId, + @QueryParam("originalRequestId") String originalRequestId, + @QueryParam("subscriptionServiceType") String subscriptionServiceType, + @QueryParam("nfRole") String nfRole, + @QueryParam("buildingBlockName") String buildingBlockName, + @QueryParam("originalRequestDate") String originalRequestDate, + @QueryParam("originalRequestorId") String originalRequestorId, + @PathParam("version") String version) { + Response responseBack = null; + long startTime = System.currentTimeMillis (); + String requestId = UUIDChecker.generateUUID(msoLogger); + MsoLogger.setServiceName ("ManualTasksQuery"); + // Generate a Request Id + UUIDChecker.generateUUID(msoLogger); + msoLogger.debug ("Incoming request received for queryFilter with taskId:" + taskId + + " originalRequestId:" + originalRequestId + + " subscriptionServiceType:" + subscriptionServiceType + + " nfRole:" + nfRole + + " buildingBlockName:" + buildingBlockName + + " originalRequestDate:" + originalRequestDate + + " originalRequestorId: " + originalRequestorId); + + // Prepare the query string to /task interface + TaskVariables tv = new TaskVariables(); + + List tvvList = new ArrayList(); + + if (originalRequestId != null) { + TaskVariableValue tvv = new TaskVariableValue(); + tvv.setName("originalRequestId"); + tvv.setValue(originalRequestId); + tvv.setOperator("eq"); + tvvList.add(tvv); + } + if (subscriptionServiceType != null) { + TaskVariableValue tvv = new TaskVariableValue(); + tvv.setName("subscriptionServiceType"); + tvv.setValue(subscriptionServiceType); + tvv.setOperator("eq"); + tvvList.add(tvv); + } + if (nfRole != null) { + TaskVariableValue tvv = new TaskVariableValue(); + tvv.setName("nfRole"); + tvv.setValue(nfRole); + tvv.setOperator("eq"); + tvvList.add(tvv); + } + if (buildingBlockName != null) { + TaskVariableValue tvv = new TaskVariableValue(); + tvv.setName("buildingBlockName"); + tvv.setValue(buildingBlockName); + tvv.setOperator("eq"); + tvvList.add(tvv); + } + if (originalRequestDate != null) { + TaskVariableValue tvv = new TaskVariableValue(); + tvv.setName("originalRequestDate"); + tvv.setValue(originalRequestDate); + tvv.setOperator("eq"); + tvvList.add(tvv); + } + if (originalRequestorId != null) { + TaskVariableValue tvv = new TaskVariableValue(); + tvv.setName("originalRequestorId"); + tvv.setValue(originalRequestorId); + tvv.setOperator("eq"); + tvvList.add(tvv); + } + + tv.setTaskVariables(tvvList); + + RequestClient requestClient = null; + MsoRequest msoRequest = new MsoRequest(requestId); + HttpResponse response = null; + long subStartTime = System.currentTimeMillis(); + + try { + requestClient = RequestClientFactory.getRequestClient (requestUrl, MsoPropertiesUtils.loadMsoProperties ()); + // Capture audit event + msoLogger.debug ("MSO API Handler Post call to Camunda engine for url: " + requestClient.getUrl ()); + + System.out.println("URL : " + requestClient.getUrl ()); + ObjectMapper mapper = new ObjectMapper(); + String camundaJsonReq = mapper.writeValueAsString(tv); + msoLogger.debug("Camunda Json Request: " + camundaJsonReq); + response = requestClient.post(camundaJsonReq); + + msoLogger.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from BPMN engine", "BPMN", requestUrl, null); + } catch (Exception e) { + msoLogger.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine", "BPMN", requestUrl, null); + msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED); + Response resp = msoRequest.buildServiceErrorResponse (HttpStatus.SC_BAD_GATEWAY, + MsoException.ServiceException, + "Failed calling bpmn " + e.getMessage (), + ErrorNumbers.SVC_NO_SERVER_RESOURCES, + null); + alarmLogger.sendAlarm ("MsoConfigurationError", + MsoAlarmLogger.CRITICAL, + Messages.errors.get (ErrorNumbers.NO_COMMUNICATION_TO_BPEL)); + msoRequest.updateFinalStatus (Status.FAILED); + msoLogger.error (MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", 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, the final response is: " + (String) resp.getEntity ()); + return resp; + } + TasksGetResponse trr = new TasksGetResponse(); + List taskList = new ArrayList(); + + ResponseHandler respHandler = new ResponseHandler (response, requestClient.getType ()); + int bpelStatus = respHandler.getStatus (); + if (bpelStatus == HttpStatus.SC_NO_CONTENT || bpelStatus == HttpStatus.SC_ACCEPTED) { + msoLogger.debug ("Received good response from Camunda"); + + msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "BPMN completed the request"); + String respBody = respHandler.getResponseBody(); + if (respBody != null) { + JSONArray data = new JSONArray(respBody); + + for (int i=0; i