Replaced all tabs with spaces in java and pom.xml
[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",
59         targetNamespace = "http://org.onap.so/vnfA")
60 @Component
61 public class MsoVnfAdapterAsyncImpl implements MsoVnfAdapterAsync {
62
63     private static final Logger logger = LoggerFactory.getLogger(MsoVnfAdapterAsyncImpl.class);
64
65     private static final String BPEL_AUTH_PROP = "org.onap.so.adapters.vnf.bpelauth";
66     private static final String ENCRYPTION_KEY_PROP = "org.onap.so.adapters.network.encryptionKey";
67
68     @Autowired
69     private Environment environment;
70
71     @Autowired
72     private MsoVnfAdapterImpl vnfImpl;
73
74     /**
75      * Health Check web method. Does nothing but return to show the adapter is deployed.
76      */
77     @Override
78     public void healthCheckA() {
79         logger.debug("Health check call in VNF Adapter");
80     }
81
82     /**
83      * This is the asynchronous "Create VNF" web service implementation. It will create a new VNF of the requested type
84      * in the specified cloud 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 success or failure, depending on the value
87      * of the 'failIfExists' parameter.
88      *
89      * All VNF types will be defined in the MSO catalog. The caller must request one of these pre-defined types or an
90      * error will be returned. Within the catalog, each VNF type references (among other things) a Heat template which
91      * is used to deploy the required VNF artifacts (VMs, networks, etc.) to the cloud.
92      *
93      * Depending on the Heat template, a variable set of input parameters will be defined, some of which are required.
94      * The caller is responsible to pass the necessary input data for the VNF or an error will be thrown.
95      *
96      * The method sends an asynchronous response to the notification URL when processing completes. The
97      * createAsyncResponse contains the vnfId (the canonical name of the stack), a Map of VNF output attributes, and a
98      * VnfRollback object. This last object can be passed as-is to the rollbackVnf operation to undo everything that was
99      * created for the VNF. This is useful if a VNF is successfully created but the orchestrator fails on a subsequent
100      * operation.
101      *
102      * Note: this method is implemented by calling the synchronous web method and translating the response to an
103      * asynchronous notification.
104      *
105      * @param cloudSiteId CLLI code of the cloud site in which to create the VNF
106      * @param cloudOwner cloud owner of the cloud site in which to create the VNF
107      * @param tenantId Openstack tenant identifier
108      * @param vnfType VNF type key, should match a VNF definition in catalog DB
109      * @param vnfName Name to be assigned to the new VNF
110      * @param inputs Map of key=value inputs for VNF stack creation
111      * @param failIfExists Flag whether already existing VNF should be considered a success or failure
112      * @param msoRequest Request tracking information for logs
113      * @param notificationURL the target URL for asynchronous response
114      */
115     @Override
116     public void createVnfA(String cloudSiteId, String cloudOwner, String tenantId, String vnfType, String vnfVersion,
117             String vnfName, String requestType, String volumeGroupHeatStackId, Map<String, Object> inputs,
118             Boolean failIfExists, Boolean backout, Boolean enableBridge, String messageId, MsoRequest msoRequest,
119             String notificationUrl) {
120
121         logger.info("{} createVnfA", MessageEnum.RA_ASYNC_CREATE_VNF);
122         // Use the synchronous method to perform the actual Create
123         MsoVnfAdapter vnfAdapter = vnfImpl;
124         // Synchronous Web Service Outputs
125         Holder<String> vnfId = new Holder<>();
126         Holder<Map<String, String>> outputs = new Holder<>();
127         Holder<VnfRollback> vnfRollback = new Holder<>();
128
129         try {
130             vnfAdapter.createVnf(cloudSiteId, cloudOwner, tenantId, vnfType, vnfVersion, vnfName, requestType,
131                     volumeGroupHeatStackId, inputs, failIfExists, backout, enableBridge, msoRequest, vnfId, outputs,
132                     vnfRollback);
133         } catch (VnfException e) {
134             logger.error("{} {} VnfException in createVnfA ", MessageEnum.RA_CREATE_VNF_ERR,
135                     ErrorCode.BusinessProcesssError.getValue(), e);
136             org.onap.so.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
137             String eMsg = null;
138             try {
139                 eMsg = e.getFaultInfo().getMessage();
140                 exCat = org.onap.so.adapters.vnf.async.client.MsoExceptionCategory
141                         .fromValue(e.getFaultInfo().getCategory().name());
142             } catch (Exception e1) {
143                 logger.error("{} {} Exception - Fault info ", MessageEnum.RA_FAULT_INFO_EXC,
144                         ErrorCode.BusinessProcesssError.getValue(), e1);
145             }
146             // Build and send Asynchronous error response
147             try {
148                 VnfAdapterNotify notifyPort = getNotifyEP(notificationUrl);
149                 notifyPort.createVnfNotification(messageId, false, exCat, eMsg, null, null, null);
150             } catch (Exception e1) {
151                 logger.error("{} {} Exception sending createVnf notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
152                         ErrorCode.BusinessProcesssError.getValue(), e1);
153             }
154             logger.info("{}", MessageEnum.RA_ASYNC_CREATE_VNF_COMPLETE);
155             return;
156         }
157         logger.debug("Async Create VNF: {} VnfId:{}", vnfName, vnfId.value);
158         // Build and send Asynchronous response
159         try {
160             VnfAdapterNotify notifyPort = getNotifyEP(notificationUrl);
161             notifyPort.createVnfNotification(messageId, true, null, null, vnfId.value, copyCreateOutputs(outputs),
162                     copyVrb(vnfRollback));
163         } catch (Exception e) {
164             logger.error("{} {} Exception sending createVnf notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
165                     ErrorCode.BusinessProcesssError.getValue(), e);
166         }
167         logger.info("{} createVnfA", MessageEnum.RA_ASYNC_CREATE_VNF_COMPLETE);
168         return;
169     }
170
171     @Override
172     public void updateVnfA(String cloudSiteId, String cloudOwner, String tenantId, String vnfType, String vnfVersion,
173             String vnfName, String requestType, String volumeGroupHeatStackId, Map<String, Object> inputs,
174             String messageId, MsoRequest msoRequest, String notificationUrl) {
175
176         logger.info("{} UpdateVnfA", MessageEnum.RA_ASYNC_UPDATE_VNF);
177
178         // Use the synchronous method to perform the actual Create
179         MsoVnfAdapter vnfAdapter = vnfImpl;
180
181         // Synchronous Web Service Outputs
182         Holder<String> vnfId = new Holder<>();
183         Holder<Map<String, String>> outputs = new Holder<>();
184         Holder<VnfRollback> vnfRollback = new Holder<>();
185
186         try {
187             vnfAdapter.updateVnf(cloudSiteId, cloudOwner, tenantId, vnfType, vnfVersion, vnfName, requestType,
188                     volumeGroupHeatStackId, inputs, msoRequest, outputs, vnfRollback);
189         } catch (VnfException e) {
190             logger.error("{} {} Exception sending updateVnf notification ", MessageEnum.RA_UPDATE_VNF_ERR,
191                     ErrorCode.BusinessProcesssError.getValue(), e);
192             org.onap.so.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
193             String eMsg = null;
194             try {
195                 eMsg = e.getFaultInfo().getMessage();
196                 exCat = org.onap.so.adapters.vnf.async.client.MsoExceptionCategory
197                         .fromValue(e.getFaultInfo().getCategory().name());
198             } catch (Exception e1) {
199                 logger.error("{} {} Exception - fault info ", MessageEnum.RA_FAULT_INFO_EXC,
200                         ErrorCode.BusinessProcesssError.getValue(), e1);
201             }
202             // Build and send Asynchronous error response
203             try {
204                 VnfAdapterNotify notifyPort = getNotifyEP(notificationUrl);
205                 notifyPort.updateVnfNotification(messageId, false, exCat, eMsg, null, null);
206             } catch (Exception e1) {
207                 logger.error("{} {} Exception sending updateVnf notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
208                         ErrorCode.BusinessProcesssError.getValue(), e1);
209             }
210             logger.info("{} UpdateVnfA", MessageEnum.RA_ASYNC_UPDATE_VNF_COMPLETE);
211             return;
212         }
213         logger.debug("Async Update VNF: {} VnfId:{}", vnfName, vnfId.value);
214         // Build and send Asynchronous response
215         try {
216             VnfAdapterNotify notifyPort = getNotifyEP(notificationUrl);
217             notifyPort.updateVnfNotification(messageId, true, null, null, copyUpdateOutputs(outputs),
218                     copyVrb(vnfRollback));
219         } catch (Exception e) {
220             logger.error("{} {} Exception sending updateVnf notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
221                     ErrorCode.BusinessProcesssError.getValue(), e);
222         }
223         logger.info("{} UpdateVnfA", MessageEnum.RA_ASYNC_UPDATE_VNF_COMPLETE);
224         return;
225     }
226
227     /**
228      * This is the "Query VNF" web service implementation. It will look up a VNF by name or ID in the specified cloud
229      * and tenant.
230      *
231      * The method returns an indicator that the VNF exists, its Openstack internal ID, its status, and the set of
232      * outputs (from when the stack was created).
233      *
234      * @param cloudSiteId CLLI code of the cloud site in which to query
235      * @param cloudOwner cloud owner of cloud site in which to query
236      * @param tenantId Openstack tenant identifier
237      * @param vnfName VNF Name or Openstack ID
238      * @param msoRequest Request tracking information for logs
239      * @param notificationURL the target URL for asynchronous response
240      */
241     @Override
242     public void queryVnfA(String cloudSiteId, String cloudOwner, String tenantId, String vnfName, String messageId,
243             MsoRequest msoRequest, String notificationUrl) {
244
245         String serviceName = "QueryVnfA";
246         logger.info("{}", MessageEnum.RA_ASYNC_QUERY_VNF);
247
248         // Use the synchronous method to perform the actual query
249         MsoVnfAdapter vnfAdapter = vnfImpl;
250
251         // Synchronous Web Service Outputs
252         Holder<Boolean> vnfExists = new Holder<>();
253         Holder<String> vnfId = new Holder<>();
254         Holder<VnfStatus> status = new Holder<>();
255         Holder<Map<String, String>> outputs = new Holder<>();
256
257         try {
258             vnfAdapter.queryVnf(cloudSiteId, cloudOwner, tenantId, vnfName, msoRequest, vnfExists, vnfId, status,
259                     outputs);
260         } catch (VnfException e) {
261             logger.error("{} {} Exception sending queryVnfA notification ", MessageEnum.RA_QUERY_VNF_ERR,
262                     ErrorCode.BusinessProcesssError.getValue(), e);
263             org.onap.so.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
264             String eMsg = null;
265             try {
266                 eMsg = e.getFaultInfo().getMessage();
267                 exCat = org.onap.so.adapters.vnf.async.client.MsoExceptionCategory
268                         .fromValue(e.getFaultInfo().getCategory().name());
269             } catch (Exception e1) {
270                 logger.error("{} {} Exception - fault info ", MessageEnum.RA_FAULT_INFO_EXC,
271                         ErrorCode.BusinessProcesssError.getValue(), e1);
272             }
273             // Build and send Asynchronous error response
274             try {
275                 VnfAdapterNotify notifyPort = getNotifyEP(notificationUrl);
276                 notifyPort.queryVnfNotification(messageId, false, exCat, eMsg, null, null, null, null);
277             } catch (Exception e1) {
278                 logger.error("{} {} Exception sending queryVnf notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
279                         ErrorCode.BusinessProcesssError.getValue(), e1);
280             }
281             logger.info("{} queryVnfA", MessageEnum.RA_ASYNC_QUERY_VNF_COMPLETE);
282             return;
283         }
284
285         if (!vnfExists.value) {
286             logger.debug("Async Query, VNF not found");
287         } else {
288             logger.debug("Async Query, VNF={}, status={}", vnfId.value, status.value);
289         }
290         // Build and send Asynchronous response
291         try {
292             VnfAdapterNotify notifyPort = getNotifyEP(notificationUrl);
293             org.onap.so.adapters.vnf.async.client.VnfStatus vnfS =
294                     org.onap.so.adapters.vnf.async.client.VnfStatus.fromValue(status.value.name());
295             notifyPort.queryVnfNotification(messageId, true, null, null, vnfExists.value, vnfId.value, vnfS,
296                     copyQueryOutputs(outputs));
297         } catch (Exception e) {
298             logger.error("{} {} Exception sending queryVnf notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
299                     ErrorCode.BusinessProcesssError.getValue(), e);
300         }
301
302         logger.info("{} queryVnfA", MessageEnum.RA_ASYNC_QUERY_VNF_COMPLETE);
303         return;
304     }
305
306     /**
307      * This is the Asynchronous "Delete VNF" web service implementation. It will delete a VNF by name or ID in the
308      * specified cloud and tenant.
309      *
310      * The method has no outputs.
311      *
312      * @param cloudSiteId CLLI code of the cloud site in which to delete
313      * @param cloudOwner cloud owner of cloud site in which to delete
314      * @param tenantId Openstack tenant identifier
315      * @param vnfName VNF Name or Openstack ID
316      * @param msoRequest Request tracking information for logs
317      * @param notificationURL the target URL for asynchronous response
318      */
319     @Override
320     public void deleteVnfA(String cloudSiteId, String cloudOwner, String tenantId, String vnfName, String messageId,
321             MsoRequest msoRequest, String notificationUrl) {
322
323         String serviceName = "DeleteVnfA";
324         logger.info("{}", MessageEnum.RA_ASYNC_DELETE_VNF);
325
326         // Use the synchronous method to perform the actual delete
327         MsoVnfAdapter vnfAdapter = vnfImpl;
328
329         try {
330             vnfAdapter.deleteVnf(cloudSiteId, cloudOwner, tenantId, vnfName, msoRequest);
331         } catch (VnfException e) {
332             logger.error("{} {} Exception sending deleteVnfA notification ", MessageEnum.RA_DELETE_VNF_ERR,
333                     ErrorCode.BusinessProcesssError.getValue(), e);
334             org.onap.so.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
335             String eMsg = null;
336             try {
337                 eMsg = e.getFaultInfo().getMessage();
338                 exCat = org.onap.so.adapters.vnf.async.client.MsoExceptionCategory
339                         .fromValue(e.getFaultInfo().getCategory().name());
340             } catch (Exception e1) {
341                 logger.error("{} {} Exception - fault info ", MessageEnum.RA_FAULT_INFO_EXC,
342                         ErrorCode.BusinessProcesssError.getValue(), e1);
343             }
344             // Build and send Asynchronous error response
345             try {
346                 VnfAdapterNotify notifyPort = getNotifyEP(notificationUrl);
347                 notifyPort.deleteVnfNotification(messageId, false, exCat, eMsg);
348             } catch (Exception e1) {
349                 logger.error("{} {} Exception sending deleteVnfA notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
350                         ErrorCode.BusinessProcesssError.getValue(), e1);
351             }
352             logger.info("{} deleteVnfA", MessageEnum.RA_ASYNC_DELETE_VNF_COMPLETE);
353             return;
354         }
355
356         logger.debug("Async Delete VNF: {}", vnfName);
357         // Build and send Asynchronous response
358         try {
359             VnfAdapterNotify notifyPort = getNotifyEP(notificationUrl);
360             notifyPort.deleteVnfNotification(messageId, true, null, null);
361
362         } catch (Exception e) {
363             logger.error("{} {} Exception sending deleteVnfA notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
364                     ErrorCode.BusinessProcesssError.getValue(), e);
365         }
366
367         logger.info("{} deleteVnfA", MessageEnum.RA_ASYNC_DELETE_VNF_COMPLETE);
368         return;
369     }
370
371     /**
372      * This web service endpoint will rollback a previous Create VNF operation. A rollback object is returned to the
373      * client in a successful creation response. The client can pass that object as-is back to the rollbackVnf operation
374      * to undo the creation.
375      */
376     @Override
377     public void rollbackVnfA(VnfRollback rollback, String messageId, String notificationUrl) {
378         // rollback may be null (e.g. if stack already existed when Create was called)
379         if (rollback == null) {
380             logger.info("{} rollbackVnfA: Empty Rollback: No action to perform", MessageEnum.RA_ROLLBACK_NULL);
381             return;
382         }
383
384         logger.info("{} rollbackVnfA", MessageEnum.RA_ASYNC_ROLLBACK_VNF);
385
386         // Use the synchronous method to perform the actual rollback
387         MsoVnfAdapter vnfAdapter = vnfImpl;
388
389         try {
390             vnfAdapter.rollbackVnf(rollback);
391         } catch (VnfException e) {
392             logger.error("{} {} Exception sending rollbackVnfA notification ", MessageEnum.RA_ROLLBACK_VNF_ERR,
393                     ErrorCode.BusinessProcesssError.getValue(), e);
394             org.onap.so.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
395             String eMsg = null;
396             try {
397                 eMsg = e.getFaultInfo().getMessage();
398                 exCat = org.onap.so.adapters.vnf.async.client.MsoExceptionCategory
399                         .fromValue(e.getFaultInfo().getCategory().name());
400             } catch (Exception e1) {
401                 logger.error("{} {} Exception - fault info ", MessageEnum.RA_FAULT_INFO_EXC,
402                         ErrorCode.BusinessProcesssError.getValue(), e1);
403             }
404             // Build and send Asynchronous error response
405             try {
406                 VnfAdapterNotify notifyPort = getNotifyEP(notificationUrl);
407                 notifyPort.rollbackVnfNotification(messageId, false, exCat, eMsg);
408             } catch (Exception e1) {
409                 logger.error("{} {} Exception sending rollbackVnfA notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
410                         ErrorCode.BusinessProcesssError.getValue(), e1);
411             }
412             logger.info("{} rollbackVnfA", MessageEnum.RA_ASYNC_ROLLBACK_VNF_COMPLETE);
413             return;
414         }
415
416         logger.debug("Async Rollback VNF:" + rollback.getVnfId());
417         // Build and send Asynchronous response
418         try {
419             VnfAdapterNotify notifyPort = getNotifyEP(notificationUrl);
420             notifyPort.rollbackVnfNotification(messageId, true, null, null);
421         } catch (Exception e) {
422             logger.error("{} {} Exception sending rollbackVnfA notification ", MessageEnum.RA_SEND_VNF_NOTIF_ERR,
423                     ErrorCode.BusinessProcesssError.getValue(), e);
424         }
425
426         logger.info("{} rollbackVnfA", MessageEnum.RA_ASYNC_ROLLBACK_VNF_COMPLETE);
427         return;
428     }
429
430     private org.onap.so.adapters.vnf.async.client.VnfRollback copyVrb(Holder<VnfRollback> hVrb) {
431         org.onap.so.adapters.vnf.async.client.VnfRollback cvrb =
432                 new org.onap.so.adapters.vnf.async.client.VnfRollback();
433
434         if (hVrb != null && hVrb.value != null) {
435             org.onap.so.adapters.vnf.async.client.MsoRequest cmr =
436                     new org.onap.so.adapters.vnf.async.client.MsoRequest();
437
438             cvrb.setCloudSiteId(hVrb.value.getCloudSiteId());
439             if (hVrb.value.getMsoRequest() != null) {
440                 cmr.setRequestId(hVrb.value.getMsoRequest().getRequestId());
441                 cmr.setServiceInstanceId(hVrb.value.getMsoRequest().getServiceInstanceId());
442             } else {
443                 cmr.setRequestId(null);
444                 cmr.setServiceInstanceId(null);
445             }
446             cvrb.setMsoRequest(cmr);
447             cvrb.setVnfId(hVrb.value.getVnfId());
448             cvrb.setTenantId(hVrb.value.getTenantId());
449             cvrb.setTenantCreated(hVrb.value.getTenantCreated());
450             cvrb.setVnfCreated(hVrb.value.getVnfCreated());
451         }
452         return cvrb;
453     }
454
455     private CreateVnfNotification.Outputs copyCreateOutputs(Holder<Map<String, String>> hMap) {
456
457         CreateVnfNotification.Outputs outputs = new CreateVnfNotification.Outputs();
458
459         if (hMap != null && hMap.value != null) {
460             Map<String, String> sMap = new HashMap<>();
461             sMap = hMap.value;
462             CreateVnfNotification.Outputs.Entry entry = new CreateVnfNotification.Outputs.Entry();
463
464             for (String key : sMap.keySet()) {
465                 entry.setKey(key);
466                 entry.setValue(sMap.get(key));
467                 outputs.getEntry().add(entry);
468             }
469         }
470         return outputs;
471     }
472
473     private UpdateVnfNotification.Outputs copyUpdateOutputs(Holder<Map<String, String>> hMap) {
474
475         UpdateVnfNotification.Outputs outputs = new UpdateVnfNotification.Outputs();
476
477         if (hMap != null && hMap.value != null) {
478             Map<String, String> sMap = new HashMap<>();
479             sMap = hMap.value;
480             UpdateVnfNotification.Outputs.Entry entry = new UpdateVnfNotification.Outputs.Entry();
481
482             for (Map.Entry<String, String> mapEntry : sMap.entrySet()) {
483                 String key = mapEntry.getKey();
484                 String value = mapEntry.getValue();
485                 entry.setKey(key);
486                 entry.setValue(value);
487                 outputs.getEntry().add(entry);
488             }
489         }
490         return outputs;
491     }
492
493     private QueryVnfNotification.Outputs copyQueryOutputs(Holder<Map<String, String>> hMap) {
494
495         QueryVnfNotification.Outputs outputs = new QueryVnfNotification.Outputs();
496
497         if (hMap != null && hMap.value != null) {
498             Map<String, String> sMap = new HashMap<>();
499             sMap = hMap.value;
500
501             QueryVnfNotification.Outputs.Entry entry = new QueryVnfNotification.Outputs.Entry();
502
503             for (Map.Entry<String, String> mapEntry : sMap.entrySet()) {
504                 String key = mapEntry.getKey();
505                 String value = mapEntry.getValue();
506                 entry.setKey(key);
507                 entry.setValue(value);
508                 outputs.getEntry().add(entry);
509             }
510         }
511         return outputs;
512     }
513
514     private VnfAdapterNotify getNotifyEP(String notificationUrl) {
515
516         URL warWsdlLoc = null;
517         try {
518             warWsdlLoc = Thread.currentThread().getContextClassLoader().getResource("VnfAdapterNotify.wsdl");
519         } catch (Exception e) {
520             logger.error("{} {} Exception - WSDL not found ", MessageEnum.RA_WSDL_NOT_FOUND,
521                     ErrorCode.BusinessProcesssError.getValue(), e);
522         }
523         if (warWsdlLoc == null) {
524             logger.error("{} {} WSDL not found", MessageEnum.RA_WSDL_NOT_FOUND,
525                     ErrorCode.BusinessProcesssError.getValue());
526         } else {
527             try {
528                 logger.debug("VnfAdpaterNotify.wsdl location:{}", warWsdlLoc.toURI().toString());
529             } catch (Exception e) {
530                 logger.error("{} {} Exception - WSDL URL convention ", MessageEnum.RA_WSDL_URL_CONVENTION_EXC,
531                         ErrorCode.BusinessProcesssError.getValue(), e);
532             }
533         }
534
535         VnfAdapterNotify_Service notifySvc =
536                 new VnfAdapterNotify_Service(warWsdlLoc, new QName("http://org.onap.so/vnfNotify", "vnfAdapterNotify"));
537
538         VnfAdapterNotify notifyPort = notifySvc.getMsoVnfAdapterAsyncImplPort();
539
540         BindingProvider bp = (BindingProvider) notifyPort;
541
542         URL epUrl = null;
543         try {
544             epUrl = new URL(notificationUrl);
545         } catch (MalformedURLException e1) {
546             logger.error("{} {} MalformedURLException ", MessageEnum.RA_INIT_NOTIF_EXC,
547                     ErrorCode.BusinessProcesssError.getValue(), e1);
548         }
549
550         if (null != epUrl) {
551             logger.debug("Notification Endpoint URL: {}", epUrl.toExternalForm());
552             bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, epUrl.toExternalForm());
553         } else {
554             logger.debug("epUrl is NULL:");
555         }
556
557         // authentication
558         try {
559             Map<String, Object> reqCtx = bp.getRequestContext();
560             Map<String, List<String>> headers = new HashMap<>();
561
562             String userCredentials = this.getEncryptedProperty(BPEL_AUTH_PROP, "", ENCRYPTION_KEY_PROP);
563
564             String basicAuth = "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes());
565             reqCtx.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
566             headers.put("Authorization", Collections.singletonList(basicAuth));
567         } catch (Exception e) {
568             logger.error("{} {} Exception - Unable to set authorization in callback request ",
569                     MessageEnum.RA_SET_CALLBACK_AUTH_EXC, ErrorCode.BusinessProcesssError.getValue(), e);
570         }
571
572         return notifyPort;
573     }
574
575     public String getEncryptedProperty(String key, String defaultValue, String encryptionKey) {
576         try {
577             return CryptoUtils.decrypt(this.environment.getProperty(key), this.environment.getProperty(encryptionKey));
578         } catch (GeneralSecurityException e) {
579             logger.debug("Exception while decrypting property: {} ", this.environment.getProperty(key), e);
580         }
581         return defaultValue;
582
583     }
584
585 }