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.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.delegate.DelegateExecution;
27 import org.onap.so.bpmn.core.WorkflowException
28 import org.onap.so.logger.MessageEnum
29 import org.onap.so.logger.MsoLogger
30 import org.slf4j.Logger
31 import org.slf4j.LoggerFactory
35 class VnfAdapterUtils {
36 private static final Logger logger = LoggerFactory.getLogger( VnfAdapterUtils.class);
39 private AbstractServiceTaskProcessor taskProcessor
41 public VnfAdapterUtils(AbstractServiceTaskProcessor taskProcessor) {
42 this.taskProcessor = taskProcessor
45 ExceptionUtil exceptionUtil = new ExceptionUtil()
47 public void validateVnfResponse(DelegateExecution execution, String responseVar, String responseCodeVar, String errorResponseVar) {
48 def method = getClass().getSimpleName() + '.validateVnfResponse(' +
49 'execution=' + execution.getId() +
50 ', responseVar=' + responseVar +
51 ', responseCodeVar=' + responseCodeVar +
52 ', errorResponseVar=' + errorResponseVar +
54 logger.trace('Entered ' + method)
57 def prefix = execution.getVariable('prefix')
59 def response = execution.getVariable(responseVar)
60 def responseCode = execution.getVariable(responseCodeVar)
61 def errorResponse = execution.getVariable(errorResponseVar)
63 // The following if statement never appears to be true as any VNF Adapter error seems to be stored in 'errorResponse'.
64 // Also, the value is stored as a WorkflowException object, not a String. Added the else if to provide the proper
65 // functionality but leaving the original code in case it is hit under some circumstances.
66 if (response.contains("WorkflowException")) {
67 execution.setVariable(prefix + "ErrorResponse", response)
68 //execution.setVariable(prefix + "ResponseCode", responseCode)
69 logger.debug(" Sub Vnf flow Error WorkflowException Response - " + "\n" + response)
70 throw new BpmnError("MSOWorkflowException")
71 } else if (errorResponse != null && errorResponse instanceof WorkflowException) {
72 // Not sure the variables with the associated prefix are still used
73 execution.setVariable(prefix + "ErrorResponse", errorResponse.getErrorMessage())
74 execution.setVariable(prefix + "ResponseCode", errorResponse.getErrorCode())
75 logger.debug("Sub Vnf flow Error WorkflowException " + prefix + "ErrorResponse" + " - " + errorResponse.getErrorMessage())
76 // this is the important part to ensure we hit the Fallout Handler
77 throw new BpmnError("MSOWorkflowException")
78 } else if (errorResponse != null && errorResponse instanceof WorkflowException) {
79 // Not sure the variables with the associated prefix are still used
80 execution.setVariable(prefix + "ErrorResponse", errorResponse.getErrorMessage())
81 execution.setVariable(prefix + "ResponseCode", errorResponse.getErrorCode())
82 logger.debug("Sub Vnf flow Error WorkflowException " + prefix + "ErrorResponse" + " - " + errorResponse.getErrorMessage())
83 // this is the important part to ensure we hit the Fallout Handler
84 throw new BpmnError("MSOWorkflowException")
86 } catch (BpmnError e) {
88 } catch (Exception e) {
89 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
90 'Caught exception in ' + method, "BPMN",
91 MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
92 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, 'Internal Error- Unable to validate VNF Response ' + e.getMessage())