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