正在显示
9 个修改的文件
包含
275 行增加
和
5 行删除
| @@ -41,8 +41,7 @@ public class CascadeController { | @@ -41,8 +41,7 @@ public class CascadeController { | ||
| 41 | @GetMapping("/server") | 41 | @GetMapping("/server") |
| 42 | public ResultJson getServerList() | 42 | public ResultJson getServerList() |
| 43 | { | 43 | { |
| 44 | - | ||
| 45 | - List<BusServer> busServers = busServerService.getServerList(); | 44 | + List<BusServer> busServers = busServerService.selectServerList(); |
| 46 | return busServers.size() > 0 | 45 | return busServers.size() > 0 |
| 47 | ? new ResultJson<>("200", "查询服务器列表,成功", busServers) | 46 | ? new ResultJson<>("200", "查询服务器列表,成功", busServers) |
| 48 | : new ResultJson<>("500", "查询服务器列表,失败"); | 47 | : new ResultJson<>("500", "查询服务器列表,失败"); |
| @@ -127,7 +126,7 @@ public class CascadeController { | @@ -127,7 +126,7 @@ public class CascadeController { | ||
| 127 | @GetMapping("/server_host") | 126 | @GetMapping("/server_host") |
| 128 | public ResultJson getServerAndHostList(@RequestParam(value = "serverName", required = false) String serverName) | 127 | public ResultJson getServerAndHostList(@RequestParam(value = "serverName", required = false) String serverName) |
| 129 | { | 128 | { |
| 130 | - BusServer busServer=BusServer.builder().serverName(serverName) | 129 | + BusServer busServer = BusServer.builder().serverName(serverName) |
| 131 | .build(); | 130 | .build(); |
| 132 | List<BusServer> servers = busServerService.getServerAndHostList(busServer); | 131 | List<BusServer> servers = busServerService.getServerAndHostList(busServer); |
| 133 | return servers.size() > 0 | 132 | return servers.size() > 0 |
src/main/java/com/sunyo/wlpt/message/bus/service/controller/view/ViewQueueController.java
0 → 100644
| 1 | +package com.sunyo.wlpt.message.bus.service.controller.view; | ||
| 2 | + | ||
| 3 | +import com.sunyo.wlpt.message.bus.service.response.ResultJson; | ||
| 4 | +import com.sunyo.wlpt.message.bus.service.service.view.ViewQueueFactory; | ||
| 5 | +import org.springframework.web.bind.annotation.*; | ||
| 6 | + | ||
| 7 | +import javax.annotation.Resource; | ||
| 8 | +import java.io.IOException; | ||
| 9 | +import java.net.URISyntaxException; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * @author 子诚 | ||
| 13 | + * Description: | ||
| 14 | + * 时间:2020/8/26 11:07 | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +@CrossOrigin | ||
| 18 | +@RequestMapping("bus/view/queue") | ||
| 19 | +@RestController | ||
| 20 | +public class ViewQueueController { | ||
| 21 | + | ||
| 22 | + @Resource | ||
| 23 | + private ViewQueueFactory viewQueueFactory; | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * @param serverName 服务器名称 | ||
| 27 | + * @param virtualHostName 虚拟主机名称 | ||
| 28 | + * @param pageNum 当前页数 | ||
| 29 | + * @param pageSize 每页数量 | ||
| 30 | + * @return | ||
| 31 | + */ | ||
| 32 | + @GetMapping("/list") | ||
| 33 | + public ResultJson getViewQueueList( | ||
| 34 | + @RequestParam(value = "serverName", required = false) String serverName, | ||
| 35 | + @RequestParam(value = "virtualHostName", required = false) String virtualHostName, | ||
| 36 | + @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, | ||
| 37 | + @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize | ||
| 38 | + ) | ||
| 39 | + { | ||
| 40 | + try { | ||
| 41 | + return viewQueueFactory.getViewQueueList(serverName, virtualHostName, pageNum, pageSize); | ||
| 42 | + } catch (IOException | URISyntaxException e) { | ||
| 43 | + return new ResultJson<>("500", "服务器异常,查询队列监控,失败!请联系管理员"); | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | +} |
| @@ -78,6 +78,13 @@ public interface BusServerMapper { | @@ -78,6 +78,13 @@ public interface BusServerMapper { | ||
| 78 | List<BusServer> selectBusServerList(BusServer busServer); | 78 | List<BusServer> selectBusServerList(BusServer busServer); |
| 79 | 79 | ||
| 80 | /** | 80 | /** |
| 81 | + * 查询服务器列表(不包含密码) | ||
| 82 | + * | ||
| 83 | + * @return 服务器列表 | ||
| 84 | + */ | ||
| 85 | + List<BusServer> selectServerList(); | ||
| 86 | + | ||
| 87 | + /** | ||
| 81 | * 先校验该服务器名称是否存在 | 88 | * 先校验该服务器名称是否存在 |
| 82 | * | 89 | * |
| 83 | * @param busServer {@link BusServer} | 90 | * @param busServer {@link BusServer} |
| @@ -86,6 +93,14 @@ public interface BusServerMapper { | @@ -86,6 +93,14 @@ public interface BusServerMapper { | ||
| 86 | List<BusServer> validateServerName(BusServer busServer); | 93 | List<BusServer> validateServerName(BusServer busServer); |
| 87 | 94 | ||
| 88 | /** | 95 | /** |
| 96 | + * 校验该服务器名称是否存在 | ||
| 97 | + * | ||
| 98 | + * @param serverName 服务器名称 | ||
| 99 | + * @return | ||
| 100 | + */ | ||
| 101 | + List<BusServer> validateByServerName(@Param("serverName") String serverName); | ||
| 102 | + | ||
| 103 | + /** | ||
| 89 | * 校验该服务器信息是否存在 | 104 | * 校验该服务器信息是否存在 |
| 90 | * | 105 | * |
| 91 | * @param busServer {@link BusServer} | 106 | * @param busServer {@link BusServer} |
| @@ -94,7 +109,7 @@ public interface BusServerMapper { | @@ -94,7 +109,7 @@ public interface BusServerMapper { | ||
| 94 | List<BusServer> validateBusServer(BusServer busServer); | 109 | List<BusServer> validateBusServer(BusServer busServer); |
| 95 | 110 | ||
| 96 | /** | 111 | /** |
| 97 | - * 查询服务器列表 | 112 | + * 查询服务器列表(包含密码) |
| 98 | * | 113 | * |
| 99 | * @return 服务器列表 | 114 | * @return 服务器列表 |
| 100 | */ | 115 | */ |
| 1 | package com.sunyo.wlpt.message.bus.service.rabbit.utils; | 1 | package com.sunyo.wlpt.message.bus.service.rabbit.utils; |
| 2 | 2 | ||
| 3 | import com.rabbitmq.http.client.Client; | 3 | import com.rabbitmq.http.client.Client; |
| 4 | +import com.rabbitmq.http.client.domain.QueueInfo; | ||
| 4 | import com.rabbitmq.http.client.domain.UserPermissions; | 5 | import com.rabbitmq.http.client.domain.UserPermissions; |
| 5 | import com.sunyo.wlpt.message.bus.service.domain.BusServer; | 6 | import com.sunyo.wlpt.message.bus.service.domain.BusServer; |
| 6 | import com.sunyo.wlpt.message.bus.service.domain.UserInfo; | 7 | import com.sunyo.wlpt.message.bus.service.domain.UserInfo; |
| @@ -10,6 +11,7 @@ import com.sunyo.wlpt.message.bus.service.utils.AESUtils; | @@ -10,6 +11,7 @@ import com.sunyo.wlpt.message.bus.service.utils.AESUtils; | ||
| 10 | import java.io.IOException; | 11 | import java.io.IOException; |
| 11 | import java.net.URISyntaxException; | 12 | import java.net.URISyntaxException; |
| 12 | import java.util.ArrayList; | 13 | import java.util.ArrayList; |
| 14 | +import java.util.List; | ||
| 13 | 15 | ||
| 14 | /** | 16 | /** |
| 15 | * @author 子诚 | 17 | * @author 子诚 |
| @@ -148,4 +150,52 @@ public class ClientUtils { | @@ -148,4 +150,52 @@ public class ClientUtils { | ||
| 148 | client.clearPermissions(vHost, username); | 150 | client.clearPermissions(vHost, username); |
| 149 | client.clearTopicPermissions(vHost, username); | 151 | client.clearTopicPermissions(vHost, username); |
| 150 | } | 152 | } |
| 153 | + | ||
| 154 | + /** | ||
| 155 | + * 获取MQ界面的队列信息,重载 | ||
| 156 | + * | ||
| 157 | + * @param busServer | ||
| 158 | + * @return | ||
| 159 | + * @throws IOException | ||
| 160 | + * @throws URISyntaxException | ||
| 161 | + */ | ||
| 162 | + public static List<QueueInfo> getViewQueues(BusServer busServer) throws IOException, URISyntaxException | ||
| 163 | + { | ||
| 164 | + Client client = connectClient(busServer); | ||
| 165 | + List<QueueInfo> queues = client.getQueues(); | ||
| 166 | + return queues; | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + /** | ||
| 170 | + * 获取MQ界面的队列信息,重载 | ||
| 171 | + * | ||
| 172 | + * @param busServer | ||
| 173 | + * @param vHostName | ||
| 174 | + * @return | ||
| 175 | + * @throws IOException | ||
| 176 | + * @throws URISyntaxException | ||
| 177 | + */ | ||
| 178 | + public static List<QueueInfo> getViewQueues(BusServer busServer, String vHostName) throws IOException, URISyntaxException | ||
| 179 | + { | ||
| 180 | + Client client = connectClient(busServer); | ||
| 181 | + List<QueueInfo> queues = client.getQueues(vHostName); | ||
| 182 | + return queues; | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + /** | ||
| 186 | + * 获取MQ界面的队列信息,重载 | ||
| 187 | + * | ||
| 188 | + * @param busServer MQ服务器信息 | ||
| 189 | + * @param vHostName 虚拟主机 | ||
| 190 | + * @param queueName 队列名称 | ||
| 191 | + * @return | ||
| 192 | + * @throws IOException | ||
| 193 | + * @throws URISyntaxException | ||
| 194 | + */ | ||
| 195 | + public QueueInfo getViewQueues(BusServer busServer, String vHostName, String queueName) throws IOException, URISyntaxException | ||
| 196 | + { | ||
| 197 | + Client client = connectClient(busServer); | ||
| 198 | + QueueInfo queue = client.getQueue(vHostName, queueName); | ||
| 199 | + return queue; | ||
| 200 | + } | ||
| 151 | } | 201 | } |
| @@ -32,6 +32,11 @@ public class ResultJson<T> implements Serializable { | @@ -32,6 +32,11 @@ public class ResultJson<T> implements Serializable { | ||
| 32 | private String error; | 32 | private String error; |
| 33 | 33 | ||
| 34 | /** | 34 | /** |
| 35 | + * 数据总条数 | ||
| 36 | + */ | ||
| 37 | + private Integer total; | ||
| 38 | + | ||
| 39 | + /** | ||
| 35 | * 响应数据 | 40 | * 响应数据 |
| 36 | */ | 41 | */ |
| 37 | private T data; | 42 | private T data; |
| @@ -41,7 +46,6 @@ public class ResultJson<T> implements Serializable { | @@ -41,7 +46,6 @@ public class ResultJson<T> implements Serializable { | ||
| 41 | */ | 46 | */ |
| 42 | private String jwtToken; | 47 | private String jwtToken; |
| 43 | 48 | ||
| 44 | - private Integer total; | ||
| 45 | 49 | ||
| 46 | /** | 50 | /** |
| 47 | * 无参,构造方法 | 51 | * 无参,构造方法 |
| @@ -105,6 +105,13 @@ public interface BusServerService { | @@ -105,6 +105,13 @@ public interface BusServerService { | ||
| 105 | List<BusServer> getServerList(); | 105 | List<BusServer> getServerList(); |
| 106 | 106 | ||
| 107 | /** | 107 | /** |
| 108 | + * 查询服务器列表(不包含密码) | ||
| 109 | + * | ||
| 110 | + * @return 服务器列表 | ||
| 111 | + */ | ||
| 112 | + List<BusServer> selectServerList(); | ||
| 113 | + | ||
| 114 | + /** | ||
| 108 | * 查询,服务器(1:n虚拟主机)的基本信息 | 115 | * 查询,服务器(1:n虚拟主机)的基本信息 |
| 109 | * | 116 | * |
| 110 | * @return List<BusServer> | 117 | * @return List<BusServer> |
| @@ -150,6 +150,12 @@ public class BusServerServiceImpl implements BusServerService { | @@ -150,6 +150,12 @@ public class BusServerServiceImpl implements BusServerService { | ||
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | @Override | 152 | @Override |
| 153 | + public List<BusServer> selectServerList() | ||
| 154 | + { | ||
| 155 | + return busServerMapper.selectServerList(); | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + @Override | ||
| 153 | public List<BusServer> getServerAndHostList(BusServer busServer) | 159 | public List<BusServer> getServerAndHostList(BusServer busServer) |
| 154 | { | 160 | { |
| 155 | return busServerMapper.getServerAndHostList(busServer); | 161 | return busServerMapper.getServerAndHostList(busServer); |
| 1 | +package com.sunyo.wlpt.message.bus.service.service.view; | ||
| 2 | + | ||
| 3 | +import com.rabbitmq.http.client.domain.QueueInfo; | ||
| 4 | +import com.sunyo.wlpt.message.bus.service.domain.BusServer; | ||
| 5 | +import com.sunyo.wlpt.message.bus.service.domain.VirtualHost; | ||
| 6 | +import com.sunyo.wlpt.message.bus.service.mapper.BusServerMapper; | ||
| 7 | +import com.sunyo.wlpt.message.bus.service.mapper.VirtualHostMapper; | ||
| 8 | +import com.sunyo.wlpt.message.bus.service.rabbit.utils.ClientUtils; | ||
| 9 | +import com.sunyo.wlpt.message.bus.service.response.ResultJson; | ||
| 10 | +import io.netty.util.internal.StringUtil; | ||
| 11 | +import org.springframework.stereotype.Service; | ||
| 12 | + | ||
| 13 | +import javax.annotation.Resource; | ||
| 14 | +import java.io.IOException; | ||
| 15 | +import java.net.URISyntaxException; | ||
| 16 | +import java.util.ArrayList; | ||
| 17 | +import java.util.Comparator; | ||
| 18 | +import java.util.List; | ||
| 19 | +import java.util.stream.Collectors; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * @author 子诚 | ||
| 23 | + * Description: | ||
| 24 | + * 时间:2020/8/26 15:09 | ||
| 25 | + */ | ||
| 26 | +@Service | ||
| 27 | +public class ViewQueueFactory { | ||
| 28 | + | ||
| 29 | + @Resource | ||
| 30 | + private BusServerMapper busServerMapper; | ||
| 31 | + | ||
| 32 | + @Resource | ||
| 33 | + private VirtualHostMapper virtualHostMapper; | ||
| 34 | + | ||
| 35 | + public ResultJson getViewQueueList(String serverName, String virtualHostName, Integer pageNum, Integer pageSize) throws IOException, | ||
| 36 | + URISyntaxException | ||
| 37 | + { | ||
| 38 | + List<QueueInfo> list = new ArrayList<>(); | ||
| 39 | + | ||
| 40 | + // 服务器名称、虚拟主机名称,均为空 | ||
| 41 | + if (StringUtil.isNullOrEmpty(serverName) && StringUtil.isNullOrEmpty(virtualHostName)) { | ||
| 42 | + List<BusServer> serverList = busServerMapper.getServerList(); | ||
| 43 | + for (BusServer busServer : serverList) { | ||
| 44 | + List<QueueInfo> queueInfoList = ClientUtils.getViewQueues(busServer); | ||
| 45 | + list.addAll(queueInfoList); | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + // 仅,服务器名称不为空 | ||
| 50 | + if (!StringUtil.isNullOrEmpty(serverName) && StringUtil.isNullOrEmpty(virtualHostName)) { | ||
| 51 | + BusServer busServer = busServerMapper.selectByServerName(serverName); | ||
| 52 | + if (busServer == null) { | ||
| 53 | + return new ResultJson("400", "该服务器名称不存在,请仔细检查"); | ||
| 54 | + } | ||
| 55 | + List<QueueInfo> queueInfoList = ClientUtils.getViewQueues(busServer); | ||
| 56 | + list.addAll(queueInfoList); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + // 仅,虚拟主机名称不为空 | ||
| 60 | + if (StringUtil.isNullOrEmpty(serverName) && !StringUtil.isNullOrEmpty(virtualHostName)) { | ||
| 61 | + VirtualHost virtualHost = virtualHostMapper.selectByVirtualHostName(virtualHostName); | ||
| 62 | + if (virtualHost == null) { | ||
| 63 | + return new ResultJson("400", "该虚拟主机名称不存在,请仔细检查"); | ||
| 64 | + } | ||
| 65 | + BusServer busServer = busServerMapper.selectByPrimaryKey(virtualHost.getServerId()); | ||
| 66 | + List<QueueInfo> queueInfoList = ClientUtils.getViewQueues(busServer, virtualHostName); | ||
| 67 | + list.addAll(queueInfoList); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + // 服务器名称、虚拟主机名称,均不为空 | ||
| 71 | + if (!StringUtil.isNullOrEmpty(serverName) && !StringUtil.isNullOrEmpty(virtualHostName)) { | ||
| 72 | + BusServer busServer = busServerMapper.selectByServerName(serverName); | ||
| 73 | + if (busServer == null) { | ||
| 74 | + return new ResultJson("400", "该服务器名称不存在,请仔细检查"); | ||
| 75 | + } | ||
| 76 | + VirtualHost virtualHost = virtualHostMapper.selectByVirtualHostName(virtualHostName); | ||
| 77 | + if (virtualHost == null) { | ||
| 78 | + return new ResultJson("400", "该虚拟主机名称不存在,请仔细检查"); | ||
| 79 | + } | ||
| 80 | + if (!virtualHost.getServerId().equals(busServer.getId())) { | ||
| 81 | + return new ResultJson("400", "该虚拟主机不属于该服务器,请仔细检查"); | ||
| 82 | + } | ||
| 83 | + List<QueueInfo> queueInfoList = ClientUtils.getViewQueues(busServer, virtualHostName); | ||
| 84 | + list.addAll(queueInfoList); | ||
| 85 | + } | ||
| 86 | + Integer total = list.size(); | ||
| 87 | + | ||
| 88 | + // 达到分页与排序效果 | ||
| 89 | + List<QueueInfo> resultList = subList(pageNum, pageSize, list); | ||
| 90 | + return resultList.size() > 0 | ||
| 91 | + ? new ResultJson<>("200", "查询队列监控,成功!", resultList, total) | ||
| 92 | + : new ResultJson<>("500", "查询队列监控,失败!"); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * 实现分页与排序效果 | ||
| 97 | + * | ||
| 98 | + * @param pageNum 开始页 | ||
| 99 | + * @param pageSize 每页大小 | ||
| 100 | + * @param list 全部的数据 | ||
| 101 | + * @return List<QueueInfo> | ||
| 102 | + */ | ||
| 103 | + public List<QueueInfo> subList(Integer pageNum, Integer pageSize, List<QueueInfo> list) | ||
| 104 | + { | ||
| 105 | + Integer total = list.size(); | ||
| 106 | + Integer start = (pageNum - 1) * pageSize; | ||
| 107 | + Integer end = start + pageSize; | ||
| 108 | + if (start > total) { | ||
| 109 | + start = 0; | ||
| 110 | + end = total; | ||
| 111 | + } | ||
| 112 | + if (end > total) { | ||
| 113 | + end = total; | ||
| 114 | + } | ||
| 115 | + List<QueueInfo> pageList = list.subList(start, end); | ||
| 116 | + // 对总信息数,进行降序排序 | ||
| 117 | + List<QueueInfo> resultList = | ||
| 118 | + pageList.stream().sorted(Comparator.comparing(QueueInfo::getTotalMessages).reversed()).collect(Collectors.toList()); | ||
| 119 | + return resultList; | ||
| 120 | + } | ||
| 121 | +} |
| @@ -250,6 +250,20 @@ | @@ -250,6 +250,20 @@ | ||
| 250 | </where> | 250 | </where> |
| 251 | </select> | 251 | </select> |
| 252 | 252 | ||
| 253 | + <!-- 获取服务器列表 --> | ||
| 254 | + <select id="selectServerList" resultMap="BaseResultMap"> | ||
| 255 | + select id, | ||
| 256 | + `server_name`, | ||
| 257 | + server_ip, | ||
| 258 | + server_port, | ||
| 259 | + client_port, | ||
| 260 | + super_username, | ||
| 261 | + description, | ||
| 262 | + gmt_create, | ||
| 263 | + gmt_modified | ||
| 264 | + from bus_server | ||
| 265 | + </select> | ||
| 266 | + | ||
| 253 | <!-- 首先。校验服务器名称,是否存在 --> | 267 | <!-- 首先。校验服务器名称,是否存在 --> |
| 254 | <select id="validateServerName" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer" | 268 | <select id="validateServerName" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer" |
| 255 | resultMap="BaseResultMap"> | 269 | resultMap="BaseResultMap"> |
| @@ -264,6 +278,14 @@ | @@ -264,6 +278,14 @@ | ||
| 264 | </where> | 278 | </where> |
| 265 | </select> | 279 | </select> |
| 266 | 280 | ||
| 281 | + <select id="validateByServerName" parameterType="java.lang.String" resultMap="BaseResultMap"> | ||
| 282 | + select | ||
| 283 | + <include refid="Base_Column_List"/> | ||
| 284 | + from bus_server | ||
| 285 | + where server_name = #{serverName,jdbcType=VARCHAR} | ||
| 286 | + </select> | ||
| 287 | + | ||
| 288 | + | ||
| 267 | <!-- 再校验服务器信息(服务器的ip,服务器的port)是否同时存在 --> | 289 | <!-- 再校验服务器信息(服务器的ip,服务器的port)是否同时存在 --> |
| 268 | <select id="validateBusServer" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer" | 290 | <select id="validateBusServer" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer" |
| 269 | resultMap="BaseResultMap"> | 291 | resultMap="BaseResultMap"> |
-
请 注册 或 登录 后发表评论