Removed MsoLogger class
[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.ErrorCode;
48 import org.onap.so.logger.MessageEnum;
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
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                 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                     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                     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                 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
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                 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                     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                     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                 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
293         String serviceName = "QueryVnfA";
294         logger.info("{}", MessageEnum.RA_ASYNC_QUERY_VNF);
295
296         // Use the synchronous method to perform the actual query
297         MsoVnfAdapter vnfAdapter = vnfImpl;
298
299         // Synchronous Web Service Outputs
300         Holder <Boolean> vnfExists = new Holder <> ();
301         Holder <String> vnfId = new Holder <> ();
302         Holder <VnfStatus> status = new Holder <> ();
303         Holder <Map <String, String>> outputs = new Holder <> ();
304
305         try {
306             vnfAdapter.queryVnf (cloudSiteId, tenantId, vnfName, msoRequest, vnfExists, vnfId, status, outputs);
307         } catch (VnfException e) {
308             logger.error("{} {} Exception sending queryVnfA notification ", MessageEnum.RA_QUERY_VNF_ERR,
309                 ErrorCode.BusinessProcesssError.getValue(), e);
310             org.onap.so.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
311             String eMsg = null;
312             try {
313                 eMsg = e.getFaultInfo ().getMessage ();
314                 exCat = org.onap.so.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
315                                                                                                      .getCategory ()
316                                                                                                      .name ());
317             } catch (Exception e1) {
318                 logger.error("{} {} Exception - fault info ", MessageEnum.RA_FAULT_INFO_EXC,
319                     ErrorCode.BusinessProcesssError.getValue(), e1);
320             }
321             // Build and send Asynchronous error response
322             try {
323                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
324                 notifyPort.queryVnfNotification (messageId, false, exCat, eMsg, null, null, null, null);
325             } catch (Exception e1) {
326                 logger.error("{} {} Exception sending queryVnf notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
327                     ErrorCode.BusinessProcesssError.getValue(), e1);
328             }
329             logger.info("{} queryVnfA", MessageEnum.RA_ASYNC_QUERY_VNF_COMPLETE);
330             return;
331         }
332
333         if (!vnfExists.value) {
334             logger.debug ("Async Query, VNF not found");
335         } else {
336             logger.debug("Async Query, VNF={}, status={}", vnfId.value, status.value);
337         }
338         // Build and send Asynchronous response
339         try {
340             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
341             org.onap.so.adapters.vnf.async.client.VnfStatus vnfS = org.onap.so.adapters.vnf.async.client.VnfStatus.fromValue (status.value.name ());
342             notifyPort.queryVnfNotification (messageId,
343                                              true,
344                                              null,
345                                              null,
346                                              vnfExists.value,
347                                              vnfId.value,
348                                              vnfS,
349                                              copyQueryOutputs (outputs));
350         } catch (Exception e) {
351             logger.error("{} {} Exception sending queryVnf notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
352                 ErrorCode.BusinessProcesssError.getValue(), e);
353         }
354
355         logger.info("{} queryVnfA", MessageEnum.RA_ASYNC_QUERY_VNF_COMPLETE);
356         return;
357     }
358
359     /**
360      * This is the Asynchronous "Delete VNF" web service implementation.
361      * It will delete a VNF by name or ID in the specified cloud and tenant.
362      *
363      * The method has no outputs.
364      *
365      * @param cloudSiteId CLLI code of the cloud site in which to delete
366      * @param tenantId Openstack tenant identifier
367      * @param vnfName VNF Name or Openstack ID
368      * @param msoRequest Request tracking information for logs
369      * @param notificationURL the target URL for asynchronous response
370      */
371     @Override
372     public void deleteVnfA (String cloudSiteId,
373                             String tenantId,
374                             String vnfName,
375                             String messageId,
376                             MsoRequest msoRequest,
377                             String notificationUrl) {
378
379         String serviceName = "DeleteVnfA";
380         logger.info("{}", MessageEnum.RA_ASYNC_DELETE_VNF);
381
382         // Use the synchronous method to perform the actual delete
383         MsoVnfAdapter vnfAdapter = vnfImpl;
384
385         try {
386             vnfAdapter.deleteVnf (cloudSiteId, tenantId, vnfName, msoRequest);
387         } catch (VnfException e) {
388             logger.error("{} {} Exception sending deleteVnfA notification ", MessageEnum.RA_DELETE_VNF_ERR,
389                 ErrorCode.BusinessProcesssError.getValue(), e);
390             org.onap.so.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
391             String eMsg = null;
392             try {
393                 eMsg = e.getFaultInfo ().getMessage ();
394                 exCat = org.onap.so.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
395                                                                                                      .getCategory ()
396                                                                                                      .name ());
397             } catch (Exception e1) {
398                 logger.error("{} {} Exception - fault info ", MessageEnum.RA_FAULT_INFO_EXC,
399                     ErrorCode.BusinessProcesssError.getValue(), e1);
400             }
401             // Build and send Asynchronous error response
402             try {
403                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
404                 notifyPort.deleteVnfNotification (messageId, false, exCat, eMsg);
405             } catch (Exception e1) {
406                 logger.error("{} {} Exception sending deleteVnfA notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
407                     ErrorCode.BusinessProcesssError.getValue(), e1);
408             }
409             logger.info("{} deleteVnfA", MessageEnum.RA_ASYNC_DELETE_VNF_COMPLETE);
410             return;
411         }
412
413         logger.debug("Async Delete VNF: {}", vnfName);
414         // Build and send Asynchronous response
415         try {
416             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
417             notifyPort.deleteVnfNotification (messageId, true, null, null);
418
419         } catch (Exception e) {
420             logger.error("{} {} Exception sending deleteVnfA notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
421                 ErrorCode.BusinessProcesssError.getValue(), e);
422         }
423
424         logger.info("{} deleteVnfA", MessageEnum.RA_ASYNC_DELETE_VNF_COMPLETE);
425         return;
426     }
427
428     /**
429      * This web service endpoint will rollback a previous Create VNF operation.
430      * A rollback object is returned to the client in a successful creation
431      * response. The client can pass that object as-is back to the rollbackVnf
432      * operation to undo the creation.
433      */
434     @Override
435     public void rollbackVnfA (VnfRollback rollback, String messageId, String notificationUrl) {
436         // rollback may be null (e.g. if stack already existed when Create was called)
437         if (rollback == null) {
438             logger.info("{} rollbackVnfA: Empty Rollback: No action to perform", MessageEnum.RA_ROLLBACK_NULL);
439             return;
440         }
441
442         logger.info("{} rollbackVnfA", MessageEnum.RA_ASYNC_ROLLBACK_VNF);
443
444         // Use the synchronous method to perform the actual rollback
445         MsoVnfAdapter vnfAdapter = vnfImpl;
446
447         try {
448             vnfAdapter.rollbackVnf (rollback);
449         } catch (VnfException e) {
450             logger.error("{} {} Exception sending rollbackVnfA notification ", MessageEnum.RA_ROLLBACK_VNF_ERR,
451                 ErrorCode.BusinessProcesssError.getValue(), e);
452             org.onap.so.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
453             String eMsg = null;
454             try {
455                 eMsg = e.getFaultInfo ().getMessage ();
456                 exCat = org.onap.so.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
457                                                                                                      .getCategory ()
458                                                                                                      .name ());
459             } catch (Exception e1) {
460                 logger.error("{} {} Exception - fault info ", MessageEnum.RA_FAULT_INFO_EXC,
461                     ErrorCode.BusinessProcesssError.getValue(), e1);
462             }
463             // Build and send Asynchronous error response
464             try {
465                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
466                 notifyPort.rollbackVnfNotification (messageId, false, exCat, eMsg);
467             } catch (Exception e1) {
468                 logger.error("{} {} Exception sending rollbackVnfA notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
469                     ErrorCode.BusinessProcesssError.getValue(), e1);
470             }
471             logger.info("{} rollbackVnfA", MessageEnum.RA_ASYNC_ROLLBACK_VNF_COMPLETE);
472             return;
473         }
474
475         logger.debug ("Async Rollback VNF:" + rollback.getVnfId ());
476         // Build and send Asynchronous response
477         try {
478             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
479             notifyPort.rollbackVnfNotification (messageId, true, null, null);
480         } catch (Exception e) {
481             logger.error("{} {} Exception sending rollbackVnfA notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
482                 ErrorCode.BusinessProcesssError.getValue(), e);
483         }
484
485         logger.info("{} rollbackVnfA", MessageEnum.RA_ASYNC_ROLLBACK_VNF_COMPLETE);
486         return;
487     }
488
489     private org.onap.so.adapters.vnf.async.client.VnfRollback copyVrb (Holder <VnfRollback> hVrb) {
490         org.onap.so.adapters.vnf.async.client.VnfRollback cvrb = new org.onap.so.adapters.vnf.async.client.VnfRollback ();
491
492         if (hVrb != null && hVrb.value != null) {
493             org.onap.so.adapters.vnf.async.client.MsoRequest cmr = new org.onap.so.adapters.vnf.async.client.MsoRequest ();
494
495             cvrb.setCloudSiteId (hVrb.value.getCloudSiteId ());
496             if (hVrb.value.getMsoRequest() != null) {
497                 cmr.setRequestId (hVrb.value.getMsoRequest ().getRequestId ());
498                 cmr.setServiceInstanceId (hVrb.value.getMsoRequest ().getServiceInstanceId ());
499             } else {
500                 cmr.setRequestId (null);
501                 cmr.setServiceInstanceId (null);
502             }
503             cvrb.setMsoRequest (cmr);
504             cvrb.setVnfId (hVrb.value.getVnfId ());
505             cvrb.setTenantId (hVrb.value.getTenantId ());
506             cvrb.setTenantCreated (hVrb.value.getTenantCreated ());
507             cvrb.setVnfCreated (hVrb.value.getVnfCreated ());
508         }
509         return cvrb;
510     }
511
512     private CreateVnfNotification.Outputs copyCreateOutputs (Holder <Map <String, String>> hMap) {
513
514         CreateVnfNotification.Outputs outputs = new CreateVnfNotification.Outputs ();
515
516         if (hMap != null && hMap.value != null) {
517             Map <String, String> sMap = new HashMap <> ();
518             sMap = hMap.value;
519             CreateVnfNotification.Outputs.Entry entry = new CreateVnfNotification.Outputs.Entry ();
520
521             for (String key : sMap.keySet ()) {
522                 entry.setKey (key);
523                 entry.setValue (sMap.get (key));
524                 outputs.getEntry ().add (entry);
525             }
526         }
527         return outputs;
528     }
529
530     private UpdateVnfNotification.Outputs copyUpdateOutputs (Holder <Map <String, String>> hMap) {
531
532         UpdateVnfNotification.Outputs outputs = new UpdateVnfNotification.Outputs ();
533
534         if (hMap != null && hMap.value != null) {
535             Map <String, String> sMap = new HashMap <> ();
536             sMap = hMap.value;
537             UpdateVnfNotification.Outputs.Entry entry = new UpdateVnfNotification.Outputs.Entry ();
538
539             for (Map.Entry<String,String> mapEntry : sMap.entrySet ()) {
540                 String key = mapEntry.getKey();
541                 String value = mapEntry.getValue();
542                 entry.setKey (key);
543                 entry.setValue (value);
544                 outputs.getEntry ().add (entry);
545             }
546         }
547         return outputs;
548     }
549
550     private QueryVnfNotification.Outputs copyQueryOutputs (Holder <Map <String, String>> hMap) {
551
552         QueryVnfNotification.Outputs outputs = new QueryVnfNotification.Outputs ();
553
554         if (hMap != null && hMap.value != null) {
555             Map <String, String> sMap = new HashMap <> ();
556             sMap = hMap.value;
557
558             QueryVnfNotification.Outputs.Entry entry = new QueryVnfNotification.Outputs.Entry ();
559
560             for (Map.Entry<String,String> mapEntry : sMap.entrySet ()) {
561                 String key = mapEntry.getKey();
562                 String value = mapEntry.getValue();
563                 entry.setKey (key);
564                 entry.setValue (value);
565                 outputs.getEntry ().add (entry);
566             }
567         }
568         return outputs;
569     }
570
571     private VnfAdapterNotify getNotifyEP (String notificationUrl) {
572
573         URL warWsdlLoc = null;
574         try {
575             warWsdlLoc = Thread.currentThread ().getContextClassLoader ().getResource ("VnfAdapterNotify.wsdl");
576         } catch (Exception e) {
577             logger.error("{} {} Exception - WSDL not found ", MessageEnum.RA_WSDL_NOT_FOUND,
578                 ErrorCode.BusinessProcesssError.getValue(), e);
579         }
580         if (warWsdlLoc == null) {
581             logger.error("{} {} WSDL not found", MessageEnum.RA_WSDL_NOT_FOUND,
582                 ErrorCode.BusinessProcesssError.getValue());
583         } else {
584             try {
585                 logger.debug("VnfAdpaterNotify.wsdl location:{}", warWsdlLoc.toURI().toString());
586             } catch (Exception e) {
587                 logger.error("{} {} Exception - WSDL URL convention ", MessageEnum.RA_WSDL_URL_CONVENTION_EXC,
588                     ErrorCode.BusinessProcesssError.getValue(), e);
589             }
590         }
591
592         VnfAdapterNotify_Service notifySvc = new VnfAdapterNotify_Service (warWsdlLoc,
593                                                                            new QName ("http://org.onap.so/vnfNotify",
594                                                                                       "vnfAdapterNotify"));
595
596         VnfAdapterNotify notifyPort = notifySvc.getMsoVnfAdapterAsyncImplPort ();
597
598         BindingProvider bp = (BindingProvider) notifyPort;
599
600         URL epUrl = null;
601         try {
602             epUrl = new URL (notificationUrl);
603         } catch (MalformedURLException e1) {
604             logger.error("{} {} MalformedURLException ", MessageEnum.RA_INIT_NOTIF_EXC,
605                 ErrorCode.BusinessProcesssError.getValue(), e1);
606         }
607
608         if(null != epUrl) {
609             logger.debug("Notification Endpoint URL: {}", epUrl.toExternalForm());
610             bp.getRequestContext ().put (BindingProvider.ENDPOINT_ADDRESS_PROPERTY, epUrl.toExternalForm ());
611         }
612         else {
613             logger.debug ("epUrl is NULL:");
614         }
615
616         // authentication
617         try {
618             Map <String, Object> reqCtx = bp.getRequestContext ();
619             Map <String, List <String>> headers = new HashMap <> ();
620
621             String userCredentials = this.getEncryptedProperty(BPEL_AUTH_PROP, "", ENCRYPTION_KEY_PROP);
622
623             String basicAuth = "Basic " + DatatypeConverter.printBase64Binary (userCredentials.getBytes ());
624             reqCtx.put (MessageContext.HTTP_REQUEST_HEADERS, headers);
625             headers.put ("Authorization", Collections.singletonList (basicAuth));
626         } catch (Exception e) {
627             logger.error("{} {} Exception - Unable to set authorization in callback request ",
628                 MessageEnum.RA_SET_CALLBACK_AUTH_EXC, ErrorCode.BusinessProcesssError.getValue(), e);
629         }
630
631         return notifyPort;
632     }
633     
634     public String getEncryptedProperty(String key, String defaultValue, String encryptionKey) {
635         try {
636                         return CryptoUtils.decrypt(this.environment.getProperty(key), this.environment.getProperty(encryptionKey));
637                 } catch (GeneralSecurityException e) {
638           logger.debug("Exception while decrypting property: {} ", this.environment.getProperty(key), e);
639                 }
640                 return defaultValue;
641
642         }
643
644 }