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