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 com.google.common.base.Strings
26 import org.onap.so.logger.ErrorCode
28 import static org.apache.commons.lang3.StringUtils.*
30 import org.camunda.bpm.engine.delegate.BpmnError
31 import org.camunda.bpm.engine.delegate.DelegateExecution
32 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
33 import org.onap.so.bpmn.common.scripts.ExceptionUtil
34 import org.onap.so.bpmn.common.scripts.MsoUtils
35 import org.onap.so.bpmn.core.WorkflowException
36 import org.onap.so.bpmn.core.json.JsonUtils
37 import org.onap.so.bpmn.core.UrnPropertiesReader
38 import org.onap.so.logger.MessageEnum
39 import org.slf4j.Logger
40 import org.slf4j.LoggerFactory
41 import org.onap.so.utils.UUIDChecker
42 import org.springframework.web.util.UriUtils
46 * This groovy class supports the <class>ScaleCustomE2EServiceInstance.bpmn</class> process.
49 public class ScaleCustomE2EServiceInstance extends AbstractServiceTaskProcessor {
50 private static final Logger logger = LoggerFactory.getLogger( ScaleCustomE2EServiceInstance.class);
52 String Prefix = "CRESI_"
53 ExceptionUtil exceptionUtil = new ExceptionUtil()
54 JsonUtils jsonUtil = new JsonUtils()
56 public void preProcessRequest(DelegateExecution execution) {
57 execution.setVariable("prefix", Prefix)
59 logger.trace("preProcessRequest() ")
63 String siRequest = execution.getVariable("bpmnRequest")
64 logger.debug(siRequest)
66 String requestId = execution.getVariable("mso-request-id")
67 execution.setVariable("msoRequestId", requestId)
68 logger.debug("Input Request:" + siRequest + " reqId:" + requestId)
70 String serviceInstanceId = execution.getVariable("serviceInstanceId")
71 if (isBlank(serviceInstanceId)) {
72 serviceInstanceId = "NULL".toString()
74 logger.debug("Generated new Service Instance:" + serviceInstanceId)
75 serviceInstanceId = UriUtils.encode(serviceInstanceId, "UTF-8")
76 execution.setVariable("serviceInstanceId", serviceInstanceId)
78 // service instance ID is also service ID
79 execution.setVariable("serviceId", serviceInstanceId)
80 // service instance name
81 String serviceInstanceName = jsonUtil.getJsonValue(siRequest, "service.serviceInstanceName")
82 execution.setVariable("serviceInstanceName", serviceInstanceName)
84 // service instance name
85 String serviceType = jsonUtil.getJsonValue(siRequest, "service.serviceType")
86 execution.setVariable("serviceType", serviceType)
88 // operationa ID (key)
89 //String operationKey = UUIDChecker.generateUUID(msoLogger)
90 String operationId = jsonUtil.getJsonValue(siRequest, "operationId")
91 execution.setVariable("operationId", operationId)
92 logger.debug("Input Request:" + siRequest + " operationId:" + operationId)
95 String resources = jsonUtil.getJsonValue(siRequest, "service.resources")
96 execution.setVariable("resources", resources)
99 String nodeTemplateUUID = UUIDChecker.getUUID();
100 execution.setVariable("nodeTemplateUUID", nodeTemplateUUID)
103 String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "service.globalSubscriberId")
104 if (isBlank(globalSubscriberId)) {
105 msg = "Input globalSubscriberId' is null"
106 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
108 execution.setVariable("globalSubscriberId", globalSubscriberId)
111 String requestDescription = "request description for test"
112 execution.setVariable("requestDescription", requestDescription)
113 execution.setVariable("URN_mso_adapters_openecomp_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
115 } catch (BpmnError e) {
117 } catch (Exception ex) {
118 msg = "Exception in preProcessRequest " + ex.getMessage()
120 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
122 logger.trace("Exit preProcessRequest ")
125 public void sendSyncResponse(DelegateExecution execution) {
126 logger.trace("sendSyncResponse ")
129 String operationId = execution.getVariable("operationId")
130 String serviceInstanceId = execution.getVariable("serviceInstanceId")
131 // RESTResponse for API Handler (APIH) Reply Task
132 String scaleServiceRestRequest = """{"operationId":"${operationId}"}""".trim()
133 logger.debug(" sendSyncResponse to APIH:" + "\n" + scaleServiceRestRequest)
134 sendWorkflowResponse(execution, 202, scaleServiceRestRequest)
135 execution.setVariable("sentSyncResponse", true)
137 } catch (Exception ex) {
138 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
140 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
142 logger.trace("Exit sendSyncResopnse ")
146 public void sendSyncError(DelegateExecution execution) {
147 logger.trace("sendSyncError ")
150 String errorMessage = ""
151 if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
152 WorkflowException wfe = execution.getVariable("WorkflowException")
153 errorMessage = wfe.getErrorMessage()
155 errorMessage = "Sending Sync Error."
158 String buildworkflowException =
159 """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
160 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
161 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
162 </aetgt:WorkflowException>"""
164 logger.debug(buildworkflowException)
165 sendWorkflowResponse(execution, 500, buildworkflowException)
167 } catch (Exception ex) {
168 logger.debug(" Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
173 public void prepareCompletionRequest(DelegateExecution execution) {
174 logger.trace("prepareCompletion ")
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.onap/so/workflow/schema/v1"
183 xmlns:ns="http://org.onap/so/request/types/v1">
184 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
185 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
186 <action>SCALE</action>
187 <source>${MsoUtils.xmlEscape(source)}</source>
189 <status-message>Service Instance was scaled successfully.</status-message>
190 <serviceInstanceId>${MsoUtils.xmlEscape(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 logger.debug(" Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
200 } catch (Exception ex) {
201 String msg = " Exception in prepareCompletion:" + ex.getMessage()
203 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
205 logger.trace("Exit prepareCompletionRequest ")
208 public void prepareFalloutRequest(DelegateExecution execution) {
209 logger.trace("prepareFalloutRequest ")
212 WorkflowException wfex = execution.getVariable("WorkflowException")
213 logger.debug(" Input Workflow Exception: " + wfex.toString())
214 String requestId = execution.getVariable("msoRequestId")
215 String source = execution.getVariable("source")
217 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
218 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
219 <action>SCALE</action>
220 <source>${MsoUtils.xmlEscape(source)}</source>
223 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
224 execution.setVariable("falloutRequest", falloutRequest)
225 } catch (Exception ex) {
226 logger.debug("Exception prepareFalloutRequest:" + ex.getMessage())
227 String errorException = " Bpmn error encountered in ScaleGenericALaCarteServiceInstance flow. FalloutHandlerRequest, buildErrorResponse() - " + ex.getMessage()
228 String requestId = execution.getVariable("msoRequestId")
229 String falloutRequest =
230 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
231 xmlns:ns="http://org.onap/so/request/types/v1"
232 xmlns:wfsch="http://org.onap/so/workflow/schema/v1">
233 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
234 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
235 <action>SCALE</action>
238 <aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
239 <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorException)}</aetgt:ErrorMessage>
240 <aetgt:ErrorCode>7000</aetgt:ErrorCode>
241 </aetgt:WorkflowException>
242 </aetgt:FalloutHandlerRequest>"""
244 execution.setVariable("falloutRequest", falloutRequest)
246 logger.trace("Exit prepareFalloutRequest ")
251 * Init the service Operation Status
253 public void prepareInitServiceOperationStatus(DelegateExecution execution){
254 logger.trace("STARTED prepareInitServiceOperationStatus Process ")
256 String serviceId = execution.getVariable("serviceInstanceId")
257 //String serviceName = execution.getVariable("serviceInstanceName")
258 String operationId = execution.getVariable("operationId")
259 String operationType = "SCALE"
261 String result = "processing"
262 String progress = "0"
264 String operationContent = "Prepare service scaling"
265 execution.setVariable("serviceInstanceId", serviceId)
266 execution.setVariable("operationId", operationId)
267 execution.setVariable("operationType", operationType)
269 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
270 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
271 logger.info("DB Adapter Endpoint is: " + dbAdapterEndpoint)
274 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
275 xmlns:ns="http://org.onap.so/requestsdb">
278 <ns:updateServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
279 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
280 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
281 <serviceName>${MsoUtils.xmlEscape(serviceName)}</serviceName>
282 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
283 <userId>${MsoUtils.xmlEscape(userId)}</userId>
284 <result>${MsoUtils.xmlEscape(result)}</result>
285 <operationContent>${MsoUtils.xmlEscape(operationContent)}</operationContent>
286 <progress>${MsoUtils.xmlEscape(progress)}</progress>
287 <reason>${MsoUtils.xmlEscape(reason)}</reason>
288 </ns:updateServiceOperationStatus>
290 </soapenv:Envelope>"""
292 payload = utils.formatXml(payload)
293 execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
294 logger.info("Outgoing updateServiceOperStatusRequest: \n" + payload)
295 logger.debug("Scale network service updateServiceOperStatusRequest Request: " + payload)
298 logger.error(Strings.repeat("{} ", 5), MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
299 "Exception Occured Processing prepareInitServiceOperationStatus.", "BPMN",
300 ErrorCode.UnknownError.getValue(), e);
301 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
303 logger.trace("COMPLETED prepareInitServiceOperationStatus Process ")