2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 CMCC. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.scripts
25 import static org.apache.commons.lang3.StringUtils.*
27 import org.camunda.bpm.engine.delegate.BpmnError
28 import org.camunda.bpm.engine.delegate.DelegateExecution
29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.onap.so.bpmn.common.scripts.ExceptionUtil
31 import org.onap.so.bpmn.common.scripts.MsoUtils
32 import org.onap.so.bpmn.core.WorkflowException
33 import org.onap.so.bpmn.core.json.JsonUtils
34 import org.onap.so.bpmn.core.UrnPropertiesReader
35 import org.onap.so.logger.MessageEnum
36 import org.onap.so.logger.MsoLogger
37 import org.slf4j.Logger
38 import org.slf4j.LoggerFactory
39 import org.onap.so.utils.UUIDChecker
40 import org.springframework.web.util.UriUtils
44 * This groovy class supports the <class>ScaleCustomE2EServiceInstance.bpmn</class> process.
47 public class ScaleCustomE2EServiceInstance extends AbstractServiceTaskProcessor {
48 private static final Logger logger = LoggerFactory.getLogger( ScaleCustomE2EServiceInstance.class);
50 String Prefix = "CRESI_"
51 ExceptionUtil exceptionUtil = new ExceptionUtil()
52 JsonUtils jsonUtil = new JsonUtils()
54 public void preProcessRequest(DelegateExecution execution) {
55 execution.setVariable("prefix", Prefix)
57 logger.trace("preProcessRequest() ")
61 String siRequest = execution.getVariable("bpmnRequest")
62 logger.debug(siRequest)
64 String requestId = execution.getVariable("mso-request-id")
65 execution.setVariable("msoRequestId", requestId)
66 logger.debug("Input Request:" + siRequest + " reqId:" + requestId)
68 String serviceInstanceId = execution.getVariable("serviceInstanceId")
69 if (isBlank(serviceInstanceId)) {
70 serviceInstanceId = "NULL".toString()
72 logger.debug("Generated new Service Instance:" + serviceInstanceId)
73 serviceInstanceId = UriUtils.encode(serviceInstanceId, "UTF-8")
74 execution.setVariable("serviceInstanceId", serviceInstanceId)
76 // service instance ID is also service ID
77 execution.setVariable("serviceId", serviceInstanceId)
78 // service instance name
79 String serviceInstanceName = jsonUtil.getJsonValue(siRequest, "service.serviceInstanceName")
80 execution.setVariable("serviceInstanceName", serviceInstanceName)
82 // service instance name
83 String serviceType = jsonUtil.getJsonValue(siRequest, "service.serviceType")
84 execution.setVariable("serviceType", serviceType)
86 // operationa ID (key)
87 //String operationKey = UUIDChecker.generateUUID(msoLogger)
88 String operationId = jsonUtil.getJsonValue(siRequest, "operationId")
89 execution.setVariable("operationId", operationId)
90 logger.debug("Input Request:" + siRequest + " operationId:" + operationId)
93 String resources = jsonUtil.getJsonValue(siRequest, "service.resources")
94 execution.setVariable("resources", resources)
97 String nodeTemplateUUID = UUIDChecker.getUUID();
98 execution.setVariable("nodeTemplateUUID", nodeTemplateUUID)
101 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "service.globalSubscriberId")
102 if (isBlank(globalSubscriberId)) {
103 msg = "Input globalSubscriberId' is null"
104 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
106 execution.setVariable("globalSubscriberId", globalSubscriberId)
109 String requestDescription = "request description for test"
110 execution.setVariable("requestDescription", requestDescription)
111 execution.setVariable("URN_mso_adapters_openecomp_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
113 } catch (BpmnError e) {
115 } catch (Exception ex) {
116 msg = "Exception in preProcessRequest " + ex.getMessage()
118 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
120 logger.trace("Exit preProcessRequest ")
123 public void sendSyncResponse(DelegateExecution execution) {
124 logger.trace("sendSyncResponse ")
127 String operationId = execution.getVariable("operationId")
128 String serviceInstanceId = execution.getVariable("serviceInstanceId")
129 // RESTResponse for API Handler (APIH) Reply Task
130 String scaleServiceRestRequest = """{"operationId":"${operationId}"}""".trim()
131 logger.debug(" sendSyncResponse to APIH:" + "\n" + scaleServiceRestRequest)
132 sendWorkflowResponse(execution, 202, scaleServiceRestRequest)
133 execution.setVariable("sentSyncResponse", true)
135 } catch (Exception ex) {
136 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
138 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
140 logger.trace("Exit sendSyncResopnse ")
144 public void sendSyncError(DelegateExecution execution) {
145 logger.trace("sendSyncError ")
148 String errorMessage = ""
149 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
150 WorkflowException wfe = execution.getVariable("WorkflowException")
151 errorMessage = wfe.getErrorMessage()
153 errorMessage = "Sending Sync Error."
156 String buildworkflowException =
157 """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
158 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
159 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
160 </aetgt:WorkflowException>"""
162 logger.debug(buildworkflowException)
163 sendWorkflowResponse(execution, 500, buildworkflowException)
165 } catch (Exception ex) {
166 logger.debug(" Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
171 public void prepareCompletionRequest(DelegateExecution execution) {
172 logger.trace("prepareCompletion ")
175 String requestId = execution.getVariable("msoRequestId")
176 String serviceInstanceId = execution.getVariable("serviceInstanceId")
177 String source = execution.getVariable("source")
179 String msoCompletionRequest =
180 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
181 xmlns:ns="http://org.onap/so/request/types/v1">
182 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
183 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
184 <action>SCALE</action>
185 <source>${MsoUtils.xmlEscape(source)}</source>
187 <status-message>Service Instance was scaled successfully.</status-message>
188 <serviceInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceInstanceId>
189 <mso-bpel-name>ScaleGenericALaCarteServiceInstance</mso-bpel-name>
190 </aetgt:MsoCompletionRequest>"""
193 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
195 execution.setVariable("CompleteMsoProcessRequest", xmlMsoCompletionRequest)
196 logger.debug(" Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
198 } catch (Exception ex) {
199 String msg = " Exception in prepareCompletion:" + ex.getMessage()
201 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
203 logger.trace("Exit prepareCompletionRequest ")
206 public void prepareFalloutRequest(DelegateExecution execution) {
207 logger.trace("prepareFalloutRequest ")
210 WorkflowException wfex = execution.getVariable("WorkflowException")
211 logger.debug(" Input Workflow Exception: " + wfex.toString())
212 String requestId = execution.getVariable("msoRequestId")
213 String source = execution.getVariable("source")
215 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
216 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
217 <action>SCALE</action>
218 <source>${MsoUtils.xmlEscape(source)}</source>
221 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
222 execution.setVariable("falloutRequest", falloutRequest)
223 } catch (Exception ex) {
224 logger.debug("Exception prepareFalloutRequest:" + ex.getMessage())
225 String errorException = " Bpmn error encountered in ScaleGenericALaCarteServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
226 String requestId = execution.getVariable("msoRequestId")
227 String falloutRequest =
228 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
229 xmlns:ns="http://org.onap/so/request/types/v1"
230 xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
231 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
232 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
233 <action>SCALE</action>
236 <aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
237 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorException)}</aetgt:ErrorMessage>
238 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
239 </aetgt:WorkflowException>
240 </aetgt:FalloutHandlerRequest>"""
242 execution.setVariable("falloutRequest", falloutRequest)
244 logger.trace("Exit prepareFalloutRequest ")
249 * Init the service Operation Status
251 public void prepareInitServiceOperationStatus(DelegateExecution execution){
252 logger.trace("STARTED prepareInitServiceOperationStatus Process ")
254 String serviceId = execution.getVariable("serviceInstanceId")
255 //String serviceName = execution.getVariable("serviceInstanceName")
256 String operationId = execution.getVariable("operationId")
257 String operationType = "SCALE"
259 String result = "processing"
260 String progress = "0"
262 String operationContent = "Prepare service scaling"
263 execution.setVariable("serviceInstanceId", serviceId)
264 execution.setVariable("operationId", operationId)
265 execution.setVariable("operationType", operationType)
267 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
268 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
269 logger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
272 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
273 xmlns:ns="http://org.onap.so/requestsdb">
276 <ns:updateServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
277 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
278 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
279 <serviceName>${MsoUtils.xmlEscape(serviceName)}</serviceName>
280 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
281 <userId>${MsoUtils.xmlEscape(userId)}</userId>
282 <result>${MsoUtils.xmlEscape(result)}</result>
283 <operationContent>${MsoUtils.xmlEscape(operationContent)}</operationContent>
284 <progress>${MsoUtils.xmlEscape(progress)}</progress>
285 <reason>${MsoUtils.xmlEscape(reason)}</reason>
286 </ns:updateServiceOperationStatus>
288 </soapenv:Envelope>"""
290 payload = utils.formatXml(payload)
291 execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
292 logger.info("Outgoing updateServiceOperStatusRequest: \n" + payload)
293 logger.debug("Scale network service updateServiceOperStatusRequest Request: " + payload)
296 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
297 "Exception Occured Processing prepareInitServiceOperationStatus.", "BPMN",
298 MsoLogger.ErrorCode.UnknownError.getValue(), e);
299 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
301 logger.trace("COMPLETED prepareInitServiceOperationStatus Process ")