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.gamma.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;
40 import com.att.domain2.workflow.vnf.async.adapter.callback.wsdl.v1.CreateVnfNotification;
41 import com.att.domain2.workflow.vnf.async.adapter.callback.wsdl.v1.DeleteVnfNotification;
42 import com.att.domain2.workflow.vnf.async.adapter.callback.wsdl.v1.MsoExceptionCategory;
43 import com.att.domain2.workflow.vnf.async.adapter.callback.wsdl.v1.QueryVnfNotification;
44 import com.att.domain2.workflow.vnf.async.adapter.callback.wsdl.v1.RollbackVnfNotification;
45 import com.att.domain2.workflow.vnf.async.adapter.callback.wsdl.v1.UpdateVnfNotification;
46 import com.att.domain2.workflow.vnf.async.adapter.callback.wsdl.v1.VnfAdapterNotify;
47 import com.att.domain2.workflow.vnf.async.adapter.callback.wsdl.v1.VnfRollback;
48 import com.att.domain2.workflow.vnf.async.adapter.callback.wsdl.v1.VnfStatus;
49 import org.openecomp.mso.logger.MessageEnum;
50 import org.openecomp.mso.logger.MsoLogger;
53 * This is the service class for VnfAdapterNotify
54 * TODO: Add addition VnfAdapterNotify Methods for remaining VnfAdapterNotify operations.
57 @WebService(serviceName = "vnfAdapterNotify", targetNamespace = "http://com.att.mso/vnfNotify")
58 public class VnfAdapterNotifyServiceImpl implements VnfAdapterNotify{
60 private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
62 private final String logMarker = "[VNF-NOTIFY]";
64 @Context WebServiceContext wsContext;
66 private volatile ProcessEngineServices pes4junit = null;
75 @WebMethod(operationName = "rollbackVnfNotification")
77 @RequestWrapper(localName = "rollbackVnfNotification", targetNamespace = "http://com.att.mso/vnfNotify", className = "org.openecomp.mso.adapters.vnf.async.client.RollbackVnfNotification")
78 @Action(input = "http://com.att.mso/notify/adapterNotify/rollbackVnfNotificationRequest")
79 public void rollbackVnfNotification(
80 @WebParam(name = "messageId", targetNamespace = "")
82 @WebParam(name = "completed", targetNamespace = "")
84 @WebParam(name = "exception", targetNamespace = "")
85 MsoExceptionCategory exception,
86 @WebParam(name = "errorMessage", targetNamespace = "")
87 String errorMessage) {
91 RollbackVnfNotification rollbackVnfNotification = new RollbackVnfNotification();
93 rollbackVnfNotification.setMessageId(messageId);
94 rollbackVnfNotification.setCompleted(completed);
95 rollbackVnfNotification.setException(exception);
96 rollbackVnfNotification.setErrorMessage(errorMessage);
98 ProcessEngineServices pes = getProcessEngineServices();
99 RuntimeService runtimeService = pes.getRuntimeService();
101 MsoLogger.setServiceName("MSO." + "vnfAdapterRollback");
102 MsoLogger.setLogContext(messageId, "N/A");
103 msoLogger.debug(logMarker + "Received RollbackVnfNotification" + rollbackVnfNotification.toString());
105 long startTime = System.currentTimeMillis();
108 /* Check to make sure the process instance is ready for correlation*/
109 isReadyforCorrelation(runtimeService, messageId, "rollbackVnfNotificationCallback", "VNFRB_messageId");
111 msoLogger.debug(logMarker + "*** Received MSO rollbackVnfNotification Callback ******");
112 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Call to MSO VnfAdapterNotifyService ");
113 msoLogger.debug(logMarker + "Rollback VNF Notification string:\n" + rollbackVnfNotification.toString());
115 System.out.println("testing ROllbackVnfNotification : " + rollbackVnfNotification.toString());
117 Map<String,Object> variables = new HashMap<String,Object>();
118 variables.put("VNFRB_messageId", messageId );
119 variables.put("rollbackVnfNotificationCallback", rollbackVnfNotification.toString());
121 /*Correlating the response with the running instance*/
123 runtimeService.createMessageCorrelation("rollbackVnfNotificationCallback").setVariables(variables)
124 .processInstanceVariableEquals("VNFRB_messageId", messageId).correlate();
126 msoLogger.debug(logMarker + "***** Completed processing of MSO VnfAdapterNotifyService ******");
127 } catch(MismatchingMessageCorrelationException e) {
128 msoLogger.debug(logMarker + "[CORM]correlation id mismatch");
130 "VNF Adapter Notify Service received a Create VNF Notification request with RequestId '"
132 + "' but that RequestId could not be correlated to any active process - ignoring the request";
134 msoLogger.error (MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
135 MsoLogger.ErrorCode.UnknownError, logMarker + ":" + msg);
138 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
139 logMarker + "Completed the execution of MSO Vnf Adapter Notify for Rollback VNF Notification.");
141 msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
142 logMarker + "Completed the execution of MSO Vnf Adapter Notify for Rollback VNF Notification.", "BPMN",
143 MsoLogger.getServiceName(), "rollbackVnfNotification");
152 * @param errorMessage
161 @WebMethod(operationName = "queryVnfNotification")
163 @RequestWrapper(localName = "queryVnfNotification", targetNamespace = "http://com.att.mso/vnfNotify", className = "org.openecomp.mso.adapters.vnf.async.client.QueryVnfNotification")
164 @Action(input = "http://com.att.mso/notify/adapterNotify/queryVnfNotificationRequest")
165 public void queryVnfNotification(
166 @WebParam(name = "messageId", targetNamespace = "")
168 @WebParam(name = "completed", targetNamespace = "")
170 @WebParam(name = "exception", targetNamespace = "")
171 MsoExceptionCategory exception,
172 @WebParam(name = "errorMessage", targetNamespace = "")
174 @WebParam(name = "vnfExists", targetNamespace = "")
176 @WebParam(name = "vnfId", targetNamespace = "")
178 @WebParam(name = "status", targetNamespace = "")
180 @WebParam(name = "outputs", targetNamespace = "")
181 com.att.domain2.workflow.vnf.async.adapter.callback.wsdl.v1.QueryVnfNotification.Outputs outputs){
183 QueryVnfNotification queryVnfNotification = new QueryVnfNotification();
185 queryVnfNotification.setMessageId(messageId);
186 queryVnfNotification.setCompleted(completed);
187 queryVnfNotification.setException(exception);
188 queryVnfNotification.setErrorMessage(errorMessage);
189 queryVnfNotification.setVnfExists(vnfExists);
190 queryVnfNotification.setVnfId(vnfId);
191 queryVnfNotification.setStatus(status);
192 queryVnfNotification.setOutputs(outputs);
195 ProcessEngineServices pes = getProcessEngineServices();
196 RuntimeService runtimeService = pes.getRuntimeService();
198 msoLogger.setServiceName("MSO." + "vnf Adapter Query");
199 msoLogger.setLogContext(messageId, "N/A");
200 msoLogger.debug(logMarker + "Received QueryVnfNotification" + queryVnfNotification.toString());
202 System.out.println("Received QueryVnfNotification : " + queryVnfNotification.toString());
204 long startTime = System.currentTimeMillis();
207 /* Check to make sure the process instance is ready for correlation*/
208 isReadyforCorrelation(runtimeService, messageId, "queryVnfNotificationCallback", "VNFQ_messageId");
210 msoLogger.debug(logMarker + "*** Received MSO queryVnfNotification Callback ******");
211 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Call to MSO VnfAdapterNotifyService ");
212 msoLogger.debug(logMarker + "Query VNF Notification string:\n" + queryVnfNotification.toString());
214 Map<String,Object> variables = new HashMap<String,Object>();
215 variables.put("VNFQ_messageId", messageId );
216 variables.put("queryVnfNotificationCallback", queryVnfNotification.toString());
218 /*Correlating the response with the running instance*/
220 runtimeService.createMessageCorrelation("queryVnfNotificationCallback").setVariables(variables)
221 .processInstanceVariableEquals("VNFQ_messageId", messageId).correlate();
223 msoLogger.debug(logMarker + "***** Completed processing of MSO VnfAdapterNotifyService ******");
224 } catch(MismatchingMessageCorrelationException e) {
225 msoLogger.debug(logMarker + "[CORM]correlation id mismatch");
227 "VNF Adapter Notify Service received a Query VNF Notification request with RequestId '"
229 + "' but that RequestId could not be correlated to any active process - ignoring the request";
231 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
232 MsoLogger.ErrorCode.UnknownError, logMarker + ":" + msg, e);
235 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
236 logMarker + "Completed the execution of MSO Vnf Adapter Notify for Query VNF Notification.");
246 * @param errorMessage
254 @WebMethod(operationName = "createVnfNotification")
256 @RequestWrapper(localName = "createVnfNotification", targetNamespace = "http://com.att.mso/vnfNotify", className = "org.openecomp.mso.adapters.vnf.async.client.CreateVnfNotification")
257 @Action(input = "http://com.att.mso/notify/adapterNotify/createVnfNotificationRequest")
258 public void createVnfNotification(
259 @WebParam(name = "messageId", targetNamespace = "")
261 @WebParam(name = "completed", targetNamespace = "")
263 @WebParam(name = "exception", targetNamespace = "")
264 MsoExceptionCategory exception,
265 @WebParam(name = "errorMessage", targetNamespace = "")
267 @WebParam(name = "vnfId", targetNamespace = "")
269 @WebParam(name = "outputs", targetNamespace = "")
270 com.att.domain2.workflow.vnf.async.adapter.callback.wsdl.v1.CreateVnfNotification.Outputs outputs,
271 @WebParam(name = "rollback", targetNamespace = "")
272 VnfRollback rollback){
274 CreateVnfNotification createVnfNotification = new CreateVnfNotification();
276 createVnfNotification.setMessageId(messageId);
277 createVnfNotification.setCompleted(completed);
278 createVnfNotification.setException(exception);
279 createVnfNotification.setErrorMessage(errorMessage);
280 createVnfNotification.setVnfId(vnfId);
281 createVnfNotification.setOutputs(outputs);
282 createVnfNotification.setRollback(rollback);
284 ProcessEngineServices pes = getProcessEngineServices();
285 RuntimeService runtimeService = pes.getRuntimeService();
287 msoLogger.setServiceName("MSO." + "vnf Adapter Create");
288 msoLogger.setLogContext(messageId, "N/A");
289 msoLogger.debug(logMarker + "Received CreateVnfNotification - " + createVnfNotification.toString());
291 long startTime = System.currentTimeMillis();
294 /* Check to make sure the process instance is ready for correlation*/
295 isReadyforCorrelation(runtimeService, messageId, "createVnfNotificationCallback", "VNFC_messageId");
297 msoLogger.debug(logMarker + "*** Received MSO createVnfNotification Callback ******");
298 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Call to MSO VnfAdapterNotifyService ");
300 msoLogger.debug(logMarker + "Create VNF Notification string:\n" + createVnfNotification.toString());
302 Map<String,Object> variables = new HashMap<String,Object>();
303 variables.put("VNFC_messageId", messageId );
304 variables.put("createVnfNotificationCallback", createVnfNotification.toString());
306 /*Correlating the response with the running instance*/
308 runtimeService.createMessageCorrelation("createVnfNotificationCallback").setVariables(variables)
309 .processInstanceVariableEquals("VNFC_messageId", messageId).correlate();
311 msoLogger.debug(logMarker + "***** Completed processing of MSO VnfAdapterNotifyService ******");
312 } catch(MismatchingMessageCorrelationException e) {
313 msoLogger.debug(logMarker + "[CORM]correlation id mismatch");
315 "VNF Adapter Notify Service received a Create VNF Notification request with RequestId '"
317 + "' but that RequestId could not be correlated to any active process - ignoring the request";
319 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
320 MsoLogger.ErrorCode.UnknownError, logMarker + ":" + msg, e);
323 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
324 logMarker + "Completed the execution of MSO Vnf Adapter Notify for Query VNF Notification.");
326 msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
327 logMarker + "Completed the execution of MSO Vnf Adapter Notify for Query VNF Notification.", "BPMN",
328 MsoLogger.getServiceName(), "createVnfNotification");
335 * @param errorMessage
342 @WebMethod(operationName = "updateVnfNotification")
344 @RequestWrapper(localName = "updateVnfNotification", targetNamespace = "http://com.att.mso/vnfNotify", className = "org.openecomp.mso.adapters.vnf.async.client.UpdateVnfNotification")
345 @Action(input = "http://com.att.mso/notify/adapterNotify/updateVnfNotificationRequest")
346 public void updateVnfNotification(
347 @WebParam(name = "messageId", targetNamespace = "")
349 @WebParam(name = "completed", targetNamespace = "")
351 @WebParam(name = "exception", targetNamespace = "")
352 MsoExceptionCategory exception,
353 @WebParam(name = "errorMessage", targetNamespace = "")
355 @WebParam(name = "outputs", targetNamespace = "")
356 com.att.domain2.workflow.vnf.async.adapter.callback.wsdl.v1.UpdateVnfNotification.Outputs outputs,
357 @WebParam(name = "rollback", targetNamespace = "")
358 VnfRollback rollback){
360 UpdateVnfNotification updateVnfNotification = new UpdateVnfNotification();
362 updateVnfNotification.setMessageId(messageId);
363 updateVnfNotification.setCompleted(completed);
364 updateVnfNotification.setException(exception);
365 updateVnfNotification.setErrorMessage(errorMessage);
366 updateVnfNotification.setOutputs(outputs);
367 updateVnfNotification.setRollback(rollback);
369 ProcessEngineServices pes = getProcessEngineServices();
370 RuntimeService runtimeService = pes.getRuntimeService();
372 msoLogger.setServiceName("MSO." + "vnf Adapter Update");
373 msoLogger.setLogContext(messageId, "N/A");
374 msoLogger.debug(logMarker + "Received UpdateVnfNotification - " + updateVnfNotification.toString());
376 long startTime = System.currentTimeMillis();
379 // Check to make sure the process instance is ready for correlation
380 isReadyforCorrelation(runtimeService, messageId, "updateVnfNotificationCallback", "VNFU_messageId");
382 msoLogger.debug(logMarker + "*** Received MSO updateVnfNotification Callback ******");
383 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Call to MSO VnfAdapterNotifyService ");
385 msoLogger.debug(logMarker + "Update VNF Notification string:\n" + updateVnfNotification.toString());
387 Map<String,Object> variables = new HashMap<String,Object>();
388 variables.put("VNFU_messageId", messageId );
389 variables.put("updateVnfNotificationCallback", updateVnfNotification.toString());
391 //Correlating the response with the running instance
392 runtimeService.createMessageCorrelation("updateVnfNotificationCallback").setVariables(variables)
393 .processInstanceVariableEquals("VNFU_messageId", messageId).correlate();
395 msoLogger.debug(logMarker + "***** Completed processing of MSO VnfAdapterNotifyService ******");
397 } catch(MismatchingMessageCorrelationException e) {
398 msoLogger.debug(logMarker + "[CORM]correlation id mismatch");
400 "VNF Adapter Notify Service received a Update VNF Notification request with RequestId '"
402 + "' but that RequestId could not be correlated to any active process - ignoring the request";
404 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
405 MsoLogger.ErrorCode.UnknownError, logMarker + ":" + msg, e);
408 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
409 logMarker + "Completed the execution of MSO Vnf Adapter Notify for Update VNF Notification.");
411 msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
412 logMarker + "Completed the execution of MSO Vnf Adapter Notify for Update VNF Notification.", "BPMN",
413 MsoLogger.getServiceName(), "updateVnfNotification");
420 * @param errorMessage
426 //@WebService(serviceName="VNFAdapterDeleteCallbackV1", targetNamespace="http://com.att.mso/vnfNotify")
427 @WebMethod(operationName = "deleteVnfNotification")
429 @RequestWrapper(localName = "deleteVnfNotification", targetNamespace = "http://com.att.mso/vnfNotify", className = "org.openecomp.mso.adapters.vnf.async.client.DeleteVnfNotification")
430 @Action(input = "http://com.att.mso/notify/adapterNotify/deleteVnfNotificationRequest")
431 public void deleteVnfNotification(
432 @WebParam(name = "messageId", targetNamespace = "")
434 @WebParam(name = "completed", targetNamespace = "")
436 @WebParam(name = "exception", targetNamespace = "")
437 MsoExceptionCategory exception,
438 @WebParam(name = "errorMessage", targetNamespace = "")
439 String errorMessage) {
441 //Callback URL to use http://localhost:8080/mso/services/VNFAdapterDeleteCallbackV1
443 //DeleteVnfNotification Class
444 DeleteVnfNotification deleteVnfNotification = new DeleteVnfNotification();
445 deleteVnfNotification.setMessageId(messageId);
446 deleteVnfNotification.setCompleted(completed);
447 deleteVnfNotification.setException(exception);
448 deleteVnfNotification.setErrorMessage(errorMessage);
450 ProcessEngineServices pes = getProcessEngineServices();
451 RuntimeService runtimeService = pes.getRuntimeService();
453 MsoLogger.setServiceName("MSO." + "vnfAdapterDelete");
454 MsoLogger.setLogContext(messageId, "N/A");
455 msoLogger.debug(logMarker + "Received DeleteVnfNotification callback: " + deleteVnfNotification.toString());
457 long startTime = System.currentTimeMillis();
460 /* Check to make sure the process instance is ready for correlation*/
461 //isReadyforCorrelation(runtimeService, messageId, "deleteVnfACallback", "VNFDEL_uuid");
463 msoLogger.debug(logMarker + " *** Received MSO deleteVnfACallback ******");
464 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Call to MSO deleteVnfACallback ");
465 msoLogger.debug(logMarker + " Callback response string:\n" + deleteVnfNotification.toString());
467 Map<String,Object> variables = new HashMap<String,Object>();
468 variables.put("VNFDEL_uuid", messageId);
469 variables.put("deleteVnfACallback", deleteVnfNotification.toString());
471 /*Correlating the response with the running instance*/
473 runtimeService.createMessageCorrelation("deleteVnfACallback")
474 .setVariables(variables)
475 .processInstanceVariableEquals("VNFDEL_uuid", messageId).correlate();
477 msoLogger.debug(logMarker + "***** Completed processing of MSO deleteVnfACallback ******");
479 } catch(MismatchingMessageCorrelationException e) {
481 msoLogger.debug(logMarker + " [CORM]correlation id mismatch");
482 // Couldn't correlate requestId to any active flow
483 //MsoLogger logger = MsoLogger.getMsoLogger("SDNCAdapterCallbackService");
486 "Vnf Adapter Callback Service received a Vnf Adapter Callback with messageId '"
488 + "' but that messageId could not be correlated to any active process - ignoring the Request";
490 msoLogger.error(MessageEnum.BPMN_SDNC_CALLBACK_EXCEPTION, "BPMN", MsoLogger.getServiceName(),
491 MsoLogger.ErrorCode.UnknownError, logMarker + ":" + msg, e);
494 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
495 logMarker + "Completed the execution of MSO VNFAdapterDeleteCallbackV1.");
497 msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
498 logMarker + "Completed the execution of MSO VNFAdapterDeleteCallbackV1.", "BPMN",
499 MsoLogger.getServiceName(), "deleteVnfNotification");
504 private void isReadyforCorrelation(RuntimeService runtimeService, String requestId, String responseName, String correlationValue) {
506 long waitingInstances = runtimeService.createExecutionQuery().messageEventSubscriptionName(responseName).processVariableValueEquals(correlationValue, requestId).count();
508 while (waitingInstances==0 && retries > 0) {
511 } catch (InterruptedException e) {
512 // TODO Auto-generated catch block
513 // should I add new exception Message to MessageEnum???
514 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, logMarker, e);
516 } // you can still play with the numbers
517 waitingInstances = runtimeService.createExecutionQuery() //
518 .messageEventSubscriptionName(responseName)
519 .processVariableValueEquals(correlationValue, requestId).count();
525 private ProcessEngineServices getProcessEngineServices() {
526 if (pes4junit == null) {
527 return BpmPlatform.getDefaultProcessEngine();
533 @WebMethod(exclude=true)
534 public void setProcessEngineServices4junit(ProcessEngineServices pes) {