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.onap.so.bpmn.infrastructure.scripts
23 import static org.apache.commons.lang3.StringUtils.*
25 import org.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.delegate.DelegateExecution
27 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil
29 import org.onap.so.bpmn.common.scripts.MsoUtils
30 import org.onap.so.bpmn.core.WorkflowException
31 import org.onap.so.bpmn.core.json.JsonUtils
32 import org.onap.so.bpmn.core.UrnPropertiesReader
33 import org.onap.so.logger.MessageEnum
34 import org.onap.so.logger.MsoLogger
35 import org.onap.so.utils.UUIDChecker
36 import org.springframework.web.util.UriUtils
40 * This groovy class supports the <class>ScaleCustomE2EServiceInstance.bpmn</class> process.
43 public class ScaleCustomE2EServiceInstance extends AbstractServiceTaskProcessor {
44 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ScaleCustomE2EServiceInstance.class);
46 String Prefix = "CRESI_"
47 ExceptionUtil exceptionUtil = new ExceptionUtil()
48 JsonUtils jsonUtil = new JsonUtils()
50 public void preProcessRequest(DelegateExecution execution) {
51 execution.setVariable("prefix", Prefix)
53 msoLogger.trace("preProcessRequest() ")
57 String siRequest = execution.getVariable("bpmnRequest")
58 msoLogger.debug(siRequest)
60 String requestId = execution.getVariable("mso-request-id")
61 execution.setVariable("msoRequestId", requestId)
62 msoLogger.debug("Input Request:" + siRequest + " reqId:" + requestId)
64 String serviceInstanceId = execution.getVariable("serviceInstanceId")
65 if (isBlank(serviceInstanceId)) {
66 serviceInstanceId = "NULL".toString()
68 msoLogger.debug("Generated new Service Instance:" + serviceInstanceId)
69 serviceInstanceId = UriUtils.encode(serviceInstanceId, "UTF-8")
70 execution.setVariable("serviceInstanceId", serviceInstanceId)
72 // service instance ID is also service ID
73 execution.setVariable("serviceId", serviceInstanceId)
74 // service instance name
75 String serviceInstanceName = jsonUtil.getJsonValue(siRequest, "service.serviceInstanceName")
76 execution.setVariable("serviceInstanceName", serviceInstanceName)
78 // service instance name
79 String serviceType = jsonUtil.getJsonValue(siRequest, "service.serviceType")
80 execution.setVariable("serviceType", serviceType)
82 // operationa ID (key)
83 //String operationKey = UUIDChecker.generateUUID(msoLogger)
84 String operationId = jsonUtil.getJsonValue(siRequest, "operationId")
85 execution.setVariable("operationId", operationId)
86 msoLogger.debug("Input Request:" + siRequest + " operationId:" + operationId)
89 String resources = jsonUtil.getJsonValue(siRequest, "service.resources")
90 execution.setVariable("resources", resources)
93 String nodeTemplateUUID = UUIDChecker.generateUUID(msoLogger)
94 execution.setVariable("nodeTemplateUUID", nodeTemplateUUID)
97 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "service.globalSubscriberId")
98 if (isBlank(globalSubscriberId)) {
99 msg = "Input globalSubscriberId' is null"
100 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
102 execution.setVariable("globalSubscriberId", globalSubscriberId)
105 String requestDescription = "request description for test"
106 execution.setVariable("requestDescription", requestDescription)
107 execution.setVariable("URN_mso_adapters_openecomp_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
109 } catch (BpmnError e) {
111 } catch (Exception ex) {
112 msg = "Exception in preProcessRequest " + ex.getMessage()
114 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
116 msoLogger.trace("Exit preProcessRequest ")
119 public void sendSyncResponse(DelegateExecution execution) {
120 msoLogger.trace("sendSyncResponse ")
123 String operationId = execution.getVariable("operationId")
124 String serviceInstanceId = execution.getVariable("serviceInstanceId")
125 // RESTResponse for API Handler (APIH) Reply Task
126 String scaleServiceRestRequest = """{"operationId":"${operationId}"}""".trim()
127 msoLogger.debug(" sendSyncResponse to APIH:" + "\n" + scaleServiceRestRequest)
128 sendWorkflowResponse(execution, 202, scaleServiceRestRequest)
129 execution.setVariable("sentSyncResponse", true)
131 } catch (Exception ex) {
132 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
134 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
136 msoLogger.trace("Exit sendSyncResopnse ")
140 public void sendSyncError(DelegateExecution execution) {
141 msoLogger.trace("sendSyncError ")
144 String errorMessage = ""
145 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
146 WorkflowException wfe = execution.getVariable("WorkflowException")
147 errorMessage = wfe.getErrorMessage()
149 errorMessage = "Sending Sync Error."
152 String buildworkflowException =
153 """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
154 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
155 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
156 </aetgt:WorkflowException>"""
158 msoLogger.debug(buildworkflowException)
159 sendWorkflowResponse(execution, 500, buildworkflowException)
161 } catch (Exception ex) {
162 msoLogger.debug(" Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
167 public void prepareCompletionRequest(DelegateExecution execution) {
168 msoLogger.trace("prepareCompletion ")
171 String requestId = execution.getVariable("msoRequestId")
172 String serviceInstanceId = execution.getVariable("serviceInstanceId")
173 String source = execution.getVariable("source")
175 String msoCompletionRequest =
176 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
177 xmlns:ns="http://org.onap/so/request/types/v1">
178 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
179 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
180 <action>SCALE</action>
181 <source>${MsoUtils.xmlEscape(source)}</source>
183 <status-message>Service Instance was scaled successfully.</status-message>
184 <serviceInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceInstanceId>
185 <mso-bpel-name>ScaleGenericALaCarteServiceInstance</mso-bpel-name>
186 </aetgt:MsoCompletionRequest>"""
189 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
191 execution.setVariable("CompleteMsoProcessRequest", xmlMsoCompletionRequest)
192 msoLogger.debug(" Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
194 } catch (Exception ex) {
195 String msg = " Exception in prepareCompletion:" + ex.getMessage()
197 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
199 msoLogger.trace("Exit prepareCompletionRequest ")
202 public void prepareFalloutRequest(DelegateExecution execution) {
203 msoLogger.trace("prepareFalloutRequest ")
206 WorkflowException wfex = execution.getVariable("WorkflowException")
207 msoLogger.debug(" Input Workflow Exception: " + wfex.toString())
208 String requestId = execution.getVariable("msoRequestId")
209 String source = execution.getVariable("source")
211 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
212 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
213 <action>SCALE</action>
214 <source>${MsoUtils.xmlEscape(source)}</source>
217 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
218 execution.setVariable("falloutRequest", falloutRequest)
219 } catch (Exception ex) {
220 msoLogger.debug("Exception prepareFalloutRequest:" + ex.getMessage())
221 String errorException = " Bpmn error encountered in ScaleGenericALaCarteServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
222 String requestId = execution.getVariable("msoRequestId")
223 String falloutRequest =
224 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
225 xmlns:ns="http://org.onap/so/request/types/v1"
226 xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
227 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
228 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
229 <action>SCALE</action>
232 <aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
233 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorException)}</aetgt:ErrorMessage>
234 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
235 </aetgt:WorkflowException>
236 </aetgt:FalloutHandlerRequest>"""
238 execution.setVariable("falloutRequest", falloutRequest)
240 msoLogger.trace("Exit prepareFalloutRequest ")
245 * Init the service Operation Status
247 public void prepareInitServiceOperationStatus(DelegateExecution execution){
248 msoLogger.trace("STARTED prepareInitServiceOperationStatus Process ")
250 String serviceId = execution.getVariable("serviceInstanceId")
251 //String serviceName = execution.getVariable("serviceInstanceName")
252 String operationId = execution.getVariable("operationId")
253 String operationType = "SCALE"
255 String result = "processing"
256 String progress = "0"
258 String operationContent = "Prepare service scaling"
259 execution.setVariable("serviceInstanceId", serviceId)
260 execution.setVariable("operationId", operationId)
261 execution.setVariable("operationType", operationType)
263 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
264 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
265 msoLogger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
268 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
269 xmlns:ns="http://org.onap.so/requestsdb">
272 <ns:updateServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
273 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
274 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
275 <serviceName>${MsoUtils.xmlEscape(serviceName)}</serviceName>
276 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
277 <userId>${MsoUtils.xmlEscape(userId)}</userId>
278 <result>${MsoUtils.xmlEscape(result)}</result>
279 <operationContent>${MsoUtils.xmlEscape(operationContent)}</operationContent>
280 <progress>${MsoUtils.xmlEscape(progress)}</progress>
281 <reason>${MsoUtils.xmlEscape(reason)}</reason>
282 </ns:updateServiceOperationStatus>
284 </soapenv:Envelope>"""
286 payload = utils.formatXml(payload)
287 execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
288 msoLogger.info("Outgoing updateServiceOperStatusRequest: \n" + payload)
289 msoLogger.debug("Scale network service updateServiceOperStatusRequest Request: " + payload)
292 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing prepareInitServiceOperationStatus.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
293 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
295 msoLogger.trace("COMPLETED prepareInitServiceOperationStatus Process ")