bridgeNode

This commit is contained in:
jiangzhongxiang 2019-06-06 17:03:15 +08:00
parent f7df92af79
commit d6eb35fd87
6 changed files with 148 additions and 10 deletions

View File

@ -1,7 +1,5 @@
package com.educoder.bridge.alarm.controller;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
@ -13,6 +11,7 @@ import org.springframework.web.bind.annotation.RestController;
import com.educoder.bridge.alarm.model.Alarm;
import com.educoder.bridge.common.model.ApiResult;
import com.educoder.bridge.common.model.BridgePage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -33,10 +32,10 @@ public class AlarmController {
*/
@RequestMapping(path = "/list", method = RequestMethod.POST)
@ApiOperation(value = "获取告警列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ApiResult<List<Alarm>> getAlarms() throws Exception {
public ApiResult<BridgePage<Alarm>> getAlarms() throws Exception {
logger.info("获取告警列表");
ApiResult<List<Alarm>> result = new ApiResult<>();
ApiResult<BridgePage<Alarm>> result = new ApiResult<>();
return result;
}

View File

@ -14,8 +14,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.educoder.bridge.alarm.model.AlarmRule;
import com.educoder.bridge.alarm.model.FirePolice;
import com.educoder.bridge.alarm.service.AlarmService;
import com.educoder.bridge.common.model.ApiResult;
import com.educoder.bridge.common.model.BridgePage;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -38,13 +41,14 @@ public class AlarmRuleController {
*/
@RequestMapping(path = "/list", method = RequestMethod.POST)
@ApiOperation(value = "获取告警规则列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ApiResult<List<AlarmRule>> getAlarmRules(@RequestBody(required = false) Map<String, Object> param)
public ApiResult<BridgePage<AlarmRule>> getAlarmRules(@RequestBody(required = false) Map<String, Object> param)
throws Exception {
logger.info("获取告警规则列表");
ApiResult<List<AlarmRule>> result = new ApiResult<>();
ApiResult<BridgePage<AlarmRule>> result = new ApiResult<>();
List<AlarmRule> list = alarmService.getAlarmRules(param);
result.setData(list);
BridgePage<AlarmRule> page = new BridgePage<>((Page<AlarmRule>) list);
result.setData(page);
return result;
}

View File

@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.RestController;
import com.educoder.bridge.alarm.model.FirePolice;
import com.educoder.bridge.alarm.service.FirePoliceService;
import com.educoder.bridge.common.model.ApiResult;
import com.educoder.bridge.common.model.BridgePage;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -39,13 +41,14 @@ public class FirePoliceController {
*/
@RequestMapping(path = "/list", method = RequestMethod.POST)
@ApiOperation(value = "获取告警人员列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ApiResult<List<FirePolice>> getFirePolices(@RequestBody(required = false) Map<String, Object> param)
public ApiResult<BridgePage<FirePolice>> getFirePolices(@RequestBody(required = false) Map<String, Object> param)
throws Exception {
logger.info("获取告警人员列表");
ApiResult<List<FirePolice>> result = new ApiResult<>();
ApiResult<BridgePage<FirePolice>> result = new ApiResult<>();
List<FirePolice> list = firePoliceService.getFirePolices(param);
result.setData(list);
BridgePage<FirePolice> page = new BridgePage<>((Page<FirePolice>) list);
result.setData(page);
return result;
}

View File

@ -138,6 +138,11 @@ public class K8sService {
List<Pod> pods = client.pods().list().getItems();
return pods == null ? 0 : pods.size();
}
public List<Pod> getPods() {
List<Pod> pods = client.pods().list().getItems();
return pods == null ? Collections.emptyList() : pods;
}
/**
* 能否直接评测

View File

@ -0,0 +1,54 @@
package com.educoder.bridge.k8s.model;
import java.time.LocalDateTime;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ApiModel(value = "bridge node 信息", description = "bridge node 信息")
public class BridgeNode {
@ApiModelProperty(value = "pod name")
private String name;
@ApiModelProperty(value = "ip")
private String ip;
@ApiModelProperty(value = "创建时间")
private LocalDateTime createTime;
@ApiModelProperty(value = "pod数量")
private Integer podNum;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public void setCreateTime(LocalDateTime createTime) {
this.createTime = createTime;
}
public Integer getPodNum() {
return podNum;
}
public void setPodNum(Integer podNum) {
this.podNum = podNum;
}
}

View File

@ -0,0 +1,73 @@
package com.educoder.bridge.k8s.service;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.educoder.bridge.game.service.K8sService;
import com.educoder.bridge.k8s.model.BridgeNode;
import com.educoder.bridge.k8s.model.NodeQueryParam;
import io.fabric8.kubernetes.api.model.Node;
import io.fabric8.kubernetes.api.model.NodeAddress;
import io.fabric8.kubernetes.api.model.Pod;
@Service
public class BridgeNodeService {
// private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private K8sService k8sService;
public List<BridgeNode> getBridgePods(NodeQueryParam param) {
Map<String, List<Pod>> nodePodMap = this.getNodePods();
List<Node> nodeList = k8sService.getNodes(param);
List<BridgeNode> list = new ArrayList<>(nodeList.size());
for (Node node : nodeList) {
BridgeNode bn = new BridgeNode();
bn.setName(node.getMetadata().getName());
// ip
List<NodeAddress> addrs = node.getStatus().getAddresses();
for (NodeAddress na : addrs) {
if ("InternalIP".equals(na.getType())) {
bn.setIp(na.getAddress());
break;
}
}
// 创建时间
String createTime = node.getMetadata().getCreationTimestamp();
if (createTime.endsWith("Z")) {
createTime = createTime.substring(0, createTime.length() - 1);
}
bn.setCreateTime(LocalDateTime.parse(createTime));
// pod数量
List<Pod> podList = nodePodMap.get(bn.getIp());
bn.setPodNum(podList == null ? 0 : podList.size());
list.add(bn);
}
return list;
}
private Map<String, List<Pod>> getNodePods() {
Map<String, List<Pod>> map = new HashMap<>();
List<Pod> list = k8sService.getPods();
for (Pod pod : list) {
String hostIp = pod.getStatus().getHostIP();
List<Pod> podList = map.get(hostIp);
if (podList == null) {
podList = new ArrayList<>();
map.put(hostIp, podList);
}
podList.add(pod);
}
return map;
}
}