5c654298fbcaecd3a3303755fb9aa0f6845813cc
[so.git] / adapters / mso-vnf-adapter / src / main / java / org / openecomp / mso / adapters / vnf / MsoVnfAdapterAsyncImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.mso.adapters.vnf;
23
24
25 import java.net.MalformedURLException;
26 import java.net.URL;
27 import java.util.Collections;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31
32 import javax.jws.WebService;
33 import javax.xml.bind.DatatypeConverter;
34 import javax.xml.namespace.QName;
35 import javax.xml.ws.BindingProvider;
36 import javax.xml.ws.Holder;
37 import javax.xml.ws.handler.MessageContext;
38
39 import org.openecomp.mso.adapters.vnf.async.client.CreateVnfNotification;
40 import org.openecomp.mso.adapters.vnf.async.client.QueryVnfNotification;
41 import org.openecomp.mso.adapters.vnf.async.client.UpdateVnfNotification;
42 import org.openecomp.mso.adapters.vnf.async.client.VnfAdapterNotify;
43 import org.openecomp.mso.adapters.vnf.async.client.VnfAdapterNotify_Service;
44 import org.openecomp.mso.adapters.vnf.exceptions.VnfException;
45 import org.openecomp.mso.cloud.CloudConfigFactory;
46 import org.openecomp.mso.entity.MsoRequest;
47 import org.openecomp.mso.logger.MessageEnum;
48 import org.openecomp.mso.logger.MsoAlarmLogger;
49 import org.openecomp.mso.logger.MsoLogger;
50 import org.openecomp.mso.openstack.beans.VnfRollback;
51 import org.openecomp.mso.openstack.beans.VnfStatus;
52 import org.openecomp.mso.properties.MsoPropertiesFactory;
53
54 @WebService(serviceName = "VnfAdapterAsync", endpointInterface = "org.openecomp.mso.adapters.vnf.MsoVnfAdapterAsync", targetNamespace = "http://org.openecomp.mso/vnfA")
55 public class MsoVnfAdapterAsyncImpl implements MsoVnfAdapterAsync {
56
57     MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
58     CloudConfigFactory cloudConfigFactory=new CloudConfigFactory();
59
60     public static final String MSO_PROP_VNF_ADAPTER="MSO_PROP_VNF_ADAPTER";
61     private static final 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         // Use the synchronous method to perform the actual Create
133         MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory, cloudConfigFactory);
134
135         // Synchronous Web Service Outputs
136         Holder <String> vnfId = new Holder <> ();
137         Holder <Map <String, String>> outputs = new Holder <> ();
138         Holder <VnfRollback> vnfRollback = new Holder <> ();
139
140         try {
141             vnfAdapter.createVnf (cloudSiteId,
142                                   tenantId,
143                                   vnfType,
144                                   vnfVersion,
145                                   vnfName,
146                                   requestType,
147                                   volumeGroupHeatStackId,
148                                   inputs,
149                                   failIfExists,
150                                   backout,
151                                   msoRequest,
152                                   vnfId,
153                                   outputs,
154                                   vnfRollback);
155             MsoLogger.setServiceName (serviceName);
156         } catch (VnfException e) {
157             MsoLogger.setServiceName (serviceName);
158             LOGGER.error (MessageEnum.RA_CREATE_VNF_ERR,  vnfName, cloudSiteId, tenantId, "", "createVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "VnfException in createVnfA", e);
159             org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
160             String eMsg = null;
161             try {
162                 eMsg = e.getFaultInfo ().getMessage ();
163                 exCat = org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
164                                                                                                      .getCategory ()
165                                                                                                      .name ());
166             } catch (Exception e1) {
167                 LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "createVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - Fault info", e1);
168             }
169             // Build and send Asynchronous error response
170             try {
171                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
172                 notifyPort.createVnfNotification (messageId, false, exCat, eMsg, null, null, null);
173             } catch (Exception e1) {
174                 error = "Error sending createVnf notification " + e1.getMessage ();
175                 LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "createVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending createVnf notification", e1);
176                 alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
177             }
178             LOGGER.info (MessageEnum.RA_ASYNC_CREATE_VNF_COMPLETE, "", "createVnfA", "", "createVnfA");
179             return;
180         }
181         LOGGER.debug ("Async Create VNF: " + vnfName + " VnfId:" + vnfId.value);
182         // Build and send Asynchronous response
183         try {
184             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
185             notifyPort.createVnfNotification (messageId,
186                                               true,
187                                               null,
188                                               null,
189                                               vnfId.value,
190                                               copyCreateOutputs (outputs),
191                                               copyVrb (vnfRollback));
192         } catch (Exception e) {
193             error = "Error sending createVnf notification " + e.getMessage ();
194             LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "createVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending createVnf notification", e);
195             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
196         }
197         LOGGER.info (MessageEnum.RA_ASYNC_CREATE_VNF_COMPLETE, "", "createVnfA");
198         return;
199     }
200
201     @Override
202     public void updateVnfA (String cloudSiteId,
203                             String tenantId,
204                             String vnfType,
205                             String vnfVersion,
206                             String vnfName,
207                             String requestType,
208                             String volumeGroupHeatStackId,
209                             Map <String, String> inputs,
210                             String messageId,
211                             MsoRequest msoRequest,
212                             String notificationUrl) {
213         String error;
214         String serviceName = "UpdateVnfA";
215         MsoLogger.setServiceName (serviceName);
216         MsoLogger.setLogContext (msoRequest);
217         LOGGER.info (MessageEnum.RA_ASYNC_UPDATE_VNF, vnfName, vnfType, cloudSiteId, tenantId, "", "UpdateVnfA");
218
219         // Use the synchronous method to perform the actual Create
220         MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory,cloudConfigFactory);
221
222         // Synchronous Web Service Outputs
223         Holder <String> vnfId = new Holder <> ();
224         Holder <Map <String, String>> outputs = new Holder <> ();
225         Holder <VnfRollback> vnfRollback = new Holder <> ();
226
227         try {
228             vnfAdapter.updateVnf (cloudSiteId, tenantId, vnfType,vnfVersion, vnfName, requestType, volumeGroupHeatStackId, inputs, msoRequest, outputs, vnfRollback);
229             MsoLogger.setServiceName (serviceName);
230         } catch (VnfException e) {
231             MsoLogger.setServiceName (serviceName);
232             LOGGER.error (MessageEnum.RA_UPDATE_VNF_ERR,  vnfName, cloudSiteId, tenantId, "", "UpdateVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending updateVnf notification", e);
233             org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
234             String eMsg = null;
235             try {
236                 eMsg = e.getFaultInfo ().getMessage ();
237                 exCat = org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
238                                                                                                      .getCategory ()
239                                                                                                      .name ());
240             } catch (Exception e1) {
241                 LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "UpdateVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
242             }
243             // Build and send Asynchronous error response
244             try {
245                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
246                 notifyPort.updateVnfNotification (messageId, false, exCat, eMsg, null, null);
247             } catch (Exception e1) {
248                 error = "Error sending updateVnf notification " + e1.getMessage ();
249                 LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "UpdateVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending updateVnf notification", e1);
250                 alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
251             }
252             LOGGER.info (MessageEnum.RA_ASYNC_UPDATE_VNF_COMPLETE, "", "UpdateVnfA");
253             return;
254         }
255         LOGGER.debug ("Async Update VNF: " + vnfName + " VnfId:" + vnfId.value);
256         // Build and send Asynchronous response
257         try {
258             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
259             notifyPort.updateVnfNotification (messageId,
260                                               true,
261                                               null,
262                                               null,
263                                               copyUpdateOutputs (outputs),
264                                               copyVrb (vnfRollback));
265         } catch (Exception e) {
266             error = "Error sending updateVnf notification " + e.getMessage ();
267             LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "UpdateVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending updateVnf notification", e);
268             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
269         }
270         LOGGER.info (MessageEnum.RA_ASYNC_UPDATE_VNF_COMPLETE, "", "UpdateVnfA");
271         return;
272     }
273
274     /**
275      * This is the "Query VNF" web service implementation.
276      * It will look up a VNF by name or ID in the specified cloud and tenant.
277      *
278      * The method returns an indicator that the VNF exists, its Openstack internal
279      * ID, its status, and the set of outputs (from when the stack was created).
280      *
281      * @param cloudSiteId CLLI code of the cloud site in which to query
282      * @param tenantId Openstack tenant identifier
283      * @param vnfName VNF Name or Openstack ID
284      * @param msoRequest Request tracking information for logs
285      * @param notificationURL the target URL for asynchronous response
286      */
287     @Override
288     public void queryVnfA (String cloudSiteId,
289                            String tenantId,
290                            String vnfName,
291                            String messageId,
292                            MsoRequest msoRequest,
293                            String notificationUrl) {
294         String error;
295         String serviceName = "QueryVnfA";
296         MsoLogger.setServiceName (serviceName);
297         MsoLogger.setLogContext (msoRequest);
298         LOGGER.info (MessageEnum.RA_ASYNC_QUERY_VNF, vnfName, cloudSiteId, tenantId);
299
300         // Use the synchronous method to perform the actual query
301         MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory,cloudConfigFactory);
302
303         // Synchronous Web Service Outputs
304         Holder <Boolean> vnfExists = new Holder <> ();
305         Holder <String> vnfId = new Holder <> ();
306         Holder <VnfStatus> status = new Holder <> ();
307         Holder <Map <String, String>> outputs = new Holder <> ();
308
309         try {
310             vnfAdapter.queryVnf (cloudSiteId, tenantId, vnfName, msoRequest, vnfExists, vnfId, status, outputs);
311             MsoLogger.setServiceName (serviceName);
312         } catch (VnfException e) {
313             MsoLogger.setServiceName (serviceName);
314             LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR,  vnfName, cloudSiteId, tenantId, "", "queryVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending queryVnfA notification", e);
315             org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
316             String eMsg = null;
317             try {
318                 eMsg = e.getFaultInfo ().getMessage ();
319                 exCat = org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
320                                                                                                      .getCategory ()
321                                                                                                      .name ());
322             } catch (Exception e1) {
323                 LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "queryVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
324             }
325             // Build and send Asynchronous error response
326             try {
327                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
328                 notifyPort.queryVnfNotification (messageId, false, exCat, eMsg, null, null, null, null);
329             } catch (Exception e1) {
330                 error = "Error sending queryVnf notification " + e1.getMessage ();
331                 LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "queryVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending queryVnf notification", e1);
332                 alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
333             }
334             LOGGER.info (MessageEnum.RA_ASYNC_QUERY_VNF_COMPLETE, "", "queryVnfA");
335             return;
336         }
337
338         if (!vnfExists.value) {
339             LOGGER.debug ("Async Query, VNF not found");
340         } else {
341             LOGGER.debug ("Async Query, VNF=" + vnfId.value + ", status=" + status.value);
342         }
343         // Build and send Asynchronous response
344         try {
345             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
346             org.openecomp.mso.adapters.vnf.async.client.VnfStatus vnfS = org.openecomp.mso.adapters.vnf.async.client.VnfStatus.fromValue (status.value.name ());
347             notifyPort.queryVnfNotification (messageId,
348                                              true,
349                                              null,
350                                              null,
351                                              vnfExists.value,
352                                              vnfId.value,
353                                              vnfS,
354                                              copyQueryOutputs (outputs));
355         } catch (Exception e) {
356             error = "Error sending queryVnf notification " + e.getMessage ();
357             LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "queryVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending queryVnf notification", e);
358             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
359         }
360
361         LOGGER.info (MessageEnum.RA_ASYNC_QUERY_VNF_COMPLETE, "", "queryVnfA");
362         return;
363     }
364
365     /**
366      * This is the Asynchronous "Delete VNF" web service implementation.
367      * It will delete a VNF by name or ID in the specified cloud and tenant.
368      *
369      * The method has no outputs.
370      *
371      * @param cloudSiteId CLLI code of the cloud site in which to delete
372      * @param tenantId Openstack tenant identifier
373      * @param vnfName VNF Name or Openstack ID
374      * @param messageId
375      * @param msoRequest Request tracking information for logs
376      * @param notificationUrl the target URL for asynchronous response
377      */
378     @Override
379     public void deleteVnfA (String cloudSiteId,
380                             String tenantId,
381                             String vnfName,
382                             String messageId,
383                             MsoRequest msoRequest,
384                             String notificationUrl) {
385         String error;
386         String serviceName = "DeleteVnfA";
387         MsoLogger.setServiceName (serviceName);
388         MsoLogger.setLogContext (msoRequest);
389         LOGGER.info (MessageEnum.RA_ASYNC_DELETE_VNF, vnfName, cloudSiteId, tenantId);
390
391         // Use the synchronous method to perform the actual delete
392         MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory,cloudConfigFactory);
393
394         try {
395             vnfAdapter.deleteVnf (cloudSiteId, tenantId, vnfName, msoRequest);
396             MsoLogger.setServiceName (serviceName);
397         } catch (VnfException e) {
398             MsoLogger.setServiceName (serviceName);
399             LOGGER.error (MessageEnum.RA_DELETE_VNF_ERR,  vnfName, cloudSiteId, tenantId, "", "deleteVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending deleteVnfA notification", e);
400             org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
401             String eMsg = null;
402             try {
403                 eMsg = e.getFaultInfo ().getMessage ();
404                 exCat = org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
405                                                                                                      .getCategory ()
406                                                                                                      .name ());
407             } catch (Exception e1) {
408                 LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "deleteVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
409             }
410             // Build and send Asynchronous error response
411             try {
412                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
413                 notifyPort.deleteVnfNotification (messageId, false, exCat, eMsg);
414             } catch (Exception e1) {
415                 error = "Error sending deleteVnf notification " + e1.getMessage ();
416                 LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "deleteVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending deleteVnfA notification", e1);
417                 alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
418             }
419             LOGGER.info (MessageEnum.RA_ASYNC_DELETE_VNF_COMPLETE, "", "deleteVnfA");
420             return;
421         }
422
423         LOGGER.debug ("Async Delete VNF: " + vnfName);
424         // Build and send Asynchronous response
425         try {
426             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
427             notifyPort.deleteVnfNotification (messageId, true, null, null);
428
429         } catch (Exception e) {
430             error = "Error sending deleteVnf notification " + e.getMessage ();
431             LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "deleteVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending deleteVnfA notification", e);
432             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
433         }
434
435         LOGGER.info (MessageEnum.RA_ASYNC_DELETE_VNF_COMPLETE, "", "deleteVnfA");
436         return;
437     }
438
439     /**
440      * This web service endpoint will rollback a previous Create VNF operation.
441      * A rollback object is returned to the client in a successful creation
442      * response. The client can pass that object as-is back to the rollbackVnf
443      * operation to undo the creation.
444      */
445     @Override
446     public void rollbackVnfA (VnfRollback rollback, String messageId, String notificationUrl) {
447         String serviceName = "RollbackVnfA";
448         MsoLogger.setServiceName (serviceName);
449         String error;
450         // rollback may be null (e.g. if stack already existed when Create was called)
451         if (rollback == null) {
452             error = "Empty Rollback: No action to perform";
453             LOGGER.info (MessageEnum.RA_ROLLBACK_NULL, "", "rollbackVnfA");
454             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
455             return;
456         }
457
458         MsoLogger.setLogContext (rollback.getMsoRequest ());
459         LOGGER.info (MessageEnum.RA_ASYNC_ROLLBACK_VNF, "", "rollbackVnfA");
460
461         // Use the synchronous method to perform the actual rollback
462         MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory,cloudConfigFactory);
463
464         try {
465             vnfAdapter.rollbackVnf (rollback);
466             MsoLogger.setServiceName (serviceName);
467         } catch (VnfException e) {
468             MsoLogger.setServiceName (serviceName);
469             LOGGER.error (MessageEnum.RA_ROLLBACK_VNF_ERR, "", "rollbackVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending rollbackVnfA notification", e);
470             org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
471             String eMsg = null;
472             try {
473                 eMsg = e.getFaultInfo ().getMessage ();
474                 exCat = org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
475                                                                                                      .getCategory ()
476                                                                                                      .name ());
477             } catch (Exception e1) {
478                 LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "rollbackVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
479             }
480             // Build and send Asynchronous error response
481             try {
482                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
483                 notifyPort.rollbackVnfNotification (messageId, false, exCat, eMsg);
484             } catch (Exception e1) {
485                 error = "Error sending rollbackVnf notification " + e1.getMessage ();
486                 LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "rollbackVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending rollbackVnfA notification", e1);
487                 alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
488             }
489             LOGGER.info (MessageEnum.RA_ASYNC_ROLLBACK_VNF_COMPLETE, "", "rollbackVnfA");
490             return;
491         }
492
493         LOGGER.debug ("Async Rollback VNF:" + rollback.getVnfId ());
494         // Build and send Asynchronous response
495         try {
496             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
497             notifyPort.rollbackVnfNotification (messageId, true, null, null);
498         } catch (Exception e) {
499             error = "Error sending rollbackVnf notification " + e.getMessage ();
500             LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "rollbackVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending rollbackVnfA notification", e);
501             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
502         }
503
504         LOGGER.info (MessageEnum.RA_ASYNC_ROLLBACK_VNF_COMPLETE, "", "rollbackVnfA");
505         return;
506     }
507
508     private org.openecomp.mso.adapters.vnf.async.client.VnfRollback copyVrb (Holder <VnfRollback> hVrb) {
509         org.openecomp.mso.adapters.vnf.async.client.VnfRollback cvrb = new org.openecomp.mso.adapters.vnf.async.client.VnfRollback ();
510
511         if (hVrb != null && hVrb.value != null) {
512             org.openecomp.mso.adapters.vnf.async.client.MsoRequest cmr = new org.openecomp.mso.adapters.vnf.async.client.MsoRequest ();
513
514             cvrb.setCloudSiteId (hVrb.value.getCloudSiteId ());
515             if (hVrb.value.getMsoRequest() != null) {
516                 cmr.setRequestId (hVrb.value.getMsoRequest ().getRequestId ());
517                 cmr.setServiceInstanceId (hVrb.value.getMsoRequest ().getServiceInstanceId ());
518             } else {
519                 cmr.setRequestId (null);
520                 cmr.setServiceInstanceId (null);
521             }
522             cvrb.setMsoRequest (cmr);
523             cvrb.setVnfId (hVrb.value.getVnfId ());
524             cvrb.setTenantId (hVrb.value.getTenantId ());
525             cvrb.setTenantCreated (hVrb.value.getTenantCreated ());
526             cvrb.setVnfCreated (hVrb.value.getVnfCreated ());
527         }
528         return cvrb;
529     }
530
531     private CreateVnfNotification.Outputs copyCreateOutputs (Holder <Map <String, String>> hMap) {
532
533         CreateVnfNotification.Outputs outputs = new CreateVnfNotification.Outputs ();
534
535         if (hMap != null && hMap.value != null) {
536             Map <String, String> sMap = new HashMap <> ();
537             sMap = hMap.value;
538             CreateVnfNotification.Outputs.Entry entry = new CreateVnfNotification.Outputs.Entry ();
539
540             for (String key : sMap.keySet ()) {
541                 entry.setKey (key);
542                 entry.setValue (sMap.get (key));
543                 outputs.getEntry ().add (entry);
544             }
545         }
546         return outputs;
547     }
548
549     private UpdateVnfNotification.Outputs copyUpdateOutputs (Holder <Map <String, String>> hMap) {
550
551         UpdateVnfNotification.Outputs outputs = new UpdateVnfNotification.Outputs ();
552
553         if (hMap != null && hMap.value != null) {
554             Map <String, String> sMap = new HashMap <> ();
555             sMap = hMap.value;
556             UpdateVnfNotification.Outputs.Entry entry = new UpdateVnfNotification.Outputs.Entry ();
557
558             for (Map.Entry<String,String> mapEntry : sMap.entrySet ()) {
559                 String key = mapEntry.getKey();
560                 String value = mapEntry.getValue();
561                 entry.setKey (key);
562                 entry.setValue (value);
563                 outputs.getEntry ().add (entry);
564             }
565         }
566         return outputs;
567     }
568
569     private QueryVnfNotification.Outputs copyQueryOutputs (Holder <Map <String, String>> hMap) {
570
571         QueryVnfNotification.Outputs outputs = new QueryVnfNotification.Outputs ();
572
573         if (hMap != null && hMap.value != null) {
574             Map <String, String> sMap = new HashMap <> ();
575             sMap = hMap.value;
576
577             QueryVnfNotification.Outputs.Entry entry = new QueryVnfNotification.Outputs.Entry ();
578
579             for (Map.Entry<String,String> mapEntry : sMap.entrySet ()) {
580                 String key = mapEntry.getKey();
581                 String value = mapEntry.getValue();
582                 entry.setKey (key);
583                 entry.setValue (value);
584                 outputs.getEntry ().add (entry);
585             }
586         }
587         return outputs;
588     }
589
590     private VnfAdapterNotify getNotifyEP (String notificationUrl) {
591
592         URL warWsdlLoc = null;
593         try {
594             warWsdlLoc = Thread.currentThread ().getContextClassLoader ().getResource ("VnfAdapterNotify.wsdl");
595         } catch (Exception e) {
596             LOGGER.error (MessageEnum.RA_WSDL_NOT_FOUND, "VnfAdapterNotify.wsdl", "", "getNotifyEP", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - WSDL not found", e);
597         }
598         if (warWsdlLoc == null) {
599             LOGGER.error (MessageEnum.RA_WSDL_NOT_FOUND, "VnfAdapterNotify.wsdl", "", "getNotifyEP", MsoLogger.ErrorCode.BusinessProcesssError, "WSDL not found");
600         } else {
601             try {
602                 LOGGER.debug ("VnfAdpaterNotify.wsdl location:" + warWsdlLoc.toURI ().toString ());
603             } catch (Exception e) {
604                 LOGGER.error (MessageEnum.RA_WSDL_URL_CONVENTION_EXC, "VnfAdapterNotify.wsdl", "", "getNotifyEP", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - WSDL URL convention", e);
605             }
606         }
607
608         VnfAdapterNotify_Service notifySvc = new VnfAdapterNotify_Service (warWsdlLoc,
609                                                                            new QName ("http://org.openecomp.mso/vnfNotify",
610                                                                                       "vnfAdapterNotify"));
611
612         VnfAdapterNotify notifyPort = notifySvc.getMsoVnfAdapterAsyncImplPort ();
613
614         BindingProvider bp = (BindingProvider) notifyPort;
615
616         URL epUrl = null;
617         try {
618             epUrl = new URL (notificationUrl);
619         } catch (MalformedURLException e1) {
620             LOGGER.error (MessageEnum.RA_INIT_NOTIF_EXC, "", "getNotifyEP", MsoLogger.ErrorCode.BusinessProcesssError, "MalformedURLException", e1);
621         }
622
623         if(null != epUrl) {
624             LOGGER.debug ("Notification Endpoint URL: " + epUrl.toExternalForm ());
625             bp.getRequestContext ().put (BindingProvider.ENDPOINT_ADDRESS_PROPERTY, epUrl.toExternalForm ());
626         }
627         else {
628             LOGGER.debug ("epUrl is NULL:");
629         }
630
631         // authentication
632         try {
633             Map <String, Object> reqCtx = bp.getRequestContext ();
634             Map <String, List <String>> headers = new HashMap <> ();
635
636             String userCredentials = msoPropertiesFactory.getMsoJavaProperties (MSO_PROP_VNF_ADAPTER).getEncryptedProperty (BPEL_AUTH_PROP,
637                                                                                              "",
638                                                                                              ENCRYPTION_KEY);
639
640             String basicAuth = "Basic " + DatatypeConverter.printBase64Binary (userCredentials.getBytes ());
641             reqCtx.put (MessageContext.HTTP_REQUEST_HEADERS, headers);
642             headers.put ("Authorization", Collections.singletonList (basicAuth));
643         } catch (Exception e) {
644             LOGGER.error (MessageEnum.RA_SET_CALLBACK_AUTH_EXC, "", "getNotifyEP", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - Unable to set authorization in callback request", e);
645             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, "Unable to set authorization in callback request");
646         }
647
648         return notifyPort;
649     }
650
651 }