浏览代码

Merge branch 'master' of luofaqiang/esb into master

demon 8 年之前
父节点
当前提交
215efbf2f6

+ 2 - 2
hos-arbiter/src/main/java/com/yihu/hos/arbiter/listener/ApplicationStartListener.java

@ -21,7 +21,7 @@ public class ApplicationStartListener implements ApplicationListener<ContextRefr
    }
    public void arbiterServerStart(){
        arbiterServerService.start();
    public void arbiterServerStart() {
        arbiterServerService.start();   //后期可以统一到Router上来处理
    }
}

+ 17 - 0
hos-arbiter/src/main/java/com/yihu/hos/arbiter/routers/ArbiterServerRouter.java

@ -0,0 +1,17 @@
package com.yihu.hos.arbiter.routers;
import org.apache.camel.builder.RouteBuilder;
/**
 * @author Airhead
 * @since 2016/12/19.
 */
//因为配置问题,暂时服务启动,先屏蔽,才使用的是Spring的事件来注册的。
//@Component
public class ArbiterServerRouter  extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("direct:arbiterServer")
                .to("bean:arbiterServerService?method=start");
    }
}

+ 0 - 4
hos-arbiter/src/main/java/com/yihu/hos/arbiter/routers/SerivceHealthRouter.java

@ -1,8 +1,6 @@
package com.yihu.hos.arbiter.routers;
import com.yihu.hos.arbiter.configuration.ActivemqConfiguration;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
@ -10,8 +8,6 @@ import org.springframework.stereotype.Component;
 */
