AT&T 1712 and 1802 release code
[so.git] / adapters / mso-vnf-adapter / src / main / java / org / openecomp / mso / adapters / vnf / MsoVnfAdapterAsyncImpl.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.vnf;
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.vnf.async.client.CreateVnfNotification;
40 import org.openecomp.mso.adapters.vnf.async.client.QueryVnfNotification;
41 import org.openecomp.mso.adapters.vnf.async.client.UpdateVnfNotification;
42 import org.openecomp.mso.adapters.vnf.async.client.VnfAdapterNotify;
43 import org.openecomp.mso.adapters.vnf.async.client.VnfAdapterNotify_Service;
44 import org.openecomp.mso.adapters.vnf.exceptions.VnfException;
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.VnfRollback;
51 import org.openecomp.mso.openstack.beans.VnfStatus;
52 import org.openecomp.mso.properties.MsoPropertiesFactory;
53
54 @WebService(serviceName = "VnfAdapterAsync", endpointInterface = "org.openecomp.mso.adapters.vnf.MsoVnfAdapterAsync", targetNamespace = "http://org.openecomp.mso/vnfA")
55 public class MsoVnfAdapterAsyncImpl implements MsoVnfAdapterAsync {
56
57         MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
58
59         CloudConfigFactory cloudConfigFactory=new CloudConfigFactory();
60
61         public static final String MSO_PROP_VNF_ADAPTER="MSO_PROP_VNF_ADAPTER";
62     private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
63     private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger ();
64     private static final String BPEL_AUTH_PROP = "org.openecomp.mso.adapters.vnf.bpelauth";
65     private static final String ENCRYPTION_KEY = "aa3871669d893c7fb8abbcda31b88b4f";
66
67     /**
68      * Health Check web method. Does nothing but return to show the adapter is deployed.
69      */
70     @Override
71     public void healthCheckA () {
72         LOGGER.debug ("Health check call in VNF Adapter");
73     }
74
75     /**
76      * This is the asynchronous "Create VNF" web service implementation.
77      * It will create a new VNF of the requested type in the specified cloud
78      * and tenant. The tenant must exist before this service is called.
79      *
80      * If a VNF with the same name already exists, this can be considered a
81      * success or failure, depending on the value of the 'failIfExists' parameter.
82      *
83      * All VNF types will be defined in the MSO catalog. The caller must request
84      * one of these pre-defined types or an error will be returned. Within the
85      * catalog, each VNF type references (among other things) a Heat template
86      * which is used to deploy the required VNF artifacts (VMs, networks, etc.)
87      * to the cloud.
88      *
89      * Depending on the Heat template, a variable set of input parameters will
90      * be defined, some of which are required. The caller is responsible to
91      * pass the necessary input data for the VNF or an error will be thrown.
92      *
93      * The method sends an asynchronous response to the notification URL when
94      * processing completes. The createAsyncResponse contains the vnfId (the
95      * canonical name of the stack), a Map of VNF output attributes, and a
96      * VnfRollback object. This last object can be passed as-is to the
97      * rollbackVnf operation to undo everything that was created for the VNF.
98      * This is useful if a VNF is successfully created but the orchestrator
99      * fails on a subsequent operation.
100      *
101      * Note: this method is implemented by calling the synchronous web method
102      * and translating the response to an asynchronous notification.
103      *
104      * @param cloudSiteId CLLI code of the cloud site in which to create the VNF
105      * @param tenantId Openstack tenant identifier
106      * @param vnfType VNF type key, should match a VNF definition in catalog DB
107      * @param vnfName Name to be assigned to the new VNF
108      * @param inputs Map of key=value inputs for VNF stack creation
109      * @param failIfExists Flag whether already existing VNF should be considered
110      *        a success or failure
111      * @param msoRequest Request tracking information for logs
112      * @param notificationURL the target URL for asynchronous response
113      */
114     @Override
115     public void createVnfA (String cloudSiteId,
116                             String tenantId,
117                             String vnfType,
118                             String vnfVersion,
119                             String vnfName,
120                             String requestType,
121                             String volumeGroupHeatStackId,
122                             Map <String, String> inputs,
123                             Boolean failIfExists,
124                             Boolean backout,
125                             String messageId,
126                             MsoRequest msoRequest,
127                             String notificationUrl) {
128         String error;
129         String serviceName = "CreateVnfA";
130         MsoLogger.setLogContext (msoRequest);
131         MsoLogger.setServiceName (serviceName);
132         LOGGER.info (MessageEnum.RA_ASYNC_CREATE_VNF, vnfName, vnfType, cloudSiteId, tenantId, "", "createVnfA");
133         // Use the synchronous method to perform the actual Create
134         MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory, cloudConfigFactory);
135
136         // Synchronous Web Service Outputs
137         Holder <String> vnfId = new Holder <> ();
138         Holder <Map <String, String>> outputs = new Holder <> ();
139         Holder <VnfRollback> vnfRollback = new Holder <> ();
140
141         try {
142             vnfAdapter.createVnf (cloudSiteId,
143                                   tenantId,
144                                   vnfType,
145                                   vnfVersion,
146                                   vnfName,
147                                   requestType,
148                                   volumeGroupHeatStackId,
149                                   inputs,
150                                   failIfExists,
151                                   backout,
152                                   msoRequest,
153                                   vnfId,
154                                   outputs,
155                                   vnfRollback);
156             MsoLogger.setServiceName (serviceName);
157         } catch (VnfException e) {
158                 MsoLogger.setServiceName (serviceName);
159                 LOGGER.error (MessageEnum.RA_CREATE_VNF_ERR,  vnfName, cloudSiteId, tenantId, "", "createVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "VnfException in createVnfA", e);
160             org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
161             String eMsg = null;
162             try {
163                 eMsg = e.getFaultInfo ().getMessage ();
164                 exCat = org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
165                                                                                                      .getCategory ()
166                                                                                                      .name ());
167             } catch (Exception e1) {
168                 LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "createVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - Fault info", e1);
169             }
170             // Build and send Asynchronous error response
171             try {
172                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
173                 notifyPort.createVnfNotification (messageId, false, exCat, eMsg, null, null, null);
174             } catch (Exception e1) {
175                 error = "Error sending createVnf notification " + e1.getMessage ();
176                 LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "createVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending createVnf notification", e1);
177                 alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
178             }
179             LOGGER.info (MessageEnum.RA_ASYNC_CREATE_VNF_COMPLETE, "", "createVnfA", "", "createVnfA");
180             return;
181         }
182         LOGGER.debug ("Async Create VNF: " + vnfName + " VnfId:" + vnfId.value);
183         // Build and send Asynchronous response
184         try {
185             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
186             notifyPort.createVnfNotification (messageId,
187                                               true,
188                                               null,
189                                               null,
190                                               vnfId.value,
191                                               copyCreateOutputs (outputs),
192                                               copyVrb (vnfRollback));
193         } catch (Exception e) {
194             error = "Error sending createVnf notification " + e.getMessage ();
195             LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "createVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending createVnf notification", e);
196             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
197         }
198         LOGGER.info (MessageEnum.RA_ASYNC_CREATE_VNF_COMPLETE, "", "createVnfA");
199         return;
200     }
201
202     @Override
203     public void updateVnfA (String cloudSiteId,
204                             String tenantId,
205                             String vnfType,
206                             String vnfVersion,
207                             String vnfName,
208                             String requestType,
209                             String volumeGroupHeatStackId,
210                             Map <String, String> inputs,
211                             String messageId,
212                             MsoRequest msoRequest,
213                             String notificationUrl) {
214         String error;
215         String serviceName = "UpdateVnfA";
216         MsoLogger.setServiceName (serviceName);
217         MsoLogger.setLogContext (msoRequest);
218         LOGGER.info (MessageEnum.RA_ASYNC_UPDATE_VNF, vnfName, vnfType, cloudSiteId, tenantId, "", "UpdateVnfA");
219
220         // Use the synchronous method to perform the actual Create
221         MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory,cloudConfigFactory);
222
223         // Synchronous Web Service Outputs
224         Holder <String> vnfId = new Holder <> ();
225         Holder <Map <String, String>> outputs = new Holder <> ();
226         Holder <VnfRollback> vnfRollback = new Holder <> ();
227
228         try {
229             vnfAdapter.updateVnf (cloudSiteId, tenantId, vnfType,vnfVersion, vnfName, requestType, volumeGroupHeatStackId, inputs, msoRequest, outputs, vnfRollback);
230             MsoLogger.setServiceName (serviceName);
231         } catch (VnfException e) {
232                 MsoLogger.setServiceName (serviceName);
233                 LOGGER.error (MessageEnum.RA_UPDATE_VNF_ERR,  vnfName, cloudSiteId, tenantId, "", "UpdateVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending updateVnf notification", e);
234             org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
235             String eMsg = null;
236             try {
237                 eMsg = e.getFaultInfo ().getMessage ();
238                 exCat = org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
239                                                                                                      .getCategory ()
240                                                                                                      .name ());
241             } catch (Exception e1) {
242                 LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "UpdateVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
243             }
244             // Build and send Asynchronous error response
245             try {
246                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
247                 notifyPort.updateVnfNotification (messageId, false, exCat, eMsg, null, null);
248             } catch (Exception e1) {
249                 error = "Error sending updateVnf notification " + e1.getMessage ();
250                 LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "UpdateVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending updateVnf notification", e1);
251                 alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
252             }
253             LOGGER.info (MessageEnum.RA_ASYNC_UPDATE_VNF_COMPLETE, "", "UpdateVnfA");
254             return;
255         }
256         LOGGER.debug ("Async Update VNF: " + vnfName + " VnfId:" + vnfId.value);
257         // Build and send Asynchronous response
258         try {
259             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
260             notifyPort.updateVnfNotification (messageId,
261                                               true,
262                                               null,
263                                               null,
264                                               copyUpdateOutputs (outputs),
265                                               copyVrb (vnfRollback));
266         } catch (Exception e) {
267             error = "Error sending updateVnf notification " + e.getMessage ();
268             LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "UpdateVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending updateVnf notification", e);
269             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
270         }
271         LOGGER.info (MessageEnum.RA_ASYNC_UPDATE_VNF_COMPLETE, "", "UpdateVnfA");
272         return;
273     }
274
275     /**
276      * This is the "Query VNF" web service implementation.
277      * It will look up a VNF by name or ID in the specified cloud and tenant.
278      *
279      * The method returns an indicator that the VNF exists, its Openstack internal
280      * ID, its status, and the set of outputs (from when the stack was created).
281      *
282      * @param cloudSiteId CLLI code of the cloud site in which to query
283      * @param tenantId Openstack tenant identifier
284      * @param vnfName VNF Name or Openstack ID
285      * @param msoRequest Request tracking information for logs
286      * @param notificationURL the target URL for asynchronous response
287      */
288     @Override
289     public void queryVnfA (String cloudSiteId,
290                            String tenantId,
291                            String vnfName,
292                            String messageId,
293                            MsoRequest msoRequest,
294                            String notificationUrl) {
295         String error;
296         String serviceName = "QueryVnfA";
297         MsoLogger.setServiceName (serviceName);
298         MsoLogger.setLogContext (msoRequest);
299         LOGGER.info (MessageEnum.RA_ASYNC_QUERY_VNF, vnfName, cloudSiteId, tenantId);
300
301         // Use the synchronous method to perform the actual query
302         MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory,cloudConfigFactory);
303
304         // Synchronous Web Service Outputs
305         Holder <Boolean> vnfExists = new Holder <> ();
306         Holder <String> vnfId = new Holder <> ();
307         Holder <VnfStatus> status = new Holder <> ();
308         Holder <Map <String, String>> outputs = new Holder <> ();
309
310         try {
311             vnfAdapter.queryVnf (cloudSiteId, tenantId, vnfName, msoRequest, vnfExists, vnfId, status, outputs);
312             MsoLogger.setServiceName (serviceName);
313         } catch (VnfException e) {
314                 MsoLogger.setServiceName (serviceName);
315             LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR,  vnfName, cloudSiteId, tenantId, "", "queryVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending queryVnfA notification", e);
316             org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
317             String eMsg = null;
318             try {
319                 eMsg = e.getFaultInfo ().getMessage ();
320                 exCat = org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
321                                                                                                      .getCategory ()
322                                                                                                      .name ());
323             } catch (Exception e1) {
324                 LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "queryVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
325             }
326             // Build and send Asynchronous error response
327             try {
328                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
329                 notifyPort.queryVnfNotification (messageId, false, exCat, eMsg, null, null, null, null);
330             } catch (Exception e1) {
331                 error = "Error sending queryVnf notification " + e1.getMessage ();
332                 LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "queryVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending queryVnf notification", e1);
333                 alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
334             }
335             LOGGER.info (MessageEnum.RA_ASYNC_QUERY_VNF_COMPLETE, "", "queryVnfA");
336             return;
337         }
338
339         if (!vnfExists.value) {
340             LOGGER.debug ("Async Query, VNF not found");
341         } else {
342             LOGGER.debug ("Async Query, VNF=" + vnfId.value + ", status=" + status.value);
343         }
344         // Build and send Asynchronous response
345         try {
346             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
347             org.openecomp.mso.adapters.vnf.async.client.VnfStatus vnfS = org.openecomp.mso.adapters.vnf.async.client.VnfStatus.fromValue (status.value.name ());
348             notifyPort.queryVnfNotification (messageId,
349                                              true,
350                                              null,
351                                              null,
352                                              vnfExists.value,
353                                              vnfId.value,
354                                              vnfS,
355                                              copyQueryOutputs (outputs));
356         } catch (Exception e) {
357             error = "Error sending queryVnf notification " + e.getMessage ();
358             LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "queryVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending queryVnf notification", e);
359             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
360         }
361
362         LOGGER.info (MessageEnum.RA_ASYNC_QUERY_VNF_COMPLETE, "", "queryVnfA");
363         return;
364     }
365
366     /**
367      * This is the Asynchronous "Delete VNF" web service implementation.
368      * It will delete a VNF by name or ID in the specified cloud and tenant.
369      *
370      * The method has no outputs.
371      *
372      * @param cloudSiteId CLLI code of the cloud site in which to delete
373      * @param tenantId Openstack tenant identifier
374      * @param vnfName VNF Name or Openstack ID
375      * @param messageId
376      * @param msoRequest Request tracking information for logs
377      * @param notificationUrl the target URL for asynchronous response
378      */
379     @Override
380     public void deleteVnfA (String cloudSiteId,
381                             String tenantId,
382                             String vnfName,
383                             String messageId,
384                             MsoRequest msoRequest,
385                             String notificationUrl) {
386         String error;
387         String serviceName = "DeleteVnfA";
388         MsoLogger.setServiceName (serviceName);
389         MsoLogger.setLogContext (msoRequest);
390         LOGGER.info (MessageEnum.RA_ASYNC_DELETE_VNF, vnfName, cloudSiteId, tenantId);
391
392         // Use the synchronous method to perform the actual delete
393         MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory,cloudConfigFactory);
394
395         try {
396             vnfAdapter.deleteVnf (cloudSiteId, tenantId, vnfName, msoRequest);
397             MsoLogger.setServiceName (serviceName);
398         } catch (VnfException e) {
399                 MsoLogger.setServiceName (serviceName);
400                 LOGGER.error (MessageEnum.RA_DELETE_VNF_ERR,  vnfName, cloudSiteId, tenantId, "", "deleteVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending deleteVnfA notification", e);
401             org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
402             String eMsg = null;
403             try {
404                 eMsg = e.getFaultInfo ().getMessage ();
405                 exCat = org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
406                                                                                                      .getCategory ()
407                                                                                                      .name ());
408             } catch (Exception e1) {
409                 LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "deleteVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
410             }
411             // Build and send Asynchronous error response
412             try {
413                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
414                 notifyPort.deleteVnfNotification (messageId, false, exCat, eMsg);
415             } catch (Exception e1) {
416                 error = "Error sending deleteVnf notification " + e1.getMessage ();
417                 LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "deleteVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending deleteVnfA notification", e1);
418                 alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
419             }
420             LOGGER.info (MessageEnum.RA_ASYNC_DELETE_VNF_COMPLETE, "", "deleteVnfA");
421             return;
422         }
423
424         LOGGER.debug ("Async Delete VNF: " + vnfName);
425         // Build and send Asynchronous response
426         try {
427             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
428             notifyPort.deleteVnfNotification (messageId, true, null, null);
429
430         } catch (Exception e) {
431             error = "Error sending deleteVnf notification " + e.getMessage ();
432             LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "deleteVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending deleteVnfA notification", e);
433             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
434         }
435
436         LOGGER.info (MessageEnum.RA_ASYNC_DELETE_VNF_COMPLETE, "", "deleteVnfA");
437         return;
438     }
439
440     /**
441      * This web service endpoint will rollback a previous Create VNF operation.
442      * A rollback object is returned to the client in a successful creation
443      * response. The client can pass that object as-is back to the rollbackVnf
444      * operation to undo the creation.
445      */
446     @Override
447     public void rollbackVnfA (VnfRollback rollback, String messageId, String notificationUrl) {
448         String serviceName = "RollbackVnfA";
449         MsoLogger.setServiceName (serviceName);
450         String error;
451         // rollback may be null (e.g. if stack already existed when Create was called)
452         if (rollback == null) {
453             error = "Empty Rollback: No action to perform";
454             LOGGER.info (MessageEnum.RA_ROLLBACK_NULL, "", "rollbackVnfA");
455             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
456             return;
457         }
458
459         MsoLogger.setLogContext (rollback.getMsoRequest ());
460         LOGGER.info (MessageEnum.RA_ASYNC_ROLLBACK_VNF, "", "rollbackVnfA");
461
462         // Use the synchronous method to perform the actual rollback
463         MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory,cloudConfigFactory);
464
465         try {
466             vnfAdapter.rollbackVnf (rollback);
467             MsoLogger.setServiceName (serviceName);
468         } catch (VnfException e) {
469                 MsoLogger.setServiceName (serviceName);
470                 LOGGER.error (MessageEnum.RA_ROLLBACK_VNF_ERR, "", "rollbackVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending rollbackVnfA notification", e);
471             org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory exCat = null;
472             String eMsg = null;
473             try {
474                 eMsg = e.getFaultInfo ().getMessage ();
475                 exCat = org.openecomp.mso.adapters.vnf.async.client.MsoExceptionCategory.fromValue (e.getFaultInfo ()
476                                                                                                      .getCategory ()
477                                                                                                      .name ());
478             } catch (Exception e1) {
479                 LOGGER.error (MessageEnum.RA_FAULT_INFO_EXC, "", "rollbackVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - fault info", e1);
480             }
481             // Build and send Asynchronous error response
482             try {
483                 VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
484                 notifyPort.rollbackVnfNotification (messageId, false, exCat, eMsg);
485             } catch (Exception e1) {
486                 error = "Error sending rollbackVnf notification " + e1.getMessage ();
487                 LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "rollbackVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending rollbackVnfA notification", e1);
488                 alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
489             }
490             LOGGER.info (MessageEnum.RA_ASYNC_ROLLBACK_VNF_COMPLETE, "", "rollbackVnfA");
491             return;
492         }
493
494         LOGGER.debug ("Async Rollback VNF:" + rollback.getVnfId ());
495         // Build and send Asynchronous response
496         try {
497             VnfAdapterNotify notifyPort = getNotifyEP (notificationUrl);
498             notifyPort.rollbackVnfNotification (messageId, true, null, null);
499         } catch (Exception e) {
500             error = "Error sending rollbackVnf notification " + e.getMessage ();
501             LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, "", "rollbackVnfA", MsoLogger.ErrorCode.BusinessProcesssError, "Exception sending rollbackVnfA notification", e);
502             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, error);
503         }
504
505         LOGGER.info (MessageEnum.RA_ASYNC_ROLLBACK_VNF_COMPLETE, "", "rollbackVnfA");
506         return;
507     }
508
509     private org.openecomp.mso.adapters.vnf.async.client.VnfRollback copyVrb (Holder <VnfRollback> hVrb) {
510         org.openecomp.mso.adapters.vnf.async.client.VnfRollback cvrb = new org.openecomp.mso.adapters.vnf.async.client.VnfRollback ();
511
512         if (hVrb != null && hVrb.value != null) {
513             org.openecomp.mso.adapters.vnf.async.client.MsoRequest cmr = new org.openecomp.mso.adapters.vnf.async.client.MsoRequest ();
514
515             cvrb.setCloudSiteId (hVrb.value.getCloudSiteId ());
516             if (hVrb.value.getMsoRequest() != null) {
517                 cmr.setRequestId (hVrb.value.getMsoRequest ().getRequestId ());
518                 cmr.setServiceInstanceId (hVrb.value.getMsoRequest ().getServiceInstanceId ());
519             } else {
520                 cmr.setRequestId (null);
521                 cmr.setServiceInstanceId (null);
522             }
523             cvrb.setMsoRequest (cmr);
524             cvrb.setVnfId (hVrb.value.getVnfId ());
525             cvrb.setTenantId (hVrb.value.getTenantId ());
526             cvrb.setTenantCreated (hVrb.value.getTenantCreated ());
527             cvrb.setVnfCreated (hVrb.value.getVnfCreated ());
528         }
529         return cvrb;
530     }
531
532     private CreateVnfNotification.Outputs copyCreateOutputs (Holder <Map <String, String>> hMap) {
533
534         CreateVnfNotification.Outputs outputs = new CreateVnfNotification.Outputs ();
535
536         if (hMap != null && hMap.value != null) {
537             Map <String, String> sMap = new HashMap <> ();
538             sMap = hMap.value;
539             CreateVnfNotification.Outputs.Entry entry = new CreateVnfNotification.Outputs.Entry ();
540
541             for (String key : sMap.keySet ()) {
542                 entry.setKey (key);
543                 entry.setValue (sMap.get (key));
544                 outputs.getEntry ().add (entry);
545             }
546         }
547         return outputs;
548     }
549
550     private UpdateVnfNotification.Outputs copyUpdateOutputs (Holder <Map <String, String>> hMap) {
551
552         UpdateVnfNotification.Outputs outputs = new UpdateVnfNotification.Outputs ();
553
554         if (hMap != null && hMap.value != null) {
555             Map <String, String> sMap = new HashMap <> ();
556             sMap = hMap.value;
557             UpdateVnfNotification.Outputs.Entry entry = new UpdateVnfNotification.Outputs.Entry ();
558
559             for (Map.Entry<String,String> mapEntry : sMap.entrySet ()) {
560                 String key = mapEntry.getKey();
561                 String value = mapEntry.getValue();
562                 entry.setKey (key);
563                 entry.setValue (value);
564                 outputs.getEntry ().add (entry);
565             }
566         }
567         return outputs;
568     }
569
570     private QueryVnfNotification.Outputs copyQueryOutputs (Holder <Map <String, String>> hMap) {
571
572         QueryVnfNotification.Outputs outputs = new QueryVnfNotification.Outputs ();
573
574         if (hMap != null && hMap.value != null) {
575             Map <String, String> sMap = new HashMap <> ();
576             sMap = hMap.value;
577
578             QueryVnfNotification.Outputs.Entry entry = new QueryVnfNotification.Outputs.Entry ();
579
580             for (Map.Entry<String,String> mapEntry : sMap.entrySet ()) {
581                 String key = mapEntry.getKey();
582                 String value = mapEntry.getValue();
583                 entry.setKey (key);
584                 entry.setValue (value);
585                 outputs.getEntry ().add (entry);
586             }
587         }
588         return outputs;
589     }
590
591     private VnfAdapterNotify getNotifyEP (String notificationUrl) {
592
593         URL warWsdlLoc = null;
594         try {
595             warWsdlLoc = Thread.currentThread ().getContextClassLoader ().getResource ("VnfAdapterNotify.wsdl");
596         } catch (Exception e) {
597             LOGGER.error (MessageEnum.RA_WSDL_NOT_FOUND, "VnfAdapterNotify.wsdl", "", "getNotifyEP", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - WSDL not found", e);
598         }
599         if (warWsdlLoc == null) {
600                 LOGGER.error (MessageEnum.RA_WSDL_NOT_FOUND, "VnfAdapterNotify.wsdl", "", "getNotifyEP", MsoLogger.ErrorCode.BusinessProcesssError, "WSDL not found");
601         } else {
602             try {
603                 LOGGER.debug ("VnfAdpaterNotify.wsdl location:" + warWsdlLoc.toURI ().toString ());
604             } catch (Exception e) {
605                 LOGGER.error (MessageEnum.RA_WSDL_URL_CONVENTION_EXC, "VnfAdapterNotify.wsdl", "", "getNotifyEP", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - WSDL URL convention", e);
606             }
607         }
608
609         VnfAdapterNotify_Service notifySvc = new VnfAdapterNotify_Service (warWsdlLoc,
610                                                                            new QName ("http://org.openecomp.mso/vnfNotify",
611                                                                                       "vnfAdapterNotify"));
612
613         VnfAdapterNotify notifyPort = notifySvc.getMsoVnfAdapterAsyncImplPort ();
614
615         BindingProvider bp = (BindingProvider) notifyPort;
616
617         URL epUrl = null;
618         try {
619             epUrl = new URL (notificationUrl);
620         } catch (MalformedURLException e1) {
621             LOGGER.error (MessageEnum.RA_INIT_NOTIF_EXC, "", "getNotifyEP", MsoLogger.ErrorCode.BusinessProcesssError, "MalformedURLException", e1);
622         }
623
624         if(null != epUrl) {
625             LOGGER.debug ("Notification Endpoint URL: " + epUrl.toExternalForm ());
626             bp.getRequestContext ().put (BindingProvider.ENDPOINT_ADDRESS_PROPERTY, epUrl.toExternalForm ());
627         }
628         else {
629             LOGGER.debug ("epUrl is NULL:");
630         }
631
632         // authentication
633         try {
634             Map <String, Object> reqCtx = bp.getRequestContext ();
635             Map <String, List <String>> headers = new HashMap <> ();
636
637             String userCredentials = msoPropertiesFactory.getMsoJavaProperties (MSO_PROP_VNF_ADAPTER).getEncryptedProperty (BPEL_AUTH_PROP,
638                                                                                              "",
639                                                                                              ENCRYPTION_KEY);
640
641             String basicAuth = "Basic " + DatatypeConverter.printBase64Binary (userCredentials.getBytes ());
642             reqCtx.put (MessageContext.HTTP_REQUEST_HEADERS, headers);
643             headers.put ("Authorization", Collections.singletonList (basicAuth));
644         } catch (Exception e) {
645             LOGGER.error (MessageEnum.RA_SET_CALLBACK_AUTH_EXC, "", "getNotifyEP", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - Unable to set authorization in callback request", e);
646             alarmLogger.sendAlarm ("MsoInternalError", MsoAlarmLogger.CRITICAL, "Unable to set authorization in callback request");
647         }
648
649         return notifyPort;
650     }
651
652 }