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.runtime.Execution
\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 (Execution execution) {
\r
63 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
64 execution.setVariable("prefix",Prefix)
\r
67 utils.log("DEBUG", " *** 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("DEBUG", "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
86 String serviceType = execution.getVariable("serviceType")
\r
87 if (isBlank(serviceType)) {
\r
88 msg = "Input serviceType' is null"
\r
89 utils.log("DEBUG", msg, isDebugEnabled)
\r
91 execution.setVariable("serviceType", serviceType)
\r
94 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "globalSubscriberId")
\r
95 if (isBlank(globalSubscriberId)) {
\r
96 msg = "Input globalSubscriberId' is null"
\r
97 utils.log("DEBUG", msg, isDebugEnabled)
\r
99 execution.setVariable("globalSubscriberId", globalSubscriberId)
\r
101 execution.setVariable("URN_mso_adapters_openecomp_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
\r
102 } catch (BpmnError e) {
\r
104 } catch (Exception ex){
\r
105 msg = "Exception in preProcessRequest " + ex.getMessage()
\r
106 utils.log("DEBUG", msg, isDebugEnabled)
\r
107 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
109 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
\r
112 public void sendSyncResponse (Execution execution) {
\r
113 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
114 utils.log("DEBUG", " *** sendSyncResponse *** ", isDebugEnabled)
\r
117 String operationId = execution.getVariable("operationId")
\r
119 // RESTResponse (for API Handler (APIH) Reply Task)
\r
120 String syncResponse = """{"operationId":"${operationId}"}""".trim()
\r
121 utils.log("DEBUG", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
\r
122 sendWorkflowResponse(execution, 202, syncResponse)
\r
124 } catch (Exception ex) {
\r
125 String msg = "Exception in sendSyncResponse: " + ex.getMessage()
\r
126 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
128 utils.log("DEBUG"," ***** Exit sendSyncResopnse *****", isDebugEnabled)
\r
131 public void sendSyncError (Execution execution) {
\r
132 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
133 utils.log("DEBUG", " *** sendSyncError *** ", isDebugEnabled)
\r
136 String errorMessage = ""
\r
137 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
\r
138 WorkflowException wfe = execution.getVariable("WorkflowException")
\r
139 errorMessage = wfe.getErrorMessage()
\r
141 errorMessage = "Sending Sync Error."
\r
144 String buildworkflowException =
\r
145 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
146 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
\r
147 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
148 </aetgt:WorkflowException>"""
\r
150 utils.logAudit(buildworkflowException)
\r
151 sendWorkflowResponse(execution, 500, buildworkflowException)
\r
153 } catch (Exception ex) {
\r
154 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
\r
159 public void preInitResourcesOperStatus(Execution execution){
\r
160 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
162 utils.log("DEBUG", " ======== STARTED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
\r
164 String serviceId = execution.getVariable("serviceInstanceId")
\r
165 String operationId = UUID.randomUUID().toString()
\r
166 String operationType = "DELETE"
\r
167 String resourceTemplateUUIDs = ""
\r
168 String result = "processing"
\r
169 String progress = "0"
\r
171 String operationContent = "Prepare service creation"
\r
172 utils.log("DEBUG", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + oprationType, isDebugEnabled)
\r
173 serviceId = UriUtils.encode(serviceId,"UTF-8")
\r
174 execution.setVariable("serviceInstanceId", serviceId)
\r
175 execution.setVariable("operationId", operationId)
\r
176 execution.setVariable("operationType", operationType)
\r
177 // we use resource instance ids for delete flow as resourceTemplateUUIDs
\r
180 "resourceInstanceId":"1111",
\r
181 "resourceType":"vIMS"
\r
184 "resourceInstanceId":"222",
\r
185 "resourceType":"vEPC"
\r
188 "resourceInstanceId":"3333",
\r
189 "resourceType":"overlay"
\r
192 "resourceInstanceId":"4444",
\r
193 "resourceType":"underlay"
\r
196 String serviceRelationShip = execution.getVariable("serviceRelationShip")
\r
198 def jsonSlurper = new JsonSlurper()
\r
199 def jsonOutput = new JsonOutput()
\r
200 List relationShipList = jsonSlurper.parseText(serviceRelationShip)
\r
202 if (relationShipList != null) {
\r
203 relationShipList.each {
\r
204 resourceTemplateUUIDs = resourceTemplateUUIDs + it.resourceInstanceId + ":"
\r
208 def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
\r
209 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
\r
210 utils.log("DEBUG", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
\r
213 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
\r
214 xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
217 <ns:initResourceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
218 <serviceId>${serviceId}</serviceId>
\r
219 <operationId>${operationId}</operationId>
\r
220 <operationType>${operationType}</operationType>
\r
221 <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>
\r
222 </ns:initResourceOperationStatus>
\r
224 </soapenv:Envelope>"""
\r
226 payload = utils.formatXml(payload)
\r
227 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
\r
228 utils.log("DEBUG", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)
\r
229 utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
\r
231 }catch(Exception e){
\r
232 utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)
\r
233 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
\r
235 utils.log("DEBUG", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
\r
238 public void prepareCompletionRequest (Execution execution) {
\r
239 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
240 utils.log("DEBUG", " *** prepareCompletion *** ", isDebugEnabled)
\r
243 String requestId = execution.getVariable("msoRequestId")
\r
244 String source = execution.getVariable("source")
\r
245 String msoCompletionRequest =
\r
246 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
247 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
248 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
249 <request-id>${requestId}</request-id>
\r
250 <action>DELETE</action>
\r
251 <source>${source}</source>
\r
253 <aetgt:status-message>E2E Service Instance was deleted successfully.</aetgt:status-message>
\r
254 <aetgt:mso-bpel-name>DeleteCustomE2EServiceInstance</aetgt:mso-bpel-name>
\r
255 </aetgt:MsoCompletionRequest>"""
\r
258 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
\r
260 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
\r
261 utils.log("DEBUG", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
\r
263 } catch (Exception ex) {
\r
264 String msg = " Exception in prepareCompletion:" + ex.getMessage()
\r
265 utils.log("DEBUG", msg, isDebugEnabled)
\r
266 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
268 utils.log("DEBUG", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
\r
271 public void prepareFalloutRequest(Execution execution){
\r
272 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
273 utils.log("DEBUG", " *** prepareFalloutRequest *** ", isDebugEnabled)
\r
276 WorkflowException wfex = execution.getVariable("WorkflowException")
\r
277 utils.log("DEBUG", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
\r
278 String requestId = execution.getVariable("msoRequestId")
\r
279 String source = execution.getVariable("source")
\r
280 String requestInfo =
\r
281 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
282 <request-id>${requestId}</request-id>
\r
283 <action>DELETE</action>
\r
284 <source>${source}</source>
\r
287 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
\r
288 execution.setVariable("falloutRequest", falloutRequest)
\r
289 } catch (Exception ex) {
\r
290 utils.log("DEBUG", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
\r
291 String errorException = " Bpmn error encountered in CreateServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
\r
292 String requestId = execution.getVariable("msoRequestId")
\r
293 String falloutRequest =
\r
294 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
295 xmlns:ns="http://org.openecomp/mso/request/types/v1"
\r
296 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
\r
297 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
298 <request-id>${requestId}</request-id>
\r
299 <action>DELETE</action>
\r
300 <source>VID</source>
\r
302 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
303 <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
\r
304 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
305 </aetgt:WorkflowException>
\r
306 </aetgt:FalloutHandlerRequest>"""
\r
308 execution.setVariable("falloutRequest", falloutRequest)
\r
310 utils.log("DEBUG", "*** Exit prepareFalloutRequest ***", isDebugEnabled)
\r
314 // *******************************
\r
315 // Build DB request Section
\r
316 // *******************************
\r
317 public void prepareDBRequest (Execution execution) {
\r
318 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
319 execution.setVariable("prefix", Prefix)
\r
322 utils.log("DEBUG", " ***** Inside prepareDBRequest of DeleteCustomE2EServiceInstance ***** ", isDebugEnabled)
\r
324 String requestId = execution.getVariable("DELSI_requestId")
\r
325 String statusMessage = "E2E Service Instance successfully deleted."
\r
327 //TODO - verify the format for Service Instance Delete,
\r
329 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
\r
332 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
333 <requestId>${requestId}</requestId>
\r
334 <lastModifiedBy>BPMN</lastModifiedBy>
\r
335 <statusMessage>${statusMessage}</statusMessage>
\r
336 <responseBody></responseBody>
\r
337 <requestStatus>COMPLETED</requestStatus>
\r
338 <progress>100</progress>
\r
339 </ns:updateInfraRequest>
\r
341 </soapenv:Envelope>"""
\r
343 String buildDeleteDBRequestAsString = utils.formatXml(dbRequest)
\r
344 execution.setVariable("DELSI_createDBRequest", buildDeleteDBRequestAsString)
\r
345 utils.logAudit(buildDeleteDBRequestAsString)
\r
347 } catch (Exception ex) {
\r
348 // try error in method block
\r
349 String exceptionMessage = "Bpmn error encountered in DeleteCustomE2EServiceInstance flow. Unexpected Error from method prepareDBRequest() - " + ex.getMessage()
\r
350 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
356 // *******************************
\r
357 // Build Error Section
\r
358 // *******************************
\r
359 public void prepareDBRequestError (Execution execution) {
\r
360 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
361 execution.setVariable("prefix", Prefix)
\r
363 utils.log("DEBUG", " ***** Inside prepareDBRequestError of DeleteCustomE2EServiceInstance ***** ", isDebugEnabled)
\r
366 String requestId = execution.getVariable("DELSI_requestId")
\r
367 String statusMessage = ""
\r
368 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
\r
369 WorkflowException wfe = execution.getVariable("WorkflowException")
\r
370 statusMessage = wfe.getErrorMessage()
\r
373 statusMessage = "Encountered Error during DeleteCustomE2EServiceInstance proccessing. "
\r
376 //TODO - verify the format for Service Instance Create,
\r
378 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
\r
381 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
382 <requestId>${requestId}</requestId>
\r
383 <lastModifiedBy>BPMN</lastModifiedBy>
\r
384 <statusMessage>${statusMessage}</statusMessage>
\r
385 <responseBody></responseBody>
\r
386 <requestStatus>FAILED</requestStatus>
\r
387 </ns:updateInfraRequest>
\r
389 </soapenv:Envelope>"""
\r
391 String buildDBRequestAsString = utils.formatXml(dbRequest)
\r
392 execution.setVariable("DELSI_createDBInfraErrorRequest", buildDBRequestAsString)
\r
393 utils.logAudit(buildDBRequestAsString)
\r
395 } catch (Exception ex) {
\r
396 // try error in method block
\r
397 String exceptionMessage = "Bpmn error encountered in DeleteCustomE2EServiceInstance flow. Unexpected Error from method prepareDBRequestError() - " + ex.getMessage()
\r
398 exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage)
\r