Browse Source

服务监控,服务启动暂停接口添加

demon 8 years ago
parent
commit
7b058f10a3

+ 43 - 0
src/main/java/com/yihu/hos/monitor/controller/ServiceMonitorController.java

@ -1,6 +1,7 @@
package com.yihu.hos.monitor.controller;
import com.yihu.hos.monitor.service.ServiceMonitorService;
import com.yihu.hos.system.service.FlowManager;
import com.yihu.hos.web.framework.model.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -27,6 +28,8 @@ public class ServiceMonitorController {
    @Resource(name = ServiceMonitorService.BEAN_ID)
    private ServiceMonitorService monitorService;
    @Resource(name = FlowManager.BEAN_ID)
    private FlowManager flowManager;
    //跳转到列表页
    @RequestMapping("/initial")
@ -65,4 +68,44 @@ public class ServiceMonitorController {
            return Result.error("获取服务树列表失败");
        }
    }
    @RequestMapping(value = "/startService", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "开启服务", produces = "application/json", notes = "开启服务")
    public Result startService(
            HttpServletRequest request,
            @ApiParam(name = "flowId", value = "流程ID", required = true)
            @RequestParam(value = "flowId") Integer flowId ) {
        try {
            boolean succ = flowManager.serviceOpenOrPause(flowId,1);
            if (succ){
                return Result.success("开启服务成功");
            }else {
                return Result.error("开启服务失败");
            }
        } catch (Exception e) {
            return Result.error("开启服务异常");
        }
    }
    @RequestMapping(value = "/stopService", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "暂停服务", produces = "application/json", notes = "暂停服务")
    public Result stopService(
            HttpServletRequest request,
            @ApiParam(name = "flowId", value = "流程ID", required = true)
            @RequestParam(value = "flowId") Integer flowId ) {
        try {
            boolean succ = flowManager.serviceOpenOrPause(flowId,0);
            if (succ){
                return Result.success("暂停服务成功");
            }else {
                return Result.error("暂停服务失败");
            }
        } catch (Exception e) {
            return Result.error("暂停服务异常");
        }
    }
}

+ 5 - 0
src/main/java/com/yihu/hos/monitor/dao/ServiceMonitorDao.java

@ -34,4 +34,9 @@ public class ServiceMonitorDao extends SQLGeneralDAO {
    public SystemServiceEndpoint getEndpointById(String id) throws Exception {
        return (SystemServiceEndpoint) super.hibernateTemplate.find("from SystemServiceEndpoint s where s.id=?", id).get(0);
    }
    public List<SystemServiceFlow> getFlowsByType(String type) throws Exception {
        return (List<SystemServiceFlow>) super.hibernateTemplate.find("from SystemServiceFlow s where s.type=?",type);
    }
}

+ 6 - 3
src/main/java/com/yihu/hos/monitor/service/ServiceMonitorService.java

