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