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