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