2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.so.adapters.vnfmadapter.rest;
23 import static org.onap.so.adapters.vnfmadapter.Constants.BASE_URL;
24 import static org.slf4j.LoggerFactory.getLogger;
25 import java.util.concurrent.ExecutorService;
26 import java.util.concurrent.Executors;
27 import javax.ws.rs.core.MediaType;
28 import org.onap.so.adapters.vnfmadapter.extclients.aai.AaiHelper;
29 import org.onap.so.adapters.vnfmadapter.extclients.aai.AaiServiceProvider;
30 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.VnfmServiceProvider;
31 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfIdentifierCreationNotification;
32 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfIdentifierDeletionNotification;
33 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification;
34 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification.OperationEnum;
35 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification.OperationStateEnum;
36 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201;
37 import org.onap.so.adapters.vnfmadapter.notificationhandling.NotificationHandler;
38 import org.slf4j.Logger;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.http.HttpStatus;
41 import org.springframework.http.ResponseEntity;
42 import org.springframework.stereotype.Controller;
43 import org.springframework.web.bind.annotation.PostMapping;
44 import org.springframework.web.bind.annotation.RequestBody;
45 import org.springframework.web.bind.annotation.RequestMapping;
48 * Controller for handling notifications from the VNFM (Virtual Network Function Manager).
51 @RequestMapping(value = BASE_URL, produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
52 consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
53 public class Sol003LcnContoller {
54 private static Logger logger = getLogger(Sol003LcnContoller.class);
55 private static final String LOG_LCN_RECEIVED = "LCN received from VNFM: ";
56 private final AaiServiceProvider aaiServiceProvider;
57 private final AaiHelper aaiHelper;
58 private final VnfmServiceProvider vnfmServiceProvider;
59 private final ExecutorService executor = Executors.newCachedThreadPool();
62 Sol003LcnContoller(final AaiServiceProvider aaiServiceProvider, final AaiHelper aaiHelper,
63 final VnfmServiceProvider vnfmServiceProvider) {
64 this.aaiServiceProvider = aaiServiceProvider;
65 this.aaiHelper = aaiHelper;
66 this.vnfmServiceProvider = vnfmServiceProvider;
69 @PostMapping(value = "/lcn/VnfIdentifierCreationNotification")
70 public ResponseEntity<Void> lcnVnfIdentifierCreationNotificationPost(
71 @RequestBody final VnfIdentifierCreationNotification vnfIdentifierCreationNotification) {
72 logger.info(LOG_LCN_RECEIVED + vnfIdentifierCreationNotification);
73 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
76 @PostMapping(value = "/lcn/VnfIdentifierDeletionNotification")
77 public ResponseEntity<Void> lcnVnfIdentifierDeletionNotificationPost(
78 @RequestBody final VnfIdentifierDeletionNotification vnfIdentifierDeletionNotification) {
79 logger.info(LOG_LCN_RECEIVED + vnfIdentifierDeletionNotification);
80 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
83 @PostMapping(value = "/lcn/VnfLcmOperationOccurrenceNotification")
84 public ResponseEntity<Void> lcnVnfLcmOperationOccurrenceNotificationPost(
85 @RequestBody final VnfLcmOperationOccurrenceNotification vnfLcmOperationOccurrenceNotification) {
86 logger.info(LOG_LCN_RECEIVED + vnfLcmOperationOccurrenceNotification);
88 final OperationEnum operation = vnfLcmOperationOccurrenceNotification.getOperation();
89 if ((operation.equals(OperationEnum.INSTANTIATE))
90 && vnfLcmOperationOccurrenceNotification.getOperationState().equals(OperationStateEnum.COMPLETED)) {
91 final InlineResponse201 vnfInstance = getVnfInstance(vnfLcmOperationOccurrenceNotification);
92 final NotificationHandler handler = new NotificationHandler(vnfLcmOperationOccurrenceNotification,
93 aaiHelper, aaiServiceProvider, vnfInstance);
94 executor.execute(handler);
97 logger.info("Sending notification response");
98 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
101 private InlineResponse201 getVnfInstance(
102 final VnfLcmOperationOccurrenceNotification vnfLcmOperationOccurrenceNotification) {
103 return vnfmServiceProvider.getVnf(vnfLcmOperationOccurrenceNotification.getLinks().getVnfInstance().getHref())