Browse Source

文件冲突解决

zhenglingfeng 8 years ago
parent
commit
1b4ff923db

+ 3 - 2
hos-broker/src/main/java/com/yihu/hos/common/dao/BrokerDao.java

@ -1,5 +1,6 @@
package com.yihu.hos.common.dao;
import com.yihu.hos.common.constants.BrokerConstant;
import com.yihu.hos.models.SystemServiceEndpoint;
import com.yihu.hos.models.SystemServiceFlow;
import com.yihu.hos.models.SystemServiceFlowClass;
@ -18,7 +19,7 @@ public class BrokerDao {
    public List<SystemServiceFlow> getSystemServiceFlowList() throws Exception {
        List<SystemServiceFlow> systemServiceFlowList = new ArrayList<>();;
        String sql = "select * from system_service_flow";
        String sql = "select * from system_service_flow t where t.file_type='"+ BrokerConstant.CLASS +"'";
        List list = jdbcTemplate.queryForList(sql);
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
@ -39,7 +40,7 @@ public class BrokerDao {
    }
    public List<SystemServiceEndpoint> getSystemServiceEndpointList() throws Exception {
        List<SystemServiceEndpoint> systemServieEndpointList = new ArrayList<>();;
        List<SystemServiceEndpoint> systemServieEndpointList = new ArrayList<>();
        String sql = "select * from system_service_endpoint";
        List list = jdbcTemplate.queryForList(sql);
        Iterator iterator = list.iterator();

+ 9 - 0
hos-broker/src/main/java/com/yihu/hos/models/SystemServiceFlow.java

@ -18,10 +18,19 @@ public class SystemServiceFlow implements java.io.Serializable {
    private String description;
    private Integer valid;
    private Date createDate;
    private String fileType;
    private String flowClassList;
    private List<SystemServiceFlowClass> flowClassArray;
    public String getFileType() {
        return fileType;
    }
    public void setFileType(String fileType) {
        this.fileType = fileType;
    }
    public String getFlowClassList() {
        return flowClassList;
    }

+ 1 - 1
hos-broker/src/main/resources/application.yml

@ -47,7 +47,7 @@ spring:
    port: 8066
hos:
  arbiter:
    enable: false
    enable: true
    url: http://localhost:10135
  timer:
      period: 10000

+ 1 - 1
hos-camel/src/main/java/api/route/ApiRouteBulider.java

@ -10,7 +10,7 @@ import org.apache.camel.builder.RouteBuilder;
public class ApiRouteBulider extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("jetty:http://localhost:9090/api/v1").routeId("api")
        from("jetty:http://localhost:9091/api/v1").routeId("api")
                .process(new ApiProcessor());
    }
}

+ 54 - 0
hos-camel/src/main/java/api1/processor/ApiProcessor.java

@ -0,0 +1,54 @@
package api1.processor;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.http.common.HttpMessage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
 * @author Airhead
 * @since 2016-11-13
 */
public class ApiProcessor implements Processor {
    public void process(Exchange exchange) throws Exception {
        // 因为很明确消息格式是http的,所以才使用这个类
        // 否则还是建议使用org.apache.camel.Message这个抽象接口
        HttpMessage message = (HttpMessage) exchange.getIn();
        InputStream bodyStream = (InputStream) message.getBody();
        String inputContext = this.analysisMessage(bodyStream);
        bodyStream.close();
        // 存入到exchange的out区域
        if (exchange.getPattern() == ExchangePattern.InOut) {
            Message outMessage = exchange.getOut();
            outMessage.setBody("hello," + inputContext);
        }
    }
    /**
     * 从stream中分析字符串内容
     *
     * @param bodyStream
     * @return
     */
    private String analysisMessage(InputStream bodyStream) throws IOException {
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        byte[] contextBytes = new byte[4096];
        int realLen;
        while ((realLen = bodyStream.read(contextBytes, 0, 4096)) != -1) {
            outStream.write(contextBytes, 0, realLen);
        }
        // 返回从Stream中读取的字串
        try {
            return new String(outStream.toByteArray(), "UTF-8");
        } finally {
            outStream.close();
        }
    }
}

+ 16 - 0
hos-camel/src/main/java/api1/route/ApiRouteBulider.java

@ -0,0 +1,16 @@
package api1.route;
import api1.processor.ApiProcessor;
import org.apache.camel.builder.RouteBuilder;
/**
 * @author Airhead
 * @since 2016-11-13
 */
public class ApiRouteBulider extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("jetty:http://localhost:9090/api/v1").routeId("api1")
                .process(new ApiProcessor());
    }
}

+ 0 - 9
pom.xml

@ -27,11 +27,6 @@
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
@ -59,10 +54,6 @@
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-data-jpa</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>

+ 19 - 16
src/main/java/com/yihu/hos/monitor/service/ServiceMonitorService.java

