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 org.camunda.bpm.engine.delegate.BpmnError
\r
23 import org.camunda.bpm.engine.delegate.DelegateExecution;
\r
24 import org.openecomp.mso.bpmn.core.WorkflowException
\r
26 class VnfAdapterUtils {
\r
28 private AbstractServiceTaskProcessor taskProcessor
\r
30 public VnfAdapterUtils(AbstractServiceTaskProcessor taskProcessor) {
\r
31 this.taskProcessor = taskProcessor
\r
34 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
36 public void validateVnfResponse(DelegateExecution execution, String responseVar, String responseCodeVar, String errorResponseVar) {
\r
37 def method = getClass().getSimpleName() + '.validateVnfResponse(' +
\r
38 'execution=' + execution.getId() +
\r
39 ', responseVar=' + responseVar +
\r
40 ', responseCodeVar=' + responseCodeVar +
\r
41 ', errorResponseVar=' + errorResponseVar +
\r
43 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
44 taskProcessor.logDebug('Entered ' + method, isDebugLogEnabled)
\r
47 def prefix = execution.getVariable('prefix')
\r
49 def response = execution.getVariable(responseVar)
\r
50 def responseCode = execution.getVariable(responseCodeVar)
\r
51 def errorResponse = execution.getVariable(errorResponseVar)
\r
53 // The following if statement never appears to be true as any VNF Adapter error seems to be stored in 'errorResponse'.
\r
54 // Also, the value is stored as a WorkflowException object, not a String. Added the else if to provide the proper
\r
55 // functionality but leaving the original code in case it is hit under some circumstances.
\r
56 if (response.contains("WorkflowException")) {
\r
57 execution.setVariable(prefix + "ErrorResponse", response)
\r
58 //execution.setVariable(prefix + "ResponseCode", responseCode)
\r
59 taskProcessor.logDebug(" Sub Vnf flow Error WorkflowException Response - " + "\n" + response, isDebugLogEnabled)
\r
60 throw new BpmnError("MSOWorkflowException")
\r
61 } else if (errorResponse != null && errorResponse instanceof WorkflowException) {
\r
62 // Not sure the variables with the associated prefix are still used
\r
63 execution.setVariable(prefix + "ErrorResponse", errorResponse.getErrorMessage())
\r
64 execution.setVariable(prefix + "ResponseCode", errorResponse.getErrorCode())
\r
65 taskProcessor.logDebug("Sub Vnf flow Error WorkflowException " + prefix + "ErrorResponse" + " - " +
\r
66 errorResponse.getErrorMessage(), isDebugLogEnabled)
\r
67 // this is the important part to ensure we hit the Fallout Handler
\r
68 throw new BpmnError("MSOWorkflowException")
\r
69 } else if (errorResponse != null && errorResponse instanceof WorkflowException) {
\r
70 // Not sure the variables with the associated prefix are still used
\r
71 execution.setVariable(prefix + "ErrorResponse", errorResponse.getErrorMessage())
\r
72 execution.setVariable(prefix + "ResponseCode", errorResponse.getErrorCode())
\r
73 taskProcessor.logDebug("Sub Vnf flow Error WorkflowException " + prefix + "ErrorResponse" + " - " +
\r
74 errorResponse.getErrorMessage(), isDebugLogEnabled)
\r
75 // this is the important part to ensure we hit the Fallout Handler
\r
76 throw new BpmnError("MSOWorkflowException")
\r
78 } catch (BpmnError e) {
\r
80 } catch (Exception e) {
\r
81 taskProcessor.logError('Caught exception in ' + method, e)
\r
82 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, 'Internal Error- Unable to validate VNF Response ' + e.getMessage())
\r