chenweida 6 سال پیش
والد
کامیت
3cd6025af9

+ 13 - 0
admin/admin-server-starter/src/main/java/com/yihu/admin/server/manage/ServerHeart.java

@ -17,6 +17,7 @@ import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -48,6 +49,18 @@ public class ServerHeart implements Runnable {
                    MicroService microService = null;
                    if (microServices.containsKey(key)) {
                        microService = microServices.get(key);
                        List<InstanceInfo> instanceInfos = application.getInstancesAsIsFromEureka();
                        List<Server> servers=new ArrayList<>();
                        for (InstanceInfo instanceInfo : instanceInfos) {
                            Server server = new Server();
                            BeanUtils.copyProperties(instanceInfo, server);
                            server.setStatus(instanceInfo.getStatus().toString());
                            server.setIp(instanceInfo.getIPAddr());
                            server.setUuid(MD5.GetMD5Code(microService.getName() + "-" + instanceInfo.getInstanceId()));
                            logger.debug(server.toString());
                            servers.add(server);
                        }
                        microService.setServers(servers);
                    } else {
                        microService = new MicroService(application.getName());
                        List<InstanceInfo> instanceInfos = application.getInstancesAsIsFromEureka();

+ 12 - 1
common-data-es-starter/src/main/java/com/yihu/base/es/config/ElasticFactory.java

@ -17,6 +17,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
@ -49,6 +50,16 @@ public class ElasticFactory {
     * 初始化链接
     * 9200
     */
    @PostConstruct
    public void initAll() {
        try {
            init();
            initTranClient();
        } catch (UnknownHostException e) {
        }
    }
    public synchronized void init() {
        String[] hostArray = elasticSearchPorperties.getClusterNodesJest().split(",");
        // Construct a new Jest client according to configuration via factory
@ -90,7 +101,7 @@ public class ElasticFactory {
        if (transportClient == null) {
            String[] hosts = elasticSearchPorperties.getClusterNodes().split(",");
            Settings settings = Settings.settingsBuilder()
                     .put("client.transport.sniff", elasticSearchPorperties.getJestDiscoveryEnabled())//开启嗅探功能
                    .put("client.transport.sniff", elasticSearchPorperties.getJestDiscoveryEnabled())//开启嗅探功能
                    .put("cluster.name", StringUtils.isEmpty(elasticSearchPorperties.getClusterName()) ? "jkzl" : elasticSearchPorperties.getClusterName())//默认集群名字是jkzl
                    .build();