2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.bpmn.infrastructure.scripts;
\r
23 import static org.apache.commons.lang3.StringUtils.*;
\r
24 import groovy.xml.XmlUtil
\r
25 import groovy.json.*
\r
26 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
27 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
28 import org.openecomp.mso.bpmn.common.scripts.VidUtils
\r
29 import org.openecomp.mso.bpmn.core.WorkflowException
\r
30 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
31 import org.openecomp.mso.rest.APIResponse
\r
33 import java.util.UUID;
\r
35 import org.camunda.bpm.engine.delegate.BpmnError
\r
36 import org.camunda.bpm.engine.runtime.Execution
\r
37 import org.apache.commons.lang3.*
\r
38 import org.apache.commons.codec.binary.Base64;
\r
39 import org.springframework.web.util.UriUtils
\r
42 * This groovy class supports the <class>CreateServiceInstance.bpmn</class> process.
\r
43 * AlaCarte flow for 1702 ServiceInstance Create
\r
46 public class CreateServiceInstance extends AbstractServiceTaskProcessor {
\r
47 String Prefix="CRESI_"
\r
48 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
49 JsonUtils jsonUtil = new JsonUtils()
\r
50 VidUtils vidUtils = new VidUtils()
\r
52 public void preProcessRequest (Execution execution) {
\r
53 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
54 execution.setVariable("prefix",Prefix)
\r
56 utils.log("DEBUG", " *** preProcessRequest() *** ", isDebugEnabled)
\r
60 String siRequest = execution.getVariable("bpmnRequest")
\r
61 utils.logAudit(siRequest)
\r
63 String requestId = execution.getVariable("mso-request-id")
\r
64 execution.setVariable("msoRequestId", requestId)
\r
65 utils.log("DEBUG", "Input Request:" + siRequest + " reqId:" + requestId, isDebugEnabled)
\r
67 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
68 if (isBlank(serviceInstanceId)) {
\r
69 serviceInstanceId = UUID.randomUUID().toString()
\r
71 utils.log("DEBUG", "Generated new Service Instance:" + serviceInstanceId, isDebugEnabled)
\r
72 serviceInstanceId = UriUtils.encode(serviceInstanceId,"UTF-8")
\r
73 execution.setVariable("serviceInstanceId", serviceInstanceId)
\r
76 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "requestDetails.subscriberInfo.globalSubscriberId")
\r
77 if (isBlank(globalSubscriberId)) {
\r
78 msg = "Input globalSubscriberId' is null"
\r
79 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
81 execution.setVariable("globalSubscriberId", globalSubscriberId)
\r
85 execution.setVariable("source", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.source"))
\r
86 execution.setVariable("serviceInstanceName", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.instanceName"))
\r
87 execution.setVariable("disableRollback", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.suppressRollback"))
\r
88 String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")
\r
89 if (isBlank(productFamilyId))
\r
91 msg = "Input productFamilyId is null"
\r
92 utils.log("DEBUG", msg, isDebugEnabled)
\r
93 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
95 execution.setVariable("productFamilyId", productFamilyId)
\r
99 String serviceModelInfo = jsonUtil.getJsonValue(siRequest, "requestDetails.modelInfo")
\r
100 if (isBlank(serviceModelInfo)) {
\r
101 msg = "Input serviceModelInfo is null"
\r
102 utils.log("DEBUG", msg, isDebugEnabled)
\r
103 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
106 execution.setVariable("serviceModelInfo", serviceModelInfo)
\r
109 utils.log("DEBUG", "modelInfo" + serviceModelInfo, isDebugEnabled)
\r
111 //requestParameters
\r
112 String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.subscriptionServiceType")
\r
113 if (isBlank(subscriptionServiceType)) {
\r
114 msg = "Input subscriptionServiceType is null"
\r
115 utils.log("DEBUG", msg, isDebugEnabled)
\r
116 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
118 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
\r
122 //execution.setVariable("serviceInputParams", jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.userParams"))
\r
123 //execution.setVariable("failExists", true)
\r
125 } catch (BpmnError e) {
\r
127 } catch (Exception ex){
\r
128 msg = "Exception in preProcessRequest " + ex.getMessage()
\r
129 utils.log("DEBUG", msg, isDebugEnabled)
\r
130 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
132 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
\r
135 public void sendSyncResponse (Execution execution) {
\r
136 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
137 utils.log("DEBUG", " *** sendSyncResponse *** ", isDebugEnabled)
\r
140 String requestId = execution.getVariable("msoRequestId")
\r
141 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
142 // RESTResponse for API Handler (APIH) Reply Task
\r
143 String createServiceRestRequest = """{"requestReferences":{"instanceId":"${serviceInstanceId}","requestId":"${requestId}"}}""".trim()
\r
144 utils.log("DEBUG", " sendSyncResponse to APIH:" + "\n" + createServiceRestRequest, isDebugEnabled)
\r
145 sendWorkflowResponse(execution, 202, createServiceRestRequest)
\r
146 execution.setVariable("sentSyncResponse", true)
\r
148 } catch (Exception ex) {
\r
149 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
\r
150 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
\r
151 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
153 utils.log("DEBUG"," ***** Exit sendSyncResopnse *****", isDebugEnabled)
\r
157 public void sendSyncError (Execution execution) {
\r
158 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
159 utils.log("DEBUG", " *** sendSyncError *** ", isDebugEnabled)
\r
162 String errorMessage = ""
\r
163 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
\r
164 WorkflowException wfe = execution.getVariable("WorkflowException")
\r
165 errorMessage = wfe.getErrorMessage()
\r
167 errorMessage = "Sending Sync Error."
\r
170 String buildworkflowException =
\r
171 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
172 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
\r
173 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
174 </aetgt:WorkflowException>"""
\r
176 utils.logAudit(buildworkflowException)
\r
177 sendWorkflowResponse(execution, 500, buildworkflowException)
\r
179 } catch (Exception ex) {
\r
180 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
\r
185 public void prepareCompletionRequest (Execution execution) {
\r
186 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
187 utils.log("DEBUG", " *** prepareCompletion *** ", isDebugEnabled)
\r
190 String requestId = execution.getVariable("msoRequestId")
\r
191 String serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
192 String source = execution.getVariable("source")
\r
194 String msoCompletionRequest =
\r
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>
\r
199 <action>CREATE</action>
\r
200 <source>${source}</source>
\r
202 <status-message>Service Instance was created successfully.</status-message>
\r
203 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
\r
204 <mso-bpel-name>CreateServiceInstance</mso-bpel-name>
\r
205 </aetgt:MsoCompletionRequest>"""
\r
208 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
\r
210 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
\r
211 utils.log("DEBUG", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
\r
213 } catch (Exception ex) {
\r
214 String msg = " Exception in prepareCompletion:" + ex.getMessage()
\r
215 utils.log("DEBUG", msg, isDebugEnabled)
\r
216 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
218 utils.log("DEBUG", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
\r
221 public void prepareFalloutRequest(Execution execution){
\r
222 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
223 utils.log("DEBUG", " *** prepareFalloutRequest *** ", isDebugEnabled)
\r
226 WorkflowException wfex = execution.getVariable("WorkflowException")
\r
227 utils.log("DEBUG", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
\r
228 String requestId = execution.getVariable("msoRequestId")
\r
229 String source = execution.getVariable("source")
\r
230 String requestInfo =
\r
231 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
232 <request-id>${requestId}</request-id>
\r
233 <action>CREATE</action>
\r
234 <source>${source}</source>
\r
237 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
\r
238 execution.setVariable("falloutRequest", falloutRequest)
\r
239 } catch (Exception ex) {
\r
240 utils.log("DEBUG", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
\r
241 String errorException = " Bpmn error encountered in CreateServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
\r
242 String requestId = execution.getVariable("msoRequestId")
\r
243 String falloutRequest =
\r
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>
\r
249 <action>CREATE</action>
\r
250 <source>VID</source>
\r
252 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
253 <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
\r
254 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
\r
255 </aetgt:WorkflowException>
\r
256 </aetgt:FalloutHandlerRequest>"""
\r
258 execution.setVariable("falloutRequest", falloutRequest)
\r
260 utils.log("DEBUG", "*** Exit prepareFalloutRequest ***", isDebugEnabled)
\r