Commit 029b7cf3 by Nepxion

重构出common工程

parent d403a5ca
<?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>4.2.1</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>
</dependencies>
</project>
\ No newline at end of file
package com.nepxion.discovery.console.entity;
package com.nepxion.discovery.plugin.framework.entity;
/**
* <p>Title: Nepxion Discovery</p>
......
package com.nepxion.discovery.console.desktop.entity;
package com.nepxion.discovery.plugin.framework.entity;
/**
* <p>Title: Nepxion Discovery</p>
......
......@@ -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>
......
......@@ -10,11 +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";
}
\ No newline at end of file
......@@ -20,10 +20,10 @@ import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.core.type.TypeReference;
import com.nepxion.discovery.console.desktop.context.PropertiesContext;
import com.nepxion.discovery.console.desktop.entity.InstanceEntity;
import com.nepxion.discovery.console.desktop.entity.ResultEntity;
import com.nepxion.discovery.console.desktop.entity.RouterEntity;
import com.nepxion.discovery.console.desktop.entity.Instance;
import com.nepxion.discovery.console.desktop.serializer.JacksonSerializer;
import com.nepxion.discovery.plugin.framework.entity.ResultEntity;
import com.nepxion.discovery.plugin.framework.entity.RouterEntity;
public class ServiceController {
public static RestTemplate restTemplate;
......@@ -33,16 +33,16 @@ public class ServiceController {
restTemplate.setErrorHandler(new ServiceErrorHandler());
}
public static Map<String, List<InstanceEntity>> getInstanceMap() {
public static Map<String, List<Instance>> getInstanceMap() {
String url = getUrl() + "/console/instance-map";
String result = restTemplate.getForEntity(url, String.class).getBody();
return convert(result, new TypeReference<Map<String, List<InstanceEntity>>>() {
return convert(result, new TypeReference<Map<String, List<Instance>>>() {
});
}
public static List<String> getVersions(InstanceEntity instance) {
public static List<String> getVersions(Instance instance) {
String url = getUrl(instance) + "/version/view";
String result = restTemplate.getForEntity(url, String.class).getBody();
......@@ -51,7 +51,7 @@ public class ServiceController {
});
}
public static List<String> getRules(InstanceEntity instance) {
public static List<String> getRules(Instance instance) {
String url = getUrl(instance) + "/config/view";
String result = restTemplate.getForEntity(url, String.class).getBody();
......@@ -60,7 +60,7 @@ public class ServiceController {
});
}
public static RouterEntity routes(InstanceEntity instance, String routeServiceIds) {
public static RouterEntity routes(Instance instance, String routeServiceIds) {
String url = getUrl(instance) + "/router/routes";
String result = restTemplate.postForEntity(url, routeServiceIds, String.class).getBody();
......@@ -78,7 +78,7 @@ public class ServiceController {
});
}
public static String versionUpdate(InstanceEntity instance, String version) {
public static String versionUpdate(Instance instance, String version) {
String url = getUrl(instance) + "/version/update";
String result = restTemplate.postForEntity(url, version, String.class).getBody();
......@@ -100,7 +100,7 @@ public class ServiceController {
});
}
public static String versionClear(InstanceEntity instance) {
public static String versionClear(Instance instance) {
String url = getUrl(instance) + "/version/clear";
String result = restTemplate.postForEntity(url, null, String.class).getBody();
......@@ -145,7 +145,7 @@ public class ServiceController {
});
}
public static String configUpdate(InstanceEntity instance, String config) {
public static String configUpdate(Instance instance, String config) {
String url = getUrl(instance) + "/config/update-sync";
// 解决中文乱码
......@@ -185,7 +185,7 @@ public class ServiceController {
});
}
public static String configClear(InstanceEntity instance) {
public static String configClear(Instance instance) {
String url = getUrl(instance) + "/config/clear";
String result = restTemplate.postForEntity(url, null, String.class).getBody();
......@@ -215,7 +215,7 @@ public class ServiceController {
return url;
}
private static String getUrl(InstanceEntity instance) {
private static String getUrl(Instance instance) {
String url = "http://" + instance.getHost() + ":" + instance.getPort();
return url;
......
......@@ -9,44 +9,19 @@ package com.nepxion.discovery.console.desktop.entity;
* @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;
import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
import com.nepxion.discovery.plugin.framework.entity.InstanceEntity;
public class InstanceEntity implements Serializable {
private static final long serialVersionUID = -3001191508072178378L;
public class Instance extends InstanceEntity {
private static final long serialVersionUID = -3381928574242229614L;
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;
......@@ -56,22 +31,6 @@ public class InstanceEntity implements Serializable {
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;
}
......@@ -88,16 +47,9 @@ public class InstanceEntity implements Serializable {
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);
Map<String, String> metadata = getMetadata();
String filterKey = metadata.get(PluginConstant.SPRING_APPLICATION_GROUP_KEY);
if (StringUtils.isEmpty(filterKey)) {
return "";
}
......@@ -111,7 +63,8 @@ public class InstanceEntity implements Serializable {
}
public String getPlugin() {
String plugin = metadata.get(ConsoleConstant.SPRING_APPLICATION_DISCOVERY_PLUGIN);
Map<String, String> metadata = getMetadata();
String plugin = metadata.get(PluginConstant.SPRING_APPLICATION_DISCOVERY_PLUGIN);
if (plugin == null) {
return "";
}
......@@ -120,7 +73,8 @@ public class InstanceEntity implements Serializable {
}
public boolean isDiscoveryControlEnabled() {
String flag = metadata.get(ConsoleConstant.SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED);
Map<String, String> metadata = getMetadata();
String flag = metadata.get(PluginConstant.SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED);
if (flag == null) {
return true;
}
......@@ -129,26 +83,12 @@ public class InstanceEntity implements Serializable {
}
public boolean isConfigRestControlEnabled() {
String flag = metadata.get(ConsoleConstant.SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED);
Map<String, String> metadata = getMetadata();
String flag = metadata.get(PluginConstant.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
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.ArrayList;
import java.util.List;
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 RouterEntity implements Serializable {
private static final long serialVersionUID = -4480475963615166799L;
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 getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
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 List<RouterEntity> getNexts() {
return nexts;
}
public void setNexts(List<RouterEntity> nexts) {
this.nexts = nexts;
}
@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
......@@ -38,8 +38,7 @@ 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.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;
......@@ -47,6 +46,7 @@ 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.discovery.plugin.framework.entity.RouterEntity;
import com.nepxion.swing.action.JSecurityAction;
import com.nepxion.swing.button.ButtonManager;
import com.nepxion.swing.button.JBasicButton;
......@@ -71,7 +71,7 @@ public class RouterTopology extends AbstractTopology {
private JBasicTextField textField;
private ActionListener layoutActionListener;
private InstanceEntity instance;
private Instance instance;
public RouterTopology() {
initializeToolBar();
......@@ -216,7 +216,7 @@ 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;
......
......@@ -16,18 +16,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>
......
package com.nepxion.discovery.console.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
*/
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";
}
\ No newline at end of file
......@@ -32,12 +32,12 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.nepxion.discovery.console.entity.InstanceEntity;
import com.nepxion.discovery.console.remote.ConfigAdapter;
import com.nepxion.discovery.console.rest.ConfigClearRestInvoker;
import com.nepxion.discovery.console.rest.ConfigUpdateRestInvoker;
import com.nepxion.discovery.console.rest.VersionClearRestInvoker;
import com.nepxion.discovery.console.rest.VersionUpdateRestInvoker;
import com.nepxion.discovery.plugin.framework.entity.InstanceEntity;
@RestController
@Api(tags = { "控制台接口" })
......
package com.nepxion.discovery.console.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 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;
private String url;
private String result;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
@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
......@@ -22,9 +22,9 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import com.nepxion.discovery.console.constant.ConsoleConstant;
import com.nepxion.discovery.console.entity.ResultEntity;
import com.nepxion.discovery.console.handler.ConsoleErrorHandler;
import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
import com.nepxion.discovery.plugin.framework.entity.ResultEntity;
public abstract class AbstractRestInvoker {
private static final Logger LOG = LoggerFactory.getLogger(AbstractRestInvoker.class);
......@@ -79,9 +79,9 @@ public abstract class AbstractRestInvoker {
protected void checkDiscoveryControlPermission(ServiceInstance serviceInstance) {
Map<String, String> metadata = serviceInstance.getMetadata();
String discoveryControlEnabled = metadata.get(ConsoleConstant.SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED);
String discoveryControlEnabled = metadata.get(PluginConstant.SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED);
if (StringUtils.isEmpty(discoveryControlEnabled)) {
throw new IllegalArgumentException("No metadata for key=" + ConsoleConstant.SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED);
throw new IllegalArgumentException("No metadata for key=" + PluginConstant.SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED);
}
if (!Boolean.valueOf(discoveryControlEnabled)) {
......@@ -92,9 +92,9 @@ public abstract class AbstractRestInvoker {
protected void checkConfigRestControlPermission(ServiceInstance serviceInstance) {
Map<String, String> metadata = serviceInstance.getMetadata();
String configRestControlEnabled = metadata.get(ConsoleConstant.SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED);
String configRestControlEnabled = metadata.get(PluginConstant.SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED);
if (StringUtils.isEmpty(configRestControlEnabled)) {
throw new IllegalArgumentException("No metadata for key=" + ConsoleConstant.SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED);
throw new IllegalArgumentException("No metadata for key=" + PluginConstant.SPRING_APPLICATION_CONFIG_REST_CONTROL_ENABLED);
}
if (!Boolean.valueOf(configRestControlEnabled)) {
......
......@@ -16,18 +16,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>
......
......@@ -11,6 +11,7 @@
<url>http://www.nepxion.com</url>
<modules>
<module>discovery-common</module>
<module>discovery-common-nacos</module>
<module>discovery-common-redis</module>
<module>discovery-plugin-framework</module>
......@@ -61,6 +62,12 @@
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>discovery-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>discovery-common-nacos</artifactId>
<version>${project.version}</version>
</dependency>
......
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