2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.common.scripts;
25 import static org.apache.commons.lang3.StringUtils.*;
27 import java.time.chrono.AbstractChronology
29 import java.text.SimpleDateFormat
32 import org.apache.commons.lang3.*
33 import org.camunda.bpm.engine.TaskService
34 import org.camunda.bpm.engine.task.Task
35 import org.camunda.bpm.engine.task.TaskQuery
36 import org.camunda.bpm.engine.delegate.BpmnError
37 import org.camunda.bpm.engine.delegate.DelegateTask
38 import org.camunda.bpm.engine.delegate.DelegateExecution
39 import org.camunda.bpm.engine.delegate.DelegateExecution
40 import org.json.JSONObject;
41 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
42 import org.onap.so.bpmn.common.scripts.ExceptionUtil
43 import org.onap.so.bpmn.core.domain.ServiceDecomposition
44 import org.onap.so.bpmn.core.json.JsonUtils
45 import org.onap.so.client.ruby.*
46 import org.onap.so.logger.MessageEnum
47 import org.onap.so.logger.MsoLogger
48 import org.slf4j.Logger
49 import org.slf4j.LoggerFactory
56 * This groovy class supports the <class>ManualHandling.bpmn</class> process.
61 * @param - msoRequestId
62 * @param - isDebugLogEnabled
63 * @param - serviceType
65 * @param - requestorId
66 * @param - currentActivity
68 * @param - failedActivity
71 * @param - validResponses
75 * @param - WorkflowException
79 public class ManualHandling extends AbstractServiceTaskProcessor {
80 private static final Logger logger = LoggerFactory.getLogger( ManualHandling.class);
84 ExceptionUtil exceptionUtil = new ExceptionUtil()
86 JsonUtils jsonUtils = new JsonUtils()
88 public void preProcessRequest (DelegateExecution execution) {
90 logger.trace("preProcessRequest of ManualHandling ")
93 execution.setVariable("prefix", Prefix)
94 setBasicDBAuthHeader(execution, execution.getVariable('isDebugLogEnabled'))
95 // check for required input
96 String requestId = execution.getVariable("msoRequestId")
97 logger.debug("msoRequestId is: " + requestId)
98 def serviceType = execution.getVariable("serviceType")
99 logger.debug("serviceType is: " + serviceType)
100 def vnfType = execution.getVariable("vnfType")
101 logger.debug("vnftype is: " + vnfType)
102 def currentActivity = execution.getVariable("currentActivity")
103 logger.debug("currentActivity is: " + currentActivity)
104 def workStep = execution.getVariable("workStep")
105 logger.debug("workStep is: " + workStep)
106 def failedActivity = execution.getVariable("failedActivity")
107 logger.debug("failedActivity is: " + failedActivity)
108 def errorCode = execution.getVariable("errorCode")
109 logger.debug("errorCode is: " + errorCode)
110 def errorText = execution.getVariable("errorText")
111 logger.debug("errorText is: " + errorText)
112 def requestorId = execution.getVariable("requestorId")
113 logger.debug("requestorId is: " + requestorId)
114 def validResponses = execution.getVariable("validResponses")
115 logger.debug("validResponses is: " + validResponses)
117 } catch (BpmnError e) {
119 } catch (Exception ex){
120 msg = "Exception in preProcessRequest " + ex.getMessage()
122 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
124 logger.trace("Exit preProcessRequest of RainyDayHandler ")
127 public void createManualTask (DelegateExecution execution) {
129 logger.trace("createManualTask of ManualHandling ")
132 String taskId = UUID.randomUUID()
133 execution.setVariable('taskId', taskId)
134 String type = "fallout"
135 String nfRole = execution.getVariable("vnfType")
136 String subscriptionServiceType = execution.getVariable("serviceType")
137 String originalRequestId = execution.getVariable("msoRequestId")
138 String originalRequestorId = execution.getVariable("requestorId")
139 String errorSource = execution.getVariable("failedActivity")
140 String errorCode = execution.getVariable("errorCode")
141 String errorMessage = execution.getVariable("errorText")
142 String buildingBlockName = execution.getVariable("currentActivity")
143 String buildingBlockStep = execution.getVariable("workStep")
144 String validResponses = execution.getVariable("validResponses")
146 logger.debug("Before creating task")
148 Map<String, String> taskVariables = new HashMap<String, String>()
149 taskVariables.put("type", type)
150 taskVariables.put("nfRole", nfRole)
151 taskVariables.put("subscriptionServiceType", subscriptionServiceType)
152 taskVariables.put("originalRequestId", originalRequestId)
153 taskVariables.put("originalRequestorId", originalRequestorId)
154 taskVariables.put("errorSource", errorSource)
155 taskVariables.put("errorCode", errorCode)
156 taskVariables.put("errorMessage", errorMessage)
157 taskVariables.put("buildingBlockName", buildingBlockName)
158 taskVariables.put("buildingBlockStep", buildingBlockStep)
159 taskVariables.put("validResponses", validResponses)
161 TaskService taskService = execution.getProcessEngineServices().getTaskService()
162 Task manualTask = taskService.newTask(taskId)
163 taskService.saveTask(manualTask)
164 taskService.setVariables(taskId, taskVariables)
165 logger.debug("successfully created task: "+ taskId)
166 } catch (BpmnError e) {
167 logger.debug("BPMN exception: " + e.errorMessage)
169 } catch (Exception ex){
170 msg = "Exception in createManualTask " + ex.getMessage()
172 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
174 logger.trace("Exit createManualTask of ManualHandling ")
177 public void setTaskVariables (DelegateTask task) {
179 DelegateExecution execution = task.getExecution()
182 logger.trace("setTaskVariables of ManualHandling ")
183 String taskId = task.getId()
184 logger.debug("taskId is: " + taskId)
187 execution.setVariable('taskId', taskId)
188 String type = "fallout"
189 String nfRole = execution.getVariable("vnfType")
190 String subscriptionServiceType = execution.getVariable("serviceType")
191 String originalRequestId = execution.getVariable("msoRequestId")
192 String originalRequestorId = execution.getVariable("requestorId")
193 String errorSource = execution.getVariable("failedActivity")
194 String errorCode = execution.getVariable("errorCode")
195 String errorMessage = execution.getVariable("errorText")
196 String buildingBlockName = execution.getVariable("currentActivity")
197 String buildingBlockStep = execution.getVariable("workStep")
198 String validResponses = execution.getVariable("validResponses")
200 logger.debug("Before creating task")
202 Map<String, String> taskVariables = new HashMap<String, String>()
203 taskVariables.put("type", type)
204 taskVariables.put("nfRole", nfRole)
205 taskVariables.put("subscriptionServiceType", subscriptionServiceType)
206 taskVariables.put("originalRequestId", originalRequestId)
207 taskVariables.put("originalRequestorId", originalRequestorId)
208 taskVariables.put("errorSource", errorSource)
209 taskVariables.put("errorCode", errorCode)
210 taskVariables.put("errorMessage", errorMessage)
211 taskVariables.put("buildingBlockName", buildingBlockName)
212 taskVariables.put("buildingBlockStep", buildingBlockStep)
213 taskVariables.put("validResponses", validResponses)
214 TaskService taskService = execution.getProcessEngineServices().getTaskService()
217 taskService.setVariables(taskId, taskVariables)
218 logger.debug("successfully created task: "+ taskId)
219 } catch (BpmnError e) {
220 logger.debug("BPMN exception: " + e.errorMessage)
222 } catch (Exception ex){
223 msg = "Exception in createManualTask " + ex.getMessage()
225 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
227 logger.trace("Exit createManualTask of ManualHandling ")
230 public void completeTask (DelegateTask task) {
232 DelegateExecution execution = task.getExecution()
235 logger.trace("completeTask of ManualHandling ")
236 String taskId = task.getId()
237 logger.debug("taskId is: " + taskId)
240 TaskService taskService = execution.getProcessEngineServices().getTaskService()
242 Map<String, String> taskVariables = taskService.getVariables(taskId)
243 String responseValue = taskVariables.get("responseValue")
245 logger.debug("Received responseValue on completion: "+ responseValue)
246 // Have to set the first letter of the response to upper case
247 String responseValueForRainyDay = responseValue.substring(0, 1).toUpperCase() + responseValue.substring(1)
248 logger.debug("ResponseValue to RainyDayHandler: "+ responseValueForRainyDay)
249 execution.setVariable("responseValue", responseValueForRainyDay)
251 } catch (BpmnError e) {
252 logger.debug("BPMN exception: " + e.errorMessage)
254 } catch (Exception ex){
255 msg = "Exception in createManualTask " + ex.getMessage()
257 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
259 logger.trace("Exit completeTask of ManualHandling ")
262 public void prepareRequestsDBStatusUpdate (DelegateExecution execution, String requestStatus){
264 def method = getClass().getSimpleName() + '.prepareRequestsDBStatusUpdate(' +'execution=' + execution.getId() +')'
265 logger.trace("prepareRequestsDBStatusUpdate of ManualHandling ")
267 def requestId = execution.getVariable("msoRequestId")
269 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.onap.so/requestsdb">
272 <req:updateInfraRequest>
273 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
274 <lastModifiedBy>ManualHandling</lastModifiedBy>
275 <requestStatus>${MsoUtils.xmlEscape(requestStatus)}</requestStatus>
276 </req:updateInfraRequest>
281 execution.setVariable("setUpdateDBstatusPayload", payload)
282 logger.debug("Outgoing Update Mso Request Payload is: " + payload)
283 logger.debug("setUpdateDBstatusPayload: " + payload)
284 } catch (BpmnError e) {
286 } catch (Exception e) {
287 logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
288 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(),
289 MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
290 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
293 logger.trace("Exit prepareRequestsDBStatusUpdate of ManualHandling ")
296 public void createAOTSTicket (DelegateExecution execution) {
298 logger.trace("createAOTSTicket of ManualHandling ")
299 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
300 // This method will not be throwing an exception, but rather log the error
303 execution.setVariable("prefix", Prefix)
304 setBasicDBAuthHeader(execution,isDebugLogEnabled)
305 // check for required input
306 String requestId = execution.getVariable("msoRequestId")
307 logger.debug("requestId is: " + requestId)
308 def currentActivity = execution.getVariable("currentActivity")
309 logger.debug("currentActivity is: " + currentActivity)
310 def workStep = execution.getVariable("workStep")
311 logger.debug("workStep is: " + workStep)
312 def failedActivity = execution.getVariable("failedActivity")
313 logger.debug("failedActivity is: " + failedActivity)
314 def errorCode = execution.getVariable("errorCode")
315 logger.debug("errorCode is: " + errorCode)
316 def errorText = execution.getVariable("errorText")
317 logger.debug("errorText is: " + errorText)
318 def vnfName = execution.getVariable("vnfName")
319 logger.debug("vnfName is: " + vnfName)
321 String rubyRequestId = UUID.randomUUID()
322 logger.debug("rubyRequestId: " + rubyRequestId)
323 String sourceName = vnfName
324 logger.debug("sourceName: " + sourceName)
325 String reason = "VID Workflow failed at " + failedActivity + " " + workStep + " call with error " + errorCode
326 logger.debug("reason: " + reason)
327 String workflowId = requestId
328 logger.debug("workflowId: " + workflowId)
329 String notification = "Request originated from VID | Workflow fallout on " + vnfName + " | Workflow step failure: " + workStep + " failed | VID workflow ID: " + workflowId
330 logger.debug("notification: " + notification)
332 logger.debug("Creating AOTS Ticket request")
334 RubyClient rubyClient = new RubyClient()
335 rubyClient.rubyCreateTicketCheckRequest(rubyRequestId, sourceName, reason, workflowId, notification)
337 } catch (BpmnError e) {
338 msg = "BPMN error in createAOTSTicket " + ex.getMessage()
339 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
340 MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue());
341 } catch (Exception ex){
342 msg = "Exception in createAOTSTicket " + ex.getMessage()
343 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
344 MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue());
346 logger.trace("Exit createAOTSTicket of ManualHandling ")