2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7 * ================================================================================
8 * Modifications Copyright (c) 2019 Samsung
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.so.bpmn.infrastructure.scripts
26 import org.onap.so.logger.ErrorCode;
28 import static org.apache.commons.lang3.StringUtils.*
30 import org.camunda.bpm.engine.delegate.BpmnError
31 import org.camunda.bpm.engine.delegate.DelegateExecution
32 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
33 import org.onap.so.bpmn.common.scripts.ExceptionUtil
34 import org.onap.so.bpmn.common.scripts.MsoUtils
35 import org.onap.so.bpmn.core.UrnPropertiesReader
36 import org.onap.so.bpmn.core.WorkflowException
37 import org.onap.so.bpmn.core.json.JsonUtils
38 import org.onap.so.logger.MessageEnum
39 import org.slf4j.Logger
40 import org.slf4j.LoggerFactory
41 import org.springframework.web.util.UriUtils
46 * This groovy class supports the <class>CreateServiceInstance.bpmn</class> process.
47 * AlaCarte flow for 1702 ServiceInstance Create
50 public class CreateCustomE2EServiceInstance extends AbstractServiceTaskProcessor {
51 String Prefix="CRESI_"
52 ExceptionUtil exceptionUtil = new ExceptionUtil()
53 JsonUtils jsonUtil = new JsonUtils()
54 private static final Logger logger = LoggerFactory.getLogger( CreateCustomE2EServiceInstance.class);
57 public void preProcessRequest (DelegateExecution execution) {
58 logger.trace("start preProcessRequest")
59 execution.setVariable("prefix",Prefix)
63 String siRequest = execution.getVariable("bpmnRequest")
64 logger.debug(siRequest)
66 String requestId = execution.getVariable("mso-request-id")
67 execution.setVariable("msoRequestId", requestId)
68 logger.debug("Input Request:" + siRequest + " reqId:" + requestId)
70 String serviceInstanceId = execution.getVariable("serviceInstanceId")
71 if (isBlank(serviceInstanceId)) {
72 serviceInstanceId = UUID.randomUUID().toString()
74 logger.debug("Generated new Service Instance:" + serviceInstanceId)
75 serviceInstanceId = UriUtils.encode(serviceInstanceId,"UTF-8")
76 execution.setVariable("serviceInstanceId", serviceInstanceId)
79 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "requestDetails.subscriberInfo.globalSubscriberId")
80 if (isBlank(globalSubscriberId)) {
81 msg = "Input globalSubscriberId' is null"
82 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
84 execution.setVariable("globalSubscriberId", globalSubscriberId)
88 execution.setVariable("source", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.source"))
89 execution.setVariable("serviceInstanceName", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.instanceName"))
90 execution.setVariable("disableRollback", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.suppressRollback"))
91 String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")
92 if (isBlank(productFamilyId))
94 msg = "Input productFamilyId is null"
96 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
98 execution.setVariable("productFamilyId", productFamilyId)
102 String serviceModelInfo = jsonUtil.getJsonValue(siRequest, "requestDetails.modelInfo")
103 if (isBlank(serviceModelInfo)) {
104 msg = "Input serviceModelInfo is null"
106 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
109 execution.setVariable("serviceModelInfo", serviceModelInfo)
112 logger.debug("modelInfo: " + serviceModelInfo)
115 String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.subscriptionServiceType")
116 if (isBlank(subscriptionServiceType)) {
117 msg = "Input subscriptionServiceType is null"
119 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
121 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
126 * Extracting User Parameters from incoming Request and converting into a Map
128 def jsonSlurper = new JsonSlurper()
129 def jsonOutput = new JsonOutput()
131 Map reqMap = jsonSlurper.parseText(siRequest)
134 def userParamsList = reqMap.requestDetails?.requestParameters?.userParams
136 Map<String, String> inputMap = [:]
137 if (userParamsList) {
138 for (def i=0; i<userParamsList.size(); i++) {
139 def userParams1 = userParamsList.get(i)
140 userParams1.each { param -> inputMap.put(param.key, param.value)}
144 logger.debug("User Input Parameters map: " + inputMap.toString())
145 execution.setVariable("serviceInputParams", inputMap)
146 execution.setVariable("uuiRequest", inputMap.get("UUIRequest"))
149 //execution.setVariable("serviceInputParams", jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.userParams"))
150 //execution.setVariable("failExists", true)
151 } catch (BpmnError e) {
153 } catch (Exception ex){
154 msg = "Exception in preProcessRequest " + ex.getMessage()
156 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
158 logger.trace("finished preProcessRequest")
161 public void sendSyncResponse (DelegateExecution execution) {
162 logger.trace("start sendSyncResponse")
164 String operationId = execution.getVariable("operationId")
165 String serviceInstanceId = execution.getVariable("serviceInstanceId")
166 // RESTResponse for API Handler (APIH) Reply Task
167 String createServiceRestRequest = """{"service":{"serviceId":"${serviceInstanceId}","operationId":"${operationId}"}}""".trim()
168 logger.debug(" sendSyncResponse to APIH:" + "\n" + createServiceRestRequest)
169 sendWorkflowResponse(execution, 202, createServiceRestRequest)
170 execution.setVariable("sentSyncResponse", true)
171 } catch (Exception ex) {
172 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
174 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
176 logger.trace("finished sendSyncResponse")
180 public void sendSyncError (DelegateExecution execution) {
181 logger.trace("start sendSyncError")
183 String errorMessage = ""
184 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
185 WorkflowException wfe = execution.getVariable("WorkflowException")
186 errorMessage = wfe.getErrorMessage()
188 errorMessage = "Sending Sync Error."
191 String buildworkflowException =
192 """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
193 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
194 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
195 </aetgt:WorkflowException>"""
197 logger.debug(buildworkflowException)
198 sendWorkflowResponse(execution, 500, buildworkflowException)
200 } catch (Exception ex) {
201 logger.debug("Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
203 logger.trace("finished sendSyncError")
206 public void prepareCompletionRequest (DelegateExecution execution) {
207 logger.trace("start prepareCompletionRequest")
209 String requestId = execution.getVariable("msoRequestId")
210 String serviceInstanceId = execution.getVariable("serviceInstanceId")
211 String source = execution.getVariable("source")
213 String msoCompletionRequest =
214 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
215 xmlns:ns="http://org.onap/so/request/types/v1">
216 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
217 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
218 <action>CREATE</action>
219 <source>${MsoUtils.xmlEscape(source)}</source>
221 <status-message>Service Instance was created successfully.</status-message>
222 <serviceInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceInstanceId>
223 <mso-bpel-name>CreateGenericALaCarteServiceInstance</mso-bpel-name>
224 </aetgt:MsoCompletionRequest>"""
227 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
229 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
230 logger.debug("Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
232 } catch (Exception ex) {
233 String msg = " Exception in prepareCompletion:" + ex.getMessage()
235 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
237 logger.trace("finished prepareCompletionRequest")
240 public void prepareFalloutRequest(DelegateExecution execution){
241 logger.trace("start prepareFalloutRequest")
243 WorkflowException wfex = execution.getVariable("WorkflowException")
244 logger.debug("Input Workflow Exception: " + wfex.toString())
245 String requestId = execution.getVariable("msoRequestId")
246 String source = execution.getVariable("source")
248 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
249 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
250 <action>CREATE</action>
251 <source>${MsoUtils.xmlEscape(source)}</source>
254 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
255 execution.setVariable("falloutRequest", falloutRequest)
256 } catch (Exception ex) {
257 logger.debug("Exception prepareFalloutRequest:" + ex.getMessage())
258 String errorException = " Bpmn error encountered in CreateGenericALaCarteServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
259 String requestId = execution.getVariable("msoRequestId")
260 String falloutRequest =
261 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
262 xmlns:ns="http://org.onap/so/request/types/v1"
263 xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
264 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
265 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
266 <action>CREATE</action>
269 <aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
270 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorException)}</aetgt:ErrorMessage>
271 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
272 </aetgt:WorkflowException>
273 </aetgt:FalloutHandlerRequest>"""
275 execution.setVariable("falloutRequest", falloutRequest)
277 logger.trace("finished prepareFalloutRequest")
281 * Init the service Operation Status
283 public void prepareInitServiceOperationStatus(DelegateExecution execution){
284 logger.trace("start prepareInitServiceOperationStatus")
286 String serviceId = execution.getVariable("serviceInstanceId")
287 String operationId = UUID.randomUUID().toString()
288 String operationType = "CREATE"
290 String result = "processing"
291 String progress = "0"
293 String operationContent = "Prepare service creation"
294 logger.debug("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId)
295 serviceId = UriUtils.encode(serviceId,"UTF-8")
296 execution.setVariable("serviceInstanceId", serviceId)
297 execution.setVariable("operationId", operationId)
298 execution.setVariable("operationType", operationType)
300 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint",execution)
301 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
302 logger.debug("DB Adapter Endpoint is: " + dbAdapterEndpoint)
305 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
306 xmlns:ns="http://org.onap.so/requestsdb">
309 <ns:initServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
310 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
311 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
312 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
313 <userId>${MsoUtils.xmlEscape(userId)}</userId>
314 <result>${MsoUtils.xmlEscape(result)}</result>
315 <operationContent>${MsoUtils.xmlEscape(operationContent)}</operationContent>
316 <progress>${MsoUtils.xmlEscape(progress)}</progress>
317 <reason>${MsoUtils.xmlEscape(reason)}</reason>
318 </ns:initServiceOperationStatus>
320 </soapenv:Envelope>"""
322 payload = utils.formatXml(payload)
323 execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
324 logger.debug("Outgoing updateServiceOperStatusRequest: \n" + payload)
325 logger.debug("CreateVfModuleInfra Outgoing updateServiceOperStatusRequest Request: " + payload)
328 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
329 "Exception Occured Processing prepareInitServiceOperationStatus.", "BPMN",
330 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
331 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
333 logger.trace("finished prepareInitServiceOperationStatus")