Merge pull request #365 from TristingChen/zlm-node-manage

fixed--多节点管理zlm,wvp重启之后节点中的redis在线状态bug修复
pull/375/head
648540858 2022-03-03 16:23:03 +08:00 committed by GitHub
commit b019106c44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 5 deletions

View File

@ -92,6 +92,7 @@ public class ZLMRunner implements CommandLineRunner {
// 获取所有的zlm 并开启主动连接 // 获取所有的zlm 并开启主动连接
List<MediaServerItem> all = mediaServerService.getAllFromDatabase(); List<MediaServerItem> all = mediaServerService.getAllFromDatabase();
mediaServerService.updateVmServer(all);
if (all.size() == 0) { if (all.size() == 0) {
all.add(mediaConfig.getMediaSerItem()); all.add(mediaConfig.getMediaSerItem());
} }

View File

@ -42,6 +42,8 @@ public interface IMediaServerService {
void setZLMConfig(MediaServerItem mediaServerItem, boolean restart); void setZLMConfig(MediaServerItem mediaServerItem, boolean restart);
void updateVmServer(List<MediaServerItem> mediaServerItemList);
SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId); SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId);
SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId, boolean isPlayback); SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId, boolean isPlayback);
@ -74,6 +76,8 @@ public interface IMediaServerService {
void delete(String id); void delete(String id);
void deleteDb(String id);
MediaServerItem getDefaultMediaServer(); MediaServerItem getDefaultMediaServer();
void updateMediaServerKeepalive(String mediaServerId, JSONObject data); void updateMediaServerKeepalive(String mediaServerId, JSONObject data);

View File

@ -46,8 +46,7 @@ import java.util.*;
* *
*/ */
@Service @Service
@Order(value=2) public class MediaServerServiceImpl implements IMediaServerService {
public class MediaServerServiceImpl implements IMediaServerService, CommandLineRunner {
private final static Logger logger = LoggerFactory.getLogger(MediaServerServiceImpl.class); private final static Logger logger = LoggerFactory.getLogger(MediaServerServiceImpl.class);
@ -102,9 +101,8 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
* *
*/ */
@Override @Override
public void run(String... args) throws Exception { public void updateVmServer(List<MediaServerItem> mediaServerItemList) {
logger.info("[缓存初始化] Media Server "); logger.info("[缓存初始化] Media Server ");
List<MediaServerItem> mediaServerItemList = mediaServerMapper.queryAll();
for (MediaServerItem mediaServerItem : mediaServerItemList) { for (MediaServerItem mediaServerItem : mediaServerItemList) {
if (StringUtils.isEmpty(mediaServerItem.getId())) { if (StringUtils.isEmpty(mediaServerItem.getId())) {
continue; continue;
@ -225,7 +223,8 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
String key = (String) mediaServerKey; String key = (String) mediaServerKey;
MediaServerItem mediaServerItem = (MediaServerItem) redisUtil.get(key); MediaServerItem mediaServerItem = (MediaServerItem) redisUtil.get(key);
// 检查状态 // 检查状态
if (redisUtil.zScore(onlineKey, mediaServerItem.getId()) != null) { Double aDouble = redisUtil.zScore(onlineKey, mediaServerItem.getId());
if (aDouble != null) {
mediaServerItem.setStatus(true); mediaServerItem.setStatus(true);
} }
result.add(mediaServerItem); result.add(mediaServerItem);
@ -610,6 +609,11 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + id; String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetup.getServerId() + "_" + id;
redisUtil.del(key); redisUtil.del(key);
} }
@Override
public void deleteDb(String id){
//同步删除数据库中的数据
mediaServerMapper.delOne(id);
}
@Override @Override
public void updateMediaServerKeepalive(String mediaServerId, JSONObject data) { public void updateMediaServerKeepalive(String mediaServerId, JSONObject data) {

View File

@ -158,6 +158,7 @@ public class ServerController {
public WVPResult<String> deleteMediaServer(@RequestParam String id){ public WVPResult<String> deleteMediaServer(@RequestParam String id){
if (mediaServerService.getOne(id) != null) { if (mediaServerService.getOne(id) != null) {
mediaServerService.delete(id); mediaServerService.delete(id);
mediaServerService.deleteDb(id);
}else { }else {
WVPResult<String> result = new WVPResult<>(); WVPResult<String> result = new WVPResult<>();
result.setCode(-1); result.setCode(-1);