2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright 2019 China Mobile
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=========================================================
20 package org.onap.datalake.feeder.controller;
22 import java.io.IOException;
24 import org.onap.datalake.feeder.config.ApplicationConfiguration;
25 import org.onap.datalake.feeder.service.PullService;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.http.MediaType;
30 import org.springframework.web.bind.annotation.*;
32 import io.swagger.annotations.ApiOperation;
35 * This controller controls DL data feeder.
42 @RequestMapping(value = "/feeder", produces = { MediaType.APPLICATION_JSON_VALUE })
43 public class FeederController {
45 private final Logger log = LoggerFactory.getLogger(this.getClass());
48 private PullService pullService;
51 ApplicationConfiguration config;
54 * @return message that application is started
57 @PostMapping("/start")
59 @ApiOperation(value="Start pulling data.")
60 public String start() throws IOException {
61 log.info("Going to start DataLake feeder ...");
62 if(pullService.isRunning() == false) {
64 log.info("DataLake feeder started.");
66 log.info("DataLake feeder already started.");
68 return "{\"running\": true}";
72 * @return message that application stop process is triggered
76 @ApiOperation(value="Stop pulling data.")
77 public String stop() {
78 log.info("Going to stop DataLake feeder ...");
79 if(pullService.isRunning() == true)
81 pullService.shutdown();
82 log.info("DataLake feeder is stopped.");
84 log.info("DataLake feeder already stopped.");
86 return "{\"running\": false}";
89 * @return feeder status
91 @GetMapping("/status")
92 @ApiOperation(value="Retrieve feeder status.")
93 public String status() {
94 String status = "Feeder is running: "+pullService.isRunning();
95 log.info("sending feeder status ...");//TODO we can send what topics are monitored, how many messages are sent, etc.
97 return "{\"version\": \""+config.getDatalakeVersion()+"\", \"running\": "+pullService.isRunning()+"}";