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=========================================================
21 package org.openecomp.mso.bpmn.infrastructure.scripts;
23 import static org.apache.commons.lang3.StringUtils.*;
24 import groovy.xml.XmlUtil
26 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
27 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
29 import org.openecomp.mso.bpmn.core.WorkflowException
30 import org.openecomp.mso.bpmn.core.json.JsonUtils
31 import org.openecomp.mso.rest.APIResponse
33 import java.util.List;
34 import java.util.UUID;
36 import org.camunda.bpm.engine.delegate.BpmnError
37 import org.camunda.bpm.engine.delegate.DelegateExecution
38 import org.apache.commons.lang3.*
39 import org.apache.commons.codec.binary.Base64;
40 import org.springframework.web.util.UriUtils
43 * This groovy class supports the <class>UpdateCustomE2EServiceInstance.bpmn</class> process.
44 * AlaCarte flow for 1702 ServiceInstance Update
47 public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor {
48 String Prefix="UPDSI_"
49 ExceptionUtil exceptionUtil = new ExceptionUtil()
50 JsonUtils jsonUtil = new JsonUtils()
53 public void preProcessRequest (DelegateExecution execution) {
54 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
55 execution.setVariable("prefix",Prefix)
57 utils.log("INFO", " *** preProcessRequest() *** ", isDebugEnabled)
61 String siRequest = execution.getVariable("bpmnRequest")
62 utils.logAudit(siRequest)
64 String requestId = execution.getVariable("mso-request-id")
65 execution.setVariable("msoRequestId", requestId)
66 utils.log("INFO", "Input Request:" + siRequest + " reqId:" + requestId, isDebugEnabled)
68 String serviceInstanceId = execution.getVariable("serviceInstanceId")
69 if (isBlank(serviceInstanceId)) {
70 msg = "Input serviceInstanceId' is null"
71 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
75 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "requestDetails.subscriberInfo.globalSubscriberId")
76 if (isBlank(globalSubscriberId)) {
77 msg = "Input globalSubscriberId' is null"
78 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
80 execution.setVariable("globalSubscriberId", globalSubscriberId)
84 execution.setVariable("source", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.source"))
85 execution.setVariable("serviceInstanceName", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.instanceName"))
86 execution.setVariable("disableRollback", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.suppressRollback"))
87 String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")
88 if (isBlank(productFamilyId))
90 msg = "Input productFamilyId is null"
91 utils.log("INFO", msg, isDebugEnabled)
92 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
94 execution.setVariable("productFamilyId", productFamilyId)
96 String userParams = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.userParams")
97 utils.log("INFO", "userParams:" + userParams, isDebugEnabled)
98 List<String> paramList = jsonUtil.StringArrayToList(execution, userParams)
99 String uuiRequest = jsonUtil.getJsonValue(paramList.get(0), "UUIRequest")
101 if (isBlank(uuiRequest)) {
102 msg = "Input uuiRequest is null"
103 utils.log("INFO", msg, isDebugEnabled)
104 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
107 execution.setVariable("uuiRequest", uuiRequest)
110 utils.log("INFO", "uuiRequest:\n" + uuiRequest, isDebugEnabled)
112 //serviceType for aai
113 String serviceType = jsonUtil.getJsonValue(uuiRequest, "service.serviceType")
114 if (isBlank(serviceType)) {
115 msg = "Input serviceType is null"
116 utils.log("INFO", msg, isDebugEnabled)
117 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
119 execution.setVariable("serviceType", serviceType)
123 * Extracting User Parameters from incoming Request and converting into a Map
125 def jsonSlurper = new JsonSlurper()
126 def jsonOutput = new JsonOutput()
128 Map reqMap = jsonSlurper.parseText(siRequest)
131 def userParamsList = reqMap.requestDetails?.requestParameters?.userParams
133 Map<String, String> inputMap = [:]
134 if (userParamsList) {
135 for (def i=0; i<userParamsList.size(); i++) {
136 def userParams1 = userParamsList.get(i)
137 userParams1.each { param -> inputMap.put(param.key, param.value)}
141 utils.log("DEBUG", "User Input Parameters map: " + inputMap.toString(), isDebugEnabled)
142 execution.setVariable("serviceInputParams", inputMap)
143 execution.setVariable("uuiRequest", inputMap.get("UUIRequest"))
146 String operationId = jsonUtil.getJsonValue(siRequest, "operationId")
147 if (isBlank(operationId)) {
148 operationId = UUID.randomUUID().toString()
150 execution.setVariable("operationId", operationId)
151 execution.setVariable("operationType", "UPDATE")
153 execution.setVariable("URN_mso_adapters_openecomp_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
155 } catch (BpmnError e) {
157 } catch (Exception ex){
158 msg = "Exception in preProcessRequest " + ex.getMessage()
159 utils.log("INFO", msg, isDebugEnabled)
160 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
162 utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)
166 * Init the service Operation Status
168 public void prepareInitServiceOperationStatus(DelegateExecution execution){
169 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
170 utils.log("DEBUG", " ======== STARTED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)
172 String serviceId = execution.getVariable("serviceInstanceId")
173 String operationId = execution.getVariable("operationId")
174 String operationType = execution.getVariable("operationType")
176 String result = "processing"
177 String progress = "0"
179 String operationContent = "Prepare service updating"
180 utils.log("DEBUG", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId, isDebugEnabled)
181 serviceId = UriUtils.encode(serviceId,"UTF-8")
182 execution.setVariable("serviceInstanceId", serviceId)
183 execution.setVariable("operationId", operationId)
184 execution.setVariable("operationType", operationType)
186 def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
187 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
188 utils.log("DEBUG", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
191 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
192 xmlns:ns="http://org.openecomp.mso/requestsdb">
195 <ns:updateServiceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
196 <serviceId>${serviceId}</serviceId>
197 <operationId>${operationId}</operationId>
198 <operationType>${operationType}</operationType>
199 <userId>${userId}</userId>
200 <result>${result}</result>
201 <operationContent>${operationContent}</operationContent>
202 <progress>${progress}</progress>
203 <reason>${reason}</reason>
204 </ns:updateServiceOperationStatus>
206 </soapenv:Envelope>"""
208 payload = utils.formatXml(payload)
209 execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
210 utils.log("DEBUG", "Outgoing updateServiceOperStatusRequest: \n" + payload, isDebugEnabled)
211 utils.logAudit("CreateVfModuleInfra Outgoing updateServiceOperStatusRequest Request: " + payload)
214 utils.log("ERROR", "Exception Occured Processing prepareInitServiceOperationStatus. Exception is:\n" + e, isDebugEnabled)
215 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
217 utils.log("DEBUG", "======== COMPLETED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)
220 public void sendSyncResponse (DelegateExecution execution) {
221 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
222 utils.log("INFO", " *** sendSyncResponse *** ", isDebugEnabled)
225 String operationId = execution.getVariable("operationId")
226 String serviceInstanceId = execution.getVariable("serviceInstanceId")
227 // RESTResponse for API Handler (APIH) Reply Task
228 String updateServiceResp = """{"operationId":"${operationId}"}""".trim()
229 utils.log("INFO", " sendSyncResponse to APIH:" + "\n" + updateServiceResp, isDebugEnabled)
230 sendWorkflowResponse(execution, 202, updateServiceResp)
231 execution.setVariable("sentSyncResponse", true)
233 } catch (Exception ex) {
234 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
235 utils.log("INFO", msg, isDebugEnabled)
236 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
238 utils.log("INFO"," ***** Exit sendSyncResopnse *****", isDebugEnabled)
242 public void sendSyncError (DelegateExecution execution) {
243 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
244 utils.log("INFO", " *** sendSyncError *** ", isDebugEnabled)
247 String errorMessage = ""
248 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
249 WorkflowException wfe = execution.getVariable("WorkflowException")
250 errorMessage = wfe.getErrorMessage()
252 errorMessage = "Sending Sync Error."
255 String buildworkflowException =
256 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
257 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
258 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
259 </aetgt:WorkflowException>"""
261 utils.logAudit(buildworkflowException)
262 sendWorkflowResponse(execution, 500, buildworkflowException)
264 } catch (Exception ex) {
265 utils.log("INFO", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
270 public void prepareCompletionRequest (DelegateExecution execution) {
271 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
272 utils.log("INFO", " *** prepareCompletion *** ", isDebugEnabled)
275 String requestId = execution.getVariable("msoRequestId")
276 String serviceInstanceId = execution.getVariable("serviceInstanceId")
277 String source = execution.getVariable("source")
279 String msoCompletionRequest =
280 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
281 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
282 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
283 <request-id>${requestId}</request-id>
284 <action>UPDATE</action>
285 <source>${source}</source>
287 <status-message>Service Instance was updated successfully.</status-message>
288 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
289 <mso-bpel-name>UpdateGenericALaCarteServiceInstance</mso-bpel-name>
290 </aetgt:MsoCompletionRequest>"""
293 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
295 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
296 utils.log("INFO", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
298 } catch (Exception ex) {
299 String msg = " Exception in prepareCompletion:" + ex.getMessage()
300 utils.log("INFO", msg, isDebugEnabled)
301 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
303 utils.log("INFO", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
306 public void prepareFalloutRequest(DelegateExecution execution){
307 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
308 utils.log("INFO", " *** prepareFalloutRequest *** ", isDebugEnabled)
311 WorkflowException wfex = execution.getVariable("WorkflowException")
312 utils.log("INFO", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
313 String requestId = execution.getVariable("msoRequestId")
314 String source = execution.getVariable("source")
316 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
317 <request-id>${requestId}</request-id>
318 <action>UPDATE</action>
319 <source>${source}</source>
322 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
323 execution.setVariable("falloutRequest", falloutRequest)
324 } catch (Exception ex) {
325 utils.log("INFO", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
326 String errorException = " Bpmn error encountered in UpdateGenericALaCarteServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
327 String requestId = execution.getVariable("msoRequestId")
328 String falloutRequest =
329 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
330 xmlns:ns="http://org.openecomp/mso/request/types/v1"
\r
331 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
\r
332 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
333 <request-id>${requestId}</request-id>
334 <action>UPDATE</action>
337 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
338 <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
339 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
340 </aetgt:WorkflowException>
341 </aetgt:FalloutHandlerRequest>"""
343 execution.setVariable("falloutRequest", falloutRequest)
345 utils.log("INFO", "*** Exit prepareFalloutRequest ***", isDebugEnabled)