2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.mso.bpmn.common.scripts
22 import org.camunda.bpm.engine.delegate.BpmnError
23 import org.camunda.bpm.engine.runtime.Execution;
24 import org.openecomp.mso.bpmn.core.WorkflowException
26 class VnfAdapterUtils {
28 private AbstractServiceTaskProcessor taskProcessor
30 public VnfAdapterUtils(AbstractServiceTaskProcessor taskProcessor) {
31 this.taskProcessor = taskProcessor
34 ExceptionUtil exceptionUtil = new ExceptionUtil()
36 public void validateVnfResponse(Execution execution, String responseVar, String responseCodeVar, String errorResponseVar) {
37 def method = getClass().getSimpleName() + '.validateVnfResponse(' +
38 'execution=' + execution.getId() +
39 ', responseVar=' + responseVar +
40 ', responseCodeVar=' + responseCodeVar +
41 ', errorResponseVar=' + errorResponseVar +
43 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
44 taskProcessor.logDebug('Entered ' + method, isDebugLogEnabled)
47 def prefix = execution.getVariable('prefix')
49 def response = execution.getVariable(responseVar)
50 def responseCode = execution.getVariable(responseCodeVar)
51 def errorResponse = execution.getVariable(errorResponseVar)
53 // The following if statement never appears to be true as any VNF Adapter error seems to be stored in 'errorResponse'.
54 // Also, the value is stored as a WorkflowException object, not a String. Added the else if to provide the proper
55 // functionality but leaving the original code in case it is hit under some circumstances.
56 if (response.contains("WorkflowException")) {
57 execution.setVariable(prefix + "ErrorResponse", response)
58 //execution.setVariable(prefix + "ResponseCode", responseCode)
59 taskProcessor.logDebug(" Sub Vnf flow Error WorkflowException Response - " + "\n" + response, isDebugLogEnabled)
60 throw new BpmnError("MSOWorkflowException")
61 } else if (errorResponse != null && errorResponse instanceof WorkflowException) {
62 // Not sure the variables with the associated prefix are still used
63 execution.setVariable(prefix + "ErrorResponse", errorResponse.getErrorMessage())
64 execution.setVariable(prefix + "ResponseCode", errorResponse.getErrorCode())
65 taskProcessor.logDebug("Sub Vnf flow Error WorkflowException " + prefix + "ErrorResponse" + " - " +
66 errorResponse.getErrorMessage(), isDebugLogEnabled)
67 // this is the important part to ensure we hit the Fallout Handler
68 throw new BpmnError("MSOWorkflowException")
70 } catch (BpmnError e) {
72 } catch (Exception e) {
73 taskProcessor.logError('Caught exception in ' + method, e)
74 taskProcessor.workflowException(execution, 'Internal Error- Unable to validate VNF Response ' + e.getMessage(), 500)