3d296d5fbd0417c7f19366264053ec43c22b65e4
[dcaegen2/services.git] /
1 /*
2 * ============LICENSE_START=======================================================
3 * ONAP : DataLake
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
10 *
11 *     http://www.apache.org/licenses/LICENSE-2.0
12 *
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=========================================================
19 */
20 package org.onap.datalake.feeder.controller;
21
22 import java.io.IOException;
23
24 import org.onap.datalake.feeder.service.PullService;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.http.MediaType;
29 import org.springframework.web.bind.annotation.GetMapping;
30 import org.springframework.web.bind.annotation.RequestMapping;
31 import org.springframework.web.bind.annotation.RestController;
32
33 import io.swagger.annotations.ApiOperation;
34
35 /**
36  * This controller controls DL data feeder.
37  * 
38  * @author Guobiao Mo
39  *
40  */
41
42 @RestController
43 @RequestMapping(value = "/feeder", produces = { MediaType.TEXT_PLAIN_VALUE })
44 public class FeederController {
45
46         private final Logger log = LoggerFactory.getLogger(this.getClass());
47         
48     @Autowired
49     private PullService pullService;
50     
51     /**
52      * @return message that application is started
53      * @throws IOException 
54      */
55     @GetMapping("/start")
56         @ApiOperation(value="Start pulling data.")
57     public String start() throws IOException {
58         log.info("DataLake feeder starting to pull data from DMaaP...");
59         pullService.start();
60         return "DataLake feeder is running.";
61     }
62
63     /**
64      * @return message that application stop process is triggered
65      */
66     @GetMapping("/stop")
67         @ApiOperation(value="Stop pulling data.")
68     public String stop() {      
69         pullService.shutdown();
70         log.info("DataLake feeder is stopped.");
71         return "DataLake feeder is stopped.";
72     }
73     /**
74      * @return feeder status
75      */
76     @GetMapping("/status")
77         @ApiOperation(value="Retrieve feeder status.")
78     public String status() {            
79         String status = "Feeder is running: "+pullService.isRunning();
80         log.info("senting feeder status ...");//TODO we can send what topics are monitored, how many messages are sent, etc. 
81         return status;
82     }    
83 }