@Component
public class SerivceHealthRouter extends RouteBuilder {
    @Autowired
    private ActivemqConfiguration activemqConfiguration;
    @Override
    public void configure() throws Exception {
        from("timer:brokerServerOnline?period={{arbiter.timer.period}}")

+ 1 - 1
hos-arbiter/src/main/java/com/yihu/hos/arbiter/services/ArbiterServerService.java

@ -51,7 +51,7 @@ public class ArbiterServerService {
        arbiterServer.setUrl(configuration.getTerminalUrl());
        try {
            String jsonBody = objectMapper.writeValueAsString(arbiterServer);
            HTTPResponse response = HttpClientKit.post(configuration.getCentralUrl(), jsonBody);
            HTTPResponse response = HttpClientKit.post(configuration.getCentralUrl() + "/arbiter", jsonBody);
            if (response.getStatusCode() != 200) {
                logger.error("register terminal arbiter server failed");
            }

+ 1 - 1
hos-arbiter/src/main/java/com/yihu/hos/arbiter/services/ServiceFlowService.java

@ -345,7 +345,7 @@ public class ServiceFlowService {
        String tenant = header.get("tenant");
        ArbiterServer arbiterServer = arbiterServerService.get(tenant);
        header.remove("tenant");
        HttpClientKit.post(arbiterServer.getUrl(), msg, header);
        HttpClientKit.post(arbiterServer.getUrl() + "/proxy", msg, header);
    }
    private boolean sendMessage(BrokerServer brokerServer, String method, String path, String msg) {

+ 5 - 5
hos-arbiter/src/main/resources/application.yml

@ -79,22 +79,22 @@ spring:
  profiles: lfq
  data:
    mongodb:
      host: 172.19.103.86
      host: 172.19.103.58
      port: 27017
      username: esb
      password: esb
      authenticationDatabase: admin
      database: configuration
  activemq:
    broker-url: tcp://172.19.103.86:61616
    broker-url: tcp://172.19.103.58:61616
    user: admin
    password: admin
arbiter:
  timer:
      period: 10000
  central:
    url:
    url: http://192.168.131.119:10135
  terminal:
    url: http://127.0.0.1:10135
    url: http://192.168.131.38:10135
  tenant:
    name: jkzl
    name: yichang

+ 21 - 30
hos-broker/src/main/java/com/yihu/hos/broker/common/scheduler/MonitorScheduler.java

@ -3,14 +3,13 @@ package com.yihu.hos.broker.common.scheduler;
import com.mongodb.*;
import com.yihu.hos.broker.common.constants.MonitorConstant;
import com.yihu.hos.broker.daos.BrokerDao;
import com.yihu.hos.broker.util.MongodbUtil;
import com.yihu.hos.broker.models.SystemServiceEndpoint;
import com.yihu.hos.broker.models.SystemServiceFlow;
import com.yihu.hos.broker.services.ServiceMonitorService;
import com.yihu.hos.broker.util.SigarUtil;
import com.yihu.hos.core.datatype.DateUtil;
import com.yihu.hos.core.log.Logger;
import com.yihu.hos.core.log.LoggerFactory;
import com.yihu.hos.broker.models.SystemServiceEndpoint;
import com.yihu.hos.broker.models.SystemServiceFlow;
import com.yihu.hos.broker.services.ServiceMonitorService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.bson.Document;
@ -36,17 +35,14 @@ import java.util.List;
@Component
public class MonitorScheduler {
    static private final Logger logger = LoggerFactory.getLogger(MonitorScheduler.class);
    private static String host = SigarUtil.getHost();
    @Value("${hos.tenant.name}")
    private String tenant;
    @Autowired
    private MongoOperations mongoOperations;
    @Autowired
    private Mongo mongo;
    static private final Logger logger = LoggerFactory.getLogger(MonitorScheduler.class);
    private static String host = SigarUtil.getHost();
    @Resource(name = ServiceMonitorService.BEAN_ID)
    private ServiceMonitorService serviceMonitorService;
    @Autowired
@ -67,41 +63,45 @@ public class MonitorScheduler {
    /**
     * 服务器健康指标采集
     *
     * @return
     */
    public String collectEnvHealth() {
        try {
            MongodbUtil monoEnv = new MongodbUtil(MonitorConstant.MONITOR);
            mongoOperations = new MongoTemplate(mongo, MonitorConstant.MONITOR);
            Document result = null;
            result = new Document();
            result.put("tenant",tenant);
            result.put("tenant", tenant);
            result.put("create_date", DateUtil.getCurrentString(DateUtil.DEFAULT_YMDHMSDATE_FORMAT));
            result.put("create_time", new Date());
            result.put("host",host);
            result.put("host", host);
            //cpu
            JSONObject cpu = JSONObject.fromObject(SigarUtil.cpu());
            result.put("data", cpu);
            result.put("type", MonitorConstant.CPU);
            monoEnv.insert(MonitorConstant.SERVER, result);
            mongoOperations.insert(result, MonitorConstant.SERVER);
            //内存
            JSONObject memory = JSONObject.fromObject(SigarUtil.memory());
            result.put("data", memory);
            result.put("type", MonitorConstant.MEMORY);
            result.remove("_id");
            monoEnv.insert(MonitorConstant.SERVER, result);
            mongoOperations.insert(result, MonitorConstant.SERVER);
            //硬盘
            List<JSONObject> files = JSONArray.fromObject(SigarUtil.file());
            result.put("data", files);
            result.put("type", MonitorConstant.FILES);
            result.remove("_id");
            monoEnv.insert(MonitorConstant.SERVER, result);
            mongoOperations.insert(result, MonitorConstant.SERVER);
            //网络
            JSONObject net = JSONObject.fromObject(SigarUtil.net());
            result.put("data", net);
            result.put("type", MonitorConstant.NET);
            result.remove("_id");
            monoEnv.insert(MonitorConstant.SERVER, result);
            mongoOperations.insert(result, MonitorConstant.SERVER);
        } catch (Exception e) {
            e.printStackTrace();
@ -131,21 +131,12 @@ public class MonitorScheduler {
        serviceMonitorService.usage(beginTime, endTime, codeList);
    }
//    @Scheduled(fixedRate=10000)
//    public void testTasks() {
//        logger.info("每10秒执行一次。开始……");
//        //statusTask.healthCheck();
//        logger.info("每10秒执行一次。结束。");
//    }
    /**
     * 服务器列表保存
     */
//    @Scheduled(cron = "0 0 12 * * ?") //每天中午12点触发
    @Scheduled(fixedDelay = 3600*24*1000,initialDelay=3000) //每天中午12点触发
    @Scheduled(fixedDelay = 3600 * 24 * 1000, initialDelay = 3000) //每天中午12点触发
    public void checkHost() {
        MongodbUtil monoEnv = new MongodbUtil(MonitorConstant.MONITOR);
        mongoOperations = new MongoTemplate(mongo, MonitorConstant.MONITOR);
        DBCollection envCollection = mongoOperations.getCollection(MonitorConstant.HOST);
        BasicDBObject queryObject = new BasicDBObject().append(QueryOperators.AND,
@ -159,10 +150,10 @@ public class MonitorScheduler {
                Document result = new Document();
                String host = SigarUtil.getHost();
                String hostName = SigarUtil.getHostName();
                result.put("tenant",tenant);
                result.put("name",  hostName);
                result.put("host",  host);
                monoEnv.insert(MonitorConstant.HOST, result);
                result.put("tenant", tenant);
                result.put("name", hostName);
                result.put("host", host);
                mongoOperations.insert(result, MonitorConstant.HOST);
            } catch (Exception e) {
                e.printStackTrace();
            }

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

@ -101,9 +101,9 @@ spring:
  profiles: lfq
  datasource:
      driverClassName: com.mysql.jdbc.Driver
      url: jdbc:mysql://192.168.1.220:3306/esb?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true
      username: hos2
      password: hos2
      url: jdbc:mysql://172.19.103.51:3306/db1?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true
      username: canal
      password: canal
      test-on-borrow: true
      validation-query: SELECT 1
      test-while-idle: true
@ -113,12 +113,12 @@ spring:
      min-idle: 10
      initial-size: 10
  activemq:
      broker-url: tcp://172.19.103.86:61616
      broker-url: tcp://172.19.103.58:61616
      user: admin
      password: admin
  data:
    mongodb:
      host: 172.19.103.86
      host: 172.19.103.58
      port: 27017
      username: esb
      password: esb

+ 0 - 8
hos-broker/src/main/resources/config/dbhelper.properties

@ -1,8 +0,0 @@
defaultName = hos-mysql
defaultUri = jdbc:mysql://172.19.103.71:3306/esb?useUnicode=true&characterEncoding=UTF-8
defaultUser = hos
defaultPassword = hos
mongodbUri=mongodb://esb:esb@172.19.103.86:27017/?authSource=admin
mongodbName=hos