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