|  |  |  | 
|---|
|  |  |  | package com.genersoft.iot.vmp.vmanager.server; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.alibaba.fastjson2.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson2.JSONObject; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.VManageBootstrap; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.common.SystemAllInfo; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.common.VersionPo; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.conf.SipConfig; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.conf.UserSetting; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.media.zlm.dto.IHookSubscribe; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.service.IMediaServerService; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.service.*; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.service.bean.MediaServerLoad; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.utils.SpringBeanFactory; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.vmanager.bean.ResourceBaceInfo; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.vmanager.bean.ResourceInfo; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.vmanager.bean.SystemConfigInfo; | 
|---|
|  |  |  | import gov.nist.javax.sip.SipStackImpl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.Operation; | 
|---|
|  |  |  | 
|---|
|  |  |  | import javax.sip.ListeningPoint; | 
|---|
|  |  |  | import javax.sip.ObjectInUseException; | 
|---|
|  |  |  | import javax.sip.SipProvider; | 
|---|
|  |  |  | import java.util.Iterator; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SuppressWarnings("rawtypes") | 
|---|
|  |  |  | @Tag(name = "服务控制") | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserSetting userSetting; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private IDeviceService deviceService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private IDeviceChannelService channelService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private IStreamPushService pushService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private IStreamProxyService proxyService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${server.port}") | 
|---|
|  |  |  | private int serverPort; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ThreadPoolTaskExecutor taskExecutor; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private IRedisCatchStorage redisCatchStorage; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping(value = "/media_server/list") | 
|---|
|  |  |  | 
|---|
|  |  |  | MediaServerItem mediaServerItemInDatabase = mediaServerService.getOne(mediaServerItem.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (mediaServerItemInDatabase != null) { | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(mediaServerItemInDatabase.getSendRtpPortRange()) && ObjectUtils.isEmpty(mediaServerItem.getSendRtpPortRange())) { | 
|---|
|  |  |  | mediaServerItem.setSendRtpPortRange("30000,30500"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mediaServerService.update(mediaServerItem); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(mediaServerItem.getSendRtpPortRange())) { | 
|---|
|  |  |  | mediaServerItem.setSendRtpPortRange("30000,30500"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mediaServerService.add(mediaServerItem); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @GetMapping(value = "/restart") | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | public void restart() { | 
|---|
|  |  |  | taskExecutor.execute(()-> { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Thread.sleep(3000); | 
|---|
|  |  |  | SipProvider up = (SipProvider) SpringBeanFactory.getBean("udpSipProvider"); | 
|---|
|  |  |  | SipStackImpl stack = (SipStackImpl) up.getSipStack(); | 
|---|
|  |  |  | stack.stop(); | 
|---|
|  |  |  | Iterator listener = stack.getListeningPoints(); | 
|---|
|  |  |  | while (listener.hasNext()) { | 
|---|
|  |  |  | stack.deleteListeningPoint((ListeningPoint) listener.next()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Iterator providers = stack.getSipProviders(); | 
|---|
|  |  |  | while (providers.hasNext()) { | 
|---|
|  |  |  | stack.deleteSipProvider((SipProvider) providers.next()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | VManageBootstrap.restart(); | 
|---|
|  |  |  | } catch (InterruptedException | ObjectInUseException e) { | 
|---|
|  |  |  | throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | //        taskExecutor.execute(()-> { | 
|---|
|  |  |  | //            try { | 
|---|
|  |  |  | //                Thread.sleep(3000); | 
|---|
|  |  |  | //                SipProvider up = (SipProvider) SpringBeanFactory.getBean("udpSipProvider"); | 
|---|
|  |  |  | //                SipStackImpl stack = (SipStackImpl) up.getSipStack(); | 
|---|
|  |  |  | //                stack.stop(); | 
|---|
|  |  |  | //                Iterator listener = stack.getListeningPoints(); | 
|---|
|  |  |  | //                while (listener.hasNext()) { | 
|---|
|  |  |  | //                    stack.deleteListeningPoint((ListeningPoint) listener.next()); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                Iterator providers = stack.getSipProviders(); | 
|---|
|  |  |  | //                while (providers.hasNext()) { | 
|---|
|  |  |  | //                    stack.deleteSipProvider((SipProvider) providers.next()); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                VManageBootstrap.restart(); | 
|---|
|  |  |  | //            } catch (InterruptedException | ObjectInUseException e) { | 
|---|
|  |  |  | //                throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage()); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        }); | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Operation(summary = "获取系统信息信息") | 
|---|
|  |  |  | @GetMapping(value = "/system/configInfo") | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | public SystemConfigInfo getConfigInfo() { | 
|---|
|  |  |  | SystemConfigInfo systemConfigInfo = new SystemConfigInfo(); | 
|---|
|  |  |  | systemConfigInfo.setVersion(versionInfo.getVersion()); | 
|---|
|  |  |  | systemConfigInfo.setSip(sipConfig); | 
|---|
|  |  |  | systemConfigInfo.setAddOn(userSetting); | 
|---|
|  |  |  | systemConfigInfo.setServerPort(serverPort); | 
|---|
|  |  |  | return systemConfigInfo; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Operation(summary = "获取版本信息") | 
|---|
|  |  |  | @GetMapping(value = "/version") | 
|---|
|  |  |  | 
|---|
|  |  |  | public List<IHookSubscribe> getHooks() { | 
|---|
|  |  |  | return zlmHttpHookSubscribe.getAll(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping(value = "/system/info") | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | @Operation(summary = "获取系统信息") | 
|---|
|  |  |  | public SystemAllInfo getSystemInfo() { | 
|---|
|  |  |  | SystemAllInfo systemAllInfo = redisCatchStorage.getSystemInfo(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return systemAllInfo; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping(value = "/media_server/load") | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | @Operation(summary = "获取负载信息") | 
|---|
|  |  |  | public List<MediaServerLoad> getMediaLoad() { | 
|---|
|  |  |  | List<MediaServerLoad> result = new ArrayList<>(); | 
|---|
|  |  |  | List<MediaServerItem> allOnline = mediaServerService.getAllOnline(); | 
|---|
|  |  |  | if (allOnline.size() == 0) { | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | for (MediaServerItem mediaServerItem : allOnline) { | 
|---|
|  |  |  | result.add(mediaServerService.getLoad(mediaServerItem)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping(value = "/resource/info") | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | @Operation(summary = "获取负载信息") | 
|---|
|  |  |  | public ResourceInfo getResourceInfo() { | 
|---|
|  |  |  | ResourceInfo result = new ResourceInfo(); | 
|---|
|  |  |  | ResourceBaceInfo deviceInfo = deviceService.getOverview(); | 
|---|
|  |  |  | result.setDevice(deviceInfo); | 
|---|
|  |  |  | ResourceBaceInfo channelInfo = channelService.getOverview(); | 
|---|
|  |  |  | result.setChannel(channelInfo); | 
|---|
|  |  |  | ResourceBaceInfo pushInfo = pushService.getOverview(); | 
|---|
|  |  |  | result.setPush(pushInfo); | 
|---|
|  |  |  | ResourceBaceInfo proxyInfo = proxyService.getOverview(); | 
|---|
|  |  |  | result.setProxy(proxyInfo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|