2 * ============LICENSE_START=======================================================
3 * BBS-RELOCATION-CPE-AUTHENTICATION-HANDLER
4 * ================================================================================
5 * Copyright (C) 2019 NOKIA 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.bbs.event.processor.controllers;
23 import io.swagger.annotations.Api;
24 import io.swagger.annotations.ApiOperation;
25 import io.swagger.annotations.ApiResponse;
26 import io.swagger.annotations.ApiResponses;
28 import java.util.concurrent.Executors;
30 import org.onap.bbs.event.processor.pipelines.CpeAuthenticationPipeline;
31 import org.onap.bbs.event.processor.pipelines.ReRegistrationPipeline;
32 import org.onap.bbs.event.processor.pipelines.Scheduler;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.http.HttpStatus;
37 import org.springframework.http.ResponseEntity;
38 import org.springframework.web.bind.annotation.GetMapping;
39 import org.springframework.web.bind.annotation.PostMapping;
40 import org.springframework.web.bind.annotation.RestController;
42 import reactor.core.publisher.Mono;
45 @Api(value = "BbsEventProcessorController", description = "Manage bbs-event-processor microService")
46 public class BbsEventProcessorController {
48 private ReRegistrationPipeline reRegistrationPipeline;
49 private CpeAuthenticationPipeline cpeAuthenticationPipeline;
50 private Scheduler scheduler;
53 * Constructs BBE event processor REST controller.
54 * @param reRegistrationPipeline processing pipeline for polling DMaaP for PNF re-registration events
55 * @param cpeAuthenticationPipeline processing pipeline for polling DMaaP for CPE authentication events
56 * @param scheduler application scheduler
59 public BbsEventProcessorController(ReRegistrationPipeline reRegistrationPipeline,
60 CpeAuthenticationPipeline cpeAuthenticationPipeline,
61 Scheduler scheduler) {
62 this.reRegistrationPipeline = reRegistrationPipeline;
63 this.cpeAuthenticationPipeline = cpeAuthenticationPipeline;
64 this.scheduler = scheduler;
67 private static final Logger LOGGER = LoggerFactory.getLogger(BbsEventProcessorController.class);
70 * Responds to health-check heartbeats.
71 * @return Proper HTTP response based on application health
73 @GetMapping("heartbeat")
74 @ApiOperation(value = "Returns liveness of bbs-event-processor microService")
75 @ApiResponses(value = {
76 @ApiResponse(code = 200, message = "bbs-event-processor microService is alive"),
77 @ApiResponse(code = 401, message = "Not authorized to view the resource"),
78 @ApiResponse(code = 403, message = "Resource access is forbidden"),
79 @ApiResponse(code = 404, message = "Resource is not found")})
80 public Mono<ResponseEntity<String>> handleHeartBeat() {
81 LOGGER.debug("bbs-event-processor has received a heartbeat request");
82 return Mono.defer(() ->
83 Mono.just(new ResponseEntity<>("bbs-event-processor is alive\n", HttpStatus.OK))
88 * Polls DMaaP for PNF re-registration events just once.
89 * @return Proper HTTP response based on request submission result
91 @PostMapping("poll-reregistration-events")
92 @ApiOperation(value = "Returns result of request submission. PNF re-registration polling will occur asynchronously")
93 @ApiResponses(value = {
94 @ApiResponse(code = 200, message = "Polling Re-registration events task submitted successfully"),
95 @ApiResponse(code = 401, message = "Not authorized to view the resource"),
96 @ApiResponse(code = 403, message = "Resource access is forbidden"),
97 @ApiResponse(code = 404, message = "Resource is not found")})
98 public Mono<ResponseEntity<String>> handleReRegistrationRestCall() {
99 LOGGER.debug("bbs-event-processor has received a re-registration handling request");
100 Executors.newSingleThreadExecutor().submit(() -> reRegistrationPipeline.processPnfReRegistrationEvents());
101 return Mono.defer(() ->
102 Mono.just(new ResponseEntity<>("Request submitted\n", HttpStatus.OK))
107 * Polls DMaaP for CPE authentication events just once.
108 * @return Proper HTTP response based on request submission result
110 @PostMapping("poll-cpe-authentication-events")
111 @ApiOperation(value = "Returns result of request submission. CPE authentication polling will occur asynchronously")
112 @ApiResponses(value = {
113 @ApiResponse(code = 200, message = "CPE authentication task submitted successfully"),
114 @ApiResponse(code = 401, message = "Not authorized to view the resource"),
115 @ApiResponse(code = 403, message = "Resource access is forbidden"),
116 @ApiResponse(code = 404, message = "Resource is not found")})
117 public Mono<ResponseEntity<String>> handleCpeAuthenticationRestCall() {
118 LOGGER.debug("bbs-event-processor has received a cpe-authentication handling request");
119 Executors.newSingleThreadExecutor().submit(() -> cpeAuthenticationPipeline.processPnfCpeAuthenticationEvents());
120 return Mono.defer(() ->
121 Mono.just(new ResponseEntity<>("Request submitted\n", HttpStatus.OK))
126 * Reschedules DMaaP polling tasks.
127 * @return Proper HTTP response based on rescheduling result
129 @PostMapping("start-tasks")
130 @ApiOperation(value = "Returns result of request to start microservice tasks")
131 @ApiResponses(value = {
132 @ApiResponse(code = 200, message = "Tasks were successfully started"),
133 @ApiResponse(code = 401, message = "Not authorized to view the resource"),
134 @ApiResponse(code = 403, message = "Resource access is forbidden"),
135 @ApiResponse(code = 404, message = "Resource is not found"),
136 @ApiResponse(code = 406, message = "Task initiation failed. Check logs")})
137 public Mono<ResponseEntity<String>> reScheduleTasks() {
138 LOGGER.trace("bbs-event-processor has received a request to reschedule all running tasks");
139 if (scheduler.reScheduleProcessingTasks()) {
140 return Mono.defer(() ->
141 Mono.just(new ResponseEntity<>("Initiation of tasks was successful\n", HttpStatus.OK))
144 return Mono.defer(() ->
145 Mono.just(new ResponseEntity<>("Initiation of tasks failed\n", HttpStatus.NOT_ACCEPTABLE))
151 * Cancels DMaaP polling tasks.
152 * @return Proper HTTP response based on cancellation result
154 @PostMapping("cancel-tasks")
155 @ApiOperation(value = "Returns result of request to cancel running microservice tasks")
156 @ApiResponses(value = {
157 @ApiResponse(code = 200, message = "Tasks were successfully cancelled"),
158 @ApiResponse(code = 401, message = "Not authorized to view the resource"),
159 @ApiResponse(code = 403, message = "Resource access is forbidden"),
160 @ApiResponse(code = 404, message = "Resource is not found"),
161 @ApiResponse(code = 406, message = "Cancellation failed. Check logs")})
162 public Mono<ResponseEntity<String>> cancelTasks() {
163 LOGGER.debug("bbs-event-processor has received a request to cancel all running tasks");
164 if (scheduler.cancelScheduledProcessingTasks()) {
165 return Mono.defer(() ->
166 Mono.just(new ResponseEntity<>("Cancellation was successful\n", HttpStatus.OK))
169 return Mono.defer(() ->
170 Mono.just(new ResponseEntity<>("Cancellation failed\n", HttpStatus.NOT_ACCEPTABLE))