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