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
22 package org.openecomp.mso.bpmn.infrastructure.scripts;
\r
24 import static org.apache.commons.lang3.StringUtils.*;
\r
25 import groovy.xml.XmlUtil
\r
26 import groovy.json.*
\r
27 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
28 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
30 import org.openecomp.mso.bpmn.core.WorkflowException
\r
31 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
32 import org.openecomp.mso.rest.APIResponse
\r
34 import java.util.UUID;
\r
36 import org.camunda.bpm.engine.delegate.BpmnError
\r
37 import org.camunda.bpm.engine.delegate.DelegateExecution
\r
38 import org.apache.commons.lang3.*
\r
39 import org.apache.commons.codec.binary.Base64;
\r
40 import org.springframework.web.util.UriUtils
\r
43 * This groovy class supports the <class>CreateServiceInstance.bpmn</class> process.
\r
44 * AlaCarte flow for 1702 ServiceInstance Create
\r
47 public class CreateCustomE2EServiceInstance extends AbstractServiceTaskProcessor {
\r
48 String Prefix="CRESI_"
\r
49 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
50 JsonUtils jsonUtil = new JsonUtils()
\r
53 public void preProcessRequest (DelegateExecution execution) {
\r
54 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
55 execution.setVariable("prefix",Prefix)
\r
57 utils.log("DEBUG", " *** preProcessRequest() *** ", isDebugEnabled)
\r
61 String siRequest = execution.getVariable("bpmnRequest")
\r
62 utils.logAudit(siRequest)
\r
64 String requestId = execution.getVariable("mso-request-id")
\r
65 execution.setVariable("msoRequestId", requestId)
\r
66 utils.log("DEBUG", "Input Request:" + siRequest + " reqId:" + requestId, isDebugEnabled)
\r
68 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
69 if (isBlank(serviceInstanceId)) {
\r
70 serviceInstanceId = UUID.randomUUID().toString()
\r
72 utils.log("DEBUG", "Generated new Service Instance:" + serviceInstanceId, isDebugEnabled)
\r
73 serviceInstanceId = UriUtils.encode(serviceInstanceId,"UTF-8")
\r
74 execution.setVariable("serviceInstanceId", serviceInstanceId)
\r
77 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "requestDetails.subscriberInfo.globalSubscriberId")
\r
78 if (isBlank(globalSubscriberId)) {
\r
79 msg = "Input globalSubscriberId' is null"
\r
80 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
82 execution.setVariable("globalSubscriberId", globalSubscriberId)
\r
86 execution.setVariable("source", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.source"))
\r
87 execution.setVariable("serviceInstanceName", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.instanceName"))
\r
88 execution.setVariable("disableRollback", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.suppressRollback"))
\r
89 String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")
\r
90 if (isBlank(productFamilyId))
\r
92 msg = "Input productFamilyId is null"
\r
93 utils.log("DEBUG", msg, isDebugEnabled)
\r
94 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
96 execution.setVariable("productFamilyId", productFamilyId)
\r
100 String serviceModelInfo = jsonUtil.getJsonValue(siRequest, "requestDetails.modelInfo")
\r
101 if (isBlank(serviceModelInfo)) {
\r
102 msg = "Input serviceModelInfo is null"
\r
103 utils.log("DEBUG", msg, isDebugEnabled)
\r
104 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
107 execution.setVariable("serviceModelInfo", serviceModelInfo)
\r
110 utils.log("DEBUG", "modelInfo" + serviceModelInfo, isDebugEnabled)
\r
112 //requestParameters
\r
113 String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.subscriptionServiceType")
\r
114 if (isBlank(subscriptionServiceType)) {
\r
115 msg = "Input subscriptionServiceType is null"
\r
116 utils.log("DEBUG", msg, isDebugEnabled)
\r
117 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
119 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
\r
124 * Extracting User Parameters from incoming Request and converting into a Map
\r
126 def jsonSlurper = new JsonSlurper()
\r
127 def jsonOutput = new JsonOutput()
\r
129 Map reqMap = jsonSlurper.parseText(siRequest)
\r
132 def userParams = reqMap.requestDetails?.requestParameters?.userParams
\r
134 Map<String, String> inputMap = [:]
\r
137 userParam -> inputMap.put(userParam.name, userParam.value.toString())
\r
141 utils.log("DEBUG", "User Input Parameters map: " + userParams.toString(), isDebugEnabled)
\r
142 execution.setVariable("serviceInputParams", inputMap)
\r
143 execution.setVariable("URN_mso_adapters_openecomp_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
\r
145 //execution.setVariable("serviceInputParams", jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.userParams"))
\r
146 //execution.setVariable("failExists", true)
\r
148 } catch (BpmnError e) {
\r
150 } catch (Exception ex){
\r
151 msg = "Exception in preProcessRequest " + ex.getMessage()
\r
152 utils.log("DEBUG", msg, isDebugEnabled)
\r
153 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
155 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
\r
158 public void sendSyncResponse (DelegateExecution execution) {
\r
159 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
160 utils.log("DEBUG", " *** sendSyncResponse *** ", isDebugEnabled)
\r
163 String operationId = execution.getVariable("operationId")
\r
164 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
165 // RESTResponse for API Handler (APIH) Reply Task
\r
166 String createServiceRestRequest = """{"service":{"serviceId":"${serviceInstanceId}","operationId":"${operationId}"}}""".trim()
\r
167 utils.log("DEBUG", " sendSyncResponse to APIH:" + "\n" + createServiceRestRequest, isDebugEnabled)
\r
168 sendWorkflowResponse(execution, 202, createServiceRestRequest)
\r
169 execution.setVariable("sentSyncResponse", true)
\r
171 } catch (Exception ex) {
\r
172 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
\r
173 utils.log("DEBUG", msg, isDebugEnabled)
\r
174 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
176 utils.log("DEBUG"," ***** Exit sendSyncResopnse *****", isDebugEnabled)
\r
180 public void sendSyncError (DelegateExecution execution) {
\r
181 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
182 utils.log("DEBUG", " *** sendSyncError *** ", isDebugEnabled)
\r
185 String errorMessage = ""
\r
186 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
\r
187 WorkflowException wfe = execution.getVariable("WorkflowException")
\r
188 errorMessage = wfe.getErrorMessage()
\r
190 errorMessage = "Sending Sync Error."
\r
193 String buildworkflowException =
\r
194 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
195 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
\r
196 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
197 </aetgt:WorkflowException>"""
\r
199 utils.logAudit(buildworkflowException)
\r
200 sendWorkflowResponse(execution, 500, buildworkflowException)
\r
202 } catch (Exception ex) {
\r
203 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
\r
208 public void prepareCompletionRequest (DelegateExecution execution) {
\r
209 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
210 utils.log("DEBUG", " *** prepareCompletion *** ", isDebugEnabled)
\r
213 String requestId = execution.getVariable("msoRequestId")
\r
214 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
215 String source = execution.getVariable("source")
\r
217 String msoCompletionRequest =
\r
218 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
219 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
220 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
221 <request-id>${requestId}</request-id>
\r
222 <action>CREATE</action>
\r
223 <source>${source}</source>
\r
225 <status-message>Service Instance was created successfully.</status-message>
\r
226 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
\r
227 <mso-bpel-name>CreateGenericALaCarteServiceInstance</mso-bpel-name>
\r
228 </aetgt:MsoCompletionRequest>"""
\r
231 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
\r
233 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
\r
234 utils.log("DEBUG", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
\r
236 } catch (Exception ex) {
\r
237 String msg = " Exception in prepareCompletion:" + ex.getMessage()
\r
238 utils.log("DEBUG", msg, isDebugEnabled)
\r
239 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
241 utils.log("DEBUG", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
\r
244 public void prepareFalloutRequest(DelegateExecution execution){
\r
245 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
246 utils.log("DEBUG", " *** prepareFalloutRequest *** ", isDebugEnabled)
\r
249 WorkflowException wfex = execution.getVariable("WorkflowException")
\r
250 utils.log("DEBUG", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
\r
251 String requestId = execution.getVariable("msoRequestId")
\r
252 String source = execution.getVariable("source")
\r
253 String requestInfo =
\r
254 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
255 <request-id>${requestId}</request-id>
\r
256 <action>CREATE</action>
\r
257 <source>${source}</source>
\r
260 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
\r
261 execution.setVariable("falloutRequest", falloutRequest)
\r
262 } catch (Exception ex) {
\r
263 utils.log("DEBUG", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
\r
264 String errorException = " Bpmn error encountered in CreateGenericALaCarteServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
\r
265 String requestId = execution.getVariable("msoRequestId")
\r
266 String falloutRequest =
\r
267 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
268 xmlns:ns="http://org.openecomp/mso/request/types/v1"
\r
269 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
\r
270 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
271 <request-id>${requestId}</request-id>
\r
272 <action>CREATE</action>
\r
273 <source>UUI</source>
\r
275 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
276 <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
\r
277 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
278 </aetgt:WorkflowException>
\r
279 </aetgt:FalloutHandlerRequest>"""
\r
281 execution.setVariable("falloutRequest", falloutRequest)
\r
283 utils.log("DEBUG", "*** Exit prepareFalloutRequest ***", isDebugEnabled)
\r
287 * Init the service Operation Status
\r
289 public void prepareInitServiceOperationStatus(DelegateExecution execution){
\r
290 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
291 utils.log("DEBUG", " ======== STARTED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)
\r
293 String serviceId = execution.getVariable("serviceInstanceId")
\r
294 String operationId = UUID.randomUUID().toString()
\r
295 String operationType = "CREATE"
\r
297 String result = "processing"
\r
298 String progress = "0"
\r
300 String operationContent = "Prepare service creation"
\r
301 utils.log("DEBUG", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId, isDebugEnabled)
\r
302 serviceId = UriUtils.encode(serviceId,"UTF-8")
\r
303 execution.setVariable("serviceInstanceId", serviceId)
\r
304 execution.setVariable("operationId", operationId)
\r
305 execution.setVariable("operationType", operationType)
\r
307 def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
\r
308 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
\r
309 utils.log("DEBUG", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
\r
312 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
\r
313 xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
316 <ns:updateServiceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
317 <serviceId>${serviceId}</serviceId>
\r
318 <operationId>${operationId}</operationId>
\r
319 <operationType>${operationType}</operationType>
\r
320 <userId>${userId}</userId>
\r
321 <result>${result}</result>
\r
322 <operationContent>${operationContent}</operationContent>
\r
323 <progress>${progress}</progress>
\r
324 <reason>${reason}</reason>
\r
325 </ns:updateServiceOperationStatus>
\r
327 </soapenv:Envelope>"""
\r
329 payload = utils.formatXml(payload)
\r
330 execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
\r
331 utils.log("DEBUG", "Outgoing updateServiceOperStatusRequest: \n" + payload, isDebugEnabled)
\r
332 utils.logAudit("CreateVfModuleInfra Outgoing updateServiceOperStatusRequest Request: " + payload)
\r
334 }catch(Exception e){
\r
335 utils.log("ERROR", "Exception Occured Processing prepareInitServiceOperationStatus. Exception is:\n" + e, isDebugEnabled)
\r
336 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
\r
338 utils.log("DEBUG", "======== COMPLETED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)
\r