2 * © 2016 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property.
4 package org.openecomp.mso.bpmn.vcpe.scripts;
6 import org.openecomp.mso.bpmn.common.scripts.*;
7 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
8 import org.openecomp.mso.bpmn.core.WorkflowException
9 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
10 import org.openecomp.mso.bpmn.common.scripts.MsoUtils
11 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
12 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
13 import org.openecomp.mso.rest.APIResponse
15 import java.util.UUID;
16 import org.camunda.bpm.engine.delegate.BpmnError
17 import org.camunda.bpm.engine.runtime.Execution
18 import org.apache.commons.lang3.*
19 import org.springframework.web.util.UriUtils;
20 import static org.apache.commons.lang3.StringUtils.*
23 * This groovy class supports the <class>DoDeleteAllottedResourceBRG.bpmn</class> process.
28 * @param - msoRequestId
29 * @param - isDebugLogEnabled
30 * @param - disableRollback - O ignored
31 * @param - failNotfound - O
32 * @param - serviceInstanceId
33 * @param - allottedResourceId
36 * @param - rollbackData - N/A
37 * @param - rolledBack - true if no deletions performed
38 * @param - WorkflowException - O
39 * @param - wasDeleted - O (ie not silentSuccess)
42 public class DoDeleteAllottedResourceBRG extends AbstractServiceTaskProcessor{
44 String Prefix="DDARBRG_"
45 ExceptionUtil exceptionUtil = new ExceptionUtil()
47 public void preProcessRequest (Execution execution) {
49 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
51 utils.log("DEBUG"," ***** preProcessRequest *****", isDebugEnabled)
54 execution.setVariable("prefix", Prefix)
57 String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
58 if (isBlank(sdncCallbackUrl)) {
59 msg = "URN_mso_workflow_sdncadapter_callback is null"
60 utils.log("DEBUG", msg, isDebugEnabled)
61 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
63 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
64 utils.log("DEBUG","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)
67 if (isBlank(execution.getVariable("serviceInstanceId"))){
68 msg = "Input serviceInstanceId is null"
69 utils.log("DEBUG", msg, isDebugEnabled)
70 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
72 if (isBlank(execution.getVariable("allottedResourceId"))){
73 msg = "Input allottedResourceId is null"
74 utils.log("DEBUG", msg, isDebugEnabled)
75 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
79 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
81 } catch (Exception ex){
82 msg = "Exception in preProcessRequest " + ex.getMessage()
83 utils.log("DEBUG", msg, isDebugEnabled)
84 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
86 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
89 public void getAaiAR (Execution execution) {
91 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
92 utils.log("DEBUG"," ***** getAaiAR ***** ", isDebugEnabled)
94 String allottedResourceId = execution.getVariable("allottedResourceId")
96 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
97 String ar = arUtils.getARbyId(execution, allottedResourceId)
100 if (isBlank(ar)) // AR was !found
102 errorMsg = "Allotted resource not found in AAI with AllottedResourceId:" + allottedResourceId
106 String aaiARPath = execution.getVariable("aaiARPath")
107 String parentServiceInstanceId = arUtils.getPSIFmARLink(execution, aaiARPath)
108 execution.setVariable("parentServiceInstanceId", parentServiceInstanceId)
110 if (!isBlank(errorMsg)) {
111 utils.log("DEBUG", errorMsg, isDebugEnabled)
112 exceptionUtil.buildAndThrowWorkflowException(execution, 500, errorMsg)
114 utils.log("DEBUG"," ***** getAaiAR *****", isDebugEnabled)
118 // aaiARPath set during query (existing AR)
119 public void updateAaiAROrchStatus(Execution execution, String status){
120 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
121 utils.log("DEBUG", " *** updateAaiAROrchStatus *** ", isDebugEnabled)
122 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
123 String aaiARPath = execution.getVariable("aaiARPath") //set during query (existing AR)
124 String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath)
125 utils.log("DEBUG", " *** Exit updateAaiAROrchStatus *** ", isDebugEnabled)
128 public String buildSDNCRequest(Execution execution, String action, String sdncRequestId) {
130 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
132 utils.log("DEBUG"," ***** buildSDNCRequest *****", isDebugEnabled)
133 String sdncReq = null
137 String allottedResourceId = execution.getVariable("allottedResourceId")
138 String serviceInstanceId = execution.getVariable("serviceInstanceId")
139 String parentServiceInstanceId = execution.getVariable("parentServiceInstanceId")
141 String callbackUrl = execution.getVariable("sdncCallbackUrl")
142 String requestId = execution.getVariable("msoRequestId")
144 String serviceChainServiceInstanceId = ""
145 String sourceNetworkId = ""
146 String sourceNetworkRole = ""
147 String allottedResourceRole = ""
149 String arModelInfo = ""
150 String modelInvariantId = ""
151 String modelVersion = ""
152 String modelUUId = ""
153 String modelCustomizationId = ""
154 String modelName = ""
158 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
159 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
160 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
161 <sdncadapter:RequestHeader>
162 <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId>
163 <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
164 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
165 <sdncadapter:SvcOperation>brg-topology-operation</sdncadapter:SvcOperation>
166 <sdncadapter:CallbackUrl>${callbackUrl}</sdncadapter:CallbackUrl>
167 </sdncadapter:RequestHeader>
168 <sdncadapterworkflow:SDNCRequestData>
169 <request-information>
170 <request-id>${requestId}</request-id>
171 <request-action>DeleteBRGInstance</request-action>
176 </request-information>
177 <service-information>
178 <service-id></service-id>
179 <subscription-service-type></subscription-service-type>
180 <ecomp-model-information></ecomp-model-information>
181 <service-instance-id>${parentServiceInstanceId}</service-instance-id>
183 <global-customer-id></global-customer-id>
184 </service-information>
185 <allotted-resource-information>
186 <allotted-resource-id>${allottedResourceId}</allotted-resource-id>
187 <allotted-resource-type>brg</allotted-resource-type>
188 <parent-service-instance-id>${parentServiceInstanceId}</parent-service-instance-id>
189 <ecomp-model-information>
190 <model-invariant-uuid>${modelInvariantId}</model-invariant-uuid>
191 <model-uuid>${modelUUId}</model-uuid>
192 <model-customization-uuid>${modelCustomizationId}</model-customization-uuid>
193 <model-version>${modelVersion}</model-version>
194 <model-name>${modelName}</model-name>
195 </ecomp-model-information>
196 </allotted-resource-information>
199 </sdncadapterworkflow:SDNCRequestData>
200 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
202 utils.log("DEBUG","sdncRequest:\n" + sdncReq, isDebugEnabled)
203 sdncReq = utils.formatXml(sdncReq)
205 } catch(Exception ex) {
206 msg = "Exception in buildSDNCRequest. " + ex.getMessage()
207 utils.log("DEBUG", msg, isDebugEnabled)
208 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
210 utils.log("DEBUG"," *****Exit buildSDNCRequest *****", isDebugEnabled)
214 public void preProcessSDNCUnassign(Execution execution) {
216 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
218 utils.log("DEBUG"," ***** preProcessSDNCUnassign *****", isDebugEnabled)
221 String sdncRequestId = UUID.randomUUID().toString()
222 String sdncUnassignReq = buildSDNCRequest(execution, "unassign", sdncRequestId)
223 execution.setVariable("sdncUnassignRequest", sdncUnassignReq)
224 utils.logAudit("sdncUnassignRequest: " + sdncUnassignReq)
225 } catch (BpmnError e) {
227 } catch(Exception ex) {
228 msg = "Exception in preProcessSDNCUnassign. " + ex.getMessage()
229 utils.log("DEBUG", msg, isDebugEnabled)
230 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
232 utils.log("DEBUG"," *****Exit preProcessSDNCUnassign *****", isDebugEnabled)
235 public void preProcessSDNCDelete(Execution execution) {
237 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
239 utils.log("DEBUG"," ***** preProcessSDNCDelete *****", isDebugEnabled)
242 String sdncRequestId = UUID.randomUUID().toString()
243 String sdncDeleteReq = buildSDNCRequest(execution, "delete", sdncRequestId)
244 execution.setVariable("sdncDeleteRequest", sdncDeleteReq)
245 utils.logAudit("sdncDeleteReq: " + sdncDeleteReq)
246 } catch (BpmnError e) {
248 } catch(Exception ex) {
249 msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
250 utils.log("DEBUG", msg, isDebugEnabled)
251 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
253 utils.log("DEBUG"," *****Exit preProcessSDNCDelete *****", isDebugEnabled)
256 public void preProcessSDNCDeactivate(Execution execution) {
258 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
260 utils.log("DEBUG"," ***** preProcessSDNCDeactivate *****", isDebugEnabled)
263 String sdncRequestId = UUID.randomUUID().toString()
264 String sdncDeactivateReq = buildSDNCRequest(execution, "deactivate", sdncRequestId)
265 execution.setVariable("sdncDeactivateRequest", sdncDeactivateReq)
266 utils.logAudit("sdncDeactivateReq: " + sdncDeactivateReq)
267 } catch (BpmnError e) {
269 } catch(Exception ex) {
270 msg = "Exception in preProcessSDNCDeactivate. " + ex.getMessage()
271 utils.log("DEBUG", msg, isDebugEnabled)
272 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
274 utils.log("DEBUG"," *****Exit preProcessSDNCDeactivate *****", isDebugEnabled)
277 public void validateSDNCResp(Execution execution, String response, String method){
279 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
280 utils.log("DEBUG", " *** ValidateSDNCResponse Process*** ", isDebugLogEnabled)
284 WorkflowException workflowException = execution.getVariable("WorkflowException")
285 utils.logAudit("workflowException: " + workflowException)
287 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
288 utils.logAudit("SDNCResponse: " + response)
290 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
291 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
293 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
294 utils.log("DEBUG", "Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + response, isDebugLogEnabled)
297 String sdncRespCode = execution.getVariable(Prefix + 'sdncRequestDataResponseCode')
298 utils.log("DEBUG", method + " AllottedResource received error response from SDNC. ResponseCode:" + sdncRespCode, isDebugLogEnabled)
299 if (sdncRespCode.equals("404") && "deactivate".equals(method))
301 execution.setVariable("ARNotFoundInSDNC", true)
302 if ("true".equals(execution.getVariable("failNotFound")))
304 msg = "Allotted Resource Not found in SDNC"
305 utils.log("DEBUG", msg, isDebugEnabled)
306 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
310 execution.setVariable("wasDeleted", false)
315 throw new BpmnError("MSOWorkflowException")
318 } catch (BpmnError e) {
320 } catch(Exception ex) {
321 msg = "Exception in validateSDNCResp. " + ex.getMessage()
322 utils.log("DEBUG", msg, isDebugEnabled)
323 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
325 logDebug(" *** Exit ValidateSDNCResp Process*** ", isDebugLogEnabled)
328 public void deleteAaiAR(Execution execution){
329 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
331 utils.log("DEBUG", " *** deleteAaiAR *** ", isDebugLogEnabled)
332 AllottedResourceUtils arUtils = new AllottedResourceUtils(this)
333 String ar = null //need to get resource-version again
334 String arLink = execution.getVariable("aaiARPath")
335 if (!isBlank(arLink))
337 ar = arUtils.getARbyLink(execution, arLink, "")
339 arUtils.deleteAR(execution, arLink + '?resource-version=' + UriUtils.encode(execution.getVariable("aaiARResourceVersion"),"UTF-8"))
340 } catch (BpmnError e) {
342 }catch(Exception ex){
343 utils.log("ERROR", "Exception Occurred Processing preProcessSDNCGetRequest. Exception is:\n" + ex, isDebugLogEnabled)
344 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during SDNC GET Method:\n" + ex.getMessage())
346 utils.log("DEBUG", " *** Exit deleteAaiAR *** ", isDebugLogEnabled)