6a44c4f2a5f01410a99673ef11b9bb1422d04ff7
[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.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.*;
31
32 import io.swagger.annotations.ApiOperation;
33
34 /**
35  * This controller controls DL data feeder.
36  * 
37  * @author Guobiao Mo
38  *
39  */
40
41 @RestController
42 @RequestMapping(value = "/feeder", produces = { MediaType.APPLICATION_JSON_VALUE })
43 public class FeederController {
44
45         private final Logger log = LoggerFactory.getLogger(this.getClass());
46         
47     @Autowired
48     private PullService pullService;
49
50     @Autowired
51     ApplicationConfiguration config;
52     
53     /**
54      * @return message that application is started
55      * @throws IOException 
56      */
57     @PostMapping("/start")
58     @ResponseBody
59         @ApiOperation(value="Start pulling data.")
60     public String start() throws IOException {
61         log.info("DataLake feeder starting to pull data from DMaaP...");
62         if(pullService.isRunning() == false) {
63             pullService.start();
64         }
65         return "{\"running\": true}";
66     }
67
68     /**
69      * @return message that application stop process is triggered
70      */
71     @PostMapping("/stop")
72     @ResponseBody
73         @ApiOperation(value="Stop pulling data.")
74     public String stop() {
75         if(pullService.isRunning() == true)
76         {
77             pullService.shutdown();
78         }
79         log.info("DataLake feeder is stopped.");
80         return "{\"running\": false}";
81     }
82     /**
83      * @return feeder status
84      */
85     @GetMapping("/status")
86         @ApiOperation(value="Retrieve feeder status.")
87     public String status() {            
88         String status = "Feeder is running: "+pullService.isRunning();
89         log.info("sending feeder status ...");//TODO we can send what topics are monitored, how many messages are sent, etc.
90
91         return "{\"version\": \""+config.getDatalakeVersion()+"\", \"running\": "+pullService.isRunning()+"}";
92     }
93 }