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=========================================================
20 package org.openecomp.mso.bpmn.infrastructure.scripts;
22 import groovy.xml.XmlUtil
25 import org.openecomp.mso.bpmn.core.json.JsonUtils
26 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
27 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
28 import org.openecomp.mso.bpmn.common.scripts.VidUtils
29 import org.openecomp.mso.bpmn.core.WorkflowException
30 import org.openecomp.mso.rest.APIResponse;
32 import java.util.UUID;
33 import javax.xml.parsers.DocumentBuilder
34 import javax.xml.parsers.DocumentBuilderFactory
36 import org.camunda.bpm.engine.delegate.BpmnError
37 import org.camunda.bpm.engine.runtime.Execution
38 import org.json.JSONObject;
39 import org.apache.commons.lang3.*
40 import org.apache.commons.codec.binary.Base64;
41 import org.w3c.dom.Document
42 import org.w3c.dom.Element
43 import org.w3c.dom.Node
44 import org.w3c.dom.NodeList
45 import org.xml.sax.InputSource
46 import static org.apache.commons.lang3.StringUtils.*;
48 import org.springframework.web.util.UriUtils;
51 * This groovy class supports the <class>DelServiceInstance.bpmn</class> process.
54 public class DelServiceInstance extends AbstractServiceTaskProcessor {
56 String Prefix="DELSI_"
57 ExceptionUtil exceptionUtil = new ExceptionUtil()
58 JsonUtils jsonUtil = new JsonUtils()
59 VidUtils vidUtils = new VidUtils()
61 public void preProcessRequest (Execution execution) {
62 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
63 execution.setVariable("prefix",Prefix)
66 utils.log("DEBUG", " *** preProcessRequest Request *** ", isDebugEnabled)
69 // check for incoming json message/input
70 String siRequest = execution.getVariable("bpmnRequest")
71 utils.logAudit(siRequest)
74 String requestId = execution.getVariable("mso-request-id")
75 execution.setVariable("msoRequestId", requestId)
76 utils.log("DEBUG", "Input Request:" + siRequest + " reqId:" + requestId, isDebugEnabled)
78 String serviceInstanceId = execution.getVariable("serviceInstanceId")
79 if (isBlank(serviceInstanceId)) {
80 msg = "Input serviceInstanceId' is null"
81 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
84 //String xmlRequestDetails = vidUtils.getJsonRequestDetailstoXml(siRequest)
85 //execution.setVariable("requestDetails", xmlRequestDetails)
88 String serviceModelInfo = jsonUtil.getJsonValue(siRequest, "requestDetails.modelInfo")
89 if (isBlank(serviceModelInfo)) {
90 msg = "Input serviceModelInfo is null"
91 utils.log("DEBUG", msg, isDebugEnabled)
94 execution.setVariable("serviceModelInfo", serviceModelInfo)
95 //utils.log("DEBUG", "modelInfo" + serviceModelInfo, isDebugEnabled)
99 String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")
100 if (isBlank(productFamilyId))
102 msg = "Input productFamilyId is null"
103 utils.log("DEBUG", msg, isDebugEnabled)
104 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
106 execution.setVariable("productFamilyId", productFamilyId)
108 String source = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.source")
109 execution.setVariable("source", source)
112 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "requestDetails.subscriberInfo.globalSubscriberId")
113 if (isBlank(globalSubscriberId)) {
114 msg = "Input globalSubscriberId' is null"
115 utils.log("DEBUG", msg, isDebugEnabled)
117 execution.setVariable("globalSubscriberId", globalSubscriberId)
121 String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.subscriptionServiceType")
122 if (isBlank(subscriptionServiceType)) {
123 msg = "Input subscriptionServiceType is null"
124 utils.log("DEBUG", msg, isDebugEnabled)
125 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
127 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
130 } catch (BpmnError e) {
132 } catch (Exception ex){
133 msg = "Exception in preProcessRequest " + ex.getMessage()
134 utils.log("DEBUG", msg, isDebugEnabled)
135 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
137 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
140 public void sendSyncResponse (Execution execution) {
141 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
142 utils.log("DEBUG", " *** sendSyncResponse *** ", isDebugEnabled)
145 String requestId = execution.getVariable("msoRequestId")
146 String serviceInstanceId = execution.getVariable("serviceInstanceId")
148 // RESTResponse (for API Handler (APIH) Reply Task)
149 String syncResponse = """{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
150 utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
151 sendWorkflowResponse(execution, 202, syncResponse)
153 } catch (Exception ex) {
154 String msg = "Exception in sendSyncResponse: " + ex.getMessage()
155 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
157 utils.log("DEBUG"," ***** Exit sendSyncResopnse *****", isDebugEnabled)
160 public void sendSyncError (Execution execution) {
161 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
162 utils.log("DEBUG", " *** sendSyncError *** ", isDebugEnabled)
165 String errorMessage = ""
166 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
167 WorkflowException wfe = execution.getVariable("WorkflowException")
168 errorMessage = wfe.getErrorMessage()
170 errorMessage = "Sending Sync Error."
173 String buildworkflowException =
174 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
175 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
176 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
177 </aetgt:WorkflowException>"""
179 utils.logAudit(buildworkflowException)
180 sendWorkflowResponse(execution, 500, buildworkflowException)
182 } catch (Exception ex) {
183 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
188 public void prepareCompletionRequest (Execution execution) {
189 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
190 utils.log("DEBUG", " *** prepareCompletion *** ", isDebugEnabled)
193 String requestId = execution.getVariable("msoRequestId")
194 String source = execution.getVariable("source")
195 String msoCompletionRequest =
196 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
197 xmlns:ns="http://org.openecomp/mso/request/types/v1">
198 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
199 <request-id>${requestId}</request-id>
200 <action>DELETE</action>
201 <source>${source}</source>
203 <aetgt:status-message>Service Instance was deleted successfully.</aetgt:status-message>
204 <aetgt:mso-bpel-name>DelServiceInstance</aetgt:mso-bpel-name>
205 </aetgt:MsoCompletionRequest>"""
208 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
210 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
211 utils.log("DEBUG", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
213 } catch (Exception ex) {
214 String msg = " Exception in prepareCompletion:" + ex.getMessage()
215 utils.log("DEBUG", msg, isDebugEnabled)
216 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
218 utils.log("DEBUG", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
221 public void prepareFalloutRequest(Execution execution){
222 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
223 utils.log("DEBUG", " *** prepareFalloutRequest *** ", isDebugEnabled)
226 WorkflowException wfex = execution.getVariable("WorkflowException")
227 utils.log("DEBUG", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
228 String requestId = execution.getVariable("msoRequestId")
229 String source = execution.getVariable("source")
231 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
232 <request-id>${requestId}</request-id>
233 <action>DELETE</action>
234 <source>${source}</source>
237 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
238 execution.setVariable("falloutRequest", falloutRequest)
239 } catch (Exception ex) {
240 utils.log("DEBUG", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
241 String errorException = " Bpmn error encountered in CreateServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
242 String requestId = execution.getVariable("msoRequestId")
243 String falloutRequest =
244 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
245 xmlns:ns="http://org.openecomp/mso/request/types/v1"
246 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
247 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
248 <request-id>${requestId}</request-id>
249 <action>DELETE</action>
252 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
253 <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
254 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
255 </aetgt:WorkflowException>
256 </aetgt:FalloutHandlerRequest>"""
258 execution.setVariable("falloutRequest", falloutRequest)
260 utils.log("DEBUG", "*** Exit prepareFalloutRequest ***", isDebugEnabled)
264 // *******************************
265 // Build DB request Section
266 // *******************************
267 public void prepareDBRequest (Execution execution) {
268 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
269 execution.setVariable("prefix", Prefix)
272 utils.log("DEBUG", " ***** Inside prepareDBRequest of DeleteServiceInstance ***** ", isDebugEnabled)
274 String requestId = execution.getVariable("DELSI_requestId")
275 String statusMessage = "Service Instance successfully deleted."
277 //TODO - verify the format for Service Instance Delete,
279 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
282 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
283 <requestId>${requestId}</requestId>
284 <lastModifiedBy>BPMN</lastModifiedBy>
285 <statusMessage>${statusMessage}</statusMessage>
286 <responseBody></responseBody>
287 <requestStatus>COMPLETED</requestStatus>
288 <progress>100</progress>
289 </ns:updateInfraRequest>
291 </soapenv:Envelope>"""
293 String buildDeleteDBRequestAsString = utils.formatXml(dbRequest)
294 execution.setVariable("DELSI_createDBRequest", buildDeleteDBRequestAsString)
295 utils.logAudit(buildDeleteDBRequestAsString)
297 } catch (Exception ex) {
298 // try error in method block
299 String exceptionMessage = "Bpmn error encountered in DeleteServiceInstance flow. Unexpected Error from method prepareDBRequest() - " + ex.getMessage()
300 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
306 // *******************************
307 // Build Error Section
308 // *******************************
309 public void prepareDBRequestError (Execution execution) {
310 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
311 execution.setVariable("prefix", Prefix)
313 utils.log("DEBUG", " ***** Inside prepareDBRequestError of DeleteServiceInstanceInfra ***** ", isDebugEnabled)
316 String requestId = execution.getVariable("DELSI_requestId")
317 String statusMessage = ""
318 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
319 WorkflowException wfe = execution.getVariable("WorkflowException")
320 statusMessage = wfe.getErrorMessage()
323 statusMessage = "Encountered Error during DeleteServiceInstanceInfra proccessing. "
326 //TODO - verify the format for Service Instance Create,
328 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
331 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
332 <requestId>${requestId}</requestId>
333 <lastModifiedBy>BPMN</lastModifiedBy>
334 <statusMessage>${statusMessage}</statusMessage>
335 <responseBody></responseBody>
336 <requestStatus>FAILED</requestStatus>
337 </ns:updateInfraRequest>
339 </soapenv:Envelope>"""
341 String buildDBRequestAsString = utils.formatXml(dbRequest)
342 execution.setVariable("DELSI_createDBInfraErrorRequest", buildDBRequestAsString)
343 utils.logAudit(buildDBRequestAsString)
345 } catch (Exception ex) {
346 // try error in method block
347 String exceptionMessage = "Bpmn error encountered in DeleteServiceInstanceInfra flow. Unexpected Error from method prepareDBRequestError() - " + ex.getMessage()
348 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)