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 org.onap.so.logger.ErrorCode;
27 import static org.apache.commons.lang3.StringUtils.*;
29 import java.time.chrono.AbstractChronology
31 import java.text.SimpleDateFormat
34 import org.apache.commons.lang3.*
35 import org.camunda.bpm.engine.TaskService
36 import org.camunda.bpm.engine.task.Task
37 import org.camunda.bpm.engine.task.TaskQuery
38 import org.camunda.bpm.engine.delegate.BpmnError
39 import org.camunda.bpm.engine.delegate.DelegateTask
40 import org.camunda.bpm.engine.delegate.DelegateExecution
41 import org.camunda.bpm.engine.delegate.DelegateExecution
42 import org.json.JSONObject;
43 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
44 import org.onap.so.bpmn.common.scripts.ExceptionUtil
45 import org.onap.so.bpmn.core.domain.ServiceDecomposition
46 import org.onap.so.bpmn.core.json.JsonUtils
47 import org.onap.so.client.ruby.*
48 import org.onap.so.logger.MessageEnum
49 import org.slf4j.Logger
50 import org.slf4j.LoggerFactory
57 * This groovy class supports the <class>ManualHandling.bpmn</class> process.
62 * @param - msoRequestId
63 * @param - isDebugLogEnabled
64 * @param - serviceType
66 * @param - requestorId
67 * @param - currentActivity
69 * @param - failedActivity
72 * @param - validResponses
76 * @param - WorkflowException
80 public class ManualHandling extends AbstractServiceTaskProcessor {
81 private static final Logger logger = LoggerFactory.getLogger( ManualHandling.class);
85 ExceptionUtil exceptionUtil = new ExceptionUtil()
87 JsonUtils jsonUtils = new JsonUtils()
89 public void preProcessRequest (DelegateExecution execution) {
91 logger.trace("preProcessRequest of ManualHandling ")
94 execution.setVariable("prefix", Prefix)
95 setBasicDBAuthHeader(execution, execution.getVariable('isDebugLogEnabled'))
96 // check for required input
97 String requestId = execution.getVariable("msoRequestId")
98 logger.debug("msoRequestId is: " + requestId)
99 def serviceType = execution.getVariable("serviceType")
100 logger.debug("serviceType is: " + serviceType)
101 def vnfType = execution.getVariable("vnfType")
102 logger.debug("vnftype is: " + vnfType)
103 def currentActivity = execution.getVariable("currentActivity")
104 logger.debug("currentActivity is: " + currentActivity)
105 def workStep = execution.getVariable("workStep")
106 logger.debug("workStep is: " + workStep)
107 def failedActivity = execution.getVariable("failedActivity")
108 logger.debug("failedActivity is: " + failedActivity)
109 def errorCode = execution.getVariable("errorCode")
110 logger.debug("errorCode is: " + errorCode)
111 def errorText = execution.getVariable("errorText")
112 logger.debug("errorText is: " + errorText)
113 def requestorId = execution.getVariable("requestorId")
114 logger.debug("requestorId is: " + requestorId)
115 def validResponses = execution.getVariable("validResponses")
116 logger.debug("validResponses is: " + validResponses)
118 } catch (BpmnError e) {
120 } catch (Exception ex){
121 msg = "Exception in preProcessRequest " + ex.getMessage()
123 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
125 logger.trace("Exit preProcessRequest of RainyDayHandler ")
128 public void createManualTask (DelegateExecution execution) {
130 logger.trace("createManualTask of ManualHandling ")
133 String taskId = UUID.randomUUID()
134 execution.setVariable('taskId', taskId)
135 String type = "fallout"
136 String nfRole = execution.getVariable("vnfType")
137 String subscriptionServiceType = execution.getVariable("serviceType")
138 String originalRequestId = execution.getVariable("msoRequestId")
139 String originalRequestorId = execution.getVariable("requestorId")
140 String errorSource = execution.getVariable("failedActivity")
141 String errorCode = execution.getVariable("errorCode")
142 String errorMessage = execution.getVariable("errorText")
143 String buildingBlockName = execution.getVariable("currentActivity")
144 String buildingBlockStep = execution.getVariable("workStep")
145 String validResponses = execution.getVariable("validResponses")
147 logger.debug("Before creating task")
149 Map<String, String> taskVariables = new HashMap<String, String>()
150 taskVariables.put("type", type)
151 taskVariables.put("nfRole", nfRole)
152 taskVariables.put("subscriptionServiceType", subscriptionServiceType)
153 taskVariables.put("originalRequestId", originalRequestId)
154 taskVariables.put("originalRequestorId", originalRequestorId)
155 taskVariables.put("errorSource", errorSource)
156 taskVariables.put("errorCode", errorCode)
157 taskVariables.put("errorMessage", errorMessage)
158 taskVariables.put("buildingBlockName", buildingBlockName)
159 taskVariables.put("buildingBlockStep", buildingBlockStep)
160 taskVariables.put("validResponses", validResponses)
161 taskVariables.put("description", "")
162 taskVariables.put("timeout", "")
164 TaskService taskService = execution.getProcessEngineServices().getTaskService()
165 Task manualTask = taskService.newTask(taskId)
166 taskService.saveTask(manualTask)
167 taskService.setVariables(taskId, taskVariables)
168 logger.debug("successfully created task: "+ taskId)
169 } catch (BpmnError e) {
170 logger.debug("BPMN exception: " + e.errorMessage)
172 } catch (Exception ex){
173 msg = "Exception in createManualTask " + ex.getMessage()
175 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
177 logger.trace("Exit createManualTask of ManualHandling ")
180 public void setTaskVariables (DelegateTask task) {
182 DelegateExecution execution = task.getExecution()
185 logger.trace("setTaskVariables of ManualHandling ")
186 String taskId = task.getId()
187 logger.debug("taskId is: " + taskId)
190 execution.setVariable('taskId', taskId)
191 String type = "fallout"
192 String nfRole = execution.getVariable("vnfType")
193 String subscriptionServiceType = execution.getVariable("serviceType")
194 String originalRequestId = execution.getVariable("msoRequestId")
195 String originalRequestorId = execution.getVariable("requestorId")
196 String errorSource = execution.getVariable("failedActivity")
197 String errorCode = execution.getVariable("errorCode")
198 String errorMessage = execution.getVariable("errorText")
199 String buildingBlockName = execution.getVariable("currentActivity")
200 String buildingBlockStep = execution.getVariable("workStep")
201 String validResponses = execution.getVariable("validResponses")
203 logger.debug("Before creating task")
205 Map<String, String> taskVariables = new HashMap<String, String>()
206 taskVariables.put("type", type)
207 taskVariables.put("nfRole", nfRole)
208 taskVariables.put("subscriptionServiceType", subscriptionServiceType)
209 taskVariables.put("originalRequestId", originalRequestId)
210 taskVariables.put("originalRequestorId", originalRequestorId)
211 taskVariables.put("errorSource", errorSource)
212 taskVariables.put("errorCode", errorCode)
213 taskVariables.put("errorMessage", errorMessage)
214 taskVariables.put("buildingBlockName", buildingBlockName)
215 taskVariables.put("buildingBlockStep", buildingBlockStep)
216 taskVariables.put("validResponses", validResponses)
217 taskVariables.put("description", "")
218 taskVariables.put("timeout", "")
219 TaskService taskService = execution.getProcessEngineServices().getTaskService()
222 taskService.setVariables(taskId, taskVariables)
223 logger.debug("successfully created task: "+ taskId)
224 } catch (BpmnError e) {
225 logger.debug("BPMN exception: " + e.errorMessage)
227 } catch (Exception ex){
228 msg = "Exception in createManualTask " + ex.getMessage()
230 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
232 logger.trace("Exit createManualTask of ManualHandling ")
235 public void completeTask (DelegateTask task) {
237 DelegateExecution execution = task.getExecution()
240 logger.trace("completeTask of ManualHandling ")
241 String taskId = task.getId()
242 logger.debug("taskId is: " + taskId)
245 TaskService taskService = execution.getProcessEngineServices().getTaskService()
247 Map<String, String> taskVariables = taskService.getVariables(taskId)
248 String responseValue = taskVariables.get("responseValue")
250 logger.debug("Received responseValue on completion: "+ responseValue)
251 // Have to set the first letter of the response to upper case
252 String responseValueForRainyDay = responseValue.substring(0, 1).toUpperCase() + responseValue.substring(1)
253 logger.debug("ResponseValue to RainyDayHandler: "+ responseValueForRainyDay)
254 execution.setVariable("responseValue", responseValueForRainyDay)
256 } catch (BpmnError e) {
257 logger.debug("BPMN exception: " + e.errorMessage)
259 } catch (Exception ex){
260 msg = "Exception in createManualTask " + ex.getMessage()
262 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
264 logger.trace("Exit completeTask of ManualHandling ")
267 public void prepareRequestsDBStatusUpdate (DelegateExecution execution, String requestStatus){
269 def method = getClass().getSimpleName() + '.prepareRequestsDBStatusUpdate(' +'execution=' + execution.getId() +')'
270 logger.trace("prepareRequestsDBStatusUpdate of ManualHandling ")
272 def requestId = execution.getVariable("msoRequestId")
274 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.onap.so/requestsdb">
277 <req:updateInfraRequest>
278 <requestId>${MsoUtils.xmlEscape(requestId)}</requestId>
279 <lastModifiedBy>ManualHandling</lastModifiedBy>
280 <requestStatus>${MsoUtils.xmlEscape(requestStatus)}</requestStatus>
281 </req:updateInfraRequest>
286 execution.setVariable("setUpdateDBstatusPayload", payload)
287 logger.debug("Outgoing Update Mso Request Payload is: " + payload)
288 logger.debug("setUpdateDBstatusPayload: " + payload)
289 } catch (BpmnError e) {
291 } catch (Exception e) {
292 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
293 'Caught exception in ' + method, "BPMN",
294 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
295 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
298 logger.trace("Exit prepareRequestsDBStatusUpdate of ManualHandling ")
301 public void createAOTSTicket (DelegateExecution execution) {
303 logger.trace("createAOTSTicket of ManualHandling ")
304 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
305 // This method will not be throwing an exception, but rather log the error
308 execution.setVariable("prefix", Prefix)
309 setBasicDBAuthHeader(execution,isDebugLogEnabled)
310 // check for required input
311 String requestId = execution.getVariable("msoRequestId")
312 logger.debug("requestId is: " + requestId)
313 def currentActivity = execution.getVariable("currentActivity")
314 logger.debug("currentActivity is: " + currentActivity)
315 def workStep = execution.getVariable("workStep")
316 logger.debug("workStep is: " + workStep)
317 def failedActivity = execution.getVariable("failedActivity")
318 logger.debug("failedActivity is: " + failedActivity)
319 def errorCode = execution.getVariable("errorCode")
320 logger.debug("errorCode is: " + errorCode)
321 def errorText = execution.getVariable("errorText")
322 logger.debug("errorText is: " + errorText)
323 def vnfName = execution.getVariable("vnfName")
324 logger.debug("vnfName is: " + vnfName)
326 String rubyRequestId = UUID.randomUUID()
327 logger.debug("rubyRequestId: " + rubyRequestId)
328 String sourceName = vnfName
329 logger.debug("sourceName: " + sourceName)
330 String reason = "VID Workflow failed at " + failedActivity + " " + workStep + " call with error " + errorCode
331 logger.debug("reason: " + reason)
332 String workflowId = requestId
333 logger.debug("workflowId: " + workflowId)
334 String notification = "Request originated from VID | Workflow fallout on " + vnfName + " | Workflow step failure: " + workStep + " failed | VID workflow ID: " + workflowId
335 logger.debug("notification: " + notification)
337 logger.debug("Creating AOTS Ticket request")
339 RubyClient rubyClient = new RubyClient()
340 rubyClient.rubyCreateTicketCheckRequest(rubyRequestId, sourceName, reason, workflowId, notification)
342 } catch (BpmnError e) {
343 msg = "BPMN error in createAOTSTicket " + ex.getMessage()
344 logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
345 ErrorCode.UnknownError.getValue());
346 } catch (Exception ex){
347 msg = "Exception in createAOTSTicket " + ex.getMessage()
348 logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
349 ErrorCode.UnknownError.getValue());
351 logger.trace("Exit createAOTSTicket of ManualHandling ")