2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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 static org.apache.commons.lang3.StringUtils.*;
23 import groovy.xml.XmlUtil
26 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
27 import org.openecomp.mso.bpmn.core.domain.ServiceInstance
28 import org.openecomp.mso.bpmn.core.domain.CompareModelsResult
29 import org.openecomp.mso.bpmn.core.domain.ModelInfo
30 import org.openecomp.mso.bpmn.core.json.JsonUtils
31 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
32 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
33 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
34 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
35 import org.openecomp.mso.bpmn.common.scripts.VidUtils
36 import org.openecomp.mso.bpmn.core.RollbackData
37 import org.openecomp.mso.bpmn.core.WorkflowException
38 import org.openecomp.mso.rest.APIResponse;
39 import org.openecomp.mso.rest.RESTClient
40 import org.openecomp.mso.rest.RESTConfig
42 import java.util.UUID;
43 import javax.xml.parsers.DocumentBuilder
44 import javax.xml.parsers.DocumentBuilderFactory
46 import org.camunda.bpm.engine.delegate.BpmnError
47 import org.camunda.bpm.engine.delegate.DelegateExecution
48 import org.json.JSONObject;
49 import org.json.JSONArray;
50 import org.apache.commons.lang3.*
51 import org.apache.commons.codec.binary.Base64;
52 import org.springframework.web.util.UriUtils;
54 import org.w3c.dom.Document
55 import org.w3c.dom.Element
56 import org.w3c.dom.Node
57 import org.w3c.dom.NodeList
58 import org.xml.sax.InputSource
60 * This groovy class supports the <class>CompareModelofE2EServiceInstance.bpmn</class> process.
63 * @param - msoRequestId
64 * @param - globalSubscriberId
65 * @param - subscriptionServiceType
66 * @param - serviceInstanceId
67 * @param - modelInvariantIdTarget
68 * @param - modelVersionIdTarget
72 * @param - WorkflowException
74 public class CompareModelofE2EServiceInstance extends AbstractServiceTaskProcessor {
76 String Prefix="CMPMDSI_"
77 private static final String DebugFlag = "isDebugEnabled"
79 ExceptionUtil exceptionUtil = new ExceptionUtil()
80 JsonUtils jsonUtil = new JsonUtils()
81 VidUtils vidUtils = new VidUtils()
83 public void preProcessRequest (DelegateExecution execution) {
84 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
85 execution.setVariable("prefix",Prefix)
88 utils.log("INFO", " *** preProcessRequest Request *** ", isDebugEnabled)
91 // check for incoming json message/input
92 String siRequest = execution.getVariable("bpmnRequest")
93 utils.logAudit(siRequest)
96 String requestId = execution.getVariable("mso-request-id")
97 execution.setVariable("msoRequestId", requestId)
98 utils.log("INFO", "Input Request:" + siRequest + " reqId:" + requestId, isDebugEnabled)
100 String serviceInstanceId = execution.getVariable("serviceInstanceId")
101 if (isBlank(serviceInstanceId)) {
102 msg = "Input serviceInstanceId' is null"
103 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
107 * Extracting User Parameters from incoming Request and converting into a Map
109 def jsonSlurper = new JsonSlurper()
110 def jsonOutput = new JsonOutput()
112 Map reqMap = jsonSlurper.parseText(siRequest)
115 def userParams = reqMap.requestDetails?.requestParameters?.userParams
117 Map<String, String> inputMap = [:]
120 userParam -> inputMap.put(userParam.name, userParam.value.toString())
123 execution.setVariable("operationType", "CompareModel")
125 utils.log("DEBUG", "User Input Parameters map: " + userParams.toString(), isDebugEnabled)
126 execution.setVariable("serviceInputParams", inputMap)
128 } catch (BpmnError e) {
130 } catch (Exception ex){
131 msg = "Exception in preProcessRequest " + ex.getMessage()
132 utils.log("INFO", msg, isDebugEnabled)
133 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
135 utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)
138 public void sendSyncResponse (DelegateExecution execution) {
139 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
140 utils.log("INFO", " *** sendSyncResponse *** ", isDebugEnabled)
143 CompareModelsResult compareModelsResult = execution.getVariable("compareModelsResult")
145 // RESTResponse (for API Handler(APIH) Reply Task)
146 String syncResponse = compareModelsResult.toString()
147 utils.log("INFO", " sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse, isDebugEnabled)
148 sendWorkflowResponse(execution, 202, syncResponse)
150 } catch (Exception ex) {
151 String msg = "Exception in sendSyncResponse: " + ex.getMessage()
152 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
154 utils.log("INFO"," ***** Exit sendSyncResopnse *****", isDebugEnabled)
157 public void sendSyncError (DelegateExecution execution) {
158 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
159 utils.log("INFO", " *** sendSyncError *** ", isDebugEnabled)
162 String errorMessage = ""
163 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
164 WorkflowException wfe = execution.getVariable("WorkflowException")
165 errorMessage = wfe.getErrorMessage()
167 errorMessage = "Sending Sync Error."
170 String buildworkflowException =
171 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
172 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
173 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
174 </aetgt:WorkflowException>"""
176 utils.logAudit(buildworkflowException)
177 sendWorkflowResponse(execution, 500, buildworkflowException)
179 } catch (Exception ex) {
180 utils.log("INFO", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
185 public void prepareCompletionRequest (DelegateExecution execution) {
186 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
187 utils.log("INFO", " *** prepareCompletion *** ", isDebugEnabled)
190 String requestId = execution.getVariable("msoRequestId")
191 String source = execution.getVariable("source")
192 String msoCompletionRequest =
193 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
194 xmlns:ns="http://org.openecomp/mso/request/types/v1">
195 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
196 <request-id>${requestId}</request-id>
197 <action>COMPAREMODEL</action>
198 <source>${source}</source>
200 <aetgt:status-message>E2E Service Instance Compare model successfully.</aetgt:status-message>
201 <aetgt:mso-bpel-name>CompareModelofE2EServiceInstance</aetgt:mso-bpel-name>
202 </aetgt:MsoCompletionRequest>"""
205 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
207 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
208 utils.log("INFO", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
210 } catch (Exception ex) {
211 String msg = " Exception in prepareCompletion:" + ex.getMessage()
212 utils.log("INFO", msg, isDebugEnabled)
213 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
215 utils.log("INFO", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
218 public void prepareFalloutRequest(DelegateExecution execution){
219 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
220 utils.log("INFO", " *** prepareFalloutRequest *** ", isDebugEnabled)
223 WorkflowException wfex = execution.getVariable("WorkflowException")
224 utils.log("INFO", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
225 String requestId = execution.getVariable("msoRequestId")
226 String source = execution.getVariable("source")
228 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
229 <request-id>${requestId}</request-id>
230 <action>COMPAREMODEL</action>
231 <source>${source}</source>
234 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
235 execution.setVariable("falloutRequest", falloutRequest)
236 } catch (Exception ex) {
237 utils.log("INFO", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
238 String errorException = " Bpmn error encountered in CompareModelofE2EServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
239 String requestId = execution.getVariable("msoRequestId")
240 String falloutRequest =
241 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
242 xmlns:ns="http://org.openecomp/mso/request/types/v1"
243 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
244 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
245 <request-id>${requestId}</request-id>
246 <action>COMPAREMODEL</action>
249 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
250 <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
251 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
252 </aetgt:WorkflowException>
253 </aetgt:FalloutHandlerRequest>"""
255 execution.setVariable("falloutRequest", falloutRequest)
257 utils.log("INFO", "*** Exit prepareFalloutRequest ***", isDebugEnabled)