2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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
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.List;
34 import java.util.UUID;
36 import org.camunda.bpm.engine.delegate.BpmnError
37 import org.camunda.bpm.engine.delegate.DelegateExecution
38 import org.apache.commons.lang3.*
39 import org.apache.commons.codec.binary.Base64;
40 import org.springframework.web.util.UriUtils
43 * This groovy class supports the <class>UpdateCustomE2EServiceInstance.bpmn</class> process.
44 * AlaCarte flow for 1702 ServiceInstance Update
47 public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor {
48 String Prefix="UPDSI_"
49 ExceptionUtil exceptionUtil = new ExceptionUtil()
50 JsonUtils jsonUtil = new JsonUtils()
53 public void preProcessRequest (DelegateExecution execution) {
54 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
55 execution.setVariable("prefix",Prefix)
57 utils.log("INFO", " *** preProcessRequest() *** ", isDebugEnabled)
61 String siRequest = execution.getVariable("bpmnRequest")
62 utils.logAudit(siRequest)
64 String requestId = execution.getVariable("mso-request-id")
65 execution.setVariable("msoRequestId", requestId)
66 utils.log("INFO", "Input Request:" + siRequest + " reqId:" + requestId, isDebugEnabled)
68 String serviceInstanceId = execution.getVariable("serviceInstanceId")
69 if (isBlank(serviceInstanceId)) {
70 msg = "Input serviceInstanceId' is null"
71 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
75 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "requestDetails.subscriberInfo.globalSubscriberId")
76 if (isBlank(globalSubscriberId)) {
77 msg = "Input globalSubscriberId' is null"
78 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
80 execution.setVariable("globalSubscriberId", globalSubscriberId)
84 execution.setVariable("source", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.source"))
85 execution.setVariable("serviceInstanceName", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.instanceName"))
86 execution.setVariable("disableRollback", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.suppressRollback"))
87 String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")
88 if (isBlank(productFamilyId))
90 msg = "Input productFamilyId is null"
91 utils.log("INFO", msg, isDebugEnabled)
92 //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
94 execution.setVariable("productFamilyId", productFamilyId)
96 String userParams = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.userParams")
97 utils.log("INFO", "userParams:" + userParams, isDebugEnabled)
98 List<String> paramList = jsonUtil.StringArrayToList(execution, userParams)
99 String uuiRequest = jsonUtil.getJsonValue(paramList.get(0), "UUIRequest")
101 if (isBlank(uuiRequest)) {
102 msg = "Input uuiRequest is null"
103 utils.log("INFO", msg, isDebugEnabled)
104 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
107 execution.setVariable("uuiRequest", uuiRequest)
110 utils.log("INFO", "uuiRequest:\n" + uuiRequest, isDebugEnabled)
113 String serviceType = jsonUtil.getJsonValue(uuiRequest, "service.parameters.serviceType")
114 if (isBlank(serviceType)) {
115 msg = "Input serviceType is null"
116 utils.log("INFO", msg, isDebugEnabled)
117 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
119 execution.setVariable("serviceType", serviceType)
123 String operationId = jsonUtil.getJsonValue(siRequest, "operationId")
124 if (isBlank(operationId)) {
125 operationId = UUID.randomUUID().toString()
127 execution.setVariable("operationId", operationId)
128 execution.setVariable("operationType", "UPDATE")
130 execution.setVariable("URN_mso_adapters_openecomp_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
132 } catch (BpmnError e) {
134 } catch (Exception ex){
135 msg = "Exception in preProcessRequest " + ex.getMessage()
136 utils.log("INFO", msg, isDebugEnabled)
137 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
139 utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)
142 public void sendSyncResponse (DelegateExecution execution) {
143 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
144 utils.log("INFO", " *** sendSyncResponse *** ", isDebugEnabled)
147 String operationId = execution.getVariable("operationId")
148 String serviceInstanceId = execution.getVariable("serviceInstanceId")
149 // RESTResponse for API Handler (APIH) Reply Task
150 String updateServiceRestRequest = """{"service":{"serviceId":"${serviceInstanceId}","operationId":"${operationId}"}}""".trim()
151 utils.log("INFO", " sendSyncResponse to APIH:" + "\n" + updateServiceRestRequest, isDebugEnabled)
152 sendWorkflowResponse(execution, 202, updateServiceRestRequest)
153 execution.setVariable("sentSyncResponse", true)
155 } catch (Exception ex) {
156 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
157 utils.log("INFO", msg, isDebugEnabled)
158 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
160 utils.log("INFO"," ***** Exit sendSyncResopnse *****", isDebugEnabled)
164 public void sendSyncError (DelegateExecution execution) {
165 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
166 utils.log("INFO", " *** sendSyncError *** ", isDebugEnabled)
169 String errorMessage = ""
170 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
171 WorkflowException wfe = execution.getVariable("WorkflowException")
172 errorMessage = wfe.getErrorMessage()
174 errorMessage = "Sending Sync Error."
177 String buildworkflowException =
178 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
179 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
180 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
181 </aetgt:WorkflowException>"""
183 utils.logAudit(buildworkflowException)
184 sendWorkflowResponse(execution, 500, buildworkflowException)
186 } catch (Exception ex) {
187 utils.log("INFO", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
192 public void prepareCompletionRequest (DelegateExecution execution) {
193 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
194 utils.log("INFO", " *** prepareCompletion *** ", isDebugEnabled)
197 String requestId = execution.getVariable("msoRequestId")
198 String serviceInstanceId = execution.getVariable("serviceInstanceId")
199 String source = execution.getVariable("source")
201 String msoCompletionRequest =
202 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
203 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
204 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
205 <request-id>${requestId}</request-id>
206 <action>UPDATE</action>
207 <source>${source}</source>
209 <status-message>Service Instance was updated successfully.</status-message>
210 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
211 <mso-bpel-name>UpdateGenericALaCarteServiceInstance</mso-bpel-name>
212 </aetgt:MsoCompletionRequest>"""
215 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
217 execution.setVariable("completionRequest", xmlMsoCompletionRequest)
218 utils.log("INFO", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
220 } catch (Exception ex) {
221 String msg = " Exception in prepareCompletion:" + ex.getMessage()
222 utils.log("INFO", msg, isDebugEnabled)
223 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
225 utils.log("INFO", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
228 public void prepareFalloutRequest(DelegateExecution execution){
229 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
230 utils.log("INFO", " *** prepareFalloutRequest *** ", isDebugEnabled)
233 WorkflowException wfex = execution.getVariable("WorkflowException")
234 utils.log("INFO", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
235 String requestId = execution.getVariable("msoRequestId")
236 String source = execution.getVariable("source")
238 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
239 <request-id>${requestId}</request-id>
240 <action>UPDATE</action>
241 <source>${source}</source>
244 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
245 execution.setVariable("falloutRequest", falloutRequest)
246 } catch (Exception ex) {
247 utils.log("INFO", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
248 String errorException = " Bpmn error encountered in UpdateGenericALaCarteServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
249 String requestId = execution.getVariable("msoRequestId")
250 String falloutRequest =
251 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
252 xmlns:ns="http://org.openecomp/mso/request/types/v1"
\r
253 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
\r
254 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
255 <request-id>${requestId}</request-id>
256 <action>UPDATE</action>
259 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
\r
260 <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
261 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
262 </aetgt:WorkflowException>
263 </aetgt:FalloutHandlerRequest>"""
265 execution.setVariable("falloutRequest", falloutRequest)
267 utils.log("INFO", "*** Exit prepareFalloutRequest ***", isDebugEnabled)