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