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