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