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