Removed MsoLogger class
[so.git] / adapters / mso-openstack-adapters / src / main / java / org / onap / so / adapters / network / MsoNetworkAdapterAsyncImpl.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) 2018 IBM.
9  * Modifications Copyright (c) 2019 Samsung
10  * ================================================================================
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  * 
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  * 
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.so.adapters.network;
26
27
28 import java.net.MalformedURLException;
29 import java.net.URL;
30 import java.security.GeneralSecurityException;
31 import java.util.Collections;
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35 import javax.jws.WebService;
36 import javax.xml.bind.DatatypeConverter;
37 import javax.xml.namespace.QName;
38 import javax.xml.ws.BindingProvider;
39 import javax.xml.ws.Holder;
40 import javax.xml.ws.handler.MessageContext;
41 import org.onap.so.adapters.network.async.client.CreateNetworkNotification;
42 import org.onap.so.adapters.network.async.client.MsoExceptionCategory;
43 import org.onap.so.adapters.network.async.client.NetworkAdapterNotify;
44 import org.onap.so.adapters.network.async.client.NetworkAdapterNotify_Service;
45 import org.onap.so.adapters.network.async.client.QueryNetworkNotification;
46 import org.onap.so.adapters.network.async.client.UpdateNetworkNotification;
47 import org.onap.so.adapters.network.exceptions.NetworkException;
48 import org.onap.so.entity.MsoRequest;
49 import org.onap.so.logger.ErrorCode;
50 import org.onap.so.logger.MessageEnum;
51 import org.onap.so.openstack.beans.NetworkRollback;
52 import org.onap.so.openstack.beans.NetworkStatus;
53 import org.onap.so.openstack.beans.Subnet;
54 import org.onap.so.utils.CryptoUtils;
55 import org.slf4j.Logger;
56 import org.slf4j.LoggerFactory;
57 import org.springframework.beans.factory.annotation.Autowired;
58 import org.springframework.core.env.Environment;
59 import org.springframework.stereotype.Component;
60
61 @Component
62 @WebService(serviceName = "NetworkAdapterAsync", endpointInterface = "org.onap.so.adapters.network.MsoNetworkAdapterAsync", targetNamespace = "http://org.onap.so/networkA")
63 public class MsoNetworkAdapterAsyncImpl implements MsoNetworkAdapterAsync {
64
65     private static final Logger logger = LoggerFactory.getLogger(MsoNetworkAdapterAsyncImpl.class);
66
67     private static final String BPEL_AUTH_PROP = "org.onap.so.adapters.network.bpelauth";
68     private static final String ENCRYPTION_KEY_PROP = "org.onap.so.adapters.network.encryptionKey";
69     private static final String NETWORK_EXCEPTION_MSG="Got a NetworkException on createNetwork: ";
70     private static final String CREATE_NETWORK_ERROR_LOGMSG ="{} {} Error sending createNetwork notification {} ";
71     private static final String FAULT_INFO_ERROR_LOGMSG = "{} {} Exception - fault info ";
72
73     @Autowired
74     private Environment environment;
75
76     @Autowired
77     private MsoNetworkAdapter networkAdapter;
78     /**
79      * Health Check web method. Does nothing but return to show the adapter is deployed.
80      */
81     @Override
82     public void healthCheckA () {
83         logger.debug ("Health check call in Network Adapter");
84     }
85
86     /**
87      * This is the "Create Network" web service implementation.
88      * It will create a new Network of the requested type in the specified cloud
89      * and tenant. The tenant must exist at the time this service is called.
90      *
91      * If a network with the same name already exists, this can be considered a
92      * success or failure, depending on the value of the 'failIfExists' parameter.
93      *
94      * There will be a pre-defined set of network types defined in the MSO Catalog.
95      * All such networks will have a similar configuration, based on the allowable
96      * Openstack networking definitions. This includes basic networks, provider
97      * networks (with a single VLAN), and multi-provider networks (one or more VLANs)
98      *
99      * Initially, all provider networks must be "vlan" type, and multiple segments in
100      * a multi-provider network must be multiple VLANs on the same physical network.
101      *
102      * This service supports two modes of Network creation/update:
103      * - via Heat Templates
104      * - via Neutron API
105      * The network orchestration mode for each network type is declared in its
106      * catalog definition. All Heat-based templates must support some subset of
107      * the same input parameters: network_name, physical_network, vlan(s).
108      *
109      * The method returns the network ID and a NetworkRollback object. This latter
110      * object can be passed as-is to the rollbackNetwork operation to undo everything
111      * that was created. This is useful if a network is successfully created but
112      * the orchestration fails on a subsequent operation.
113      */
114     @Override
115     public void createNetworkA (String cloudSiteId,
116                                 String tenantId,
117                                 String networkType,
118                                 String modelCustomizationUuid,
119                                 String networkName,
120                                 String physicalNetworkName,
121                                 List <Integer> vlans,
122                                 Boolean failIfExists,
123                                 Boolean backout,
124                                 List <Subnet> subnets,
125                                 Map<String,String> networkParams,
126                                 String messageId,
127                                 MsoRequest msoRequest,
128                                 String notificationUrl) {
129
130         logger.debug("Async Create Network: {} of type {} in {}/{}", networkName, networkType, cloudSiteId, tenantId);
131
132         // Use the synchronous method to perform the actual Create
133         
134
135         // Synchronous Web Service Outputs
136         Holder <String> networkId = new Holder <> ();
137         Holder <String> neutronNetworkId = new Holder <> ();
138         Holder <NetworkRollback> networkRollback = new Holder <> ();
139         Holder <Map <String, String>> subnetIdMap = new Holder <> ();
140         
141         HashMap<String, String> params = (HashMap<String,String>) networkParams;
142         if (params == null)
143                 params = new HashMap<String,String>();
144         String shared = null;
145         String external = null;
146         if (params.containsKey("shared"))
147                 shared = params.get("shared");
148         if (params.containsKey("external"))
149                 external = params.get("external");
150
151         try {
152             networkAdapter.createNetwork (cloudSiteId,
153                                           tenantId,
154                                           networkType,
155                                           modelCustomizationUuid,
156                                           networkName,
157                                           physicalNetworkName,
158                                           vlans,
159                                           shared,
160                                           external,
161                                           failIfExists,
162                                           backout,
163                                           subnets,
164                                           params,
165                                           msoRequest,
166                                           networkId,
167                                           neutronNetworkId,
168                                           subnetIdMap,
169                                           networkRollback);
170         } catch (NetworkException e) {
171             logger.debug (NETWORK_EXCEPTION_MSG, e);
172             MsoExceptionCategory exCat = null;
173             String eMsg = null;
174             try {
175                 eMsg = e.getFaultInfo ().getMessage ();
176                 exCat = MsoExceptionCategory.fromValue (e.getFaultInfo ().getCategory ().name ());
177             } catch (Exception e1) {
178                 logger.error(FAULT_INFO_ERROR_LOGMSG, MessageEnum.RA_FAULT_INFO_EXC,
179                     ErrorCode.DataError.getValue(), e1);
180             }
181             // Build and send Asynchronous error response
182             try {
183                 NetworkAdapterNotify notifyPort = getNotifyEP (notificationUrl);
184                 notifyPort.createNetworkNotification (messageId, false, exCat, eMsg, null, null, null, null);
185             } catch (Exception e1) {
186                 logger.error(CREATE_NETWORK_ERROR_LOGMSG, MessageEnum.RA_CREATE_NETWORK_NOTIF_EXC,
187                     ErrorCode.DataError.getValue(), e1.getMessage(), e1);
188
189             }
190             return;
191         }
192         logger.debug("Async Create Network:Name {} physicalNetworkName:{}", networkName, physicalNetworkName);
193         // Build and send Asynchronous response
194         try {
195             NetworkAdapterNotify notifyPort = getNotifyEP (notificationUrl);
196             notifyPort.createNetworkNotification (messageId,
197                                                   true,
198                                                   null,
199                                                   null,
200                                                   networkId.value,
201                                                   neutronNetworkId.value,
202                                                   copyCreateSubnetIdMap (subnetIdMap),
203                                                   copyNrb (networkRollback));
204         } catch (Exception e) {
205             logger.error(CREATE_NETWORK_ERROR_LOGMSG, MessageEnum.RA_CREATE_NETWORK_NOTIF_EXC,
206                 ErrorCode.DataError.getValue(), e.getMessage(), e);
207
208         }
209         return;
210     }
211
212     /**
213      * This is the "Update Network" web service implementation.
214      * It will update an existing Network of the requested type in the specified cloud
215      * and tenant. The typical use will be to replace the VLANs with the supplied
216      * list (to add or remove a VLAN), but other properties may be updated as well.
217      *
218      * There will be a pre-defined set of network types defined in the MSO Catalog.
219      * All such networks will have a similar configuration, based on the allowable
220      * Openstack networking definitions. This includes basic networks, provider
221      * networks (with a single VLAN), and multi-provider networks (one or more VLANs).
222      *
223      * Initially, all provider networks must currently be "vlan" type, and multi-provider
224      * networks must be multiple VLANs on the same physical network.
225      *
226      * This service supports two modes of Network update:
227      * - via Heat Templates
228      * - via Neutron API
229      * The network orchestration mode for each network type is declared in its
230      * catalog definition. All Heat-based templates must support some subset of
231      * the same input parameters: network_name, physical_network, vlan, segments.
232      *
233      * The method returns a NetworkRollback object. This object can be passed
234      * as-is to the rollbackNetwork operation to undo everything that was updated.
235      * This is useful if a network is successfully updated but orchestration
236      * fails on a subsequent operation.
237      */
238     @Override
239     public void updateNetworkA (String cloudSiteId,
240                                 String tenantId,
241                                 String networkType,
242                                 String modelCustomizationUuid,
243                                 String networkId,
244                                 String networkName,
245                                 String physicalNetworkName,
246                                 List <Integer> vlans,
247                                 List <Subnet> subnets,
248                                 Map <String,String> networkParams,
249                                 String messageId,
250                                 MsoRequest msoRequest,
251                                 String notificationUrl) {
252
253         logger.debug("Async Update Network: {} of type {} in {}/{}", networkId, networkType, cloudSiteId, tenantId);
254
255         // Use the synchronous method to perform the actual Create
256         
257
258         // Synchronous Web Service Outputs
259         Holder <NetworkRollback> networkRollback = new Holder <> ();
260         Holder <Map <String, String>> subnetIdMap = new Holder <> ();
261         
262         HashMap<String, String> params = (HashMap<String,String>) networkParams;
263         if (params == null)
264                 params = new HashMap<String,String>();
265         String shared = null;
266         String external = null;
267         if (params.containsKey("shared"))
268                 shared = params.get("shared");
269         if (params.containsKey("external"))
270                 external = params.get("external");
271
272         try {
273             networkAdapter.updateNetwork (cloudSiteId,
274                                           tenantId,
275                                           networkType,
276                                           modelCustomizationUuid,
277                                           networkId,
278                                           networkName,
279                                           physicalNetworkName,
280                                           vlans,
281                                           shared,
282                                           external,
283                                           subnets,
284                                           params,
285                                           msoRequest,
286                                           subnetIdMap,
287                                           networkRollback);
288         } catch (NetworkException e) {
289             logger.debug ("Got a NetworkException on updateNetwork: ", e);
290             MsoExceptionCategory exCat = null;
291             String eMsg = null;
292             try {
293                 eMsg = e.getFaultInfo ().getMessage ();
294                 exCat = MsoExceptionCategory.fromValue (e.getFaultInfo ().getCategory ().name ());
295             } catch (Exception e1) {
296                 logger.error(FAULT_INFO_ERROR_LOGMSG, MessageEnum.RA_FAULT_INFO_EXC,
297                     ErrorCode.DataError.getValue(), e1);
298             }
299             // Build and send Asynchronous error response
300             try {
301                 NetworkAdapterNotify notifyPort = getNotifyEP (notificationUrl);
302                 notifyPort.updateNetworkNotification (messageId, false, exCat, eMsg, null, copyNrb (networkRollback));
303             } catch (Exception e1) {
304                 logger.error("{} {} Error sending updateNetwork notification {} ",
305                     MessageEnum.RA_CREATE_NETWORK_NOTIF_EXC, ErrorCode.DataError.getValue(), e1.getMessage(),
306                     e1);
307
308             }
309             return;
310         }
311         logger.debug("Async Update Network:Name {} NetworkId:{}", networkName, networkId);
312         // Build and send Asynchronous response
313         try {
314             NetworkAdapterNotify notifyPort = getNotifyEP (notificationUrl);
315             notifyPort.updateNetworkNotification (messageId,
316                                                   true,
317                                                   null,
318                                                   null,
319                                                   copyUpdateSubnetIdMap (subnetIdMap),
320                                                   copyNrb (networkRollback));
321         } catch (Exception e) {
322             logger.error("{} {} Error sending updateNotification request {} ", MessageEnum.RA_CREATE_NETWORK_NOTIF_EXC,
323                 ErrorCode.DataError.getValue(), e.getMessage(), e);
324         }
325         return;
326     }
327
328     /**
329      * This is the queryNetwork method. It returns the existence and status of
330      * the specified network, along with its Neutron UUID and list of VLANs.
331      * This method attempts to find the network using both Heat and Neutron.
332      * Heat stacks are first searched based on the provided network name/id.
333      * If none is found, the Neutron is directly queried.
334      */
335     @Override
336     public void queryNetworkA (String cloudSiteId,
337                                String tenantId,
338                                String networkNameOrId,
339                                String messageId,
340                                MsoRequest msoRequest,
341                                String notificationUrl) {
342
343         logger.debug("Async Query Network {} in {}/{}", networkNameOrId, cloudSiteId, tenantId);
344         String errorCreateNetworkMessage = "{} {} Error sending createNetwork notification {} ";
345
346         // Use the synchronous method to perform the actual Create
347         
348
349         // Synchronous Web Service Outputs
350         Holder <Boolean> networkExists = new Holder <> ();
351         Holder <String> networkId = new Holder <> ();
352         Holder <String> neutronNetworkId = new Holder <> ();
353         Holder <NetworkStatus> status = new Holder <> ();
354         Holder <List <Integer>> vlans = new Holder <> ();
355         Holder <Map <String, String>> subnetIdMap = new Holder <> ();
356
357         try {
358             networkAdapter.queryNetwork (cloudSiteId,
359                                          tenantId,
360                                          networkNameOrId,
361                                          msoRequest,
362                                          networkExists,
363                                          networkId,
364                                          neutronNetworkId,
365                                          status,
366                                          vlans,
367                                          subnetIdMap);
368         } catch (NetworkException e) {
369             logger.debug (NETWORK_EXCEPTION_MSG, e);
370             MsoExceptionCategory exCat = null;
371             String eMsg = null;
372             try {
373                 eMsg = e.getFaultInfo ().getMessage ();
374                 exCat = MsoExceptionCategory.fromValue (e.getFaultInfo ().getCategory ().name ());
375             } catch (Exception e1) {
376                 logger.error(FAULT_INFO_ERROR_LOGMSG, MessageEnum.RA_FAULT_INFO_EXC,
377                     ErrorCode.DataError.getValue(), e1);
378             }
379             // Build and send Asynchronous error response
380             try {
381                 NetworkAdapterNotify notifyPort = getNotifyEP (notificationUrl);
382                 notifyPort.queryNetworkNotification (messageId, false, exCat, eMsg, null, null, null, null, null, null);
383             } catch (Exception e1) {
384                 logger.error(errorCreateNetworkMessage, MessageEnum.RA_CREATE_NETWORK_NOTIF_EXC,
385                     ErrorCode.DataError.getValue(), e1.getMessage(), e1);
386             }
387             return;
388         }
389         logger.debug("Async Query Network:NameOrId {} tenantId:{}", networkNameOrId, tenantId);
390         // Build and send Asynchronous response
391         try {
392             NetworkAdapterNotify notifyPort = getNotifyEP (notificationUrl);
393             org.onap.so.adapters.network.async.client.NetworkStatus networkS = org.onap.so.adapters.network.async.client.NetworkStatus.fromValue (status.value.name ());
394             notifyPort.queryNetworkNotification (messageId,
395                                                  true,
396                                                  null,
397                                                  null,
398                                                  networkExists.value,
399                                                  networkId.value,
400                                                  neutronNetworkId.value,
401                                                  networkS,
402                                                  vlans.value,
403                                                  copyQuerySubnetIdMap (subnetIdMap));
404         } catch (Exception e) {
405             logger.error(errorCreateNetworkMessage, MessageEnum.RA_CREATE_NETWORK_NOTIF_EXC,
406                 ErrorCode.DataError.getValue(), e.getMessage(), e);
407         }
408         return;
409     }
410
411     /**
412      * This is the "Delete Network" web service implementation.
413      * It will delete a Network in the specified cloud and tenant.
414      *
415      * If the network is not found, it is treated as a success.
416      *
417      * This service supports two modes of Network creation/update/delete:
418      * - via Heat Templates
419      * - via Neutron API
420      * The network orchestration mode for each network type is declared in its
421      * catalog definition.
422      *
423      * For Heat-based orchestration, the networkId should be the stack ID.
424      * For Neutron-based orchestration, the networkId should be the Neutron network UUID.
425      *
426      * The method returns nothing on success. Rollback is not possible for delete
427      * commands, so any failure on delete will require manual fallout in the client.
428      */
429     @Override
430     public void deleteNetworkA (String cloudSiteId,
431                                 String tenantId,
432                                 String networkType,
433                                 String modelCustomizationUuid,
434                                 String networkId,
435                                 String messageId,
436                                 MsoRequest msoRequest,
437                                 String notificationUrl) {
438
439         String serviceName = "DeleteNetworkA";
440         logger.debug("Async Delete Network {} in {}/{}", networkId, cloudSiteId, tenantId);
441
442         // Use the synchronous method to perform the actual Create
443         
444
445         // Synchronous Web Service Outputs
446         Holder <Boolean> networkDeleted = new Holder <> ();
447
448         try {
449             networkAdapter.deleteNetwork (cloudSiteId, tenantId, networkType, modelCustomizationUuid, networkId, msoRequest, networkDeleted);
450         } catch (NetworkException e) {
451             logger.debug (NETWORK_EXCEPTION_MSG, e);
452             MsoExceptionCategory exCat = null;
453             String eMsg = null;
454             try {
455                 eMsg = e.getFaultInfo ().getMessage ();
456                 exCat = MsoExceptionCategory.fromValue (e.getFaultInfo ().getCategory ().name ());
457             } catch (Exception e1) {
458                 logger.error(FAULT_INFO_ERROR_LOGMSG, MessageEnum.RA_FAULT_INFO_EXC,
459                     ErrorCode.DataError.getValue(), e1);
460             }
461             // Build and send Asynchronous error response
462             try {
463                 NetworkAdapterNotify notifyPort = getNotifyEP (notificationUrl);
464                 notifyPort.deleteNetworkNotification (messageId, false, exCat, eMsg, null);
465             } catch (Exception e1) {
466                 logger.error("{} {} Error sending createNetwork notification {} ",
467                     MessageEnum.RA_CREATE_NETWORK_NOTIF_EXC, ErrorCode.DataError.getValue(), e1.getMessage(),
468                     e1);
469
470             }
471             return;
472         }
473         logger.debug("Async Delete NetworkId: {} tenantId:{}", networkId, tenantId);
474         // Build and send Asynchronous response
475         try {
476             NetworkAdapterNotify notifyPort = getNotifyEP (notificationUrl);
477             notifyPort.deleteNetworkNotification (messageId, true, null, null, networkDeleted.value);
478         } catch (Exception e) {
479             logger.error("{} {} Error sending deleteNetwork notification {} ", MessageEnum.RA_CREATE_NETWORK_NOTIF_EXC,
480                 ErrorCode.DataError.getValue(), e.getMessage(), e);
481
482         }
483         return;
484     }
485
486     /**
487      * This web service endpoint will rollback a previous Create VNF operation.
488      * A rollback object is returned to the client in a successful creation
489      * response. The client can pass that object as-is back to the rollbackNetwork
490      * operation to undo the creation.
491      *
492      * The rollback includes removing the VNF and deleting the tenant if the
493      * tenant did not exist prior to the VNF creation.
494      */
495     @Override
496     public void rollbackNetworkA (NetworkRollback rollback, String messageId, String notificationUrl) {
497         // rollback may be null (e.g. if network already existed when Create was called)
498         if (rollback == null) {
499             logger.warn("{} {} Rollback is null", MessageEnum.RA_ROLLBACK_NULL,
500                 ErrorCode.SchemaError.getValue());
501             return;
502         }
503
504         logger.info("{} {}", MessageEnum.RA_ASYNC_ROLLBACK, rollback.getNetworkStackId());
505         // Use the synchronous method to perform the actual Create
506         
507
508         try {
509             networkAdapter.rollbackNetwork (rollback);
510         } catch (NetworkException e) {
511             logger.debug ("Got a NetworkException on rollbackNetwork: ", e);
512             // Build and send Asynchronous error response
513             MsoExceptionCategory exCat = null;
514             String eMsg = null;
515             try {
516                 eMsg = e.getFaultInfo ().getMessage ();
517                 exCat = MsoExceptionCategory.fromValue (e.getFaultInfo ().getCategory ().name ());
518             } catch (Exception e1) {
519                 logger.error("{} {} Exception in get fault info ", MessageEnum.RA_FAULT_INFO_EXC,
520                     ErrorCode.DataError.getValue(), e1);
521             }
522             // Build and send Asynchronous error response
523             try {
524                 NetworkAdapterNotify notifyPort = getNotifyEP (notificationUrl);
525                 notifyPort.rollbackNetworkNotification (rollback.getMsoRequest ().getRequestId (), false, exCat, eMsg);
526             } catch (Exception e1) {
527                 logger.error(CREATE_NETWORK_ERROR_LOGMSG, MessageEnum.RA_CREATE_NETWORK_NOTIF_EXC,
528                     ErrorCode.DataError.getValue(), e1.getMessage(), e1);
529
530             }
531             return;
532         }
533         logger.debug("Async Rollback NetworkId: {} tenantId:{}", rollback.getNetworkStackId(), rollback.getTenantId());
534         // Build and send Asynchronous response
535         try {
536             NetworkAdapterNotify notifyPort = getNotifyEP (notificationUrl);
537             notifyPort.rollbackNetworkNotification (rollback.getMsoRequest ().getRequestId (), true, null, null);
538         } catch (Exception e) {
539             logger
540                 .error("{} {} Error sending rollbackNetwork notification {} ", MessageEnum.RA_CREATE_NETWORK_NOTIF_EXC,
541                     ErrorCode.DataError.getValue(), e.getMessage(), e);
542
543         }
544         return;
545     }
546
547     private org.onap.so.adapters.network.async.client.NetworkRollback copyNrb (Holder <NetworkRollback> hNrb) {
548         org.onap.so.adapters.network.async.client.NetworkRollback cnrb = new org.onap.so.adapters.network.async.client.NetworkRollback ();
549
550         if (hNrb != null && hNrb.value != null) {
551             org.onap.so.adapters.network.async.client.MsoRequest cmr = new org.onap.so.adapters.network.async.client.MsoRequest ();
552
553             cnrb.setCloudId (hNrb.value.getCloudId ());
554             cmr.setRequestId (hNrb.value.getMsoRequest ().getRequestId ());
555             cmr.setServiceInstanceId (hNrb.value.getMsoRequest ().getServiceInstanceId ());
556             cnrb.setMsoRequest (cmr);
557             cnrb.setNetworkId (hNrb.value.getNetworkId ());
558             cnrb.setNetworkStackId (hNrb.value.getNetworkStackId ());
559             cnrb.setNeutronNetworkId (hNrb.value.getNeutronNetworkId ());
560             cnrb.setTenantId (hNrb.value.getTenantId ());
561             cnrb.setNetworkType (hNrb.value.getNetworkType ());
562             cnrb.setNetworkCreated (hNrb.value.getNetworkCreated ());
563             cnrb.setNetworkName (hNrb.value.getNetworkName ());
564             cnrb.setPhysicalNetwork (hNrb.value.getPhysicalNetwork ());
565             List <Integer> vlansc = cnrb.getVlans ();
566             List <Integer> vlansh = hNrb.value.getVlans ();
567             if (vlansh != null) {
568                 vlansc.addAll (vlansh);
569             }
570         }
571         return cnrb;
572     }
573
574     private NetworkAdapterNotify getNotifyEP (String notificationUrl) {
575
576         URL warWsdlLoc = null;
577         try {
578             warWsdlLoc = Thread.currentThread ().getContextClassLoader ().getResource ("NetworkAdapterNotify.wsdl");
579         } catch (Exception e) {
580             logger.error("{} {} Exception - WSDL not found ", MessageEnum.RA_WSDL_NOT_FOUND,
581                 ErrorCode.DataError.getValue(), e);
582         }
583         if (warWsdlLoc == null) {
584             logger
585                 .error("{} {} WSDL not found", MessageEnum.RA_WSDL_NOT_FOUND, ErrorCode.DataError.getValue());
586         } else {
587             try {
588                 logger.debug("NetworkAdpaterNotify.wsdl location: {}", warWsdlLoc.toURI().toString());
589             } catch (Exception e) {
590                 logger.error("{} {} Exception - WSDL URL convention ", MessageEnum.RA_WSDL_URL_CONVENTION_EXC,
591                     ErrorCode.SchemaError.getValue(), e);
592             }
593         }
594
595         NetworkAdapterNotify_Service notifySvc = new NetworkAdapterNotify_Service (warWsdlLoc,
596                                                                                    new QName ("http://org.onap.so/networkNotify",
597                                                                                               "networkAdapterNotify"));
598
599         NetworkAdapterNotify notifyPort = notifySvc.getMsoNetworkAdapterAsyncImplPort ();
600
601         BindingProvider bp = (BindingProvider) notifyPort;
602
603         URL epUrl = null;
604         try {
605             epUrl = new URL (notificationUrl);
606         } catch (MalformedURLException e1) {
607             logger.error("{} {} Exception - init notification ", MessageEnum.RA_INIT_NOTIF_EXC,
608                 ErrorCode.DataError.getValue(), e1);
609         }
610
611         if(null != epUrl) {
612             logger.debug("Notification Endpoint URL: {}", epUrl.toExternalForm());
613             bp.getRequestContext ().put (BindingProvider.ENDPOINT_ADDRESS_PROPERTY, epUrl.toExternalForm ());
614         }
615         else {
616             logger.debug("Notification Endpoint URL is NULL: ");
617         }
618
619         // authentication
620         try {
621             Map <String, Object> reqCtx = bp.getRequestContext ();
622             Map <String, List <String>> headers = new HashMap <> ();
623
624             String userCredentials = this.getEncryptedProperty (BPEL_AUTH_PROP, "", ENCRYPTION_KEY_PROP);
625
626             String basicAuth = "Basic " + DatatypeConverter.printBase64Binary (userCredentials.getBytes ());
627             reqCtx.put (MessageContext.HTTP_REQUEST_HEADERS, headers);
628             headers.put ("Authorization", Collections.singletonList (basicAuth));
629         } catch (Exception e) {
630             logger.error("{} {} Unable to set authorization in callback request {} ",
631                 MessageEnum.RA_SET_CALLBACK_AUTH_EXC, ErrorCode.DataError.getValue(), e.getMessage(), e);
632         }
633
634         return notifyPort;
635     }
636     
637     public String getEncryptedProperty(String key, String defaultValue, String encryptionKey) {
638         try {
639                         return CryptoUtils.decrypt(this.environment.getProperty(key), this.environment.getProperty(encryptionKey));
640                 } catch (GeneralSecurityException e) {
641           logger.debug("Exception while decrypting property: {} ", this.environment.getProperty(key), e);
642                 }
643                 return defaultValue;
644
645         }
646
647     private CreateNetworkNotification.SubnetIdMap copyCreateSubnetIdMap (Holder <Map <String, String>> hMap) {
648
649         CreateNetworkNotification.SubnetIdMap subnetIdMap = new CreateNetworkNotification.SubnetIdMap ();
650
651         if (hMap != null && hMap.value != null) {
652             Map <String, String> sMap = hMap.value;
653             CreateNetworkNotification.SubnetIdMap.Entry entry = new CreateNetworkNotification.SubnetIdMap.Entry ();
654
655             for (Map.Entry<String,String> mapEntry : sMap.entrySet ()) {
656                 String key = mapEntry.getKey();
657                         String value = mapEntry.getValue();
658                 entry.setKey (key);
659                 entry.setValue (value);
660                 subnetIdMap.getEntry ().add (entry);
661             }
662         }
663         return subnetIdMap;
664     }
665
666     private UpdateNetworkNotification.SubnetIdMap copyUpdateSubnetIdMap (Holder <Map <String, String>> hMap) {
667
668         UpdateNetworkNotification.SubnetIdMap subnetIdMap = new UpdateNetworkNotification.SubnetIdMap ();
669
670         if (hMap != null && hMap.value != null) {
671             Map <String, String> sMap = hMap.value;
672             UpdateNetworkNotification.SubnetIdMap.Entry entry = new UpdateNetworkNotification.SubnetIdMap.Entry ();
673
674             for (Map.Entry<String,String> mapEntry : sMap.entrySet ()) {
675                 String key = mapEntry.getKey();
676                 String value = mapEntry.getValue();
677                 entry.setKey (key);
678                 entry.setValue (value);
679                 subnetIdMap.getEntry ().add (entry);
680             }
681         }
682         return subnetIdMap;
683     }
684
685     private QueryNetworkNotification.SubnetIdMap copyQuerySubnetIdMap (Holder <Map <String, String>> hMap) {
686
687         QueryNetworkNotification.SubnetIdMap subnetIdMap = new QueryNetworkNotification.SubnetIdMap ();
688
689         if (hMap != null && hMap.value != null) {
690             Map <String, String> sMap = hMap.value;
691             QueryNetworkNotification.SubnetIdMap.Entry entry = new QueryNetworkNotification.SubnetIdMap.Entry ();
692
693             for (Map.Entry<String,String> mapEntry : sMap.entrySet ()) {
694                 String key = mapEntry.getKey();
695                 String value = mapEntry.getValue();
696                 entry.setKey (key);
697                 entry.setValue (value);
698                 subnetIdMap.getEntry ().add (entry);
699             }
700         }
701         return subnetIdMap;
702     }
703 }