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 CreateGenericALaCarteServiceInstance 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 globalSubscriberId = jsonUtil.getJsonValue(siRequest, "requestDetails.subscriberInfo.globalSubscriberId")
77 if (isBlank(globalSubscriberId)) {
78 msg = "Input globalSubscriberId' is null"
79 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
81 execution.setVariable("globalSubscriberId", globalSubscriberId)
85 execution.setVariable("source", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.source"))
86 execution.setVariable("serviceInstanceName", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.instanceName"))
87 execution.setVariable("disableRollback", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.suppressRollback"))
88 String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")
89 if (isBlank(productFamilyId))
91 msg = "Input productFamilyId is null"
92 utils.log("DEBUG", msg, isDebugEnabled)
93 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
95 execution.setVariable("productFamilyId", productFamilyId)
99 String serviceModelInfo = jsonUtil.getJsonValue(siRequest, "requestDetails.modelInfo")
100 if (isBlank(serviceModelInfo)) {
101 msg = "Input serviceModelInfo is null"
102 utils.log("DEBUG", msg, isDebugEnabled)
103 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
106 execution.setVariable("serviceModelInfo", serviceModelInfo)
109 utils.log("DEBUG", "modelInfo" + serviceModelInfo, isDebugEnabled)
112 String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.subscriptionServiceType")
113 if (isBlank(subscriptionServiceType)) {
114 msg = "Input subscriptionServiceType is null"
115 utils.log("DEBUG", msg, isDebugEnabled)
116 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
118 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
122 //execution.setVariable("serviceInputParams", jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.userParams"))
123 //execution.setVariable("failExists", true)
125 } catch (BpmnError e) {
127 } catch (Exception ex){
128 msg = "Exception in preProcessRequest " + ex.getMessage()
129 utils.log("DEBUG", msg, isDebugEnabled)
130 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
132 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
135 public void sendSyncResponse (Execution execution) {
136 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
137 utils.log("DEBUG", " *** sendSyncResponse *** ", isDebugEnabled)
140 String requestId = execution.getVariable("msoRequestId")
141 String serviceInstanceId = execution.getVariable("serviceInstanceId")
142 // RESTResponse for API Handler (APIH) Reply Task
143 String createServiceRestRequest = """{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
144 utils.log("DEBUG", " sendSyncResponse to APIH:" + "\n" + createServiceRestRequest, isDebugEnabled)
145 sendWorkflowResponse(execution, 202, createServiceRestRequest)
146 execution.setVariable("sentSyncResponse", true)
148 } catch (Exception ex) {
149 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
150 utils.log("DEBUG", msg, isDebugEnabled)
151 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
153 utils.log("DEBUG"," ***** Exit sendSyncResopnse *****", isDebugEnabled)
157 public void sendSyncError (Execution execution) {
158 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
159 utils.log("DEBUG", " *** 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">
\r
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("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
185 public void prepareCompletionRequest (Execution execution) {
186 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
187 utils.log("DEBUG", " *** prepareCompletion *** ", isDebugEnabled)
190 String requestId = execution.getVariable("msoRequestId")
191 String serviceInstanceId = execution.getVariable("serviceInstanceId")
192 String source = execution.getVariable("source")
194 String msoCompletionRequest =
195 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
196 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
197 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
198 <request-id>${requestId}</request-id>
199 <action>CREATE</action>
200 <source>${source}</source>
202 <status-message>Service Instance was created successfully.</status-message>
203 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
204 <mso-bpel-name>CreateGenericALaCarteServiceInstance</mso-bpel-name>
205 </aetgt:MsoCompletionRequest>"""
208 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
210 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
211 utils.log("DEBUG", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
213 } catch (Exception ex) {
214 String msg = " Exception in prepareCompletion:" + ex.getMessage()
215 utils.log("DEBUG", msg, isDebugEnabled)
216 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
218 utils.log("DEBUG", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
221 public void prepareFalloutRequest(Execution execution){
222 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
223 utils.log("DEBUG", " *** prepareFalloutRequest *** ", isDebugEnabled)
226 WorkflowException wfex = execution.getVariable("WorkflowException")
227 utils.log("DEBUG", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
228 String requestId = execution.getVariable("msoRequestId")
229 String source = execution.getVariable("source")
231 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
232 <request-id>${requestId}</request-id>
233 <action>CREATE</action>
234 <source>${source}</source>
237 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
238 execution.setVariable("falloutRequest", falloutRequest)
239 } catch (Exception ex) {
240 utils.log("DEBUG", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
241 String errorException = " Bpmn error encountered in CreateGenericALaCarteServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
242 String requestId = execution.getVariable("msoRequestId")
243 String falloutRequest =
244 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
245 xmlns:ns="http://org.openecomp/mso/request/types/v1"
\r
246 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
\r
247 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
248 <request-id>${requestId}</request-id>
249 <action>CREATE</action>
252 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
253 <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
254 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
255 </aetgt:WorkflowException>
256 </aetgt:FalloutHandlerRequest>"""
258 execution.setVariable("falloutRequest", falloutRequest)
260 utils.log("DEBUG", "*** Exit prepareFalloutRequest ***", isDebugEnabled)