2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. 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
28 import org.openecomp.mso.bpmn.common.scripts.VidUtils
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.UUID;
35 import org.camunda.bpm.engine.delegate.BpmnError
36 import org.camunda.bpm.engine.runtime.Execution
37 import org.apache.commons.lang3.*
38 import org.apache.commons.codec.binary.Base64;
39 import org.springframework.web.util.UriUtils
42 * This groovy class supports the <class>CreateServiceInstance.bpmn</class> process.
43 * AlaCarte flow for 1702 ServiceInstance Create
46 public class CreateCustomE2EServiceInstance extends AbstractServiceTaskProcessor {
47 String Prefix="CRESI_"
48 ExceptionUtil exceptionUtil = new ExceptionUtil()
49 JsonUtils jsonUtil = new JsonUtils()
50 VidUtils vidUtils = new VidUtils()
52 public void preProcessRequest (Execution execution) {
53 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
54 execution.setVariable("prefix",Prefix)
56 utils.log("DEBUG", " *** preProcessRequest() *** ", isDebugEnabled)
60 String siRequest = execution.getVariable("bpmnRequest")
61 utils.logAudit(siRequest)
63 String requestId = execution.getVariable("mso-request-id")
64 execution.setVariable("msoRequestId", requestId)
65 utils.log("DEBUG", "Input Request:" + siRequest + " reqId:" + requestId, isDebugEnabled)
67 String serviceInstanceId = execution.getVariable("serviceInstanceId")
68 if (isBlank(serviceInstanceId)) {
69 serviceInstanceId = UUID.randomUUID().toString()
71 utils.log("DEBUG", "Generated new Service Instance:" + serviceInstanceId, isDebugEnabled)
72 serviceInstanceId = UriUtils.encode(serviceInstanceId,"UTF-8")
73 execution.setVariable("serviceInstanceId", serviceInstanceId)
76 String p_domainHost = jsonUtil.getJsonValue(siRequest, "service.parameters.domainHost")
77 if (isBlank(p_domainHost)) {
78 msg = "Input parameters domainHost is null"
79 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
81 execution.setVariable("p_domainHost", p_domainHost)
84 String p_nodeTemplateName = jsonUtil.getJsonValue(siRequest, "service.parameters.nodeTemplateName")
85 if (isBlank(p_nodeTemplateName)) {
86 msg = "Input parameters nodeTemplateName is null"
87 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
89 execution.setVariable("p_nodeTemplateName", p_nodeTemplateName)
92 String p_nodeType = jsonUtil.getJsonValue(siRequest, "service.parameters.nodeType")
93 if (isBlank(p_nodeType)) {
94 msg = "Input parameters nodeType is null"
95 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
97 execution.setVariable("p_nodeType", p_nodeType)
101 def jsonSlurper = new JsonSlurper()
102 //def jsonOutput = new JsonOutput()
104 Map reqMap = jsonSlurper.parseText(siRequest)
106 def p_segments = reqMap.service?.parameters?.segments
108 //List<Segment> segList = []
111 // p_segment -> segList.add(p_segment)
112 // //p_segment.domainHost
115 //execution.setVariable("segments", segList)
117 //location Constraints
118 def p_locationConstraints = reqMap.service?.parameters?.nsParameters?.locationConstraints
119 if(p_locationConstraints){
120 //Copy data. no data available now so ignoring
123 //additionalParamForNs
124 String p_param1 = jsonUtil.getJsonValue(siRequest, "service.parameters.nsParameters.additionalParamForNs.E2EServcie.param1")
125 if (isBlank(p_param1)) {
126 msg = "Input parameters p_param1 is null"
127 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
129 execution.setVariable("p_param1", p_param1)
132 String p_param2 = jsonUtil.getJsonValue(siRequest, "service.parameters.nsParameters.additionalParamForNs.E2EServcie.param2")
133 if (isBlank(p_param2)) {
134 msg = "Input parameters p_param2 is null"
135 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
137 execution.setVariable("p_param2", p_param2)
141 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "requestDetails.subscriberInfo.globalSubscriberId")
142 if (isBlank(globalSubscriberId)) {
143 msg = "Input globalSubscriberId' is null"
144 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
146 execution.setVariable("globalSubscriberId", globalSubscriberId)
150 execution.setVariable("source", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.source"))
151 execution.setVariable("serviceInstanceName", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.instanceName"))
152 execution.setVariable("disableRollback", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.suppressRollback"))
153 String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")
154 if (isBlank(productFamilyId))
156 msg = "Input productFamilyId is null"
157 utils.log("DEBUG", msg, isDebugEnabled)
158 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
160 execution.setVariable("productFamilyId", productFamilyId)
164 String serviceModelInfo = jsonUtil.getJsonValue(siRequest, "requestDetails.modelInfo")
165 if (isBlank(serviceModelInfo)) {
166 msg = "Input serviceModelInfo is null"
167 utils.log("DEBUG", msg, isDebugEnabled)
168 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
171 execution.setVariable("serviceModelInfo", serviceModelInfo)
174 utils.log("DEBUG", "modelInfo" + serviceModelInfo, isDebugEnabled)
177 String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.subscriptionServiceType")
178 if (isBlank(subscriptionServiceType)) {
179 msg = "Input subscriptionServiceType is null"
180 utils.log("DEBUG", msg, isDebugEnabled)
181 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
183 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
187 //execution.setVariable("serviceInputParams", jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.userParams"))
188 //execution.setVariable("failExists", true)
190 } catch (BpmnError e) {
192 } catch (Exception ex){
193 msg = "Exception in preProcessRequest " + ex.getMessage()
194 utils.log("DEBUG", msg, isDebugEnabled)
195 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
197 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
200 public void sendSyncResponse (Execution execution) {
201 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
202 utils.log("DEBUG", " *** sendSyncResponse *** ", isDebugEnabled)
205 String requestId = execution.getVariable("msoRequestId")
206 String serviceInstanceId = execution.getVariable("serviceInstanceId")
207 // RESTResponse for API Handler (APIH) Reply Task
208 String createServiceRestRequest = """{"service":{"serviceId":"${serviceInstanceId}","operationId":"${requestId}"}}""".trim()
209 utils.log("DEBUG", " sendSyncResponse to APIH:" + "\n" + createServiceRestRequest, isDebugEnabled)
210 sendWorkflowResponse(execution, 202, createServiceRestRequest)
211 execution.setVariable("sentSyncResponse", true)
213 } catch (Exception ex) {
214 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
215 utils.log("DEBUG", msg, isDebugEnabled)
216 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
218 utils.log("DEBUG"," ***** Exit sendSyncResopnse *****", isDebugEnabled)
222 public void sendSyncError (Execution execution) {
223 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
224 utils.log("DEBUG", " *** sendSyncError *** ", isDebugEnabled)
227 String errorMessage = ""
228 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
229 WorkflowException wfe = execution.getVariable("WorkflowException")
230 errorMessage = wfe.getErrorMessage()
232 errorMessage = "Sending Sync Error."
235 String buildworkflowException =
236 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
237 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
238 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
239 </aetgt:WorkflowException>"""
241 utils.logAudit(buildworkflowException)
242 sendWorkflowResponse(execution, 500, buildworkflowException)
244 } catch (Exception ex) {
245 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
250 public void prepareCompletionRequest (Execution execution) {
251 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
252 utils.log("DEBUG", " *** prepareCompletion *** ", isDebugEnabled)
255 String requestId = execution.getVariable("msoRequestId")
256 String serviceInstanceId = execution.getVariable("serviceInstanceId")
257 String source = execution.getVariable("source")
259 String msoCompletionRequest =
260 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
261 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
262 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
263 <request-id>${requestId}</request-id>
264 <action>CREATE</action>
265 <source>${source}</source>
267 <status-message>Service Instance was created successfully.</status-message>
268 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
269 <mso-bpel-name>CreateGenericALaCarteServiceInstance</mso-bpel-name>
270 </aetgt:MsoCompletionRequest>"""
273 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
275 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
276 utils.log("DEBUG", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
278 } catch (Exception ex) {
279 String msg = " Exception in prepareCompletion:" + ex.getMessage()
280 utils.log("DEBUG", msg, isDebugEnabled)
281 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
283 utils.log("DEBUG", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
286 public void prepareFalloutRequest(Execution execution){
287 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
288 utils.log("DEBUG", " *** prepareFalloutRequest *** ", isDebugEnabled)
291 WorkflowException wfex = execution.getVariable("WorkflowException")
292 utils.log("DEBUG", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
293 String requestId = execution.getVariable("msoRequestId")
294 String source = execution.getVariable("source")
296 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
297 <request-id>${requestId}</request-id>
298 <action>CREATE</action>
299 <source>${source}</source>
302 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
303 execution.setVariable("falloutRequest", falloutRequest)
304 } catch (Exception ex) {
305 utils.log("DEBUG", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
306 String errorException = " Bpmn error encountered in CreateGenericALaCarteServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
307 String requestId = execution.getVariable("msoRequestId")
308 String falloutRequest =
309 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
310 xmlns:ns="http://org.openecomp/mso/request/types/v1"
\r
311 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
\r
312 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
313 <request-id>${requestId}</request-id>
314 <action>CREATE</action>
317 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
318 <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
319 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
320 </aetgt:WorkflowException>
321 </aetgt:FalloutHandlerRequest>"""
323 execution.setVariable("falloutRequest", falloutRequest)
325 utils.log("DEBUG", "*** Exit prepareFalloutRequest ***", isDebugEnabled)