Commit 1609e01d by ankeway Committed by GitHub

Merge pull request #1 from Nepxion/master

更新数据
parents 66ca58f0 199c98ce
......@@ -2,6 +2,7 @@
*.class
.classpath
.springBeans
.factorypath
# Mobile Tools for Java (J2ME)
.mtj.tmp/
......@@ -9,6 +10,7 @@
*.classpath
*.project
*.springBeans
bin/
log/
test-output/
......
language: java
jdk:
- oraclejdk8
\ No newline at end of file
- openjdk8
\ No newline at end of file
Nepxion Discovery
Copyright 2017-2050 The Nepxion Studio
This product includes software developed at
The Nepxion Studio (http://www.nepxion.com).
\ No newline at end of file
......@@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2010-2050 The Nepxion Studio
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
......
......@@ -15,6 +15,6 @@
@title Nepxion Discovery
@color 0a
call mvn clean deploy -DskipTests -e -P release -pl discovery-plugin-starter-eureka,discovery-plugin-starter-consul,discovery-plugin-starter-zookeeper,discovery-console-starter,discovery-plugin-config-center-extension-nacos,discovery-console-extension-nacos -am
call mvn clean deploy -DskipTests -e -P release -pl discovery-plugin-starter-eureka,discovery-plugin-starter-consul,discovery-plugin-starter-zookeeper,discovery-plugin-starter-nacos,discovery-plugin-config-center-starter-apollo,discovery-plugin-config-center-starter-nacos,discovery-plugin-config-center-starter-redis,discovery-console-starter-apollo,discovery-console-starter-nacos,discovery-console-starter-redis,discovery-plugin-strategy-starter-service,discovery-plugin-strategy-starter-zuul,discovery-plugin-strategy-starter-gateway,discovery-plugin-strategy-starter-hystrix -am
pause
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>discovery-common-apollo</artifactId>
<name>Nepxion Discovery Common Apollo</name>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<description>Nepxion Discovery is an enhancement for Spring Cloud Discovery</description>
<url>http://www.nepxion.com</url>
<parent>
<groupId>com.nepxion</groupId>
<artifactId>discovery</artifactId>
<version>5.0.5</version>
</parent>
<dependencies>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.nepxion.discovery.common.apollo.configuration;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import com.nepxion.discovery.common.apollo.constant.ApolloConstant;
import com.nepxion.discovery.common.apollo.operation.ApolloOperation;
@Configuration
public class ApolloAutoConfiguration {
@Autowired
private Environment environment;
@Bean
@ConditionalOnMissingBean
public Config apolloConfig() {
String namespace = environment.getProperty(ApolloConstant.APOLLO_PLUGIN_NAMESPACE);
if (StringUtils.isNotEmpty(namespace)) {
return ConfigService.getConfig(namespace);
} else {
return ConfigService.getAppConfig();
}
}
@Bean
public ApolloOperation apolloOperation() {
return new ApolloOperation();
}
}
\ No newline at end of file
package com.nepxion.discovery.common.apollo.constant;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import com.ctrip.framework.apollo.core.ConfigConsts;
public class ApolloConstant implements ConfigConsts {
public static final String TYPE = "Apollo";
public static final String APOLLO_PLUGIN_NAMESPACE = "apollo.plugin.namespace";
}
\ No newline at end of file
package com.nepxion.discovery.common.apollo.operation;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import org.springframework.beans.factory.annotation.Autowired;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigChangeListener;
import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.google.common.collect.Sets;
public class ApolloOperation {
@Autowired
private Config apolloConfig;
public String getConfig(String group, String serviceId) {
return apolloConfig.getProperty(group + "-" + serviceId, null);
}
public ConfigChangeListener subscribeConfig(String group, String serviceId, ApolloSubscribeCallback subscribeCallback) {
ConfigChangeListener configListener = new ConfigChangeListener() {
@Override
public void onChange(ConfigChangeEvent changeEvent) {
ConfigChange change = changeEvent.getChange(group + "-" + serviceId);
String config = change.getNewValue();
subscribeCallback.callback(config);
}
};
apolloConfig.addChangeListener(configListener, Sets.newHashSet(group + "-" + serviceId));
return configListener;
}
public void unsubscribeConfig(String group, String serviceId, ConfigChangeListener configListener) {
apolloConfig.removeChangeListener(configListener);
}
}
\ No newline at end of file
package com.nepxion.discovery.plugin.configcenter.extension.nacos.constant;
package com.nepxion.discovery.common.apollo.operation;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -9,8 +9,6 @@ package com.nepxion.discovery.plugin.configcenter.extension.nacos.constant;
* @version 1.0
*/
public class NacosConstant {
public static final String URL_KEY = "serverAddr";
public static final String URL = "nacos.url";
public static final String TIMEOUT = "nacos.timout";
public interface ApolloSubscribeCallback {
void callback(String config);
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>discovery-console-extension-nacos</artifactId>
<name>Nepxion Discovery Console Extension Nacos</name>
<artifactId>discovery-common-nacos</artifactId>
<name>Nepxion Discovery Common Nacos</name>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<description>Nepxion Discovery is an enhancement for Spring Cloud Discovery</description>
......@@ -11,18 +11,18 @@
<parent>
<groupId>com.nepxion</groupId>
<artifactId>discovery</artifactId>
<version>4.1.0</version>
<version>5.0.5</version>
</parent>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>discovery-console</artifactId>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.nepxion.discovery.common.nacos.configuration;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import com.nepxion.discovery.common.nacos.constant.NacosConstant;
import com.nepxion.discovery.common.nacos.operation.NacosOperation;
@Configuration
public class NacosAutoConfiguration {
@Autowired
private Environment environment;
@Bean
@ConditionalOnMissingBean
public ConfigService nacosConfigService() throws NacosException {
Properties properties = new Properties();
String serverAddr = environment.getProperty(NacosConstant.NACOS_SERVER_ADDR);
if (StringUtils.isNotEmpty(serverAddr)) {
properties.put(NacosConstant.SERVER_ADDR, serverAddr);
} else {
throw new IllegalArgumentException(NacosConstant.NACOS_SERVER_ADDR + " can't be null or empty");
}
String accessKey = environment.getProperty(NacosConstant.NACOS_ACCESS_KEY);
if (StringUtils.isNotEmpty(accessKey)) {
properties.put(NacosConstant.ACCESS_KEY, accessKey);
}
String secretKey = environment.getProperty(NacosConstant.NACOS_SECRET_KEY);
if (StringUtils.isNotEmpty(secretKey)) {
properties.put(NacosConstant.SECRET_KEY, secretKey);
}
String namespace = environment.getProperty(NacosConstant.NACOS_PLUGIN_NAMESPACE);
if (StringUtils.isNotEmpty(namespace)) {
properties.put(NacosConstant.NAMESPACE, namespace);
}
String clusterName = environment.getProperty(NacosConstant.NACOS_PLUGIN_CLUSTER_NAME);
if (StringUtils.isNotEmpty(clusterName)) {
properties.put(NacosConstant.CLUSTER_NAME, clusterName);
}
String contextPath = environment.getProperty(NacosConstant.NACOS_PLUGIN_CONTEXT_PATH);
if (StringUtils.isNotEmpty(contextPath)) {
properties.put(NacosConstant.CONTEXT_PATH, contextPath);
}
String endpoint = environment.getProperty(NacosConstant.NACOS_PLUGIN_ENDPOINT);
if (StringUtils.isNotEmpty(endpoint)) {
properties.put(NacosConstant.ENDPOINT, endpoint);
}
String encode = environment.getProperty(NacosConstant.NACOS_PLUGIN_ENCODE);
if (StringUtils.isNotEmpty(encode)) {
properties.put(NacosConstant.ENCODE, encode);
}
String namingLoadCacheAtStart = environment.getProperty(NacosConstant.NACOS_PLUGIN_NAMING_LOAD_CACHE_AT_START);
if (StringUtils.isNotEmpty(namingLoadCacheAtStart)) {
properties.put(NacosConstant.NAMING_LOAD_CACHE_AT_START, namingLoadCacheAtStart);
}
return NacosFactory.createConfigService(properties);
}
@Bean
public NacosOperation nacosOperation() {
return new NacosOperation();
}
}
\ No newline at end of file
package com.nepxion.discovery.common.nacos.constant;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import com.alibaba.nacos.api.PropertyKeyConst;
public class NacosConstant extends PropertyKeyConst {
public static final String TYPE = "Nacos";
public static final String NACOS_SERVER_ADDR = "nacos.server-addr";
public static final String NACOS_ACCESS_KEY = "nacos.access-key";
public static final String NACOS_SECRET_KEY = "nacos.secret-key";
public static final String NACOS_PLUGIN_NAMESPACE = "nacos.plugin.namespace";
public static final String NACOS_PLUGIN_CLUSTER_NAME = "nacos.plugin.cluster-name";
public static final String NACOS_PLUGIN_CONTEXT_PATH = "nacos.plugin.context-path";
public static final String NACOS_PLUGIN_ENDPOINT = "nacos.plugin.endpoint";
public static final String NACOS_PLUGIN_ENCODE = "nacos.plugin.encode";
public static final String NACOS_PLUGIN_NAMING_LOAD_CACHE_AT_START = "nacos.plugin.naming-load-cache-at-start";
public static final String NACOS_PLUGIN_TIMEOUT = "nacos.plugin.timout";
public static final long DEFAULT_TIMEOUT = 30000;
}
\ No newline at end of file
package com.nepxion.discovery.common.nacos.operation;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import java.util.concurrent.Executor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.Listener;
import com.alibaba.nacos.api.exception.NacosException;
import com.nepxion.discovery.common.nacos.constant.NacosConstant;
public class NacosOperation {
@Autowired
private ConfigService nacosConfigService;
@Autowired
private Environment environment;
public String getConfig(String group, String serviceId) throws NacosException {
long timeout = environment.getProperty(NacosConstant.NACOS_PLUGIN_TIMEOUT, Long.class, NacosConstant.DEFAULT_TIMEOUT);
return nacosConfigService.getConfig(serviceId, group, timeout);
}
public boolean removeConfig(String group, String serviceId) throws NacosException {
return nacosConfigService.removeConfig(serviceId, group);
}
public boolean publishConfig(String group, String serviceId, String config) throws NacosException {
return nacosConfigService.publishConfig(serviceId, group, config);
}
public Listener subscribeConfig(String group, String serviceId, Executor executor, NacosSubscribeCallback subscribeCallback) throws NacosException {
Listener configListener = new Listener() {
@Override
public void receiveConfigInfo(String config) {
subscribeCallback.callback(config);
}
@Override
public Executor getExecutor() {
return executor;
}
};
nacosConfigService.addListener(serviceId, group, configListener);
return configListener;
}
public void unsubscribeConfig(String group, String serviceId, Listener configListener) {
nacosConfigService.removeListener(serviceId, group, configListener);
}
}
\ No newline at end of file
package com.nepxion.discovery.console.constant;
package com.nepxion.discovery.common.nacos.operation;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -9,7 +9,6 @@ package com.nepxion.discovery.console.constant;
* @version 1.0
*/
public class ConsoleConstant {
public static final String SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED = "spring.application.discovery.control.enabled";
public static final String SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED = "spring.application.config.rest.control.enabled";
public interface NacosSubscribeCallback {
void callback(String config);
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>discovery-common-redis</artifactId>
<name>Nepxion Discovery Common Redis</name>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<description>Nepxion Discovery is an enhancement for Spring Cloud Discovery</description>
<url>http://www.nepxion.com</url>
<parent>
<groupId>com.nepxion</groupId>
<artifactId>discovery</artifactId>
<version>5.0.5</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.nepxion.discovery.console.extension.nacos.configuration;
package com.nepxion.discovery.common.redis.configuration;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -6,40 +6,30 @@ package com.nepxion.discovery.console.extension.nacos.configuration;
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @author JiKai Sun
* @version 1.0
*/
import java.util.Properties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import com.nepxion.discovery.console.extension.nacos.adapter.NacosConfigAdapter;
import com.nepxion.discovery.console.extension.nacos.constant.NacosConstant;
import com.nepxion.discovery.console.remote.ConfigAdapter;
import com.nepxion.discovery.common.redis.operation.RedisOperation;
@Configuration
public class NacosConfigConfiguration {
public class RedisAutoConfiguration {
@Autowired
private Environment environment;
private StringRedisTemplate stringRedisTemplate;
@Bean
public ConfigService configService() throws NacosException {
String url = environment.getProperty(NacosConstant.URL);
Properties properties = new Properties();
properties.put(NacosConstant.URL_KEY, url);
return NacosFactory.createConfigService(properties);
public HashOperations<String, String, String> hashOperations() {
return stringRedisTemplate.opsForHash();
}
@Bean
public ConfigAdapter configAdapter() throws NacosException {
return new NacosConfigAdapter();
public RedisOperation redisOperation() {
return new RedisOperation();
}
}
\ No newline at end of file
package com.nepxion.discovery.plugin.example.extension;
package com.nepxion.discovery.common.redis.constant;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -6,17 +6,10 @@ package com.nepxion.discovery.plugin.example.extension;
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @author JiKai Sun
* @version 1.0
*/
import com.google.common.eventbus.Subscribe;
import com.nepxion.discovery.plugin.framework.event.RegisterFailureEvent;
import com.nepxion.eventbus.annotation.EventBus;
@EventBus
public class MySubscriber {
@Subscribe
public void onRegisterFailure(RegisterFailureEvent registerFailureEvent) {
System.out.println("========== 注册失败:eventType=" + registerFailureEvent.getEventType() + ", eventDescription=" + registerFailureEvent.getEventDescription() + ", serviceId=" + registerFailureEvent.getServiceId() + ", host=" + registerFailureEvent.getHost() + ", port=" + registerFailureEvent.getPort());
}
public class RedisConstant {
public static final String TYPE = "Redis";
}
\ No newline at end of file
package com.nepxion.discovery.common.redis.operation;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @author JiKai Sun
* @version 1.0
*/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
public class RedisOperation {
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Autowired
private HashOperations<String, String, String> hashOperations;
public String getConfig(String group, String serviceId) {
return hashOperations.get(group, serviceId);
}
public boolean removeConfig(String group, String serviceId) {
publishConfig(group, serviceId, "");
return hashOperations.delete(group, serviceId) == 1;
}
public boolean publishConfig(String group, String serviceId, String config) {
hashOperations.put(group, serviceId, config);
stringRedisTemplate.convertAndSend(group + "-" + serviceId, config);
return true;
}
public void subscribeConfig(String config, RedisSubscribeCallback redisSubscribeCallback) {
redisSubscribeCallback.callback(config);
}
}
\ No newline at end of file
package com.nepxion.discovery.common.redis.operation;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @author JiKai Sun
* @version 1.0
*/
public interface RedisSubscribeCallback {
void callback(String config);
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>discovery-common</artifactId>
<name>Nepxion Discovery Common</name>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<description>Nepxion Discovery is an enhancement for Spring Cloud Discovery</description>
<url>http://www.nepxion.com</url>
<parent>
<groupId>com.nepxion</groupId>
<artifactId>discovery</artifactId>
<version>5.0.5</version>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.nepxion.discovery.plugin.framework.constant;
package com.nepxion.discovery.common.constant;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -9,27 +9,51 @@ package com.nepxion.discovery.plugin.framework.constant;
* @version 1.0
*/
public class PluginConstant {
public class DiscoveryConstant {
public static final String DISCOVERY_VERSION = "5.0.5";
public static final String SPRING_APPLICATION_DISCOVERY_PLUGIN = "spring.application.discovery.plugin";
public static final String SPRING_APPLICATION_DISCOVERY_VERSION = "spring.application.discovery.version";
public static final String SPRING_APPLICATION_REGISTER_CONTROL_ENABLED = "spring.application.register.control.enabled";
public static final String SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED = "spring.application.discovery.control.enabled";
public static final String SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED = "spring.application.config.rest.control.enabled";
public static final String SPRING_APPLICATION_CONFIG_FORMAT = "spring.application.config.format";
public static final String SPRING_APPLICATION_CONFIG_PATH = "spring.application.config.path";
public static final String SPRING_APPLICATION_GROUP_KEY = "spring.application.group.key";
public static final String SPRING_APPLICATION_CONTEXT_PATH = "spring.application.context-path";
public static final String SPRING_APPLICATION_NAME = "spring.application.name";
public static final String GROUP = "group";
public static final String SERVICE_ID = "serviceId";
public static final String HOST = "host";
public static final String PORT = "port";
public static final String METADATA = "metadata";
public static final String REGION = "region";
public static final String VERSION = "version";
public static final String DYNAMIC_VERSION = "dynamicVersion";
public static final String RULE = "rule";
public static final String DYNAMIC_RULE = "dynamicRule";
public static final String REACH_MAX_LIMITED_COUNT = "reach max limited count";
public static final String N_D_REGION = "n-d-region";
public static final String N_D_VERSION = "n-d-version";
public static final String N_D_ADDRESS = "n-d-address";
public static final String XML_FORMAT = "xml";
public static final String JSON_FORMAT = "json";
public static final String PREFIX_CLASSPATH = "classpath:";
public static final String PREFIX_FILE = "file:";
public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
public static final String ENCODING_UTF_8 = "UTF-8";
public static final String SEPARATE = ";";
public static final String ASYNC = "async";
public static final String SYNC = "sync";
public static final String GLOBAL = "global";
public static final String PARTIAL = "partial";
public static final String OK = "OK";
public static final String NO = "NO";
public static final String UNKNOWN = "UNKNOWN";
public static final String EXT = "ext";
}
\ No newline at end of file
package com.nepxion.discovery.plugin.framework.entity;
package com.nepxion.discovery.common.entity;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -24,10 +24,6 @@ public class CountFilterEntity implements Serializable {
private Integer filterValue;
private Map<String, Integer> filterMap = new LinkedHashMap<String, Integer>();
public CountFilterEntity() {
}
public Integer getFilterValue() {
return filterValue;
}
......
package com.nepxion.discovery.common.entity;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
public class CustomizationEntity implements Serializable {
private static final long serialVersionUID = -5135099669922746855L;
private Map<String, Map<String, String>> customizationMap = new LinkedHashMap<String, Map<String, String>>();
public Map<String, Map<String, String>> getCustomizationMap() {
return customizationMap;
}
public void setCustomizationMap(Map<String, Map<String, String>> customizationMap) {
this.customizationMap = customizationMap;
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
@Override
public boolean equals(Object object) {
return EqualsBuilder.reflectionEquals(this, object);
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}
\ No newline at end of file
package com.nepxion.discovery.plugin.framework.entity;
package com.nepxion.discovery.common.entity;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -13,10 +13,7 @@ public class DiscoveryEntity extends FilterHolderEntity {
private static final long serialVersionUID = -7417362859952278987L;
private VersionFilterEntity versionFilterEntity;
public DiscoveryEntity() {
}
private WeightFilterEntity weightFilterEntity;
public VersionFilterEntity getVersionFilterEntity() {
return versionFilterEntity;
......@@ -25,4 +22,12 @@ public class DiscoveryEntity extends FilterHolderEntity {
public void setVersionFilterEntity(VersionFilterEntity versionFilterEntity) {
this.versionFilterEntity = versionFilterEntity;
}
public WeightFilterEntity getWeightFilterEntity() {
return weightFilterEntity;
}
public void setWeightFilterEntity(WeightFilterEntity weightFilterEntity) {
this.weightFilterEntity = weightFilterEntity;
}
}
\ No newline at end of file
package com.nepxion.discovery.plugin.framework.entity;
package com.nepxion.discovery.common.entity;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -21,10 +21,6 @@ public class FilterHolderEntity implements Serializable {
private HostFilterEntity hostFilterEntity;
public FilterHolderEntity() {
}
public HostFilterEntity getHostFilterEntity() {
return hostFilterEntity;
}
......
package com.nepxion.discovery.plugin.framework.entity;
package com.nepxion.discovery.common.entity;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -10,8 +10,8 @@ package com.nepxion.discovery.plugin.framework.entity;
*/
public enum FilterType {
BLACKLIST("blacklist", "黑名单"),
WHITELIST("whitelist", "白名单");
BLACKLIST("blacklist", "blacklist"),
WHITELIST("whitelist", "whitelist");
private String value;
private String description;
......
package com.nepxion.discovery.plugin.framework.entity;
package com.nepxion.discovery.common.entity;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -26,10 +26,6 @@ public class HostFilterEntity implements Serializable {
private List<String> filterValueList;
private Map<String, List<String>> filterMap = new LinkedHashMap<String, List<String>>();
public HostFilterEntity() {
}
public FilterType getFilterType() {
return filterType;
}
......
package com.nepxion.discovery.console.entity;
package com.nepxion.discovery.common.entity;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -22,9 +22,10 @@ public class InstanceEntity implements Serializable {
private String serviceId;
private String version;
private String region;
private String host;
private int port;
private Map<String, String> metaData;
private Map<String, String> metadata;
public String getServiceId() {
return serviceId;
......@@ -42,6 +43,14 @@ public class InstanceEntity implements Serializable {
this.version = version;
}
public String getRegion() {
return region;
}
public void setRegion(String region) {
this.region = region;
}
public String getHost() {
return host;
}
......@@ -58,12 +67,12 @@ public class InstanceEntity implements Serializable {
this.port = port;
}
public Map<String, String> getMetaData() {
return metaData;
public Map<String, String> getMetadata() {
return metadata;
}
public void setMetaData(Map<String, String> metaData) {
this.metaData = metaData;
public void setMetadata(Map<String, String> metadata) {
this.metadata = metadata;
}
@Override
......
package com.nepxion.discovery.common.entity;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import com.nepxion.discovery.common.constant.DiscoveryConstant;
public class InstanceEntityWrapper {
public static String getContextPath(InstanceEntity instanceEntity) {
Map<String, String> metadata = instanceEntity.getMetadata();
return metadata.get(DiscoveryConstant.SPRING_APPLICATION_CONTEXT_PATH);
}
public static String getGroup(InstanceEntity instanceEntity) {
Map<String, String> metadata = instanceEntity.getMetadata();
String groupKey = metadata.get(DiscoveryConstant.SPRING_APPLICATION_GROUP_KEY);
if (StringUtils.isEmpty(groupKey)) {
return StringUtils.EMPTY;
}
String filter = metadata.get(groupKey);
if (filter == null) {
return StringUtils.EMPTY;
}
return filter;
}
public static String getPlugin(InstanceEntity instanceEntity) {
Map<String, String> metadata = instanceEntity.getMetadata();
String plugin = metadata.get(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_PLUGIN);
if (plugin == null) {
return StringUtils.EMPTY;
}
return plugin;
}
public static boolean isRegisterControlEnabled(InstanceEntity instanceEntity) {
Map<String, String> metadata = instanceEntity.getMetadata();
String flag = metadata.get(DiscoveryConstant.SPRING_APPLICATION_REGISTER_CONTROL_ENABLED);
if (flag == null) {
return true;
}
return Boolean.valueOf(flag);
}
public static boolean isDiscoveryControlEnabled(InstanceEntity instanceEntity) {
Map<String, String> metadata = instanceEntity.getMetadata();
String flag = metadata.get(DiscoveryConstant.SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED);
if (flag == null) {
return true;
}
return Boolean.valueOf(flag);
}
public static boolean isConfigRestControlEnabled(InstanceEntity instanceEntity) {
Map<String, String> metadata = instanceEntity.getMetadata();
String flag = metadata.get(DiscoveryConstant.SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED);
if (flag == null) {
return true;
}
return Boolean.valueOf(flag);
}
}
\ No newline at end of file
package com.nepxion.discovery.console.entity;
package com.nepxion.discovery.common.entity;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -10,32 +10,24 @@ package com.nepxion.discovery.console.entity;
*/
import java.io.Serializable;
import java.util.Map;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
public class ResultEntity implements Serializable {
private static final long serialVersionUID = -3322655604556025836L;
public class RegionWeightEntity implements Serializable {
private static final long serialVersionUID = 3356648245119125011L;
private String url;
private String result;
private Map<String, Integer> weightMap;
public String getUrl() {
return url;
public Map<String, Integer> getWeightMap() {
return weightMap;
}
public void setUrl(String url) {
this.url = url;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
public void setWeightMap(Map<String, Integer> weightMap) {
this.weightMap = weightMap;
}
@Override
......
package com.nepxion.discovery.plugin.framework.entity;
package com.nepxion.discovery.common.entity;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -14,10 +14,6 @@ public class RegisterEntity extends FilterHolderEntity {
private CountFilterEntity countFilterEntity;
public RegisterEntity() {
}
public CountFilterEntity getCountFilterEntity() {
return countFilterEntity;
}
......
package com.nepxion.discovery.console.desktop.entity;
package com.nepxion.discovery.common.entity;
/**
* <p>Title: Nepxion Discovery</p>
......
package com.nepxion.discovery.console.desktop.entity;
package com.nepxion.discovery.common.entity;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -12,6 +12,7 @@ package com.nepxion.discovery.console.desktop.entity;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
......@@ -23,8 +24,12 @@ public class RouterEntity implements Serializable {
private String serviceId;
private String version;
private String region;
private String host;
private int port;
private int weight = -1;
private Map<String, String> customMap;
private String contextPath;
private List<RouterEntity> nexts = new ArrayList<RouterEntity>();
......@@ -44,6 +49,14 @@ public class RouterEntity implements Serializable {
this.version = version;
}
public String getRegion() {
return region;
}
public void setRegion(String region) {
this.region = region;
}
public String getHost() {
return host;
}
......@@ -60,6 +73,30 @@ public class RouterEntity implements Serializable {
this.port = port;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public Map<String, String> getCustomMap() {
return customMap;
}
public void setCustomMap(Map<String, String> customMap) {
this.customMap = customMap;
}
public String getContextPath() {
return contextPath;
}
public void setContextPath(String contextPath) {
this.contextPath = contextPath;
}
public List<RouterEntity> getNexts() {
return nexts;
}
......
package com.nepxion.discovery.plugin.framework.entity;
package com.nepxion.discovery.common.entity;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -21,6 +21,8 @@ public class RuleEntity implements Serializable {
private RegisterEntity registerEntity;
private DiscoveryEntity discoveryEntity;
private StrategyEntity strategyEntity;
private CustomizationEntity customizationEntity;
private String content;
public RegisterEntity getRegisterEntity() {
......@@ -39,6 +41,22 @@ public class RuleEntity implements Serializable {
this.discoveryEntity = discoveryEntity;
}
public CustomizationEntity getCustomizationEntity() {
return customizationEntity;
}
public void setCustomizationEntity(CustomizationEntity customizationEntity) {
this.customizationEntity = customizationEntity;
}
public StrategyEntity getStrategyEntity() {
return strategyEntity;
}
public void setStrategyEntity(StrategyEntity strategyEntity) {
this.strategyEntity = strategyEntity;
}
public String getContent() {
return content;
}
......
package com.nepxion.discovery.common.entity;
import java.io.Serializable;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
public class StrategyEntity implements Serializable {
private static final long serialVersionUID = -588258474716367451L;
private String versionValue;
private String regionValue;
private String addressValue;
public String getVersionValue() {
return versionValue;
}
public void setVersionValue(String versionValue) {
this.versionValue = versionValue;
}
public String getRegionValue() {
return regionValue;
}
public void setRegionValue(String regionValue) {
this.regionValue = regionValue;
}
public String getAddressValue() {
return addressValue;
}
public void setAddressValue(String addressValue) {
this.addressValue = addressValue;
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
@Override
public boolean equals(Object object) {
return EqualsBuilder.reflectionEquals(this, object);
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}
\ No newline at end of file
package com.nepxion.discovery.common.entity;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
public class UserEntity {
private String userId;
private String password;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
@Override
public boolean equals(Object object) {
return EqualsBuilder.reflectionEquals(this, object);
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}
\ No newline at end of file
package com.nepxion.discovery.plugin.framework.entity;
package com.nepxion.discovery.common.entity;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -17,7 +17,7 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
public class DiscoveryServiceEntity implements Serializable {
public class VersionEntity implements Serializable {
private static final long serialVersionUID = 9074414583796627542L;
private String consumerServiceName;
......@@ -25,10 +25,6 @@ public class DiscoveryServiceEntity implements Serializable {
private List<String> consumerVersionValueList;
private List<String> providerVersionValueList;
public DiscoveryServiceEntity() {
}
public String getConsumerServiceName() {
return consumerServiceName;
}
......
package com.nepxion.discovery.plugin.framework.entity;
package com.nepxion.discovery.common.entity;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -22,18 +22,14 @@ import org.apache.commons.lang3.builder.ToStringStyle;
public class VersionFilterEntity implements Serializable {
private static final long serialVersionUID = -6147106004826964165L;
private Map<String, List<DiscoveryServiceEntity>> serviceEntityMap = new LinkedHashMap<String, List<DiscoveryServiceEntity>>();
private Map<String, List<VersionEntity>> versionEntityMap = new LinkedHashMap<String, List<VersionEntity>>();
public VersionFilterEntity() {
}
public Map<String, List<DiscoveryServiceEntity>> getServiceEntityMap() {
return serviceEntityMap;
public Map<String, List<VersionEntity>> getVersionEntityMap() {
return versionEntityMap;
}
public void setServiceEntityMap(Map<String, List<DiscoveryServiceEntity>> serviceEntityMap) {
this.serviceEntityMap = serviceEntityMap;
public void setVersionEntityMap(Map<String, List<VersionEntity>> versionEntityMap) {
this.versionEntityMap = versionEntityMap;
}
@Override
......
package com.nepxion.discovery.plugin.framework.entity;
package com.nepxion.discovery.common.entity;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -10,76 +10,42 @@ package com.nepxion.discovery.plugin.framework.entity;
*/
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
public class WeightEntity implements Serializable {
private static final long serialVersionUID = 4242297554671632704L;
public class RouterEntity implements Serializable {
private static final long serialVersionUID = -4480475963615166799L;
private String consumerServiceName;
private String providerServiceName;
private Map<String, Integer> weightMap;
private String serviceId;
private String version;
private String host;
private int port;
private List<RouterEntity> nexts = new ArrayList<RouterEntity>();
public String getServiceId() {
return serviceId;
}
public void setServiceId(String serviceId) {
this.serviceId = serviceId;
public String getConsumerServiceName() {
return consumerServiceName;
}
public String getVersion() {
return version;
public void setConsumerServiceName(String consumerServiceName) {
this.consumerServiceName = consumerServiceName;
}
public void setVersion(String version) {
this.version = version;
public String getProviderServiceName() {
return providerServiceName;
}
public String getHost() {
return host;
public void setProviderServiceName(String providerServiceName) {
this.providerServiceName = providerServiceName;
}
public void setHost(String host) {
this.host = host;
public Map<String, Integer> getWeightMap() {
return weightMap;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public List<RouterEntity> getNexts() {
return nexts;
}
public void setNexts(List<RouterEntity> nexts) {
this.nexts = nexts;
}
public String toInfo() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("[")
.append(PluginConstant.SERVICE_ID).append("=").append(serviceId).append(", ")
.append(PluginConstant.VERSION).append("=").append(version).append(", ")
.append(PluginConstant.HOST).append("=").append(host).append(", ")
.append(PluginConstant.PORT).append("=").append(port)
.append("]");
return stringBuilder.toString();
public void setWeightMap(Map<String, Integer> weightMap) {
this.weightMap = weightMap;
}
@Override
......
package com.nepxion.discovery.common.entity;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
public class WeightFilterEntity implements Serializable {
private static final long serialVersionUID = 7313443273653189837L;
private Map<String, List<WeightEntity>> weightEntityMap = new LinkedHashMap<String, List<WeightEntity>>();
private RegionWeightEntity regionWeightEntity;
public Map<String, List<WeightEntity>> getWeightEntityMap() {
return weightEntityMap;
}
public void setWeightEntityMap(Map<String, List<WeightEntity>> weightEntityMap) {
this.weightEntityMap = weightEntityMap;
}
public RegionWeightEntity getRegionWeightEntity() {
return regionWeightEntity;
}
public void setRegionWeightEntity(RegionWeightEntity regionWeightEntity) {
this.regionWeightEntity = regionWeightEntity;
}
public boolean hasWeight() {
return MapUtils.isNotEmpty(weightEntityMap) || regionWeightEntity != null;
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
@Override
public boolean equals(Object object) {
return EqualsBuilder.reflectionEquals(this, object);
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}
\ No newline at end of file
package com.nepxion.discovery.plugin.framework.exception;
package com.nepxion.discovery.common.exception;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -9,22 +9,22 @@ package com.nepxion.discovery.plugin.framework.exception;
* @version 1.0
*/
public class PluginException extends RuntimeException {
public class DiscoveryException extends RuntimeException {
private static final long serialVersionUID = 7975167663357170655L;
public PluginException() {
public DiscoveryException() {
super();
}
public PluginException(String message) {
public DiscoveryException(String message) {
super(message);
}
public PluginException(String message, Throwable cause) {
public DiscoveryException(String message, Throwable cause) {
super(message, cause);
}
public PluginException(Throwable cause) {
public DiscoveryException(Throwable cause) {
super(cause);
}
}
\ No newline at end of file
package com.nepxion.discovery.console.desktop.controller;
package com.nepxion.discovery.common.handler;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -16,14 +16,16 @@ import org.apache.commons.io.IOUtils;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.DefaultResponseErrorHandler;
public class ServiceErrorHandler extends DefaultResponseErrorHandler {
import com.nepxion.discovery.common.constant.DiscoveryConstant;
public class RestErrorHandler extends DefaultResponseErrorHandler {
private String cause;
@Override
public void handleError(ClientHttpResponse response) throws IOException {
// 这里绝对不能关闭InputStream
InputStream inputStream = response.getBody();
cause = IOUtils.toString(inputStream, "UTF-8");
cause = IOUtils.toString(inputStream, DiscoveryConstant.ENCODING_UTF_8);
}
public String getCause() {
......
package com.nepxion.discovery.common.thread;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
// Copy from Alibaba Sentinel project
public class NamedThreadFactory implements ThreadFactory {
private AtomicInteger count = new AtomicInteger(1);
private ThreadGroup group;
private String namePrefix;
private boolean daemon;
public NamedThreadFactory(String namePrefix) {
this(namePrefix, false);
}
public NamedThreadFactory(String namePrefix, boolean daemon) {
SecurityManager securityManager = System.getSecurityManager();
this.group = securityManager != null ? securityManager.getThreadGroup() : Thread.currentThread().getThreadGroup();
this.namePrefix = namePrefix;
this.daemon = daemon;
}
@Override
public Thread newThread(Runnable runnable) {
Thread thread = new Thread(group, runnable, namePrefix + "-thread-" + count.getAndIncrement(), 0);
thread.setDaemon(daemon);
return thread;
}
}
\ No newline at end of file
package com.nepxion.discovery.console.desktop.serializer;
package com.nepxion.discovery.common.util;
/**
* <p>Title: Nepxion Discovery</p>
......@@ -9,20 +9,41 @@ package com.nepxion.discovery.console.desktop.serializer;
* @version 1.0
*/
import java.text.SimpleDateFormat;
import java.io.IOException;
import org.apache.commons.lang3.StringUtils;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
public class JacksonSerializer {
public class JsonUtil {
private static ObjectMapper objectMapper;
static {
objectMapper = new ObjectMapper();
objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"));
// objectMapper.getSerializerProvider().setNullKeySerializer(new NullKeySerializer());
// objectMapper.setDateFormat(new SimpleDateFormat(DiscoveryConstant.DATE_FORMAT));
}
public static class NullKeySerializer extends StdSerializer<Object> {
private static final long serialVersionUID = -9176767187240330396L;
public NullKeySerializer() {
this(null);
}
public NullKeySerializer(Class<Object> object) {
super(object);
}
@Override
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeFieldName(StringUtils.EMPTY);
}
}
public static <T> String toJson(T object) {
......
package com.nepxion.discovery.common.util;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.client.ResponseErrorHandler;
import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.core.type.TypeReference;
import com.nepxion.discovery.common.handler.RestErrorHandler;
public class RestUtil {
public static <T> T fromJson(RestTemplate restTemplate, String result, TypeReference<T> typeReference) {
try {
return JsonUtil.fromJson(result, typeReference);
} catch (Exception e) {
String cause = getCause(restTemplate);
if (StringUtils.isNotEmpty(cause)) {
throw new IllegalArgumentException(cause);
}
throw e;
}
}
public static String getCause(RestTemplate restTemplate) {
ResponseErrorHandler responseErrorHandler = restTemplate.getErrorHandler();
if (responseErrorHandler instanceof RestErrorHandler) {
RestErrorHandler errorHandler = (RestErrorHandler) responseErrorHandler;
return errorHandler.getCause();
}
return null;
}
}
\ No newline at end of file
package com.nepxion.discovery.common.util;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
public class StringUtil {
public static List<String> splitToList(String value, String separate) {
if (StringUtils.isEmpty(value)) {
return null;
}
String[] valueArray = StringUtils.split(value, separate);
return Arrays.asList(valueArray);
}
}
\ No newline at end of file
package com.nepxion.discovery.common.util;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import org.apache.commons.lang3.StringUtils;
public class UrlUtil {
public static String formatUrl(String url) {
if (!url.startsWith("http://")) {
url = "http://" + url;
}
if (!url.endsWith("/")) {
url = url + "/";
}
return url;
}
public static String formatContextPath(String contextPath) {
if (StringUtils.isEmpty(contextPath)) {
return "/";
} else {
if (!contextPath.startsWith("/")) {
contextPath = "/" + contextPath;
}
if (!contextPath.endsWith("/")) {
contextPath = contextPath + "/";
}
}
return contextPath;
}
}
\ No newline at end of file
,---.
/ O \
| .-. |
| | | |
`--' `--'
,------.
| .--. '
| '--' |
| | --'
`--'
,-----.
' .-. '
| | | |
' '-' '
`-----'
,--.
| |
| |
| '--.
`-----'
,--.
| |
| |
| '--.
`-----'
,-----.
' .-. '
| | | |
' '-' '
`-----'
\ No newline at end of file
,-----.
' .--./
| |
' '--'\
`-----'
,-----.
' .-. '
| | | |
' '-' '
`-----'
,--. ,--.
| ,'.| |
| |' ' |
| | ` |
`--' `--'
,---.
' .-'
`. `-.
.-' |
`-----'
,--. ,--.
| | | |
| | | |
' '-' '
`-----'
,--.
| |
| |
| '--.
`-----'
\ No newline at end of file
,------.
| .-. \
| | \ :
| '--' /
`-------'
,--.
| |
| |
| |
`--'
,---.
' .-'
`. `-.
.-' |
`-----'
,-----.
' .--./
| |
' '--'\
`-----'
,-----.
' .-. '
| | | |
' '-' '
`-----'
,--. ,--.
\ `.' /
\ /
\ /
`-'
,------.
| .---'
| `--,
| `---.
`------'
,------.
| .--. '
| '--'.'
| |\ \
`--' '--'
,--. ,--.
\ `.' /
'. /
| |
`--'
\ No newline at end of file
,------.
| .---'
| `--,
| `---.
`------'
,--. ,--.
| | | |
| | | |
' '-' '
`-----'
,------.
| .--. '
| '--'.'
| |\ \
`--' '--'
,------.
| .---'
| `--,
| `---.
`------'
,--. ,--.
| .' /
| . '
| |\ \
`--' '--'
,---.
/ O \
| .-. |
| | | |
`--' `--'
\ No newline at end of file
,--. ,--.
| ,'.| |
| |' ' |
| | ` |
`--' `--'
,---.
/ O \
| .-. |
| | | |
`--' `--'
,-----.
' .--./
| |
' '--'\
`-----'
,-----.
' .-. '
| | | |
' '-' '
`-----'
,---.
' .-'
`. `-.
.-' |
`-----'
\ No newline at end of file
,------.
| .--. '
| '--'.'
| |\ \
`--' '--'
,------.
| .---'
| `--,
| `---.
`------'
,------.
| .-. \
| | \ :
| '--' /
`-------'
,--.
| |
| |
| |
`--'
,---.
' .-'
`. `-.
.-' |
`-----'
\ No newline at end of file
,-------.
`--. /
/ /
/ `--.
`-------'
,-----.
' .-. '
| | | |
' '-' '
`-----'
,-----.
' .-. '
| | | |
' '-' '
`-----'
,--. ,--.
| .' /
| . '
| |\ \
`--' '--'
,------.
| .---'
| `--,
| `---.
`------'
,------.
| .---'
| `--,
| `---.
`------'
,------.
| .--. '
| '--' |
| | --'
`--'
,------.
| .---'
| `--,
| `---.
`------'
,------.
| .--. '
| '--'.'
| |\ \
`--' '--'
\ No newline at end of file
......@@ -11,7 +11,7 @@
<parent>
<groupId>com.nepxion</groupId>
<artifactId>discovery</artifactId>
<version>4.1.0</version>
<version>5.0.5</version>
</parent>
<properties>
......@@ -29,18 +29,8 @@
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<groupId>${project.groupId}</groupId>
<artifactId>discovery-common</artifactId>
</dependency>
<dependency>
......@@ -60,11 +50,6 @@
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>${disruptor.version}</version>
......
......@@ -10,9 +10,11 @@ package com.nepxion.discovery.console.desktop;
*/
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.nepxion.discovery.console.desktop.controller.ServiceController;
import com.nepxion.discovery.console.desktop.icon.ConsoleIconFactory;
import com.nepxion.discovery.console.desktop.locale.ConsoleLocale;
import com.nepxion.swing.frame.JBasicFrame;
......@@ -22,9 +24,10 @@ import com.nepxion.swing.style.texture.shrink.JGreenOutlookTextureStyle;
public class ConsoleFrame extends JBasicFrame {
private static final long serialVersionUID = 1L;
private static final Logger LOG = LoggerFactory.getLogger(ConsoleFrame.class);
public ConsoleFrame() {
super(ConsoleLocale.getString("title"), ConsoleIconFactory.getSwingIcon("ribbon/navigator_nepxion.png"), new Dimension(1280, 900));
super(ConsoleLocale.getString("title") + " " + getSubTitle(), ConsoleIconFactory.getSwingIcon("ribbon/navigator_nepxion.png"), new Dimension(1280, 900));
}
public void launch() {
......@@ -35,16 +38,18 @@ public class ConsoleFrame extends JBasicFrame {
getContentPane().add(reflectionHierarchy);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
}
});
setTitle(ConsoleLocale.getString("title"));
setExtendedState(ConsoleFrame.MAXIMIZED_BOTH);
setVisible(true);
toFront();
}
private static String getSubTitle() {
try {
return "[" + ServiceController.getDiscoveryType() + " " + ConsoleLocale.getString("discovery_center") + "] [" + ServiceController.getConfigType() + " " + ConsoleLocale.getString("config_center") + "]";
} catch (Exception e) {
LOG.error("Not connnect to Discovery Console", e);
return "[" + ConsoleLocale.getString("not_connnect_to_console") + "]";
}
}
}
\ No newline at end of file
......@@ -19,6 +19,9 @@ public class ConsoleLauncher {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
ConsoleLogin consoleLogin = new ConsoleLogin();
consoleLogin.launch();
ConsoleFrame consoleFrame = new ConsoleFrame();
consoleFrame.launch();
}
......
package com.nepxion.discovery.console.desktop;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import java.awt.Component;
import java.awt.Font;
import java.awt.Frame;
import java.util.Locale;
import java.util.Vector;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;
import javax.swing.JPanel;
import org.apache.commons.lang3.StringUtils;
import com.nepxion.discovery.common.entity.UserEntity;
import com.nepxion.discovery.console.desktop.controller.ServiceController;
import com.nepxion.discovery.console.desktop.locale.ConsoleLocale;
import com.nepxion.swing.combobox.JBasicComboBox;
import com.nepxion.swing.dialog.JLoginDialog;
import com.nepxion.swing.font.FontContext;
import com.nepxion.swing.label.JBasicLabel;
import com.nepxion.swing.layout.table.TableLayout;
public class ConsoleLogin extends JLoginDialog {
private static final long serialVersionUID = 1L;
private JBasicLabel urlLabel;
private JBasicComboBox urlComboBox;
public ConsoleLogin() {
super(null);
}
public ConsoleLogin(Frame parent) {
super(parent);
}
@SuppressWarnings("unchecked")
@Override
protected void initEditorPanelLayout() {
urlLabel = new JBasicLabel();
urlLabel.setFont(new Font(FontContext.getFontName(), FONT_STYLE, FONT_SIZE));
String url = null;
try {
url = ServiceController.getUrl();
} catch (Exception e) {
}
Vector<String> urls = new Vector<String>();
if (StringUtils.isNotEmpty(url)) {
urls.add(url);
}
urlComboBox = new JBasicComboBox(urls);
urlComboBox.setEditable(true);
urlComboBox.setRenderer(new DefaultListCellRenderer() {
private static final long serialVersionUID = 1L;
@SuppressWarnings("rawtypes")
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
setToolTipText(value.toString());
return this;
}
});
double[][] size = {
{ 80, 230 },
{ TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED }
};
TableLayout tableLayout = new TableLayout(size);
tableLayout.setVGap(10);
editorPanel = new JPanel();
editorPanel.setLayout(tableLayout);
editorPanel.add(urlLabel, "0, 0");
editorPanel.add(urlComboBox, "1, 0");
editorPanel.add(accountLabel, "0, 1");
editorPanel.add(accountTextField, "1, 1");
editorPanel.add(passwordLabel, "0, 2");
editorPanel.add(passwordField, "1, 2");
editorPanel.add(localeLabel, "0, 3");
editorPanel.add(localeComboBox, "1, 3");
}
@Override
protected void initLocale(Locale locale) {
super.initLocale(locale);
urlLabel.setText(ConsoleLocale.getString("url", locale));
}
@Override
public boolean login(String userId, String password, Locale locale) throws Exception {
Object url = urlComboBox.getSelectedItem();
if (url == null || StringUtils.isEmpty(url.toString().trim())) {
throw new IllegalArgumentException("Console url can't be null or empty");
}
ServiceController.setUrl(url.toString().trim());
UserEntity userEntity = new UserEntity();
userEntity.setUserId(userId);
userEntity.setPassword(password);
return ServiceController.authenticate(userEntity);
}
public void launch() {
setVisible(true);
toFront();
}
}
\ No newline at end of file
......@@ -10,12 +10,6 @@ package com.nepxion.discovery.console.desktop.constant;
*/
public class ConsoleConstant {
public static final String SPRING_APPLICATION_DISCOVERY_PLUGIN = "spring.application.discovery.plugin";
public static final String SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED = "spring.application.discovery.control.enabled";
public static final String SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED = "spring.application.config.rest.control.enabled";
public static final String SPRING_APPLICATION_GROUP_KEY = "spring.application.group.key";
public static final String FILTER = "filter";
public static final String PLUGIN = "plugin";
public static final String NO_FILTER_DESCRIPTION = "[No filter]";
}
\ No newline at end of file
......@@ -29,7 +29,9 @@ public class UIContext {
public static void initialize() {
FontContext.registerFont(getFontName(), Font.PLAIN, getDefaultFontSize());
LookAndFeelManager.setNimbusLookAndFeel();
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
LookAndFeelManager.setNimbusLookAndFeel();
}
}
public static String getFontName() {
......
package com.nepxion.discovery.console.desktop.entity;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import com.nepxion.discovery.common.entity.InstanceEntity;
public class Instance extends InstanceEntity {
private static final long serialVersionUID = -3381928574242229614L;
private String dynamicVersion;
private String rule;
private String dynamicRule;
public String getDynamicVersion() {
return dynamicVersion;
}
public void setDynamicVersion(String dynamicVersion) {
this.dynamicVersion = dynamicVersion;
}
public String getRule() {
return rule;
}
public void setRule(String rule) {
this.rule = rule;
}
public String getDynamicRule() {
return dynamicRule;
}
public void setDynamicRule(String dynamicRule) {
this.dynamicRule = dynamicRule;
}
}
\ No newline at end of file
package com.nepxion.discovery.console.desktop.entity;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import java.io.Serializable;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.nepxion.discovery.console.desktop.constant.ConsoleConstant;
public class InstanceEntity implements Serializable {
private static final long serialVersionUID = -3001191508072178378L;
private String serviceId;
private String version;
private String dynamicVersion;
private String host;
private int port;
private String rule;
private String dynamicRule;
private Map<String, String> metaData;
public String getServiceId() {
return serviceId;
}
public void setServiceId(String serviceId) {
this.serviceId = serviceId;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getDynamicVersion() {
return dynamicVersion;
}
public void setDynamicVersion(String dynamicVersion) {
this.dynamicVersion = dynamicVersion;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public String getRule() {
return rule;
}
public void setRule(String rule) {
this.rule = rule;
}
public String getDynamicRule() {
return dynamicRule;
}
public void setDynamicRule(String dynamicRule) {
this.dynamicRule = dynamicRule;
}
public Map<String, String> getMetaData() {
return metaData;
}
public void setMetaData(Map<String, String> metaData) {
this.metaData = metaData;
}
public String getFilter() {
String filterKey = metaData.get(ConsoleConstant.SPRING_APPLICATION_GROUP_KEY);
if (StringUtils.isEmpty(filterKey)) {
return "";
}
String filter = metaData.get(filterKey);
if (filter == null) {
return "";
}
return filter;
}
public String getPlugin() {
String plugin = metaData.get(ConsoleConstant.SPRING_APPLICATION_DISCOVERY_PLUGIN);
if (plugin == null) {
return "";
}
return plugin;
}
public boolean isDiscoveryControlEnabled() {
String flag = metaData.get(ConsoleConstant.SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED);
if (flag == null) {
return true;
}
return Boolean.valueOf(flag);
}
public boolean isConfigRestControlEnabled() {
String flag = metaData.get(ConsoleConstant.SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED);
if (flag == null) {
return true;
}
return Boolean.valueOf(flag);
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
@Override
public boolean equals(Object object) {
return EqualsBuilder.reflectionEquals(this, object);
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}
\ No newline at end of file
......@@ -16,7 +16,10 @@ import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.HierarchyEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.List;
import java.util.Map;
import javax.swing.Box;
import javax.swing.DefaultComboBoxModel;
......@@ -27,6 +30,7 @@ import javax.swing.JSlider;
import javax.swing.JToolBar;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import com.nepxion.cots.twaver.element.TElementManager;
......@@ -37,15 +41,16 @@ import com.nepxion.cots.twaver.graph.TGraphControlBar;
import com.nepxion.cots.twaver.graph.TGraphManager;
import com.nepxion.cots.twaver.graph.TLayoutPanel;
import com.nepxion.cots.twaver.graph.TLayouterBar;
import com.nepxion.discovery.common.entity.RouterEntity;
import com.nepxion.discovery.console.desktop.controller.ServiceController;
import com.nepxion.discovery.console.desktop.entity.InstanceEntity;
import com.nepxion.discovery.console.desktop.entity.RouterEntity;
import com.nepxion.discovery.console.desktop.entity.Instance;
import com.nepxion.discovery.console.desktop.icon.ConsoleIconFactory;
import com.nepxion.discovery.console.desktop.locale.ConsoleLocale;
import com.nepxion.discovery.console.desktop.workspace.topology.AbstractTopology;
import com.nepxion.discovery.console.desktop.workspace.topology.LocationEntity;
import com.nepxion.discovery.console.desktop.workspace.topology.TopologyEntity;
import com.nepxion.discovery.console.desktop.workspace.topology.TopologyEntityType;
import com.nepxion.discovery.console.desktop.workspace.topology.TopologyStyleType;
import com.nepxion.swing.action.JSecurityAction;
import com.nepxion.swing.button.ButtonManager;
import com.nepxion.swing.button.JBasicButton;
......@@ -63,14 +68,14 @@ public class RouterTopology extends AbstractTopology {
private static final long serialVersionUID = 1L;
private LocationEntity nodeLocationEntity = new LocationEntity(100, 200, 200, 0);
private TopologyEntity serviceNodeEntity = new TopologyEntity(TopologyEntityType.SERVICE, true, true);
private TopologyEntity serviceNodeEntity = new TopologyEntity(TopologyEntityType.SERVICE, TopologyStyleType.MIDDLE, true);
private TGraphBackground background;
private JBasicComboBox comboBox;
private JBasicTextField textField;
private ActionListener layoutActionListener;
private InstanceEntity instance;
private Instance instance;
public RouterTopology() {
initializeToolBar();
......@@ -79,8 +84,17 @@ public class RouterTopology extends AbstractTopology {
}
private void initializeToolBar() {
JSecurityAction addServiceAction = createAddServiceAction();
comboBox = new JBasicComboBox();
comboBox.setPreferredSize(new Dimension(300, comboBox.getPreferredSize().height));
comboBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (comboBox.getSelectedItem() != e.getItem()) {
addServiceAction.execute(null);
}
}
});
textField = new JBasicTextField();
textField.setPreferredSize(new Dimension(650, textField.getPreferredSize().height));
......@@ -91,7 +105,7 @@ public class RouterTopology extends AbstractTopology {
toolBar.add(new JLabel(ConsoleLocale.getString("service_list")));
toolBar.add(Box.createHorizontalStrut(5));
toolBar.add(comboBox);
toolBar.add(new JClassicButton(createAddServiceAction()));
toolBar.add(new JClassicButton(addServiceAction));
toolBar.add(new JClassicButton(createDeleteServiceAction()));
toolBar.add(textField);
toolBar.add(new JClassicButton(createExecuteRouterAction()));
......@@ -130,10 +144,12 @@ public class RouterTopology extends AbstractTopology {
typeComboBox.setSelectedIndex(2);
JPanel childPanel2 = (JPanel) layoutPanel.getComponent(1);
JSlider yOffsetSlider = (JSlider) childPanel2.getComponent(11);
yOffsetSlider.setValue(0);
JSlider xGapSlider = (JSlider) childPanel2.getComponent(13);
xGapSlider.setValue(200);
JSlider yGapSlider = (JSlider) childPanel2.getComponent(15);
yGapSlider.setValue(100);
yGapSlider.setValue(150);
JPanel childPanel3 = (JPanel) layoutPanel.getComponent(2);
JBasicButton runButton = (JBasicButton) childPanel3.getComponent(1);
......@@ -172,7 +188,7 @@ public class RouterTopology extends AbstractTopology {
index++;
}
addLink(node, nextNode);
addLink(node, nextNode, next);
route(next, nextNode, index);
}
......@@ -189,6 +205,17 @@ public class RouterTopology extends AbstractTopology {
stringBuilder.append("\n [V").append(routerEntity.getVersion()).append("]");
}
if (StringUtils.isNotEmpty(routerEntity.getRegion())) {
stringBuilder.append("\n [Region=").append(routerEntity.getRegion()).append("]");
}
Map<String, String> customMap = routerEntity.getCustomMap();
if (MapUtils.isNotEmpty(customMap)) {
for (Map.Entry<String, String> entry : customMap.entrySet()) {
stringBuilder.append("\n ").append(entry.getKey()).append("=").append(entry.getValue());
}
}
return ButtonManager.getHtmlText(stringBuilder.toString());
}
......@@ -203,9 +230,25 @@ public class RouterTopology extends AbstractTopology {
return node;
}
private void addLink(TNode fromNode, TNode toNode) {
@SuppressWarnings("unchecked")
private void addLink(TNode fromNode, TNode toNode, RouterEntity routerEntity) {
List<TLink> links = TElementManager.getLinks(dataBox);
for (TLink link : links) {
if (link.getFrom() == fromNode && link.getTo() == toNode) {
return;
}
}
int weight = routerEntity.getWeight();
TLink link = createLink(fromNode, toNode, true);
link.putLinkToArrowColor(Color.yellow);
if (weight > -1) {
link.setName("weight=" + weight);
link.putLinkFlowing(true);
link.putLinkFlowingColor(new Color(255, 155, 85));
link.putLinkFlowingWidth(3);
}
dataBox.addElement(link);
}
......@@ -215,11 +258,11 @@ public class RouterTopology extends AbstractTopology {
comboBox.setModel(new DefaultComboBoxModel<>(services));
}
public void setInstance(InstanceEntity instance) {
public void setInstance(Instance instance) {
if (this.instance != instance) {
this.instance = instance;
textField.setText("");
textField.setText(StringUtils.EMPTY);
dataBox.clear();
}
}
......@@ -229,8 +272,13 @@ public class RouterTopology extends AbstractTopology {
private static final long serialVersionUID = 1L;
public void execute(ActionEvent e) {
Object selectedItem = comboBox.getSelectedItem();
if (selectedItem == null) {
return;
}
String routerPath = textField.getText();
String serviceId = comboBox.getSelectedItem().toString();
String serviceId = selectedItem.toString();
if (StringUtils.isNotEmpty(routerPath)) {
routerPath = routerPath + ";" + serviceId;
} else {
......@@ -256,7 +304,7 @@ public class RouterTopology extends AbstractTopology {
if (routerPath.contains(";")) {
routerPath = routerPath.substring(0, routerPath.lastIndexOf(";"));
} else {
routerPath = "";
routerPath = StringUtils.EMPTY;
}
textField.setText(routerPath);
......@@ -301,7 +349,7 @@ public class RouterTopology extends AbstractTopology {
private static final long serialVersionUID = 1L;
public void execute(ActionEvent e) {
textField.setText("");
textField.setText(StringUtils.EMPTY);
dataBox.clear();
}
};
......
......@@ -12,63 +12,141 @@ package com.nepxion.discovery.console.desktop.workspace.topology;
import java.awt.Point;
public class TopologyEntity {
public static final String REGISTRY_LARGE_IMAGE = "registry_48.png";
public static final String MQ_LARGE_IMAGE = "mq_48.png";
public static final String CACHE_LARGE_IMAGE = "cache_48.png";
public static final String LOGGER_LARGE_IMAGE = "logger_48.png";
public static final String SERVICE_LARGE_IMAGE = "service_48.png";
public static final String REFERENCE_LARGE_IMAGE = "reference_48.png";
public static final String REGISTRY_SMALL_IMAGE = "registry_32.png";
public static final String MQ_SMALL_IMAGE = "mq_32.png";
public static final String CACHE_SMALL_IMAGE = "cache_32.png";
public static final String LOGGER_SMALL_IMAGE = "logger_32.png";
public static final String SERVICE_SMALL_IMAGE = "service_32.png";
public static final String REFERENCE_SMALL_IMAGE = "reference_32.png";
private TopologyEntityType type;
public static final String THEME_DIRECTORY = "theme_1/";
public static final String SERVICE_GROUP_LARGE_IMAGE = "service_group_80.png";
public static final String SERVICE_GROUP_MIDDLE_IMAGE = "service_group_64.png";
public static final String SERVICE_GROUP_SMALL_IMAGE = "service_group_48.png";
public static final String REFERENCE_GROUP_LARGE_IMAGE = "reference_group_80.png";
public static final String REFERENCE_GROUP_MIDDLE_IMAGE = "reference_group_64.png";
public static final String REFERENCE_GROUP_SMALL_IMAGE = "reference_group_48.png";
public static final String GATEWAY_GROUP_LARGE_IMAGE = "gateway_group_80.png";
public static final String GATEWAY_GROUP_MIDDLE_IMAGE = "gateway_group_64.png";
public static final String GATEWAY_GROUP_SMALL_IMAGE = "gateway_group_48.png";
public static final String SERVICE_LARGE_IMAGE = THEME_DIRECTORY + "service_64.png";
public static final String SERVICE_MIDDLE_IMAGE = THEME_DIRECTORY + "service_48.png";
public static final String SERVICE_SMALL_IMAGE = THEME_DIRECTORY + "service_32.png";
public static final String REFERENCE_LARGE_IMAGE = THEME_DIRECTORY + "reference_64.png";
public static final String REFERENCE_MIDDLE_IMAGE = THEME_DIRECTORY + "reference_48.png";
public static final String REFERENCE_SMALL_IMAGE = THEME_DIRECTORY + "reference_32.png";
public static final String GATEWAY_LARGE_IMAGE = THEME_DIRECTORY + "gateway_64.png";
public static final String GATEWAY_MIDDLE_IMAGE = THEME_DIRECTORY + "gateway_48.png";
public static final String GATEWAY_SMALL_IMAGE = THEME_DIRECTORY + "gateway_32.png";
private TopologyEntityType entityType;
private TopologyStyleType styleType;
private String image;
private Point location;
private boolean horizontalPile;
public TopologyEntity(TopologyEntityType type, boolean largeStyle, Point location) {
initialize(type, largeStyle);
public TopologyEntity(TopologyEntityType entityType, TopologyStyleType styleType, Point location) {
initialize(entityType, styleType);
this.location = location;
}
public TopologyEntity(TopologyEntityType type, boolean largeStyle, boolean horizontalPile) {
initialize(type, largeStyle);
public TopologyEntity(TopologyEntityType entityType, TopologyStyleType styleType, boolean horizontalPile) {
initialize(entityType, styleType);
this.horizontalPile = horizontalPile;
}
private void initialize(TopologyEntityType type, boolean largeStyle) {
this.type = type;
switch (type) {
case REGISTRY:
image = largeStyle ? REGISTRY_LARGE_IMAGE : REGISTRY_SMALL_IMAGE;
break;
case MQ:
image = largeStyle ? MQ_LARGE_IMAGE : MQ_SMALL_IMAGE;
private void initialize(TopologyEntityType entityType, TopologyStyleType styleType) {
this.entityType = entityType;
this.styleType = styleType;
switch (entityType) {
case SERVICE_GROUP:
switch (styleType) {
case LARGE:
image = SERVICE_GROUP_LARGE_IMAGE;
break;
case MIDDLE:
image = SERVICE_GROUP_MIDDLE_IMAGE;
break;
case SMALL:
image = SERVICE_GROUP_SMALL_IMAGE;
break;
}
break;
case CACHE:
image = largeStyle ? CACHE_LARGE_IMAGE : CACHE_SMALL_IMAGE;
case REFERENCE_GROUP:
switch (styleType) {
case LARGE:
image = REFERENCE_GROUP_LARGE_IMAGE;
break;
case MIDDLE:
image = REFERENCE_GROUP_MIDDLE_IMAGE;
break;
case SMALL:
image = REFERENCE_GROUP_SMALL_IMAGE;
break;
}
break;
case LOGGER:
image = largeStyle ? LOGGER_LARGE_IMAGE : LOGGER_SMALL_IMAGE;
case GATEWAY_GROUP:
switch (styleType) {
case LARGE:
image = GATEWAY_GROUP_LARGE_IMAGE;
break;
case MIDDLE:
image = GATEWAY_GROUP_MIDDLE_IMAGE;
break;
case SMALL:
image = GATEWAY_GROUP_SMALL_IMAGE;
break;
}
break;
case SERVICE:
image = largeStyle ? SERVICE_LARGE_IMAGE : SERVICE_SMALL_IMAGE;
switch (styleType) {
case LARGE:
image = SERVICE_LARGE_IMAGE;
break;
case MIDDLE:
image = SERVICE_MIDDLE_IMAGE;
break;
case SMALL:
image = SERVICE_SMALL_IMAGE;
break;
}
break;
case REFERENCE:
image = largeStyle ? REFERENCE_LARGE_IMAGE : REFERENCE_SMALL_IMAGE;
switch (styleType) {
case LARGE:
image = REFERENCE_LARGE_IMAGE;
break;
case MIDDLE:
image = REFERENCE_MIDDLE_IMAGE;
break;
case SMALL:
image = REFERENCE_SMALL_IMAGE;
break;
}
break;
case GATEWAY:
switch (styleType) {
case LARGE:
image = GATEWAY_LARGE_IMAGE;
break;
case MIDDLE:
image = GATEWAY_MIDDLE_IMAGE;
break;
case SMALL:
image = GATEWAY_SMALL_IMAGE;
break;
}
break;
}
}
public TopologyEntityType getType() {
return type;
public TopologyEntityType getEntityType() {
return entityType;
}
public TopologyStyleType getStyleType() {
return styleType;
}
public String getImage() {
......
......@@ -10,10 +10,10 @@ package com.nepxion.discovery.console.desktop.workspace.topology;
*/
public enum TopologyEntityType {
REGISTRY,
MQ,
CACHE,
LOGGER,
SERVICE,
REFERENCE
SERVICE_GROUP,
REFERENCE_GROUP,
GATEWAY_GROUP,
SERVICE,
REFERENCE,
GATEWAY
}
\ No newline at end of file
package com.nepxion.discovery.console.desktop.workspace.topology;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
public enum TopologyStyleType {
LARGE,
MIDDLE,
SMALL
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment