2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. 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.common.workflow.service;
23 import java.util.HashMap;
26 import javax.jws.Oneway;
27 import javax.jws.WebMethod;
28 import javax.jws.WebParam;
29 import javax.jws.WebService;
30 import javax.ws.rs.core.Context;
31 import javax.xml.ws.Action;
32 import javax.xml.ws.RequestWrapper;
33 import javax.xml.ws.WebServiceContext;
35 import org.camunda.bpm.BpmPlatform;
36 import org.camunda.bpm.engine.MismatchingMessageCorrelationException;
37 import org.camunda.bpm.engine.ProcessEngineServices;
38 import org.camunda.bpm.engine.RuntimeService;
39 import org.openecomp.mso.bpmn.common.adapter.vnf.CreateVnfNotification;
40 import org.openecomp.mso.bpmn.common.adapter.vnf.DeleteVnfNotification;
41 import org.openecomp.mso.bpmn.common.adapter.vnf.MsoExceptionCategory;
42 import org.openecomp.mso.bpmn.common.adapter.vnf.QueryVnfNotification;
43 import org.openecomp.mso.bpmn.common.adapter.vnf.RollbackVnfNotification;
44 import org.openecomp.mso.bpmn.common.adapter.vnf.UpdateVnfNotification;
45 import org.openecomp.mso.bpmn.common.adapter.vnf.VnfAdapterNotify;
46 import org.openecomp.mso.bpmn.common.adapter.vnf.VnfRollback;
47 import org.openecomp.mso.bpmn.common.adapter.vnf.VnfStatus;
48 import org.openecomp.mso.logger.MessageEnum;
49 import org.openecomp.mso.logger.MsoLogger;
52 * This is the service class for VnfAdapterNotify
53 * TODO: Add addition VnfAdapterNotify Methods for remaining VnfAdapterNotify operations.
56 @WebService(serviceName = "vnfAdapterNotify", targetNamespace = "http://org.openecomp.mso/vnfNotify")
57 public class VnfAdapterNotifyServiceImpl implements VnfAdapterNotify{
59 private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
61 private final String logMarker = "[VNF-NOTIFY]";
63 @Context WebServiceContext wsContext;
65 private volatile ProcessEngineServices pes4junit = null;
74 @WebMethod(operationName = "rollbackVnfNotification")
76 @RequestWrapper(localName = "rollbackVnfNotification", targetNamespace = "http://org.openecomp.mso/vnfNotify", className = "org.openecomp.mso.adapters.vnf.async.client.RollbackVnfNotification")
77 @Action(input = "http://org.openecomp.mso/notify/adapterNotify/rollbackVnfNotificationRequest")
78 public void rollbackVnfNotification(
79 @WebParam(name = "messageId", targetNamespace = "")
81 @WebParam(name = "completed", targetNamespace = "")
83 @WebParam(name = "exception", targetNamespace = "")
84 MsoExceptionCategory exception,
85 @WebParam(name = "errorMessage", targetNamespace = "")
86 String errorMessage) {
90 RollbackVnfNotification rollbackVnfNotification = new RollbackVnfNotification();
92 rollbackVnfNotification.setMessageId(messageId);
93 rollbackVnfNotification.setCompleted(completed);
94 rollbackVnfNotification.setException(exception);
95 rollbackVnfNotification.setErrorMessage(errorMessage);
97 ProcessEngineServices pes = getProcessEngineServices();
98 RuntimeService runtimeService = pes.getRuntimeService();
100 MsoLogger.setServiceName("MSO." + "vnfAdapterRollback");
101 MsoLogger.setLogContext(messageId, "N/A");
102 msoLogger.debug(logMarker + "Received RollbackVnfNotification" + rollbackVnfNotification.toString());
104 long startTime = System.currentTimeMillis();
107 /* Check to make sure the process instance is ready for correlation*/
108 isReadyforCorrelation(runtimeService, messageId, "rollbackVnfNotificationCallback", "VNFRB_messageId");
110 msoLogger.debug(logMarker + "*** Received MSO rollbackVnfNotification Callback ******");
111 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Call to MSO VnfAdapterNotifyService ");
112 msoLogger.debug(logMarker + "Rollback VNF Notification string:\n" + rollbackVnfNotification.toString());
114 System.out.println("testing ROllbackVnfNotification : " + rollbackVnfNotification.toString());
116 Map<String,Object> variables = new HashMap<String,Object>();
117 variables.put("VNFRB_messageId", messageId );
118 variables.put("rollbackVnfNotificationCallback", rollbackVnfNotification.toString());
120 /*Correlating the response with the running instance*/
122 runtimeService.createMessageCorrelation("rollbackVnfNotificationCallback").setVariables(variables)
123 .processInstanceVariableEquals("VNFRB_messageId", messageId).correlate();
125 msoLogger.debug(logMarker + "***** Completed processing of MSO VnfAdapterNotifyService ******");
126 } catch(MismatchingMessageCorrelationException e) {
127 msoLogger.debug(logMarker + "[CORM]correlation id mismatch");
129 "VNF Adapter Notify Service received a Create VNF Notification request with RequestId '"
131 + "' but that RequestId could not be correlated to any active process - ignoring the request";
133 msoLogger.error (MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
134 MsoLogger.ErrorCode.UnknownError, logMarker + ":" + msg);
137 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
138 logMarker + "Completed the execution of MSO Vnf Adapter Notify for Rollback VNF Notification.");
140 msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
141 logMarker + "Completed the execution of MSO Vnf Adapter Notify for Rollback VNF Notification.", "BPMN",
142 MsoLogger.getServiceName(), "rollbackVnfNotification");
151 * @param errorMessage
160 @WebMethod(operationName = "queryVnfNotification")
162 @RequestWrapper(localName = "queryVnfNotification", targetNamespace = "http://org.openecomp.mso/vnfNotify", className = "org.openecomp.mso.adapters.vnf.async.client.QueryVnfNotification")
163 @Action(input = "http://org.openecomp.mso/notify/adapterNotify/queryVnfNotificationRequest")
164 public void queryVnfNotification(
165 @WebParam(name = "messageId", targetNamespace = "")
167 @WebParam(name = "completed", targetNamespace = "")
169 @WebParam(name = "exception", targetNamespace = "")
170 MsoExceptionCategory exception,
171 @WebParam(name = "errorMessage", targetNamespace = "")
173 @WebParam(name = "vnfExists", targetNamespace = "")
175 @WebParam(name = "vnfId", targetNamespace = "")
177 @WebParam(name = "status", targetNamespace = "")
179 @WebParam(name = "outputs", targetNamespace = "")
180 org.openecomp.mso.bpmn.common.adapter.vnf.QueryVnfNotification.Outputs outputs){
182 QueryVnfNotification queryVnfNotification = new QueryVnfNotification();
184 queryVnfNotification.setMessageId(messageId);
185 queryVnfNotification.setCompleted(completed);
186 queryVnfNotification.setException(exception);
187 queryVnfNotification.setErrorMessage(errorMessage);
188 queryVnfNotification.setVnfExists(vnfExists);
189 queryVnfNotification.setVnfId(vnfId);
190 queryVnfNotification.setStatus(status);
191 queryVnfNotification.setOutputs(outputs);
194 ProcessEngineServices pes = getProcessEngineServices();
195 RuntimeService runtimeService = pes.getRuntimeService();
197 MsoLogger.setServiceName("MSO." + "vnf Adapter Query");
198 MsoLogger.setLogContext(messageId, "N/A");
199 msoLogger.debug(logMarker + "Received QueryVnfNotification" + queryVnfNotification.toString());
201 System.out.println("Received QueryVnfNotification : " + queryVnfNotification.toString());
203 long startTime = System.currentTimeMillis();
206 /* Check to make sure the process instance is ready for correlation*/
207 isReadyforCorrelation(runtimeService, messageId, "queryVnfNotificationCallback", "VNFQ_messageId");
209 msoLogger.debug(logMarker + "*** Received MSO queryVnfNotification Callback ******");
210 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Call to MSO VnfAdapterNotifyService ");
211 msoLogger.debug(logMarker + "Query VNF Notification string:\n" + queryVnfNotification.toString());
213 Map<String,Object> variables = new HashMap<String,Object>();
214 variables.put("VNFQ_messageId", messageId );
215 variables.put("queryVnfNotificationCallback", queryVnfNotification.toString());
217 /*Correlating the response with the running instance*/
219 runtimeService.createMessageCorrelation("queryVnfNotificationCallback").setVariables(variables)
220 .processInstanceVariableEquals("VNFQ_messageId", messageId).correlate();
222 msoLogger.debug(logMarker + "***** Completed processing of MSO VnfAdapterNotifyService ******");
223 } catch(MismatchingMessageCorrelationException e) {
224 msoLogger.debug(logMarker + "[CORM]correlation id mismatch");
226 "VNF Adapter Notify Service received a Query VNF Notification request with RequestId '"
228 + "' but that RequestId could not be correlated to any active process - ignoring the request";
230 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
231 MsoLogger.ErrorCode.UnknownError, logMarker + ":" + msg, e);
234 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
235 logMarker + "Completed the execution of MSO Vnf Adapter Notify for Query VNF Notification.");
245 * @param errorMessage
253 @WebMethod(operationName = "createVnfNotification")
255 @RequestWrapper(localName = "createVnfNotification", targetNamespace = "http://org.openecomp.mso/vnfNotify", className = "org.openecomp.mso.adapters.vnf.async.client.CreateVnfNotification")
256 @Action(input = "http://org.openecomp.mso/notify/adapterNotify/createVnfNotificationRequest")
257 public void createVnfNotification(
258 @WebParam(name = "messageId", targetNamespace = "")
260 @WebParam(name = "completed", targetNamespace = "")
262 @WebParam(name = "exception", targetNamespace = "")
263 MsoExceptionCategory exception,
264 @WebParam(name = "errorMessage", targetNamespace = "")
266 @WebParam(name = "vnfId", targetNamespace = "")
268 @WebParam(name = "outputs", targetNamespace = "")
269 org.openecomp.mso.bpmn.common.adapter.vnf.CreateVnfNotification.Outputs outputs,
270 @WebParam(name = "rollback", targetNamespace = "")
271 VnfRollback rollback){
273 CreateVnfNotification createVnfNotification = new CreateVnfNotification();
275 createVnfNotification.setMessageId(messageId);
276 createVnfNotification.setCompleted(completed);
277 createVnfNotification.setException(exception);
278 createVnfNotification.setErrorMessage(errorMessage);
279 createVnfNotification.setVnfId(vnfId);
280 createVnfNotification.setOutputs(outputs);
281 createVnfNotification.setRollback(rollback);
283 ProcessEngineServices pes = getProcessEngineServices();
284 RuntimeService runtimeService = pes.getRuntimeService();
286 MsoLogger.setServiceName("MSO." + "vnf Adapter Create");
287 MsoLogger.setLogContext(messageId, "N/A");
288 msoLogger.debug(logMarker + "Received CreateVnfNotification - " + createVnfNotification.toString());
290 long startTime = System.currentTimeMillis();
293 /* Check to make sure the process instance is ready for correlation*/
294 isReadyforCorrelation(runtimeService, messageId, "createVnfNotificationCallback", "VNFC_messageId");
296 msoLogger.debug(logMarker + "*** Received MSO createVnfNotification Callback ******");
297 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Call to MSO VnfAdapterNotifyService ");
299 msoLogger.debug(logMarker + "Create VNF Notification string:\n" + createVnfNotification.toString());
301 Map<String,Object> variables = new HashMap<String,Object>();
302 variables.put("VNFC_messageId", messageId );
303 variables.put("createVnfNotificationCallback", createVnfNotification.toString());
305 /*Correlating the response with the running instance*/
307 runtimeService.createMessageCorrelation("createVnfNotificationCallback").setVariables(variables)
308 .processInstanceVariableEquals("VNFC_messageId", messageId).correlate();
310 msoLogger.debug(logMarker + "***** Completed processing of MSO VnfAdapterNotifyService ******");
311 } catch(MismatchingMessageCorrelationException e) {
312 msoLogger.debug(logMarker + "[CORM]correlation id mismatch");
314 "VNF Adapter Notify Service received a Create VNF Notification request with RequestId '"
316 + "' but that RequestId could not be correlated to any active process - ignoring the request";
318 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
319 MsoLogger.ErrorCode.UnknownError, logMarker + ":" + msg, e);
322 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
323 logMarker + "Completed the execution of MSO Vnf Adapter Notify for Query VNF Notification.");
325 msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
326 logMarker + "Completed the execution of MSO Vnf Adapter Notify for Query VNF Notification.", "BPMN",
327 MsoLogger.getServiceName(), "createVnfNotification");
334 * @param errorMessage
341 @WebMethod(operationName = "updateVnfNotification")
343 @RequestWrapper(localName = "updateVnfNotification", targetNamespace = "http://org.openecomp.mso/vnfNotify", className = "org.openecomp.mso.adapters.vnf.async.client.UpdateVnfNotification")
344 @Action(input = "http://org.openecomp.mso/notify/adapterNotify/updateVnfNotificationRequest")
345 public void updateVnfNotification(
346 @WebParam(name = "messageId", targetNamespace = "")
348 @WebParam(name = "completed", targetNamespace = "")
350 @WebParam(name = "exception", targetNamespace = "")
351 MsoExceptionCategory exception,
352 @WebParam(name = "errorMessage", targetNamespace = "")
354 @WebParam(name = "outputs", targetNamespace = "")
355 org.openecomp.mso.bpmn.common.adapter.vnf.UpdateVnfNotification.Outputs outputs,
356 @WebParam(name = "rollback", targetNamespace = "")
357 VnfRollback rollback){
359 UpdateVnfNotification updateVnfNotification = new UpdateVnfNotification();
361 updateVnfNotification.setMessageId(messageId);
362 updateVnfNotification.setCompleted(completed);
363 updateVnfNotification.setException(exception);
364 updateVnfNotification.setErrorMessage(errorMessage);
365 updateVnfNotification.setOutputs(outputs);
366 updateVnfNotification.setRollback(rollback);
368 ProcessEngineServices pes = getProcessEngineServices();
369 RuntimeService runtimeService = pes.getRuntimeService();
371 MsoLogger.setServiceName("MSO." + "vnf Adapter Update");
372 MsoLogger.setLogContext(messageId, "N/A");
373 msoLogger.debug(logMarker + "Received UpdateVnfNotification - " + updateVnfNotification.toString());
375 long startTime = System.currentTimeMillis();
378 // Check to make sure the process instance is ready for correlation
379 isReadyforCorrelation(runtimeService, messageId, "updateVnfNotificationCallback", "VNFU_messageId");
381 msoLogger.debug(logMarker + "*** Received MSO updateVnfNotification Callback ******");
382 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Call to MSO VnfAdapterNotifyService ");
384 msoLogger.debug(logMarker + "Update VNF Notification string:\n" + updateVnfNotification.toString());
386 Map<String,Object> variables = new HashMap<String,Object>();
387 variables.put("VNFU_messageId", messageId );
388 variables.put("updateVnfNotificationCallback", updateVnfNotification.toString());
390 //Correlating the response with the running instance
391 runtimeService.createMessageCorrelation("updateVnfNotificationCallback").setVariables(variables)
392 .processInstanceVariableEquals("VNFU_messageId", messageId).correlate();
394 msoLogger.debug(logMarker + "***** Completed processing of MSO VnfAdapterNotifyService ******");
396 } catch(MismatchingMessageCorrelationException e) {
397 msoLogger.debug(logMarker + "[CORM]correlation id mismatch");
399 "VNF Adapter Notify Service received a Update VNF Notification request with RequestId '"
401 + "' but that RequestId could not be correlated to any active process - ignoring the request";
403 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
404 MsoLogger.ErrorCode.UnknownError, logMarker + ":" + msg, e);
407 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
408 logMarker + "Completed the execution of MSO Vnf Adapter Notify for Update VNF Notification.");
410 msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
411 logMarker + "Completed the execution of MSO Vnf Adapter Notify for Update VNF Notification.", "BPMN",
412 MsoLogger.getServiceName(), "updateVnfNotification");
419 * @param errorMessage
425 //@WebService(serviceName="VNFAdapterDeleteCallbackV1", targetNamespace="http://org.openecomp.mso/vnfNotify")
426 @WebMethod(operationName = "deleteVnfNotification")
428 @RequestWrapper(localName = "deleteVnfNotification", targetNamespace = "http://org.openecomp.mso/vnfNotify", className = "org.openecomp.mso.adapters.vnf.async.client.DeleteVnfNotification")
429 @Action(input = "http://org.openecomp.mso/notify/adapterNotify/deleteVnfNotificationRequest")
430 public void deleteVnfNotification(
431 @WebParam(name = "messageId", targetNamespace = "")
433 @WebParam(name = "completed", targetNamespace = "")
435 @WebParam(name = "exception", targetNamespace = "")
436 MsoExceptionCategory exception,
437 @WebParam(name = "errorMessage", targetNamespace = "")
438 String errorMessage) {
440 //Callback URL to use http://localhost:28080/mso/services/VNFAdapterDeleteCallbackV1
442 //DeleteVnfNotification Class
443 DeleteVnfNotification deleteVnfNotification = new DeleteVnfNotification();
444 deleteVnfNotification.setMessageId(messageId);
445 deleteVnfNotification.setCompleted(completed);
446 deleteVnfNotification.setException(exception);
447 deleteVnfNotification.setErrorMessage(errorMessage);
449 ProcessEngineServices pes = getProcessEngineServices();
450 RuntimeService runtimeService = pes.getRuntimeService();
452 MsoLogger.setServiceName("MSO." + "vnfAdapterDelete");
453 MsoLogger.setLogContext(messageId, "N/A");
454 msoLogger.debug(logMarker + "Received DeleteVnfNotification callback: " + deleteVnfNotification.toString());
456 long startTime = System.currentTimeMillis();
459 /* Check to make sure the process instance is ready for correlation*/
460 //isReadyforCorrelation(runtimeService, messageId, "deleteVnfACallback", "VNFDEL_uuid");
462 msoLogger.debug(logMarker + " *** Received MSO deleteVnfACallback ******");
463 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Call to MSO deleteVnfACallback ");
464 msoLogger.debug(logMarker + " Callback response string:\n" + deleteVnfNotification.toString());
466 Map<String,Object> variables = new HashMap<String,Object>();
467 variables.put("VNFDEL_uuid", messageId);
468 variables.put("deleteVnfACallback", deleteVnfNotification.toString());
470 /*Correlating the response with the running instance*/
472 runtimeService.createMessageCorrelation("deleteVnfACallback")
473 .setVariables(variables)
474 .processInstanceVariableEquals("VNFDEL_uuid", messageId).correlate();
476 msoLogger.debug(logMarker + "***** Completed processing of MSO deleteVnfACallback ******");
478 } catch(MismatchingMessageCorrelationException e) {
480 msoLogger.debug(logMarker + " [CORM]correlation id mismatch");
481 // Couldn't correlate requestId to any active flow
482 //MsoLogger logger = MsoLogger.getMsoLogger("SDNCAdapterCallbackService");
485 "Vnf Adapter Callback Service received a Vnf Adapter Callback with messageId '"
487 + "' but that messageId could not be correlated to any active process - ignoring the Request";
489 msoLogger.error(MessageEnum.BPMN_SDNC_CALLBACK_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
490 MsoLogger.ErrorCode.UnknownError, logMarker + ":" + msg, e);
493 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
494 logMarker + "Completed the execution of MSO VNFAdapterDeleteCallbackV1.");
496 msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
497 logMarker + "Completed the execution of MSO VNFAdapterDeleteCallbackV1.", "BPMN",
498 MsoLogger.getServiceName(), "deleteVnfNotification");
503 private void isReadyforCorrelation(RuntimeService runtimeService, String requestId, String responseName, String correlationValue) {
505 long waitingInstances = runtimeService.createExecutionQuery().messageEventSubscriptionName(responseName).processVariableValueEquals(correlationValue, requestId).count();
507 while (waitingInstances==0 && retries > 0) {
510 } catch (InterruptedException e) {
511 // TODO Auto-generated catch block
512 // should I add new exception Message to MessageEnum???
513 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, logMarker, e);
515 } // you can still play with the numbers
516 waitingInstances = runtimeService.createExecutionQuery() //
517 .messageEventSubscriptionName(responseName)
518 .processVariableValueEquals(correlationValue, requestId).count();
524 private ProcessEngineServices getProcessEngineServices() {
525 if (pes4junit == null) {
526 return BpmPlatform.getDefaultProcessEngine();
532 @WebMethod(exclude=true)
533 public void setProcessEngineServices4junit(ProcessEngineServices pes) {