2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
\r
7 * ================================================================================
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
19 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.bpmn.infrastructure.scripts;
\r
23 import groovy.xml.XmlUtil
\r
24 import groovy.json.*
\r
26 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
27 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
28 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
29 import org.openecomp.mso.bpmn.common.scripts.VidUtils
\r
30 import org.openecomp.mso.bpmn.core.WorkflowException
\r
31 import org.openecomp.mso.rest.APIResponse;
\r
33 import java.util.UUID;
\r
34 import javax.xml.parsers.DocumentBuilder
\r
35 import javax.xml.parsers.DocumentBuilderFactory
\r
37 import org.camunda.bpm.engine.delegate.BpmnError
\r
38 import org.camunda.bpm.engine.delegate.DelegateExecution
\r
39 import org.json.JSONObject;
\r
40 import org.apache.commons.lang3.*
\r
41 import org.apache.commons.codec.binary.Base64;
\r
42 import org.w3c.dom.Document
\r
43 import org.w3c.dom.Element
\r
44 import org.w3c.dom.Node
\r
45 import org.w3c.dom.NodeList
\r
46 import org.xml.sax.InputSource
\r
47 import static org.apache.commons.lang3.StringUtils.*;
\r
49 import org.springframework.web.util.UriUtils;
\r
52 * This groovy class supports the <class>DelE2EServiceInstance.bpmn</class> process.
\r
55 public class DeleteCustomE2EServiceInstance extends AbstractServiceTaskProcessor {
\r
57 String Prefix="DELSI_"
\r
58 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
59 JsonUtils jsonUtil = new JsonUtils()
\r
60 VidUtils vidUtils = new VidUtils()
\r
62 public void preProcessRequest (DelegateExecution execution) {
\r
63 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
64 execution.setVariable("prefix",Prefix)
\r
67 utils.log("INFO", " *** preProcessRequest Request *** ", isDebugEnabled)
\r
70 // check for incoming json message/input
\r
71 String siRequest = execution.getVariable("bpmnRequest")
\r
72 utils.logAudit(siRequest)
\r
75 String requestId = execution.getVariable("mso-request-id")
\r
76 execution.setVariable("msoRequestId", requestId)
\r
77 utils.log("INFO", "Input Request:" + siRequest + " reqId:" + requestId, isDebugEnabled)
\r
79 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
80 if (isBlank(serviceInstanceId)) {
\r
81 msg = "Input serviceInstanceId' is null"
\r
82 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
87 // String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")
\r
88 // if (isBlank(productFamilyId))
\r
90 // msg = "Input productFamilyId is null"
\r
91 // utils.log("INFO", msg, isDebugEnabled)
\r
92 // //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
94 // execution.setVariable("productFamilyId", productFamilyId)
\r
96 String source = jsonUtil.getJsonValue(siRequest, "source")
\r
97 execution.setVariable("source", source)
\r
100 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "globalSubscriberId")
\r
101 if (isBlank(globalSubscriberId)) {
\r
102 msg = "Input globalSubscriberId' is null"
\r
103 utils.log("INFO", msg, isDebugEnabled)
\r
105 execution.setVariable("globalSubscriberId", globalSubscriberId)
\r
108 //requestParameters
\r
109 String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "serviceType")
\r
110 if (isBlank(subscriptionServiceType)) {
\r
111 msg = "Input subscriptionServiceType is null"
\r
112 utils.log("DEBUG", msg, isDebugEnabled)
\r
113 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
115 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
\r
118 execution.setVariable("operationType", "DELETE")
\r
119 } catch (BpmnError e) {
\r
121 } catch (Exception ex){
\r
122 msg = "Exception in preProcessRequest " + ex.getMessage()
\r
123 utils.log("INFO", msg, isDebugEnabled)
\r
124 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
126 utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)
\r
129 public void sendSyncResponse (DelegateExecution execution) {
\r
130 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
131 utils.log("INFO", " *** sendSyncResponse *** ", isDebugEnabled)
\r
134 String requestId = execution.getVariable("msoRequestId")
\r
135 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
137 // RESTResponse (for API Handler (APIH) Reply Task)
\r
138 String syncResponse = """{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
\r
139 utils.log("INFO", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
\r
140 sendWorkflowResponse(execution, 202, syncResponse)
\r
142 } catch (Exception ex) {
\r
143 String msg = "Exception in sendSyncResponse: " + ex.getMessage()
\r
144 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
146 utils.log("INFO"," ***** Exit sendSyncResopnse *****", isDebugEnabled)
\r
149 public void sendSyncError (DelegateExecution execution) {
\r
150 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
151 utils.log("INFO", " *** sendSyncError *** ", isDebugEnabled)
\r
154 String errorMessage = ""
\r
155 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
\r
156 WorkflowException wfe = execution.getVariable("WorkflowException")
\r
157 errorMessage = wfe.getErrorMessage()
\r
159 errorMessage = "Sending Sync Error."
\r
162 String buildworkflowException =
\r
163 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
164 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
\r
165 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
166 </aetgt:WorkflowException>"""
\r
168 utils.logAudit(buildworkflowException)
\r
169 sendWorkflowResponse(execution, 500, buildworkflowException)
\r
171 } catch (Exception ex) {
\r
172 utils.log("INFO", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
\r
177 public void prepareCompletionRequest (DelegateExecution execution) {
\r
178 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
179 utils.log("INFO", " *** prepareCompletion *** ", isDebugEnabled)
\r
182 String requestId = execution.getVariable("msoRequestId")
\r
183 String source = execution.getVariable("source")
\r
184 String msoCompletionRequest =
\r
185 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
186 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
187 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
188 <request-id>${requestId}</request-id>
\r
189 <action>DELETE</action>
\r
190 <source>${source}</source>
\r
192 <aetgt:status-message>E2E Service Instance was deleted successfully.</aetgt:status-message>
\r
193 <aetgt:mso-bpel-name>DeleteCustomE2EServiceInstance</aetgt:mso-bpel-name>
\r
194 </aetgt:MsoCompletionRequest>"""
\r
197 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
\r
199 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
\r
200 utils.log("INFO", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
\r
202 } catch (Exception ex) {
\r
203 String msg = " Exception in prepareCompletion:" + ex.getMessage()
\r
204 utils.log("INFO", msg, isDebugEnabled)
\r
205 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
207 utils.log("INFO", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
\r
210 public void prepareFalloutRequest(DelegateExecution execution){
\r
211 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
212 utils.log("INFO", " *** prepareFalloutRequest *** ", isDebugEnabled)
\r
215 WorkflowException wfex = execution.getVariable("WorkflowException")
\r
216 utils.log("INFO", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
\r
217 String requestId = execution.getVariable("msoRequestId")
\r
218 String source = execution.getVariable("source")
\r
219 String requestInfo =
\r
220 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
221 <request-id>${requestId}</request-id>
\r
222 <action>DELETE</action>
\r
223 <source>${source}</source>
\r
226 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
\r
227 execution.setVariable("falloutRequest", falloutRequest)
\r
228 } catch (Exception ex) {
\r
229 utils.log("INFO", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
\r
230 String errorException = " Bpmn error encountered in CreateServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
\r
231 String requestId = execution.getVariable("msoRequestId")
\r
232 String falloutRequest =
\r
233 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
234 xmlns:ns="http://org.openecomp/mso/request/types/v1"
\r
235 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
\r
236 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
237 <request-id>${requestId}</request-id>
\r
238 <action>DELETE</action>
\r
239 <source>VID</source>
\r
241 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
242 <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
\r
243 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
244 </aetgt:WorkflowException>
\r
245 </aetgt:FalloutHandlerRequest>"""
\r
247 execution.setVariable("falloutRequest", falloutRequest)
\r
249 utils.log("INFO", "*** Exit prepareFalloutRequest ***", isDebugEnabled)
\r
253 // *******************************
\r
254 // Build DB request Section
\r
255 // *******************************
\r
256 public void prepareDBRequest (DelegateExecution execution) {
\r
257 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
258 execution.setVariable("prefix", Prefix)
\r
261 utils.log("INFO", " ***** Inside prepareDBRequest of DeleteCustomE2EServiceInstance ***** ", isDebugEnabled)
\r
263 String requestId = execution.getVariable("DELSI_requestId")
\r
264 String statusMessage = "E2E Service Instance successfully deleted."
\r
266 //TODO - verify the format for Service Instance Delete,
\r
268 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
\r
271 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
272 <requestId>${requestId}</requestId>
\r
273 <lastModifiedBy>BPMN</lastModifiedBy>
\r
274 <statusMessage>${statusMessage}</statusMessage>
\r
275 <responseBody></responseBody>
\r
276 <requestStatus>COMPLETED</requestStatus>
\r
277 <progress>100</progress>
\r
278 </ns:updateInfraRequest>
\r
280 </soapenv:Envelope>"""
\r
282 String buildDeleteDBRequestAsString = utils.formatXml(dbRequest)
\r
283 execution.setVariable("DELSI_createDBRequest", buildDeleteDBRequestAsString)
\r
284 utils.logAudit(buildDeleteDBRequestAsString)
\r
286 } catch (Exception ex) {
\r
287 // try error in method block
\r
288 String exceptionMessage = "Bpmn error encountered in DeleteCustomE2EServiceInstance flow. Unexpected Error from method prepareDBRequest() - " + ex.getMessage()
\r
289 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
295 // *******************************
\r
296 // Build Error Section
\r
297 // *******************************
\r
298 public void prepareDBRequestError (DelegateExecution execution) {
\r
299 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
300 execution.setVariable("prefix", Prefix)
\r
302 utils.log("INFO", " ***** Inside prepareDBRequestError of DeleteCustomE2EServiceInstance ***** ", isDebugEnabled)
\r
305 String requestId = execution.getVariable("DELSI_requestId")
\r
306 String statusMessage = ""
\r
307 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
\r
308 WorkflowException wfe = execution.getVariable("WorkflowException")
\r
309 statusMessage = wfe.getErrorMessage()
\r
312 statusMessage = "Encountered Error during DeleteCustomE2EServiceInstance proccessing. "
\r
315 //TODO - verify the format for Service Instance Create,
\r
317 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
\r
320 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
321 <requestId>${requestId}</requestId>
\r
322 <lastModifiedBy>BPMN</lastModifiedBy>
\r
323 <statusMessage>${statusMessage}</statusMessage>
\r
324 <responseBody></responseBody>
\r
325 <requestStatus>FAILED</requestStatus>
\r
326 </ns:updateInfraRequest>
\r
328 </soapenv:Envelope>"""
\r
330 String buildDBRequestAsString = utils.formatXml(dbRequest)
\r
331 execution.setVariable("DELSI_createDBInfraErrorRequest", buildDBRequestAsString)
\r
332 utils.logAudit(buildDBRequestAsString)
\r
334 } catch (Exception ex) {
\r
335 // try error in method block
\r
336 String exceptionMessage = "Bpmn error encountered in DeleteCustomE2EServiceInstance flow. Unexpected Error from method prepareDBRequestError() - " + ex.getMessage()
\r
337 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
\r
343 public void processJavaException(DelegateExecution execution) {
\r