2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
20 package org.openecomp.mso.bpmn.common.scripts;
\r
22 import static org.apache.commons.lang3.StringUtils.*;
\r
24 import java.time.chrono.AbstractChronology
\r
25 import java.util.List
\r
26 import java.text.SimpleDateFormat
\r
27 import java.util.Date
\r
29 import org.apache.commons.lang3.*
\r
30 import org.camunda.bpm.engine.TaskService
\r
31 import org.camunda.bpm.engine.task.Task
\r
32 import org.camunda.bpm.engine.task.TaskQuery
\r
33 import org.camunda.bpm.engine.delegate.BpmnError
\r
34 import org.camunda.bpm.engine.delegate.DelegateTask
\r
35 import org.camunda.bpm.engine.delegate.DelegateExecution
\r
36 import org.camunda.bpm.engine.delegate.DelegateExecution
\r
37 import org.json.JSONObject;
\r
38 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
39 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
40 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
\r
41 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
42 import org.openecomp.mso.client.ruby.*
\r
47 * This groovy class supports the <class>ManualHandling.bpmn</class> process.
\r
52 * @param - msoRequestId
\r
53 * @param - isDebugLogEnabled
\r
54 * @param - serviceType
\r
56 * @param - requestorId
\r
57 * @param - currentActivity
\r
59 * @param - failedActivity
\r
60 * @param - errorCode
\r
61 * @param - errorText
\r
62 * @param - validResponses
\r
66 * @param - WorkflowException
\r
70 public class ManualHandling extends AbstractServiceTaskProcessor {
\r
73 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
75 JsonUtils jsonUtils = new JsonUtils()
\r
77 public void preProcessRequest (DelegateExecution execution) {
\r
78 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
\r
80 utils.log("DEBUG"," ***** preProcessRequest of ManualHandling *****", isDebugLogEnabled)
\r
83 execution.setVariable("prefix", Prefix)
\r
84 setBasicDBAuthHeader(execution, isDebugLogEnabled)
\r
85 // check for required input
\r
86 String requestId = execution.getVariable("msoRequestId")
\r
87 utils.log("DEBUG", "msoRequestId is: " + requestId, isDebugLogEnabled)
\r
88 def serviceType = execution.getVariable("serviceType")
\r
89 utils.log("DEBUG", "serviceType is: " + serviceType, isDebugLogEnabled)
\r
90 def vnfType = execution.getVariable("vnfType")
\r
91 utils.log("DEBUG", "vnftype is: " + vnfType, isDebugLogEnabled)
\r
92 def currentActivity = execution.getVariable("currentActivity")
\r
93 utils.log("DEBUG", "currentActivity is: " + currentActivity, isDebugLogEnabled)
\r
94 def workStep = execution.getVariable("workStep")
\r
95 utils.log("DEBUG", "workStep is: " + workStep, isDebugLogEnabled)
\r
96 def failedActivity = execution.getVariable("failedActivity")
\r
97 utils.log("DEBUG", "failedActivity is: " + failedActivity, isDebugLogEnabled)
\r
98 def errorCode = execution.getVariable("errorCode")
\r
99 utils.log("DEBUG", "errorCode is: " + errorCode, isDebugLogEnabled)
\r
100 def errorText = execution.getVariable("errorText")
\r
101 utils.log("DEBUG", "errorText is: " + errorText, isDebugLogEnabled)
\r
102 def requestorId = execution.getVariable("requestorId")
\r
103 utils.log("DEBUG", "requestorId is: " + requestorId, isDebugLogEnabled)
\r
104 def validResponses = execution.getVariable("validResponses")
\r
105 utils.log("DEBUG", "validResponses is: " + validResponses, isDebugLogEnabled)
\r
107 } catch (BpmnError e) {
\r
109 } catch (Exception ex){
\r
110 msg = "Exception in preProcessRequest " + ex.getMessage()
\r
111 utils.log("DEBUG", msg, isDebugLogEnabled)
\r
112 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
114 utils.log("DEBUG"," ***** Exit preProcessRequest of RainyDayHandler *****", isDebugLogEnabled)
\r
117 public void createManualTask (DelegateExecution execution) {
\r
118 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
\r
120 utils.log("DEBUG"," ***** createManualTask of ManualHandling *****", isDebugLogEnabled)
\r
123 String taskId = UUID.randomUUID()
\r
124 execution.setVariable('taskId', taskId)
\r
125 String type = "fallout"
\r
126 String nfRole = execution.getVariable("vnfType")
\r
127 String subscriptionServiceType = execution.getVariable("serviceType")
\r
128 String originalRequestId = execution.getVariable("msoRequestId")
\r
129 String originalRequestorId = execution.getVariable("requestorId")
\r
130 String errorSource = execution.getVariable("failedActivity")
\r
131 String errorCode = execution.getVariable("errorCode")
\r
132 String errorMessage = execution.getVariable("errorText")
\r
133 String buildingBlockName = execution.getVariable("currentActivity")
\r
134 String buildingBlockStep = execution.getVariable("workStep")
\r
135 String validResponses = execution.getVariable("validResponses")
\r
137 utils.log("DEBUG", "Before creating task", isDebugLogEnabled)
\r
139 Map<String, String> taskVariables = new HashMap<String, String>()
\r
140 taskVariables.put("type", type)
\r
141 taskVariables.put("nfRole", nfRole)
\r
142 taskVariables.put("subscriptionServiceType", subscriptionServiceType)
\r
143 taskVariables.put("originalRequestId", originalRequestId)
\r
144 taskVariables.put("originalRequestorId", originalRequestorId)
\r
145 taskVariables.put("errorSource", errorSource)
\r
146 taskVariables.put("errorCode", errorCode)
\r
147 taskVariables.put("errorMessage", errorMessage)
\r
148 taskVariables.put("buildingBlockName", buildingBlockName)
\r
149 taskVariables.put("buildingBlockStep", buildingBlockStep)
\r
150 taskVariables.put("validResponses", validResponses)
\r
152 TaskService taskService = execution.getProcessEngineServices().getTaskService()
\r
153 Task manualTask = taskService.newTask(taskId)
\r
154 taskService.saveTask(manualTask)
\r
155 taskService.setVariables(taskId, taskVariables)
\r
156 utils.log("DEBUG", "successfully created task: "+ taskId, isDebugLogEnabled)
\r
158 } catch (BpmnError e) {
\r
159 utils.log("DEBUG", "BPMN exception: " + e.errorMessage, isDebugLogEnabled)
\r
161 } catch (Exception ex){
\r
162 msg = "Exception in createManualTask " + ex.getMessage()
\r
163 utils.log("DEBUG", msg, isDebugLogEnabled)
\r
164 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
166 utils.log("DEBUG"," ***** Exit createManualTask of ManualHandling *****", isDebugLogEnabled)
\r
169 public void setTaskVariables (DelegateTask task) {
\r
171 DelegateExecution execution = task.getExecution()
\r
173 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
\r
175 utils.log("DEBUG"," ***** setTaskVariables of ManualHandling *****", isDebugLogEnabled)
\r
176 String taskId = task.getId()
\r
177 utils.log("DEBUG", "taskId is: " + taskId, isDebugLogEnabled)
\r
180 execution.setVariable('taskId', taskId)
\r
181 String type = "fallout"
\r
182 String nfRole = execution.getVariable("vnfType")
\r
183 String subscriptionServiceType = execution.getVariable("serviceType")
\r
184 String originalRequestId = execution.getVariable("msoRequestId")
\r
185 String originalRequestorId = execution.getVariable("requestorId")
\r
186 String errorSource = execution.getVariable("failedActivity")
\r
187 String errorCode = execution.getVariable("errorCode")
\r
188 String errorMessage = execution.getVariable("errorText")
\r
189 String buildingBlockName = execution.getVariable("currentActivity")
\r
190 String buildingBlockStep = execution.getVariable("workStep")
\r
191 String validResponses = execution.getVariable("validResponses")
\r
193 utils.log("DEBUG", "Before creating task", isDebugLogEnabled)
\r
195 Map<String, String> taskVariables = new HashMap<String, String>()
\r
196 taskVariables.put("type", type)
\r
197 taskVariables.put("nfRole", nfRole)
\r
198 taskVariables.put("subscriptionServiceType", subscriptionServiceType)
\r
199 taskVariables.put("originalRequestId", originalRequestId)
\r
200 taskVariables.put("originalRequestorId", originalRequestorId)
\r
201 taskVariables.put("errorSource", errorSource)
\r
202 taskVariables.put("errorCode", errorCode)
\r
203 taskVariables.put("errorMessage", errorMessage)
\r
204 taskVariables.put("buildingBlockName", buildingBlockName)
\r
205 taskVariables.put("buildingBlockStep", buildingBlockStep)
\r
206 taskVariables.put("validResponses", validResponses)
\r
207 TaskService taskService = execution.getProcessEngineServices().getTaskService()
\r
210 taskService.setVariables(taskId, taskVariables)
\r
211 utils.log("DEBUG", "successfully created task: "+ taskId, isDebugLogEnabled)
\r
213 } catch (BpmnError e) {
\r
214 utils.log("DEBUG", "BPMN exception: " + e.errorMessage, isDebugLogEnabled)
\r
216 } catch (Exception ex){
\r
217 msg = "Exception in createManualTask " + ex.getMessage()
\r
218 utils.log("DEBUG", msg, isDebugLogEnabled)
\r
219 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
221 utils.log("DEBUG"," ***** Exit createManualTask of ManualHandling *****", isDebugLogEnabled)
\r
224 public void completeTask (DelegateTask task) {
\r
226 DelegateExecution execution = task.getExecution()
\r
228 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
\r
230 utils.log("DEBUG"," ***** completeTask of ManualHandling *****", isDebugLogEnabled)
\r
231 String taskId = task.getId()
\r
232 utils.log("DEBUG", "taskId is: " + taskId, isDebugLogEnabled)
\r
235 TaskService taskService = execution.getProcessEngineServices().getTaskService()
\r
237 Map<String, String> taskVariables = taskService.getVariables(taskId)
\r
238 String responseValue = taskVariables.get("responseValue")
\r
240 utils.log("DEBUG", "Received responseValue on completion: "+ responseValue, isDebugLogEnabled)
\r
241 // Have to set the first letter of the response to upper case
\r
242 String responseValueForRainyDay = responseValue.substring(0, 1).toUpperCase() + responseValue.substring(1)
\r
243 utils.log("DEBUG", "ResponseValue to RainyDayHandler: "+ responseValueForRainyDay, isDebugLogEnabled)
\r
244 execution.setVariable("responseValue", responseValueForRainyDay)
\r
246 } catch (BpmnError e) {
\r
247 utils.log("DEBUG", "BPMN exception: " + e.errorMessage, isDebugLogEnabled)
\r
249 } catch (Exception ex){
\r
250 msg = "Exception in createManualTask " + ex.getMessage()
\r
251 utils.log("DEBUG", msg, isDebugLogEnabled)
\r
252 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
254 utils.log("DEBUG"," ***** Exit completeTask of ManualHandling *****", isDebugLogEnabled)
\r
257 public void prepareRequestsDBStatusUpdate (DelegateExecution execution, String requestStatus){
\r
259 def method = getClass().getSimpleName() + '.prepareRequestsDBStatusUpdate(' +'execution=' + execution.getId() +')'
\r
260 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
261 utils.log("DEBUG"," ***** prepareRequestsDBStatusUpdate of ManualHandling *****", isDebugLogEnabled)
\r
263 def requestId = execution.getVariable("msoRequestId")
\r
264 String payload = """
\r
265 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.openecomp.mso/requestsdb">
\r
268 <req:updateInfraRequest>
\r
269 <requestId>${requestId}</requestId>
\r
270 <lastModifiedBy>ManualHandling</lastModifiedBy>
\r
271 <requestStatus>${requestStatus}</requestStatus>
\r
272 </req:updateInfraRequest>
\r
274 </soapenv:Envelope>
\r
277 execution.setVariable("setUpdateDBstatusPayload", payload)
\r
278 utils.log("DEBUG", "Outgoing Update Mso Request Payload is: " + payload, isDebugLogEnabled)
\r
279 utils.logAudit("setUpdateDBstatusPayload: " + payload)
\r
281 } catch (BpmnError e) {
\r
283 } catch (Exception e) {
\r
284 logError('Caught exception in ' + method, e)
\r
285 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
\r
288 utils.log("DEBUG"," ***** Exit prepareRequestsDBStatusUpdate of ManualHandling *****", isDebugLogEnabled)
\r
291 public void createAOTSTicket (DelegateExecution execution) {
\r
292 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
\r
294 utils.log("DEBUG"," ***** createAOTSTicket of ManualHandling *****", isDebugLogEnabled)
\r
296 // This method will not be throwing an exception, but rather log the error
\r
299 execution.setVariable("prefix", Prefix)
\r
300 setBasicDBAuthHeader(execution, isDebugLogEnabled)
\r
301 // check for required input
\r
302 String requestId = execution.getVariable("msoRequestId")
\r
303 utils.log("DEBUG", "requestId is: " + requestId, isDebugLogEnabled)
\r
304 def currentActivity = execution.getVariable("currentActivity")
\r
305 utils.log("DEBUG", "currentActivity is: " + currentActivity, isDebugLogEnabled)
\r
306 def workStep = execution.getVariable("workStep")
\r
307 utils.log("DEBUG", "workStep is: " + workStep, isDebugLogEnabled)
\r
308 def failedActivity = execution.getVariable("failedActivity")
\r
309 utils.log("DEBUG", "failedActivity is: " + failedActivity, isDebugLogEnabled)
\r
310 def errorCode = execution.getVariable("errorCode")
\r
311 utils.log("DEBUG", "errorCode is: " + errorCode, isDebugLogEnabled)
\r
312 def errorText = execution.getVariable("errorText")
\r
313 utils.log("DEBUG", "errorText is: " + errorText, isDebugLogEnabled)
\r
314 def vnfName = execution.getVariable("vnfName")
\r
315 utils.log("DEBUG", "vnfName is: " + vnfName, isDebugLogEnabled)
\r
317 String rubyRequestId = UUID.randomUUID()
\r
318 utils.log("DEBUG", "rubyRequestId: " + rubyRequestId, isDebugLogEnabled)
\r
319 String sourceName = vnfName
\r
320 utils.log("DEBUG", "sourceName: " + sourceName, isDebugLogEnabled)
\r
321 String reason = "VID Workflow failed at " + failedActivity + " " + workStep + " call with error " + errorCode
\r
322 utils.log("DEBUG", "reason: " + reason, isDebugLogEnabled)
\r
323 String workflowId = requestId
\r
324 utils.log("DEBUG", "workflowId: " + workflowId, isDebugLogEnabled)
\r
325 String notification = "Request originated from VID | Workflow fallout on " + vnfName + " | Workflow step failure: " + workStep + " failed | VID workflow ID: " + workflowId
\r
326 utils.log("DEBUG", "notification: " + notification, isDebugLogEnabled)
\r
328 utils.log("DEBUG", "Creating AOTS Ticket request")
\r
330 RubyClient rubyClient = new RubyClient()
\r
331 rubyClient.rubyCreateTicketCheckRequest(rubyRequestId, sourceName, reason, workflowId, notification)
\r
333 } catch (BpmnError e) {
\r
334 msg = "BPMN error in createAOTSTicket " + ex.getMessage()
\r
335 utils.log("ERROR", msg, isDebugLogEnabled)
\r
336 } catch (Exception ex){
\r
337 msg = "Exception in createAOTSTicket " + ex.getMessage()
\r
338 utils.log("ERROR", msg, isDebugLogEnabled)
\r
340 utils.log("DEBUG"," ***** Exit createAOTSTicket of ManualHandling *****", isDebugLogEnabled)
\r