mirror of
https://github.com/didi/KnowStreaming.git
synced 2026-01-03 11:28:12 +08:00
[Feature] 集群Group列表按照Group维度进行展示 (#580)
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.xiaojukeji.know.streaming.km.common.bean.dto.cluster;
|
||||
|
||||
import com.xiaojukeji.know.streaming.km.common.bean.dto.pagination.PaginationBaseDTO;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author wyb
|
||||
* @date 2022/10/17
|
||||
*/
|
||||
@Data
|
||||
public class ClusterGroupSummaryDTO extends PaginationBaseDTO {
|
||||
@ApiModelProperty("查找该Topic")
|
||||
private String searchTopicName;
|
||||
|
||||
@ApiModelProperty("查找该Group")
|
||||
private String searchGroupName;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.xiaojukeji.know.streaming.km.common.bean.entity.group;
|
||||
|
||||
import com.xiaojukeji.know.streaming.km.common.constant.Constant;
|
||||
import com.xiaojukeji.know.streaming.km.common.enums.group.GroupStateEnum;
|
||||
import com.xiaojukeji.know.streaming.km.common.enums.group.GroupTypeEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.kafka.clients.admin.ConsumerGroupDescription;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author wyb
|
||||
* @date 2022/10/10
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Group {
|
||||
/**
|
||||
* 集群id
|
||||
*/
|
||||
private Long clusterPhyId;
|
||||
|
||||
/**
|
||||
* group类型
|
||||
* @see GroupTypeEnum
|
||||
*/
|
||||
private GroupTypeEnum type;
|
||||
|
||||
/**
|
||||
* group名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* group状态
|
||||
* @see GroupStateEnum
|
||||
*/
|
||||
private GroupStateEnum state;
|
||||
|
||||
/**
|
||||
* group成员数量
|
||||
*/
|
||||
private Integer memberCount;
|
||||
|
||||
/**
|
||||
* group消费的topic列表
|
||||
*/
|
||||
private List<GroupTopicMember> topicMembers;
|
||||
|
||||
/**
|
||||
* group分配策略
|
||||
*/
|
||||
private String partitionAssignor;
|
||||
|
||||
/**
|
||||
* group协调器brokerId
|
||||
*/
|
||||
private int coordinatorId;
|
||||
|
||||
public Group(Long clusterPhyId, String groupName, ConsumerGroupDescription groupDescription) {
|
||||
this.clusterPhyId = clusterPhyId;
|
||||
this.type = groupDescription.isSimpleConsumerGroup()? GroupTypeEnum.CONSUMER: GroupTypeEnum.CONNECTOR;
|
||||
this.name = groupName;
|
||||
this.state = GroupStateEnum.getByRawState(groupDescription.state());
|
||||
this.memberCount = groupDescription.members() == null? 0: groupDescription.members().size();
|
||||
this.topicMembers = new ArrayList<>();
|
||||
this.partitionAssignor = groupDescription.partitionAssignor();
|
||||
this.coordinatorId = groupDescription.coordinator() == null? Constant.INVALID_CODE: groupDescription.coordinator().id();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.xiaojukeji.know.streaming.km.common.bean.entity.group;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author wyb
|
||||
* @date 2022/10/10
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class GroupTopicMember {
|
||||
/**
|
||||
* Topic名称
|
||||
*/
|
||||
private String topicName;
|
||||
|
||||
/**
|
||||
* 消费此Topic的成员数量
|
||||
*/
|
||||
private Integer memberCount;
|
||||
|
||||
public GroupTopicMember(String topicName, Integer memberCount) {
|
||||
this.topicName = topicName;
|
||||
this.memberCount = memberCount;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package com.xiaojukeji.know.streaming.km.common.bean.po.group;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.xiaojukeji.know.streaming.km.common.bean.po.BasePO;
|
||||
import com.xiaojukeji.know.streaming.km.common.constant.Constant;
|
||||
import com.xiaojukeji.know.streaming.km.common.enums.group.GroupStateEnum;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@@ -23,12 +22,19 @@ public class GroupMemberPO extends BasePO {
|
||||
|
||||
private Integer memberCount;
|
||||
|
||||
public GroupMemberPO(Long clusterPhyId, String topicName, String groupName, Date updateTime) {
|
||||
public GroupMemberPO(Long clusterPhyId, String topicName, String groupName, String state, Integer memberCount) {
|
||||
this.clusterPhyId = clusterPhyId;
|
||||
this.topicName = topicName;
|
||||
this.groupName = groupName;
|
||||
this.state = GroupStateEnum.UNKNOWN.getState();
|
||||
this.memberCount = 0;
|
||||
this.state = state;
|
||||
this.memberCount = memberCount;
|
||||
}
|
||||
public GroupMemberPO(Long clusterPhyId, String topicName, String groupName, String state, Integer memberCount, Date updateTime) {
|
||||
this.clusterPhyId = clusterPhyId;
|
||||
this.topicName = topicName;
|
||||
this.groupName = groupName;
|
||||
this.state = state;
|
||||
this.memberCount = memberCount;
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.xiaojukeji.know.streaming.km.common.bean.po.group;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.xiaojukeji.know.streaming.km.common.bean.po.BasePO;
|
||||
import com.xiaojukeji.know.streaming.km.common.constant.Constant;
|
||||
import com.xiaojukeji.know.streaming.km.common.enums.group.GroupStateEnum;
|
||||
import com.xiaojukeji.know.streaming.km.common.enums.group.GroupTypeEnum;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@TableName(Constant.MYSQL_TABLE_NAME_PREFIX + "group")
|
||||
public class GroupPO extends BasePO {
|
||||
/**
|
||||
* 集群id
|
||||
*/
|
||||
private Long clusterPhyId;
|
||||
|
||||
/**
|
||||
* group类型
|
||||
*
|
||||
* @see GroupTypeEnum
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* group名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* group状态
|
||||
*
|
||||
* @see GroupStateEnum
|
||||
*/
|
||||
private String state;
|
||||
|
||||
/**
|
||||
* group成员数量
|
||||
*/
|
||||
private Integer memberCount;
|
||||
|
||||
/**
|
||||
* group消费的topic列表
|
||||
*/
|
||||
private String topicMembers;
|
||||
|
||||
/**
|
||||
* group分配策略
|
||||
*/
|
||||
private String partitionAssignor;
|
||||
|
||||
/**
|
||||
* group协调器brokerId
|
||||
*/
|
||||
private int coordinatorId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.xiaojukeji.know.streaming.km.common.bean.vo.group;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author wyb
|
||||
* @date 2022/10/9
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(value = "Group信息")
|
||||
public class GroupOverviewVO {
|
||||
@ApiModelProperty(value = "Group名称", example = "group-know-streaming-test")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "Group状态", example = "Empty")
|
||||
private String state;
|
||||
|
||||
@ApiModelProperty(value = "group的成员数", example = "12")
|
||||
private Integer memberCount;
|
||||
|
||||
@ApiModelProperty(value = "Topic列表", example = "[topic1,topic2]")
|
||||
private List<String> topicNameList;
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(value = "GroupTopic信息")
|
||||
public class GroupTopicOverviewVO extends GroupTopicBasicVO{
|
||||
public class GroupTopicOverviewVO extends GroupTopicBasicVO {
|
||||
@ApiModelProperty(value = "最大Lag", example = "12345678")
|
||||
private Long maxLag;
|
||||
}
|
||||
|
||||
@@ -18,4 +18,14 @@ public class PaginationConstant {
|
||||
* 默认页大小
|
||||
*/
|
||||
public static final Integer DEFAULT_PAGE_SIZE = 10;
|
||||
|
||||
/**
|
||||
* group列表的默认排序规则
|
||||
*/
|
||||
public static final String DEFAULT_GROUP_SORTED_FIELD = "name";
|
||||
|
||||
/**
|
||||
* groupTopic列表的默认排序规则
|
||||
*/
|
||||
public static final String DEFAULT_GROUP_TOPIC_SORTED_FIELD = "topicName";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.xiaojukeji.know.streaming.km.common.converter;
|
||||
|
||||
import com.xiaojukeji.know.streaming.km.common.bean.entity.group.Group;
|
||||
import com.xiaojukeji.know.streaming.km.common.bean.entity.group.GroupTopicMember;
|
||||
import com.xiaojukeji.know.streaming.km.common.bean.po.group.GroupPO;
|
||||
import com.xiaojukeji.know.streaming.km.common.bean.vo.group.GroupOverviewVO;
|
||||
import com.xiaojukeji.know.streaming.km.common.enums.group.GroupStateEnum;
|
||||
import com.xiaojukeji.know.streaming.km.common.enums.group.GroupTypeEnum;
|
||||
import com.xiaojukeji.know.streaming.km.common.utils.ConvertUtil;
|
||||
import com.xiaojukeji.know.streaming.km.common.utils.ValidateUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author wyb
|
||||
* @date 2022/10/10
|
||||
*/
|
||||
public class GroupConverter {
|
||||
|
||||
private GroupConverter() {
|
||||
|
||||
}
|
||||
|
||||
public static GroupOverviewVO convert2GroupOverviewVO(Group group) {
|
||||
GroupOverviewVO vo = ConvertUtil.obj2Obj(group, GroupOverviewVO.class);
|
||||
|
||||
vo.setState(group.getState().getState());
|
||||
vo.setTopicNameList(group.getTopicMembers().stream().map(elem -> elem.getTopicName()).collect(Collectors.toList()));
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
public static Group convert2Group(GroupPO po) {
|
||||
if (po == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Group group = ConvertUtil.obj2Obj(po, Group.class);
|
||||
if (!ValidateUtils.isBlank(po.getTopicMembers())) {
|
||||
group.setTopicMembers(ConvertUtil.str2ObjArrayByJson(po.getTopicMembers(), GroupTopicMember.class));
|
||||
} else {
|
||||
group.setTopicMembers(new ArrayList<>());
|
||||
}
|
||||
|
||||
group.setType(GroupTypeEnum.getTypeByCode(po.getType()));
|
||||
group.setState(GroupStateEnum.getByState(po.getState()));
|
||||
return group;
|
||||
}
|
||||
|
||||
public static GroupPO convert2GroupPO(Group group) {
|
||||
if (group == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
GroupPO po = ConvertUtil.obj2Obj(group, GroupPO.class);
|
||||
po.setTopicMembers(ConvertUtil.obj2Json(group.getTopicMembers()));
|
||||
po.setType(group.getType().getCode());
|
||||
po.setState(group.getState().getState());
|
||||
return po;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.xiaojukeji.know.streaming.km.common.enums.group;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author wyb
|
||||
* @date 2022/10/11
|
||||
*/
|
||||
@Getter
|
||||
public enum GroupTypeEnum {
|
||||
|
||||
UNKNOWN(-1, "Unknown"),
|
||||
|
||||
CONSUMER(0, "Consumer客户端的消费组"),
|
||||
|
||||
CONNECTOR(1, "Connector的消费组");
|
||||
|
||||
private final Integer code;
|
||||
|
||||
private final String msg;
|
||||
|
||||
GroupTypeEnum(Integer code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public static GroupTypeEnum getTypeByCode(Integer code) {
|
||||
if (code == null) return UNKNOWN;
|
||||
for (GroupTypeEnum groupTypeEnum : GroupTypeEnum.values()) {
|
||||
if (groupTypeEnum.code.equals(code)) {
|
||||
return groupTypeEnum;
|
||||
}
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user