5e42fa56038ff04bd122a59b6087cfe47c1a7142
[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 cloudOwner cloud owner of the cloud site in which to create the VNF
112      * @param tenantId Openstack tenant identifier
113      * @param vnfType VNF type key, should match a VNF definition in catalog DB
114      * @param vnfName Name to be assigned to the new VNF
115      * @param inputs Map of key=value inputs for VNF stack creation
116      * @param failIfExists Flag whether already existing VNF should be considered
117      *        a success or failure
118      * @param msoRequest Request tracking information for logs
119      * @param notificationURL the target URL for asynchronous response
120      */
121     @Override
122     public void createVnfA (String cloudSiteId,
123                             String cloudOwner,
124                             String tenantId,
125                             String vnfType,
126                             String vnfVersion,
127                             String vnfName,
128                             String requestType,
129                             String volumeGroupHeatStackId,
130                             Map <String, Object> inputs,
131                             Boolean failIfExists,
132                             Boolean backout,
133                             Boolean enableBridge,
134                             String messageId,
135                             MsoRequest msoRequest,
136                             String notificationUrl) {
137
138         logger.info("{} createVnfA", MessageEnum.RA_ASYNC_CREATE_VNF);
139         // Use the synchronous method to perform the actual Create
140         MsoVnfAdapter vnfAdapter = vnfImpl;
141         // Synchronous Web Service Outputs
142         Holder <String> vnfId = new Holder <> ();
143         Holder <Map <String, String>> outputs = new Holder <> ();
144         Holder <VnfRollback> vnfRollback = new Holder <> ();
145
146         try {
147             vnfAdapter.createVnf (cloudSiteId,
148                                   cloudOwner,
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         } catch (VnfException e) {
164             logger.error("{} {} VnfException in createVnfA ", MessageEnum.RA_CREATE_VNF_ERR,
165                 ErrorCode.BusinessProcesssError.getValue(), e);
166             org.onap.so.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
167             String eMsg = null;
168             try {
169                 eMsg = e.getFaultInfo ().getMessage ();
170                 exCat = org.onap.so.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
171                                                                                                      .getCategory ()
172                                                                                                      .name ());
173             } catch (Exception e1) {
174                 logger.error("{} {} Exception - Fault info ", MessageEnum.RA_FAULT_INFO_EXC,
175                     ErrorCode.BusinessProcesssError.getValue(), 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                 logger.error("{} {} Exception sending createVnf notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
183                     ErrorCode.BusinessProcesssError.getValue(), e1);
184             }
185             logger.info("{}", MessageEnum.RA_ASYNC_CREATE_VNF_COMPLETE);
186             return;
187         }
188         logger.debug("Async Create VNF: {} VnfId:{}", vnfName, vnfId.value);
189         // Build and send Asynchronous response
190         try {
191             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
192             notifyPort.createVnfNotification (messageId,
193                                               true,
194                                               null,
195                                               null,
196                                               vnfId.value,
197                                               copyCreateOutputs (outputs),
198                                               copyVrb (vnfRollback));
199         } catch (Exception e) {
200             logger.error("{} {} Exception sending createVnf notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
201                 ErrorCode.BusinessProcesssError.getValue(), e);
202         }
203         logger.info("{} createVnfA", MessageEnum.RA_ASYNC_CREATE_VNF_COMPLETE);
204         return;
205     }
206
207     @Override
208     public void updateVnfA (String cloudSiteId,
209                             String cloudOwner,
210                             String tenantId,
211                             String vnfType,
212                             String vnfVersion,
213                             String vnfName,
214                             String requestType,
215                             String volumeGroupHeatStackId,
216                             Map <String, Object> inputs,
217                             String messageId,
218                             MsoRequest msoRequest,
219                             String notificationUrl) {
220
221         logger.info("{} UpdateVnfA", MessageEnum.RA_ASYNC_UPDATE_VNF);
222
223         // Use the synchronous method to perform the actual Create
224         MsoVnfAdapter vnfAdapter = vnfImpl;
225
226         // Synchronous Web Service Outputs
227         Holder <String> vnfId = new Holder <> ();
228         Holder <Map <String, String>> outputs = new Holder <> ();
229         Holder <VnfRollback> vnfRollback = new Holder <> ();
230
231         try {
232             vnfAdapter.updateVnf (cloudSiteId, cloudOwner, tenantId, vnfType,vnfVersion, vnfName, requestType, volumeGroupHeatStackId, inputs, msoRequest, outputs, vnfRollback);
233         } catch (VnfException e) {
234             logger.error("{} {} Exception sending updateVnf notification ", MessageEnum.RA_UPDATE_VNF_ERR,
235                 ErrorCode.BusinessProcesssError.getValue(), e);
236             org.onap.so.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
237             String eMsg = null;
238             try {
239                 eMsg = e.getFaultInfo ().getMessage ();
240                 exCat = org.onap.so.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
241                                                                                                      .getCategory ()
242                                                                                                      .name ());
243             } catch (Exception e1) {
244                 logger.error("{} {} Exception - fault info ", MessageEnum.RA_FAULT_INFO_EXC,
245                     ErrorCode.BusinessProcesssError.getValue(), e1);
246             }
247             // Build and send Asynchronous error response
248             try {
249                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
250                 notifyPort.updateVnfNotification (messageId, false, exCat, eMsg, null, null);
251             } catch (Exception e1) {
252                 logger.error("{} {} Exception sending updateVnf notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
253                     ErrorCode.BusinessProcesssError.getValue(), e1);
254             }
255             logger.info("{} UpdateVnfA", MessageEnum.RA_ASYNC_UPDATE_VNF_COMPLETE);
256             return;
257         }
258         logger.debug("Async Update VNF: {} VnfId:{}", vnfName, vnfId.value);
259         // Build and send Asynchronous response
260         try {
261             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
262             notifyPort.updateVnfNotification (messageId,
263                                               true,
264                                               null,
265                                               null,
266                                               copyUpdateOutputs (outputs),
267                                               copyVrb (vnfRollback));
268         } catch (Exception e) {
269             logger.error("{} {} Exception sending updateVnf notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
270                 ErrorCode.BusinessProcesssError.getValue(), e);
271         }
272         logger.info("{} UpdateVnfA", MessageEnum.RA_ASYNC_UPDATE_VNF_COMPLETE);
273         return;
274     }
275
276     /**
277      * This is the "Query VNF" web service implementation.
278      * It will look up a VNF by name or ID in the specified cloud and tenant.
279      *
280      * The method returns an indicator that the VNF exists, its Openstack internal
281      * ID, its status, and the set of outputs (from when the stack was created).
282      *
283      * @param cloudSiteId CLLI code of the cloud site in which to query
284      * @param cloudOwner cloud owner of cloud site in which to query
285      * @param tenantId Openstack tenant identifier
286      * @param vnfName VNF Name or Openstack ID
287      * @param msoRequest Request tracking information for logs
288      * @param notificationURL the target URL for asynchronous response
289      */
290     @Override
291     public void queryVnfA (String cloudSiteId,
292                            String cloudOwner,
293                            String tenantId,
294                            String vnfName,
295                            String messageId,
296                            MsoRequest msoRequest,
297                            String notificationUrl) {
298
299         String serviceName = "QueryVnfA";
300         logger.info("{}", MessageEnum.RA_ASYNC_QUERY_VNF);
301
302         // Use the synchronous method to perform the actual query
303         MsoVnfAdapter vnfAdapter = vnfImpl;
304
305         // Synchronous Web Service Outputs
306         Holder <Boolean> vnfExists = new Holder <> ();
307         Holder <String> vnfId = new Holder <> ();
308         Holder <VnfStatus> status = new Holder <> ();
309         Holder <Map <String, String>> outputs = new Holder <> ();
310
311         try {
312             vnfAdapter.queryVnf (cloudSiteId, cloudOwner, tenantId, vnfName, msoRequest, vnfExists, vnfId, status, outputs);
313         } catch (VnfException e) {
314             logger.error("{} {} Exception sending queryVnfA notification ", MessageEnum.RA_QUERY_VNF_ERR,
315                 ErrorCode.BusinessProcesssError.getValue(), e);
316             org.onap.so.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
317             String eMsg = null;
318             try {
319                 eMsg = e.getFaultInfo ().getMessage ();
320                 exCat = org.onap.so.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
321                                                                                                      .getCategory ()
322                                                                                                      .name ());
323             } catch (Exception e1) {
324                 logger.error("{} {} Exception - fault info ", MessageEnum.RA_FAULT_INFO_EXC,
325                     ErrorCode.BusinessProcesssError.getValue(), e1);
326             }
327             // Build and send Asynchronous error response
328             try {
329                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
330                 notifyPort.queryVnfNotification (messageId, false, exCat, eMsg, null, null, null, null);
331             } catch (Exception e1) {
332                 logger.error("{} {} Exception sending queryVnf notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
333                     ErrorCode.BusinessProcesssError.getValue(), e1);
334             }
335             logger.info("{} queryVnfA", MessageEnum.RA_ASYNC_QUERY_VNF_COMPLETE);
336             return;
337         }
338
339         if (!vnfExists.value) {
340             logger.debug ("Async Query, VNF not found");
341         } else {
342             logger.debug("Async Query, VNF={}, status={}", vnfId.value, status.value);
343         }
344         // Build and send Asynchronous response
345         try {
346             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
347             org.onap.so.adapters.vnf.async.client.VnfStatus vnfS = org.onap.so.adapters.vnf.async.client.VnfStatus.fromValue (status.value.name ());
348             notifyPort.queryVnfNotification (messageId,
349                                              true,
350                                              null,
351                                              null,
352                                              vnfExists.value,
353                                              vnfId.value,
354                                              vnfS,
355                                              copyQueryOutputs (outputs));
356         } catch (Exception e) {
357             logger.error("{} {} Exception sending queryVnf notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
358                 ErrorCode.BusinessProcesssError.getValue(), e);
359         }
360
361         logger.info("{} queryVnfA", MessageEnum.RA_ASYNC_QUERY_VNF_COMPLETE);
362         return;
363     }
364
365     /**
366      * This is the Asynchronous "Delete VNF" web service implementation.
367      * It will delete a VNF by name or ID in the specified cloud and tenant.
368      *
369      * The method has no outputs.
370      *
371      * @param cloudSiteId CLLI code of the cloud site in which to delete
372      * @param cloudOwner cloud owner of cloud site in which to delete
373      * @param tenantId Openstack tenant identifier
374      * @param vnfName VNF Name or Openstack ID
375      * @param msoRequest Request tracking information for logs
376      * @param notificationURL the target URL for asynchronous response
377      */
378     @Override
379     public void deleteVnfA (String cloudSiteId,
380                             String cloudOwner,
381                             String tenantId,
382                             String vnfName,
383                             String messageId,
384                             MsoRequest msoRequest,
385                             String notificationUrl) {
386
387         String serviceName = "DeleteVnfA";
388         logger.info("{}", MessageEnum.RA_ASYNC_DELETE_VNF);
389
390         // Use the synchronous method to perform the actual delete
391         MsoVnfAdapter vnfAdapter = vnfImpl;
392
393         try {
394             vnfAdapter.deleteVnf (cloudSiteId, cloudOwner, tenantId, vnfName, msoRequest);
395         } catch (VnfException e) {
396             logger.error("{} {} Exception sending deleteVnfA notification ", MessageEnum.RA_DELETE_VNF_ERR,
397                 ErrorCode.BusinessProcesssError.getValue(), e);
398             org.onap.so.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
399             String eMsg = null;
400             try {
401                 eMsg = e.getFaultInfo ().getMessage ();
402                 exCat = org.onap.so.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
403                                                                                                      .getCategory ()
404                                                                                                      .name ());
405             } catch (Exception e1) {
406                 logger.error("{} {} Exception - fault info ", MessageEnum.RA_FAULT_INFO_EXC,
407                     ErrorCode.BusinessProcesssError.getValue(), e1);
408             }
409             // Build and send Asynchronous error response
410             try {
411                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
412                 notifyPort.deleteVnfNotification (messageId, false, exCat, eMsg);
413             } catch (Exception e1) {
414                 logger.error("{} {} Exception sending deleteVnfA notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
415                     ErrorCode.BusinessProcesssError.getValue(), e1);
416             }
417             logger.info("{} deleteVnfA", MessageEnum.RA_ASYNC_DELETE_VNF_COMPLETE);
418             return;
419         }
420
421         logger.debug("Async Delete VNF: {}", vnfName);
422         // Build and send Asynchronous response
423         try {
424             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
425             notifyPort.deleteVnfNotification (messageId, true, null, null);
426
427         } catch (Exception e) {
428             logger.error("{} {} Exception sending deleteVnfA notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
429                 ErrorCode.BusinessProcesssError.getValue(), e);
430         }
431
432         logger.info("{} deleteVnfA", MessageEnum.RA_ASYNC_DELETE_VNF_COMPLETE);
433         return;
434     }
435
436     /**
437      * This web service endpoint will rollback a previous Create VNF operation.
438      * A rollback object is returned to the client in a successful creation
439      * response. The client can pass that object as-is back to the rollbackVnf
440      * operation to undo the creation.
441      */
442     @Override
443     public void rollbackVnfA (VnfRollback rollback, String messageId, String notificationUrl) {
444         // rollback may be null (e.g. if stack already existed when Create was called)
445         if (rollback == null) {
446             logger.info("{} rollbackVnfA: Empty Rollback: No action to perform", MessageEnum.RA_ROLLBACK_NULL);
447             return;
448         }
449
450         logger.info("{} rollbackVnfA", MessageEnum.RA_ASYNC_ROLLBACK_VNF);
451
452         // Use the synchronous method to perform the actual rollback
453         MsoVnfAdapter vnfAdapter = vnfImpl;
454
455         try {
456             vnfAdapter.rollbackVnf (rollback);
457         } catch (VnfException e) {
458             logger.error("{} {} Exception sending rollbackVnfA notification ", MessageEnum.RA_ROLLBACK_VNF_ERR,
459                 ErrorCode.BusinessProcesssError.getValue(), e);
460             org.onap.so.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
461             String eMsg = null;
462             try {
463                 eMsg = e.getFaultInfo ().getMessage ();
464                 exCat = org.onap.so.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
465                                                                                                      .getCategory ()
466                                                                                                      .name ());
467             } catch (Exception e1) {
468                 logger.error("{} {} Exception - fault info ", MessageEnum.RA_FAULT_INFO_EXC,
469                     ErrorCode.BusinessProcesssError.getValue(), e1);
470             }
471             // Build and send Asynchronous error response
472             try {
473                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
474                 notifyPort.rollbackVnfNotification (messageId, false, exCat, eMsg);
475             } catch (Exception e1) {
476                 logger.error("{} {} Exception sending rollbackVnfA notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
477                     ErrorCode.BusinessProcesssError.getValue(), e1);
478             }
479             logger.info("{} rollbackVnfA", MessageEnum.RA_ASYNC_ROLLBACK_VNF_COMPLETE);
480             return;
481         }
482
483         logger.debug ("Async Rollback VNF:" + rollback.getVnfId ());
484         // Build and send Asynchronous response
485         try {
486             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
487             notifyPort.rollbackVnfNotification (messageId, true, null, null);
488         } catch (Exception e) {
489             logger.error("{} {} Exception sending rollbackVnfA notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
490                 ErrorCode.BusinessProcesssError.getValue(), e);
491         }
492
493         logger.info("{} rollbackVnfA", MessageEnum.RA_ASYNC_ROLLBACK_VNF_COMPLETE);
494         return;
495     }
496
497     private org.onap.so.adapters.vnf.async.client.VnfRollback copyVrb (Holder <VnfRollback> hVrb) {
498         org.onap.so.adapters.vnf.async.client.VnfRollback cvrb = new org.onap.so.adapters.vnf.async.client.VnfRollback ();
499
500         if (hVrb != null && hVrb.value != null) {
501             org.onap.so.adapters.vnf.async.client.MsoRequest cmr = new org.onap.so.adapters.vnf.async.client.MsoRequest ();
502
503             cvrb.setCloudSiteId (hVrb.value.getCloudSiteId ());
504             if (hVrb.value.getMsoRequest() != null) {
505                 cmr.setRequestId (hVrb.value.getMsoRequest ().getRequestId ());
506                 cmr.setServiceInstanceId (hVrb.value.getMsoRequest ().getServiceInstanceId ());
507             } else {
508                 cmr.setRequestId (null);
509                 cmr.setServiceInstanceId (null);
510             }
511             cvrb.setMsoRequest (cmr);
512             cvrb.setVnfId (hVrb.value.getVnfId ());
513             cvrb.setTenantId (hVrb.value.getTenantId ());
514             cvrb.setTenantCreated (hVrb.value.getTenantCreated ());
515             cvrb.setVnfCreated (hVrb.value.getVnfCreated ());
516         }
517         return cvrb;
518     }
519
520     private CreateVnfNotification.Outputs copyCreateOutputs (Holder <Map <String, String>> hMap) {
521
522         CreateVnfNotification.Outputs outputs = new CreateVnfNotification.Outputs ();
523
524         if (hMap != null && hMap.value != null) {
525             Map <String, String> sMap = new HashMap <> ();
526             sMap = hMap.value;
527             CreateVnfNotification.Outputs.Entry entry = new CreateVnfNotification.Outputs.Entry ();
528
529             for (String key : sMap.keySet ()) {
530                 entry.setKey (key);
531                 entry.setValue (sMap.get (key));
532                 outputs.getEntry ().add (entry);
533             }
534         }
535         return outputs;
536     }
537
538     private UpdateVnfNotification.Outputs copyUpdateOutputs (Holder <Map <String, String>> hMap) {
539
540         UpdateVnfNotification.Outputs outputs = new UpdateVnfNotification.Outputs ();
541
542         if (hMap != null && hMap.value != null) {
543             Map <String, String> sMap = new HashMap <> ();
544             sMap = hMap.value;
545             UpdateVnfNotification.Outputs.Entry entry = new UpdateVnfNotification.Outputs.Entry ();
546
547             for (Map.Entry<String,String> mapEntry : sMap.entrySet ()) {
548                 String key = mapEntry.getKey();
549                 String value = mapEntry.getValue();
550                 entry.setKey (key);
551                 entry.setValue (value);
552                 outputs.getEntry ().add (entry);
553             }
554         }
555         return outputs;
556     }
557
558     private QueryVnfNotification.Outputs copyQueryOutputs (Holder <Map <String, String>> hMap) {
559
560         QueryVnfNotification.Outputs outputs = new QueryVnfNotification.Outputs ();
561
562         if (hMap != null && hMap.value != null) {
563             Map <String, String> sMap = new HashMap <> ();
564             sMap = hMap.value;
565
566             QueryVnfNotification.Outputs.Entry entry = new QueryVnfNotification.Outputs.Entry ();
567
568             for (Map.Entry<String,String> mapEntry : sMap.entrySet ()) {
569                 String key = mapEntry.getKey();
570                 String value = mapEntry.getValue();
571                 entry.setKey (key);
572                 entry.setValue (value);
573                 outputs.getEntry ().add (entry);
574             }
575         }
576         return outputs;
577     }
578
579     private VnfAdapterNotify getNotifyEP (String notificationUrl) {
580
581         URL warWsdlLoc = null;
582         try {
583             warWsdlLoc = Thread.currentThread ().getContextClassLoader ().getResource ("VnfAdapterNotify.wsdl");
584         } catch (Exception e) {
585             logger.error("{} {} Exception - WSDL not found ", MessageEnum.RA_WSDL_NOT_FOUND,
586                 ErrorCode.BusinessProcesssError.getValue(), e);
587         }
588         if (warWsdlLoc == null) {
589             logger.error("{} {} WSDL not found", MessageEnum.RA_WSDL_NOT_FOUND,
590                 ErrorCode.BusinessProcesssError.getValue());
591         } else {
592             try {
593                 logger.debug("VnfAdpaterNotify.wsdl location:{}", warWsdlLoc.toURI().toString());
594             } catch (Exception e) {
595                 logger.error("{} {} Exception - WSDL URL convention ", MessageEnum.RA_WSDL_URL_CONVENTION_EXC,
596                     ErrorCode.BusinessProcesssError.getValue(), e);
597             }
598         }
599
600         VnfAdapterNotify_Service notifySvc = new VnfAdapterNotify_Service (warWsdlLoc,
601                                                                            new QName ("http://org.onap.so/vnfNotify",
602                                                                                       "vnfAdapterNotify"));
603
604         VnfAdapterNotify notifyPort = notifySvc.getMsoVnfAdapterAsyncImplPort ();
605
606         BindingProvider bp = (BindingProvider) notifyPort;
607
608         URL epUrl = null;
609         try {
610             epUrl = new URL (notificationUrl);
611         } catch (MalformedURLException e1) {
612             logger.error("{} {} MalformedURLException ", MessageEnum.RA_INIT_NOTIF_EXC,
613                 ErrorCode.BusinessProcesssError.getValue(), e1);
614         }
615
616         if(null != epUrl) {
617             logger.debug("Notification Endpoint URL: {}", epUrl.toExternalForm());
618             bp.getRequestContext ().put (BindingProvider.ENDPOINT_ADDRESS_PROPERTY, epUrl.toExternalForm ());
619         }
620         else {
621             logger.debug ("epUrl is NULL:");
622         }
623
624         // authentication
625         try {
626             Map <String, Object> reqCtx = bp.getRequestContext ();
627             Map <String, List <String>> headers = new HashMap <> ();
628
629             String userCredentials = this.getEncryptedProperty(BPEL_AUTH_PROP, "", ENCRYPTION_KEY_PROP);
630
631             String basicAuth = "Basic " + DatatypeConverter.printBase64Binary (userCredentials.getBytes ());
632             reqCtx.put (MessageContext.HTTP_REQUEST_HEADERS, headers);
633             headers.put ("Authorization", Collections.singletonList (basicAuth));
634         } catch (Exception e) {
635             logger.error("{} {} Exception - Unable to set authorization in callback request ",
636                 MessageEnum.RA_SET_CALLBACK_AUTH_EXC, ErrorCode.BusinessProcesssError.getValue(), e);
637         }
638
639         return notifyPort;
640     }
641
642     public String getEncryptedProperty(String key, String defaultValue, String encryptionKey) {
643         try {
644                         return CryptoUtils.decrypt(this.environment.getProperty(key), this.environment.getProperty(encryptionKey));
645                 } catch (GeneralSecurityException e) {
646           logger.debug("Exception while decrypting property: {} ", this.environment.getProperty(key), e);
647                 }
648                 return defaultValue;
649
650         }
651
652 }