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.delegate.DelegateExecution
\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.PolicyClient
\r
35 import org.openecomp.mso.client.policy.PolicyClientImpl
\r
36 import org.openecomp.mso.client.policy.entities.DictionaryData
\r
37 import org.openecomp.mso.client.policy.entities.PolicyDecision
\r
38 import org.openecomp.mso.client.policy.entities.Treatments
\r
39 import org.openecomp.mso.client.policy.PolicyRestClient
\r
42 import com.att.ecomp.mso.bpmn.core.domain.*
\r
44 import groovy.json.*
\r
47 * This groovy class supports the <class>RainyDayHandler.bpmn</class> process.
\r
52 * @param - msoRequestId
\r
53 * @param - isDebugLogEnabled
\r
54 * @param - serviceType
\r
56 * @param - currentActivity
\r
58 * @param - failedActivity
\r
59 * @param - errorCode
\r
60 * @param - errorText
\r
64 * @param - WorkflowException
\r
65 * @param - handlingCode
\r
68 public class RainyDayHandler extends AbstractServiceTaskProcessor {
\r
70 String Prefix="RDH_"
\r
71 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
73 JsonUtils jsonUtils = new JsonUtils()
\r
75 public void preProcessRequest (DelegateExecution execution) {
\r
76 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
\r
78 utils.log("DEBUG"," ***** preProcessRequest of RainyDayHandler *****", isDebugLogEnabled)
\r
81 execution.setVariable("prefix", Prefix)
\r
82 // check for required input
\r
83 String requestId = execution.getVariable("msoRequestId")
\r
84 utils.log("DEBUG", "msoRequestId is: " + requestId, isDebugLogEnabled)
\r
85 def serviceType = execution.getVariable("serviceType")
\r
86 utils.log("DEBUG", "serviceType is: " + serviceType, isDebugLogEnabled)
\r
87 def vnfType = execution.getVariable("vnfType")
\r
88 utils.log("DEBUG", "vnftype is: " + vnfType, isDebugLogEnabled)
\r
89 def currentActivity = execution.getVariable("currentActivity")
\r
90 utils.log("DEBUG", "currentActivity is: " + currentActivity, isDebugLogEnabled)
\r
91 def workStep = execution.getVariable("workStep")
\r
92 utils.log("DEBUG", "workStep is: " + workStep, isDebugLogEnabled)
\r
93 def failedActivity = execution.getVariable("failedActivity")
\r
94 utils.log("DEBUG", "failedActivity is: " + failedActivity, isDebugLogEnabled)
\r
95 def errorCode = execution.getVariable("errorCode")
\r
96 utils.log("DEBUG", "errorCode is: " + errorCode, isDebugLogEnabled)
\r
97 def errorText = execution.getVariable("errorText")
\r
98 utils.log("DEBUG", "errorText is: " + errorText, isDebugLogEnabled)
\r
99 String defaultPolicyDisposition = (String) execution.getVariable('URN_policy_default_disposition')
\r
100 utils.log("DEBUG", "defaultPolicyDisposition is: " + defaultPolicyDisposition, isDebugLogEnabled)
\r
101 execution.setVariable('defaultPolicyDisposition', defaultPolicyDisposition)
\r
103 } catch (BpmnError e) {
\r
105 } catch (Exception ex){
\r
106 msg = "Exception in preProcessRequest " + ex.getMessage()
\r
107 utils.log("DEBUG", msg, isDebugLogEnabled)
\r
108 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
110 utils.log("DEBUG"," ***** Exit preProcessRequest of RainyDayHandler *****", isDebugLogEnabled)
\r
113 public void queryPolicy (DelegateExecution execution) {
\r
114 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
\r
116 utils.log("DEBUG"," ***** queryPolicy of RainyDayHandler *****", isDebugLogEnabled)
\r
121 String serviceType = execution.getVariable("serviceType")
\r
122 String vnfType = execution.getVariable("vnfType")
\r
124 utils.log("DEBUG", "serviceType: " + serviceType, isDebugLogEnabled)
\r
125 utils.log("DEBUG", "vnfType: " + vnfType, isDebugLogEnabled)
\r
127 def errorCode = execution.getVariable("errorCode")
\r
128 def bbId = execution.getVariable("currentActivity")
\r
129 def workStep = execution.getVariable("workStep")
\r
131 utils.log("DEBUG", "Before querying policy", isDebugLogEnabled)
\r
133 String decision = 'DENY'
\r
134 String disposition = "Abort"
\r
135 String defaultAllowedTreatments = "rollback, skip, manual, abort"
\r
137 String defaultPolicyDisposition = (String) execution.getVariable('defaultPolicyDisposition')
\r
138 if (defaultPolicyDisposition != null) {
\r
139 utils.log("DEBUG", "Setting disposition to the configured default instead of querying Policy: " + defaultPolicyDisposition, isDebugLogEnabled)
\r
140 disposition = defaultPolicyDisposition
\r
141 utils.log("DEBUG", "Setting default allowed treatments: " + defaultAllowedTreatments, isDebugLogEnabled)
\r
142 execution.setVariable("validResponses", defaultAllowedTreatments)
\r
146 PolicyDecision decisionObject = null
\r
149 PolicyClient policyClient = new PolicyClientImpl()
\r
150 utils.log("DEBUG", "Created policy client", isDebugLogEnabled)
\r
151 decisionObject = policyClient.getDecision(serviceType, vnfType, bbId, workStep, errorCode)
\r
152 utils.log("DEBUG", "Obtained decision object", isDebugLogEnabled)
\r
153 DictionaryData dictClient = policyClient.getAllowedTreatments(bbId, workStep)
\r
154 Treatments treatments = dictClient.getTreatments()
\r
155 String validResponses = treatments.getString()
\r
156 if (validResponses != null) {
\r
157 validResponses = validResponses.toLowerCase()
\r
159 utils.log("DEBUG", "Obtained validResponses: " + validResponses, isDebugLogEnabled)
\r
160 execution.setVariable("validResponses", validResponses)
\r
162 } catch(Exception e) {
\r
163 msg = "Exception in queryPolicy " + e.getMessage()
\r
164 utils.log("DEBUG", msg, isDebugLogEnabled)
\r
168 if (decisionObject != null) {
\r
169 decision = decisionObject.getDecision()
\r
170 disposition = decisionObject.getDetails()
\r
171 utils.log("DEBUG", "Obtained disposition from policy engine: " + disposition, isDebugLogEnabled)
\r
174 disposition = "Abort"
\r
176 if (disposition == null) {
\r
177 disposition = "Abort"
\r
180 execution.setVariable("handlingCode", disposition)
\r
182 utils.log("DEBUG", "Disposition: "+ disposition, isDebugLogEnabled)
\r
184 } catch (BpmnError e) {
\r
185 utils.log("DEBUG", "BPMN exception: " + e.errorMessage, isDebugLogEnabled)
\r
187 } catch (Exception ex){
\r
188 msg = "Exception in queryPolicy " + ex.getMessage()
\r
189 utils.log("DEBUG", msg, isDebugLogEnabled)
\r
190 //exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
192 utils.log("DEBUG"," ***** Exit queryPolicy of RainyDayHandler *****", isDebugLogEnabled)
\r