@ -7,6 +7,7 @@ import com.yihu.hos.monitor.dao.ServiceMonitorDao;
import com.yihu.hos.system.model.SystemServiceEndpoint;
import com.yihu.hos.system.model.SystemServiceFlow;
import com.yihu.hos.system.model.SystemServiceFlowConfig;
import com.yihu.hos.system.service.FlowManager;
import com.yihu.hos.tenant.model.TenantSession;
import com.yihu.hos.web.framework.constant.ServiceFlowConstant;
import com.yihu.hos.web.framework.model.Result;
@ -18,6 +19,7 @@ import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
@ -42,6 +44,9 @@ public class ServiceMonitorService {
    @Autowired
    private ServiceMonitorDao serviceMonitorDao;
    @Resource(name = FlowManager.BEAN_ID)
    private FlowManager flowManager;
    public Result metrics(HttpSession session,String id, String beginTime, String endTime) throws Exception {
        String name;
        String code;
@ -104,7 +109,7 @@ public class ServiceMonitorService {
    public Result getServiceTreeList() throws Exception {
        List<TreeView> treeList = new ArrayList<>();
        List<SystemServiceFlow> flowList = serviceMonitorDao.getAllFlows();
        List<SystemServiceFlow> flowList = serviceMonitorDao.getFlowsByType(ServiceFlowConstant.CLASS);
        List<SystemServiceFlowConfig> flowEndpointList = serviceMonitorDao.getAllFlowEndpoints();
        List<SystemServiceEndpoint> endpointList = serviceMonitorDao.getAllEndpoints();
        Map<Integer, List<String>> flowEndpointMap = new HashMap<>();
@ -126,7 +131,6 @@ public class ServiceMonitorService {
        }
        for (SystemServiceFlow flow : flowList) {
            if (flow.getFileType().equals(ServiceFlowConstant.CLASS)) {
                TreeView rootTree = new TreeView();
                rootTree.setIschecked(false);
                rootTree.setId("flow" + flow.getId());
@ -144,7 +148,6 @@ public class ServiceMonitorService {
                        childTree.setText(endpoint.getName());
                        treeList.add(childTree);
                    }
                }
            }
        }
        JSONArray jsonArray = new JSONArray(treeList);

+ 2 - 0
src/main/java/com/yihu/hos/system/dao/FlowDao.java

@ -16,6 +16,8 @@ import java.util.Map;
 */
@Repository("flowDao")
public class FlowDao extends SQLGeneralDAO {
    public static final String BEAN_ID = "flowDao";
    public Result getFlowList(Map<String, Object> params) throws Exception {
        StringBuilder sb = new StringBuilder("from SystemServiceFlow t where 1=1 ");
        if (!StringUtils.isEmpty(params.get("valid"))) //是否有效

+ 65 - 20
src/main/java/com/yihu/hos/system/service/FlowManager.java

@ -150,7 +150,7 @@ public class FlowManager {
        return null;
    }
    
    public Result getFlowList(Map<String, Object> params) throws Exception {
        return flowDao.getFlowList(params);
    }
@ -190,7 +190,7 @@ public class FlowManager {
        /* ===================================  flowClass 部分================================================*/
    
    public SystemServiceFlow getFlowById(Integer id) throws Exception {
        return flowDao.getEntity(SystemServiceFlow.class, id);
    }
@ -322,8 +322,10 @@ public class FlowManager {
    @Transactional
    public Result deleteFlow(Integer id) throws Exception {
        SystemServiceFlow flow = flowDao.getEntity(SystemServiceFlow.class, id);
        if (flow == null){ return Result.error("删除流程失败");}
        ArrayList<ServiceFlow.HandleFile>  handleFiles =new ArrayList<>();
        if (flow == null) {
            return Result.error("删除流程失败");
        }
        ArrayList<ServiceFlow.HandleFile> handleFiles = new ArrayList<>();
        List<SystemServiceFlowClass> flowClassList = flowClassDao.getFlowClassByFlowId(id);
        if (ServiceFlowConstant.JAVA.equals(flow.getFileType())) {
            flowTempDao.deleteFlowTempByFlowId(id);
@ -353,12 +355,12 @@ public class FlowManager {
    }
    
    public Result getFlowClassList(Map<String, Object> params) throws Exception {
        return null;
    }
    
    public List<SystemServiceFlowClass> getFlowClassByFlowId(Integer flowId) throws Exception {
        return flowClassDao.getFlowClassByFlowId(flowId);
    }
@ -384,13 +386,13 @@ public class FlowManager {
        return succ;
    }
    
    public List<SystemServiceFlowTemp> getFlowTempByFlowId(Integer id) throws Exception {
        return flowTempDao.getFlowTempByFlowId(id);
    }
    //TODO
    
    public boolean genFlewByflowTempId(Integer flowTempId) throws Exception {
        SystemServiceFlow flow = getFlowById(flowTempId);
        //生成新的route类
@ -399,7 +401,7 @@ public class FlowManager {
        return false;
    }
    
    public Result uploadFile(CommonsMultipartFile file) {
        String dbName = "upload";
        String newFileName;
@ -414,7 +416,7 @@ public class FlowManager {
        return Result.error("上传失败");
    }
    
    public Result readFile(OutputStream os, String fileName) {
        String dbName = "upload";
        try {
@ -469,7 +471,7 @@ public class FlowManager {
     * @return
     * @throws Exception
     */
    
    public ActionResult getFlowList(String type) throws Exception {
        List<SystemServiceFlow> flowList = flowDao.getFlowList(type);
        ActionResult re = new ActionResult();
@ -521,7 +523,7 @@ public class FlowManager {
     * @return
     * @throws Exception
     */
    
    public Integer updateCamelFile(Integer flowTempId, Integer flowId, String newCron) throws Exception {
         /* 修改route文件无需重新生成flowClass记录,文件名根据className+routeId 生成;*/
        List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(flowTempId, ServiceFlowConstant.FLOW_TYPE_ROUTE);
@ -542,7 +544,7 @@ public class FlowManager {
            //生成新的route文件
            String newFileName = genRouteJavaFile(flow.getCode(), flowTemp.getClassName(), deName, newCron);
            String enNewFileName = DES.encrypt(newFileName,DES.COMMON_PASSWORD);
            String enNewFileName = DES.encrypt(newFileName, DES.COMMON_PASSWORD);
            ServiceFlow serviceFlow = new ServiceFlow();
            serviceFlow.setRouteCode(flow.getCode());
            serviceFlow.setFlowType(ServiceFlowConstant.JAVA);
@ -550,10 +552,10 @@ public class FlowManager {
            handleFile.setRouteCode(flow.getCode());
            handleFile.setFileType(ServiceFlowConstant.JAVA);
            handleFile.setPackageName(basePath.toString());
            handleFile.setClassName(flowTemp.getClassName()+flow.getCode());
            handleFile.setClassName(flowTemp.getClassName() + flow.getCode());
            handleFile.setFilePath(enNewFileName);
            handleFile.setUsage(ServiceFlowConstant.FLOW_TYPE_ROUTE);
            ArrayList<ServiceFlow.HandleFile>  handleFiles =new ArrayList<>();
            ArrayList<ServiceFlow.HandleFile> handleFiles = new ArrayList<>();
            handleFiles.add(handleFile);
            serviceFlow.setHandleFiles(handleFiles);
            serviceFlowEventService.serviceFlowModifiedAdd(serviceFlow);
@ -592,7 +594,7 @@ public class FlowManager {
            newFlowClass.setIsUpdate("1");
            //生成新的route文件
            String newFileName = genRouteJavaFile(newFlow.getCode(), flowTemp.getClassName(), deName, newCron);
            String enNewFileName = DES.encrypt(newFileName,DES.COMMON_PASSWORD);
            String enNewFileName = DES.encrypt(newFileName, DES.COMMON_PASSWORD);
            if (newFileName != null) {
                ServiceFlow serviceFlow = new ServiceFlow();
@ -602,10 +604,10 @@ public class FlowManager {
                handleFile.setRouteCode(newFlow.getCode());
                handleFile.setFileType(ServiceFlowConstant.JAVA);
                handleFile.setPackageName(flowTemp.getPackageName());
                handleFile.setClassName(flowTemp.getClassName()+newFlow.getCode());
                handleFile.setClassName(flowTemp.getClassName() + newFlow.getCode());
                handleFile.setFilePath(enNewFileName);
                handleFile.setUsage(ServiceFlowConstant.FLOW_TYPE_ROUTE);
                ArrayList<ServiceFlow.HandleFile>  handleFiles =new ArrayList<>();
                ArrayList<ServiceFlow.HandleFile> handleFiles = new ArrayList<>();
                handleFiles.add(handleFile);
                serviceFlow.setHandleFiles(handleFiles);
                serviceFlowEventService.serviceFlowModifiedAdd(serviceFlow);
@ -636,7 +638,7 @@ public class FlowManager {
            newFlow.setCreateDate(new Date());
            newFlow.setFileType(ServiceFlowConstant.CLASS);
            flowDao.saveEntity(newFlow);
            ArrayList<ServiceFlow.HandleFile>  handleFiles =new ArrayList<>();
            ArrayList<ServiceFlow.HandleFile> handleFiles = new ArrayList<>();
            //新增processor记录
            for (SystemServiceFlowTemp process : flowTempProces) {
@ -662,7 +664,7 @@ public class FlowManager {
                processClass.setIsUpdate("1");
                //生成新的java文件
                String newFileName = genProcessorJavaFile(jobId, newFlow.getCode(), deName, processClass.getClassName());
                String enNewFileName = DES.encrypt(newFileName,DES.COMMON_PASSWORD);
                String enNewFileName = DES.encrypt(newFileName, DES.COMMON_PASSWORD);
                if (newFileName != null) {
                    //发送消息
@ -691,5 +693,48 @@ public class FlowManager {
        return null;
    }
    /**
     *  服务启动/暂停
     * @param flowId 流程ID
     * @param oper   服务操作;1:启动;0:暂停
     * @return
     * @throws Exception
     */
    public boolean serviceOpenOrPause(Integer flowId, Integer oper) throws Exception {
        SystemServiceFlow flow = flowDao.getEntity(SystemServiceFlow.class, flowId);
        if (flow != null) {
            List<SystemServiceFlowClass> flowClassList = flowClassDao.getFlowClassByFlowId(flowId);
            //route模板文件记录是否存在。不存在就返回。
            ArrayList<ServiceFlow.HandleFile> handleFiles = new ArrayList<>();
            //新增processor记录
            ServiceFlow serviceFlow = new ServiceFlow();
            serviceFlow.setRouteCode(flow.getCode());
            serviceFlow.setFlowType(ServiceFlowConstant.CLASS);
            for (SystemServiceFlowClass flowClass : flowClassList) {
//                String deName = DES.decrypt(flowClass.getClassPath(), DES.COMMON_PASSWORD);//吉阿米果的文件名
                //发送消息
                ServiceFlow.HandleFile handleFile = new ServiceFlow.HandleFile();
                handleFile.setRouteCode(flow.getCode());
                handleFile.setFileType(ServiceFlowConstant.CLASS);
                handleFile.setPackageName(flowClass.getPackageName());
                handleFile.setClassName(flowClass.getClassName());
                handleFile.setFilePath(flowClass.getClassPath());
                handleFile.setUsage(ServiceFlowConstant.FLOW_TYPE_PROCESSOR);
                handleFiles.add(handleFile);
            }
            serviceFlow.setHandleFiles(handleFiles);
            if (1 == oper){
                serviceFlowEventService.serviceFlowStarted(serviceFlow);
            }else if (0 == oper){
                serviceFlowEventService.serviceFlowStopped(serviceFlow);
            }else {
                return false;
            }
            return true;
        } else {
            return false;
        }
    }
}

+ 12 - 0
src/main/webapp/WEB-INF/ehr/jsp/monitor/service/sEnvManage.jsp

@ -1,6 +1,8 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8" %>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<link rel="stylesheet" href="${contextRoot}/develop/lib/plugin/switchery/switchery.css">
<style>
    .c-item{float:left;height: 30px;line-height: 30px;width: 150px;background: #fff;color:#000;text-align: center;font-size: 12px;border:1px solid #dcdcdc;}
    .c-bor-r{border-right: 0;}
@ -30,6 +32,16 @@
        <!-- ####### 查询条件部分 ####### -->
        <div class="m-form-inline" data-role-form>
            <div class="m-form-group">
                <div class="col-sm-3" style="text-align: center;padding-top:10px;">
                    <div style="width:255px">
                        <input type="checkbox" class="js-switch" id="jobStatusSwitch" checked />
                    </div>
                    <div style="float: left;width:235px;border-left:1px solid #e1e1e1;;line-height: 32px;" id="jobStatus">
                        -
                    </div>
                    <div style="clear: both;padding-top:20px;">任务调度</div>
                </div>
                <div class="m-form-control">
                    <label style="font-weight: 900;" id="serviceName"></label>
                </div>

+ 26 - 0
src/main/webapp/WEB-INF/ehr/jsp/monitor/service/sEnvManageJs.jsp

@ -1,11 +1,15 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8" %>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>
<script src="${contextRoot}/develop/lib/plugin/switchery/switchery.js"></script>
<script src="${contextRoot}/develop/lib/plugin/echarts/echarts-all.js"></script>
<script>
    $(function () {
        //l-layout-left
        //初始化layout
        initSwitcher();
        $("#div_wrapper").ligerLayout({
            height: "99%",
            leftWidth: 200,
@ -48,6 +52,27 @@
        getServiceTree();
    });
    function initSwitcher(){
        var me = this;
        //开关控件
        var changeCheckbox = document.querySelector('#jobStatusSwitch');
        var switchery = new Switchery(changeCheckbox, { disabled: true,size: 'large' });
        changeCheckbox.onchange = function() {
            //debugger
            var a = me.switchery;
            var jobId = $("#selJob").ligerComboBox("getValue");
            if(!changeCheckbox.checked)
            {
                me.valid(jobId,"0");
            }
            else{
                me.valid(jobId,"1");
            }
        };
    }
    function getServiceTree(){
        var serviceTree = $("#div_wrapper_left_ul_servicetree");
        //初始化树
@ -114,6 +139,7 @@
    }
    var service = {
        switchery:null,
        bandwidth:function(data){
            // 基于准备好的dom,初始化echarts实例
            var myChart = echarts.init(document.getElementById('main1'));