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=========================================================
21 package org.onap.so.bpmn.common.scripts;
23 import static org.apache.commons.lang3.StringUtils.*;
25 import org.apache.commons.lang3.*
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.so.bpmn.core.UrnPropertiesReader;
29 import org.onap.so.bpmn.core.json.JsonUtils
30 import org.onap.so.client.policy.PolicyClient
31 import org.onap.so.client.policy.PolicyClientImpl
32 import org.onap.so.client.policy.entities.DictionaryData
33 import org.onap.so.client.policy.entities.PolicyDecision
34 import org.onap.so.client.policy.entities.Treatments
35 import org.onap.so.logger.MsoLogger
39 * This groovy class supports the <class>RainyDayHandler.bpmn</class> process.
44 * @param - msoRequestId
45 * @param - isDebugLogEnabled
46 * @param - serviceType
48 * @param - currentActivity
50 * @param - failedActivity
56 * @param - WorkflowException
57 * @param - handlingCode
60 public class RainyDayHandler extends AbstractServiceTaskProcessor {
61 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, RainyDayHandler.class);
65 ExceptionUtil exceptionUtil = new ExceptionUtil()
67 JsonUtils jsonUtils = new JsonUtils()
69 public void preProcessRequest (DelegateExecution execution) {
71 msoLogger.trace("preProcessRequest of RainyDayHandler ")
74 execution.setVariable("prefix", Prefix)
75 // check for required input
76 String requestId = execution.getVariable("msoRequestId")
77 msoLogger.debug("msoRequestId is: " + requestId)
78 def serviceType = execution.getVariable("serviceType")
79 msoLogger.debug("serviceType is: " + serviceType)
80 def vnfType = execution.getVariable("vnfType")
81 msoLogger.debug("vnftype is: " + vnfType)
82 def currentActivity = execution.getVariable("currentActivity")
83 msoLogger.debug("currentActivity is: " + currentActivity)
84 def workStep = execution.getVariable("workStep")
85 msoLogger.debug("workStep is: " + workStep)
86 def failedActivity = execution.getVariable("failedActivity")
87 msoLogger.debug("failedActivity is: " + failedActivity)
88 def errorCode = execution.getVariable("errorCode")
89 msoLogger.debug("errorCode is: " + errorCode)
90 def errorText = execution.getVariable("errorText")
91 msoLogger.debug("errorText is: " + errorText)
92 String defaultPolicyDisposition = (String) UrnPropertiesReader.getVariable("policy.default.disposition",execution)
93 msoLogger.debug("defaultPolicyDisposition is: " + defaultPolicyDisposition)
94 execution.setVariable('defaultPolicyDisposition', defaultPolicyDisposition)
96 } catch (BpmnError e) {
98 } catch (Exception ex){
99 msg = "Exception in preProcessRequest " + ex.getMessage()
101 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
103 msoLogger.trace("Exit preProcessRequest of RainyDayHandler ")
106 public void queryPolicy (DelegateExecution execution) {
108 msoLogger.trace("queryPolicy of RainyDayHandler ")
113 String serviceType = execution.getVariable("serviceType")
114 String vnfType = execution.getVariable("vnfType")
116 msoLogger.debug("serviceType: " + serviceType)
117 msoLogger.debug("vnfType: " + vnfType)
119 def errorCode = execution.getVariable("errorCode")
120 def bbId = execution.getVariable("currentActivity")
121 def workStep = execution.getVariable("workStep")
123 msoLogger.debug("Before querying policy")
125 String decision = 'DENY'
126 String disposition = "Abort"
127 String defaultAllowedTreatments = "rollback, skip, manual, abort"
129 String defaultPolicyDisposition = (String) execution.getVariable('defaultPolicyDisposition')
130 if (defaultPolicyDisposition != null && !defaultPolicyDisposition.isEmpty()) {
131 msoLogger.debug("Setting disposition to the configured default instead of querying Policy: " + defaultPolicyDisposition)
132 disposition = defaultPolicyDisposition
133 msoLogger.debug("Setting default allowed treatments: " + defaultAllowedTreatments)
134 execution.setVariable("validResponses", defaultAllowedTreatments)
138 PolicyDecision decisionObject = null
141 PolicyClient policyClient = new PolicyClientImpl()
142 msoLogger.debug("Created policy client")
143 decisionObject = policyClient.getDecision(serviceType, vnfType, bbId, workStep, errorCode)
144 msoLogger.debug("Obtained decision object")
145 DictionaryData dictClient = policyClient.getAllowedTreatments(bbId, workStep)
146 Treatments treatments = dictClient.getTreatments()
147 String validResponses = treatments.getString()
148 if (validResponses != null) {
149 validResponses = validResponses.toLowerCase()
151 msoLogger.debug("Obtained validResponses: " + validResponses)
152 execution.setVariable("validResponses", validResponses)
154 } catch(Exception e) {
155 msg = "Exception in queryPolicy " + e.getMessage()
160 if (decisionObject != null) {
161 decision = decisionObject.getDecision()
162 disposition = decisionObject.getDetails()
163 msoLogger.debug("Obtained disposition from policy engine: " + disposition)
166 disposition = "Abort"
168 if (disposition == null) {
169 disposition = "Abort"
172 execution.setVariable("handlingCode", disposition)
174 msoLogger.debug("Disposition: "+ disposition)
176 } catch (BpmnError e) {
177 msoLogger.debug("BPMN exception: " + e.errorMessage)
179 } catch (Exception ex){
180 msg = "Exception in queryPolicy " + ex.getMessage()
182 //exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
184 msoLogger.trace("Exit queryPolicy of RainyDayHandler ")