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