2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 CMCC. 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 org.camunda.bpm.engine.delegate.DelegateExecution
25 import static org.apache.commons.lang3.StringUtils.*
26 import org.openecomp.mso.logger.MsoLogger
27 import org.openecomp.mso.utils.UUIDChecker
28 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
29 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
30 import org.openecomp.mso.bpmn.core.WorkflowException
31 import org.openecomp.mso.bpmn.core.json.JsonUtils
32 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
34 import org.camunda.bpm.engine.delegate.BpmnError
35 import org.camunda.bpm.engine.runtime.Execution
37 import org.springframework.web.util.UriUtils
41 * This groovy class supports the <class>ScaleCustomE2EServiceInstance.bpmn</class> process.
44 public class ScaleCustomE2EServiceInstance extends AbstractServiceTaskProcessor {
45 String Prefix = "CRESI_"
46 ExceptionUtil exceptionUtil = new ExceptionUtil()
47 JsonUtils jsonUtil = new JsonUtils()
48 private MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH);
50 public void preProcessRequest(DelegateExecution execution) {
51 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
52 execution.setVariable("prefix", Prefix)
54 utils.log("DEBUG", " *** preProcessRequest() *** ", isDebugEnabled)
58 String siRequest = execution.getVariable("bpmnRequest")
59 utils.logAudit(siRequest)
61 String requestId = execution.getVariable("mso-request-id")
62 execution.setVariable("msoRequestId", requestId)
63 utils.log("DEBUG", "Input Request:" + siRequest + " reqId:" + requestId, isDebugEnabled)
65 String serviceInstanceId = execution.getVariable("serviceInstanceId")
66 if (isBlank(serviceInstanceId)) {
67 serviceInstanceId = "NULL".toString()
69 utils.log("DEBUG", "Generated new Service Instance:" + serviceInstanceId, isDebugEnabled)
70 serviceInstanceId = UriUtils.encode(serviceInstanceId, "UTF-8")
71 execution.setVariable("serviceInstanceId", serviceInstanceId)
73 // service instance ID is also service ID
74 execution.setVariable("serviceId", serviceInstanceId)
75 // service instance name
76 String serviceInstanceName = jsonUtil.getJsonValue(siRequest, "service.serviceInstanceName")
77 execution.setVariable("serviceInstanceName", serviceInstanceName)
79 // service instance name
80 String serviceType = jsonUtil.getJsonValue(siRequest, "service.serviceType")
81 execution.setVariable("serviceType", serviceType)
83 // operationa ID (key)
84 //String operationKey = UUIDChecker.generateUUID(msoLogger)
85 String operationId = jsonUtil.getJsonValue(siRequest, "operationId")
86 execution.setVariable("operationId", operationId)
87 utils.log("DEBUG", "Input Request:" + siRequest + " operationId:" + operationId, isDebugEnabled)
90 String resources = jsonUtil.getJsonValue(siRequest, "service.resources")
91 execution.setVariable("resources", resources)
94 String nodeTemplateUUID = UUIDChecker.generateUUID(msoLogger)
95 execution.setVariable("nodeTemplateUUID", nodeTemplateUUID)
98 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "service.globalSubscriberId")
99 if (isBlank(globalSubscriberId)) {
100 msg = "Input globalSubscriberId' is null"
101 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
103 execution.setVariable("globalSubscriberId", globalSubscriberId)
106 String requestDescription = "request description for test"
107 execution.setVariable("requestDescription", requestDescription)
108 execution.setVariable("URN_mso_adapters_openecomp_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
110 } catch (BpmnError e) {
112 } catch (Exception ex) {
113 msg = "Exception in preProcessRequest " + ex.getMessage()
114 utils.log("DEBUG", msg, isDebugEnabled)
115 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
117 utils.log("DEBUG", " ***** Exit preProcessRequest *****", isDebugEnabled)
120 public void sendSyncResponse(DelegateExecution execution) {
121 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
122 utils.log("DEBUG", " *** sendSyncResponse *** ", isDebugEnabled)
125 String operationId = execution.getVariable("operationId")
126 String serviceInstanceId = execution.getVariable("serviceInstanceId")
127 // RESTResponse for API Handler (APIH) Reply Task
128 String scaleServiceRestRequest = """{"service":{"serviceId":"${serviceInstanceId}","operationId":"${
131 utils.log("DEBUG", " sendSyncResponse to APIH:" + "\n" + scaleServiceRestRequest, isDebugEnabled)
132 sendWorkflowResponse(execution, 202, scaleServiceRestRequest)
133 execution.setVariable("sentSyncResponse", true)
135 } catch (Exception ex) {
136 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
137 utils.log("DEBUG", msg, isDebugEnabled)
138 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
140 utils.log("DEBUG", " ***** Exit sendSyncResopnse *****", isDebugEnabled)
144 public void sendSyncError(DelegateExecution execution) {
145 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
146 utils.log("DEBUG", " *** sendSyncError *** ", isDebugEnabled)
149 String errorMessage = ""
150 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
151 WorkflowException wfe = execution.getVariable("WorkflowException")
152 errorMessage = wfe.getErrorMessage()
154 errorMessage = "Sending Sync Error."
157 String buildworkflowException =
158 """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
159 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
160 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
161 </aetgt:WorkflowException>"""
163 utils.logAudit(buildworkflowException)
164 sendWorkflowResponse(execution, 500, buildworkflowException)
166 } catch (Exception ex) {
167 utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
172 public void prepareCompletionRequest(DelegateExecution execution) {
173 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
174 utils.log("DEBUG", " *** prepareCompletion *** ", isDebugEnabled)
177 String requestId = execution.getVariable("msoRequestId")
178 String serviceInstanceId = execution.getVariable("serviceInstanceId")
179 String source = execution.getVariable("source")
181 String msoCompletionRequest =
182 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
183 xmlns:ns="http://org.openecomp/mso/request/types/v1">
184 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
185 <request-id>${requestId}</request-id>
186 <action>SCALE</action>
187 <source>${source}</source>
189 <status-message>Service Instance was scaled successfully.</status-message>
190 <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
191 <mso-bpel-name>ScaleGenericALaCarteServiceInstance</mso-bpel-name>
192 </aetgt:MsoCompletionRequest>"""
195 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
197 execution.setVariable("CompleteMsoProcessRequest", xmlMsoCompletionRequest)
198 utils.log("DEBUG", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
200 } catch (Exception ex) {
201 String msg = " Exception in prepareCompletion:" + ex.getMessage()
202 utils.log("DEBUG", msg, isDebugEnabled)
203 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
205 utils.log("DEBUG", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
208 public void prepareFalloutRequest(DelegateExecution execution) {
209 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
210 utils.log("DEBUG", " *** prepareFalloutRequest *** ", isDebugEnabled)
213 WorkflowException wfex = execution.getVariable("WorkflowException")
214 utils.log("DEBUG", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
215 String requestId = execution.getVariable("msoRequestId")
216 String source = execution.getVariable("source")
218 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
219 <request-id>${requestId}</request-id>
220 <action>SCALE</action>
221 <source>${source}</source>
224 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
225 execution.setVariable("falloutRequest", falloutRequest)
226 } catch (Exception ex) {
227 utils.log("DEBUG", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
228 String errorException = " Bpmn error encountered in ScaleGenericALaCarteServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
229 String requestId = execution.getVariable("msoRequestId")
230 String falloutRequest =
231 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
232 xmlns:ns="http://org.openecomp/mso/request/types/v1"
233 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
234 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
235 <request-id>${requestId}</request-id>
236 <action>SCALE</action>
239 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">
240 <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
241 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
242 </aetgt:WorkflowException>
243 </aetgt:FalloutHandlerRequest>"""
245 execution.setVariable("falloutRequest", falloutRequest)
247 utils.log("DEBUG", "*** Exit prepareFalloutRequest ***", isDebugEnabled)
252 * Init the service Operation Status
254 public void prepareInitServiceOperationStatus(DelegateExecution execution){
255 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
256 utils.log("INFO", " ======== STARTED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)
258 String serviceId = execution.getVariable("serviceInstanceId")
259 String serviceName = execution.getVariable("serviceInstanceName")
260 String operationId = execution.getVariable("operationId")
261 String operationType = "SCALE"
263 String result = "processing"
264 String progress = "0"
266 String operationContent = "Prepare service scaling"
267 execution.setVariable("serviceInstanceId", serviceId)
268 execution.setVariable("operationId", operationId)
269 execution.setVariable("operationType", operationType)
271 def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
272 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
273 utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
276 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
277 xmlns:ns="http://org.openecomp.mso/requestsdb">
280 <ns:updateServiceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
281 <serviceId>${serviceId}</serviceId>
282 <operationId>${operationId}</operationId>
283 <serviceName>${serviceName}</serviceName>
284 <operationType>${operationType}</operationType>
285 <userId>${userId}</userId>
286 <result>${result}</result>
287 <operationContent>${operationContent}</operationContent>
288 <progress>${progress}</progress>
289 <reason>${reason}</reason>
290 </ns:updateServiceOperationStatus>
292 </soapenv:Envelope>"""
294 payload = utils.formatXml(payload)
295 execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
296 utils.log("INFO", "Outgoing updateServiceOperStatusRequest: \n" + payload, isDebugEnabled)
297 utils.logAudit("Scale network service updateServiceOperStatusRequest Request: " + payload)
300 utils.log("ERROR", "Exception Occured Processing prepareInitServiceOperationStatus. Exception is:\n" + e, isDebugEnabled)
301 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
303 utils.log("INFO", "======== COMPLETED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)