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
117 String operationId = jsonUtil.getJsonValue(siRequest, "operationId")
\r
118 execution.setVariable("operationId", operationId)
\r
120 execution.setVariable("operationType", "DELETE")
\r
121 } catch (BpmnError e) {
\r
123 } catch (Exception ex){
\r
124 msg = "Exception in preProcessRequest " + ex.getMessage()
\r
125 utils.log("INFO", msg, isDebugEnabled)
\r
126 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
128 utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)
\r
131 public void sendSyncResponse (DelegateExecution execution) {
\r
132 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
133 utils.log("INFO", " *** sendSyncResponse *** ", isDebugEnabled)
\r
135 String operationId = execution.getVariable("operationId")
\r
136 String syncResponse = """{"operationId":"${operationId}"}""".trim()
\r
137 utils.log("INFO", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
\r
138 sendWorkflowResponse(execution, 202, syncResponse)
\r
140 } catch (Exception ex) {
\r
141 String msg = "Exception in sendSyncResponse: " + ex.getMessage()
\r
142 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
144 utils.log("INFO"," ***** Exit sendSyncResopnse *****", isDebugEnabled)
\r
147 public void sendSyncError (DelegateExecution execution) {
\r
148 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
149 utils.log("INFO", " *** sendSyncError *** ", isDebugEnabled)
\r
152 String errorMessage = ""
\r
153 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
\r
154 WorkflowException wfe = execution.getVariable("WorkflowException")
\r
155 errorMessage = wfe.getErrorMessage()
\r
157 errorMessage = "Sending Sync Error."
\r
160 String buildworkflowException =
\r
161 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
162 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
\r
163 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
164 </aetgt:WorkflowException>"""
\r
166 utils.logAudit(buildworkflowException)
\r
167 sendWorkflowResponse(execution, 500, buildworkflowException)
\r
169 } catch (Exception ex) {
\r
170 utils.log("INFO", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
\r
175 public void prepareCompletionRequest (DelegateExecution execution) {
\r
176 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
177 utils.log("INFO", " *** prepareCompletion *** ", isDebugEnabled)
\r
180 String requestId = execution.getVariable("msoRequestId")
\r
181 String source = execution.getVariable("source")
\r
182 String msoCompletionRequest =
\r
183 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
184 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
185 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
186 <request-id>${requestId}</request-id>
\r
187 <action>DELETE</action>
\r
188 <source>${source}</source>
\r
190 <aetgt:status-message>E2E Service Instance was deleted successfully.</aetgt:status-message>
\r
191 <aetgt:mso-bpel-name>DeleteCustomE2EServiceInstance</aetgt:mso-bpel-name>
\r
192 </aetgt:MsoCompletionRequest>"""
\r
195 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
\r
197 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
\r
198 utils.log("INFO", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
\r
200 } catch (Exception ex) {
\r
201 String msg = " Exception in prepareCompletion:" + ex.getMessage()
\r
202 utils.log("INFO", msg, isDebugEnabled)
\r
203 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
205 utils.log("INFO", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
\r
208 public void prepareFalloutRequest(DelegateExecution execution){
\r
209 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
210 utils.log("INFO", " *** prepareFalloutRequest *** ", isDebugEnabled)
\r
213 WorkflowException wfex = execution.getVariable("WorkflowException")
\r
214 utils.log("INFO", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
\r
215 String requestId = execution.getVariable("msoRequestId")
\r
216 String source = execution.getVariable("source")
\r
217 String requestInfo =
\r
218 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
219 <request-id>${requestId}</request-id>
\r
220 <action>DELETE</action>
\r
221 <source>${source}</source>
\r
224 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
\r
225 execution.setVariable("falloutRequest", falloutRequest)
\r
226 } catch (Exception ex) {
\r
227 utils.log("INFO", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
\r
228 String errorException = " Bpmn error encountered in CreateServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
\r
229 String requestId = execution.getVariable("msoRequestId")
\r
230 String falloutRequest =
\r
231 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
232 xmlns:ns="http://org.openecomp/mso/request/types/v1"
\r
233 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
\r
234 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
235 <request-id>${requestId}</request-id>
\r
236 <action>DELETE</action>
\r
237 <source>VID</source>
\r
239 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
240 <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
\r
241 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
242 </aetgt:WorkflowException>
\r
243 </aetgt:FalloutHandlerRequest>"""
\r
245 execution.setVariable("falloutRequest", falloutRequest)
\r
247 utils.log("INFO", "*** Exit prepareFalloutRequest ***", isDebugEnabled)
\r
251 // *******************************
\r
252 // Build DB request Section
\r
253 // *******************************
\r
254 public void prepareDBRequest (DelegateExecution execution) {
\r
255 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
256 execution.setVariable("prefix", Prefix)
\r
259 utils.log("INFO", " ***** Inside prepareDBRequest of DeleteCustomE2EServiceInstance ***** ", isDebugEnabled)
\r
261 String requestId = execution.getVariable("DELSI_requestId")
\r
262 String statusMessage = "E2E Service Instance successfully deleted."
\r
264 //TODO - verify the format for Service Instance Delete,
\r
266 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
\r
269 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
270 <requestId>${requestId}</requestId>
\r
271 <lastModifiedBy>BPMN</lastModifiedBy>
\r
272 <statusMessage>${statusMessage}</statusMessage>
\r
273 <responseBody></responseBody>
\r
274 <requestStatus>COMPLETED</requestStatus>
\r
275 <progress>100</progress>
\r
276 </ns:updateInfraRequest>
\r
278 </soapenv:Envelope>"""
\r
280 String buildDeleteDBRequestAsString = utils.formatXml(dbRequest)
\r
281 execution.setVariable("DELSI_createDBRequest", buildDeleteDBRequestAsString)
\r
282 utils.logAudit(buildDeleteDBRequestAsString)
\r
284 } catch (Exception ex) {
\r
285 // try error in method block
\r
286 String exceptionMessage = "Bpmn error encountered in DeleteCustomE2EServiceInstance flow. Unexpected Error from method prepareDBRequest() - " + ex.getMessage()
\r
287 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
293 // *******************************
\r
294 // Build Error Section
\r
295 // *******************************
\r
296 public void prepareDBRequestError (DelegateExecution execution) {
\r
297 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
298 execution.setVariable("prefix", Prefix)
\r
300 utils.log("INFO", " ***** Inside prepareDBRequestError of DeleteCustomE2EServiceInstance ***** ", isDebugEnabled)
\r
303 String requestId = execution.getVariable("DELSI_requestId")
\r
304 String statusMessage = ""
\r
305 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
\r
306 WorkflowException wfe = execution.getVariable("WorkflowException")
\r
307 statusMessage = wfe.getErrorMessage()
\r
310 statusMessage = "Encountered Error during DeleteCustomE2EServiceInstance proccessing. "
\r
313 //TODO - verify the format for Service Instance Create,
\r
315 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
\r
318 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
319 <requestId>${requestId}</requestId>
\r
320 <lastModifiedBy>BPMN</lastModifiedBy>
\r
321 <statusMessage>${statusMessage}</statusMessage>
\r
322 <responseBody></responseBody>
\r
323 <requestStatus>FAILED</requestStatus>
\r
324 </ns:updateInfraRequest>
\r
326 </soapenv:Envelope>"""
\r
328 String buildDBRequestAsString = utils.formatXml(dbRequest)
\r
329 execution.setVariable("DELSI_createDBInfraErrorRequest", buildDBRequestAsString)
\r
330 utils.logAudit(buildDBRequestAsString)
\r
332 } catch (Exception ex) {
\r
333 // try error in method block
\r
334 String exceptionMessage = "Bpmn error encountered in DeleteCustomE2EServiceInstance flow. Unexpected Error from method prepareDBRequestError() - " + ex.getMessage()
\r
335 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
\r
341 public void processJavaException(DelegateExecution execution) {
\r
346 * Init the service Operation Status
\r
348 public void prepareInitServiceOperationStatus(DelegateExecution execution){
\r
349 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
350 utils.log("DEBUG", " ======== STARTED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)
\r
352 String serviceId = execution.getVariable("serviceInstanceId")
\r
353 String operationId = execution.getVariable("operationId")
\r
355 String result = "processing"
\r
356 String progress = "0"
\r
358 String operationContent = "Prepare service creation"
\r
359 utils.log("DEBUG", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId, isDebugEnabled)
\r
360 serviceId = UriUtils.encode(serviceId,"UTF-8")
\r
362 def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
\r
363 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
\r
364 utils.log("DEBUG", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
\r
367 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
\r
368 xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
371 <ns:updateServiceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
372 <serviceId>${serviceId}</serviceId>
\r
373 <operationId>${operationId}</operationId>
\r
374 <operationType>DELETE</operationType>
\r
375 <userId>${userId}</userId>
\r
376 <result>${result}</result>
\r
377 <operationContent>${operationContent}</operationContent>
\r
378 <progress>${progress}</progress>
\r
379 <reason>${reason}</reason>
\r
380 </ns:updateServiceOperationStatus>
\r
382 </soapenv:Envelope>"""
\r
384 payload = utils.formatXml(payload)
\r
385 execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
\r
386 utils.log("DEBUG", "Outgoing updateServiceOperStatusRequest: \n" + payload, isDebugEnabled)
\r
388 }catch(Exception e){
\r
389 utils.log("ERROR", "Exception Occured Processing prepareInitServiceOperationStatus. Exception is:\n" + e, isDebugEnabled)
\r
390 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
\r
392 utils.log("DEBUG", "======== COMPLETED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)
\r