package cn.reghao.tnb.sb.zk.controller;

import cn.reghao.tnb.sb.zk.cluster.Node;
import cn.reghao.tnb.sb.zk.model.po.NodeInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author reghao
 * @date 2023-04-03 14:18:38
 */
@RestController
@RequestMapping("/zk/api/cluster")
public class ClusterController {
    private final Node node;

    public ClusterController(Node node) {
        this.node = node;
    }

    @GetMapping("/leader")
    public String getLeader() throws Exception {
        String leader = node.getLeader();
        return leader;
    }

    @GetMapping("/nodes")
    public List<NodeInfo> allNodes() throws Exception {
        return node.getAllNodes();
    }
}
