GatewayHeartbeatController.java 2.2 KB
Newer Older
Z
zengqiao 已提交
1 2 3 4 5
package com.xiaojukeji.kafka.manager.web.api.versionone.gateway;

import com.alibaba.fastjson.JSON;
import com.xiaojukeji.kafka.manager.common.annotations.ApiLevel;
import com.xiaojukeji.kafka.manager.common.constant.ApiLevelContent;
Z
zengqiao 已提交
6
import com.xiaojukeji.kafka.manager.common.entity.Result;
Z
zengqiao 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
import com.xiaojukeji.kafka.manager.common.entity.dto.gateway.TopicConnectionDTO;
import com.xiaojukeji.kafka.manager.common.utils.ValidateUtils;
import com.xiaojukeji.kafka.manager.service.service.gateway.TopicConnectionService;
import com.xiaojukeji.kafka.manager.common.constant.ApiPrefix;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zengqiao
 * @date 20/7/6
 */
@Api(tags = "GATEWAY-WEB相关接口(REST)")
@RestController
@RequestMapping(ApiPrefix.GATEWAY_API_V1_PREFIX)
public class GatewayHeartbeatController {
    private final static Logger LOGGER = LoggerFactory.getLogger(GatewayHeartbeatController.class);

    @Autowired
    private TopicConnectionService topicConnectionService;

    @ApiLevel(level = ApiLevelContent.LEVEL_NORMAL_3)
    @ApiOperation(value = "连接信息上报入口", notes = "Broker主动上报信息")
    @RequestMapping(value = "heartbeat/survive-user", method = RequestMethod.POST)
    @ResponseBody
Z
zengqiao 已提交
37 38 39
    public Result receiveTopicConnections(@RequestParam("clusterId") String clusterId,
                                          @RequestParam("brokerId") String brokerId,
                                          @RequestBody List<TopicConnectionDTO> dtoList) {
Z
zengqiao 已提交
40 41
        try {
            if (ValidateUtils.isEmptyList(dtoList)) {
Z
zengqiao 已提交
42
                return Result.buildSuc();
Z
zengqiao 已提交
43 44
            }
            topicConnectionService.batchAdd(dtoList);
Z
zengqiao 已提交
45
            return Result.buildSuc();
Z
zengqiao 已提交
46 47 48 49
        } catch (Exception e) {
            LOGGER.error("receive topic connections failed, clusterId:{} brokerId:{} req:{}",
                    clusterId, brokerId, JSON.toJSONString(dtoList), e);
        }
Z
zengqiao 已提交
50
        return Result.buildFailure("fail");
Z
zengqiao 已提交
51 52
    }
}