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
26 import org.apache.commons.lang3.*
\r
27 import org.camunda.bpm.engine.delegate.BpmnError
\r
28 import org.camunda.bpm.engine.runtime.Execution
\r
29 import org.json.JSONObject;
\r
30 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
31 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
32 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
\r
33 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
34 import org.openecomp.mso.client.policy.PolicyDecision
\r
35 import org.openecomp.mso.client.policy.PolicyRestClient
\r
38 import com.att.ecomp.mso.bpmn.core.domain.*
\r
40 import groovy.json.*
\r
43 * This groovy class supports the <class>RainyDayHandler.bpmn</class> process.
\r
48 * @param - msoRequestId
\r
49 * @param - isDebugLogEnabled
\r
50 * @param - serviceType
\r
52 * @param - currentActivity
\r
54 * @param - failedActivity
\r
55 * @param - errorCode
\r
56 * @param - errorText
\r
59 * @param - WorkflowException
\r
60 * @param - handlingCode
\r
63 public class RainyDayHandler extends AbstractServiceTaskProcessor {
\r
65 String Prefix="RDH_"
\r
66 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
68 JsonUtils jsonUtils = new JsonUtils()
\r
70 public void preProcessRequest (Execution execution) {
\r
71 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
\r
73 utils.log("DEBUG"," ***** preProcessRequest of RainyDayHandler *****", isDebugLogEnabled)
\r
76 execution.setVariable("prefix", Prefix)
\r
77 // check for required input
\r
78 String requestId = execution.getVariable("msoRequestId")
\r
79 utils.log("DEBUG", "msoRequestId is: " + requestId, isDebugLogEnabled)
\r
80 def serviceType = execution.getVariable("serviceType")
\r
81 utils.log("DEBUG", "serviceType is: " + serviceType, isDebugLogEnabled)
\r
82 def vnfType = execution.getVariable("vnfType")
\r
83 utils.log("DEBUG", "vnftype is: " + vnfType, isDebugLogEnabled)
\r
84 def currentActivity = execution.getVariable("currentActivity")
\r
85 utils.log("DEBUG", "currentActivity is: " + currentActivity, isDebugLogEnabled)
\r
86 def workStep = execution.getVariable("workStep")
\r
87 utils.log("DEBUG", "workStep is: " + workStep, isDebugLogEnabled)
\r
88 def failedActivity = execution.getVariable("failedActivity")
\r
89 utils.log("DEBUG", "failedActivity is: " + failedActivity, isDebugLogEnabled)
\r
90 def errorCode = execution.getVariable("errorCode")
\r
91 utils.log("DEBUG", "errorCode is: " + errorCode, isDebugLogEnabled)
\r
92 def errorText = execution.getVariable("errorText")
\r
93 utils.log("DEBUG", "errorText is: " + errorText, isDebugLogEnabled)
\r
95 } catch (BpmnError e) {
\r
97 } catch (Exception ex){
\r
98 msg = "Exception in preProcessRequest " + ex.getMessage()
\r
99 utils.log("DEBUG", msg, isDebugLogEnabled)
\r
100 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
102 utils.log("DEBUG"," ***** Exit preProcessRequest of RainyDayHandler *****", isDebugLogEnabled)
\r
105 public void queryPolicy (Execution execution) {
\r
106 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
\r
108 utils.log("DEBUG"," ***** queryPolicy of RainyDayHandler *****", isDebugLogEnabled)
\r
113 String serviceType = execution.getVariable("serviceType")
\r
114 String vnfType = execution.getVariable("vnfType")
\r
116 utils.log("DEBUG", "serviceType: " + serviceType, isDebugLogEnabled)
\r
117 utils.log("DEBUG", "vnfType: " + vnfType, isDebugLogEnabled)
\r
119 def errorCode = execution.getVariable("errorCode")
\r
120 def bbId = execution.getVariable("currentActivity")
\r
121 def workStep = execution.getVariable("workStep")
\r
123 utils.log("DEBUG", "Before querying policy", isDebugLogEnabled)
\r
125 PolicyDecision decisionObject = null
\r
128 PolicyRestClient policyClient = new PolicyRestClient()
\r
129 utils.log("DEBUG", "Created policy client", isDebugLogEnabled)
\r
130 decisionObject = policyClient.getDecision(serviceType, vnfType, bbId, workStep, errorCode)
\r
131 utils.log("DEBUG", "Obtained decision object", isDebugLogEnabled)
\r
132 } catch(Exception e) {
\r
133 msg = "Exception in queryPolicy " + e.getMessage()
\r
134 utils.log("DEBUG", msg, isDebugLogEnabled)
\r
138 String decision = 'DENY'
\r
139 String disposition = "Abort"
\r
140 if (decisionObject != null) {
\r
141 decision = decisionObject.getDecision()
\r
142 disposition = decisionObject.getDetails()
\r
143 utils.log("DEBUG", "Obtained disposition from policy engine: " + disposition, isDebugLogEnabled)
\r
146 disposition = "Manual"
\r
148 if (disposition == null) {
\r
149 disposition = "Manual"
\r
151 execution.setVariable("handlingCode", disposition)
\r
152 execution.setVariable("validResponses", "rollback, abort, skip, retry")
\r
153 utils.log("DEBUG", "Disposition: "+ disposition, isDebugLogEnabled)
\r
155 } catch (BpmnError e) {
\r
156 utils.log("DEBUG", "BPMN exception: " + e.errorMessage, isDebugLogEnabled)
\r
158 } catch (Exception ex){
\r
159 msg = "Exception in queryPolicy " + ex.getMessage()
\r
160 utils.log("DEBUG", msg, isDebugLogEnabled)
\r
161 //exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
163 utils.log("DEBUG"," ***** Exit queryPolicy of RainyDayHandler *****", isDebugLogEnabled)
\r