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