Initial OpenECOMP MSO commit
[so.git] / adapters / mso-vnf-adapter / src / main / java / org / openecomp / mso / adapters / vnf / MsoVnfAdapterAsyncImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.mso.adapters.vnf;
22
23
24 import java.net.MalformedURLException;
25 import java.net.URL;
26 import java.util.Collections;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30
31 import javax.jws.WebService;
32 import javax.xml.bind.DatatypeConverter;
33 import javax.xml.namespace.QName;
34 import javax.xml.ws.BindingProvider;
35 import javax.xml.ws.Holder;
36 import javax.xml.ws.handler.MessageContext;
37
38 import org.openecomp.mso.adapters.vnf.async.client.CreateVnfNotification;
39 import org.openecomp.mso.adapters.vnf.async.client.QueryVnfNotification;
40 import org.openecomp.mso.adapters.vnf.async.client.UpdateVnfNotification;
41 import org.openecomp.mso.adapters.vnf.async.client.VnfAdapterNotify;
42 import org.openecomp.mso.adapters.vnf.async.client.VnfAdapterNotify_Service;
43 import org.openecomp.mso.adapters.vnf.exceptions.VnfException;
44 import org.openecomp.mso.cloud.CloudConfigFactory;
45 import org.openecomp.mso.entity.MsoRequest;
46 import org.openecomp.mso.logger.MessageEnum;
47 import org.openecomp.mso.logger.MsoAlarmLogger;
48 import org.openecomp.mso.logger.MsoLogger;
49 import org.openecomp.mso.properties.MsoPropertiesFactory;
50 import org.openecomp.mso.openstack.beans.VnfStatus;
51 import org.openecomp.mso.openstack.beans.VnfRollback;
52
53 @WebService(serviceName = "VnfAdapterAsync", endpointInterface = "org.openecomp.mso.adapters.vnf.MsoVnfAdapterAsync", targetNamespace = "http://com.att.mso/vnfA")
54 public class MsoVnfAdapterAsyncImpl implements MsoVnfAdapterAsync {
55
56         MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
57
58         CloudConfigFactory cloudConfigFactory=new CloudConfigFactory();
59
60         public static final String MSO_PROP_VNF_ADAPTER="MSO_PROP_VNF_ADAPTER";
61     private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
62     private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger ();
63     private static final String BPEL_AUTH_PROP = "org.openecomp.mso.adapters.vnf.bpelauth";
64     private static final String ENCRYPTION_KEY = "aa3871669d893c7fb8abbcda31b88b4f";
65
66     /**
67      * Health Check web method. Does nothing but return to show the adapter is deployed.
68      */
69     @Override
70     public void healthCheckA () {
71         LOGGER.debug ("Health check call in VNF Adapter");
72     }
73
74     /**
75      * This is the asynchronous "Create VNF" web service implementation.
76      * It will create a new VNF of the requested type in the specified cloud
77      * and tenant. The tenant must exist before this service is called.
78      *
79      * If a VNF with the same name already exists, this can be considered a
80      * success or failure, depending on the value of the 'failIfExists' parameter.
81      *
82      * All VNF types will be defined in the MSO catalog. The caller must request
83      * one of these pre-defined types or an error will be returned. Within the
84      * catalog, each VNF type references (among other things) a Heat template
85      * which is used to deploy the required VNF artifacts (VMs, networks, etc.)
86      * to the cloud.
87      *
88      * Depending on the Heat template, a variable set of input parameters will
89      * be defined, some of which are required. The caller is responsible to
90      * pass the necessary input data for the VNF or an error will be thrown.
91      *
92      * The method sends an asynchronous response to the notification URL when
93      * processing completes. The createAsyncResponse contains the vnfId (the
94      * canonical name of the stack), a Map of VNF output attributes, and a
95      * VnfRollback object. This last object can be passed as-is to the
96      * rollbackVnf operation to undo everything that was created for the VNF.
97      * This is useful if a VNF is successfully created but the orchestrator
98      * fails on a subsequent operation.
99      *
100      * Note: this method is implemented by calling the synchronous web method
101      * and translating the response to an asynchronous notification.
102      *
103      * @param cloudSiteId CLLI code of the cloud site in which to create the VNF
104      * @param tenantId Openstack tenant identifier
105      * @param vnfType VNF type key, should match a VNF definition in catalog DB
106      * @param vnfName Name to be assigned to the new VNF
107      * @param inputs Map of key=value inputs for VNF stack creation
108      * @param failIfExists Flag whether already existing VNF should be considered
109      *        a success or failure
110      * @param msoRequest Request tracking information for logs
111      * @param notificationURL the target URL for asynchronous response
112      */
113     @Override
114     public void createVnfA (String cloudSiteId,
115                             String tenantId,
116                             String vnfType,
117                             String vnfVersion,
118                             String vnfName,
119                             String requestType,
120                             String volumeGroupHeatStackId,
121                             Map <String, String> inputs,
122                             Boolean failIfExists,
123                             Boolean backout,
124                             String messageId,
125                             MsoRequest msoRequest,
126                             String notificationUrl) {
127         String error;
128         String serviceName = "CreateVnfA";
129         MsoLogger.setLogContext (msoRequest);
130         MsoLogger.setServiceName (serviceName);
131         LOGGER.info (MessageEnum.RA_ASYNC_CREATE_VNF, vnfName, vnfType, cloudSiteId, tenantId, "", "createVnfA");
132         // Will capture execution time for metrics
133         long startTime = System.currentTimeMillis ();
134         // Use the synchronous method to perform the actual Create
135         MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory, cloudConfigFactory);
136
137         // Synchronous Web Service Outputs
138         Holder <String> vnfId = new Holder <String> ();
139         Holder <Map <String, String>> outputs = new Holder <Map <String, String>> ();
140         Holder <VnfRollback> vnfRollback = new Holder <VnfRollback> ();
141
142         try {
143             vnfAdapter.createVnf (cloudSiteId,
144                                   tenantId,
145                                   vnfType,
146                                   vnfVersion,
147                                   vnfName,
148                                   requestType,
149                                   volumeGroupHeatStackId,
150                                   inputs,
151                                   failIfExists,
152                                   backout,
153                                   msoRequest,
154                                   vnfId,
155                                   outputs,
156                                   vnfRollback);
157             MsoLogger.setServiceName (serviceName);
158         } catch (VnfException e) {
159                 MsoLogger.setServiceName (serviceName);
160                 LOGGER.error (MessageEnum.RA_CREATE_VNF_ERR,  vnfName, cloudSiteId, tenantId, "", "createVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "VnfException in createVnfA", e);
161             org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
162             String eMsg = null;
163             try {
164                 eMsg = e.getFaultInfo ().getMessage ();
165                 exCat = org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
166                                                                                                      .getCategory ()
167                                                                                                      .name ());
168             } catch (Exception e1) {
169                 LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "createVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - Fault info", e1);
170             }
171             // Build and send Asynchronous error response
172             try {
173                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
174                 notifyPort.createVnfNotification (messageId, false, exCat, eMsg, null, null, null);
175             } catch (Exception e1) {
176                 error = "Error sending createVnf notification " + e1.getMessage ();
177                 LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "createVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending createVnf notification", e1);
178                 alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
179             }
180             LOGGER.info (MessageEnum.RA_ASYNC_CREATE_VNF_COMPLETE, "", "createVnfA", "", "createVnfA");
181             return;
182         }
183         LOGGER.debug ("Async Create VNF: " + vnfName + " VnfId:" + vnfId.value);
184         // Build and send Asynchronous response
185         try {
186             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
187             notifyPort.createVnfNotification (messageId,
188                                               true,
189                                               null,
190                                               null,
191                                               vnfId.value,
192                                               copyCreateOutputs (outputs),
193                                               copyVrb (vnfRollback));
194         } catch (Exception e) {
195             error = "Error sending createVnf notification " + e.getMessage ();
196             LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "createVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending createVnf notification", e);
197             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
198         }
199         LOGGER.info (MessageEnum.RA_ASYNC_CREATE_VNF_COMPLETE, "", "createVnfA");
200         return;
201     }
202
203     @Override
204     public void updateVnfA (String cloudSiteId,
205                             String tenantId,
206                             String vnfType,
207                             String vnfVersion,
208                             String vnfName,
209                             String requestType,
210                             String volumeGroupHeatStackId,
211                             Map <String, String> inputs,
212                             String messageId,
213                             MsoRequest msoRequest,
214                             String notificationUrl) {
215         String error;
216         String serviceName = "UpdateVnfA";
217         MsoLogger.setServiceName (serviceName);
218         MsoLogger.setLogContext (msoRequest);
219         // Will capture execution time for metrics
220         long startTime = System.currentTimeMillis ();
221         LOGGER.info (MessageEnum.RA_ASYNC_UPDATE_VNF, vnfName, vnfType, cloudSiteId, tenantId, "", "UpdateVnfA");
222
223         // Use the synchronous method to perform the actual Create
224         MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory,cloudConfigFactory);
225
226         // Synchronous Web Service Outputs
227         Holder <String> vnfId = new Holder <String> ();
228         Holder <Map <String, String>> outputs = new Holder <Map <String, String>> ();
229         Holder <VnfRollback> vnfRollback = new Holder <VnfRollback> ();
230
231         try {
232             vnfAdapter.updateVnf (cloudSiteId, tenantId, vnfType,vnfVersion, vnfName, requestType, volumeGroupHeatStackId, inputs, msoRequest, outputs, vnfRollback);
233             MsoLogger.setServiceName (serviceName);
234         } catch (VnfException e) {
235                 MsoLogger.setServiceName (serviceName);
236                 LOGGER.error (MessageEnum.RA_UPDATE_VNF_ERR,  vnfName, cloudSiteId, tenantId, "", "UpdateVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending updateVnf notification", e);
237             org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
238             String eMsg = null;
239             try {
240                 eMsg = e.getFaultInfo ().getMessage ();
241                 exCat = org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
242                                                                                                      .getCategory ()
243                                                                                                      .name ());
244             } catch (Exception e1) {
245                 LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "UpdateVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
246             }
247             // Build and send Asynchronous error response
248             try {
249                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
250                 notifyPort.updateVnfNotification (messageId, false, exCat, eMsg, null, null);
251             } catch (Exception e1) {
252                 error = "Error sending updateVnf notification " + e1.getMessage ();
253                 LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "UpdateVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending updateVnf notification", e1);
254                 alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
255             }
256             LOGGER.info (MessageEnum.RA_ASYNC_UPDATE_VNF_COMPLETE, "", "UpdateVnfA");
257             return;
258         }
259         LOGGER.debug ("Async Update VNF: " + vnfName + " VnfId:" + vnfId.value);
260         // Build and send Asynchronous response
261         try {
262             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
263             notifyPort.updateVnfNotification (messageId,
264                                               true,
265                                               null,
266                                               null,
267                                               copyUpdateOutputs (outputs),
268                                               copyVrb (vnfRollback));
269         } catch (Exception e) {
270             error = "Error sending updateVnf notification " + e.getMessage ();
271             LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "UpdateVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending updateVnf notification", e);
272             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
273         }
274         LOGGER.info (MessageEnum.RA_ASYNC_UPDATE_VNF_COMPLETE, "", "UpdateVnfA");
275         return;
276     }
277
278     /**
279      * This is the "Query VNF" web service implementation.
280      * It will look up a VNF by name or ID in the specified cloud and tenant.
281      *
282      * The method returns an indicator that the VNF exists, its Openstack internal
283      * ID, its status, and the set of outputs (from when the stack was created).
284      *
285      * @param cloudSiteId CLLI code of the cloud site in which to query
286      * @param tenantId Openstack tenant identifier
287      * @param vnfName VNF Name or Openstack ID
288      * @param msoRequest Request tracking information for logs
289      * @param notificationURL the target URL for asynchronous response
290      */
291     @Override
292     public void queryVnfA (String cloudSiteId,
293                            String tenantId,
294                            String vnfName,
295                            String messageId,
296                            MsoRequest msoRequest,
297                            String notificationUrl) {
298         String error;
299         String serviceName = "QueryVnfA";
300         MsoLogger.setServiceName (serviceName);
301         MsoLogger.setLogContext (msoRequest);
302         // Will capture execution time for metrics
303         long startTime = System.currentTimeMillis ();
304         LOGGER.info (MessageEnum.RA_ASYNC_QUERY_VNF, vnfName, cloudSiteId, tenantId);
305
306         // Use the synchronous method to perform the actual query
307         MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory,cloudConfigFactory);
308
309         // Synchronous Web Service Outputs
310         Holder <Boolean> vnfExists = new Holder <Boolean> ();
311         Holder <String> vnfId = new Holder <String> ();
312         Holder <VnfStatus> status = new Holder <VnfStatus> ();
313         Holder <Map <String, String>> outputs = new Holder <Map <String, String>> ();
314
315         try {
316             vnfAdapter.queryVnf (cloudSiteId, tenantId, vnfName, msoRequest, vnfExists, vnfId, status, outputs);
317             MsoLogger.setServiceName (serviceName);
318         } catch (VnfException e) {
319                 MsoLogger.setServiceName (serviceName);
320             LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR,  vnfName, cloudSiteId, tenantId, "", "queryVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending queryVnfA notification", e);
321             org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
322             String eMsg = null;
323             try {
324                 eMsg = e.getFaultInfo ().getMessage ();
325                 exCat = org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
326                                                                                                      .getCategory ()
327                                                                                                      .name ());
328             } catch (Exception e1) {
329                 LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "queryVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
330             }
331             // Build and send Asynchronous error response
332             try {
333                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
334                 notifyPort.queryVnfNotification (messageId, false, exCat, eMsg, null, null, null, null);
335             } catch (Exception e1) {
336                 error = "Error sending queryVnf notification " + e1.getMessage ();
337                 LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "queryVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending queryVnf notification", e1);
338                 alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
339             }
340             LOGGER.info (MessageEnum.RA_ASYNC_QUERY_VNF_COMPLETE, "", "queryVnfA");
341             return;
342         }
343
344         if (!vnfExists.value) {
345             LOGGER.debug ("Async Query, VNF not found");
346         } else {
347             LOGGER.debug ("Async Query, VNF=" + vnfId.value + ", status=" + status.value);
348         }
349         // Build and send Asynchronous response
350         try {
351             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
352             org.openecomp.mso.adapters.vnf.async.client.VnfStatus vnfS = org.openecomp.mso.adapters.vnf.async.client.VnfStatus.fromValue (status.value.name ());
353             notifyPort.queryVnfNotification (messageId,
354                                              true,
355                                              null,
356                                              null,
357                                              vnfExists.value,
358                                              vnfId.value,
359                                              vnfS,
360                                              copyQueryOutputs (outputs));
361         } catch (Exception e) {
362             error = "Error sending queryVnf notification " + e.getMessage ();
363             LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "queryVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending queryVnf notification", e);
364             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
365         }
366
367         LOGGER.info (MessageEnum.RA_ASYNC_QUERY_VNF_COMPLETE, "", "queryVnfA");
368         return;
369     }
370
371     /**
372      * This is the Asynchronous "Delete VNF" web service implementation.
373      * It will delete a VNF by name or ID in the specified cloud and tenant.
374      *
375      * The method has no outputs.
376      *
377      * @param cloudSiteId CLLI code of the cloud site in which to delete
378      * @param tenantId Openstack tenant identifier
379      * @param vnfName VNF Name or Openstack ID
380      * @param msoRequest Request tracking information for logs
381      * @param notificationURL the target URL for asynchronous response
382      */
383     @Override
384     public void deleteVnfA (String cloudSiteId,
385                             String tenantId,
386                             String vnfName,
387                             String messageId,
388                             MsoRequest msoRequest,
389                             String notificationUrl) {
390         String error;
391         String serviceName = "DeleteVnfA";
392         MsoLogger.setServiceName (serviceName);
393         MsoLogger.setLogContext (msoRequest);
394         // Will capture execution time for metrics
395         long startTime = System.currentTimeMillis ();
396         LOGGER.info (MessageEnum.RA_ASYNC_DELETE_VNF, vnfName, cloudSiteId, tenantId);
397
398         // Use the synchronous method to perform the actual delete
399         MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory,cloudConfigFactory);
400
401         try {
402             vnfAdapter.deleteVnf (cloudSiteId, tenantId, vnfName, msoRequest);
403             MsoLogger.setServiceName (serviceName);
404         } catch (VnfException e) {
405                 MsoLogger.setServiceName (serviceName);
406                 LOGGER.error (MessageEnum.RA_DELETE_VNF_ERR,  vnfName, cloudSiteId, tenantId, "", "deleteVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending deleteVnfA notification", e);
407             org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
408             String eMsg = null;
409             try {
410                 eMsg = e.getFaultInfo ().getMessage ();
411                 exCat = org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
412                                                                                                      .getCategory ()
413                                                                                                      .name ());
414             } catch (Exception e1) {
415                 LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "deleteVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
416             }
417             // Build and send Asynchronous error response
418             try {
419                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
420                 notifyPort.deleteVnfNotification (messageId, false, exCat, eMsg);
421             } catch (Exception e1) {
422                 error = "Error sending deleteVnf notification " + e1.getMessage ();
423                 LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "deleteVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending deleteVnfA notification", e1);
424                 alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
425             }
426             LOGGER.info (MessageEnum.RA_ASYNC_DELETE_VNF_COMPLETE, "", "deleteVnfA");
427             return;
428         }
429
430         LOGGER.debug ("Async Delete VNF: " + vnfName);
431         // Build and send Asynchronous response
432         try {
433             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
434             notifyPort.deleteVnfNotification (messageId, true, null, null);
435
436         } catch (Exception e) {
437             error = "Error sending deleteVnf notification " + e.getMessage ();
438             LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "deleteVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending deleteVnfA notification", e);
439             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
440         }
441
442         LOGGER.info (MessageEnum.RA_ASYNC_DELETE_VNF_COMPLETE, "", "deleteVnfA");
443         return;
444     }
445
446     /**
447      * This web service endpoint will rollback a previous Create VNF operation.
448      * A rollback object is returned to the client in a successful creation
449      * response. The client can pass that object as-is back to the rollbackVnf
450      * operation to undo the creation.
451      */
452     @Override
453     public void rollbackVnfA (VnfRollback rollback, String messageId, String notificationUrl) {
454         String serviceName = "RollbackVnfA";
455         MsoLogger.setServiceName (serviceName);
456         // Will capture execution time for metrics
457         long startTime = System.currentTimeMillis ();
458         String error;
459         // rollback may be null (e.g. if stack already existed when Create was called)
460         if (rollback == null) {
461             error = "Empty Rollback: No action to perform";
462             LOGGER.info (MessageEnum.RA_ROLLBACK_NULL, "", "rollbackVnfA");
463             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
464             return;
465         }
466
467         MsoLogger.setLogContext (rollback.getMsoRequest ());
468         LOGGER.info (MessageEnum.RA_ASYNC_ROLLBACK_VNF, "", "rollbackVnfA");
469
470         // Use the synchronous method to perform the actual rollback
471         MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory,cloudConfigFactory);
472
473         try {
474             vnfAdapter.rollbackVnf (rollback);
475             MsoLogger.setServiceName (serviceName);
476         } catch (VnfException e) {
477                 MsoLogger.setServiceName (serviceName);
478                 LOGGER.error (MessageEnum.RA_ROLLBACK_VNF_ERR, "", "rollbackVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending rollbackVnfA notification", e);
479             org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
480             String eMsg = null;
481             try {
482                 eMsg = e.getFaultInfo ().getMessage ();
483                 exCat = org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
484                                                                                                      .getCategory ()
485                                                                                                      .name ());
486             } catch (Exception e1) {
487                 LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "rollbackVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
488             }
489             // Build and send Asynchronous error response
490             try {
491                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
492                 notifyPort.rollbackVnfNotification (messageId, false, exCat, eMsg);
493             } catch (Exception e1) {
494                 error = "Error sending rollbackVnf notification " + e1.getMessage ();
495                 LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "rollbackVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending rollbackVnfA notification", e1);
496                 alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
497             }
498             LOGGER.info (MessageEnum.RA_ASYNC_ROLLBACK_VNF_COMPLETE, "", "rollbackVnfA");
499             return;
500         }
501
502         LOGGER.debug ("Async Rollback VNF:" + rollback.getVnfId ());
503         // Build and send Asynchronous response
504         try {
505             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
506             notifyPort.rollbackVnfNotification (messageId, true, null, null);
507         } catch (Exception e) {
508             error = "Error sending rollbackVnf notification " + e.getMessage ();
509             LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "rollbackVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending rollbackVnfA notification", e);
510             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
511         }
512
513         LOGGER.info (MessageEnum.RA_ASYNC_ROLLBACK_VNF_COMPLETE, "", "rollbackVnfA");
514         return;
515     }
516
517     private org.openecomp.mso.adapters.vnf.async.client.VnfRollback copyVrb (Holder <VnfRollback> hVrb) {
518         org.openecomp.mso.adapters.vnf.async.client.VnfRollback cvrb = new org.openecomp.mso.adapters.vnf.async.client.VnfRollback ();
519
520         if (hVrb != null && hVrb.value != null) {
521             org.openecomp.mso.adapters.vnf.async.client.MsoRequest cmr = new org.openecomp.mso.adapters.vnf.async.client.MsoRequest ();
522
523             cvrb.setCloudSiteId (hVrb.value.getCloudSiteId ());
524             if (hVrb.value.getMsoRequest() != null) {
525                 cmr.setRequestId (hVrb.value.getMsoRequest ().getRequestId ());
526                 cmr.setServiceInstanceId (hVrb.value.getMsoRequest ().getServiceInstanceId ());
527             } else {
528                 cmr.setRequestId (null);
529                 cmr.setServiceInstanceId (null);
530             }
531             cvrb.setMsoRequest (cmr);
532             cvrb.setVnfId (hVrb.value.getVnfId ());
533             cvrb.setTenantId (hVrb.value.getTenantId ());
534             cvrb.setTenantCreated (hVrb.value.getTenantCreated ());
535             cvrb.setVnfCreated (hVrb.value.getVnfCreated ());
536         }
537         return cvrb;
538     }
539
540     private CreateVnfNotification.Outputs copyCreateOutputs (Holder <Map <String, String>> hMap) {
541
542         CreateVnfNotification.Outputs outputs = new CreateVnfNotification.Outputs ();
543
544         if (hMap != null && hMap.value != null) {
545             Map <String, String> sMap = new HashMap <String, String> ();
546             sMap = hMap.value;
547             CreateVnfNotification.Outputs.Entry entry = new CreateVnfNotification.Outputs.Entry ();
548
549             for (String key : sMap.keySet ()) {
550                 entry.setKey (key);
551                 entry.setValue (sMap.get (key));
552                 outputs.getEntry ().add (entry);
553             }
554         }
555         return outputs;
556     }
557
558     private UpdateVnfNotification.Outputs copyUpdateOutputs (Holder <Map <String, String>> hMap) {
559
560         UpdateVnfNotification.Outputs outputs = new UpdateVnfNotification.Outputs ();
561
562         if (hMap != null && hMap.value != null) {
563             Map <String, String> sMap = new HashMap <String, String> ();
564             sMap = hMap.value;
565             UpdateVnfNotification.Outputs.Entry entry = new UpdateVnfNotification.Outputs.Entry ();
566
567             for (String key : sMap.keySet ()) {
568                 entry.setKey (key);
569                 entry.setValue (sMap.get (key));
570                 outputs.getEntry ().add (entry);
571             }
572         }
573         return outputs;
574     }
575
576     private QueryVnfNotification.Outputs copyQueryOutputs (Holder <Map <String, String>> hMap) {
577
578         QueryVnfNotification.Outputs outputs = new QueryVnfNotification.Outputs ();
579
580         if (hMap != null && hMap.value != null) {
581             Map <String, String> sMap = new HashMap <String, String> ();
582             sMap = hMap.value;
583
584             QueryVnfNotification.Outputs.Entry entry = new QueryVnfNotification.Outputs.Entry ();
585
586             for (String key : sMap.keySet ()) {
587                 entry.setKey (key);
588                 entry.setValue (sMap.get (key));
589                 outputs.getEntry ().add (entry);
590             }
591         }
592         return outputs;
593     }
594
595     private VnfAdapterNotify getNotifyEP (String notificationUrl) {
596
597         URL warWsdlLoc = null;
598         try {
599             warWsdlLoc = Thread.currentThread ().getContextClassLoader ().getResource ("VnfAdapterNotify.wsdl");
600         } catch (Exception e) {
601             LOGGER.error (MessageEnum.RA_WSDL_NOT_FOUND, "VnfAdapterNotify.wsdl", "", "getNotifyEP", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - WSDL not found", e);
602         }
603         if (warWsdlLoc == null) {
604                 LOGGER.error (MessageEnum.RA_WSDL_NOT_FOUND, "VnfAdapterNotify.wsdl", "", "getNotifyEP", MsoLogger.ErrorCode.BusinessProcesssError, "WSDL not found");
605         } else {
606             try {
607                 LOGGER.debug ("VnfAdpaterNotify.wsdl location:" + warWsdlLoc.toURI ().toString ());
608             } catch (Exception e) {
609                 LOGGER.error (MessageEnum.RA_WSDL_URL_CONVENTION_EXC, "VnfAdapterNotify.wsdl", "", "getNotifyEP", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - WSDL URL convention", e);
610             }
611         }
612
613         VnfAdapterNotify_Service notifySvc = new VnfAdapterNotify_Service (warWsdlLoc,
614                                                                            new QName ("http://com.att.mso/vnfNotify",
615                                                                                       "vnfAdapterNotify"));
616
617         VnfAdapterNotify notifyPort = notifySvc.getMsoVnfAdapterAsyncImplPort ();
618
619         BindingProvider bp = (BindingProvider) notifyPort;
620
621         URL epUrl = null;
622         try {
623             epUrl = new URL (notificationUrl);
624         } catch (MalformedURLException e1) {
625             LOGGER.error (MessageEnum.RA_INIT_NOTIF_EXC, "", "getNotifyEP", MsoLogger.ErrorCode.BusinessProcesssError, "MalformedURLException", e1);
626         }
627
628         LOGGER.debug ("Notification Endpoint URL: " + epUrl.toExternalForm ());
629
630         bp.getRequestContext ().put (BindingProvider.ENDPOINT_ADDRESS_PROPERTY, epUrl.toExternalForm ());
631
632         // authentication
633         try {
634             Map <String, Object> req_ctx = bp.getRequestContext ();
635             Map <String, List <String>> headers = new HashMap <String, List <String>> ();
636
637             String userCredentials = msoPropertiesFactory.getMsoJavaProperties (MSO_PROP_VNF_ADAPTER).getEncryptedProperty (BPEL_AUTH_PROP,
638                                                                                              "",
639                                                                                              ENCRYPTION_KEY);
640
641             String basicAuth = "Basic " + DatatypeConverter.printBase64Binary (userCredentials.getBytes ());
642             req_ctx.put (MessageContext.HTTP_REQUEST_HEADERS, headers);
643             headers.put ("Authorization", Collections.singletonList (basicAuth));
644         } catch (Exception e) {
645             LOGGER.error (MessageEnum.RA_SET_CALLBACK_AUTH_EXC, "", "getNotifyEP", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - Unable to set authorization in callback request", e);
646             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, "Unable to set authorization in callback request");
647         }
648
649         return notifyPort;
650     }
651
652 }