@ -1,6 +1,7 @@
package com.yihu.hos.monitor.service;
import com.mongodb.*;
import com.yihu.hos.common.constants.Constants;
import com.yihu.hos.core.datatype.CollectionUtil;
import com.yihu.hos.monitor.dao.ServiceMonitorDao;
import com.yihu.hos.system.model.SystemServiceEndpoint;
@ -120,22 +121,24 @@ public class ServiceMonitorService {
        }
        for (SystemServiceFlow flow : flowList) {
            TreeView rootTree = new TreeView();
            rootTree.setIschecked(false);
            rootTree.setId("flow" + flow.getId());
            rootTree.setPid("-1");
            rootTree.setText(flow.getName());
            treeList.add(rootTree);
            List<String> endpointIdList = flowEndpointMap.get(flow.getId());
            if (!CollectionUtil.isEmpty(endpointIdList)) {
                for (String endpointId : endpointIdList) {
                    SystemServiceEndpoint endpoint = endpointMap.get(endpointId);
                    TreeView childTree = new TreeView();
                    childTree.setIschecked(false);
                    childTree.setId("endpoint" + endpoint.getId());
                    childTree.setPid("flow" + flow.getId());
                    childTree.setText(endpoint.getName());
                    treeList.add(childTree);
            if (flow.getFileType().equals(Constants.CLASS)) {
                TreeView rootTree = new TreeView();
                rootTree.setIschecked(false);
                rootTree.setId("flow" + flow.getId());
                rootTree.setPid("-1");
                rootTree.setText(flow.getName());
                treeList.add(rootTree);
                List<String> endpointIdList = flowEndpointMap.get(flow.getId());
                if (!CollectionUtil.isEmpty(endpointIdList)) {
                    for (String endpointId : endpointIdList) {
                        SystemServiceEndpoint endpoint = endpointMap.get(endpointId);
                        TreeView childTree = new TreeView();
                        childTree.setIschecked(false);
                        childTree.setId("endpoint" + endpoint.getId());
                        childTree.setPid("flow" + flow.getId());
                        childTree.setText(endpoint.getName());
                        treeList.add(childTree);
                    }
                }
            }
        }

+ 36 - 25
src/main/java/com/yihu/hos/system/service/FlowManager.java

@ -111,30 +111,46 @@ public class FlowManager implements IFlowManage {
        }else if (Constants.CLASS.equals(flow.getFileType())){
            List<Integer> classIds = flowClassDao.getFlowClassIds(obj.getId());//原flowclass集合
            List<SystemServiceFlowClass> flowClassList = obj.getFlowClassArray();
            SystemServiceFlowClass flowClassRoute = null;
            String oper = "";
            for (SystemServiceFlowClass flowClass:flowClassList){
                if (flowClass.getId()!=null) {
                    classIds.remove(flowClass.getId());
                    flowClassDao.updateEntity(flowClass);
                    sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_UPDATE);
                    if (!flowClass.getType().equals(Constants.FLOW_TYPE_ROUTE)) {
                        sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_UPDATE);
                    } else {
                        flowClassRoute = flowClass;
                        oper = Constants.FLOW_OP_UPDATE;
                    }
                }else {
                    flowClassDao.saveEntity(flowClass);
                    sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_ADD);
                    if (!flowClass.getType().equals(Constants.FLOW_TYPE_ROUTE)) {
                        flowClassDao.saveEntity(flowClass);
                        sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_ADD);
                    } else {
                        flowClassRoute = flowClass;
                        oper = Constants.FLOW_OP_ADD;
                    }
                }
            }
            //删除判断
            if (classIds !=null && classIds.size()>0){
                for (Integer id:classIds){
                    SystemServiceFlowClass flowClass = getFlowClassById(id);
                    flowClassDao.deleteEntity(flowClass);
                    sendDeleteMessage(flow.getCode(), flowClass);
                    if (!flowClass.getType().equals(Constants.FLOW_TYPE_ROUTE)) {
                        sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_DELETE);
                    } else {
                        flowClassRoute = flowClass;
                        oper = Constants.FLOW_OP_DELETE;
                    }
                }
            }
            if (flowClassRoute != null) {
                sendUpdateMessage(flow.getCode(), flowClassRoute, oper);
            }
        }
        flowDao.updateEntity(flow);
@ -146,11 +162,22 @@ public class FlowManager implements IFlowManage {
    public Result deleteFlow(Integer id) throws Exception {
        SystemServiceFlow flow = flowDao.getEntity(SystemServiceFlow.class, id);
        List<SystemServiceFlowClass> flowClassList = flowClassDao.getFlowClassByFlowId(id);
        SystemServiceFlowClass flowClassRoute = null;
        String oper = "";
        for (SystemServiceFlowClass flowClass:flowClassList){
            flowClassDao.deleteEntity(flowClass);
            //发送消息到MQ对列
            sendDeleteMessage(flow.getCode(), flowClass);
            if (!flowClass.getType().equals(Constants.FLOW_TYPE_ROUTE)) {
                sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_DELETE);
            } else {
                flowClassRoute = flowClass;
                oper = Constants.FLOW_OP_DELETE;
            }
        }
        if (flowClassRoute != null) {
            sendUpdateMessage(flow.getCode(), flowClassRoute, oper);
        }
        boolean succ = flowTempDao.deleteFlowTempByFlowId(id);
        flowDao.deleteEntity(flow);
        return Result.success("删除成功");
@ -250,22 +277,6 @@ public class FlowManager implements IFlowManage {
    }
    /**
     * 发送MQ消息-删除路由
     * @param flowCode 服务流程Code标识
     * @param flowClass
     */
    public  void sendDeleteMessage(String flowCode,SystemServiceFlowClass flowClass){
        //发送消息到MQ对列
        if ( Constants.FLOW_TYPE_ROUTE.equals(flowClass.getType())) {
            //route
            serviceFlowEventService.routeDefineDelete(flowCode, flowClass.getPackageName(), flowClass.getClassName());
        } else if (Constants.FLOW_TYPE_PROCESSOR.equals(flowClass.getType())) {
            //processor
            serviceFlowEventService.processorDataDeleted(flowCode, flowClass.getPackageName(), flowClass.getClassName(), flowClass.getClassPath());
        }
    }
    /**
     * 获取流程列表
     * @param type 流程的文件类型