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