Refactor project structure using maven
This commit is contained in:
parent
22bb9cbcf7
commit
26f39d57ff
|
|
@ -21,318 +21,297 @@ limitations under the License.
|
|||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-parent</artifactId>
|
||||
<version>2.6.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo</artifactId>
|
||||
<version>2.6.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>${project.artifactId}</name>
|
||||
<name>dubbo-all</name>
|
||||
<description>The all in one project of dubbo</description>
|
||||
<properties>
|
||||
<skip_maven_deploy>false</skip_maven_deploy>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-cluster</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-config-api</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>jetty</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-config-spring</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-filter-cache</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-filter-validation</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-remoting-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-remoting-netty</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-remoting-netty4</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-remoting-mina</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.mina</groupId>
|
||||
<artifactId>mina-core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-remoting-grizzly</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.glassfish.grizzly</groupId>
|
||||
<artifactId>grizzly-core</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-remoting-p2p</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-remoting-http</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>jetty</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-logging-juli</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-default</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-injvm</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-rmi</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-hessian</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.caucho</groupId>
|
||||
<artifactId>hessian</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-http</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.caucho</groupId>
|
||||
<artifactId>hessian</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-webservice</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-frontend-simple</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-transports-http</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-thrift</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.thrift</groupId>
|
||||
<artifactId>libthrift</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-memcached</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.googlecode.xmemcached</groupId>
|
||||
<artifactId>xmemcached</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-redis</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-rest</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jaxrs</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-client</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-netty4</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jdk-http</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-undertow</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.undertow</groupId>
|
||||
<artifactId>undertow-servlet</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.undertow</groupId>
|
||||
<artifactId>undertow-core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jackson-provider</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jaxb-provider</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-registry-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-registry-default</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-registry-multicast</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-registry-zookeeper</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.zookeeper</groupId>
|
||||
<artifactId>zookeeper</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.101tec</groupId>
|
||||
<artifactId>zkclient</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-framework</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-registry-redis</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-monitor-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-monitor-default</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-container-spring</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-container-jetty</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>jetty</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-container-log4j</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-container-logback</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-qos</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>hessian-lite</artifactId>
|
||||
<version>3.2.1-fixed-2</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Transitive dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.netty</groupId>
|
||||
<artifactId>netty</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
|
@ -0,0 +1,269 @@
|
|||
<?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">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<!--<parent>-->
|
||||
<!--<artifactId>dubbo-parent</artifactId>-->
|
||||
<!--<groupId>com.alibaba</groupId>-->
|
||||
<!--<version>2.6.0</version>-->
|
||||
<!--<relativePath>../pom.xml</relativePath>-->
|
||||
<!--</parent>-->
|
||||
<parent>
|
||||
<groupId>org.sonatype.oss</groupId>
|
||||
<artifactId>oss-parent</artifactId>
|
||||
<version>7</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-bom</artifactId>
|
||||
<version>2.6.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>dubbo-bom</name>
|
||||
<description>Dubbo dependencies BOM</description>
|
||||
<url>http://dubbo.io</url>
|
||||
|
||||
<inceptionYear>2011</inceptionYear>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache 2</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<organization>
|
||||
<name>The Dubbo Project</name>
|
||||
<url>http://dubbo.io</url>
|
||||
</organization>
|
||||
|
||||
<issueManagement>
|
||||
<system>Github Issues</system>
|
||||
<url>https://github.com/alibaba/dubbo/issues</url>
|
||||
</issueManagement>
|
||||
<scm>
|
||||
<url>https://github.com/alibaba/dubbo/tree/master</url>
|
||||
<connection>scm:git:git://github.com/alibaba/dubbo.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:alibaba/dubbo.git</developerConnection>
|
||||
</scm>
|
||||
<mailingLists>
|
||||
<mailingList>
|
||||
<name>Dubbo User Mailling List</name>
|
||||
<subscribe>dubbo+subscribe@googlegroups.com</subscribe>
|
||||
<unsubscribe>dubbo+unsubscribe@googlegroups.com</unsubscribe>
|
||||
<post>dubbo@googlegroups.com</post>
|
||||
<archive>http://groups.google.com/group/dubbo</archive>
|
||||
</mailingList>
|
||||
<mailingList>
|
||||
<name>Dubbo Developer Mailling List</name>
|
||||
<subscribe>dubbo-developers+subscribe@googlegroups.com</subscribe>
|
||||
<unsubscribe>dubbo-developers+unsubscribe@googlegroups.com</unsubscribe>
|
||||
<post>dubbo-developers@googlegroups.com</post>
|
||||
<archive>http://groups.google.com/group/dubbo-developers</archive>
|
||||
</mailingList>
|
||||
</mailingLists>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>dubbo.io</id>
|
||||
<name>The Dubbo Project Contributors</name>
|
||||
<email>dubbo@googlegroups.com</email>
|
||||
<url>http://dubbo.io</url>
|
||||
<organization>The Dubbo Project</organization>
|
||||
<organizationUrl>http://dubbo.io</organizationUrl>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-cluster</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-config-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-config-spring</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-filter-cache</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-filter-validation</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-remoting-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-remoting-netty</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-remoting-netty4</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-remoting-mina</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-remoting-grizzly</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-remoting-p2p</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-remoting-http</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-default</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-injvm</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-rmi</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-hessian</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-http</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-webservice</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-thrift</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-memcached</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-redis</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-rpc-rest</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-registry-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-registry-default</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-registry-multicast</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-registry-zookeeper</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-registry-redis</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-monitor-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-monitor-default</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-container-spring</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-container-jetty</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-container-log4j</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-container-logback</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-qos</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>hessian-lite</artifactId>
|
||||
<version>3.2.1-fixed-2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,379 @@
|
|||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.sonatype.oss</groupId>
|
||||
<artifactId>oss-parent</artifactId>
|
||||
<version>7</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-dependencies</artifactId>
|
||||
<version>2.6.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>dubbo-dependencies-bom</name>
|
||||
<description>Dubbo dependencies BOM</description>
|
||||
<url>http://dubbo.io</url>
|
||||
|
||||
<inceptionYear>2011</inceptionYear>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache 2</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<organization>
|
||||
<name>The Dubbo Project</name>
|
||||
<url>http://dubbo.io</url>
|
||||
</organization>
|
||||
|
||||
<issueManagement>
|
||||
<system>Github Issues</system>
|
||||
<url>https://github.com/alibaba/dubbo/issues</url>
|
||||
</issueManagement>
|
||||
<scm>
|
||||
<url>https://github.com/alibaba/dubbo/tree/master</url>
|
||||
<connection>scm:git:git://github.com/alibaba/dubbo.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:alibaba/dubbo.git</developerConnection>
|
||||
</scm>
|
||||
<mailingLists>
|
||||
<mailingList>
|
||||
<name>Dubbo User Mailling List</name>
|
||||
<subscribe>dubbo+subscribe@googlegroups.com</subscribe>
|
||||
<unsubscribe>dubbo+unsubscribe@googlegroups.com</unsubscribe>
|
||||
<post>dubbo@googlegroups.com</post>
|
||||
<archive>http://groups.google.com/group/dubbo</archive>
|
||||
</mailingList>
|
||||
<mailingList>
|
||||
<name>Dubbo Developer Mailling List</name>
|
||||
<subscribe>dubbo-developers+subscribe@googlegroups.com</subscribe>
|
||||
<unsubscribe>dubbo-developers+unsubscribe@googlegroups.com</unsubscribe>
|
||||
<post>dubbo-developers@googlegroups.com</post>
|
||||
<archive>http://groups.google.com/group/dubbo-developers</archive>
|
||||
</mailingList>
|
||||
</mailingLists>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>dubbo.io</id>
|
||||
<name>The Dubbo Project Contributors</name>
|
||||
<email>dubbo@googlegroups.com</email>
|
||||
<url>http://dubbo.io</url>
|
||||
<organization>The Dubbo Project</organization>
|
||||
<organizationUrl>http://dubbo.io</organizationUrl>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<properties>
|
||||
<!-- Common libs -->
|
||||
<spring_version>4.3.10.RELEASE</spring_version>
|
||||
<javassist_version>3.20.0-GA</javassist_version>
|
||||
<netty_version>3.2.5.Final</netty_version>
|
||||
<netty4_version>4.0.35.Final</netty4_version>
|
||||
<mina_version>1.1.7</mina_version>
|
||||
<grizzly_version>2.1.4</grizzly_version>
|
||||
<httpclient_version>4.5.3</httpclient_version>
|
||||
<xstream_version>1.4.1</xstream_version>
|
||||
<fastjson_version>1.2.31</fastjson_version>
|
||||
<bsf_version>3.1</bsf_version>
|
||||
<sorcerer_version>0.8</sorcerer_version>
|
||||
<zookeeper_version>3.4.9</zookeeper_version>
|
||||
<zkclient_version>0.2</zkclient_version>
|
||||
<curator_version>2.12.0</curator_version>
|
||||
<jedis_version>2.9.0</jedis_version>
|
||||
<xmemcached_version>1.3.6</xmemcached_version>
|
||||
<cxf_version>3.0.14</cxf_version>
|
||||
<thrift_version>0.8.0</thrift_version>
|
||||
<jfreechart_version>1.0.13</jfreechart_version>
|
||||
<hessian_version>4.0.38</hessian_version>
|
||||
<servlet_version>3.1.0</servlet_version>
|
||||
<jetty_version>6.1.26</jetty_version>
|
||||
<validation_version>1.1.0.Final</validation_version>
|
||||
<hibernate_validator_version>5.4.1.Final</hibernate_validator_version>
|
||||
<jel_version>3.0.1-b08</jel_version>
|
||||
<jcache_version>1.0.0</jcache_version>
|
||||
<sca_version>2.0-M5.1</sca_version>
|
||||
<guice_version>3.0</guice_version>
|
||||
<webx_version>3.1.6</webx_version>
|
||||
<velocity_version>1.7</velocity_version>
|
||||
<kryo_version>4.0.1</kryo_version>
|
||||
<kryo_serializers_version>0.42</kryo_serializers_version>
|
||||
<fst_version>2.48-jdk-6</fst_version>
|
||||
|
||||
<rs_api_version>2.0</rs_api_version>
|
||||
<resteasy_version>3.0.19.Final</resteasy_version>
|
||||
<tomcat_embed_version>8.0.11</tomcat_embed_version>
|
||||
<!-- Log libs -->
|
||||
<slf4j_version>1.7.25</slf4j_version>
|
||||
<jcl_version>1.2</jcl_version>
|
||||
<log4j_version>1.2.16</log4j_version>
|
||||
<logback_version>1.2.2</logback_version>
|
||||
<commons_lang3_version>3.4</commons_lang3_version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- Common libs -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>${spring_version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
<version>${javassist_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.netty</groupId>
|
||||
<artifactId>netty</artifactId>
|
||||
<version>${netty_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>${netty4_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.mina</groupId>
|
||||
<artifactId>mina-core</artifactId>
|
||||
<version>${mina_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.grizzly</groupId>
|
||||
<artifactId>grizzly-core</artifactId>
|
||||
<version>${grizzly_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${httpclient_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.xstream</groupId>
|
||||
<artifactId>xstream</artifactId>
|
||||
<version>${xstream_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.bsf</groupId>
|
||||
<artifactId>bsf-api</artifactId>
|
||||
<version>${bsf_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jvnet.sorcerer</groupId>
|
||||
<artifactId>sorcerer-javac</artifactId>
|
||||
<version>${sorcerer_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.zookeeper</groupId>
|
||||
<artifactId>zookeeper</artifactId>
|
||||
<version>${zookeeper_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.101tec</groupId>
|
||||
<artifactId>zkclient</artifactId>
|
||||
<version>${zkclient_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-framework</artifactId>
|
||||
<version>${curator_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>${jedis_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.xmemcached</groupId>
|
||||
<artifactId>xmemcached</artifactId>
|
||||
<version>${xmemcached_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-frontend-simple</artifactId>
|
||||
<version>${cxf_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-transports-http</artifactId>
|
||||
<version>${cxf_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.thrift</groupId>
|
||||
<artifactId>libthrift</artifactId>
|
||||
<version>${thrift_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jfree</groupId>
|
||||
<artifactId>jfreechart</artifactId>
|
||||
<version>${jfreechart_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.caucho</groupId>
|
||||
<artifactId>hessian</artifactId>
|
||||
<version>${hessian_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>${servlet_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>jetty</artifactId>
|
||||
<version>${jetty_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<version>${validation_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>${hibernate_validator_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish</groupId>
|
||||
<artifactId>javax.el</artifactId>
|
||||
<version>${jel_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.cache</groupId>
|
||||
<artifactId>cache-api</artifactId>
|
||||
<version>${jcache_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-sca-api</artifactId>
|
||||
<version>${sca_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.inject</groupId>
|
||||
<artifactId>guice</artifactId>
|
||||
<version>${guice_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.citrus</groupId>
|
||||
<artifactId>citrus-webx-all</artifactId>
|
||||
<version>${webx_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity</artifactId>
|
||||
<version>${velocity_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.esotericsoftware</groupId>
|
||||
<artifactId>kryo</artifactId>
|
||||
<version>${kryo_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.javakaffee</groupId>
|
||||
<artifactId>kryo-serializers</artifactId>
|
||||
<version>${kryo_serializers_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.ruedigermoeller</groupId>
|
||||
<artifactId>fst</artifactId>
|
||||
<version>${fst_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>javax.ws.rs-api</artifactId>
|
||||
<version>${rs_api_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jaxrs</artifactId>
|
||||
<version>${resteasy_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-client</artifactId>
|
||||
<version>${resteasy_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-netty4</artifactId>
|
||||
<version>${resteasy_version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jdk-http</artifactId>
|
||||
<version>${resteasy_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jackson-provider</artifactId>
|
||||
<version>${resteasy_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jaxb-provider</artifactId>
|
||||
<version>${resteasy_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-core</artifactId>
|
||||
<version>${tomcat_embed_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-logging-juli</artifactId>
|
||||
<version>${tomcat_embed_version}</version>
|
||||
</dependency>
|
||||
<!-- Log libs -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${slf4j_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>${jcl_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>${log4j_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${logback_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons_lang3_version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
</project>
|
||||
|
|
@ -1,170 +0,0 @@
|
|||
<!--
|
||||
- Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
- contributor license agreements. See the NOTICE file distributed with
|
||||
- this work for additional information regarding copyright ownership.
|
||||
- The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
- (the "License"); you may not use this file except in compliance with
|
||||
- the License. You may obtain a copy of the License at
|
||||
-
|
||||
- http://www.apache.org/licenses/LICENSE-2.0
|
||||
-
|
||||
- Unless required by applicable law or agreed to in writing, software
|
||||
- distributed under the License is distributed on an "AS IS" BASIS,
|
||||
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
- See the License for the specific language governing permissions and
|
||||
- limitations under the License.
|
||||
-->
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-parent</artifactId>
|
||||
<version>2.6.0</version>
|
||||
</parent>
|
||||
<artifactId>dubbo-admin</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<name>${project.artifactId}</name>
|
||||
<description>The admin module of dubbo project</description>
|
||||
<properties>
|
||||
<wtpversion>1.5</wtpversion>
|
||||
<wtpContextName>/</wtpContextName>
|
||||
<eclipse.useProjectReferences>false</eclipse.useProjectReferences>
|
||||
<skip_maven_deploy>false</skip_maven_deploy>
|
||||
</properties>
|
||||
<!-- Fix webx 3.x not compatible with spring 4.x or higher -->
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>3.2.16.RELEASE</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.citrus</groupId>
|
||||
<artifactId>citrus-webx-all</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.netty</groupId>
|
||||
<artifactId>netty</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.mina</groupId>
|
||||
<artifactId>mina-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.grizzly</groupId>
|
||||
<artifactId>grizzly-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.xstream</groupId>
|
||||
<artifactId>xstream</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.bsf</groupId>
|
||||
<artifactId>bsf-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.zookeeper</groupId>
|
||||
<artifactId>zookeeper</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.101tec</groupId>
|
||||
<artifactId>zkclient</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-framework</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.xmemcached</groupId>
|
||||
<artifactId>xmemcached</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.thrift</groupId>
|
||||
<artifactId>libthrift</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.caucho</groupId>
|
||||
<artifactId>hessian</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.cache</groupId>
|
||||
<artifactId>cache-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>maven-jetty-plugin</artifactId>
|
||||
<version>${jetty_version}</version>
|
||||
<configuration>
|
||||
<contextPath>/</contextPath>
|
||||
<scanIntervalSeconds>10</scanIntervalSeconds>
|
||||
<connectors>
|
||||
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
|
||||
<port>8080</port>
|
||||
<maxIdleTime>60000</maxIdleTime>
|
||||
</connector>
|
||||
</connectors>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance;
|
||||
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Context
|
||||
*
|
||||
*/
|
||||
public interface PageContext {
|
||||
|
||||
public String get(String key);
|
||||
|
||||
public String[] gets(String key);
|
||||
|
||||
public Map<String, String[]> getAll();
|
||||
|
||||
public void put(String key, Object value);
|
||||
|
||||
public String getMessage(String key, Object... args);
|
||||
|
||||
public String getClientAddress();
|
||||
|
||||
public String getOperateAddress();
|
||||
|
||||
public String getRegistryAddress();
|
||||
|
||||
public String getURI();
|
||||
|
||||
public String getURL();
|
||||
|
||||
public String getReferer();
|
||||
|
||||
public User getLoginUser();
|
||||
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.biz.common.i18n;
|
||||
|
||||
public interface MessageResourceService {
|
||||
|
||||
public String get(String key, Object... args);
|
||||
|
||||
public String getMessage(String key, Object... args);
|
||||
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.biz.common.i18n.impl;
|
||||
|
||||
import com.alibaba.dubbo.governance.biz.common.i18n.MessageResourceService;
|
||||
import com.alibaba.dubbo.governance.web.common.i18n.LocaleUtil;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.NoSuchMessageException;
|
||||
|
||||
public class MessageResourceServiceImpl implements MessageResourceService {
|
||||
|
||||
@Autowired
|
||||
private MessageSource messageSource;
|
||||
|
||||
public void setMessageSource(MessageSource messageSource) {
|
||||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
public String get(String key, Object... args) {
|
||||
try {
|
||||
if (messageSource != null) {
|
||||
return messageSource.getMessage(key, args, key, LocaleUtil.getLocale());
|
||||
}
|
||||
return key;
|
||||
} catch (NoSuchMessageException e) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
public String getMessage(String key, Object... args) {
|
||||
return get(key, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.service;
|
||||
|
||||
import com.alibaba.dubbo.registry.common.domain.Config;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* TODO Comment of ConfigDAO
|
||||
*
|
||||
*/
|
||||
public interface ConfigService {
|
||||
|
||||
void update(List<Config> configs);
|
||||
|
||||
Map<String, String> findAllConfigsMap();
|
||||
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.service;
|
||||
|
||||
import com.alibaba.dubbo.registry.common.domain.Consumer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Query service for consumer info
|
||||
*
|
||||
*/
|
||||
public interface ConsumerService {
|
||||
|
||||
List<Consumer> findByService(String serviceName);
|
||||
|
||||
Consumer findConsumer(Long id);
|
||||
|
||||
List<Consumer> findAll();
|
||||
|
||||
/**
|
||||
* query for all consumer addresses
|
||||
*/
|
||||
List<String> findAddresses();
|
||||
|
||||
List<String> findAddressesByApplication(String application);
|
||||
|
||||
List<String> findAddressesByService(String serviceName);
|
||||
|
||||
List<Consumer> findByAddress(String consumerAddress);
|
||||
|
||||
List<String> findServicesByAddress(String consumerAddress);
|
||||
|
||||
List<String> findApplications();
|
||||
|
||||
List<String> findApplicationsByServiceName(String serviceName);
|
||||
|
||||
List<Consumer> findByApplication(String application);
|
||||
|
||||
List<String> findServicesByApplication(String application);
|
||||
|
||||
List<String> findServices();
|
||||
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.service;
|
||||
|
||||
import com.alibaba.dubbo.registry.common.domain.Override;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface OverrideService {
|
||||
|
||||
void saveOverride(Override override);
|
||||
|
||||
void updateOverride(Override override);
|
||||
|
||||
void deleteOverride(Long id);
|
||||
|
||||
void enableOverride(Long id);
|
||||
|
||||
void disableOverride(Long id);
|
||||
|
||||
List<Override> findByService(String service);
|
||||
|
||||
List<Override> findByAddress(String address);
|
||||
|
||||
List<Override> findByServiceAndAddress(String service, String address);
|
||||
|
||||
List<Override> findByApplication(String application);
|
||||
|
||||
List<Override> findByServiceAndApplication(String service, String application);
|
||||
|
||||
List<Override> findAll();
|
||||
|
||||
Override findById(Long id);
|
||||
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.service;
|
||||
|
||||
import com.alibaba.dubbo.registry.common.domain.Owner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface OwnerService {
|
||||
|
||||
List<String> findAllServiceNames();
|
||||
|
||||
List<String> findServiceNamesByUsername(String username);
|
||||
|
||||
List<String> findUsernamesByServiceName(String serviceName);
|
||||
|
||||
List<Owner> findByService(String serviceName);
|
||||
|
||||
List<Owner> findAll();
|
||||
|
||||
Owner findById(Long id);
|
||||
|
||||
void saveOwner(Owner owner);
|
||||
|
||||
void deleteOwner(Owner owner);
|
||||
|
||||
}
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.service;
|
||||
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ProviderService
|
||||
*
|
||||
*/
|
||||
public interface ProviderService {
|
||||
|
||||
void create(Provider provider);
|
||||
|
||||
void enableProvider(Long id);
|
||||
|
||||
void disableProvider(Long id);
|
||||
|
||||
void doublingProvider(Long id);
|
||||
|
||||
void halvingProvider(Long id);
|
||||
|
||||
void deleteStaticProvider(Long id);
|
||||
|
||||
void updateProvider(Provider provider);
|
||||
|
||||
Provider findProvider(Long id);
|
||||
|
||||
List<String> findServices();
|
||||
|
||||
List<String> findAddresses();
|
||||
|
||||
List<String> findAddressesByApplication(String application);
|
||||
|
||||
List<String> findAddressesByService(String serviceName);
|
||||
|
||||
List<String> findApplicationsByServiceName(String serviceName);
|
||||
|
||||
List<Provider> findByService(String serviceName);
|
||||
|
||||
List<Provider> findAll();
|
||||
|
||||
List<Provider> findByAddress(String providerAddress);
|
||||
|
||||
List<String> findServicesByAddress(String providerAddress);
|
||||
|
||||
List<String> findApplications();
|
||||
|
||||
List<Provider> findByApplication(String application);
|
||||
|
||||
List<String> findServicesByApplication(String application);
|
||||
|
||||
List<String> findMethodsByService(String serviceName);
|
||||
|
||||
Provider findByServiceAndAddress(String service, String address);
|
||||
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.service;
|
||||
|
||||
import com.alibaba.dubbo.registry.common.domain.Route;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* RouteService
|
||||
*
|
||||
*/
|
||||
public interface RouteService {
|
||||
|
||||
void createRoute(Route route);
|
||||
|
||||
void updateRoute(Route route);
|
||||
|
||||
void deleteRoute(Long id);
|
||||
|
||||
void enableRoute(Long id);
|
||||
|
||||
void disableRoute(Long id);
|
||||
|
||||
Route findRoute(Long id);
|
||||
|
||||
List<Route> findAll();
|
||||
|
||||
List<Route> findByService(String serviceName);
|
||||
|
||||
List<Route> findByAddress(String address);
|
||||
|
||||
List<Route> findByServiceAndAddress(String service, String address);
|
||||
|
||||
List<Route> findForceRouteByService(String service);
|
||||
|
||||
List<Route> findForceRouteByAddress(String address);
|
||||
|
||||
List<Route> findForceRouteByServiceAndAddress(String service, String address);
|
||||
|
||||
List<Route> findAllForceRoute();
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.service;
|
||||
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* UserService
|
||||
*
|
||||
*/
|
||||
public interface UserService {
|
||||
|
||||
List<User> findAllUsers();
|
||||
|
||||
User findUser(String username);
|
||||
|
||||
User findById(Long id);
|
||||
|
||||
void createUser(User user);
|
||||
|
||||
void updateUser(User user);
|
||||
|
||||
void modifyUser(User user);
|
||||
|
||||
boolean updatePassword(User user, String oldPassword);
|
||||
|
||||
void resetPassword(User user);
|
||||
|
||||
void enableUser(User user);
|
||||
|
||||
void disableUser(User user);
|
||||
|
||||
void deleteUser(User user);
|
||||
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.service.impl;
|
||||
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
import com.alibaba.dubbo.common.logger.LoggerFactory;
|
||||
import com.alibaba.dubbo.governance.sync.RegistryServerSync;
|
||||
import com.alibaba.dubbo.registry.RegistryService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* IbatisDAO
|
||||
*
|
||||
*/
|
||||
public class AbstractService {
|
||||
|
||||
protected static final Logger logger = LoggerFactory.getLogger(AbstractService.class);
|
||||
@Autowired
|
||||
protected RegistryService registryService;
|
||||
@Autowired
|
||||
private RegistryServerSync sync;
|
||||
|
||||
public ConcurrentMap<String, ConcurrentMap<String, Map<Long, URL>>> getRegistryCache() {
|
||||
return sync.getRegistryCache();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.service.impl;
|
||||
|
||||
import com.alibaba.dubbo.governance.service.ConfigService;
|
||||
import com.alibaba.dubbo.registry.common.domain.Config;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* TODO Comment of IbatisConfigDAO
|
||||
*
|
||||
*/
|
||||
public class ConfigServiceImpl extends AbstractService implements ConfigService {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.alibaba.dubbo.governance.service.ConfigService#update(java.util.List)
|
||||
*/
|
||||
public void update(List<Config> configs) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.alibaba.dubbo.governance.service.ConfigService#findAllConfigsMap()
|
||||
*/
|
||||
public Map<String, String> findAllConfigsMap() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,220 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.service.impl;
|
||||
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.governance.service.ConsumerService;
|
||||
import com.alibaba.dubbo.governance.sync.util.Pair;
|
||||
import com.alibaba.dubbo.governance.sync.util.SyncUtils;
|
||||
import com.alibaba.dubbo.registry.common.domain.Consumer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class ConsumerServiceImpl extends AbstractService implements ConsumerService {
|
||||
|
||||
public List<Consumer> findByService(String service) {
|
||||
return SyncUtils.url2ConsumerList(findConsumerUrlByService(service));
|
||||
}
|
||||
|
||||
public Consumer findConsumer(Long id) {
|
||||
return SyncUtils.url2Consumer(findConsumerUrl(id));
|
||||
}
|
||||
|
||||
private Pair<Long, URL> findConsumerUrl(Long id) {
|
||||
return SyncUtils.filterFromCategory(getRegistryCache(), Constants.CONSUMERS_CATEGORY, id);
|
||||
}
|
||||
|
||||
public List<Consumer> findAll() {
|
||||
return SyncUtils.url2ConsumerList(findAllConsumerUrl());
|
||||
}
|
||||
|
||||
private Map<Long, URL> findAllConsumerUrl() {
|
||||
Map<String, String> filter = new HashMap<String, String>();
|
||||
filter.put(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY);
|
||||
return SyncUtils.filterFromCategory(getRegistryCache(), filter);
|
||||
}
|
||||
|
||||
public List<String> findAddresses() {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
ConcurrentMap<String, Map<Long, URL>> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
|
||||
if (null == consumerUrls) return ret;
|
||||
|
||||
for (Map.Entry<String, Map<Long, URL>> e1 : consumerUrls.entrySet()) {
|
||||
Map<Long, URL> value = e1.getValue();
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
String app = u.getAddress();
|
||||
if (app != null) ret.add(app);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<String> findAddressesByApplication(String application) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
ConcurrentMap<String, Map<Long, URL>> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
|
||||
|
||||
if(consumerUrls == null)
|
||||
return ret;
|
||||
|
||||
for (Map.Entry<String, Map<Long, URL>> e1 : consumerUrls.entrySet()) {
|
||||
Map<Long, URL> value = e1.getValue();
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
if (application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
|
||||
String addr = u.getAddress();
|
||||
if (addr != null) ret.add(addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<String> findAddressesByService(String service) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
ConcurrentMap<String, Map<Long, URL>> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
|
||||
if (null == consumerUrls) return ret;
|
||||
|
||||
for (Map.Entry<Long, URL> e2 : consumerUrls.get(service).entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
String app = u.getAddress();
|
||||
if (app != null) ret.add(app);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<Consumer> findByAddress(String consumerAddress) {
|
||||
return SyncUtils.url2ConsumerList(findConsumerUrlByAddress(consumerAddress));
|
||||
}
|
||||
|
||||
public List<String> findServicesByAddress(String address) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
ConcurrentMap<String, Map<Long, URL>> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
|
||||
if (consumerUrls == null || address == null || address.length() == 0) return ret;
|
||||
|
||||
for (Map.Entry<String, Map<Long, URL>> e1 : consumerUrls.entrySet()) {
|
||||
Map<Long, URL> value = e1.getValue();
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
if (address.equals(u.getAddress())) {
|
||||
ret.add(e1.getKey());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Map<Long, URL> findConsumerUrlByAddress(String address) {
|
||||
Map<String, String> filter = new HashMap<String, String>();
|
||||
filter.put(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY);
|
||||
filter.put(SyncUtils.ADDRESS_FILTER_KEY, address);
|
||||
|
||||
return SyncUtils.filterFromCategory(getRegistryCache(), filter);
|
||||
}
|
||||
|
||||
public List<String> findApplications() {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
ConcurrentMap<String, Map<Long, URL>> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
|
||||
if (consumerUrls == null) return ret;
|
||||
|
||||
for (Map.Entry<String, Map<Long, URL>> e1 : consumerUrls.entrySet()) {
|
||||
Map<Long, URL> value = e1.getValue();
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
String app = u.getParameter(Constants.APPLICATION_KEY);
|
||||
if (app != null) ret.add(app);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<String> findApplicationsByServiceName(String service) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
ConcurrentMap<String, Map<Long, URL>> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
|
||||
if (consumerUrls == null) return ret;
|
||||
|
||||
Map<Long, URL> value = consumerUrls.get(service);
|
||||
if (value == null) {
|
||||
return ret;
|
||||
}
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
String app = u.getParameter(Constants.APPLICATION_KEY);
|
||||
if (app != null) ret.add(app);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<Consumer> findByApplication(String application) {
|
||||
return SyncUtils.url2ConsumerList(findConsumerUrlByApplication(application));
|
||||
}
|
||||
|
||||
private Map<Long, URL> findConsumerUrlByApplication(String application) {
|
||||
Map<String, String> filter = new HashMap<String, String>();
|
||||
filter.put(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY);
|
||||
filter.put(Constants.APPLICATION_KEY, application);
|
||||
|
||||
return SyncUtils.filterFromCategory(getRegistryCache(), filter);
|
||||
}
|
||||
|
||||
public List<String> findServicesByApplication(String application) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
ConcurrentMap<String, Map<Long, URL>> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
|
||||
if (consumerUrls == null || application == null || application.length() == 0) return ret;
|
||||
|
||||
for (Map.Entry<String, Map<Long, URL>> e1 : consumerUrls.entrySet()) {
|
||||
Map<Long, URL> value = e1.getValue();
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
if (application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
|
||||
ret.add(e1.getKey());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<String> findServices() {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
ConcurrentMap<String, Map<Long, URL>> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
|
||||
if (consumerUrls != null) ret.addAll(consumerUrls.keySet());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Map<Long, URL> findConsumerUrlByService(String service) {
|
||||
Map<String, String> filter = new HashMap<String, String>();
|
||||
filter.put(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY);
|
||||
filter.put(SyncUtils.SERVICE_FILTER_KEY, service);
|
||||
|
||||
return SyncUtils.filterFromCategory(getRegistryCache(), filter);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,188 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.service.impl;
|
||||
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.governance.service.OverrideService;
|
||||
import com.alibaba.dubbo.governance.sync.util.Pair;
|
||||
import com.alibaba.dubbo.governance.sync.util.SyncUtils;
|
||||
import com.alibaba.dubbo.registry.common.domain.Override;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* IbatisOverrideDAO.java
|
||||
*
|
||||
*/
|
||||
public class OverrideServiceImpl extends AbstractService implements OverrideService {
|
||||
|
||||
public void saveOverride(Override override) {
|
||||
URL url = getUrlFromOverride(override);
|
||||
registryService.register(url);
|
||||
}
|
||||
|
||||
public void updateOverride(Override override) {
|
||||
Long id = override.getId();
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no override id");
|
||||
}
|
||||
URL oldOverride = findOverrideUrl(id);
|
||||
if (oldOverride == null) {
|
||||
throw new IllegalStateException("Route was changed!");
|
||||
}
|
||||
URL newOverride = getUrlFromOverride(override);
|
||||
|
||||
registryService.unregister(oldOverride);
|
||||
registryService.register(newOverride);
|
||||
|
||||
}
|
||||
|
||||
public void deleteOverride(Long id) {
|
||||
URL oldOverride = findOverrideUrl(id);
|
||||
if (oldOverride == null) {
|
||||
throw new IllegalStateException("Route was changed!");
|
||||
}
|
||||
registryService.unregister(oldOverride);
|
||||
}
|
||||
|
||||
public void enableOverride(Long id) {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no override id");
|
||||
}
|
||||
|
||||
URL oldOverride = findOverrideUrl(id);
|
||||
if (oldOverride == null) {
|
||||
throw new IllegalStateException("Override was changed!");
|
||||
}
|
||||
if (oldOverride.getParameter("enabled", true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
URL newOverride = oldOverride.addParameter("enabled", true);
|
||||
registryService.unregister(oldOverride);
|
||||
registryService.register(newOverride);
|
||||
|
||||
}
|
||||
|
||||
public void disableOverride(Long id) {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no override id");
|
||||
}
|
||||
|
||||
URL oldProvider = findOverrideUrl(id);
|
||||
if (oldProvider == null) {
|
||||
throw new IllegalStateException("Override was changed!");
|
||||
}
|
||||
if (!oldProvider.getParameter("enabled", true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
URL newProvider = oldProvider.addParameter("enabled", false);
|
||||
registryService.unregister(oldProvider);
|
||||
registryService.register(newProvider);
|
||||
|
||||
}
|
||||
|
||||
private Map<Long, URL> findOverrideUrl(String service, String address, String application) {
|
||||
Map<String, String> filter = new HashMap<String, String>();
|
||||
filter.put(Constants.CATEGORY_KEY, Constants.CONFIGURATORS_CATEGORY);
|
||||
if (service != null && service.length() > 0) {
|
||||
filter.put(SyncUtils.SERVICE_FILTER_KEY, service);
|
||||
}
|
||||
if (address != null && address.length() > 0) {
|
||||
filter.put(SyncUtils.ADDRESS_FILTER_KEY, address);
|
||||
}
|
||||
if (application != null && application.length() > 0) {
|
||||
filter.put(Constants.APPLICATION_KEY, application);
|
||||
}
|
||||
return SyncUtils.filterFromCategory(getRegistryCache(), filter);
|
||||
}
|
||||
|
||||
public List<Override> findByAddress(String address) {
|
||||
return SyncUtils.url2OverrideList(findOverrideUrl(null, address, null));
|
||||
}
|
||||
|
||||
public List<Override> findByServiceAndAddress(String service, String address) {
|
||||
return SyncUtils.url2OverrideList(findOverrideUrl(service, address, null));
|
||||
}
|
||||
|
||||
public List<Override> findByApplication(String application) {
|
||||
return SyncUtils.url2OverrideList(findOverrideUrl(null, null, application));
|
||||
}
|
||||
|
||||
public List<Override> findByService(String service) {
|
||||
return SyncUtils.url2OverrideList(findOverrideUrl(service, null, null));
|
||||
}
|
||||
|
||||
public List<Override> findByServiceAndApplication(String service, String application) {
|
||||
return SyncUtils.url2OverrideList(findOverrideUrl(service, null, application));
|
||||
}
|
||||
|
||||
public List<Override> findAll() {
|
||||
return SyncUtils.url2OverrideList(findOverrideUrl(null, null, null));
|
||||
}
|
||||
|
||||
private Pair<Long, URL> findOverrideUrlPair(Long id) {
|
||||
return SyncUtils.filterFromCategory(getRegistryCache(), Constants.CONFIGURATORS_CATEGORY, id);
|
||||
}
|
||||
|
||||
public Override findById(Long id) {
|
||||
return SyncUtils.url2Override(findOverrideUrlPair(id));
|
||||
}
|
||||
|
||||
private URL getUrlFromOverride(Override override) {
|
||||
return override.toUrl();
|
||||
/*Map<String, String> params = ConvertUtil.serviceName2Map(override.getService());
|
||||
if(!params.containsKey(Constants.INTERFACE_KEY)) {
|
||||
throw new IllegalArgumentException("No interface info");
|
||||
}
|
||||
if(!params.containsKey(Constants.VERSION_KEY)) {
|
||||
throw new IllegalArgumentException("No version info");
|
||||
}
|
||||
|
||||
boolean enabled = override.isEnabled();
|
||||
if(!enabled) {
|
||||
params.put("enabled", "false");
|
||||
}
|
||||
String application = override.getApplication();
|
||||
if(!StringUtils.isEmpty(application)) {
|
||||
params.put("application", application);
|
||||
}
|
||||
String address = override.getAddress();
|
||||
if(!StringUtils.isEmpty(address)) {
|
||||
params.put("address", address);
|
||||
}
|
||||
|
||||
String overrideAddress = override.getOverrideAddress();
|
||||
if(StringUtils.isEmpty(overrideAddress)) {
|
||||
overrideAddress = "0.0.0.0";
|
||||
}
|
||||
params.put(Constants.CATEGORY_KEY, Constants.CONFIGURATORS_CATEGORY);
|
||||
|
||||
URL url = new URL("override", overrideAddress, -1, params);
|
||||
url = url.addParameterString(override.getParams());
|
||||
return url;*/
|
||||
}
|
||||
|
||||
URL findOverrideUrl(Long id) {
|
||||
return getUrlFromOverride(findById(id));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,158 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.service.impl;
|
||||
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.OverrideService;
|
||||
import com.alibaba.dubbo.governance.service.OwnerService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.registry.common.domain.Override;
|
||||
import com.alibaba.dubbo.registry.common.domain.Owner;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class OwnerServiceImpl extends AbstractService implements OwnerService {
|
||||
|
||||
@Autowired
|
||||
ProviderService providerService;
|
||||
|
||||
@Autowired
|
||||
OverrideService overrideService;
|
||||
|
||||
public List<String> findAllServiceNames() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<String> findServiceNamesByUsername(String username) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<String> findUsernamesByServiceName(String serviceName) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Owner> findByService(String serviceName) {
|
||||
List<Provider> pList = providerService.findByService(serviceName);
|
||||
List<Override> cList = overrideService.findByServiceAndAddress(serviceName, Constants.ANYHOST_VALUE);
|
||||
return toOverrideLiset(pList, cList);
|
||||
}
|
||||
|
||||
public List<Owner> findAll() {
|
||||
List<Provider> pList = providerService.findAll();
|
||||
List<Override> cList = overrideService.findAll();
|
||||
return toOverrideLiset(pList, cList);
|
||||
}
|
||||
|
||||
public Owner findById(Long id) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<Owner> toOverrideLiset(List<Provider> pList, List<Override> cList) {
|
||||
Map<String, Owner> oList = new HashMap<String, Owner>();
|
||||
for (Provider p : pList) {
|
||||
if (p.getUsername() != null) {
|
||||
for (String username : Constants.COMMA_SPLIT_PATTERN.split(p.getUsername())) {
|
||||
Owner o = new Owner();
|
||||
o.setService(p.getService());
|
||||
o.setUsername(username);
|
||||
oList.put(o.getService() + "/" + o.getUsername(), o);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Override c : cList) {
|
||||
Map<String, String> params = StringUtils.parseQueryString(c.getParams());
|
||||
String usernames = params.get("owner");
|
||||
if (usernames != null && usernames.length() > 0) {
|
||||
for (String username : Constants.COMMA_SPLIT_PATTERN.split(usernames)) {
|
||||
Owner o = new Owner();
|
||||
o.setService(c.getService());
|
||||
o.setUsername(username);
|
||||
oList.put(o.getService() + "/" + o.getUsername(), o);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ArrayList<Owner>(oList.values());
|
||||
}
|
||||
|
||||
public void saveOwner(Owner owner) {
|
||||
List<Override> overrides = overrideService.findByServiceAndAddress(owner.getService(), Constants.ANYHOST_VALUE);
|
||||
if (overrides == null || overrides.size() == 0) {
|
||||
Override override = new Override();
|
||||
override.setAddress(Constants.ANYHOST_VALUE);
|
||||
override.setService(owner.getService());
|
||||
override.setEnabled(true);
|
||||
override.setParams("owner=" + owner.getUsername());
|
||||
overrideService.saveOverride(override);
|
||||
} else {
|
||||
for (Override override : overrides) {
|
||||
Map<String, String> params = StringUtils.parseQueryString(override.getParams());
|
||||
String usernames = params.get("owner");
|
||||
if (usernames == null || usernames.length() == 0) {
|
||||
usernames = owner.getUsername();
|
||||
} else {
|
||||
usernames = usernames + "," + owner.getUsername();
|
||||
}
|
||||
params.put("owner", usernames);
|
||||
override.setParams(StringUtils.toQueryString(params));
|
||||
overrideService.updateOverride(override);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteOwner(Owner owner) {
|
||||
List<Override> overrides = overrideService.findByServiceAndAddress(owner.getService(), Constants.ANYHOST_VALUE);
|
||||
if (overrides == null || overrides.size() == 0) {
|
||||
Override override = new Override();
|
||||
override.setAddress(Constants.ANYHOST_VALUE);
|
||||
override.setService(owner.getService());
|
||||
override.setEnabled(true);
|
||||
override.setParams("owner=" + owner.getUsername());
|
||||
overrideService.saveOverride(override);
|
||||
} else {
|
||||
for (Override override : overrides) {
|
||||
Map<String, String> params = StringUtils.parseQueryString(override.getParams());
|
||||
String usernames = params.get("owner");
|
||||
if (usernames != null && usernames.length() > 0) {
|
||||
if (usernames.equals(owner.getUsername())) {
|
||||
params.remove("owner");
|
||||
} else {
|
||||
usernames = usernames.replace(owner.getUsername() + ",", "").replace("," + owner.getUsername(), "");
|
||||
params.put("owner", usernames);
|
||||
}
|
||||
if (params.size() > 0) {
|
||||
override.setParams(StringUtils.toQueryString(params));
|
||||
overrideService.updateOverride(override);
|
||||
} else {
|
||||
overrideService.deleteOverride(override.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,459 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.service.impl;
|
||||
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.OverrideService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.governance.sync.util.Pair;
|
||||
import com.alibaba.dubbo.governance.sync.util.SyncUtils;
|
||||
import com.alibaba.dubbo.registry.common.domain.Override;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
import com.alibaba.dubbo.registry.common.route.ParseUtils;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* IbatisProviderService
|
||||
*
|
||||
*/
|
||||
public class ProviderServiceImpl extends AbstractService implements ProviderService {
|
||||
|
||||
@Autowired
|
||||
OverrideService overrideService;
|
||||
|
||||
public void create(Provider provider) {
|
||||
URL url = provider.toUrl();
|
||||
registryService.register(url);
|
||||
}
|
||||
|
||||
public void enableProvider(Long id) {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no provider id");
|
||||
}
|
||||
|
||||
Provider oldProvider = findProvider(id);
|
||||
|
||||
if (oldProvider == null) {
|
||||
throw new IllegalStateException("Provider was changed!");
|
||||
}
|
||||
if (oldProvider.isDynamic()) {
|
||||
// Make sure we only have one override configured disable property.
|
||||
if (!oldProvider.isEnabled()) {
|
||||
Override override = new Override();
|
||||
override.setAddress(oldProvider.getAddress());
|
||||
override.setService(oldProvider.getService());
|
||||
override.setEnabled(true);
|
||||
override.setParams(Constants.DISABLED_KEY + "=false");
|
||||
overrideService.saveOverride(override);
|
||||
return;
|
||||
}
|
||||
List<Override> oList = overrideService.findByServiceAndAddress(oldProvider.getService(), oldProvider.getAddress());
|
||||
|
||||
for (Override o : oList) {
|
||||
Map<String, String> params = StringUtils.parseQueryString(o.getParams());
|
||||
if (params.containsKey(Constants.DISABLED_KEY)) {
|
||||
if (params.get(Constants.DISABLED_KEY).equals("true")) {
|
||||
overrideService.deleteOverride(o.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
oldProvider.setEnabled(true);
|
||||
updateProvider(oldProvider);
|
||||
}
|
||||
}
|
||||
|
||||
public void disableProvider(Long id) {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no provider id");
|
||||
}
|
||||
|
||||
Provider oldProvider = findProvider(id);
|
||||
if (oldProvider == null) {
|
||||
throw new IllegalStateException("Provider was changed!");
|
||||
}
|
||||
|
||||
if (oldProvider.isDynamic()) {
|
||||
// Make sure we only have one override configured disable property.
|
||||
if (oldProvider.isEnabled()) {
|
||||
Override override = new Override();
|
||||
override.setAddress(oldProvider.getAddress());
|
||||
override.setService(oldProvider.getService());
|
||||
override.setEnabled(true);
|
||||
override.setParams(Constants.DISABLED_KEY + "=true");
|
||||
overrideService.saveOverride(override);
|
||||
return;
|
||||
}
|
||||
List<Override> oList = overrideService.findByServiceAndAddress(oldProvider.getService(), oldProvider.getAddress());
|
||||
|
||||
for (Override o : oList) {
|
||||
Map<String, String> params = StringUtils.parseQueryString(o.getParams());
|
||||
if (params.containsKey(Constants.DISABLED_KEY)) {
|
||||
if (params.get(Constants.DISABLED_KEY).equals("false")) {
|
||||
overrideService.deleteOverride(o.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
oldProvider.setEnabled(false);
|
||||
updateProvider(oldProvider);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void doublingProvider(Long id) {
|
||||
setWeight(id, 2F);
|
||||
}
|
||||
|
||||
public void halvingProvider(Long id) {
|
||||
setWeight(id, 0.5F);
|
||||
}
|
||||
|
||||
public void setWeight(Long id, float factor) {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no provider id");
|
||||
}
|
||||
Provider oldProvider = findProvider(id);
|
||||
if (oldProvider == null) {
|
||||
throw new IllegalStateException("Provider was changed!");
|
||||
}
|
||||
Map<String, String> map = StringUtils.parseQueryString(oldProvider.getParameters());
|
||||
String weight = map.get(Constants.WEIGHT_KEY);
|
||||
if (oldProvider.isDynamic()) {
|
||||
// Make sure we only have one override configured disable property.
|
||||
List<Override> overrides = overrideService.findByServiceAndAddress(oldProvider.getService(), oldProvider.getAddress());
|
||||
if (overrides == null || overrides.size() == 0) {
|
||||
int value = getWeight(weight, factor);
|
||||
if (value != Constants.DEFAULT_WEIGHT) {
|
||||
Override override = new Override();
|
||||
override.setAddress(oldProvider.getAddress());
|
||||
override.setService(oldProvider.getService());
|
||||
override.setEnabled(true);
|
||||
override.setParams(Constants.WEIGHT_KEY + "=" + String.valueOf(value));
|
||||
overrideService.saveOverride(override);
|
||||
}
|
||||
} else {
|
||||
for (Override override : overrides) {
|
||||
Map<String, String> params = StringUtils.parseQueryString(override.getParams());
|
||||
String overrideWeight = params.get(Constants.WEIGHT_KEY);
|
||||
if (overrideWeight == null || overrideWeight.length() == 0) {
|
||||
overrideWeight = weight;
|
||||
}
|
||||
int value = getWeight(overrideWeight, factor);
|
||||
if (value == getWeight(weight, 1)) {
|
||||
params.remove(Constants.WEIGHT_KEY);
|
||||
} else {
|
||||
params.put(Constants.WEIGHT_KEY, String.valueOf(value));
|
||||
}
|
||||
if (params.size() > 0) {
|
||||
override.setParams(StringUtils.toQueryString(params));
|
||||
overrideService.updateOverride(override);
|
||||
} else {
|
||||
overrideService.deleteOverride(override.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int value = getWeight(weight, factor);
|
||||
if (value == Constants.DEFAULT_WEIGHT) {
|
||||
map.remove(Constants.WEIGHT_KEY);
|
||||
} else {
|
||||
map.put(Constants.WEIGHT_KEY, String.valueOf(value));
|
||||
}
|
||||
oldProvider.setParameters(StringUtils.toQueryString(map));
|
||||
updateProvider(oldProvider);
|
||||
}
|
||||
}
|
||||
|
||||
private int getWeight(String value, float factor) {
|
||||
int weight = 100;
|
||||
if (value != null && value.length() > 0) {
|
||||
weight = Integer.parseInt(value);
|
||||
}
|
||||
weight = (int) (weight * factor);
|
||||
if (weight < 1) weight = 1;
|
||||
if (weight == 2) weight = 3;
|
||||
if (weight == 24) weight = 25;
|
||||
return weight;
|
||||
}
|
||||
|
||||
public void deleteStaticProvider(Long id) {
|
||||
URL oldProvider = findProviderUrl(id);
|
||||
if (oldProvider == null) {
|
||||
throw new IllegalStateException("Provider was changed!");
|
||||
}
|
||||
registryService.unregister(oldProvider);
|
||||
}
|
||||
|
||||
public void updateProvider(Provider provider) {
|
||||
Long id = provider.getId();
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no provider id");
|
||||
}
|
||||
|
||||
URL oldProvider = findProviderUrl(id);
|
||||
if (oldProvider == null) {
|
||||
throw new IllegalStateException("Provider was changed!");
|
||||
}
|
||||
URL newProvider = provider.toUrl();
|
||||
|
||||
registryService.unregister(oldProvider);
|
||||
registryService.register(newProvider);
|
||||
}
|
||||
|
||||
public Provider findProvider(Long id) {
|
||||
return SyncUtils.url2Provider(findProviderUrlPair(id));
|
||||
}
|
||||
|
||||
public Pair<Long, URL> findProviderUrlPair(Long id) {
|
||||
return SyncUtils.filterFromCategory(getRegistryCache(), Constants.PROVIDERS_CATEGORY, id);
|
||||
}
|
||||
|
||||
public List<String> findServices() {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
|
||||
if (providerUrls != null) ret.addAll(providerUrls.keySet());
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<String> findAddresses() {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
|
||||
ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
|
||||
if (null == providerUrls) return ret;
|
||||
|
||||
for (Map.Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
|
||||
Map<Long, URL> value = e1.getValue();
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
String app = u.getAddress();
|
||||
if (app != null) ret.add(app);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<String> findAddressesByApplication(String application) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
|
||||
for (Map.Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
|
||||
Map<Long, URL> value = e1.getValue();
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
if (application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
|
||||
String addr = u.getAddress();
|
||||
if (addr != null) ret.add(addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<String> findAddressesByService(String service) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
|
||||
if (null == providerUrls) return ret;
|
||||
|
||||
for (Map.Entry<Long, URL> e2 : providerUrls.get(service).entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
String app = u.getAddress();
|
||||
if (app != null) ret.add(app);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<String> findApplicationsByServiceName(String service) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
|
||||
if (null == providerUrls) return ret;
|
||||
|
||||
Map<Long, URL> value = providerUrls.get(service);
|
||||
if (value == null) {
|
||||
return ret;
|
||||
}
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
String app = u.getParameter(Constants.APPLICATION_KEY);
|
||||
if (app != null) ret.add(app);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<Provider> findByService(String serviceName) {
|
||||
return SyncUtils.url2ProviderList(findProviderUrlByService(serviceName));
|
||||
}
|
||||
|
||||
private Map<Long, URL> findProviderUrlByService(String service) {
|
||||
Map<String, String> filter = new HashMap<String, String>();
|
||||
filter.put(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY);
|
||||
filter.put(SyncUtils.SERVICE_FILTER_KEY, service);
|
||||
|
||||
return SyncUtils.filterFromCategory(getRegistryCache(), filter);
|
||||
}
|
||||
|
||||
public List<Provider> findAll() {
|
||||
return SyncUtils.url2ProviderList(findAllProviderUrl());
|
||||
}
|
||||
|
||||
private Map<Long, URL> findAllProviderUrl() {
|
||||
Map<String, String> filter = new HashMap<String, String>();
|
||||
filter.put(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY);
|
||||
return SyncUtils.filterFromCategory(getRegistryCache(), filter);
|
||||
}
|
||||
|
||||
public List<Provider> findByAddress(String providerAddress) {
|
||||
return SyncUtils.url2ProviderList(findProviderUrlByAddress(providerAddress));
|
||||
}
|
||||
|
||||
public Map<Long, URL> findProviderUrlByAddress(String address) {
|
||||
Map<String, String> filter = new HashMap<String, String>();
|
||||
filter.put(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY);
|
||||
filter.put(SyncUtils.ADDRESS_FILTER_KEY, address);
|
||||
|
||||
return SyncUtils.filterFromCategory(getRegistryCache(), filter);
|
||||
}
|
||||
|
||||
public List<String> findServicesByAddress(String address) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
|
||||
ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
|
||||
if (providerUrls == null || address == null || address.length() == 0) return ret;
|
||||
|
||||
for (Map.Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
|
||||
Map<Long, URL> value = e1.getValue();
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
if (address.equals(u.getAddress())) {
|
||||
ret.add(e1.getKey());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<String> findApplications() {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
|
||||
if (providerUrls == null) return ret;
|
||||
|
||||
for (Map.Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
|
||||
Map<Long, URL> value = e1.getValue();
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
String app = u.getParameter(Constants.APPLICATION_KEY);
|
||||
if (app != null) ret.add(app);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<Provider> findByApplication(String application) {
|
||||
return SyncUtils.url2ProviderList(findProviderUrlByApplication(application));
|
||||
}
|
||||
|
||||
private Map<Long, URL> findProviderUrlByApplication(String application) {
|
||||
Map<String, String> filter = new HashMap<String, String>();
|
||||
filter.put(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY);
|
||||
filter.put(Constants.APPLICATION_KEY, application);
|
||||
return SyncUtils.filterFromCategory(getRegistryCache(), filter);
|
||||
}
|
||||
|
||||
public List<String> findServicesByApplication(String application) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
|
||||
ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
|
||||
if (providerUrls == null || application == null || application.length() == 0) return ret;
|
||||
|
||||
for (Map.Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
|
||||
Map<Long, URL> value = e1.getValue();
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
if (application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
|
||||
ret.add(e1.getKey());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<String> findMethodsByService(String service) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
|
||||
ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
|
||||
if (providerUrls == null || service == null || service.length() == 0) return ret;
|
||||
|
||||
Map<Long, URL> providers = providerUrls.get(service);
|
||||
if (null == providers || providers.isEmpty()) return ret;
|
||||
|
||||
Entry<Long, URL> p = providers.entrySet().iterator().next();
|
||||
String value = p.getValue().getParameter("methods");
|
||||
if (value == null || value.length() == 0) {
|
||||
return ret;
|
||||
}
|
||||
String[] methods = value.split(ParseUtils.METHOD_SPLIT);
|
||||
if (methods == null || methods.length == 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (String m : methods) {
|
||||
ret.add(m);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private URL findProviderUrl(Long id) {
|
||||
return findProvider(id).toUrl();
|
||||
}
|
||||
|
||||
public Provider findByServiceAndAddress(String service, String address) {
|
||||
return SyncUtils.url2Provider(findProviderUrl(service, address));
|
||||
}
|
||||
|
||||
private Pair<Long, URL> findProviderUrl(String service, String address) {
|
||||
Map<String, String> filter = new HashMap<String, String>();
|
||||
filter.put(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY);
|
||||
filter.put(SyncUtils.ADDRESS_FILTER_KEY, address);
|
||||
|
||||
Map<Long, URL> ret = SyncUtils.filterFromCategory(getRegistryCache(), filter);
|
||||
if (ret.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
Long key = ret.entrySet().iterator().next().getKey();
|
||||
return new Pair<Long, URL>(key, ret.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,166 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.service.impl;
|
||||
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.governance.service.RouteService;
|
||||
import com.alibaba.dubbo.governance.sync.util.Pair;
|
||||
import com.alibaba.dubbo.governance.sync.util.SyncUtils;
|
||||
import com.alibaba.dubbo.registry.common.domain.Route;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* IbatisRouteService
|
||||
*
|
||||
*/
|
||||
public class RouteServiceImpl extends AbstractService implements RouteService {
|
||||
|
||||
public void createRoute(Route route) {
|
||||
registryService.register(route.toUrl());
|
||||
}
|
||||
|
||||
public void updateRoute(Route route) {
|
||||
Long id = route.getId();
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no route id");
|
||||
}
|
||||
URL oldRoute = findRouteUrl(id);
|
||||
if (oldRoute == null) {
|
||||
throw new IllegalStateException("Route was changed!");
|
||||
}
|
||||
|
||||
registryService.unregister(oldRoute);
|
||||
registryService.register(route.toUrl());
|
||||
}
|
||||
|
||||
public void deleteRoute(Long id) {
|
||||
URL oldRoute = findRouteUrl(id);
|
||||
if (oldRoute == null) {
|
||||
throw new IllegalStateException("Route was changed!");
|
||||
}
|
||||
registryService.unregister(oldRoute);
|
||||
}
|
||||
|
||||
public void enableRoute(Long id) {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no route id");
|
||||
}
|
||||
|
||||
URL oldRoute = findRouteUrl(id);
|
||||
if (oldRoute == null) {
|
||||
throw new IllegalStateException("Route was changed!");
|
||||
}
|
||||
if (oldRoute.getParameter("enabled", true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
registryService.unregister(oldRoute);
|
||||
URL newRoute = oldRoute.addParameter("enabled", true);
|
||||
registryService.register(newRoute);
|
||||
|
||||
}
|
||||
|
||||
public void disableRoute(Long id) {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no route id");
|
||||
}
|
||||
|
||||
URL oldRoute = findRouteUrl(id);
|
||||
if (oldRoute == null) {
|
||||
throw new IllegalStateException("Route was changed!");
|
||||
}
|
||||
if (!oldRoute.getParameter("enabled", true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
URL newRoute = oldRoute.addParameter("enabled", false);
|
||||
registryService.unregister(oldRoute);
|
||||
registryService.register(newRoute);
|
||||
|
||||
}
|
||||
|
||||
public List<Route> findAll() {
|
||||
return SyncUtils.url2RouteList(findAllUrl());
|
||||
}
|
||||
|
||||
private Map<Long, URL> findAllUrl() {
|
||||
Map<String, String> filter = new HashMap<String, String>();
|
||||
filter.put(Constants.CATEGORY_KEY, Constants.ROUTERS_CATEGORY);
|
||||
|
||||
return SyncUtils.filterFromCategory(getRegistryCache(), filter);
|
||||
}
|
||||
|
||||
public Route findRoute(Long id) {
|
||||
return SyncUtils.url2Route(findRouteUrlPair(id));
|
||||
}
|
||||
|
||||
public Pair<Long, URL> findRouteUrlPair(Long id) {
|
||||
return SyncUtils.filterFromCategory(getRegistryCache(), Constants.ROUTERS_CATEGORY, id);
|
||||
}
|
||||
|
||||
private URL findRouteUrl(Long id) {
|
||||
return findRoute(id).toUrl();
|
||||
}
|
||||
|
||||
private Map<Long, URL> findRouteUrl(String service, String address, boolean force) {
|
||||
Map<String, String> filter = new HashMap<String, String>();
|
||||
filter.put(Constants.CATEGORY_KEY, Constants.ROUTERS_CATEGORY);
|
||||
if (service != null && service.length() > 0) {
|
||||
filter.put(SyncUtils.SERVICE_FILTER_KEY, service);
|
||||
}
|
||||
if (address != null && address.length() > 0) {
|
||||
filter.put(SyncUtils.ADDRESS_FILTER_KEY, address);
|
||||
}
|
||||
if (force) {
|
||||
filter.put("force", "true");
|
||||
}
|
||||
return SyncUtils.filterFromCategory(getRegistryCache(), filter);
|
||||
}
|
||||
|
||||
public List<Route> findByService(String serviceName) {
|
||||
return SyncUtils.url2RouteList(findRouteUrl(serviceName, null, false));
|
||||
}
|
||||
|
||||
public List<Route> findByAddress(String address) {
|
||||
return SyncUtils.url2RouteList(findRouteUrl(null, address, false));
|
||||
}
|
||||
|
||||
public List<Route> findByServiceAndAddress(String service, String address) {
|
||||
return SyncUtils.url2RouteList(findRouteUrl(service, address, false));
|
||||
}
|
||||
|
||||
public List<Route> findForceRouteByService(String service) {
|
||||
return SyncUtils.url2RouteList(findRouteUrl(service, null, true));
|
||||
}
|
||||
|
||||
public List<Route> findForceRouteByAddress(String address) {
|
||||
return SyncUtils.url2RouteList(findRouteUrl(null, address, true));
|
||||
}
|
||||
|
||||
public List<Route> findForceRouteByServiceAndAddress(String service, String address) {
|
||||
return SyncUtils.url2RouteList(findRouteUrl(service, address, true));
|
||||
}
|
||||
|
||||
public List<Route> findAllForceRoute() {
|
||||
return SyncUtils.url2RouteList(findRouteUrl(null, null, true));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,128 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.service.impl;
|
||||
|
||||
import com.alibaba.dubbo.governance.service.UserService;
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
import com.alibaba.dubbo.registry.common.util.Coder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* IBatisUserService
|
||||
*
|
||||
*/
|
||||
public class UserServiceImpl extends AbstractService implements UserService {
|
||||
|
||||
private String rootPassword;
|
||||
private String guestPassword;
|
||||
|
||||
public void setRootPassword(String password) {
|
||||
this.rootPassword = (password == null ? "" : password);
|
||||
}
|
||||
|
||||
public void setGuestPassword(String password) {
|
||||
this.guestPassword = (password == null ? "" : password);
|
||||
}
|
||||
|
||||
public User findUser(String username) {
|
||||
if ("guest".equals(username)) {
|
||||
User user = new User();
|
||||
user.setUsername(username);
|
||||
user.setPassword(Coder.encodeMd5(username + ":" + User.REALM + ":" + guestPassword));
|
||||
user.setName(username);
|
||||
user.setRole(User.GUEST);
|
||||
user.setEnabled(true);
|
||||
user.setLocale("zh");
|
||||
user.setServicePrivilege("");
|
||||
return user;
|
||||
} else if ("root".equals(username)) {
|
||||
User user = new User();
|
||||
user.setUsername(username);
|
||||
user.setPassword(Coder.encodeMd5(username + ":" + User.REALM + ":" + rootPassword));
|
||||
user.setName(username);
|
||||
user.setRole(User.ROOT);
|
||||
user.setEnabled(true);
|
||||
user.setLocale("zh");
|
||||
user.setServicePrivilege("*");
|
||||
return user;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<User> findAllUsers() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public Map<String, User> findAllUsersMap() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public User findById(Long id) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public void createUser(User user) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void updateUser(User user) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void modifyUser(User user) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public boolean updatePassword(User user, String oldPassword) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public void resetPassword(User user) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void enableUser(User user) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void disableUser(User user) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void deleteUser(User user) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public List<User> findUsersByServiceName(String serviceName) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.status;
|
||||
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
import com.alibaba.dubbo.common.logger.LoggerFactory;
|
||||
import com.alibaba.dubbo.common.status.Status;
|
||||
import com.alibaba.dubbo.common.status.StatusChecker;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
/**
|
||||
* DatabaseStatus
|
||||
*
|
||||
*/
|
||||
public class DatabaseStatusChecker implements StatusChecker {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DatabaseStatusChecker.class);
|
||||
|
||||
private int version;
|
||||
|
||||
private String message;
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
check(); // init
|
||||
}
|
||||
|
||||
public Status check() {
|
||||
boolean ok;
|
||||
try {
|
||||
Connection connection = dataSource.getConnection();
|
||||
try {
|
||||
DatabaseMetaData metaData = connection.getMetaData();
|
||||
ResultSet resultSet = metaData.getTypeInfo();
|
||||
try {
|
||||
ok = resultSet.next();
|
||||
} finally {
|
||||
resultSet.close();
|
||||
}
|
||||
if (message == null) {
|
||||
message = metaData.getURL()
|
||||
+ " (" + metaData.getDatabaseProductName()
|
||||
+ " " + metaData.getDatabaseProductVersion()
|
||||
+ ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")";
|
||||
}
|
||||
if (version == 0) {
|
||||
version = metaData.getDatabaseMajorVersion();
|
||||
}
|
||||
} finally {
|
||||
connection.close();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
ok = false;
|
||||
}
|
||||
return new Status(!ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message);
|
||||
}
|
||||
|
||||
private String getIsolation(int i) {
|
||||
if (i == Connection.TRANSACTION_READ_COMMITTED) {
|
||||
return "READ_COMMITTED";
|
||||
}
|
||||
if (i == Connection.TRANSACTION_READ_UNCOMMITTED) {
|
||||
return "READ_UNCOMMITTED";
|
||||
}
|
||||
if (i == Connection.TRANSACTION_REPEATABLE_READ) {
|
||||
return "REPEATABLE_READ";
|
||||
}
|
||||
if (i == Connection.TRANSACTION_SERIALIZABLE) {
|
||||
return "SERIALIZABLE)";
|
||||
}
|
||||
return "NONE";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.status;
|
||||
|
||||
import com.alibaba.dubbo.common.status.Status;
|
||||
import com.alibaba.dubbo.common.status.StatusChecker;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.OperatingSystemMXBean;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Load Status
|
||||
*
|
||||
*/
|
||||
public class LoadStatusChecker implements StatusChecker {
|
||||
|
||||
public Status check() {
|
||||
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
|
||||
double load;
|
||||
try {
|
||||
Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
|
||||
load = (Double) method.invoke(operatingSystemMXBean, new Object[0]);
|
||||
} catch (Throwable e) {
|
||||
load = -1;
|
||||
}
|
||||
int cpu = operatingSystemMXBean.getAvailableProcessors();
|
||||
return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), "Load: " + load + " / CPU: " + cpu);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.status;
|
||||
|
||||
import com.alibaba.dubbo.common.status.Status;
|
||||
import com.alibaba.dubbo.common.status.StatusChecker;
|
||||
|
||||
/**
|
||||
* MemoryStatus
|
||||
*
|
||||
*/
|
||||
public class MemoryStatusChecker implements StatusChecker {
|
||||
|
||||
public Status check() {
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
long freeMemory = runtime.freeMemory();
|
||||
long totalMemory = runtime.totalMemory();
|
||||
long maxMemory = runtime.maxMemory();
|
||||
boolean ok = (maxMemory - (totalMemory - freeMemory) > 2048); // Alarm when spare memory < 2M
|
||||
String msg = "Max:" + (maxMemory / 1024 / 1024) + "M, Total:"
|
||||
+ (totalMemory / 1024 / 1024) + "M, Free:" + (freeMemory / 1024 / 1024)
|
||||
+ "M, Use:" + ((totalMemory / 1024 / 1024) - (freeMemory / 1024 / 1024)) + "M";
|
||||
return new Status(ok ? Status.Level.OK : Status.Level.WARN, msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,159 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.sync;
|
||||
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
import com.alibaba.dubbo.common.logger.LoggerFactory;
|
||||
import com.alibaba.dubbo.common.utils.NetUtils;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.web.common.pulltool.Tool;
|
||||
import com.alibaba.dubbo.registry.NotifyListener;
|
||||
import com.alibaba.dubbo.registry.RegistryService;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class RegistryServerSync implements InitializingBean, DisposableBean, NotifyListener {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(RegistryServerSync.class);
|
||||
|
||||
private static final URL SUBSCRIBE = new URL(Constants.ADMIN_PROTOCOL, NetUtils.getLocalHost(), 0, "",
|
||||
Constants.INTERFACE_KEY, Constants.ANY_VALUE,
|
||||
Constants.GROUP_KEY, Constants.ANY_VALUE,
|
||||
Constants.VERSION_KEY, Constants.ANY_VALUE,
|
||||
Constants.CLASSIFIER_KEY, Constants.ANY_VALUE,
|
||||
Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY + ","
|
||||
+ Constants.CONSUMERS_CATEGORY + ","
|
||||
+ Constants.ROUTERS_CATEGORY + ","
|
||||
+ Constants.CONFIGURATORS_CATEGORY,
|
||||
Constants.ENABLED_KEY, Constants.ANY_VALUE,
|
||||
Constants.CHECK_KEY, String.valueOf(false));
|
||||
|
||||
private static final AtomicLong ID = new AtomicLong();
|
||||
|
||||
/**
|
||||
* Make sure ID never changed when the same url notified many times
|
||||
*/
|
||||
private final ConcurrentHashMap<String, Long> URL_IDS_MAPPER = new ConcurrentHashMap<String, Long>();
|
||||
|
||||
// ConcurrentMap<category, ConcurrentMap<servicename, Map<Long, URL>>>
|
||||
private final ConcurrentMap<String, ConcurrentMap<String, Map<Long, URL>>> registryCache = new ConcurrentHashMap<String, ConcurrentMap<String, Map<Long, URL>>>();
|
||||
@Autowired
|
||||
private RegistryService registryService;
|
||||
|
||||
public ConcurrentMap<String, ConcurrentMap<String, Map<Long, URL>>> getRegistryCache() {
|
||||
return registryCache;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
logger.info("Init Dubbo Admin Sync Cache...");
|
||||
registryService.subscribe(SUBSCRIBE, this);
|
||||
}
|
||||
|
||||
public void destroy() throws Exception {
|
||||
registryService.unsubscribe(SUBSCRIBE, this);
|
||||
}
|
||||
|
||||
// Notification of of any service with any type (override、subcribe、route、provider) is full.
|
||||
public void notify(List<URL> urls) {
|
||||
if (urls == null || urls.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// Map<category, Map<servicename, Map<Long, URL>>>
|
||||
final Map<String, Map<String, Map<Long, URL>>> categories = new HashMap<String, Map<String, Map<Long, URL>>>();
|
||||
String interfaceName = null;
|
||||
for (URL url : urls) {
|
||||
String category = url.getParameter(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY);
|
||||
if (Constants.EMPTY_PROTOCOL.equalsIgnoreCase(url.getProtocol())) { // NOTE: group and version in empty protocol is *
|
||||
ConcurrentMap<String, Map<Long, URL>> services = registryCache.get(category);
|
||||
if (services != null) {
|
||||
String group = url.getParameter(Constants.GROUP_KEY);
|
||||
String version = url.getParameter(Constants.VERSION_KEY);
|
||||
// NOTE: group and version in empty protocol is *
|
||||
if (!Constants.ANY_VALUE.equals(group) && !Constants.ANY_VALUE.equals(version)) {
|
||||
services.remove(url.getServiceKey());
|
||||
} else {
|
||||
for (Map.Entry<String, Map<Long, URL>> serviceEntry : services.entrySet()) {
|
||||
String service = serviceEntry.getKey();
|
||||
if (Tool.getInterface(service).equals(url.getServiceInterface())
|
||||
&& (Constants.ANY_VALUE.equals(group) || StringUtils.isEquals(group, Tool.getGroup(service)))
|
||||
&& (Constants.ANY_VALUE.equals(version) || StringUtils.isEquals(version, Tool.getVersion(service)))) {
|
||||
services.remove(service);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (StringUtils.isEmpty(interfaceName)) {
|
||||
interfaceName = url.getServiceInterface();
|
||||
}
|
||||
Map<String, Map<Long, URL>> services = categories.get(category);
|
||||
if (services == null) {
|
||||
services = new HashMap<String, Map<Long, URL>>();
|
||||
categories.put(category, services);
|
||||
}
|
||||
String service = url.getServiceKey();
|
||||
Map<Long, URL> ids = services.get(service);
|
||||
if (ids == null) {
|
||||
ids = new HashMap<Long, URL>();
|
||||
services.put(service, ids);
|
||||
}
|
||||
|
||||
// Make sure we use the same ID for the same URL
|
||||
if (URL_IDS_MAPPER.containsKey(url.toFullString())) {
|
||||
ids.put(URL_IDS_MAPPER.get(url.toFullString()), url);
|
||||
} else {
|
||||
long currentId = ID.incrementAndGet();
|
||||
ids.put(currentId, url);
|
||||
URL_IDS_MAPPER.putIfAbsent(url.toFullString(), currentId);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (categories.size() == 0) {
|
||||
return;
|
||||
}
|
||||
for (Map.Entry<String, Map<String, Map<Long, URL>>> categoryEntry : categories.entrySet()) {
|
||||
String category = categoryEntry.getKey();
|
||||
ConcurrentMap<String, Map<Long, URL>> services = registryCache.get(category);
|
||||
if (services == null) {
|
||||
services = new ConcurrentHashMap<String, Map<Long, URL>>();
|
||||
registryCache.put(category, services);
|
||||
} else {// Fix map can not be cleared when service is unregistered: when a unique “group/service:version” service is unregistered, but we still have the same services with different version or group, so empty protocols can not be invoked.
|
||||
Set<String> keys = new HashSet<String>(services.keySet());
|
||||
for (String key : keys) {
|
||||
if (Tool.getInterface(key).equals(interfaceName) && !categoryEntry.getValue().entrySet().contains(key)) {
|
||||
services.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
services.putAll(categoryEntry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.sync.util;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Pair<K, V> implements Map.Entry<K, V> {
|
||||
|
||||
private K key;
|
||||
|
||||
private V value;
|
||||
|
||||
public Pair() {
|
||||
}
|
||||
|
||||
public Pair(K key, V value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public K getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(K key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public V getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public V setValue(V value) {
|
||||
V old = this.value;
|
||||
this.value = value;
|
||||
return old;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((key == null) ? 0 : key.hashCode());
|
||||
result = prime * result + ((value == null) ? 0 : value.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Pair<?, ?> other = (Pair<?, ?>) obj;
|
||||
if (key == null) {
|
||||
if (other.key != null)
|
||||
return false;
|
||||
} else if (!key.equals(other.key))
|
||||
return false;
|
||||
if (value == null) {
|
||||
if (other.value != null)
|
||||
return false;
|
||||
} else if (!value.equals(other.value))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,254 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.sync.util;
|
||||
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.registry.common.domain.Consumer;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
import com.alibaba.dubbo.registry.common.domain.Route;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SyncUtils {
|
||||
|
||||
public static final String SERVICE_FILTER_KEY = ".service";
|
||||
|
||||
public static final String ADDRESS_FILTER_KEY = ".address";
|
||||
|
||||
public static final String ID_FILTER_KEY = ".id";
|
||||
|
||||
public static Provider url2Provider(Pair<Long, URL> pair) {
|
||||
if (pair == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Long id = pair.getKey();
|
||||
URL url = pair.getValue();
|
||||
|
||||
if (url == null)
|
||||
return null;
|
||||
|
||||
Provider p = new Provider();
|
||||
p.setId(id);
|
||||
p.setService(url.getServiceKey());
|
||||
p.setAddress(url.getAddress());
|
||||
p.setApplication(url.getParameter(Constants.APPLICATION_KEY));
|
||||
p.setUrl(url.toIdentityString());
|
||||
p.setParameters(url.toParameterString());
|
||||
|
||||
p.setDynamic(url.getParameter("dynamic", true));
|
||||
p.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));
|
||||
p.setWeight(url.getParameter(Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT));
|
||||
p.setUsername(url.getParameter("owner"));
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
public static List<Provider> url2ProviderList(Map<Long, URL> ps) {
|
||||
List<Provider> ret = new ArrayList<Provider>();
|
||||
for (Map.Entry<Long, URL> entry : ps.entrySet()) {
|
||||
ret.add(url2Provider(new Pair<Long, URL>(entry.getKey(), entry.getValue())));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Consumer url2Consumer(Pair<Long, URL> pair) {
|
||||
if (pair == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Long id = pair.getKey();
|
||||
URL url = pair.getValue();
|
||||
|
||||
if (null == url)
|
||||
return null;
|
||||
|
||||
Consumer c = new Consumer();
|
||||
c.setId(id);
|
||||
c.setService(url.getServiceKey());
|
||||
c.setAddress(url.getHost());
|
||||
c.setApplication(url.getParameter(Constants.APPLICATION_KEY));
|
||||
c.setParameters(url.toParameterString());
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
public static List<Consumer> url2ConsumerList(Map<Long, URL> cs) {
|
||||
List<Consumer> list = new ArrayList<Consumer>();
|
||||
if (cs == null) return list;
|
||||
for (Map.Entry<Long, URL> entry : cs.entrySet()) {
|
||||
list.add(url2Consumer(new Pair<Long, URL>(entry.getKey(), entry.getValue())));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static Route url2Route(Pair<Long, URL> pair) {
|
||||
if (pair == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Long id = pair.getKey();
|
||||
URL url = pair.getValue();
|
||||
|
||||
if (null == url)
|
||||
return null;
|
||||
|
||||
Route r = new Route();
|
||||
r.setId(id);
|
||||
r.setName(url.getParameter("name"));
|
||||
r.setService(url.getServiceKey());
|
||||
r.setPriority(url.getParameter(Constants.PRIORITY_KEY, 0));
|
||||
r.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));
|
||||
r.setForce(url.getParameter(Constants.FORCE_KEY, false));
|
||||
r.setRule(url.getParameterAndDecoded(Constants.RULE_KEY));
|
||||
return r;
|
||||
}
|
||||
|
||||
public static List<Route> url2RouteList(Map<Long, URL> cs) {
|
||||
List<Route> list = new ArrayList<Route>();
|
||||
if (cs == null) return list;
|
||||
for (Map.Entry<Long, URL> entry : cs.entrySet()) {
|
||||
list.add(url2Route(new Pair<Long, URL>(entry.getKey(), entry.getValue())));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static com.alibaba.dubbo.registry.common.domain.Override url2Override(Pair<Long, URL> pair) {
|
||||
if (pair == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Long id = pair.getKey();
|
||||
URL url = pair.getValue();
|
||||
|
||||
if (null == url)
|
||||
return null;
|
||||
|
||||
com.alibaba.dubbo.registry.common.domain.Override o = new com.alibaba.dubbo.registry.common.domain.Override();
|
||||
o.setId(id);
|
||||
|
||||
Map<String, String> parameters = new HashMap<String, String>(url.getParameters());
|
||||
|
||||
o.setService(url.getServiceKey());
|
||||
parameters.remove(Constants.INTERFACE_KEY);
|
||||
parameters.remove(Constants.GROUP_KEY);
|
||||
parameters.remove(Constants.VERSION_KEY);
|
||||
parameters.remove(Constants.APPLICATION_KEY);
|
||||
parameters.remove(Constants.CATEGORY_KEY);
|
||||
parameters.remove(Constants.DYNAMIC_KEY);
|
||||
parameters.remove(Constants.ENABLED_KEY);
|
||||
|
||||
o.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));
|
||||
|
||||
String host = url.getHost();
|
||||
boolean anyhost = url.getParameter(Constants.ANYHOST_VALUE, false);
|
||||
if (!anyhost || !"0.0.0.0".equals(host)) {
|
||||
o.setAddress(url.getAddress());
|
||||
}
|
||||
|
||||
o.setApplication(url.getParameter(Constants.APPLICATION_KEY, url.getUsername()));
|
||||
parameters.remove(Constants.VERSION_KEY);
|
||||
|
||||
o.setParams(StringUtils.toQueryString(parameters));
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
// Map<category, Map<servicename, Map<Long, URL>>>
|
||||
public static <SM extends Map<String, Map<Long, URL>>> Map<Long, URL> filterFromCategory(Map<String, SM> urls, Map<String, String> filter) {
|
||||
String c = (String) filter.get(Constants.CATEGORY_KEY);
|
||||
if (c == null) throw new IllegalArgumentException("no category");
|
||||
|
||||
filter.remove(Constants.CATEGORY_KEY);
|
||||
return filterFromService(urls.get(c), filter);
|
||||
}
|
||||
|
||||
public static List<com.alibaba.dubbo.registry.common.domain.Override> url2OverrideList(Map<Long, URL> cs) {
|
||||
List<com.alibaba.dubbo.registry.common.domain.Override> list = new ArrayList<com.alibaba.dubbo.registry.common.domain.Override>();
|
||||
if (cs == null) return list;
|
||||
for (Map.Entry<Long, URL> entry : cs.entrySet()) {
|
||||
list.add(url2Override(new Pair<Long, URL>(entry.getKey(), entry.getValue())));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
// Map<servicename, Map<Long, URL>>
|
||||
public static Map<Long, URL> filterFromService(Map<String, Map<Long, URL>> urls, Map<String, String> filter) {
|
||||
Map<Long, URL> ret = new HashMap<Long, URL>();
|
||||
if (urls == null) return ret;
|
||||
|
||||
String s = (String) filter.remove(SERVICE_FILTER_KEY);
|
||||
if (s == null) {
|
||||
for (Map.Entry<String, Map<Long, URL>> entry : urls.entrySet()) {
|
||||
filterFromUrls(entry.getValue(), ret, filter);
|
||||
}
|
||||
} else {
|
||||
Map<Long, URL> map = urls.get(s);
|
||||
filterFromUrls(map, ret, filter);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Map<Long, URL>
|
||||
static void filterFromUrls(Map<Long, URL> from, Map<Long, URL> to, Map<String, String> filter) {
|
||||
if (from == null || from.isEmpty()) return;
|
||||
|
||||
for (Map.Entry<Long, URL> entry : from.entrySet()) {
|
||||
URL url = entry.getValue();
|
||||
|
||||
boolean match = true;
|
||||
for (Map.Entry<String, String> e : filter.entrySet()) {
|
||||
String key = e.getKey();
|
||||
String value = e.getValue();
|
||||
|
||||
if (ADDRESS_FILTER_KEY.equals(key)) {
|
||||
if (!value.equals(url.getAddress())) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (!value.equals(url.getParameter(key))) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (match) {
|
||||
to.put(entry.getKey(), url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <SM extends Map<String, Map<Long, URL>>> Pair<Long, URL> filterFromCategory(Map<String, SM> urls, String category, Long id) {
|
||||
SM services = urls.get(category);
|
||||
if (services == null) return null;
|
||||
|
||||
for (Map.Entry<String, Map<Long, URL>> e1 : services.entrySet()) {
|
||||
Map<Long, URL> u = e1.getValue();
|
||||
if (u.containsKey(id)) return new Pair<Long, URL>(id, u.get(id));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.auth;
|
||||
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* MinasUser: DubboUser
|
||||
*
|
||||
*/
|
||||
public class DubboUser implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final ThreadLocal<User> userHolder = new ThreadLocal<User>();
|
||||
|
||||
private DubboUser() {
|
||||
}
|
||||
|
||||
public static final User getCurrentUser() {
|
||||
return (User) userHolder.get();
|
||||
}
|
||||
|
||||
public static final void setCurrentUser(User user) {
|
||||
userHolder.set(user);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.i18n;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class LocaleUtil {
|
||||
private static ThreadLocal<Locale> userLocale = new ThreadLocal<Locale>();
|
||||
|
||||
public static void cleanLocale() {
|
||||
userLocale.remove();
|
||||
}
|
||||
|
||||
public static Locale getLocale() {
|
||||
return userLocale.get();
|
||||
}
|
||||
|
||||
public static void setLocale(Locale locale) {
|
||||
userLocale.set(locale);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,218 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.interceptor;
|
||||
|
||||
import com.alibaba.citrus.service.pipeline.PipelineContext;
|
||||
import com.alibaba.citrus.service.pipeline.support.AbstractValve;
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
import com.alibaba.dubbo.common.logger.LoggerFactory;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.UserService;
|
||||
import com.alibaba.dubbo.governance.web.util.WebConstants;
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
import com.alibaba.dubbo.registry.common.util.Coder;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class AuthorizationValve extends AbstractValve {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AuthorizationValve.class);
|
||||
private static final String BASIC_CHALLENGE = "Basic";
|
||||
private static final String DIGEST_CHALLENGE = "Digest";
|
||||
private static final String CHALLENGE = BASIC_CHALLENGE;
|
||||
private static final String REALM = User.REALM;
|
||||
private static Pattern PARAMETER_PATTERN = Pattern.compile("(\\w+)=[\"]?([^,\"]+)[\"]?[,]?\\s*");
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
@Autowired
|
||||
private HttpServletResponse response;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
private String logout = "/logout";
|
||||
private String logoutCookie = "logout";
|
||||
|
||||
static Map<String, String> parseParameters(String query) {
|
||||
Matcher matcher = PARAMETER_PATTERN.matcher(query);
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
while (matcher.find()) {
|
||||
String key = matcher.group(1);
|
||||
String value = matcher.group(2);
|
||||
map.put(key, value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
static byte[] readToBytes(InputStream in) throws IOException {
|
||||
byte[] buf = new byte[in.available()];
|
||||
in.read(buf);
|
||||
return buf;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() throws Exception {
|
||||
}
|
||||
|
||||
public void invoke(PipelineContext pipelineContext) throws Exception {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("AuthorizationValve of uri: " + request.getRequestURI());
|
||||
}
|
||||
String uri = request.getRequestURI();
|
||||
String contextPath = request.getContextPath();
|
||||
if (contextPath != null && contextPath.length() > 0 && !"/".equals(contextPath)) {
|
||||
uri = uri.substring(contextPath.length());
|
||||
}
|
||||
if (uri.equals(logout)) {
|
||||
if (!isLogout()) {
|
||||
setLogout(true);
|
||||
showLoginForm();
|
||||
} else {
|
||||
setLogout(false);
|
||||
response.sendRedirect(contextPath == null || contextPath.length() == 0 ? "/" : contextPath);
|
||||
}
|
||||
return;
|
||||
}
|
||||
//FIXME
|
||||
if (!uri.startsWith("/status/")) {
|
||||
User user = null;
|
||||
String authType = null;
|
||||
String authorization = request.getHeader("Authorization");
|
||||
if (authorization != null && authorization.length() > 0) {
|
||||
int i = authorization.indexOf(' ');
|
||||
if (i >= 0) {
|
||||
authType = authorization.substring(0, i);
|
||||
String authPrincipal = authorization.substring(i + 1);
|
||||
if (BASIC_CHALLENGE.equalsIgnoreCase(authType)) {
|
||||
user = loginByBase(authPrincipal);
|
||||
} else if (DIGEST_CHALLENGE.equalsIgnoreCase(authType)) {
|
||||
user = loginByDigest(authPrincipal);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (user == null || user.getUsername() == null || user.getUsername().length() == 0) {
|
||||
showLoginForm();
|
||||
pipelineContext.breakPipeline(1);
|
||||
}
|
||||
if (user != null && StringUtils.isNotEmpty(user.getUsername())) {
|
||||
request.getSession().setAttribute(WebConstants.CURRENT_USER_KEY, user);
|
||||
pipelineContext.invokeNext();
|
||||
}
|
||||
} else {
|
||||
pipelineContext.invokeNext();
|
||||
}
|
||||
}
|
||||
|
||||
private User getUser(String username) {
|
||||
return userService.findUser(username);
|
||||
}
|
||||
|
||||
private void showLoginForm() throws IOException {
|
||||
if (DIGEST_CHALLENGE.equals(CHALLENGE)) {
|
||||
response.setHeader("WWW-Authenticate", CHALLENGE + " realm=\"" + REALM + "\", qop=\"auth\", nonce=\""
|
||||
+ UUID.randomUUID().toString().replace("-", "") + "\", opaque=\""
|
||||
+ Coder.encodeMd5(REALM) + "\"");
|
||||
} else {
|
||||
response.setHeader("WWW-Authenticate", CHALLENGE + " realm=\"" + REALM + "\"");
|
||||
}
|
||||
response.setHeader("Cache-Control", "must-revalidate,no-cache,no-store");
|
||||
response.setHeader("Content-Type", "text/html; charset=iso-8859-1");
|
||||
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
private User loginByBase(String authorization) {
|
||||
authorization = Coder.decodeBase64(authorization);
|
||||
int i = authorization.indexOf(':');
|
||||
String username = authorization.substring(0, i);
|
||||
if (username != null && username.length() > 0) {
|
||||
String password = authorization.substring(i + 1);
|
||||
if (password != null && password.length() > 0) {
|
||||
String passwordDigest = Coder.encodeMd5(username + ":" + REALM + ":" + password);
|
||||
User user = getUser(username);
|
||||
if (user != null) {
|
||||
String pwd = user.getPassword();
|
||||
if (pwd != null && pwd.length() > 0) {
|
||||
if (passwordDigest.equals(pwd)) {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private User loginByDigest(String value) throws IOException {
|
||||
Map<String, String> params = parseParameters(value);
|
||||
String username = params.get("username");
|
||||
if (username != null && username.length() > 0) {
|
||||
String passwordDigest = params.get("response");
|
||||
if (passwordDigest != null && passwordDigest.length() > 0) {
|
||||
User user = getUser(username);
|
||||
if (user != null) {
|
||||
String pwd = user.getPassword();
|
||||
// A valid user, validate password
|
||||
if (pwd != null && pwd.length() > 0) {
|
||||
String uri = params.get("uri");
|
||||
String nonce = params.get("nonce");
|
||||
String nc = params.get("nc");
|
||||
String cnonce = params.get("cnonce");
|
||||
String qop = params.get("qop");
|
||||
String method = request.getMethod();
|
||||
String a1 = pwd;
|
||||
|
||||
String a2 = "auth-int".equals(qop)
|
||||
? Coder.encodeMd5(method + ":" + uri + ":" + Coder.encodeMd5(readToBytes(request.getInputStream())))
|
||||
: Coder.encodeMd5(method + ":" + uri);
|
||||
String digest = "auth".equals(qop) || "auth-int".equals(qop)
|
||||
? Coder.encodeMd5(a1 + ":" + nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" + a2)
|
||||
: Coder.encodeMd5(a1 + ":" + nonce + ":" + a2);
|
||||
if (digest.equals(passwordDigest)) {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isLogout() {
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if (cookies != null && cookies.length > 0) {
|
||||
for (Cookie cookie : cookies) {
|
||||
if (cookie != null && logoutCookie.equals(cookie.getName())) {
|
||||
return "true".equals(cookie.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setLogout(boolean logoutValue) {
|
||||
response.addCookie(new Cookie(logoutCookie, String.valueOf(logoutValue)));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.interceptor;
|
||||
|
||||
import com.alibaba.citrus.service.pipeline.PipelineContext;
|
||||
import com.alibaba.citrus.service.pipeline.support.AbstractValve;
|
||||
import com.alibaba.citrus.turbine.TurbineRunData;
|
||||
import com.alibaba.dubbo.governance.web.common.i18n.LocaleUtil;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.alibaba.citrus.turbine.util.TurbineUtil.getTurbineRunData;
|
||||
|
||||
public class LocaleValve extends AbstractValve {
|
||||
|
||||
//Add exceptions for interceptors
|
||||
private final static Set<String> TARGET_WITHOUT_CHECK = new HashSet<String>();
|
||||
|
||||
static {
|
||||
TARGET_WITHOUT_CHECK.add("/ok");
|
||||
TARGET_WITHOUT_CHECK.add("/error");
|
||||
TARGET_WITHOUT_CHECK.add("/login");
|
||||
TARGET_WITHOUT_CHECK.add("/logout");
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
private boolean ignoreTarget(String target) {
|
||||
return TARGET_WITHOUT_CHECK.contains(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() throws Exception {
|
||||
}
|
||||
|
||||
public void invoke(PipelineContext pipelineContext) throws Exception {
|
||||
TurbineRunData rundata = getTurbineRunData(request);
|
||||
if (ignoreTarget(rundata.getTarget())) {
|
||||
pipelineContext.invokeNext();
|
||||
return;
|
||||
}
|
||||
|
||||
// default chinese
|
||||
String[] temp = rundata.getCookies().getStrings("locale");
|
||||
String locale = null;
|
||||
if (temp != null) {
|
||||
if (temp.length > 1) {
|
||||
locale = temp[temp.length - 1];
|
||||
} else if (temp.length == 1) {
|
||||
locale = temp[0];
|
||||
}
|
||||
}
|
||||
if (locale == null || "".equals(locale)) {
|
||||
locale = "en";
|
||||
}
|
||||
|
||||
Locale newLocale = Locale.SIMPLIFIED_CHINESE;
|
||||
if ("en".equals(locale)) {
|
||||
newLocale = Locale.ENGLISH;
|
||||
} else if ("zh".equals(locale)) {
|
||||
newLocale = Locale.SIMPLIFIED_CHINESE;
|
||||
} else if ("zh_TW".equals(locale)) {
|
||||
newLocale = Locale.TRADITIONAL_CHINESE;
|
||||
}
|
||||
LocaleUtil.setLocale(newLocale);
|
||||
|
||||
pipelineContext.invokeNext();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,204 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.interceptor;
|
||||
|
||||
import com.alibaba.citrus.service.requestcontext.rewrite.RewriteSubstitutionContext;
|
||||
import com.alibaba.citrus.service.requestcontext.rewrite.RewriteSubstitutionHandler;
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
import com.alibaba.dubbo.common.logger.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Rewrite: RESTFUL URL -> WebX URL.
|
||||
*
|
||||
*/
|
||||
public class RestfuleUrlRewriter implements RewriteSubstitutionHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(RestfuleUrlRewriter.class);
|
||||
|
||||
private static final Map<String, String> pl2single;
|
||||
private static final Set<String> appParameter;
|
||||
private final static String METHOD_KEY = "_method"; // show,
|
||||
private final static String TYPE_KEY = "_type";
|
||||
private final static String ID_KEY = "id";
|
||||
private final static String PAGES_KEY = "currentPage";
|
||||
private final static String PATH_KEY = "_path";
|
||||
private final static Pattern SLASH_PATTERN = Pattern.compile("/+");
|
||||
private final static Pattern NUM_PATTERN = Pattern.compile("\\d+");
|
||||
private final static Pattern MULTI_NUM_PATTERN = Pattern.compile("[+\\d]+");
|
||||
private final static Pattern PAGES_SPLIT_PATTERN = Pattern.compile("/+pages/+");
|
||||
private final static Pattern PAGES_PATTERN = Pattern.compile(".*/+pages/+\\d+$");
|
||||
|
||||
static {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
|
||||
map.put("services", "service");
|
||||
map.put("users", "user");
|
||||
map.put("addresses", "address");
|
||||
map.put("applications", "application");
|
||||
|
||||
map.put("providers", "provider");
|
||||
map.put("comsumers", "comsumer");
|
||||
|
||||
pl2single = Collections.unmodifiableMap(map);
|
||||
Set<String> set = new HashSet<String>();
|
||||
|
||||
set.add("_path");
|
||||
set.add("currentPage");
|
||||
set.add("_method");
|
||||
set.add("_type");
|
||||
set.add("id");
|
||||
|
||||
appParameter = Collections.unmodifiableSet(set);
|
||||
}
|
||||
|
||||
public void postSubstitution(RewriteSubstitutionContext context) {
|
||||
final String oldPath = context.getPath();
|
||||
String path = oldPath;
|
||||
while (path.startsWith("/")) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
|
||||
Map<String, String> param = new HashMap<String, String>();
|
||||
|
||||
// Paging
|
||||
if (PAGES_PATTERN.matcher(path).matches()) {
|
||||
String[] page_path = PAGES_SPLIT_PATTERN.split(path);
|
||||
path = page_path[0];
|
||||
param.put(PATH_KEY, page_path[0]);
|
||||
param.put(PAGES_KEY, page_path[1]);
|
||||
} else {
|
||||
param.put(PATH_KEY, path);
|
||||
}
|
||||
List<String> temp = Arrays.asList(SLASH_PATTERN.split(path));
|
||||
//Compatible with 2.0.x registry shell style url, for example: http://root:hello1234@127.0.0.1:8080/status/dubbo.test.api.HelloService:1.1
|
||||
if ("status".equals(temp.get(0)) && temp.size() > 1) {
|
||||
context.setPath("servicestatus");
|
||||
return;
|
||||
}
|
||||
//Compatible with paths containing group
|
||||
String[] split = temp.toArray(new String[temp.size()]);
|
||||
|
||||
if (temp.size() > 2 && temp.contains("services")) {
|
||||
List<String> parts = new ArrayList<String>();
|
||||
parts.addAll(temp);
|
||||
for (int i = 0; i < temp.size(); i++) {
|
||||
if ("services".equals(temp.get(i)) && i < (temp.size() - 1) && (!temp.get(i + 1).contains(".")) && (!temp.get(i + 1).matches("\\d+"))) {
|
||||
String group = parts.get(i + 1);
|
||||
String service = parts.get(i + 2);
|
||||
parts.remove(i + 1);
|
||||
parts.set(i + 1, group + "/" + service);
|
||||
break;
|
||||
}
|
||||
}
|
||||
split = parts.toArray(new String[parts.size()]);
|
||||
}
|
||||
|
||||
int index = split.length;
|
||||
// module/action
|
||||
if (split.length < 2) return;
|
||||
// The last part do not contains '.', like .htm .xsd .css etc.
|
||||
if (split[index - 1].contains(".")) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String type;
|
||||
// Even number
|
||||
// module/k/v/type or module/k/v/type/id/method
|
||||
if (index % 2 == 0) {
|
||||
if (MULTI_NUM_PATTERN.matcher(split[index - 2]).matches()) {
|
||||
// module/k/v/action/id/operate
|
||||
if (index < 4) return;
|
||||
|
||||
param.put(METHOD_KEY, split[index - 1]);
|
||||
param.put(ID_KEY, split[index - 2]);
|
||||
type = split[index - 3];
|
||||
param.put(TYPE_KEY, type);
|
||||
index -= 3;
|
||||
} else {
|
||||
// module/k/v/type
|
||||
type = split[index - 1];
|
||||
param.put(TYPE_KEY, type);
|
||||
--index;
|
||||
}
|
||||
}
|
||||
// Odd number
|
||||
// module/k/v/type/method or module/k/v/type/id
|
||||
else {
|
||||
if (index < 3) return;
|
||||
// module/k/v/type/id
|
||||
if (NUM_PATTERN.matcher(split[index - 1]).matches()) {
|
||||
param.put(ID_KEY, split[index - 1]);
|
||||
}
|
||||
// module/k/v/type/method
|
||||
else {
|
||||
param.put(METHOD_KEY, split[index - 1]);
|
||||
}
|
||||
type = split[index - 2];
|
||||
param.put(TYPE_KEY, type);
|
||||
index -= 2;
|
||||
}
|
||||
|
||||
// Extract KV pair
|
||||
for (int i = 1; i < index; i += 2) {
|
||||
param.put(split[i], split[i + 1]);
|
||||
}
|
||||
|
||||
String method = param.get(METHOD_KEY);
|
||||
|
||||
String defaultRedirect = null;
|
||||
if (method == null || method.equals("index")) {
|
||||
defaultRedirect = oldPath;
|
||||
} else {
|
||||
defaultRedirect = oldPath.split("/" + method)[0];
|
||||
}
|
||||
String id = param.get(ID_KEY);
|
||||
if (id != null) {
|
||||
int i = defaultRedirect.lastIndexOf("/");
|
||||
defaultRedirect = defaultRedirect.substring(0, i);
|
||||
}
|
||||
context.getParameters().setString("defaultRedirect", defaultRedirect);
|
||||
|
||||
final String module = split[0];
|
||||
context.setPath("/" + module + "/" + type + ".htm");
|
||||
|
||||
for (Map.Entry<String, String> entry : param.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
if (pl2single.containsKey(key)) {
|
||||
key = pl2single.get(key);
|
||||
} else if (appParameter.contains(key)) {
|
||||
// nothing
|
||||
} else {
|
||||
logger.info("key " + key + " is not pl noun!");
|
||||
}
|
||||
context.getParameters().setString(key, entry.getValue());
|
||||
}
|
||||
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("REWRITE restful uri " + oldPath + " to uri " + module + "/" + type + ".htm?" + param);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.interceptor;
|
||||
|
||||
import com.alibaba.citrus.service.pipeline.PipelineContext;
|
||||
import com.alibaba.citrus.service.pipeline.support.AbstractValve;
|
||||
import com.alibaba.citrus.turbine.TurbineRunData;
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
import com.alibaba.dubbo.common.logger.LoggerFactory;
|
||||
import com.alibaba.dubbo.governance.web.util.WebConstants;
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.alibaba.citrus.turbine.util.TurbineUtil.getTurbineRunData;
|
||||
|
||||
public class ServicePrivilegeCheckValve extends AbstractValve {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ServicePrivilegeCheckValve.class);
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Override
|
||||
protected void init() throws Exception {
|
||||
}
|
||||
|
||||
public void invoke(PipelineContext pipelineContext) throws Exception {
|
||||
User user = (User) request.getSession().getAttribute(WebConstants.CURRENT_USER_KEY);
|
||||
invokeCheckServicePrivilege(user);
|
||||
pipelineContext.invokeNext();
|
||||
}
|
||||
|
||||
|
||||
private void invokeCheckServicePrivilege(User user) {
|
||||
TurbineRunData rundata = getTurbineRunData(request);
|
||||
HttpSession session = request.getSession();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String[]> requestMapping = request.getParameterMap();
|
||||
|
||||
// record the last operation to request
|
||||
String returnURL = "";
|
||||
if (session.getAttribute("returnURL") == null) {
|
||||
returnURL = request.getContextPath();
|
||||
} else {
|
||||
returnURL = (String) session.getAttribute("returnURL");
|
||||
}
|
||||
|
||||
if (requestMapping.get("service").length > 0) {
|
||||
String service = ((String[]) requestMapping.get("service"))[0];
|
||||
String method = "index";
|
||||
if (requestMapping.get("_method").length > 0) {
|
||||
method = requestMapping.get("_method")[0];
|
||||
}
|
||||
|
||||
boolean exclude = "index".equals(method) || "show".equals(method);
|
||||
if (!exclude) {
|
||||
if (user != null && !user.hasServicePrivilege(service)) {
|
||||
request.setAttribute("returnURL", returnURL);
|
||||
redirectToNoRight(rundata);
|
||||
}
|
||||
}
|
||||
}
|
||||
String type = requestMapping.get("_type").length == 0 ? null : requestMapping.get("_type")[0];
|
||||
if (!"noServicePrivilege".equals(type)) {
|
||||
session.setAttribute("returnURL", request.getRequestURI());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* redirect if in case of no right.
|
||||
* @param rundata
|
||||
*/
|
||||
private void redirectToNoRight(TurbineRunData rundata) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("No right to access: " + request.getRequestURI());
|
||||
}
|
||||
|
||||
rundata.getParameters().setString("returnURL1", (String) rundata.getRequest().getAttribute("returnURL"));
|
||||
rundata.setRedirectLocation("http://localhost:8080/governance/noServicePrivilege?returnURL=" + rundata.getRequest().getAttribute("returnURL"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.governance.web.common.pulltool.RootContextPath;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Error_404 {
|
||||
|
||||
public void execute(Map<String, Object> context) throws Throwable {
|
||||
String contextPath = (String) context.get("request.contextPath");
|
||||
context.put("rootContextPath", new RootContextPath(contextPath));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.governance.web.common.pulltool.RootContextPath;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Error_other {
|
||||
|
||||
public void execute(Map<String, Object> context) throws Throwable {
|
||||
String contextPath = (String) context.get("request.contextPath");
|
||||
context.put("rootContextPath", new RootContextPath(contextPath));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,243 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
import com.alibaba.dubbo.common.logger.LoggerFactory;
|
||||
import com.alibaba.dubbo.common.utils.CompatibleTypeUtils;
|
||||
import com.alibaba.dubbo.governance.biz.common.i18n.MessageResourceService;
|
||||
import com.alibaba.dubbo.governance.web.common.pulltool.RootContextPath;
|
||||
import com.alibaba.dubbo.governance.web.util.WebConstants;
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* BaseScreen
|
||||
*
|
||||
*/
|
||||
public abstract class Restful {
|
||||
|
||||
protected static final Logger logger = LoggerFactory.getLogger(Restful.class);
|
||||
|
||||
protected static final Pattern SPACE_SPLIT_PATTERN = Pattern.compile("\\s+");
|
||||
//FIXME, to extract these auxiliary methods
|
||||
protected String role = null;
|
||||
protected String operator = null;
|
||||
protected User currentUser = null;
|
||||
protected String operatorAddress = null;
|
||||
protected String currentRegistry = null;
|
||||
@Autowired
|
||||
private MessageResourceService messageResourceService;
|
||||
|
||||
private static boolean isPrimitive(Class<?> cls) {
|
||||
return cls.isPrimitive() || cls == Boolean.class || cls == Byte.class
|
||||
|| cls == Character.class || cls == Short.class || cls == Integer.class
|
||||
|| cls == Long.class || cls == Float.class || cls == Double.class
|
||||
|| cls == String.class;
|
||||
}
|
||||
|
||||
private static Object convertPrimitive(Class<?> cls, String value) {
|
||||
if (cls == boolean.class || cls == Boolean.class) {
|
||||
return value == null || value.length() == 0 ? false : Boolean.valueOf(value);
|
||||
} else if (cls == byte.class || cls == Byte.class) {
|
||||
return value == null || value.length() == 0 ? 0 : Byte.valueOf(value);
|
||||
} else if (cls == char.class || cls == Character.class) {
|
||||
return value == null || value.length() == 0 ? '\0' : value.charAt(0);
|
||||
} else if (cls == short.class || cls == Short.class) {
|
||||
return value == null || value.length() == 0 ? 0 : Short.valueOf(value);
|
||||
} else if (cls == int.class || cls == Integer.class) {
|
||||
return value == null || value.length() == 0 ? 0 : Integer.valueOf(value);
|
||||
} else if (cls == long.class || cls == Long.class) {
|
||||
return value == null || value.length() == 0 ? 0 : Long.valueOf(value);
|
||||
} else if (cls == float.class || cls == Float.class) {
|
||||
return value == null || value.length() == 0 ? 0 : Float.valueOf(value);
|
||||
} else if (cls == double.class || cls == Double.class) {
|
||||
return value == null || value.length() == 0 ? 0 : Double.valueOf(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getMessage(String key, Object... args) {
|
||||
return messageResourceService.getMessage(key, args);
|
||||
}
|
||||
|
||||
public void execute(Map<String, Object> context) throws Throwable {
|
||||
if (context.get(WebConstants.CURRENT_USER_KEY) != null) {
|
||||
User user = (User) context.get(WebConstants.CURRENT_USER_KEY);
|
||||
currentUser = user;
|
||||
operator = user.getUsername();
|
||||
role = user.getRole();
|
||||
context.put(WebConstants.CURRENT_USER_KEY, user);
|
||||
}
|
||||
operatorAddress = (String) context.get("request.remoteHost");
|
||||
context.put("operator", operator);
|
||||
context.put("operatorAddress", operatorAddress);
|
||||
|
||||
context.put("currentRegistry", currentRegistry);
|
||||
|
||||
String httpMethod = (String) context.get("request.method");
|
||||
String method = (String) context.get("_method");
|
||||
String contextPath = (String) context.get("request.contextPath");
|
||||
context.put("rootContextPath", new RootContextPath(contextPath));
|
||||
|
||||
// Analyze Method
|
||||
if (method == null || method.length() == 0) {
|
||||
String id = (String) context.get("id");
|
||||
if (id == null || id.length() == 0) {
|
||||
method = "index";
|
||||
} else {
|
||||
method = "show";
|
||||
}
|
||||
}
|
||||
if ("index".equals(method)) {
|
||||
if ("post".equalsIgnoreCase(httpMethod)) {
|
||||
method = "create";
|
||||
}
|
||||
} else if ("show".equals(method)) {
|
||||
if ("put".equalsIgnoreCase(httpMethod) || "post".equalsIgnoreCase(httpMethod)) { // Instead of submitting a PUT request with a form, use POST instead
|
||||
method = "update";
|
||||
} else if ("delete".equalsIgnoreCase(httpMethod)) { // Instead of submitting a PUT request with a form, use POST instead
|
||||
method = "delete";
|
||||
}
|
||||
}
|
||||
context.put("_method", method);
|
||||
|
||||
try {
|
||||
Method m = null;
|
||||
try {
|
||||
m = getClass().getMethod(method, new Class<?>[]{Map.class});
|
||||
} catch (NoSuchMethodException e) {
|
||||
for (Method mtd : getClass().getMethods()) {
|
||||
if (Modifier.isPublic(mtd.getModifiers())
|
||||
&& mtd.getName().equals(method)) {
|
||||
m = mtd;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (m == null) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
if (m.getParameterTypes().length > 2) {
|
||||
throw new IllegalStateException("Unsupport restful method " + m);
|
||||
} else if (m.getParameterTypes().length == 2
|
||||
&& (m.getParameterTypes()[0].equals(Map.class)
|
||||
|| !m.getParameterTypes()[1].equals(Map.class))) {
|
||||
throw new IllegalStateException("Unsupport restful method " + m);
|
||||
}
|
||||
Object r;
|
||||
if (m.getParameterTypes().length == 0) {
|
||||
r = m.invoke(this, new Object[0]);
|
||||
} else {
|
||||
Object value;
|
||||
Class<?> t = m.getParameterTypes()[0];
|
||||
if (Map.class.equals(t)) {
|
||||
value = context;
|
||||
} else if (isPrimitive(t)) {
|
||||
String id = (String) context.get("id");
|
||||
value = convertPrimitive(t, id);
|
||||
} else if (t.isArray() && isPrimitive(t.getComponentType())) {
|
||||
String id = (String) context.get("id");
|
||||
String[] ids = id == null ? new String[0] : id.split("[.+]+");
|
||||
value = Array.newInstance(t.getComponentType(), ids.length);
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
Array.set(value, i, convertPrimitive(t.getComponentType(), ids[i]));
|
||||
}
|
||||
} else {
|
||||
value = t.newInstance();
|
||||
for (Method mtd : t.getMethods()) {
|
||||
if (Modifier.isPublic(mtd.getModifiers())
|
||||
&& mtd.getName().startsWith("set")
|
||||
&& mtd.getParameterTypes().length == 1) {
|
||||
String p = mtd.getName().substring(3, 4).toLowerCase() + mtd.getName().substring(4);
|
||||
Object v = context.get(p);
|
||||
if (v == null) {
|
||||
if ("operator".equals(p)) {
|
||||
v = operator;
|
||||
} else if ("operatorAddress".equals(p)) {
|
||||
v = (String) context.get("request.remoteHost");
|
||||
}
|
||||
}
|
||||
if (v != null) {
|
||||
try {
|
||||
mtd.invoke(value, new Object[]{CompatibleTypeUtils.compatibleTypeConvert(v, mtd.getParameterTypes()[0])});
|
||||
} catch (Throwable e) {
|
||||
logger.warn(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m.getParameterTypes().length == 1) {
|
||||
r = m.invoke(this, new Object[]{value});
|
||||
} else {
|
||||
r = m.invoke(this, new Object[]{value, context});
|
||||
}
|
||||
}
|
||||
if (m.getReturnType() == boolean.class || m.getReturnType() == Boolean.class) {
|
||||
context.put("rundata.layout", "redirect");
|
||||
context.put("rundata.target", "redirect");
|
||||
context.put("success", r == null || ((Boolean) r).booleanValue());
|
||||
if (context.get("redirect") == null) {
|
||||
context.put("redirect", getDefaultRedirect(context, method));
|
||||
}
|
||||
} else if (m.getReturnType() == String.class) {
|
||||
String redirect = (String) r;
|
||||
if (redirect == null) {
|
||||
redirect = getDefaultRedirect(context, method);
|
||||
}
|
||||
|
||||
if (context.get("chain") != null) {
|
||||
context.put("rundata.layout", "home");
|
||||
context.put("rundata.target", "home");
|
||||
} else {
|
||||
context.put("rundata.redirect", redirect);
|
||||
}
|
||||
} else {
|
||||
context.put("rundata.layout", method);
|
||||
context.put("rundata.target", context.get("rundata.target") + "/" + method);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof InvocationTargetException) {
|
||||
throw ((InvocationTargetException) e).getTargetException();
|
||||
}
|
||||
// if (e instanceof InvocationTargetException) {
|
||||
// e = ((InvocationTargetException) e).getTargetException();
|
||||
// }
|
||||
// logger.warn(e.getMessage(), e);
|
||||
// context.put("rundata.layout", "redirect");
|
||||
// context.put("rundata.target", "redirect");
|
||||
// context.put("success", false);
|
||||
// context.put("exception", e);
|
||||
// context.put("redirect", getDefaultRedirect(context, method));
|
||||
}
|
||||
}
|
||||
|
||||
private String getDefaultRedirect(Map<String, Object> context, String operate) {
|
||||
String defaultRedirect = (String) context.get("defaultRedirect");
|
||||
return defaultRedirect;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
|
||||
package com.alibaba.dubbo.governance.web.common.pulltool;
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* DateFormat Utility
|
||||
*
|
||||
*/
|
||||
public class DateFormatUtil {
|
||||
|
||||
private static final String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
private static final ThreadLocal<Map<String, DateFormat>> tl = new ThreadLocal<Map<String, DateFormat>>();
|
||||
|
||||
/**
|
||||
* According to the specified format, Get a DateFormat
|
||||
*
|
||||
* @param format
|
||||
* @return
|
||||
*/
|
||||
public static DateFormat getDateFormat(String format) {
|
||||
Map<String, DateFormat> map = tl.get();
|
||||
|
||||
if (map == null) {
|
||||
map = new HashMap<String, DateFormat>();
|
||||
tl.set(map);
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(format)) {
|
||||
format = DEFAULT_FORMAT;
|
||||
}
|
||||
|
||||
DateFormat ret = map.get(format);
|
||||
|
||||
if (ret == null) {
|
||||
ret = new SimpleDateFormat(format);
|
||||
map.put(format, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Default DateFormat
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static DateFormat getDateFormat() {
|
||||
return getDateFormat(null);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.pulltool;
|
||||
|
||||
import com.alibaba.citrus.service.pull.ToolFactory;
|
||||
import com.alibaba.dubbo.governance.biz.common.i18n.MessageResourceService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* PullTool for accessing message bundle.
|
||||
*x
|
||||
*/
|
||||
public class I18nMessageTool implements ToolFactory {
|
||||
|
||||
@Autowired
|
||||
private MessageResourceService messageResourceService;
|
||||
private boolean singleton = true;
|
||||
|
||||
public Object createTool() throws Exception {
|
||||
return messageResourceService;
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
return this.singleton;
|
||||
}
|
||||
|
||||
public void setSingleton(boolean singleton) {
|
||||
this.singleton = singleton;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.pulltool;
|
||||
|
||||
public class RootContextPath {
|
||||
|
||||
private String contextPath;
|
||||
|
||||
public RootContextPath(String contextPath) {
|
||||
this.contextPath = contextPath;
|
||||
}
|
||||
|
||||
public String getURI(String uri) {
|
||||
String prefix;
|
||||
if (contextPath != null && contextPath.length() > 0 && !"/".equals(contextPath)) {
|
||||
prefix = contextPath;
|
||||
} else {
|
||||
prefix = "";
|
||||
}
|
||||
if (uri.startsWith("/")) {
|
||||
return prefix + uri;
|
||||
} else {
|
||||
return prefix + "/" + uri;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,483 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.pulltool;
|
||||
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.utils.NetUtils;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.OverrideService;
|
||||
import com.alibaba.dubbo.governance.service.RouteService;
|
||||
import com.alibaba.dubbo.registry.common.domain.Consumer;
|
||||
import com.alibaba.dubbo.registry.common.domain.Override;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
import com.alibaba.dubbo.registry.common.domain.Route;
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
import com.alibaba.dubbo.registry.common.route.ParseUtils;
|
||||
import com.alibaba.dubbo.registry.common.route.RouteRule;
|
||||
import com.alibaba.dubbo.registry.common.route.RouteRule.MatchPair;
|
||||
import com.alibaba.dubbo.registry.common.util.StringEscapeUtils;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Array;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.UnknownHostException;
|
||||
import java.text.ParseException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Tool
|
||||
*
|
||||
*/
|
||||
public class Tool {
|
||||
|
||||
private static final Comparator<String> SIMPLE_NAME_COMPARATOR = new Comparator<String>() {
|
||||
public int compare(String s1, String s2) {
|
||||
if (s1 == null && s2 == null) {
|
||||
return 0;
|
||||
}
|
||||
if (s1 == null) {
|
||||
return -1;
|
||||
}
|
||||
if (s2 == null) {
|
||||
return 1;
|
||||
}
|
||||
s1 = getSimpleName(s1);
|
||||
s2 = getSimpleName(s2);
|
||||
return s1.compareToIgnoreCase(s2);
|
||||
}
|
||||
};
|
||||
private OverrideService overrideService;
|
||||
private RouteService routeService;
|
||||
|
||||
public static String toStackTraceString(Throwable t) {
|
||||
StringWriter writer = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(writer);
|
||||
t.printStackTrace(pw);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
public static boolean isContains(String[] values, String value) {
|
||||
return StringUtils.isContains(values, value);
|
||||
}
|
||||
|
||||
public static boolean startWith(String value, String prefix) {
|
||||
return value.startsWith(prefix);
|
||||
}
|
||||
|
||||
public static String getHostPrefix(String address) {
|
||||
if (address != null && address.length() > 0) {
|
||||
String hostname = getHostName(address);
|
||||
if (!address.startsWith(hostname)) {
|
||||
return "(" + hostname + ")";
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String getHostName(String address) {
|
||||
return NetUtils.getHostName(address);
|
||||
}
|
||||
|
||||
public static String getHostAddress(String address) {
|
||||
if (address != null && address.length() > 0) {
|
||||
int i = address.indexOf(':');
|
||||
String port = address.substring(i + 1);
|
||||
String hostname = NetUtils.getHostName(address);
|
||||
if (!address.equals(hostname)) {
|
||||
return hostname + ":" + port;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String getPath(String url) {
|
||||
try {
|
||||
return URL.valueOf(url).getPath();
|
||||
} catch (Throwable t) {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getAddress(String url) {
|
||||
try {
|
||||
return URL.valueOf(url).getAddress();
|
||||
} catch (Throwable t) {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getInterface(String service) {
|
||||
if (service != null && service.length() > 0) {
|
||||
int i = service.indexOf('/');
|
||||
if (i >= 0) {
|
||||
service = service.substring(i + 1);
|
||||
}
|
||||
i = service.lastIndexOf(':');
|
||||
if (i >= 0) {
|
||||
service = service.substring(0, i);
|
||||
}
|
||||
}
|
||||
return service;
|
||||
}
|
||||
|
||||
public static String getGroup(String service) {
|
||||
if (service != null && service.length() > 0) {
|
||||
int i = service.indexOf('/');
|
||||
if (i >= 0) {
|
||||
return service.substring(0, i);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getVersion(String service) {
|
||||
if (service != null && service.length() > 0) {
|
||||
int i = service.lastIndexOf(':');
|
||||
if (i >= 0) {
|
||||
return service.substring(i + 1);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getIP(String address) {
|
||||
if (address != null && address.length() > 0) {
|
||||
int i = address.indexOf("://");
|
||||
if (i >= 0) {
|
||||
address = address.substring(i + 3);
|
||||
}
|
||||
i = address.indexOf('/');
|
||||
if (i >= 0) {
|
||||
address = address.substring(0, i);
|
||||
}
|
||||
i = address.indexOf('@');
|
||||
if (i >= 0) {
|
||||
address = address.substring(i + 1);
|
||||
}
|
||||
i = address.indexOf(':');
|
||||
if (i >= 0) {
|
||||
address = address.substring(0, i);
|
||||
}
|
||||
if (address.matches("[a-zA-Z]+")) {
|
||||
try {
|
||||
address = InetAddress.getByName(address).getHostAddress();
|
||||
} catch (UnknownHostException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
||||
public static String encode(String url) {
|
||||
try {
|
||||
return URLEncoder.encode(url, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
public static String escape(String html) {
|
||||
return StringEscapeUtils.escapeHtml(html);
|
||||
}
|
||||
|
||||
public static String unescape(String html) {
|
||||
return StringEscapeUtils.unescapeHtml(html);
|
||||
}
|
||||
|
||||
public static String encodeUrl(String url) {
|
||||
return URL.encode(url);
|
||||
}
|
||||
|
||||
public static String decodeUrl(String url) {
|
||||
return URL.decode(url);
|
||||
}
|
||||
|
||||
public static String encodeHtml(String html) {
|
||||
return StringEscapeUtils.escapeHtml(html);
|
||||
}
|
||||
|
||||
public static int countMapValues(Map<?, ?> map) {
|
||||
int total = 0;
|
||||
if (map != null && map.size() > 0) {
|
||||
for (Object value : map.values()) {
|
||||
if (value != null) {
|
||||
if (value instanceof Number) {
|
||||
total += ((Number) value).intValue();
|
||||
} else if (value.getClass().isArray()) {
|
||||
total += Array.getLength(value);
|
||||
} else if (value instanceof Collection) {
|
||||
total += ((Collection<?>) value).size();
|
||||
} else if (value instanceof Map) {
|
||||
total += ((Map<?, ?>) value).size();
|
||||
} else {
|
||||
total += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public static List<String> sortSimpleName(List<String> list) {
|
||||
if (list != null && list.size() > 0) {
|
||||
Collections.sort(list, SIMPLE_NAME_COMPARATOR);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static String getSimpleName(String name) {
|
||||
if (name != null && name.length() > 0) {
|
||||
final int ip = name.indexOf('/');
|
||||
String v = ip != -1 ? name.substring(0, ip + 1) : "";
|
||||
|
||||
int i = name.lastIndexOf(':');
|
||||
int j = (i >= 0 ? name.lastIndexOf('.', i) : name.lastIndexOf('.'));
|
||||
if (j >= 0) {
|
||||
name = name.substring(j + 1);
|
||||
}
|
||||
name = v + name;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public static String getParameter(String parameters, String key) {
|
||||
String value = "";
|
||||
if (parameters != null && parameters.length() > 0) {
|
||||
String[] pairs = parameters.split("&");
|
||||
for (String pair : pairs) {
|
||||
String[] kv = pair.split("=");
|
||||
if (key.equals(kv[0])) {
|
||||
value = kv[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static Map<String, String> toParameterMap(String parameters) {
|
||||
return StringUtils.parseQueryString(parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the version value from the paramters parameter of provider
|
||||
*
|
||||
* @param parameters
|
||||
* @return
|
||||
*/
|
||||
public static String getVersionFromPara(String parameters) {
|
||||
String version = "";
|
||||
if (parameters != null && parameters.length() > 0) {
|
||||
String[] params = parameters.split("&");
|
||||
for (String o : params) {
|
||||
String[] kv = o.split("=");
|
||||
if ("version".equals(kv[0])) {
|
||||
version = kv[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
public static boolean isProviderEnabled(Provider provider, List<Override> oList) {
|
||||
for (Override o : oList) {
|
||||
if (o.isMatch(provider)) {
|
||||
Map<String, String> params = StringUtils.parseQueryString(o.getParams());
|
||||
String disbaled = params.get(Constants.DISABLED_KEY);
|
||||
if (disbaled != null && disbaled.length() > 0) {
|
||||
return !"true".equals(disbaled);
|
||||
}
|
||||
}
|
||||
}
|
||||
return provider.isEnabled();
|
||||
}
|
||||
|
||||
public static int getProviderWeight(Provider provider, List<Override> oList) {
|
||||
for (Override o : oList) {
|
||||
if (o.isMatch(provider)) {
|
||||
Map<String, String> params = StringUtils.parseQueryString(o.getParams());
|
||||
String weight = params.get(Constants.WEIGHT_KEY);
|
||||
if (weight != null && weight.length() > 0) {
|
||||
return Integer.parseInt(weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
return provider.getWeight();
|
||||
}
|
||||
|
||||
public void setOverrideService(OverrideService overrideService) {
|
||||
this.overrideService = overrideService;
|
||||
}
|
||||
|
||||
public void setRouteService(RouteService routeService) {
|
||||
this.routeService = routeService;
|
||||
}
|
||||
|
||||
public String formatTimestamp(String timestamp) {
|
||||
if (timestamp == null || timestamp.length() == 0) {
|
||||
return "";
|
||||
}
|
||||
return formatDate(new Date(Long.valueOf(timestamp)));
|
||||
}
|
||||
|
||||
//format date
|
||||
public String formatDate(Date date) {
|
||||
if (date == null) {
|
||||
return "";
|
||||
}
|
||||
return DateFormatUtil.getDateFormat().format(date);
|
||||
}
|
||||
|
||||
public String formatDate(Date date, String template) {
|
||||
if (date == null || template == null) {
|
||||
return "";
|
||||
}
|
||||
return DateFormatUtil.getDateFormat(template).format(date);
|
||||
}
|
||||
|
||||
public boolean beforeNow(Date date) {
|
||||
Date now = new Date();
|
||||
if (now.after(date)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//minus of date
|
||||
public long dateMinus(Date date1, Date date2) {
|
||||
return (date1.getTime() - date1.getTime()) / 1000;
|
||||
}
|
||||
|
||||
public boolean isProviderEnabled(Provider provider) {
|
||||
List<Override> oList = overrideService.findByServiceAndAddress(provider.getService(), provider.getAddress());
|
||||
return isProviderEnabled(provider, oList);
|
||||
}
|
||||
|
||||
public int getProviderWeight(Provider provider) {
|
||||
List<Override> oList = overrideService.findByServiceAndAddress(provider.getService(), provider.getAddress());
|
||||
return getProviderWeight(provider, oList);
|
||||
}
|
||||
|
||||
public boolean isInBlackList(Consumer consumer) {
|
||||
String service = consumer.getService();
|
||||
List<Route> routes = routeService.findForceRouteByService(service);
|
||||
if (routes == null || routes.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
String ip = getIP(consumer.getAddress());
|
||||
for (Route route : routes) {
|
||||
try {
|
||||
if (!route.isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
String filterRule = route.getFilterRule();
|
||||
if (filterRule == null || filterRule.length() == 0 || "false".equals(filterRule)) {
|
||||
Map<String, MatchPair> rule = RouteRule.parseRule(route.getMatchRule());
|
||||
MatchPair pair = rule.get("consumer.host");
|
||||
if (pair == null) {
|
||||
pair = rule.get("host");
|
||||
}
|
||||
if (pair != null) {
|
||||
if (pair.getMatches() != null && pair.getMatches().size() > 0) {
|
||||
for (String host : pair.getMatches()) {
|
||||
if (ParseUtils.isMatchGlobPattern(host, ip)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pair.getUnmatches() != null && pair.getUnmatches().size() > 0) {
|
||||
boolean forbid = true;
|
||||
for (String host : pair.getUnmatches()) {
|
||||
if (ParseUtils.isMatchGlobPattern(host, ip)) {
|
||||
forbid = false;
|
||||
}
|
||||
}
|
||||
if (forbid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getConsumerMock(Consumer consumer) {
|
||||
return getOverridesMock(consumer.getOverrides());
|
||||
}
|
||||
|
||||
public String getOverridesMock(List<Override> overrides) {
|
||||
if (overrides != null && overrides.size() > 0) {
|
||||
for (Override override : overrides) {
|
||||
Map<String, String> params = StringUtils.parseQueryString(override.getParams());
|
||||
String mock = params.get("mock");
|
||||
if (mock != null && mock.length() > 0) {
|
||||
return mock;
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean checkUrl(User user, String uri) {
|
||||
return true;
|
||||
/*if(!User.ROOT.equals(user.getRole())){
|
||||
List<String> disabledSysinfo = new ArrayList<String>();
|
||||
List<String> disabledSysmanage = new ArrayList<String>();
|
||||
Map<String, Boolean> features = daoCache.getFeatures();
|
||||
if (features.size() > 0){
|
||||
for(Entry<String,Boolean> feature : features.entrySet()){
|
||||
if(feature.getKey().startsWith("Sysinfo") && !feature.getValue()){
|
||||
disabledSysinfo.add(feature.getKey().replace(".", "/").toLowerCase());
|
||||
}else if(feature.getKey().startsWith("Sysmanage") && !feature.getValue()){
|
||||
disabledSysmanage.add(feature.getKey().replace(".", "/").toLowerCase());
|
||||
}
|
||||
}
|
||||
if(uri.startsWith("/sysinfo")){
|
||||
for(String disabled : disabledSysinfo){
|
||||
if (uri.contains(disabled)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(uri.startsWith("/sysmanage")){
|
||||
for(String disabled : disabledSysmanage){
|
||||
if (uri.contains(disabled)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;*/
|
||||
}
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.pulltool;
|
||||
|
||||
import com.alibaba.citrus.service.pull.ToolFactory;
|
||||
import com.alibaba.dubbo.governance.service.OverrideService;
|
||||
import com.alibaba.dubbo.governance.service.RouteService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* PullTool for accessing message bundle.
|
||||
*
|
||||
*/
|
||||
public class ToolUtil implements ToolFactory {
|
||||
@Autowired
|
||||
OverrideService overrideService;
|
||||
|
||||
@Autowired
|
||||
RouteService routeService;
|
||||
private boolean singleton = false;
|
||||
|
||||
public Object createTool() throws Exception {
|
||||
Tool tool = new Tool();
|
||||
tool.setOverrideService(overrideService);
|
||||
tool.setRouteService(routeService);
|
||||
return tool;
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
return this.singleton;
|
||||
}
|
||||
|
||||
public void setSingleton(boolean singleton) {
|
||||
this.singleton = singleton;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.resolver;
|
||||
|
||||
import com.alibaba.citrus.service.dataresolver.DataResolver;
|
||||
import com.alibaba.citrus.service.dataresolver.DataResolverContext;
|
||||
import com.alibaba.citrus.service.dataresolver.DataResolverFactory;
|
||||
import com.alibaba.citrus.turbine.TurbineRunDataInternal;
|
||||
import com.alibaba.citrus.turbine.util.TurbineUtil;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* MapDataResolverFactory
|
||||
*
|
||||
*/
|
||||
public class MapDataResolverFactory implements DataResolverFactory {
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
public DataResolver getDataResolver(DataResolverContext context) {
|
||||
if (Map.class == context.getTypeInfo().getRawType()) {
|
||||
return new MapDataResolver(context);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public class MapDataResolver implements DataResolver {
|
||||
|
||||
public final DataResolverContext context;
|
||||
|
||||
public MapDataResolver(DataResolverContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Object resolve() {
|
||||
TurbineRunDataInternal rundata = (TurbineRunDataInternal) TurbineUtil.getTurbineRunData(request);
|
||||
return new ParameterMap(request, rundata.getContext(), rundata);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,364 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.resolver;
|
||||
|
||||
import com.alibaba.citrus.turbine.Context;
|
||||
import com.alibaba.citrus.turbine.TurbineRunDataInternal;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* ParameterMap
|
||||
*
|
||||
*/
|
||||
public class ParameterMap implements Map<String, Object> {
|
||||
|
||||
private static final String CONTEXT_PREFIX = "context.";
|
||||
|
||||
private static final String PARAMETER_PREFIX = "parameter.";
|
||||
|
||||
private static final String HEADER_PREFIX = "header.";
|
||||
|
||||
private static final String REQUEST_PREFIX = "request.";
|
||||
|
||||
private static final String SESSION_PREFIX = "session.";
|
||||
|
||||
private static final String COOKIE_PREFIX = "cookie.";
|
||||
|
||||
private static final String APPLICATION_PREFIX = "application.";
|
||||
|
||||
private static final String RUNDATA_PREFIX = "rundata.";
|
||||
|
||||
private static final String METHOD_KEY = REQUEST_PREFIX + "method";
|
||||
|
||||
private static final String REMOTE_HOST_KEY = REQUEST_PREFIX + "remoteHost";
|
||||
|
||||
private static final String CONTEXT_PATH_KEY = REQUEST_PREFIX + "contextPath";
|
||||
|
||||
private static final String USER_PRINCIPAL_KEY = REQUEST_PREFIX + "userPrincipal";
|
||||
|
||||
private static final String TARGET_KEY = RUNDATA_PREFIX + "target";
|
||||
|
||||
private static final String FORWARD_KEY = RUNDATA_PREFIX + "forward";
|
||||
|
||||
private static final String BACKWARD_KEY = RUNDATA_PREFIX + "backward";
|
||||
|
||||
private static final String REDIRECT_KEY = RUNDATA_PREFIX + "redirect";
|
||||
|
||||
private static final String REDIRECTED_KEY = RUNDATA_PREFIX + "redirected";
|
||||
|
||||
private static final String LAYOUT_KEY = RUNDATA_PREFIX + "layout";
|
||||
|
||||
private static final String LAYOUT_ENABLED_KEY = RUNDATA_PREFIX + "layoutEnabled";
|
||||
|
||||
private final HttpServletRequest request;
|
||||
|
||||
private final Context context;
|
||||
|
||||
private final TurbineRunDataInternal rundata;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ParameterMap(HttpServletRequest request, Context context, TurbineRunDataInternal navigator) {
|
||||
super();
|
||||
this.request = request;
|
||||
this.context = context;
|
||||
this.rundata = navigator;
|
||||
Enumeration<String> keys = request.getParameterNames();
|
||||
while (keys.hasMoreElements()) {
|
||||
String key = keys.nextElement();
|
||||
Object value = getParameterValue(key);
|
||||
context.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsValue(Object value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
Set<String> keys = context.keySet();
|
||||
if (keys != null && keys.size() > 0) {
|
||||
for (String key : keys) {
|
||||
if (value.equals(context.get(key))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsKey(Object key) {
|
||||
String k = (String) key;
|
||||
if (k == null || k.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
return context.containsKey(k) || request.getParameter(k) != null;
|
||||
}
|
||||
|
||||
public Object get(Object key) {
|
||||
String k = (String) key;
|
||||
if (k == null || k.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
if (METHOD_KEY.equals(k)) {
|
||||
return request.getMethod();
|
||||
} else if (REMOTE_HOST_KEY.equals(k)) {
|
||||
return request.getRemoteHost();
|
||||
} else if (CONTEXT_PATH_KEY.equals(k)) {
|
||||
return request.getContextPath();
|
||||
} else if (USER_PRINCIPAL_KEY.equals(k)) {
|
||||
return request.getUserPrincipal();
|
||||
} else if (TARGET_KEY.equals(k)) {
|
||||
return rundata.getTarget();
|
||||
} else if (FORWARD_KEY.equals(k)) {
|
||||
return rundata.getRedirectTarget();
|
||||
} else if (REDIRECT_KEY.equals(k)) {
|
||||
return rundata.getRedirectLocation();
|
||||
} else if (REDIRECTED_KEY.equals(k)) {
|
||||
return rundata.isRedirected();
|
||||
} else if (LAYOUT_KEY.equals(k)) {
|
||||
return rundata.getLayoutTemplateOverride();
|
||||
} else if (LAYOUT_ENABLED_KEY.equals(k)) {
|
||||
return rundata.isLayoutEnabled();
|
||||
} else if (k.startsWith(CONTEXT_PREFIX)) {
|
||||
return context.get(k.substring(CONTEXT_PREFIX.length()));
|
||||
} else if (k.startsWith(PARAMETER_PREFIX)) {
|
||||
return getParameterValue(k.substring(PARAMETER_PREFIX.length()));
|
||||
} else if (k.startsWith(HEADER_PREFIX)) {
|
||||
return request.getHeader(k.substring(HEADER_PREFIX.length()));
|
||||
} else if (k.startsWith(REQUEST_PREFIX)) {
|
||||
return request.getAttribute(k.substring(REQUEST_PREFIX.length()));
|
||||
} else if (k.startsWith(SESSION_PREFIX)) {
|
||||
return request.getSession().getAttribute(k.substring(SESSION_PREFIX.length()));
|
||||
} else if (k.startsWith(COOKIE_PREFIX)) {
|
||||
return getCookieValue(k.substring(COOKIE_PREFIX.length()));
|
||||
} else if (k.startsWith(APPLICATION_PREFIX)) {
|
||||
return request.getSession().getServletContext().getAttribute(k.substring(APPLICATION_PREFIX.length()));
|
||||
} else {
|
||||
Object value = context.get(k);
|
||||
if (value == null) {
|
||||
value = getParameterValue(k);
|
||||
if (value == null) {
|
||||
value = request.getAttribute(k);
|
||||
if (value == null) {
|
||||
value = request.getSession().getAttribute(k);
|
||||
if (value == null) {
|
||||
value = getCookieValue(k);
|
||||
if (value == null) {
|
||||
value = request.getSession().getServletContext().getAttribute(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
private Object getParameterValue(String key) {
|
||||
String[] values = request.getParameterValues(key);
|
||||
if (values == null || values.length == 0) {
|
||||
return null;
|
||||
} else if (values.length == 1) {
|
||||
return values[0];
|
||||
} else {
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
private Object getCookieValue(String key) {
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if (cookies != null && cookies.length > 0) {
|
||||
for (Cookie cookie : cookies) {
|
||||
if (key.equals(cookie.getName())) {
|
||||
return cookie.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object put(String key, Object value) {
|
||||
if (key == null || key.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
if (TARGET_KEY.equals(key)) {
|
||||
rundata.setTarget((String) value);
|
||||
return null;
|
||||
} else if (FORWARD_KEY.equals(key)) {
|
||||
rundata.setRedirectTarget((String) value);
|
||||
return null;
|
||||
} else if (BACKWARD_KEY.equals(key)) {
|
||||
rundata.setRedirectLocation(request.getHeader("Referer"));
|
||||
return null;
|
||||
} else if (REDIRECT_KEY.equals(key)) {
|
||||
rundata.setRedirectLocation((String) value);
|
||||
return null;
|
||||
} else if (LAYOUT_KEY.equals(key)) {
|
||||
rundata.setLayout((String) value);
|
||||
return null;
|
||||
} else if (LAYOUT_ENABLED_KEY.equals(key)) {
|
||||
rundata.setLayoutEnabled((Boolean) value);
|
||||
return null;
|
||||
} else {
|
||||
if (key.startsWith(REQUEST_PREFIX)) {
|
||||
key = key.substring(APPLICATION_PREFIX.length());
|
||||
Object old = request.getAttribute(key);
|
||||
if (value == null) {
|
||||
request.removeAttribute(key);
|
||||
} else {
|
||||
request.setAttribute(key, value);
|
||||
}
|
||||
return old;
|
||||
} else if (key.startsWith(SESSION_PREFIX)) {
|
||||
key = key.substring(APPLICATION_PREFIX.length());
|
||||
Object old = request.getSession().getAttribute(key);
|
||||
if (value == null) {
|
||||
request.getSession().removeAttribute(key);
|
||||
} else {
|
||||
request.getSession().setAttribute(key, value);
|
||||
}
|
||||
return old;
|
||||
} else if (key.startsWith(COOKIE_PREFIX)) {
|
||||
key = key.substring(APPLICATION_PREFIX.length());
|
||||
Object old = null;
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if (cookies != null && cookies.length > 0) {
|
||||
for (Cookie cookie : cookies) {
|
||||
if (key.equals(cookie.getName())) {
|
||||
old = cookie.getValue();
|
||||
if (value == null) {
|
||||
cookie.setMaxAge(-1);
|
||||
} else {
|
||||
cookie.setValue((String) value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return old;
|
||||
} else if (key.startsWith(APPLICATION_PREFIX)) {
|
||||
key = key.substring(APPLICATION_PREFIX.length());
|
||||
Object old = request.getSession().getServletContext().getAttribute(key);
|
||||
if (value == null) {
|
||||
request.getSession().getServletContext().removeAttribute(key);
|
||||
} else {
|
||||
request.getSession().getServletContext().setAttribute(key, value);
|
||||
}
|
||||
return old;
|
||||
} else {
|
||||
if (key.startsWith(APPLICATION_PREFIX)) {
|
||||
key = key.substring(APPLICATION_PREFIX.length());
|
||||
}
|
||||
Object old = context.get(key);
|
||||
if (value == null) {
|
||||
context.remove(key);
|
||||
} else {
|
||||
context.put(key, value);
|
||||
}
|
||||
return old;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object remove(Object key) {
|
||||
return put((String) key, null);
|
||||
}
|
||||
|
||||
public void putAll(Map<? extends String, ? extends Object> map) {
|
||||
if (map != null && map.size() > 0) {
|
||||
for (Map.Entry<? extends String, ? extends Object> entry : map.entrySet()) {
|
||||
put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
Set<String> keys = context.keySet();
|
||||
if (keys != null && keys.size() > 0) {
|
||||
for (String key : keys) {
|
||||
context.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Set<String> keySet() {
|
||||
return context.keySet();
|
||||
}
|
||||
|
||||
public Collection<Object> values() {
|
||||
Set<String> keys = context.keySet();
|
||||
Set<Object> values = new HashSet<Object>();
|
||||
if (keys != null && keys.size() > 0) {
|
||||
for (String key : keys) {
|
||||
values.add(context.get(key));
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public Set<Entry<String, Object>> entrySet() {
|
||||
Set<String> keys = context.keySet();
|
||||
Set<Entry<String, Object>> entries = new HashSet<Entry<String, Object>>();
|
||||
if (keys != null && keys.size() > 0) {
|
||||
for (String key : keys) {
|
||||
entries.add(new ParameterEntry(key));
|
||||
}
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
private class ParameterEntry implements Entry<String, Object> {
|
||||
|
||||
private final String key;
|
||||
|
||||
private volatile Object value;
|
||||
|
||||
public ParameterEntry(String key) {
|
||||
this.key = key;
|
||||
this.value = ParameterMap.this.get(key);
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object setValue(Object value) {
|
||||
this.value = value;
|
||||
return ParameterMap.this.put(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.utils;
|
||||
|
||||
import com.alibaba.dubbo.governance.service.OwnerService;
|
||||
import com.alibaba.dubbo.registry.common.route.ParseUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class RelateUserUtils {
|
||||
/**
|
||||
* Add an owner related with service
|
||||
*
|
||||
* @param usernames the user to add
|
||||
* @param serviceName no wildcards
|
||||
*/
|
||||
public static void addOwnersOfService(Set<String> usernames, String serviceName,
|
||||
OwnerService ownerDAO) {
|
||||
List<String> serviceNamePatterns = ownerDAO.findAllServiceNames();
|
||||
for (String p : serviceNamePatterns) {
|
||||
if (ParseUtils.isMatchGlobPattern(p, serviceName)) {
|
||||
List<String> list = ownerDAO.findUsernamesByServiceName(p);
|
||||
usernames.addAll(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an owner related with service pattern
|
||||
*
|
||||
* @param usernames the user to add
|
||||
* @param serviceNamePattern service pattern, Glob
|
||||
*/
|
||||
public static void addOwnersOfServicePattern(Set<String> usernames, String serviceNamePattern,
|
||||
OwnerService ownerDAO) {
|
||||
List<String> serviceNamePatterns = ownerDAO.findAllServiceNames();
|
||||
for (String p : serviceNamePatterns) {
|
||||
if (ParseUtils.hasIntersection(p, serviceNamePattern)) {
|
||||
List<String> list = ownerDAO.findUsernamesByServiceName(p);
|
||||
usernames.addAll(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,270 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.governance.service.RouteService;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
import com.alibaba.dubbo.registry.common.domain.Access;
|
||||
import com.alibaba.dubbo.registry.common.domain.Route;
|
||||
import com.alibaba.dubbo.registry.common.route.RouteRule;
|
||||
import com.alibaba.dubbo.registry.common.route.RouteRule.MatchPair;
|
||||
import com.alibaba.dubbo.registry.common.util.Tool;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Providers. URI: /services/$service/accesses
|
||||
*
|
||||
*/
|
||||
public class Accesses extends Restful {
|
||||
|
||||
private static final Pattern IP_PATTERN = Pattern.compile("\\d{1,3}(\\.\\d{1,3}){3}$");
|
||||
private static final Pattern LOCAL_IP_PATTERN = Pattern.compile("127(\\.\\d{1,3}){3}$");
|
||||
private static final Pattern ALL_IP_PATTERN = Pattern.compile("0{1,3}(\\.0{1,3}){3}$");
|
||||
@Autowired
|
||||
private RouteService routeService;
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
|
||||
public void index(Map<String, Object> context) throws Exception {
|
||||
String service = (String) context.get("service");
|
||||
String address = (String) context.get("address");
|
||||
address = Tool.getIP(address);
|
||||
List<Route> routes;
|
||||
if (service != null && service.length() > 0) {
|
||||
routes = routeService.findForceRouteByService(service);
|
||||
} else if (address != null && address.length() > 0) {
|
||||
routes = routeService.findForceRouteByAddress(address);
|
||||
} else {
|
||||
routes = routeService.findAllForceRoute();
|
||||
}
|
||||
List<Access> accesses = new ArrayList<Access>();
|
||||
if (routes == null) {
|
||||
context.put("accesses", accesses);
|
||||
return;
|
||||
}
|
||||
for (Route route : routes) {
|
||||
Map<String, MatchPair> rule = RouteRule.parseRule(route.getMatchRule());
|
||||
MatchPair pair = rule.get("consumer.host");
|
||||
if (pair != null) {
|
||||
for (String host : pair.getMatches()) {
|
||||
Access access = new Access();
|
||||
access.setAddress(host);
|
||||
access.setService(route.getService());
|
||||
access.setAllow(false);
|
||||
accesses.add(access);
|
||||
}
|
||||
for (String host : pair.getUnmatches()) {
|
||||
Access access = new Access();
|
||||
access.setAddress(host);
|
||||
access.setService(route.getService());
|
||||
access.setAllow(true);
|
||||
accesses.add(access);
|
||||
}
|
||||
}
|
||||
}
|
||||
context.put("accesses", accesses);
|
||||
}
|
||||
|
||||
public void add(Map<String, Object> context) {
|
||||
List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
|
||||
context.put("serviceList", serviceList);
|
||||
}
|
||||
|
||||
public boolean create(Map<String, Object> context) throws Exception {
|
||||
String addr = (String) context.get("consumerAddress");
|
||||
String services = (String) context.get("service");
|
||||
Set<String> consumerAddresses = toAddr(addr);
|
||||
Set<String> aimServices = toService(services);
|
||||
for (String aimService : aimServices) {
|
||||
boolean isFirst = false;
|
||||
List<Route> routes = routeService.findForceRouteByService(aimService);
|
||||
Route route = null;
|
||||
if (routes == null || routes.size() == 0) {
|
||||
isFirst = true;
|
||||
route = new Route();
|
||||
route.setService(aimService);
|
||||
route.setForce(true);
|
||||
route.setName(aimService + " blackwhitelist");
|
||||
route.setFilterRule("false");
|
||||
route.setEnabled(true);
|
||||
} else {
|
||||
route = routes.get(0);
|
||||
}
|
||||
Map<String, MatchPair> when = null;
|
||||
MatchPair matchPair = null;
|
||||
if (isFirst) {
|
||||
when = new HashMap<String, MatchPair>();
|
||||
matchPair = new MatchPair(new HashSet<String>(), new HashSet<String>());
|
||||
when.put("consumer.host", matchPair);
|
||||
} else {
|
||||
when = RouteRule.parseRule(route.getMatchRule());
|
||||
matchPair = when.get("consumer.host");
|
||||
}
|
||||
for (String consumerAddress : consumerAddresses) {
|
||||
if (Boolean.valueOf((String) context.get("allow"))) {
|
||||
matchPair.getUnmatches().add(Tool.getIP(consumerAddress));
|
||||
|
||||
} else {
|
||||
matchPair.getMatches().add(Tool.getIP(consumerAddress));
|
||||
}
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
RouteRule.contidionToString(sb, when);
|
||||
route.setMatchRule(sb.toString());
|
||||
route.setUsername(operator);
|
||||
if (isFirst) {
|
||||
routeService.createRoute(route);
|
||||
} else {
|
||||
routeService.updateRoute(route);
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private Set<String> toAddr(String addr) throws IOException {
|
||||
Set<String> consumerAddresses = new HashSet<String>();
|
||||
BufferedReader reader = new BufferedReader(new StringReader(addr));
|
||||
while (true) {
|
||||
String line = reader.readLine();
|
||||
if (null == line)
|
||||
break;
|
||||
|
||||
String[] split = line.split("[\\s,;]+");
|
||||
for (String s : split) {
|
||||
if (s.length() == 0)
|
||||
continue;
|
||||
if (!IP_PATTERN.matcher(s).matches()) {
|
||||
throw new IllegalStateException("illegal IP: " + s);
|
||||
}
|
||||
if (LOCAL_IP_PATTERN.matcher(s).matches() || ALL_IP_PATTERN.matcher(s).matches()) {
|
||||
throw new IllegalStateException("local IP or any host ip is illegal: " + s);
|
||||
}
|
||||
|
||||
consumerAddresses.add(s);
|
||||
}
|
||||
}
|
||||
return consumerAddresses;
|
||||
}
|
||||
|
||||
private Set<String> toService(String services) throws IOException {
|
||||
Set<String> aimServices = new HashSet<String>();
|
||||
BufferedReader reader = new BufferedReader(new StringReader(services));
|
||||
while (true) {
|
||||
String line = reader.readLine();
|
||||
if (null == line)
|
||||
break;
|
||||
|
||||
String[] split = line.split("[\\s,;]+");
|
||||
for (String s : split) {
|
||||
if (s.length() == 0)
|
||||
continue;
|
||||
aimServices.add(s);
|
||||
}
|
||||
}
|
||||
return aimServices;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws ParseException
|
||||
*/
|
||||
public boolean delete(Map<String, Object> context) throws ParseException {
|
||||
String accesses = (String) context.get("accesses");
|
||||
String[] temp = accesses.split(" ");
|
||||
Map<String, Set<String>> prepareToDeleate = new HashMap<String, Set<String>>();
|
||||
for (String s : temp) {
|
||||
String service = s.split("=")[0];
|
||||
String address = s.split("=")[1];
|
||||
Set<String> addresses = prepareToDeleate.get(service);
|
||||
if (addresses == null) {
|
||||
prepareToDeleate.put(service, new HashSet<String>());
|
||||
addresses = prepareToDeleate.get(service);
|
||||
}
|
||||
addresses.add(address);
|
||||
}
|
||||
for (Entry<String, Set<String>> entry : prepareToDeleate.entrySet()) {
|
||||
|
||||
String service = entry.getKey();
|
||||
List<Route> routes = routeService.findForceRouteByService(service);
|
||||
if (routes == null || routes.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
for (Route blackwhitelist : routes) {
|
||||
MatchPair pairs = RouteRule.parseRule(blackwhitelist.getMatchRule()).get("consumer.host");
|
||||
Set<String> matches = new HashSet<String>();
|
||||
matches.addAll(pairs.getMatches());
|
||||
Set<String> unmatches = new HashSet<String>();
|
||||
unmatches.addAll(pairs.getUnmatches());
|
||||
for (String pair : pairs.getMatches()) {
|
||||
for (String address : entry.getValue()) {
|
||||
if (pair.equals(address)) {
|
||||
matches.remove(pair);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String pair : pairs.getUnmatches()) {
|
||||
for (String address : entry.getValue()) {
|
||||
if (pair.equals(address)) {
|
||||
unmatches.remove(pair);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (matches.size() == 0 && unmatches.size() == 0) {
|
||||
routeService.deleteRoute(blackwhitelist.getId());
|
||||
} else {
|
||||
Map<String, MatchPair> condition = new HashMap<String, MatchPair>();
|
||||
condition.put("consumer.host", new MatchPair(matches, unmatches));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
RouteRule.contidionToString(sb, condition);
|
||||
blackwhitelist.setMatchRule(sb.toString());
|
||||
routeService.updateRoute(blackwhitelist);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void show(Map<String, Object> context) {
|
||||
}
|
||||
|
||||
public void edit(Map<String, Object> context) {
|
||||
}
|
||||
|
||||
public String update(Map<String, Object> context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,126 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.ConsumerService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* Providers.
|
||||
* URI: /services/$service/providers
|
||||
*
|
||||
*/
|
||||
public class Addresses extends Restful {
|
||||
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
|
||||
@Autowired
|
||||
private ConsumerService consumerService;
|
||||
|
||||
public void index(Map<String, Object> context) {
|
||||
String application = (String) context.get("application");
|
||||
String service = (String) context.get("service");
|
||||
List<String> providerAddresses = null;
|
||||
List<String> consumerAddresses = null;
|
||||
|
||||
if (application != null && application.length() > 0) {
|
||||
providerAddresses = providerService.findAddressesByApplication(application);
|
||||
consumerAddresses = consumerService.findAddressesByApplication(application);
|
||||
} else if (service != null && service.length() > 0) {
|
||||
providerAddresses = providerService.findAddressesByService(service);
|
||||
consumerAddresses = consumerService.findAddressesByService(service);
|
||||
} else {
|
||||
providerAddresses = providerService.findAddresses();
|
||||
consumerAddresses = consumerService.findAddresses();
|
||||
}
|
||||
|
||||
Set<String> addresses = new TreeSet<String>();
|
||||
if (providerAddresses != null) {
|
||||
addresses.addAll(providerAddresses);
|
||||
}
|
||||
if (consumerAddresses != null) {
|
||||
addresses.addAll(consumerAddresses);
|
||||
}
|
||||
context.put("providerAddresses", providerAddresses);
|
||||
context.put("consumerAddresses", consumerAddresses);
|
||||
context.put("addresses", addresses);
|
||||
|
||||
if (context.get("service") == null
|
||||
&& context.get("application") == null
|
||||
&& context.get("address") == null) {
|
||||
context.put("address", "*");
|
||||
}
|
||||
|
||||
String keyword = (String) context.get("keyword");
|
||||
if (StringUtils.isNotEmpty(keyword)) {
|
||||
if ("*".equals(keyword)) return;
|
||||
|
||||
keyword = keyword.toLowerCase();
|
||||
Set<String> newList = new HashSet<String>();
|
||||
Set<String> newProviders = new HashSet<String>();
|
||||
Set<String> newConsumers = new HashSet<String>();
|
||||
|
||||
for (String o : addresses) {
|
||||
if (o.toLowerCase().indexOf(keyword) != -1) {
|
||||
newList.add(o);
|
||||
}
|
||||
}
|
||||
for (String o : providerAddresses) {
|
||||
if (o.toLowerCase().indexOf(keyword) != -1) {
|
||||
newProviders.add(o);
|
||||
}
|
||||
}
|
||||
for (String o : consumerAddresses) {
|
||||
if (o.toLowerCase().indexOf(keyword) != -1) {
|
||||
newConsumers.add(o);
|
||||
}
|
||||
}
|
||||
context.put("addresses", newList);
|
||||
context.put("providerAddresses", newProviders);
|
||||
context.put("consumerAddresses", newConsumers);
|
||||
}
|
||||
}
|
||||
|
||||
public void search(Map<String, Object> context) {
|
||||
index(context);
|
||||
|
||||
Set<String> newList = new HashSet<String>();
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<String> list = (Set<String>) context.get("addresses");
|
||||
String keyword = (String) context.get("keyword");
|
||||
if (StringUtils.isNotEmpty(keyword)) {
|
||||
keyword = keyword.toLowerCase();
|
||||
for (String o : list) {
|
||||
if (o.toLowerCase().indexOf(keyword) != -1) {
|
||||
newList.add(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
context.put("addresses", newList);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,274 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.ConsumerService;
|
||||
import com.alibaba.dubbo.governance.service.OverrideService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
import com.alibaba.dubbo.registry.common.domain.Override;
|
||||
import com.alibaba.dubbo.registry.common.route.OverrideUtils;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* Providers.
|
||||
* URI: /applications
|
||||
*
|
||||
*/
|
||||
public class Applications extends Restful {
|
||||
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
|
||||
@Autowired
|
||||
private ConsumerService consumerService;
|
||||
|
||||
@Autowired
|
||||
private OverrideService overrideService;
|
||||
|
||||
public void index(Map<String, Object> context) {
|
||||
String service = (String) context.get("service");
|
||||
if (context.get("service") != null) {
|
||||
Set<String> applications = new TreeSet<String>();
|
||||
List<String> providerApplications = providerService.findApplicationsByServiceName(service);
|
||||
if (providerApplications != null && providerApplications.size() > 0) {
|
||||
applications.addAll(providerApplications);
|
||||
}
|
||||
List<String> consumerApplications = consumerService.findApplicationsByServiceName(service);
|
||||
if (consumerApplications != null && consumerApplications.size() > 0) {
|
||||
applications.addAll(consumerApplications);
|
||||
}
|
||||
context.put("applications", applications);
|
||||
context.put("providerApplications", providerApplications);
|
||||
context.put("consumerApplications", consumerApplications);
|
||||
if (service != null && service.length() > 0) {
|
||||
List<Override> overrides = overrideService.findByService(service);
|
||||
Map<String, List<Override>> application2Overrides = new HashMap<String, List<Override>>();
|
||||
if (overrides != null && overrides.size() > 0
|
||||
&& applications != null && applications.size() > 0) {
|
||||
for (String a : applications) {
|
||||
if (overrides != null && overrides.size() > 0) {
|
||||
List<Override> appOverrides = new ArrayList<Override>();
|
||||
for (Override override : overrides) {
|
||||
if (override.isMatch(service, null, a)) {
|
||||
appOverrides.add(override);
|
||||
}
|
||||
}
|
||||
Collections.sort(appOverrides, OverrideUtils.OVERRIDE_COMPARATOR);
|
||||
application2Overrides.put(a, appOverrides);
|
||||
}
|
||||
}
|
||||
}
|
||||
context.put("overrides", application2Overrides);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (context.get("service") == null
|
||||
&& context.get("application") == null
|
||||
&& context.get("address") == null) {
|
||||
context.put("application", "*");
|
||||
}
|
||||
Set<String> applications = new TreeSet<String>();
|
||||
List<String> providerApplications = providerService.findApplications();
|
||||
if (providerApplications != null && providerApplications.size() > 0) {
|
||||
applications.addAll(providerApplications);
|
||||
}
|
||||
List<String> consumerApplications = consumerService.findApplications();
|
||||
if (consumerApplications != null && consumerApplications.size() > 0) {
|
||||
applications.addAll(consumerApplications);
|
||||
}
|
||||
|
||||
Set<String> newList = new HashSet<String>();
|
||||
Set<String> newProviders = new HashSet<String>();
|
||||
Set<String> newConsumers = new HashSet<String>();
|
||||
context.put("applications", applications);
|
||||
context.put("providerApplications", providerApplications);
|
||||
context.put("consumerApplications", consumerApplications);
|
||||
|
||||
String keyword = (String) context.get("keyword");
|
||||
if (StringUtils.isNotEmpty(keyword) && !"*".equals(keyword)) {
|
||||
keyword = keyword.toLowerCase();
|
||||
for (String o : applications) {
|
||||
if (o.toLowerCase().indexOf(keyword) != -1) {
|
||||
newList.add(o);
|
||||
}
|
||||
}
|
||||
for (String o : providerApplications) {
|
||||
if (o.toLowerCase().indexOf(keyword) != -1) {
|
||||
newProviders.add(o);
|
||||
}
|
||||
}
|
||||
for (String o : consumerApplications) {
|
||||
if (o.toLowerCase().indexOf(keyword) != -1) {
|
||||
newConsumers.add(o);
|
||||
}
|
||||
}
|
||||
context.put("applications", newList);
|
||||
context.put("providerApplications", newProviders);
|
||||
context.put("consumerApplications", newConsumers);
|
||||
}
|
||||
}
|
||||
|
||||
public void search(Map<String, Object> context) {
|
||||
index(context);
|
||||
|
||||
Set<String> newList = new HashSet<String>();
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<String> apps = (Set<String>) context.get("applications");
|
||||
String keyword = (String) context.get("keyword");
|
||||
if (StringUtils.isNotEmpty(keyword)) {
|
||||
keyword = keyword.toLowerCase();
|
||||
for (String o : apps) {
|
||||
if (o.toLowerCase().indexOf(keyword) != -1) {
|
||||
newList.add(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
context.put("applications", newList);
|
||||
}
|
||||
|
||||
public boolean shield(Map<String, Object> context) throws Exception {
|
||||
return mock(context, "force:return null");
|
||||
}
|
||||
|
||||
public boolean tolerant(Map<String, Object> context) throws Exception {
|
||||
return mock(context, "fail:return null");
|
||||
}
|
||||
|
||||
public boolean recover(Map<String, Object> context) throws Exception {
|
||||
return mock(context, "");
|
||||
}
|
||||
|
||||
private boolean mock(Map<String, Object> context, String mock) throws Exception {
|
||||
String service = (String) context.get("service");
|
||||
String applications = (String) context.get("application");
|
||||
if (service == null || service.length() == 0
|
||||
|| applications == null || applications.length() == 0) {
|
||||
context.put("message", getMessage("NoSuchOperationData"));
|
||||
return false;
|
||||
}
|
||||
if (!super.currentUser.hasServicePrivilege(service)) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", service));
|
||||
return false;
|
||||
}
|
||||
for (String application : SPACE_SPLIT_PATTERN.split(applications)) {
|
||||
List<Override> overrides = overrideService.findByServiceAndApplication(service, application);
|
||||
if (overrides != null && overrides.size() > 0) {
|
||||
for (Override override : overrides) {
|
||||
Map<String, String> map = StringUtils.parseQueryString(override.getParams());
|
||||
if (mock == null || mock.length() == 0) {
|
||||
map.remove("mock");
|
||||
} else {
|
||||
map.put("mock", URL.encode(mock));
|
||||
}
|
||||
if (map.size() > 0) {
|
||||
override.setParams(StringUtils.toQueryString(map));
|
||||
override.setEnabled(true);
|
||||
override.setOperator(operator);
|
||||
override.setOperatorAddress(operatorAddress);
|
||||
overrideService.updateOverride(override);
|
||||
} else {
|
||||
overrideService.deleteOverride(override.getId());
|
||||
}
|
||||
}
|
||||
} else if (mock != null && mock.length() > 0) {
|
||||
Override override = new Override();
|
||||
override.setService(service);
|
||||
override.setApplication(application);
|
||||
override.setParams("mock=" + URL.encode(mock));
|
||||
override.setEnabled(true);
|
||||
override.setOperator(operator);
|
||||
override.setOperatorAddress(operatorAddress);
|
||||
overrideService.saveOverride(override);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean allshield(Map<String, Object> context) throws Exception {
|
||||
return allmock(context, "force:return null");
|
||||
}
|
||||
|
||||
public boolean alltolerant(Map<String, Object> context) throws Exception {
|
||||
return allmock(context, "fail:return null");
|
||||
}
|
||||
|
||||
public boolean allrecover(Map<String, Object> context) throws Exception {
|
||||
return allmock(context, "");
|
||||
}
|
||||
|
||||
private boolean allmock(Map<String, Object> context, String mock) throws Exception {
|
||||
String service = (String) context.get("service");
|
||||
if (service == null || service.length() == 0) {
|
||||
context.put("message", getMessage("NoSuchOperationData"));
|
||||
return false;
|
||||
}
|
||||
if (!super.currentUser.hasServicePrivilege(service)) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", service));
|
||||
return false;
|
||||
}
|
||||
List<Override> overrides = overrideService.findByService(service);
|
||||
Override allOverride = null;
|
||||
if (overrides != null && overrides.size() > 0) {
|
||||
for (Override override : overrides) {
|
||||
if (override.isDefault()) {
|
||||
allOverride = override;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (allOverride != null) {
|
||||
Map<String, String> map = StringUtils.parseQueryString(allOverride.getParams());
|
||||
if (mock == null || mock.length() == 0) {
|
||||
map.remove("mock");
|
||||
} else {
|
||||
map.put("mock", URL.encode(mock));
|
||||
}
|
||||
if (map.size() > 0) {
|
||||
allOverride.setParams(StringUtils.toQueryString(map));
|
||||
allOverride.setEnabled(true);
|
||||
allOverride.setOperator(operator);
|
||||
allOverride.setOperatorAddress(operatorAddress);
|
||||
overrideService.updateOverride(allOverride);
|
||||
} else {
|
||||
overrideService.deleteOverride(allOverride.getId());
|
||||
}
|
||||
} else if (mock != null && mock.length() > 0) {
|
||||
Override override = new Override();
|
||||
override.setService(service);
|
||||
override.setParams("mock=" + URL.encode(mock));
|
||||
override.setEnabled(true);
|
||||
override.setOperator(operator);
|
||||
override.setOperatorAddress(operatorAddress);
|
||||
overrideService.saveOverride(override);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,421 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.ConsumerService;
|
||||
import com.alibaba.dubbo.governance.service.OverrideService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.governance.service.RouteService;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
import com.alibaba.dubbo.registry.common.domain.Consumer;
|
||||
import com.alibaba.dubbo.registry.common.domain.Override;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
import com.alibaba.dubbo.registry.common.domain.Route;
|
||||
import com.alibaba.dubbo.registry.common.route.OverrideUtils;
|
||||
import com.alibaba.dubbo.registry.common.route.RouteRule;
|
||||
import com.alibaba.dubbo.registry.common.route.RouteRule.MatchPair;
|
||||
import com.alibaba.dubbo.registry.common.route.RouteUtils;
|
||||
import com.alibaba.dubbo.registry.common.util.Tool;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Consumers. URI: /services/$service/consumers
|
||||
*
|
||||
*/
|
||||
public class Consumers extends Restful {
|
||||
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
|
||||
@Autowired
|
||||
private ConsumerService consumerService;
|
||||
|
||||
@Autowired
|
||||
private OverrideService overrideService;
|
||||
|
||||
@Autowired
|
||||
private RouteService routeService;
|
||||
|
||||
public void index(Map<String, Object> context) throws Exception {
|
||||
String service = (String) context.get("service");
|
||||
String application = (String) context.get("application");
|
||||
String address = (String) context.get("address");
|
||||
List<Consumer> consumers;
|
||||
List<Override> overrides;
|
||||
List<Provider> providers = null;
|
||||
List<Route> routes = null;
|
||||
// service
|
||||
if (service != null && service.length() > 0) {
|
||||
consumers = consumerService.findByService(service);
|
||||
overrides = overrideService.findByService(service);
|
||||
providers = providerService.findByService(service);
|
||||
routes = routeService.findByService(service);
|
||||
}
|
||||
// address
|
||||
else if (address != null && address.length() > 0) {
|
||||
consumers = consumerService.findByAddress(address);
|
||||
overrides = overrideService.findByAddress(Tool.getIP(address));
|
||||
}
|
||||
// application
|
||||
else if (application != null && application.length() > 0) {
|
||||
consumers = consumerService.findByApplication(application);
|
||||
overrides = overrideService.findByApplication(application);
|
||||
}
|
||||
// all
|
||||
else {
|
||||
consumers = consumerService.findAll();
|
||||
overrides = overrideService.findAll();
|
||||
}
|
||||
if (consumers != null && consumers.size() > 0) {
|
||||
for (Consumer consumer : consumers) {
|
||||
if (service == null || service.length() == 0) {
|
||||
providers = providerService.findByService(consumer.getService());
|
||||
routes = routeService.findByService(consumer.getService());
|
||||
}
|
||||
List<Route> routed = new ArrayList<Route>();
|
||||
consumer.setProviders(RouteUtils.route(consumer.getService(), consumer.getAddress(), consumer.getParameters(), providers, overrides, routes, null, routed));
|
||||
consumer.setRoutes(routed);
|
||||
OverrideUtils.setConsumerOverrides(consumer, overrides);
|
||||
}
|
||||
}
|
||||
context.put("consumers", consumers);
|
||||
}
|
||||
|
||||
public void show(Long id, Map<String, Object> context) {
|
||||
Consumer consumer = consumerService.findConsumer(id);
|
||||
List<Provider> providers = providerService.findByService(consumer.getService());
|
||||
List<Route> routes = routeService.findByService(consumer.getService());
|
||||
List<Override> overrides = overrideService.findByService(consumer.getService());
|
||||
List<Route> routed = new ArrayList<Route>();
|
||||
consumer.setProviders(RouteUtils.route(consumer.getService(), consumer.getAddress(), consumer.getParameters(), providers, overrides, routes, null, routed));
|
||||
consumer.setRoutes(routed);
|
||||
OverrideUtils.setConsumerOverrides(consumer, overrides);
|
||||
context.put("consumer", consumer);
|
||||
context.put("providers", consumer.getProviders());
|
||||
context.put("routes", consumer.getRoutes());
|
||||
context.put("overrides", consumer.getOverrides());
|
||||
}
|
||||
|
||||
public void edit(Long id, Map<String, Object> context) {
|
||||
show(id, context);
|
||||
}
|
||||
|
||||
public boolean update(Consumer newConsumer, Map<String, Object> context) {
|
||||
Long id = newConsumer.getId();
|
||||
String parameters = newConsumer.getParameters();
|
||||
Consumer consumer = consumerService.findConsumer(id);
|
||||
if (consumer == null) {
|
||||
context.put("message", getMessage("NoSuchOperationData", id));
|
||||
return false;
|
||||
}
|
||||
String service = consumer.getService();
|
||||
if (!super.currentUser.hasServicePrivilege(service)) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", service));
|
||||
return false;
|
||||
}
|
||||
Map<String, String> oldMap = StringUtils.parseQueryString(consumer.getParameters());
|
||||
Map<String, String> newMap = StringUtils.parseQueryString(parameters);
|
||||
for (Map.Entry<String, String> entry : oldMap.entrySet()) {
|
||||
if (entry.getValue().equals(newMap.get(entry.getKey()))) {
|
||||
newMap.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
String address = consumer.getAddress();
|
||||
List<Override> overrides = overrideService.findByServiceAndAddress(consumer.getService(), consumer.getAddress());
|
||||
OverrideUtils.setConsumerOverrides(consumer, overrides);
|
||||
Override override = consumer.getOverride();
|
||||
if (override != null) {
|
||||
if (newMap.size() > 0) {
|
||||
override.setParams(StringUtils.toQueryString(newMap));
|
||||
override.setEnabled(true);
|
||||
override.setOperator(operator);
|
||||
override.setOperatorAddress(operatorAddress);
|
||||
overrideService.updateOverride(override);
|
||||
} else {
|
||||
overrideService.deleteOverride(override.getId());
|
||||
}
|
||||
} else {
|
||||
override = new Override();
|
||||
override.setService(service);
|
||||
override.setAddress(address);
|
||||
override.setParams(StringUtils.toQueryString(newMap));
|
||||
override.setEnabled(true);
|
||||
override.setOperator(operator);
|
||||
override.setOperatorAddress(operatorAddress);
|
||||
overrideService.saveOverride(override);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void routed(Long id, Map<String, Object> context) {
|
||||
show(id, context);
|
||||
}
|
||||
|
||||
public void notified(Long id, Map<String, Object> context) {
|
||||
show(id, context);
|
||||
}
|
||||
|
||||
public void overrided(Long id, Map<String, Object> context) {
|
||||
show(id, context);
|
||||
}
|
||||
|
||||
public boolean shield(Long[] ids, Map<String, Object> context) throws Exception {
|
||||
return mock(ids, context, "force:return null");
|
||||
}
|
||||
|
||||
public boolean tolerant(Long[] ids, Map<String, Object> context) throws Exception {
|
||||
return mock(ids, context, "fail:return null");
|
||||
}
|
||||
|
||||
public boolean recover(Long[] ids, Map<String, Object> context) throws Exception {
|
||||
return mock(ids, context, "");
|
||||
}
|
||||
|
||||
private boolean mock(Long[] ids, Map<String, Object> context, String mock) throws Exception {
|
||||
if (ids == null || ids.length == 0) {
|
||||
context.put("message", getMessage("NoSuchOperationData"));
|
||||
return false;
|
||||
}
|
||||
List<Consumer> consumers = new ArrayList<Consumer>();
|
||||
for (Long id : ids) {
|
||||
Consumer c = consumerService.findConsumer(id);
|
||||
if (c != null) {
|
||||
consumers.add(c);
|
||||
if (!super.currentUser.hasServicePrivilege(c.getService())) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", c.getService()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Consumer consumer : consumers) {
|
||||
String service = consumer.getService();
|
||||
String address = Tool.getIP(consumer.getAddress());
|
||||
List<Override> overrides = overrideService.findByServiceAndAddress(service, address);
|
||||
if (overrides != null && overrides.size() > 0) {
|
||||
for (Override override : overrides) {
|
||||
Map<String, String> map = StringUtils.parseQueryString(override.getParams());
|
||||
if (mock == null || mock.length() == 0) {
|
||||
map.remove("mock");
|
||||
} else {
|
||||
map.put("mock", URL.encode(mock));
|
||||
}
|
||||
if (map.size() > 0) {
|
||||
override.setParams(StringUtils.toQueryString(map));
|
||||
override.setEnabled(true);
|
||||
override.setOperator(operator);
|
||||
override.setOperatorAddress(operatorAddress);
|
||||
overrideService.updateOverride(override);
|
||||
} else {
|
||||
overrideService.deleteOverride(override.getId());
|
||||
}
|
||||
}
|
||||
} else if (mock != null && mock.length() > 0) {
|
||||
Override override = new Override();
|
||||
override.setService(service);
|
||||
override.setAddress(address);
|
||||
override.setParams("mock=" + URL.encode(mock));
|
||||
override.setEnabled(true);
|
||||
override.setOperator(operator);
|
||||
override.setOperatorAddress(operatorAddress);
|
||||
overrideService.saveOverride(override);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean allshield(Map<String, Object> context) throws Exception {
|
||||
return allmock(context, "force:return null");
|
||||
}
|
||||
|
||||
public boolean alltolerant(Map<String, Object> context) throws Exception {
|
||||
return allmock(context, "fail:return null");
|
||||
}
|
||||
|
||||
public boolean allrecover(Map<String, Object> context) throws Exception {
|
||||
return allmock(context, "");
|
||||
}
|
||||
|
||||
private boolean allmock(Map<String, Object> context, String mock) throws Exception {
|
||||
String service = (String) context.get("service");
|
||||
if (service == null || service.length() == 0) {
|
||||
context.put("message", getMessage("NoSuchOperationData"));
|
||||
return false;
|
||||
}
|
||||
if (!super.currentUser.hasServicePrivilege(service)) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", service));
|
||||
return false;
|
||||
}
|
||||
List<Override> overrides = overrideService.findByService(service);
|
||||
Override allOverride = null;
|
||||
if (overrides != null && overrides.size() > 0) {
|
||||
for (Override override : overrides) {
|
||||
if (override.isDefault()) {
|
||||
allOverride = override;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (allOverride != null) {
|
||||
Map<String, String> map = StringUtils.parseQueryString(allOverride.getParams());
|
||||
if (mock == null || mock.length() == 0) {
|
||||
map.remove("mock");
|
||||
} else {
|
||||
map.put("mock", URL.encode(mock));
|
||||
}
|
||||
if (map.size() > 0) {
|
||||
allOverride.setParams(StringUtils.toQueryString(map));
|
||||
allOverride.setEnabled(true);
|
||||
allOverride.setOperator(operator);
|
||||
allOverride.setOperatorAddress(operatorAddress);
|
||||
overrideService.updateOverride(allOverride);
|
||||
} else {
|
||||
overrideService.deleteOverride(allOverride.getId());
|
||||
}
|
||||
} else if (mock != null && mock.length() > 0) {
|
||||
Override override = new Override();
|
||||
override.setService(service);
|
||||
override.setParams("mock=" + URL.encode(mock));
|
||||
override.setEnabled(true);
|
||||
override.setOperator(operator);
|
||||
override.setOperatorAddress(operatorAddress);
|
||||
overrideService.saveOverride(override);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean allow(Long[] ids, Map<String, Object> context) throws Exception {
|
||||
return access(ids, context, true, false);
|
||||
}
|
||||
|
||||
public boolean forbid(Long[] ids, Map<String, Object> context) throws Exception {
|
||||
return access(ids, context, false, false);
|
||||
}
|
||||
|
||||
public boolean onlyallow(Long[] ids, Map<String, Object> context) throws Exception {
|
||||
return access(ids, context, true, true);
|
||||
}
|
||||
|
||||
public boolean onlyforbid(Long[] ids, Map<String, Object> context) throws Exception {
|
||||
return access(ids, context, false, true);
|
||||
}
|
||||
|
||||
private boolean access(Long[] ids, Map<String, Object> context, boolean allow, boolean only) throws Exception {
|
||||
if (ids == null || ids.length == 0) {
|
||||
context.put("message", getMessage("NoSuchOperationData"));
|
||||
return false;
|
||||
}
|
||||
List<Consumer> consumers = new ArrayList<Consumer>();
|
||||
for (Long id : ids) {
|
||||
Consumer c = consumerService.findConsumer(id);
|
||||
if (c != null) {
|
||||
consumers.add(c);
|
||||
if (!super.currentUser.hasServicePrivilege(c.getService())) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", c.getService()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<String, Set<String>> serviceAddresses = new HashMap<String, Set<String>>();
|
||||
for (Consumer consumer : consumers) {
|
||||
String service = consumer.getService();
|
||||
String address = Tool.getIP(consumer.getAddress());
|
||||
Set<String> addresses = serviceAddresses.get(service);
|
||||
if (addresses == null) {
|
||||
addresses = new HashSet<String>();
|
||||
serviceAddresses.put(service, addresses);
|
||||
}
|
||||
addresses.add(address);
|
||||
}
|
||||
for (Map.Entry<String, Set<String>> entry : serviceAddresses.entrySet()) {
|
||||
String service = entry.getKey();
|
||||
boolean isFirst = false;
|
||||
List<Route> routes = routeService.findForceRouteByService(service);
|
||||
Route route = null;
|
||||
if (routes == null || routes.size() == 0) {
|
||||
isFirst = true;
|
||||
route = new Route();
|
||||
route.setService(service);
|
||||
route.setForce(true);
|
||||
route.setName(service + " blackwhitelist");
|
||||
route.setFilterRule("false");
|
||||
route.setEnabled(true);
|
||||
} else {
|
||||
route = routes.get(0);
|
||||
}
|
||||
Map<String, MatchPair> when = null;
|
||||
MatchPair matchPair = null;
|
||||
if (isFirst) {
|
||||
when = new HashMap<String, MatchPair>();
|
||||
matchPair = new MatchPair(new HashSet<String>(), new HashSet<String>());
|
||||
when.put("consumer.host", matchPair);
|
||||
} else {
|
||||
when = RouteRule.parseRule(route.getMatchRule());
|
||||
matchPair = when.get("consumer.host");
|
||||
}
|
||||
if (only) {
|
||||
matchPair.getUnmatches().clear();
|
||||
matchPair.getMatches().clear();
|
||||
if (allow) {
|
||||
matchPair.getUnmatches().addAll(entry.getValue());
|
||||
} else {
|
||||
matchPair.getMatches().addAll(entry.getValue());
|
||||
}
|
||||
} else {
|
||||
for (String consumerAddress : entry.getValue()) {
|
||||
if (matchPair.getUnmatches().size() > 0) { // whitelist take effect
|
||||
matchPair.getMatches().remove(consumerAddress); // remove data in blacklist
|
||||
if (allow) { // if allowed
|
||||
matchPair.getUnmatches().add(consumerAddress); // add to whitelist
|
||||
} else { // if not allowed
|
||||
matchPair.getUnmatches().remove(consumerAddress); // remove from whitelist
|
||||
}
|
||||
} else { // blacklist take effect
|
||||
if (allow) { // if allowed
|
||||
matchPair.getMatches().remove(consumerAddress); // remove from blacklist
|
||||
} else { // if not allowed
|
||||
matchPair.getMatches().add(consumerAddress); // add to blacklist
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
RouteRule.contidionToString(sb, when);
|
||||
route.setMatchRule(sb.toString());
|
||||
route.setUsername(operator);
|
||||
if (matchPair.getMatches().size() > 0 || matchPair.getUnmatches().size() > 0) {
|
||||
if (isFirst) {
|
||||
routeService.createRoute(route);
|
||||
} else {
|
||||
routeService.updateRoute(route);
|
||||
}
|
||||
} else if (!isFirst) {
|
||||
routeService.deleteRoute(route.getId());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,131 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.utils.CollectionUtils;
|
||||
import com.alibaba.dubbo.governance.service.OverrideService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
import com.alibaba.dubbo.registry.common.domain.LoadBalance;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
import com.alibaba.dubbo.registry.common.util.OverrideUtils;
|
||||
import com.alibaba.dubbo.registry.common.util.Tool;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Providers.
|
||||
* URI: /services/$service/loadbalances
|
||||
*
|
||||
*/
|
||||
public class Loadbalances extends Restful {
|
||||
|
||||
@Autowired
|
||||
private OverrideService overrideService;
|
||||
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
|
||||
public void index(Map<String, Object> context) {
|
||||
final String service = StringUtils.trimToNull((String) context.get("service"));
|
||||
|
||||
List<LoadBalance> loadbalances;
|
||||
if (service != null && service.length() > 0) {
|
||||
loadbalances = OverrideUtils.overridesToLoadBalances(overrideService.findByService(service));
|
||||
|
||||
loadbalances = OverrideUtils.overridesToLoadBalances(overrideService.findByService(service));
|
||||
} else {
|
||||
loadbalances = OverrideUtils.overridesToLoadBalances(overrideService.findAll());
|
||||
}
|
||||
context.put("loadbalances", loadbalances);
|
||||
}
|
||||
|
||||
public void show(Long id, Map<String, Object> context) {
|
||||
LoadBalance loadbalance = OverrideUtils.overrideToLoadBalance(overrideService.findById(id));
|
||||
context.put("loadbalance", loadbalance);
|
||||
}
|
||||
|
||||
public void add(Map<String, Object> context) {
|
||||
String service = (String) context.get("service");
|
||||
if (service != null && service.length() > 0 && !service.contains("*")) {
|
||||
List<Provider> providerList = providerService.findByService(service);
|
||||
List<String> addressList = new ArrayList<String>();
|
||||
for (Provider provider : providerList) {
|
||||
addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
|
||||
}
|
||||
context.put("addressList", addressList);
|
||||
context.put("service", service);
|
||||
context.put("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
|
||||
} else {
|
||||
List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
|
||||
context.put("serviceList", serviceList);
|
||||
}
|
||||
if (context.get("input") != null) context.put("input", context.get("input"));
|
||||
}
|
||||
|
||||
public void edit(Long id, Map<String, Object> context) {
|
||||
add(context);
|
||||
show(id, context);
|
||||
}
|
||||
|
||||
public boolean create(LoadBalance loadBalance, Map<String, Object> context) {
|
||||
if (!super.currentUser.hasServicePrivilege(loadBalance.getService())) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", loadBalance.getService()));
|
||||
return false;
|
||||
}
|
||||
|
||||
loadBalance.setUsername((String) context.get("operator"));
|
||||
overrideService.saveOverride(OverrideUtils.loadBalanceToOverride(loadBalance));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean update(LoadBalance loadBalance, Map<String, Object> context) {
|
||||
if (!super.currentUser.hasServicePrivilege(loadBalance.getService())) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", loadBalance.getService()));
|
||||
return false;
|
||||
}
|
||||
overrideService.updateOverride(OverrideUtils.loadBalanceToOverride(loadBalance));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
public boolean delete(Long[] ids, Map<String, Object> context) {
|
||||
for (Long id : ids) {
|
||||
LoadBalance lb = OverrideUtils.overrideToLoadBalance(overrideService.findById(id));
|
||||
if (!super.currentUser.hasServicePrivilege(lb.getService())) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", lb.getService()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (Long id : ids) {
|
||||
overrideService.deleteOverride(id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
import com.alibaba.citrus.turbine.Context;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* TODO Comment of NoServicePrivilege
|
||||
*
|
||||
*/
|
||||
public class NoServicePrivilege {
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
public void execute(Context context) {
|
||||
context.put("returnUrl", request.getParameter("returnUrl"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,366 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.utils.CollectionUtils;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.ConsumerService;
|
||||
import com.alibaba.dubbo.governance.service.OverrideService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
import com.alibaba.dubbo.registry.common.domain.Override;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Overrides extends Restful {
|
||||
static final Pattern AND = Pattern.compile("\\&");
|
||||
static final Pattern EQUAL = Pattern.compile("([^=\\s]*)\\s*=\\s*(\\S*)");
|
||||
static final String DEFAULT_MOCK_JSON_KEY = "mock";
|
||||
static final String MOCK_JSON_KEY_POSTFIX = ".mock";
|
||||
static final String FORM_OVERRIDE_KEY = "overrideKey";
|
||||
static final String FORM_OVERRIDE_VALUE = "overrideValue";
|
||||
static final String FORM_DEFAULT_MOCK_METHOD_FORCE = "mockDefaultMethodForce";
|
||||
static final String FORM_DEFAULT_MOCK_METHOD_JSON = "mockDefaultMethodJson";
|
||||
static final String FORM_ORIGINAL_METHOD_FORCE_PREFIX = "mockMethodForce.";
|
||||
static final String FORM_ORIGINAL_METHOD_PREFIX = "mockMethod.";
|
||||
static final String FORM_DYNAMIC_METHOD_NAME_PREFIX = "mockMethodName";
|
||||
static final String FORM_DYNAMIC_METHOD_FORCE_PREFIX = "mockMethodForce";
|
||||
static final String FORM_DYNAMIC_METHOD_JSON_PREFIX = "mockMethodJson";
|
||||
@Autowired
|
||||
private OverrideService overrideService;
|
||||
|
||||
// FORM KEY
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
@Autowired
|
||||
private ConsumerService consumerService;
|
||||
|
||||
static Map<String, String> parseQueryString(String query) {
|
||||
HashMap<String, String> ret = new HashMap<String, String>();
|
||||
if (query == null || (query = query.trim()).length() == 0) return ret;
|
||||
|
||||
String[] kvs = AND.split(query);
|
||||
for (String kv : kvs) {
|
||||
Matcher matcher = EQUAL.matcher(kv);
|
||||
if (!matcher.matches()) continue;
|
||||
String key = matcher.group(1);
|
||||
String value = matcher.group(2);
|
||||
ret.put(key, value);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void index(Map<String, Object> context) {
|
||||
String service = (String) context.get("service");
|
||||
String application = (String) context.get("application");
|
||||
String address = (String) context.get("address");
|
||||
List<Override> overrides;
|
||||
if (StringUtils.isNotEmpty(service)) {
|
||||
overrides = overrideService.findByService(service);
|
||||
} else if (StringUtils.isNotEmpty(application)) {
|
||||
overrides = overrideService.findByApplication(application);
|
||||
} else if (StringUtils.isNotEmpty(address)) {
|
||||
overrides = overrideService.findByAddress(address);
|
||||
} else {
|
||||
overrides = overrideService.findAll();
|
||||
}
|
||||
context.put("overrides", overrides);
|
||||
}
|
||||
|
||||
public void show(Long id, Map<String, Object> context) {
|
||||
Override override = overrideService.findById(id);
|
||||
|
||||
Map<String, String> parameters = parseQueryString(override.getParams());
|
||||
|
||||
if (parameters.get(DEFAULT_MOCK_JSON_KEY) != null) {
|
||||
String mock = URL.decode(parameters.get(DEFAULT_MOCK_JSON_KEY));
|
||||
String[] tokens = parseMock(mock);
|
||||
context.put(FORM_DEFAULT_MOCK_METHOD_FORCE, tokens[0]);
|
||||
context.put(FORM_DEFAULT_MOCK_METHOD_JSON, tokens[1]);
|
||||
parameters.remove(DEFAULT_MOCK_JSON_KEY);
|
||||
}
|
||||
|
||||
Map<String, String> method2Force = new LinkedHashMap<String, String>();
|
||||
Map<String, String> method2Json = new LinkedHashMap<String, String>();
|
||||
|
||||
for (Iterator<Map.Entry<String, String>> iterator = parameters.entrySet().iterator(); iterator.hasNext(); ) {
|
||||
Map.Entry<String, String> e = iterator.next();
|
||||
String key = e.getKey();
|
||||
|
||||
if (key.endsWith(MOCK_JSON_KEY_POSTFIX)) {
|
||||
String m = key.substring(0, key.length() - MOCK_JSON_KEY_POSTFIX.length());
|
||||
parseMock(m, e.getValue(), method2Force, method2Json);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
context.put("methodForces", method2Force);
|
||||
context.put("methodJsons", method2Json);
|
||||
context.put("parameters", parameters);
|
||||
context.put("override", override);
|
||||
}
|
||||
|
||||
public void add(Map<String, Object> context) {
|
||||
List<String> serviceList = new ArrayList<String>();
|
||||
List<String> applicationList = new ArrayList<String>();
|
||||
String service = (String) context.get("service");
|
||||
String application = (String) context.get("application");
|
||||
if (StringUtils.isNotEmpty(application)) {
|
||||
serviceList.addAll(providerService.findServicesByApplication(application));
|
||||
serviceList.addAll(consumerService.findServicesByApplication(application));
|
||||
context.put("serviceList", serviceList);
|
||||
} else if (StringUtils.isNotEmpty(service)) {
|
||||
applicationList.addAll(providerService.findApplicationsByServiceName(service));
|
||||
applicationList.addAll(consumerService.findApplicationsByServiceName(service));
|
||||
context.put("applicationList", applicationList);
|
||||
} else {
|
||||
serviceList.addAll(providerService.findServices());
|
||||
serviceList.addAll(consumerService.findServices());
|
||||
providerService.findServicesByApplication(application);
|
||||
consumerService.findServicesByApplication(application);
|
||||
}
|
||||
context.put("serviceList", serviceList);
|
||||
|
||||
if (StringUtils.isNotEmpty(service) && !service.contains("*")) {
|
||||
context.put("methods", CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(service))));
|
||||
}
|
||||
}
|
||||
|
||||
public void edit(Long id, Map<String, Object> context) {
|
||||
Override override = overrideService.findById(id);
|
||||
|
||||
Map<String, String> parameters = parseQueryString(override.getParams());
|
||||
|
||||
if (parameters.get(DEFAULT_MOCK_JSON_KEY) != null) {
|
||||
String mock = URL.decode(parameters.get(DEFAULT_MOCK_JSON_KEY));
|
||||
String[] tokens = parseMock(mock);
|
||||
context.put(FORM_DEFAULT_MOCK_METHOD_FORCE, tokens[0]);
|
||||
context.put(FORM_DEFAULT_MOCK_METHOD_JSON, tokens[1]);
|
||||
parameters.remove(DEFAULT_MOCK_JSON_KEY);
|
||||
}
|
||||
|
||||
Map<String, String> method2Force = new LinkedHashMap<String, String>();
|
||||
Map<String, String> method2Json = new LinkedHashMap<String, String>();
|
||||
|
||||
List<String> methods = CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(override.getService())));
|
||||
if (methods != null && methods.isEmpty()) {
|
||||
for (String m : methods) {
|
||||
parseMock(m, parameters.get(m + MOCK_JSON_KEY_POSTFIX), method2Force, method2Json);
|
||||
parameters.remove(m + MOCK_JSON_KEY_POSTFIX);
|
||||
}
|
||||
}
|
||||
for (Iterator<Map.Entry<String, String>> iterator = parameters.entrySet().iterator(); iterator.hasNext(); ) {
|
||||
Map.Entry<String, String> e = iterator.next();
|
||||
String key = e.getKey();
|
||||
|
||||
if (key.endsWith(MOCK_JSON_KEY_POSTFIX)) {
|
||||
String m = key.substring(0, key.length() - MOCK_JSON_KEY_POSTFIX.length());
|
||||
parseMock(m, e.getValue(), method2Force, method2Json);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
context.put("methods", methods);
|
||||
context.put("methodForces", method2Force);
|
||||
context.put("methodJsons", method2Json);
|
||||
context.put("parameters", parameters);
|
||||
context.put("override", override);
|
||||
}
|
||||
|
||||
private void parseMock(String m, String mock, Map<String, String> method2Force, Map<String, String> method2Json) {
|
||||
String[] tokens = parseMock(mock);
|
||||
method2Force.put(m, tokens[0]);
|
||||
method2Json.put(m, tokens[1]);
|
||||
}
|
||||
|
||||
private String[] parseMock(String mock) {
|
||||
mock = URL.decode(mock);
|
||||
String force;
|
||||
if (mock.startsWith("force:")) {
|
||||
force = "force";
|
||||
mock = mock.substring("force:".length());
|
||||
} else if (mock.startsWith("fail:")) {
|
||||
force = "fail";
|
||||
mock = mock.substring("fail:".length());
|
||||
} else {
|
||||
force = "fail";
|
||||
}
|
||||
String[] tokens = new String[2];
|
||||
tokens[0] = force;
|
||||
tokens[1] = mock;
|
||||
return tokens;
|
||||
}
|
||||
|
||||
boolean catchParams(Override override, Map<String, Object> context) {
|
||||
String service = (String) context.get("service");
|
||||
if (service == null || service.trim().length() == 0) {
|
||||
context.put("message", getMessage("service is blank!"));
|
||||
return false;
|
||||
}
|
||||
if (!super.currentUser.hasServicePrivilege(service)) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", service));
|
||||
return false;
|
||||
}
|
||||
|
||||
String defaultMockMethodForce = (String) context.get(FORM_DEFAULT_MOCK_METHOD_FORCE);
|
||||
String defaultMockMethodJson = (String) context.get(FORM_DEFAULT_MOCK_METHOD_JSON);
|
||||
|
||||
Map<String, String> override2Value = new HashMap<String, String>();
|
||||
Map<String, String> method2Json = new HashMap<String, String>();
|
||||
|
||||
for (Map.Entry<String, Object> param : context.entrySet()) {
|
||||
String key = param.getKey().trim();
|
||||
if (!(param.getValue() instanceof String)) continue;
|
||||
|
||||
String value = (String) param.getValue();
|
||||
|
||||
if (key.startsWith(FORM_OVERRIDE_KEY) && value != null && value.trim().length() > 0) {
|
||||
String index = key.substring(FORM_OVERRIDE_KEY.length());
|
||||
String overrideValue = (String) context.get(FORM_OVERRIDE_VALUE + index);
|
||||
if (overrideValue != null && overrideValue.trim().length() > 0) {
|
||||
override2Value.put(value.trim(), overrideValue.trim());
|
||||
}
|
||||
}
|
||||
|
||||
if (key.startsWith(FORM_ORIGINAL_METHOD_PREFIX) && value != null && value.trim().length() > 0) {
|
||||
String method = key.substring(FORM_ORIGINAL_METHOD_PREFIX.length());
|
||||
String force = (String) context.get(FORM_ORIGINAL_METHOD_FORCE_PREFIX + method);
|
||||
method2Json.put(method, force + ":" + value.trim());
|
||||
}
|
||||
|
||||
if (key.startsWith(FORM_DYNAMIC_METHOD_NAME_PREFIX) && value != null && value.trim().length() > 0) {
|
||||
String index = key.substring(FORM_DYNAMIC_METHOD_NAME_PREFIX.length());
|
||||
String force = (String) context.get(FORM_DYNAMIC_METHOD_FORCE_PREFIX + index);
|
||||
String json = (String) context.get(FORM_DYNAMIC_METHOD_JSON_PREFIX + index);
|
||||
|
||||
if (json != null && json.trim().length() > 0) {
|
||||
method2Json.put(value.trim(), force + ":" + json.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder paramters = new StringBuilder();
|
||||
boolean isFirst = true;
|
||||
if (defaultMockMethodJson != null && defaultMockMethodJson.trim().length() > 0) {
|
||||
paramters.append("mock=").append(URL.encode(defaultMockMethodForce + ":" + defaultMockMethodJson.trim()));
|
||||
isFirst = false;
|
||||
}
|
||||
for (Map.Entry<String, String> e : method2Json.entrySet()) {
|
||||
if (isFirst) isFirst = false;
|
||||
else paramters.append("&");
|
||||
|
||||
paramters.append(e.getKey()).append(MOCK_JSON_KEY_POSTFIX).append("=").append(URL.encode(e.getValue()));
|
||||
}
|
||||
for (Map.Entry<String, String> e : override2Value.entrySet()) {
|
||||
if (isFirst) isFirst = false;
|
||||
else paramters.append("&");
|
||||
|
||||
paramters.append(e.getKey()).append("=").append(URL.encode(e.getValue()));
|
||||
}
|
||||
|
||||
String p = paramters.toString();
|
||||
if (p.trim().length() == 0) {
|
||||
context.put("message", getMessage("Please enter Parameters!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
override.setParams(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean create(Override override, Map<String, Object> context) {
|
||||
if (!catchParams(override, context)) return false;
|
||||
|
||||
overrideService.saveOverride(override);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean update(Override override, Map<String, Object> context) {
|
||||
Override o = overrideService.findById(override.getId());
|
||||
override.setService(o.getService());
|
||||
override.setAddress(o.getAddress());
|
||||
override.setApplication(o.getApplication());
|
||||
|
||||
if (!catchParams(override, context)) return false;
|
||||
|
||||
overrideService.updateOverride(override);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean delete(Long[] ids, Map<String, Object> context) {
|
||||
for (Long id : ids) {
|
||||
overrideService.deleteOverride(id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean enable(Long[] ids, Map<String, Object> context) {
|
||||
for (Long id : ids) {
|
||||
Override override = overrideService.findById(id);
|
||||
if (override == null) {
|
||||
context.put("message", getMessage("NoSuchOperationData", id));
|
||||
return false;
|
||||
} else {
|
||||
if (!super.currentUser.hasServicePrivilege(override.getService())) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", override.getService()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Long id : ids) {
|
||||
overrideService.enableOverride(id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean disable(Long[] ids, Map<String, Object> context) {
|
||||
for (Long id : ids) {
|
||||
Override override = overrideService.findById(id);
|
||||
if (override == null) {
|
||||
context.put("message", getMessage("NoSuchOperationData", id));
|
||||
return false;
|
||||
} else {
|
||||
if (!super.currentUser.hasServicePrivilege(override.getService())) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", override.getService()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Long id : ids) {
|
||||
overrideService.disableOverride(id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.governance.service.OwnerService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
import com.alibaba.dubbo.registry.common.domain.Owner;
|
||||
import com.alibaba.dubbo.registry.common.util.Tool;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Providers. URI: /services/$service/owners
|
||||
*
|
||||
*/
|
||||
public class Owners extends Restful {
|
||||
|
||||
@Autowired
|
||||
private OwnerService ownerService;
|
||||
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
|
||||
public void index(Map<String, Object> context) {
|
||||
String service = (String) context.get("service");
|
||||
List<Owner> owners;
|
||||
if (service != null && service.length() > 0) {
|
||||
owners = ownerService.findByService(service);
|
||||
} else {
|
||||
owners = ownerService.findAll();
|
||||
}
|
||||
context.put("owners", owners);
|
||||
}
|
||||
|
||||
public void add(Map<String, Object> context) {
|
||||
String service = (String) context.get("service");
|
||||
if (service == null || service.length() == 0) {
|
||||
List<String> serviceList = Tool.sortSimpleName(new ArrayList<String>(providerService.findServices()));
|
||||
context.put("serviceList", serviceList);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean create(Owner owner, Map<String, Object> context) {
|
||||
String service = owner.getService();
|
||||
String username = owner.getUsername();
|
||||
if (service == null || service.length() == 0
|
||||
|| username == null || username.length() == 0) {
|
||||
context.put("message", getMessage("NoSuchOperationData"));
|
||||
return false;
|
||||
}
|
||||
if (!super.currentUser.hasServicePrivilege(service)) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", service));
|
||||
return false;
|
||||
}
|
||||
ownerService.saveOwner(owner);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean delete(Long[] ids, Map<String, Object> context) {
|
||||
String service = (String) context.get("service");
|
||||
String username = (String) context.get("username");
|
||||
Owner owner = new Owner();
|
||||
owner.setService(service);
|
||||
owner.setUsername(username);
|
||||
if (service == null || service.length() == 0
|
||||
|| username == null || username.length() == 0) {
|
||||
context.put("message", getMessage("NoSuchOperationData"));
|
||||
return false;
|
||||
}
|
||||
if (!super.currentUser.hasServicePrivilege(service)) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", service));
|
||||
return false;
|
||||
}
|
||||
ownerService.deleteOwner(owner);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,385 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.OverrideService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
import com.alibaba.dubbo.registry.common.domain.Override;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
import com.alibaba.dubbo.registry.common.route.OverrideUtils;
|
||||
import com.alibaba.dubbo.registry.common.util.Tool;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>Providers.</p>
|
||||
* URI: <br>
|
||||
* GET /providers, show all providers<br>
|
||||
* GET /providers/add, show web form for add a static provider<br>
|
||||
* POST /provider/create, create a static provider, save form<br>
|
||||
* GET /providers/$id, show provider details<br>
|
||||
* GET /providers/$id/edit, web form for edit provider<br>
|
||||
* POST /providers/$id, update provider, save form<br>
|
||||
* GET /providers/$id/delete, delete a provider<br>
|
||||
* GET /providers/$id/tostatic, transfer to static<br>
|
||||
* GET /providers/$id/todynamic, transfer to dynamic<br>
|
||||
* GET /providers/$id/enable, enable a provider<br>
|
||||
* GET /providers/$id/disable, disable a provider<br>
|
||||
* GET /providers/$id/reconnect, reconnect<br>
|
||||
* GET /providers/$id/recover, recover<br>
|
||||
* <br>
|
||||
* GET /services/$service/providers, show all provider of a specific service<br>
|
||||
* GET /services/$service/providers/add, show web form for add a static provider<br>
|
||||
* POST /services/$service/providers, save a static provider<br>
|
||||
* GET /services/$service/providers/$id, show provider details<br>
|
||||
* GET /services/$service/providers/$id/edit, show web form for edit provider<br>
|
||||
* POST /services/$service/providers/$id, save changes of provider<br>
|
||||
* GET /services/$service/providers/$id/delete, delete provider<br>
|
||||
* GET /services/$service/providers/$id/tostatic, transfer to static<br>
|
||||
* GET /services/$service/providers/$id/todynamic, transfer to dynamic<br>
|
||||
* GET /services/$service/providers/$id/enable, enable<br>
|
||||
* GET /services/$service/providers/$id/disable, diable<br>
|
||||
* GET /services/$service/providers/$id/reconnect, reconnect<br>
|
||||
* GET /services/$service/providers/$id/recover, recover<br>
|
||||
*
|
||||
*/
|
||||
public class Providers extends Restful {
|
||||
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
|
||||
@Autowired
|
||||
private OverrideService overrideService;
|
||||
|
||||
@Autowired
|
||||
private HttpServletResponse response;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
public void index(Provider provider, Map<String, Object> context) {
|
||||
String service = (String) context.get("service");
|
||||
String application = (String) context.get("application");
|
||||
String address = (String) context.get("address");
|
||||
|
||||
String value = "";
|
||||
String separators = "....";
|
||||
|
||||
List<Provider> providers = null;
|
||||
|
||||
// service
|
||||
if (service != null && service.length() > 0) {
|
||||
providers = providerService.findByService(service);
|
||||
|
||||
value = service + separators + request.getRequestURI();
|
||||
}
|
||||
// address
|
||||
else if (address != null && address.length() > 0) {
|
||||
providers = providerService.findByAddress(address);
|
||||
|
||||
value = address + separators + request.getRequestURI();
|
||||
}
|
||||
// application
|
||||
else if (application != null && application.length() > 0) {
|
||||
providers = providerService.findByApplication(application);
|
||||
|
||||
value = application + separators + request.getRequestURI();
|
||||
}
|
||||
// all
|
||||
else {
|
||||
providers = providerService.findAll();
|
||||
}
|
||||
|
||||
context.put("providers", providers);
|
||||
context.put("serviceAppMap", getServiceAppMap(providers));
|
||||
|
||||
// record search history to cookies
|
||||
setSearchHistroy(context, value);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Calculate the application list corresponding to each service, to facilitate the "repeat" prompt on service page
|
||||
* @param providers app services
|
||||
*/
|
||||
private Map<String, Set<String>> getServiceAppMap(List<Provider> providers) {
|
||||
Map<String, Set<String>> serviceAppMap = new HashMap<String, Set<String>>();
|
||||
if (providers != null && providers.size() >= 0) {
|
||||
for (Provider provider : providers) {
|
||||
Set<String> appSet;
|
||||
String service = provider.getService();
|
||||
if (serviceAppMap.get(service) == null) {
|
||||
appSet = new HashSet<String>();
|
||||
} else {
|
||||
appSet = serviceAppMap.get(service);
|
||||
}
|
||||
appSet.add(provider.getApplication());
|
||||
serviceAppMap.put(service, appSet);
|
||||
}
|
||||
}
|
||||
return serviceAppMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Record search history to cookies, steps:
|
||||
* Check whether the added record exists in the cookie, and if so, update the list order; if it does not exist, insert it to the front
|
||||
*
|
||||
* @param context
|
||||
* @param value
|
||||
*/
|
||||
private void setSearchHistroy(Map<String, Object> context, String value) {
|
||||
// Analyze existing cookies
|
||||
String separatorsB = "\\.\\.\\.\\.\\.\\.";
|
||||
String newCookiev = value;
|
||||
Cookie[] cookies = request.getCookies();
|
||||
for (Cookie c : cookies) {
|
||||
if (c.getName().equals("HISTORY")) {
|
||||
String cookiev = c.getValue();
|
||||
String[] values = cookiev.split(separatorsB);
|
||||
int count = 1;
|
||||
for (String v : values) {
|
||||
if (count <= 10) {
|
||||
if (!value.equals(v)) {
|
||||
newCookiev = newCookiev + separatorsB + v;
|
||||
}
|
||||
}
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Cookie _cookie = new Cookie("HISTORY", newCookiev);
|
||||
_cookie.setMaxAge(60 * 60 * 24 * 7); // Set the cookie's lifetime to 30 minutes
|
||||
_cookie.setPath("/");
|
||||
response.addCookie(_cookie); // Write to client hard disk
|
||||
}
|
||||
|
||||
public void show(Long id, Map<String, Object> context) {
|
||||
Provider provider = providerService.findProvider(id);
|
||||
if (provider != null && provider.isDynamic()) {
|
||||
List<Override> overrides = overrideService.findByServiceAndAddress(provider.getService(), provider.getAddress());
|
||||
OverrideUtils.setProviderOverrides(provider, overrides);
|
||||
}
|
||||
context.put("provider", provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load new service page, get all the service name
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public void add(Long id, Map<String, Object> context) {
|
||||
if (context.get("service") == null) {
|
||||
List<String> serviceList = Tool.sortSimpleName(new ArrayList<String>(providerService.findServices()));
|
||||
context.put("serviceList", serviceList);
|
||||
}
|
||||
if (id != null) {
|
||||
Provider p = providerService.findProvider(id);
|
||||
if (p != null) {
|
||||
context.put("provider", p);
|
||||
String parameters = p.getParameters();
|
||||
if (parameters != null && parameters.length() > 0) {
|
||||
Map<String, String> map = StringUtils.parseQueryString(parameters);
|
||||
map.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
||||
map.remove("pid");
|
||||
p.setParameters(StringUtils.toQueryString(map));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void edit(Long id, Map<String, Object> context) {
|
||||
show(id, context);
|
||||
}
|
||||
|
||||
public boolean create(Provider provider, Map<String, Object> context) {
|
||||
String service = provider.getService();
|
||||
if (!super.currentUser.hasServicePrivilege(service)) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", service));
|
||||
return false;
|
||||
}
|
||||
if (provider.getParameters() == null) {
|
||||
String url = provider.getUrl();
|
||||
if (url != null) {
|
||||
int i = url.indexOf('?');
|
||||
if (i > 0) {
|
||||
provider.setUrl(url.substring(0, i));
|
||||
provider.setParameters(url.substring(i + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
provider.setDynamic(false); // Provider add through web page must be static
|
||||
providerService.create(provider);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean update(Provider newProvider, Map<String, Object> context) {
|
||||
Long id = newProvider.getId();
|
||||
String parameters = newProvider.getParameters();
|
||||
Provider provider = providerService.findProvider(id);
|
||||
if (provider == null) {
|
||||
context.put("message", getMessage("NoSuchOperationData", id));
|
||||
return false;
|
||||
}
|
||||
String service = provider.getService();
|
||||
if (!super.currentUser.hasServicePrivilege(service)) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", service));
|
||||
return false;
|
||||
}
|
||||
Map<String, String> oldMap = StringUtils.parseQueryString(provider.getParameters());
|
||||
Map<String, String> newMap = StringUtils.parseQueryString(parameters);
|
||||
for (Map.Entry<String, String> entry : oldMap.entrySet()) {
|
||||
if (entry.getValue().equals(newMap.get(entry.getKey()))) {
|
||||
newMap.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
if (provider.isDynamic()) {
|
||||
String address = provider.getAddress();
|
||||
List<Override> overrides = overrideService.findByServiceAndAddress(provider.getService(), provider.getAddress());
|
||||
OverrideUtils.setProviderOverrides(provider, overrides);
|
||||
Override override = provider.getOverride();
|
||||
if (override != null) {
|
||||
if (newMap.size() > 0) {
|
||||
override.setParams(StringUtils.toQueryString(newMap));
|
||||
override.setEnabled(true);
|
||||
override.setOperator(operator);
|
||||
override.setOperatorAddress(operatorAddress);
|
||||
overrideService.updateOverride(override);
|
||||
} else {
|
||||
overrideService.deleteOverride(override.getId());
|
||||
}
|
||||
} else {
|
||||
override = new Override();
|
||||
override.setService(service);
|
||||
override.setAddress(address);
|
||||
override.setParams(StringUtils.toQueryString(newMap));
|
||||
override.setEnabled(true);
|
||||
override.setOperator(operator);
|
||||
override.setOperatorAddress(operatorAddress);
|
||||
overrideService.saveOverride(override);
|
||||
}
|
||||
} else {
|
||||
provider.setParameters(parameters);
|
||||
providerService.updateProvider(provider);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean delete(Long[] ids, Map<String, Object> context) {
|
||||
for (Long id : ids) {
|
||||
Provider provider = providerService.findProvider(id);
|
||||
if (provider == null) {
|
||||
context.put("message", getMessage("NoSuchOperationData", id));
|
||||
return false;
|
||||
} else if (provider.isDynamic()) {
|
||||
context.put("message", getMessage("CanNotDeleteDynamicData", id));
|
||||
return false;
|
||||
} else if (!super.currentUser.hasServicePrivilege(provider.getService())) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", provider.getService()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (Long id : ids) {
|
||||
providerService.deleteStaticProvider(id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean enable(Long[] ids, Map<String, Object> context) {
|
||||
Map<Long, Provider> id2Provider = new HashMap<Long, Provider>();
|
||||
for (Long id : ids) {
|
||||
Provider provider = providerService.findProvider(id);
|
||||
if (provider == null) {
|
||||
context.put("message", getMessage("NoSuchOperationData", id));
|
||||
return false;
|
||||
} else if (!super.currentUser.hasServicePrivilege(provider.getService())) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", provider.getService()));
|
||||
return false;
|
||||
}
|
||||
id2Provider.put(id, provider);
|
||||
}
|
||||
for (Long id : ids) {
|
||||
providerService.enableProvider(id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean disable(Long[] ids, Map<String, Object> context) {
|
||||
for (Long id : ids) {
|
||||
Provider provider = providerService.findProvider(id);
|
||||
if (provider == null) {
|
||||
context.put("message", getMessage("NoSuchOperationData", id));
|
||||
return false;
|
||||
} else if (!super.currentUser.hasServicePrivilege(provider.getService())) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", provider.getService()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (Long id : ids) {
|
||||
providerService.disableProvider(id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean doubling(Long[] ids, Map<String, Object> context) {
|
||||
for (Long id : ids) {
|
||||
Provider provider = providerService.findProvider(id);
|
||||
if (provider == null) {
|
||||
context.put("message", getMessage("NoSuchOperationData", id));
|
||||
return false;
|
||||
} else if (!super.currentUser.hasServicePrivilege(provider.getService())) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", provider.getService()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (Long id : ids) {
|
||||
providerService.doublingProvider(id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean halving(Long[] ids, Map<String, Object> context) {
|
||||
for (Long id : ids) {
|
||||
Provider provider = providerService.findProvider(id);
|
||||
if (provider == null) {
|
||||
context.put("message", getMessage("NoSuchOperationData", id));
|
||||
return false;
|
||||
} else if (!super.currentUser.hasServicePrivilege(provider.getService())) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", provider.getService()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (Long id : ids) {
|
||||
providerService.halvingProvider(id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,523 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.utils.CollectionUtils;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.ConsumerService;
|
||||
import com.alibaba.dubbo.governance.service.OwnerService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.governance.service.RouteService;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
import com.alibaba.dubbo.registry.common.domain.Consumer;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
import com.alibaba.dubbo.registry.common.domain.Route;
|
||||
import com.alibaba.dubbo.registry.common.route.ParseUtils;
|
||||
import com.alibaba.dubbo.registry.common.route.RouteRule;
|
||||
import com.alibaba.dubbo.registry.common.route.RouteUtils;
|
||||
import com.alibaba.dubbo.registry.common.util.Tool;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Providers.
|
||||
* URI: /services/$service/routes
|
||||
*
|
||||
*/
|
||||
public class Routes extends Restful {
|
||||
|
||||
private static final int MAX_RULE_LENGTH = 1000;
|
||||
static String[][] when_names = {
|
||||
{"method", "method", "unmethod"},
|
||||
{"consumer.application", "consumerApplication", "unconsumerApplication"},
|
||||
{"consumer.cluster", "consumerCluster", "unconsumerCluster"},
|
||||
{"consumer.host", "consumerHost", "unconsumerHost"},
|
||||
{"consumer.version", "consumerVersion", "unconsumerVersion"},
|
||||
{"consumer.group", "consumerGroup", "unconsumerGroup"},
|
||||
};
|
||||
static String[][] then_names = {
|
||||
{"provider.application", "providerApplication", "unproviderApplication"},
|
||||
{"provider.cluster", "providerCluster", "unproviderCluster"}, // Must check if Cluster exists
|
||||
{"provider.host", "providerHost", "unproviderHost"},
|
||||
{"provider.protocol", "providerProtocol", "unproviderProtocol"},
|
||||
{"provider.port", "providerPort", "unproviderPort"},
|
||||
{"provider.version", "providerVersion", "unproviderVersion"},
|
||||
{"provider.group", "providerGroup", "unproviderGroup"}
|
||||
};
|
||||
@Autowired
|
||||
private RouteService routeService;
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
@Autowired
|
||||
private ConsumerService consumerService;
|
||||
|
||||
static void checkService(String service) {
|
||||
if (service.contains(",")) throw new IllegalStateException("service(" + service + ") contain illegale ','");
|
||||
|
||||
String interfaceName = service;
|
||||
int gi = interfaceName.indexOf("/");
|
||||
if (gi != -1) interfaceName = interfaceName.substring(gi + 1);
|
||||
int vi = interfaceName.indexOf(':');
|
||||
if (vi != -1) interfaceName = interfaceName.substring(0, vi);
|
||||
|
||||
if (interfaceName.indexOf('*') != -1 && interfaceName.indexOf('*') != interfaceName.length() - 1) {
|
||||
throw new IllegalStateException("service(" + service + ") only allow 1 *, and must be last char!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add owners related with service
|
||||
*
|
||||
* @param usernames the usernames to add
|
||||
* @param serviceName no wildcards
|
||||
*/
|
||||
public static void addOwnersOfService(Set<String> usernames, String serviceName,
|
||||
OwnerService ownerDAO) {
|
||||
List<String> serviceNamePatterns = ownerDAO.findAllServiceNames();
|
||||
for (String p : serviceNamePatterns) {
|
||||
if (ParseUtils.isMatchGlobPattern(p, serviceName)) {
|
||||
List<String> list = ownerDAO.findUsernamesByServiceName(p);
|
||||
usernames.addAll(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add owners related with service pattern
|
||||
*
|
||||
* @param usernames the usernames to add
|
||||
* @param serviceNamePattern service pattern, Glob
|
||||
*/
|
||||
public static void addOwnersOfServicePattern(Set<String> usernames, String serviceNamePattern,
|
||||
OwnerService ownerDAO) {
|
||||
List<String> serviceNamePatterns = ownerDAO.findAllServiceNames();
|
||||
for (String p : serviceNamePatterns) {
|
||||
if (ParseUtils.hasIntersection(p, serviceNamePattern)) {
|
||||
List<String> list = ownerDAO.findUsernamesByServiceName(p);
|
||||
usernames.addAll(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Routing module home page
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public void index(Map<String, Object> context) {
|
||||
String service = (String) context.get("service");
|
||||
String address = (String) context.get("address");
|
||||
address = Tool.getIP(address);
|
||||
List<Route> routes;
|
||||
if (service != null && service.length() > 0
|
||||
&& address != null && address.length() > 0) {
|
||||
routes = routeService.findByServiceAndAddress(service, address);
|
||||
} else if (service != null && service.length() > 0) {
|
||||
routes = routeService.findByService(service);
|
||||
} else if (address != null && address.length() > 0) {
|
||||
routes = routeService.findByAddress(address);
|
||||
} else {
|
||||
routes = routeService.findAll();
|
||||
}
|
||||
context.put("routes", routes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display routing details
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public void show(Map<String, Object> context) {
|
||||
try {
|
||||
Route route = routeService.findRoute(Long.parseLong((String) context.get("id")));
|
||||
|
||||
if (route == null) {
|
||||
throw new IllegalArgumentException("The route is not existed.");
|
||||
}
|
||||
if (route.getService() != null && !route.getService().isEmpty()) {
|
||||
context.put("service", route.getService());
|
||||
}
|
||||
|
||||
RouteRule routeRule = RouteRule.parse(route);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, RouteRule.MatchPair>[] paramArray = new Map[]{
|
||||
routeRule.getWhenCondition(), routeRule.getThenCondition()};
|
||||
String[][][] namesArray = new String[][][]{when_names, then_names};
|
||||
|
||||
for (int i = 0; i < paramArray.length; ++i) {
|
||||
Map<String, RouteRule.MatchPair> param = paramArray[i];
|
||||
String[][] names = namesArray[i];
|
||||
for (String[] name : names) {
|
||||
RouteRule.MatchPair matchPair = param.get(name[0]);
|
||||
if (matchPair == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!matchPair.getMatches().isEmpty()) {
|
||||
String m = RouteRule.join(matchPair.getMatches());
|
||||
context.put(name[1], m);
|
||||
}
|
||||
if (!matchPair.getUnmatches().isEmpty()) {
|
||||
String u = RouteRule.join(matchPair.getUnmatches());
|
||||
context.put(name[2], u);
|
||||
}
|
||||
}
|
||||
}
|
||||
context.put("route", route);
|
||||
context.put("methods", CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(route.getService()))));
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load new route page
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public void add(Map<String, Object> context) {
|
||||
String service = (String) context.get("service");
|
||||
if (service != null && service.length() > 0 && !service.contains("*")) {
|
||||
context.put("service", service);
|
||||
context.put("methods", CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(service))));
|
||||
} else {
|
||||
List<String> serviceList = Tool.sortSimpleName(new ArrayList<String>(providerService.findServices()));
|
||||
context.put("serviceList", serviceList);
|
||||
}
|
||||
|
||||
if (context.get("input") != null) context.put("input", context.get("input"));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load modified routing page
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public void edit(Map<String, Object> context) {
|
||||
add(context);
|
||||
show(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the routing information to the database
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public boolean create(Map<String, Object> context) {
|
||||
String name = (String) context.get("name");
|
||||
String service = (String) context.get("service");
|
||||
if (StringUtils.isNotEmpty(service)
|
||||
&& StringUtils.isNotEmpty(name)) {
|
||||
checkService(service);
|
||||
|
||||
Map<String, String> when_name2valueList = new HashMap<String, String>();
|
||||
Map<String, String> notWhen_name2valueList = new HashMap<String, String>();
|
||||
for (String[] names : when_names) {
|
||||
when_name2valueList.put(names[0], (String) context.get(names[1]));
|
||||
notWhen_name2valueList.put(names[0], (String) context.get(names[2])); // TODO. We should guarantee value is never null in here, will be supported later
|
||||
}
|
||||
|
||||
Map<String, String> then_name2valueList = new HashMap<String, String>();
|
||||
Map<String, String> notThen_name2valueList = new HashMap<String, String>();
|
||||
for (String[] names : then_names) {
|
||||
then_name2valueList.put(names[0], (String) context.get(names[1]));
|
||||
notThen_name2valueList.put(names[0], (String) context.get(names[2]));
|
||||
}
|
||||
|
||||
RouteRule routeRule = RouteRule.createFromNameAndValueListString(
|
||||
when_name2valueList, notWhen_name2valueList,
|
||||
then_name2valueList, notThen_name2valueList);
|
||||
|
||||
if (routeRule.getThenCondition().isEmpty()) {
|
||||
context.put("message", getMessage("Add route error! then is empty."));
|
||||
return false;
|
||||
}
|
||||
|
||||
String matchRule = routeRule.getWhenConditionString();
|
||||
String filterRule = routeRule.getThenConditionString();
|
||||
|
||||
// Limit the length of the expression
|
||||
if (matchRule.length() > MAX_RULE_LENGTH) {
|
||||
context.put("message", getMessage("When rule is too long!"));
|
||||
return false;
|
||||
}
|
||||
if (filterRule.length() > MAX_RULE_LENGTH) {
|
||||
context.put("message", getMessage("Then rule is too long!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
Route route = new Route();
|
||||
route.setService(service);
|
||||
route.setName(name);
|
||||
route.setUsername((String) context.get("operator"));
|
||||
route.setOperator((String) context.get("operatorAddress"));
|
||||
route.setRule(routeRule.toString());
|
||||
if (StringUtils.isNotEmpty((String) context.get("priority"))) {
|
||||
route.setPriority(Integer.parseInt((String) context.get("priority")));
|
||||
}
|
||||
routeService.createRoute(route);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the update data to the database
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public boolean update(Map<String, Object> context) {
|
||||
String idStr = (String) context.get("id");
|
||||
if (idStr != null && idStr.length() > 0) {
|
||||
String[] blacks = (String[]) context.get("black");
|
||||
boolean black = false;
|
||||
if (blacks != null && blacks.length > 0) {
|
||||
black = true;
|
||||
}
|
||||
|
||||
Route oldRoute = routeService.findRoute(Long.valueOf(idStr));
|
||||
if (null == oldRoute) {
|
||||
context.put("message", getMessage("NoSuchRecord"));
|
||||
return false;
|
||||
}
|
||||
// Check parameters, patchwork rule
|
||||
if (StringUtils.isNotEmpty((String) context.get("name"))) {
|
||||
String service = oldRoute.getService();
|
||||
if (context.get("operator") == null) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", service));
|
||||
return false;
|
||||
}
|
||||
|
||||
Map<String, String> when_name2valueList = new HashMap<String, String>();
|
||||
Map<String, String> notWhen_name2valueList = new HashMap<String, String>();
|
||||
for (String[] names : when_names) {
|
||||
when_name2valueList.put(names[0], (String) context.get(names[1]));
|
||||
notWhen_name2valueList.put(names[0], (String) context.get(names[2]));
|
||||
}
|
||||
|
||||
Map<String, String> then_name2valueList = new HashMap<String, String>();
|
||||
Map<String, String> notThen_name2valueList = new HashMap<String, String>();
|
||||
for (String[] names : then_names) {
|
||||
then_name2valueList.put(names[0], (String) context.get(names[1]));
|
||||
notThen_name2valueList.put(names[0], (String) context.get(names[2]));
|
||||
}
|
||||
|
||||
RouteRule routeRule = RouteRule.createFromNameAndValueListString(
|
||||
when_name2valueList, notWhen_name2valueList,
|
||||
then_name2valueList, notThen_name2valueList);
|
||||
|
||||
RouteRule result = null;
|
||||
if (black) {
|
||||
RouteRule.MatchPair matchPair = routeRule.getThenCondition().get("black");
|
||||
Map<String, RouteRule.MatchPair> then = null;
|
||||
if (null == matchPair) {
|
||||
matchPair = new RouteRule.MatchPair();
|
||||
then = new HashMap<String, RouteRule.MatchPair>();
|
||||
then.put("black", matchPair);
|
||||
} else {
|
||||
matchPair.getMatches().clear();
|
||||
}
|
||||
matchPair.getMatches().add(String.valueOf(black));
|
||||
result = RouteRule.copyWithReplace(routeRule, null, then);
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
result = routeRule;
|
||||
}
|
||||
|
||||
if (result.getThenCondition().isEmpty()) {
|
||||
context.put("message", getMessage("Update route error! then is empty."));
|
||||
return false;
|
||||
}
|
||||
|
||||
String matchRule = result.getWhenConditionString();
|
||||
String filterRule = result.getThenConditionString();
|
||||
|
||||
// Limit the length of the expression
|
||||
if (matchRule.length() > MAX_RULE_LENGTH) {
|
||||
context.put("message", getMessage("When rule is too long!"));
|
||||
return false;
|
||||
}
|
||||
if (filterRule.length() > MAX_RULE_LENGTH) {
|
||||
context.put("message", getMessage("Then rule is too long!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
int priority = 0;
|
||||
if (StringUtils.isNotEmpty((String) context.get("priority"))) {
|
||||
priority = Integer.parseInt((String) context.get("priority"));
|
||||
}
|
||||
|
||||
Route route = new Route();
|
||||
route.setRule(result.toString());
|
||||
route.setService(service);
|
||||
route.setPriority(priority);
|
||||
route.setName((String) context.get("name"));
|
||||
route.setUsername((String) context.get("operator"));
|
||||
route.setOperator((String) context.get("operatorAddress"));
|
||||
route.setId(Long.valueOf(idStr));
|
||||
route.setPriority(Integer.parseInt((String) context.get("priority")));
|
||||
route.setEnabled(oldRoute.isEnabled());
|
||||
routeService.updateRoute(route);
|
||||
|
||||
Set<String> usernames = new HashSet<String>();
|
||||
usernames.add((String) context.get("operator"));
|
||||
usernames.add(route.getUsername());
|
||||
//RelateUserUtils.addOwnersOfService(usernames, route.getService(), ownerDAO);
|
||||
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("action", "update");
|
||||
params.put("route", route);
|
||||
|
||||
} else {
|
||||
context.put("message", getMessage("MissRequestParameters", "name"));
|
||||
}
|
||||
} else {
|
||||
context.put("message", getMessage("MissRequestParameters", "id"));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the route rule for the specified ID
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
public boolean delete(Long[] ids, Map<String, Object> context) {
|
||||
for (Long id : ids) {
|
||||
routeService.deleteRoute(id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the specified route ID rules (batch processing)
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
public boolean enable(Long[] ids, Map<String, Object> context) {
|
||||
for (Long id : ids) {
|
||||
routeService.enableRoute(id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disabling route rules for specified IDs (can be batch processed)
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
public boolean disable(Long[] ids, Map<String, Object> context) {
|
||||
for (Long id : ids) {
|
||||
routeService.disableRoute(id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose consumers
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public void routeselect(Map<String, Object> context) {
|
||||
long rid = Long.valueOf((String) context.get("id"));
|
||||
context.put("id", rid);
|
||||
|
||||
Route route = routeService.findRoute(rid);
|
||||
if (route == null) {
|
||||
throw new IllegalStateException("Route(id=" + rid + ") is not existed!");
|
||||
}
|
||||
|
||||
context.put("route", route);
|
||||
// retrieve data
|
||||
List<Consumer> consumers = consumerService.findByService(route.getService());
|
||||
context.put("consumers", consumers);
|
||||
|
||||
Map<String, Boolean> matchRoute = new HashMap<String, Boolean>();
|
||||
for (Consumer c : consumers) {
|
||||
matchRoute.put(c.getAddress(), RouteUtils.matchRoute(c.getAddress(), null, route, null));
|
||||
}
|
||||
context.put("matchRoute", matchRoute);
|
||||
}
|
||||
|
||||
public void preview(Map<String, Object> context) throws Exception {
|
||||
String rid = (String) context.get("id");
|
||||
String consumerid = (String) context.get("cid");
|
||||
|
||||
|
||||
if (StringUtils.isEmpty(rid)) {
|
||||
context.put("message", getMessage("MissRequestParameters", "id"));
|
||||
}
|
||||
|
||||
Map<String, String> serviceUrls = new HashMap<String, String>();
|
||||
Route route = routeService.findRoute(Long.valueOf(rid));
|
||||
if (null == route) {
|
||||
context.put("message", getMessage("NoSuchRecord"));
|
||||
}
|
||||
List<Provider> providers = providerService.findByService(route.getService());
|
||||
if (providers != null) {
|
||||
for (Provider p : providers) {
|
||||
serviceUrls.put(p.getUrl(), p.getParameters());
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotEmpty(consumerid)) {
|
||||
Consumer consumer = consumerService.findConsumer(Long.valueOf(consumerid));
|
||||
if (null == consumer) {
|
||||
context.put("message", getMessage("NoSuchRecord"));
|
||||
}
|
||||
Map<String, String> result = RouteUtils.previewRoute(consumer.getService(), consumer.getAddress(), consumer.getParameters(), serviceUrls,
|
||||
route, null, null);
|
||||
context.put("route", route);
|
||||
context.put("consumer", consumer);
|
||||
context.put("result", result);
|
||||
} else {
|
||||
String address = (String) context.get("address");
|
||||
String service = (String) context.get("service");
|
||||
|
||||
Map<String, String> result = RouteUtils.previewRoute(service, address, null, serviceUrls,
|
||||
route, null, null);
|
||||
context.put("route", route);
|
||||
|
||||
Consumer consumer = new Consumer();
|
||||
consumer.setService(service);
|
||||
consumer.setAddress(address);
|
||||
context.put("consumer", consumer);
|
||||
context.put("result", result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,200 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.ConsumerService;
|
||||
import com.alibaba.dubbo.governance.service.OverrideService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
import com.alibaba.dubbo.registry.common.domain.Override;
|
||||
import com.alibaba.dubbo.registry.common.route.OverrideUtils;
|
||||
import com.alibaba.dubbo.registry.common.util.Tool;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* Providers. URI: /services/$service/providers /addresses/$address/services /application/$application/services
|
||||
*
|
||||
*/
|
||||
public class Services extends Restful {
|
||||
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
|
||||
@Autowired
|
||||
private ConsumerService consumerService;
|
||||
|
||||
@Autowired
|
||||
private OverrideService overrideService;
|
||||
|
||||
public void index(Map<String, Object> context) {
|
||||
String application = (String) context.get("application");
|
||||
String address = (String) context.get("address");
|
||||
|
||||
if (context.get("service") == null
|
||||
&& context.get("application") == null
|
||||
&& context.get("address") == null) {
|
||||
context.put("service", "*");
|
||||
}
|
||||
|
||||
List<String> providerServices = null;
|
||||
List<String> consumerServices = null;
|
||||
List<Override> overrides = null;
|
||||
if (application != null && application.length() > 0) {
|
||||
providerServices = providerService.findServicesByApplication(application);
|
||||
consumerServices = consumerService.findServicesByApplication(application);
|
||||
overrides = overrideService.findByApplication(application);
|
||||
} else if (address != null && address.length() > 0) {
|
||||
providerServices = providerService.findServicesByAddress(address);
|
||||
consumerServices = consumerService.findServicesByAddress(address);
|
||||
overrides = overrideService.findByAddress(Tool.getIP(address));
|
||||
} else {
|
||||
providerServices = providerService.findServices();
|
||||
consumerServices = consumerService.findServices();
|
||||
overrides = overrideService.findAll();
|
||||
}
|
||||
|
||||
Set<String> services = new TreeSet<String>();
|
||||
if (providerServices != null) {
|
||||
services.addAll(providerServices);
|
||||
}
|
||||
if (consumerServices != null) {
|
||||
services.addAll(consumerServices);
|
||||
}
|
||||
|
||||
Map<String, List<Override>> service2Overrides = new HashMap<String, List<Override>>();
|
||||
if (overrides != null && overrides.size() > 0
|
||||
&& services != null && services.size() > 0) {
|
||||
for (String s : services) {
|
||||
if (overrides != null && overrides.size() > 0) {
|
||||
for (Override override : overrides) {
|
||||
List<Override> serOverrides = new ArrayList<Override>();
|
||||
if (override.isMatch(s, address, application)) {
|
||||
serOverrides.add(override);
|
||||
}
|
||||
Collections.sort(serOverrides, OverrideUtils.OVERRIDE_COMPARATOR);
|
||||
service2Overrides.put(s, serOverrides);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context.put("providerServices", providerServices);
|
||||
context.put("consumerServices", consumerServices);
|
||||
context.put("services", services);
|
||||
context.put("overrides", service2Overrides);
|
||||
|
||||
String keyword = (String) context.get("keyword");
|
||||
if (StringUtils.isNotEmpty(keyword) && !"*".equals(keyword)) {
|
||||
keyword = keyword.toLowerCase();
|
||||
Set<String> newList = new HashSet<String>();
|
||||
Set<String> newProviders = new HashSet<String>();
|
||||
Set<String> newConsumers = new HashSet<String>();
|
||||
|
||||
for (String o : services) {
|
||||
if (o.toLowerCase().toLowerCase().indexOf(keyword) != -1) {
|
||||
newList.add(o);
|
||||
}
|
||||
}
|
||||
for (String o : providerServices) {
|
||||
if (o.toLowerCase().indexOf(keyword) != -1) {
|
||||
newProviders.add(o);
|
||||
}
|
||||
}
|
||||
for (String o : consumerServices) {
|
||||
if (o.toLowerCase().indexOf(keyword) != -1) {
|
||||
newConsumers.add(o);
|
||||
}
|
||||
}
|
||||
context.put("services", newList);
|
||||
context.put("providerServices", newProviders);
|
||||
context.put("consumerServices", newConsumers);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean shield(Map<String, Object> context) throws Exception {
|
||||
return mock(context, "force:return null");
|
||||
}
|
||||
|
||||
public boolean tolerant(Map<String, Object> context) throws Exception {
|
||||
return mock(context, "fail:return null");
|
||||
}
|
||||
|
||||
public boolean recover(Map<String, Object> context) throws Exception {
|
||||
return mock(context, "");
|
||||
}
|
||||
|
||||
private boolean mock(Map<String, Object> context, String mock) throws Exception {
|
||||
String services = (String) context.get("service");
|
||||
String application = (String) context.get("application");
|
||||
if (services == null || services.length() == 0
|
||||
|| application == null || application.length() == 0) {
|
||||
context.put("message", getMessage("NoSuchOperationData"));
|
||||
return false;
|
||||
}
|
||||
for (String service : SPACE_SPLIT_PATTERN.split(services)) {
|
||||
if (!super.currentUser.hasServicePrivilege(service)) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", service));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (String service : SPACE_SPLIT_PATTERN.split(services)) {
|
||||
List<Override> overrides = overrideService.findByServiceAndApplication(service, application);
|
||||
if (overrides != null && overrides.size() > 0) {
|
||||
for (Override override : overrides) {
|
||||
Map<String, String> map = StringUtils.parseQueryString(override.getParams());
|
||||
if (mock == null || mock.length() == 0) {
|
||||
map.remove("mock");
|
||||
} else {
|
||||
map.put("mock", URL.encode(mock));
|
||||
}
|
||||
if (map.size() > 0) {
|
||||
override.setParams(StringUtils.toQueryString(map));
|
||||
override.setEnabled(true);
|
||||
override.setOperator(operator);
|
||||
override.setOperatorAddress(operatorAddress);
|
||||
overrideService.updateOverride(override);
|
||||
} else {
|
||||
overrideService.deleteOverride(override.getId());
|
||||
}
|
||||
}
|
||||
} else if (mock != null && mock.length() > 0) {
|
||||
Override override = new Override();
|
||||
override.setService(service);
|
||||
override.setApplication(application);
|
||||
override.setParams("mock=" + URL.encode(mock));
|
||||
override.setEnabled(true);
|
||||
override.setOperator(operator);
|
||||
override.setOperatorAddress(operatorAddress);
|
||||
overrideService.saveOverride(override);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,236 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.utils.CollectionUtils;
|
||||
import com.alibaba.dubbo.governance.service.OverrideService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
import com.alibaba.dubbo.registry.common.domain.Weight;
|
||||
import com.alibaba.dubbo.registry.common.util.OverrideUtils;
|
||||
import com.alibaba.dubbo.registry.common.util.Tool;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Providers.
|
||||
* URI: /services/$service/weights
|
||||
*
|
||||
*/
|
||||
public class Weights extends Restful {
|
||||
|
||||
private static final Pattern IP_PATTERN = Pattern.compile("\\d{1,3}(\\.\\d{1,3}){3}$");
|
||||
private static final Pattern LOCAL_IP_PATTERN = Pattern.compile("127(\\.\\d{1,3}){3}$");
|
||||
private static final Pattern ALL_IP_PATTERN = Pattern.compile("0{1,3}(\\.0{1,3}){3}$");
|
||||
@Autowired
|
||||
private OverrideService overrideService;
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
|
||||
public void index(Map<String, Object> context) {
|
||||
final String service = StringUtils.trimToNull((String) context.get("service"));
|
||||
String address = (String) context.get("address");
|
||||
address = Tool.getIP(address);
|
||||
List<Weight> weights;
|
||||
if (service != null && service.length() > 0) {
|
||||
weights = OverrideUtils.overridesToWeights(overrideService.findByService(service));
|
||||
} else if (address != null && address.length() > 0) {
|
||||
weights = OverrideUtils.overridesToWeights(overrideService.findByAddress(address));
|
||||
} else {
|
||||
weights = OverrideUtils.overridesToWeights(overrideService.findAll());
|
||||
}
|
||||
context.put("weights", weights);
|
||||
}
|
||||
|
||||
/**
|
||||
* load page for the adding
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public void add(Map<String, Object> context) {
|
||||
String service = (String) context.get("service");
|
||||
if (service != null && service.length() > 0 && !service.contains("*")) {
|
||||
List<Provider> providerList = providerService.findByService(service);
|
||||
List<String> addressList = new ArrayList<String>();
|
||||
for (Provider provider : providerList) {
|
||||
addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
|
||||
}
|
||||
context.put("addressList", addressList);
|
||||
context.put("service", service);
|
||||
context.put("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
|
||||
} else {
|
||||
List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
|
||||
context.put("serviceList", serviceList);
|
||||
}
|
||||
if (context.get("input") != null) context.put("input", context.get("input"));
|
||||
}
|
||||
|
||||
/**
|
||||
* load page for the multi adding
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public void multiadd(Map<String, Object> context) {
|
||||
List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
|
||||
context.put("serviceList", serviceList);
|
||||
}
|
||||
|
||||
public boolean create(Map<String, Object> context) throws Exception {
|
||||
String addr = (String) context.get("address");
|
||||
String services = (String) context.get("multiservice");
|
||||
if (services == null || services.trim().length() == 0) {
|
||||
services = (String) context.get("service");
|
||||
}
|
||||
String weight = (String) context.get("weight");
|
||||
|
||||
int w = Integer.parseInt(weight);
|
||||
|
||||
Set<String> addresses = new HashSet<String>();
|
||||
BufferedReader reader = new BufferedReader(new StringReader(addr));
|
||||
while (true) {
|
||||
String line = reader.readLine();
|
||||
if (null == line)
|
||||
break;
|
||||
|
||||
String[] split = line.split("[\\s,;]+");
|
||||
for (String s : split) {
|
||||
if (s.length() == 0)
|
||||
continue;
|
||||
|
||||
String ip = s;
|
||||
String port = null;
|
||||
if (s.indexOf(":") != -1) {
|
||||
ip = s.substring(0, s.indexOf(":"));
|
||||
port = s.substring(s.indexOf(":") + 1, s.length());
|
||||
if (port.trim().length() == 0) port = null;
|
||||
}
|
||||
if (!IP_PATTERN.matcher(ip).matches()) {
|
||||
context.put("message", "illegal IP: " + s);
|
||||
return false;
|
||||
}
|
||||
if (LOCAL_IP_PATTERN.matcher(ip).matches() || ALL_IP_PATTERN.matcher(ip).matches()) {
|
||||
context.put("message", "local IP or any host ip is illegal: " + s);
|
||||
return false;
|
||||
}
|
||||
if (port != null) {
|
||||
if (!NumberUtils.isDigits(port)) {
|
||||
context.put("message", "illegal port: " + s);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
addresses.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> aimServices = new HashSet<String>();
|
||||
reader = new BufferedReader(new StringReader(services));
|
||||
while (true) {
|
||||
String line = reader.readLine();
|
||||
if (null == line)
|
||||
break;
|
||||
|
||||
String[] split = line.split("[\\s,;]+");
|
||||
for (String s : split) {
|
||||
if (s.length() == 0)
|
||||
continue;
|
||||
if (!super.currentUser.hasServicePrivilege(s)) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", s));
|
||||
return false;
|
||||
}
|
||||
aimServices.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
for (String aimService : aimServices) {
|
||||
for (String a : addresses) {
|
||||
Weight wt = new Weight();
|
||||
wt.setUsername((String) context.get("operator"));
|
||||
wt.setAddress(Tool.getIP(a));
|
||||
wt.setService(aimService);
|
||||
wt.setWeight(w);
|
||||
overrideService.saveOverride(OverrideUtils.weightToOverride(wt));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void edit(Long id, Map<String, Object> context) {
|
||||
add(context);
|
||||
show(id, context);
|
||||
context.put("service", overrideService.findById(id).getService());
|
||||
}
|
||||
|
||||
public void sameSeviceEdit(Long id, Map<String, Object> context) {
|
||||
add(context);
|
||||
show(id, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* load weight for editing
|
||||
*
|
||||
* @param id
|
||||
* @param context
|
||||
*/
|
||||
public void show(Long id, Map<String, Object> context) {
|
||||
Weight weight = OverrideUtils.overrideToWeight(overrideService.findById(id));
|
||||
context.put("weight", weight);
|
||||
}
|
||||
|
||||
public boolean update(Weight weight, Map<String, Object> context) {
|
||||
if (!super.currentUser.hasServicePrivilege(weight.getService())) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", weight.getService()));
|
||||
return false;
|
||||
}
|
||||
weight.setAddress(Tool.getIP(weight.getAddress()));
|
||||
overrideService.updateOverride(OverrideUtils.weightToOverride(weight));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
public boolean delete(Long[] ids, Map<String, Object> context) {
|
||||
for (Long id : ids) {
|
||||
Weight w = OverrideUtils.overrideToWeight(overrideService.findById(id));
|
||||
if (!super.currentUser.hasServicePrivilege(w.getService())) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", w.getService()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (Long id : ids) {
|
||||
overrideService.deleteOverride(id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.control;
|
||||
|
||||
import com.alibaba.citrus.service.requestcontext.parser.CookieParser;
|
||||
import com.alibaba.citrus.turbine.Context;
|
||||
import com.alibaba.dubbo.governance.sync.RegistryServerSync;
|
||||
import com.alibaba.dubbo.governance.web.common.pulltool.RootContextPath;
|
||||
import com.alibaba.dubbo.governance.web.util.WebConstants;
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
public class Menu {
|
||||
|
||||
@Autowired
|
||||
ServletContext servletcontext;
|
||||
@Autowired
|
||||
RegistryServerSync registryServerSync;
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
public void execute(HttpSession session, Context context, CookieParser parser) {
|
||||
|
||||
User user = (User) session.getAttribute(WebConstants.CURRENT_USER_KEY);
|
||||
if (user != null) context.put("operator", user.getUsername());
|
||||
|
||||
RootContextPath rootContextPath = new RootContextPath(request.getContextPath());
|
||||
context.put("rootContextPath", rootContextPath);
|
||||
if (!context.containsKey("bucLogoutAddress")) {
|
||||
context.put("bucLogoutAddress", rootContextPath.getURI("logout"));
|
||||
}
|
||||
if (!context.containsKey("helpUrl")) {
|
||||
context.put("helpUrl", "http://code.alibabatech.com/wiki/display/dubbo");
|
||||
}
|
||||
context.put(WebConstants.CURRENT_USER_KEY, user);
|
||||
context.put("language", parser.getString("locale"));
|
||||
context.put("registryServerSync", registryServerSync);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Disable extends Shell {
|
||||
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
public void setProviderDAO(ProviderService providerDAO) {
|
||||
this.providerService = providerDAO;
|
||||
}
|
||||
|
||||
protected String doExecute(Map<String, Object> context) throws Exception {
|
||||
String address = request.getParameter("provider");
|
||||
if (address == null || address.length() == 0) {
|
||||
address = request.getParameter("client");
|
||||
}
|
||||
if (address == null || address.length() == 0) {
|
||||
throw new IllegalArgumentException("The url provider parameter is null! Usage: " + request.getRequestURL().toString() + "?provider=" + operatorAddress);
|
||||
}
|
||||
List<Provider> providers = providerService.findByAddress(address);
|
||||
if (providers != null && providers.size() > 0) {
|
||||
for (Provider provider : providers) {
|
||||
if (!currentUser.hasServicePrivilege(provider.getService())) {
|
||||
throw new IllegalStateException("The user " + currentUser.getUsername() + " have no privilege of service " + provider.getService());
|
||||
}
|
||||
}
|
||||
for (Provider provider : providers) {
|
||||
provider.setUsername(operator);
|
||||
provider.setOperatorAddress(operatorAddress);
|
||||
providerService.disableProvider(provider.getId());
|
||||
}
|
||||
}
|
||||
return "Disable " + (providers == null ? 0 : providers.size()) + " services.";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import com.alibaba.citrus.turbine.Context;
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
import com.alibaba.dubbo.common.logger.LoggerFactory;
|
||||
import com.alibaba.dubbo.governance.service.ConsumerService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.governance.web.common.pulltool.RootContextPath;
|
||||
import com.alibaba.dubbo.registry.common.domain.Consumer;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Index
|
||||
*
|
||||
*/
|
||||
public class Index {
|
||||
// logger
|
||||
private static final Logger logger = LoggerFactory.getLogger(Index.class);
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
|
||||
@Autowired
|
||||
private ConsumerService consumerService;
|
||||
|
||||
public void execute(Context context) {
|
||||
Set<String> applications = new HashSet<String>();
|
||||
Set<String> services = new HashSet<String>();
|
||||
List<Provider> pList = new ArrayList<Provider>();
|
||||
try {
|
||||
pList = providerService.findAll();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
for (Provider p : pList) {
|
||||
applications.add(p.getApplication());
|
||||
services.add(p.getService());
|
||||
}
|
||||
List<Consumer> cList = new ArrayList<Consumer>();
|
||||
try {
|
||||
cList = consumerService.findAll();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
for (Consumer c : cList) {
|
||||
applications.add(c.getApplication());
|
||||
services.add(c.getService());
|
||||
}
|
||||
context.put("rootContextPath", new RootContextPath(request.getContextPath()));
|
||||
context.put("services", services.size());
|
||||
context.put("providers", pList.size());
|
||||
context.put("consumers", cList.size());
|
||||
context.put("applications", applications.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.governance.service.ConsumerService;
|
||||
import com.alibaba.dubbo.registry.RegistryService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Lookup extends Restful {
|
||||
|
||||
@Autowired
|
||||
ConsumerService consumerDAO;
|
||||
|
||||
@Autowired
|
||||
private RegistryService registryService;
|
||||
|
||||
public Result doExecute(Map<String, Object> context) throws Exception {
|
||||
String inf = request.getParameter("interface");
|
||||
if (inf == null || inf.isEmpty()) {
|
||||
throw new IllegalArgumentException("please give me the interface");
|
||||
}
|
||||
String group = null;
|
||||
if (inf.contains("/")) {
|
||||
int idx = inf.indexOf('/');
|
||||
group = inf.substring(idx);
|
||||
inf = inf.substring(idx + 1, inf.length());
|
||||
}
|
||||
String version = null;
|
||||
if (inf.contains(":")) {
|
||||
int idx = inf.lastIndexOf(':');
|
||||
version = inf.substring(idx + 1, inf.length());
|
||||
inf = inf.substring(idx);
|
||||
}
|
||||
|
||||
String parameters = request.getParameter("parameters");
|
||||
String url = "subscribe://" + operatorAddress + "/" + request.getParameter("interface");
|
||||
if (parameters != null && parameters.trim().length() > 0) {
|
||||
url += parameters.trim();
|
||||
}
|
||||
|
||||
URL u = URL.valueOf(url);
|
||||
if (group != null) {
|
||||
u.addParameter("group", group);
|
||||
}
|
||||
|
||||
if (version != null) u.addParameter("version", version);
|
||||
|
||||
List<URL> lookup = registryService.lookup(u);
|
||||
|
||||
Map<String, Map<String, String>> serviceUrl = new HashMap<String, Map<String, String>>();
|
||||
Map<String, String> urls = new HashMap<String, String>();
|
||||
serviceUrl.put(request.getParameter("interface").trim(), urls);
|
||||
|
||||
for (URL u2 : lookup) {
|
||||
urls.put(u2.toIdentityString(), u2.toParameterString());
|
||||
}
|
||||
|
||||
Result result = new Result();
|
||||
result.setMessage(serviceUrl);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Reg extends Restful {
|
||||
|
||||
public Result doExecute(Map<String, Object> context) throws Exception {
|
||||
if (url == null) {
|
||||
throw new IllegalArgumentException("please give me the url");
|
||||
}
|
||||
if (url.getPath().isEmpty()) {
|
||||
throw new IllegalArgumentException("please use interface as your url path");
|
||||
}
|
||||
Map<String, String> tmp = new HashMap<String, String>();
|
||||
tmp.put(url.toIdentityString(), url.toParameterString());
|
||||
Map<String, Map<String, String>> register = new HashMap<String, Map<String, String>>();
|
||||
register.put(url.getPath(), tmp);
|
||||
// Map<String, Map<String, String>> newRegister = RegistryUtils.convertRegister(register);
|
||||
// registryService.register(operatorAddress, newRegister, false);
|
||||
Result result = new Result();
|
||||
result.setMessage("Register Successfully!");
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.utils.CollectionUtils;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Register extends Shell {
|
||||
|
||||
@Autowired
|
||||
private ProviderService providerDAO;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
// @Autowired
|
||||
// private RegistryCache registryCache;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected String doExecute(Map<String, Object> context) throws Exception {
|
||||
Map<String, String[]> params = request.getParameterMap();
|
||||
if (params == null || params.size() == 0) {
|
||||
throw new IllegalArgumentException("The url parameters is null! Usage: " + request.getRequestURL().toString() + "?com.xxx.XxxService=http://" + request.getRemoteAddr() + "/xxxService?application=xxx&foo1=123");
|
||||
}
|
||||
Map<String, Map<String, String>> map = new HashMap<String, Map<String, String>>();
|
||||
for (Map.Entry<String, String[]> entry : params.entrySet()) {
|
||||
if (entry.getKey() != null && entry.getKey().length() > 0
|
||||
&& entry.getValue() != null && entry.getValue().length > 0
|
||||
&& entry.getValue()[0] != null && entry.getValue()[0].length() > 0) {
|
||||
if (!currentUser.hasServicePrivilege(entry.getKey())) {
|
||||
throw new IllegalStateException("The user " + currentUser.getUsername() + " have no privilege of service " + entry.getKey());
|
||||
}
|
||||
String serviceName = entry.getKey();
|
||||
Map<String, String> url2query = CollectionUtils.split(Arrays.asList(entry.getValue()), "?");
|
||||
// check whether url contain application info
|
||||
for (Map.Entry<String, String> e : url2query.entrySet()) {
|
||||
Map<String, String> query = StringUtils.parseQueryString(e.getValue());
|
||||
String app = query.get("application");
|
||||
if (StringUtils.isBlank(app)) {
|
||||
throw new IllegalStateException("No application for service(" + serviceName + "): "
|
||||
+ e.getKey() + "?" + e.getValue());
|
||||
}
|
||||
}
|
||||
map.put(serviceName, url2query);
|
||||
}
|
||||
}
|
||||
if (map.size() > 0) {
|
||||
// providerDAO.register(registryCache.getCurrentRegistry(), request.getRemoteAddr(), operatorAddress, operator, map, false, true);
|
||||
}
|
||||
return "Register " + map.size() + " services.";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.governance.web.util.WebConstants;
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class Restful {
|
||||
|
||||
protected String role = null;
|
||||
protected String operator = null;
|
||||
|
||||
// @Autowired
|
||||
// RegistryValidator registryService;
|
||||
protected User currentUser = null;
|
||||
protected String operatorAddress = null;
|
||||
protected URL url = null;
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
@Autowired
|
||||
private HttpServletResponse response;
|
||||
|
||||
public void execute(Map<String, Object> context) throws Exception {
|
||||
Result result = new Result();
|
||||
if (request.getParameter("url") != null) {
|
||||
url = URL.valueOf(URL.decode(request.getParameter("url")));
|
||||
}
|
||||
if (context.get(WebConstants.CURRENT_USER_KEY) != null) {
|
||||
User user = (User) context.get(WebConstants.CURRENT_USER_KEY);
|
||||
currentUser = user;
|
||||
operator = user.getUsername();
|
||||
role = user.getRole();
|
||||
context.put(WebConstants.CURRENT_USER_KEY, user);
|
||||
}
|
||||
operatorAddress = (String) context.get("clientid");
|
||||
if (operatorAddress == null || operatorAddress.isEmpty()) {
|
||||
operatorAddress = (String) context.get("request.remoteHost");
|
||||
}
|
||||
context.put("operator", operator);
|
||||
context.put("operatorAddress", operatorAddress);
|
||||
String jsonResult = null;
|
||||
try {
|
||||
result = doExecute(context);
|
||||
result.setStatus("OK");
|
||||
} catch (IllegalArgumentException t) {
|
||||
result.setStatus("ERROR");
|
||||
result.setCode(3);
|
||||
result.setMessage(t.getMessage());
|
||||
}
|
||||
// catch (InvalidRequestException t) {
|
||||
// result.setStatus("ERROR");
|
||||
// result.setCode(2);
|
||||
// result.setMessage(t.getMessage());
|
||||
// }
|
||||
catch (Throwable t) {
|
||||
result.setStatus("ERROR");
|
||||
result.setCode(1);
|
||||
result.setMessage(t.getMessage());
|
||||
}
|
||||
response.setContentType("application/javascript");
|
||||
ServletOutputStream os = response.getOutputStream();
|
||||
try {
|
||||
jsonResult = JSON.toJSONString(result);
|
||||
os.print(jsonResult);
|
||||
} catch (Exception e) {
|
||||
response.setStatus(500);
|
||||
os.print(e.getMessage());
|
||||
} finally {
|
||||
os.flush();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Result doExecute(Map<String, Object> context) throws Exception;
|
||||
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Result implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 4922467873471920132L;
|
||||
private String status;
|
||||
private Object message;
|
||||
private int code;
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Object getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(Object message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + code;
|
||||
result = prime * result + ((message == null) ? 0 : message.hashCode());
|
||||
result = prime * result + ((status == null) ? 0 : status.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
Result other = (Result) obj;
|
||||
if (code != other.code) return false;
|
||||
if (message == null) {
|
||||
if (other.message != null) return false;
|
||||
} else if (!message.equals(other.message)) return false;
|
||||
if (status == null) {
|
||||
if (other.status != null) return false;
|
||||
} else if (!status.equals(other.status)) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Map;
|
||||
|
||||
public class Servicestatus {
|
||||
// @Autowired
|
||||
// private RegistryCache registryCache;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Autowired
|
||||
private ProviderService providerDAO;
|
||||
|
||||
@Autowired
|
||||
private HttpServletResponse response;
|
||||
|
||||
public void execute(Map<String, Object> context) throws Exception {
|
||||
String uri = request.getRequestURI();
|
||||
String contextPath = request.getContextPath();
|
||||
if (contextPath != null && !"/".equals(contextPath)) {
|
||||
uri = uri.substring(contextPath.length());
|
||||
}
|
||||
if (uri.startsWith("/status/")) {
|
||||
uri = uri.substring("/status/".length());
|
||||
}
|
||||
// Map<String, String> providers = registryCache.getServices().get(uri);
|
||||
// if (providers == null || providers.size() == 0) {
|
||||
// providers = providerDAO.lookup(uri);
|
||||
// }
|
||||
// if (providers == null || providers.size() == 0) {
|
||||
// context.put("message", "ERROR"
|
||||
// + new SimpleDateFormat(" [yyyy-MM-dd HH:mm:ss] ").format(new Date())
|
||||
// + Status.filterOK("No such any provider for service " + uri));
|
||||
// } else {
|
||||
// context.put("message", "OK");
|
||||
// }
|
||||
PrintWriter writer = response.getWriter();
|
||||
writer.print(context.get("message").toString());
|
||||
writer.flush();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.governance.web.util.WebConstants;
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public abstract class Shell {
|
||||
private static final Pattern OK_PATTERN = Pattern.compile("ok", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern ERROR_PATTERN = Pattern.compile("error", Pattern.CASE_INSENSITIVE);
|
||||
protected String role = null;
|
||||
protected String operator = null;
|
||||
protected User currentUser = null;
|
||||
protected String operatorAddress = null;
|
||||
@Autowired
|
||||
private HttpServletResponse response;
|
||||
|
||||
private static String filterOK(String value) {
|
||||
if (value == null || value.length() == 0) {
|
||||
return value;
|
||||
}
|
||||
return OK_PATTERN.matcher(value).replaceAll("0k");
|
||||
}
|
||||
|
||||
private static String filterERROR(String value) {
|
||||
if (value == null || value.length() == 0) {
|
||||
return value;
|
||||
}
|
||||
return ERROR_PATTERN.matcher(value).replaceAll("err0r");
|
||||
}
|
||||
|
||||
public void execute(Map<String, Object> context) throws Exception {
|
||||
if (context.get(WebConstants.CURRENT_USER_KEY) != null) {
|
||||
User user = (User) context.get(WebConstants.CURRENT_USER_KEY);
|
||||
currentUser = user;
|
||||
operator = user.getUsername();
|
||||
role = user.getRole();
|
||||
context.put(WebConstants.CURRENT_USER_KEY, user);
|
||||
}
|
||||
operatorAddress = (String) context.get("request.remoteHost");
|
||||
context.put("operator", operator);
|
||||
context.put("operatorAddress", operatorAddress);
|
||||
try {
|
||||
String message = doExecute(context);
|
||||
context.put("message", "OK: " + filterERROR(message));
|
||||
} catch (Throwable t) {
|
||||
context.put("message", "ERROR: " + filterOK(t.getMessage()));
|
||||
}
|
||||
PrintWriter writer = response.getWriter();
|
||||
writer.print(context.get("message"));
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
protected abstract String doExecute(Map<String, Object> context) throws Exception;
|
||||
|
||||
}
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.status.Status.Level;
|
||||
import com.alibaba.dubbo.common.status.StatusChecker;
|
||||
import com.alibaba.dubbo.registry.common.StatusManager;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Status {
|
||||
private static final Pattern OK_PATTERN = Pattern.compile("o(k)", Pattern.CASE_INSENSITIVE);
|
||||
@Autowired
|
||||
private HttpServletResponse response;
|
||||
|
||||
public static String filterOK(String message) {
|
||||
if (message == null)
|
||||
return "";
|
||||
// Avoid the ok keyword, use the number 0 instead of the letter o
|
||||
return OK_PATTERN.matcher(message).replaceAll("0$1");
|
||||
}
|
||||
|
||||
public void execute(Map<String, Object> context) throws Exception {
|
||||
//FIXME cache monitoring has bad performance, should be removed from summary page.
|
||||
Map<String, com.alibaba.dubbo.common.status.Status> statuses = StatusManager.getInstance().getStatusList(new String[]{"cache"});
|
||||
com.alibaba.dubbo.common.status.Status status = StatusManager.getInstance().getStatusSummary(statuses);
|
||||
Level level = status.getLevel();
|
||||
if (!com.alibaba.dubbo.common.status.Status.Level.OK.equals(level)) {
|
||||
context.put("message", level
|
||||
+ new SimpleDateFormat(" [yyyy-MM-dd HH:mm:ss] ").format(new Date())
|
||||
+ filterOK(status.getMessage()));
|
||||
} else {
|
||||
context.put("message", level.toString());
|
||||
}
|
||||
PrintWriter writer = response.getWriter();
|
||||
writer.print(context.get("message").toString());
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
public void setStatusHandlers(Collection<StatusChecker> statusHandlers) {
|
||||
StatusManager.getInstance().addStatusHandlers(statusHandlers);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* UnReg.java
|
||||
*
|
||||
*/
|
||||
public class Unreg extends Restful {
|
||||
|
||||
public Result doExecute(Map<String, Object> context) throws Exception {
|
||||
if (url == null) {
|
||||
throw new IllegalArgumentException("please give me the url");
|
||||
}
|
||||
if (url.getPath().isEmpty()) {
|
||||
throw new IllegalArgumentException("please use interface as your url path");
|
||||
}
|
||||
HashMap<String, Set<String>> services = new HashMap<String, Set<String>>();
|
||||
Set<String> serviceUrl = new HashSet<String>();
|
||||
serviceUrl.add(url.toIdentityString());
|
||||
String name = url.getPath();
|
||||
String version = url.getParameter("version");
|
||||
if (version != null) {
|
||||
name = name + ":" + version;
|
||||
}
|
||||
String group = url.getParameter("group");
|
||||
if (group != null) {
|
||||
name = group + "/" + name;
|
||||
}
|
||||
services.put(name, serviceUrl);
|
||||
// registryService.unregister(operatorAddress,services);
|
||||
Result result = new Result();
|
||||
result.setMessage("Unregister Successfully!");
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.utils.CollectionUtils;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class Unregister extends Shell {
|
||||
|
||||
@Autowired
|
||||
private ProviderService providervice;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected String doExecute(Map<String, Object> context) throws Exception {
|
||||
Map<String, String[]> params = request.getParameterMap();
|
||||
if (params == null || params.size() == 0) {
|
||||
throw new IllegalArgumentException("The url parameters is null! Usage: " + request.getRequestURL().toString() + "?com.xxx.XxxService=http://" + operatorAddress + "/xxxService");
|
||||
}
|
||||
for (Map.Entry<String, String[]> entry : params.entrySet()) {
|
||||
if (entry.getKey() != null && entry.getKey().length() > 0
|
||||
&& entry.getValue() != null && entry.getValue().length > 0
|
||||
&& entry.getValue()[0] != null && entry.getValue()[0].length() > 0) {
|
||||
if (!currentUser.hasServicePrivilege(entry.getKey())) {
|
||||
throw new IllegalStateException("The user " + operator + " have no privilege of service " + entry.getKey());
|
||||
}
|
||||
for (Entry<String, String> e : CollectionUtils.split(Arrays.asList(entry.getValue()), "?").entrySet()) {
|
||||
Provider provider = providervice.findByServiceAndAddress(entry.getKey(), e.getKey());
|
||||
if (provider != null) {
|
||||
providervice.deleteStaticProvider(provider.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "Unregister " + params.size() + " services.";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Unregisterall extends Shell {
|
||||
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
protected String doExecute(Map<String, Object> context) throws Exception {
|
||||
String address = request.getParameter("provider");
|
||||
if (address == null || address.length() == 0) {
|
||||
address = request.getParameter("client");
|
||||
}
|
||||
if (address == null || address.length() == 0) {
|
||||
throw new IllegalArgumentException("The url provider parameter is null! Usage: " + request.getRequestURL().toString() + "?provider=" + operatorAddress);
|
||||
}
|
||||
List<Provider> providers = providerService.findByAddress(address);
|
||||
if (providers != null && providers.size() > 0) {
|
||||
for (Provider provider : providers) {
|
||||
if (!currentUser.hasServicePrivilege(provider.getService())) {
|
||||
throw new IllegalStateException("The user " + currentUser + " have no privilege of service " + provider.getService());
|
||||
}
|
||||
}
|
||||
for (Provider provider : providers) {
|
||||
provider.setUsername(operator);
|
||||
provider.setOperatorAddress(operatorAddress);
|
||||
providerService.deleteStaticProvider(provider.getId());
|
||||
}
|
||||
}
|
||||
return "Unregister " + (providers == null ? 0 : providers.size()) + " services.";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.personal.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.governance.service.UserService;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Infos extends Restful {
|
||||
@Autowired
|
||||
private UserService userDAO;
|
||||
|
||||
public void index(Map<String, Object> context) {
|
||||
User user = userDAO.findById(currentUser.getId());
|
||||
context.put("user", user);
|
||||
}
|
||||
|
||||
public boolean update(Map<String, Object> context) {
|
||||
User user = new User();
|
||||
user.setId(currentUser.getId());
|
||||
user.setUsername(currentUser.getUsername());
|
||||
user.setOperatorAddress(operatorAddress);
|
||||
user.setName((String) context.get("name"));
|
||||
user.setDepartment((String) context.get("department"));
|
||||
user.setEmail((String) context.get("email"));
|
||||
user.setPhone((String) context.get("phone"));
|
||||
user.setAlitalk((String) context.get("alitalk"));
|
||||
user.setLocale((String) context.get("locale"));
|
||||
userDAO.modifyUser(user);
|
||||
context.put("redirect", "../" + getClass().getSimpleName().toLowerCase());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.personal.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.governance.service.UserService;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Passwds extends Restful {
|
||||
|
||||
@Autowired
|
||||
private UserService userDAO;
|
||||
|
||||
public void index(Map<String, Object> context) {
|
||||
|
||||
}
|
||||
|
||||
public boolean create(Map<String, Object> context) {
|
||||
User user = new User();
|
||||
user.setOperator(operator);
|
||||
user.setOperatorAddress(operatorAddress);
|
||||
user.setPassword((String) context.get("newPassword"));
|
||||
user.setUsername(operator);
|
||||
|
||||
boolean sucess = userDAO.updatePassword(user, (String) context.get("oldPassword"));
|
||||
if (!sucess)
|
||||
context.put("message", getMessage("passwd.oldwrong"));
|
||||
return sucess;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,152 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.sysinfo.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.ConsumerService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
import com.alibaba.dubbo.registry.common.domain.Consumer;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Dump extends Restful {
|
||||
|
||||
@Autowired
|
||||
ProviderService providerDAO;
|
||||
|
||||
@Autowired
|
||||
ConsumerService consumerDAO;
|
||||
|
||||
@Autowired
|
||||
HttpServletResponse response;
|
||||
|
||||
public void noProviders(Map<String, Object> context) throws IOException {
|
||||
PrintWriter writer = response.getWriter();
|
||||
List<String> sortedService = getNoProviders();
|
||||
Collections.sort(sortedService);
|
||||
writer.println(sortedService.size() + " services don't have provider");
|
||||
for (String noProvider : sortedService) {
|
||||
writer.println(noProvider);
|
||||
}
|
||||
writer.flush();
|
||||
response.setContentType("text/plain");
|
||||
}
|
||||
|
||||
public void services(Map<String, Object> context) throws IOException {
|
||||
PrintWriter writer = response.getWriter();
|
||||
List<String> sortedService = providerDAO.findServices();
|
||||
Collections.sort(sortedService);
|
||||
writer.println(sortedService.size() + " services");
|
||||
for (String service : sortedService) {
|
||||
writer.println(service + (providerDAO.findByService(service).size()));
|
||||
}
|
||||
writer.flush();
|
||||
response.setContentType("text/plain");
|
||||
}
|
||||
|
||||
public void providers(Map<String, Object> context) throws IOException {
|
||||
PrintWriter writer = response.getWriter();
|
||||
List<Provider> providers = providerDAO.findAll();
|
||||
List<String> sortedProviders = new ArrayList<String>();
|
||||
for (Provider provider : providers) {
|
||||
sortedProviders.add(provider.getUrl() + " " + provider.getService());
|
||||
}
|
||||
Collections.sort(sortedProviders);
|
||||
writer.println(sortedProviders.size() + " provider instance");
|
||||
for (String provider : sortedProviders) {
|
||||
writer.println(provider);
|
||||
}
|
||||
writer.flush();
|
||||
response.setContentType("text/plain");
|
||||
}
|
||||
|
||||
public void consumers(Map<String, Object> context) throws IOException {
|
||||
PrintWriter writer = response.getWriter();
|
||||
List<Consumer> consumers = consumerDAO.findAll();
|
||||
List<String> sortedConsumerss = new ArrayList<String>();
|
||||
for (Consumer consumer : consumers) {
|
||||
sortedConsumerss.add(consumer.getAddress() + " " + consumer.getService());
|
||||
}
|
||||
Collections.sort(sortedConsumerss);
|
||||
writer.println(sortedConsumerss.size() + " consumer instance");
|
||||
for (String consumer : sortedConsumerss) {
|
||||
writer.println(consumer);
|
||||
}
|
||||
writer.flush();
|
||||
response.setContentType("text/plain");
|
||||
}
|
||||
|
||||
public void versions(Map<String, Object> context) throws IOException {
|
||||
PrintWriter writer = response.getWriter();
|
||||
List<Provider> providers = providerDAO.findAll();
|
||||
List<Consumer> consumers = consumerDAO.findAll();
|
||||
Set<String> parametersSet = new HashSet<String>();
|
||||
Map<String, Set<String>> versions = new HashMap<String, Set<String>>();
|
||||
for (Provider provider : providers) {
|
||||
parametersSet.add(provider.getParameters());
|
||||
}
|
||||
for (Consumer consumer : consumers) {
|
||||
parametersSet.add(consumer.getParameters());
|
||||
}
|
||||
Iterator<String> temp = parametersSet.iterator();
|
||||
while (temp.hasNext()) {
|
||||
Map<String, String> parameter = StringUtils.parseQueryString(temp.next());
|
||||
if (parameter != null) {
|
||||
String dubboversion = parameter.get("dubbo");
|
||||
String app = parameter.get("application");
|
||||
if (versions.get(dubboversion) == null) {
|
||||
Set<String> apps = new HashSet<String>();
|
||||
versions.put(dubboversion, apps);
|
||||
}
|
||||
versions.get(dubboversion).add(app);
|
||||
}
|
||||
}
|
||||
for (String version : versions.keySet()) {
|
||||
writer.println("dubbo version: " + version);
|
||||
writer.println(StringUtils.join(versions.get(version), "\n"));
|
||||
writer.println("\n");
|
||||
}
|
||||
context.put("versions", versions);
|
||||
writer.flush();
|
||||
response.setContentType("text/plain");
|
||||
}
|
||||
|
||||
private List<String> getNoProviders() {
|
||||
List<String> providerServices = providerDAO.findServices();
|
||||
List<String> consumerServices = consumerDAO.findServices();
|
||||
List<String> noProviderServices = new ArrayList<String>();
|
||||
if (consumerServices != null) {
|
||||
noProviderServices.addAll(consumerServices);
|
||||
noProviderServices.removeAll(providerServices);
|
||||
}
|
||||
return noProviderServices;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.sysinfo.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.governance.service.ConsumerService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Dumps extends Restful {
|
||||
|
||||
@Autowired
|
||||
ProviderService providerDAO;
|
||||
|
||||
@Autowired
|
||||
ConsumerService consumerDAO;
|
||||
|
||||
@Autowired
|
||||
HttpServletResponse response;
|
||||
|
||||
public void index(Map<String, Object> context) {
|
||||
context.put("noProviderServices", getNoProviders());
|
||||
context.put("services", providerDAO.findServices());
|
||||
context.put("providers", providerDAO.findAll());
|
||||
context.put("consumers", consumerDAO.findAll());
|
||||
}
|
||||
|
||||
private List<String> getNoProviders() {
|
||||
List<String> providerServices = providerDAO.findServices();
|
||||
List<String> consumerServices = consumerDAO.findServices();
|
||||
List<String> noProviderServices = new ArrayList<String>();
|
||||
if (consumerServices != null) {
|
||||
noProviderServices.addAll(consumerServices);
|
||||
noProviderServices.removeAll(providerServices);
|
||||
}
|
||||
return noProviderServices;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.sysinfo.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.Version;
|
||||
import com.alibaba.dubbo.common.utils.NetUtils;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Envs extends Restful {
|
||||
|
||||
private static final long SECOND = 1000;
|
||||
private static final long MINUTE = 60 * SECOND;
|
||||
private static final long HOUR = 60 * MINUTE;
|
||||
private static final long DAY = 24 * HOUR;
|
||||
|
||||
public void index(Map<String, Object> context) throws Exception {
|
||||
Map<String, String> properties = new TreeMap<String, String>();
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("Version: ");
|
||||
msg.append(Version.getVersion(Envs.class, "2.2.0"));
|
||||
properties.put("Registry", msg.toString());
|
||||
String address = NetUtils.getLocalHost();
|
||||
properties.put("Host", NetUtils.getHostName(address) + "/" + address);
|
||||
properties.put("Java", System.getProperty("java.runtime.name") + " " + System.getProperty("java.runtime.version"));
|
||||
properties.put("OS", System.getProperty("os.name") + " "
|
||||
+ System.getProperty("os.version"));
|
||||
properties.put("CPU", System.getProperty("os.arch", "") + ", "
|
||||
+ String.valueOf(Runtime.getRuntime().availableProcessors()) + " cores");
|
||||
properties.put("Locale", Locale.getDefault().toString() + "/"
|
||||
+ System.getProperty("file.encoding"));
|
||||
properties.put("Uptime", formatUptime(ManagementFactory.getRuntimeMXBean().getUptime())
|
||||
+ " From " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z").format(new Date(ManagementFactory.getRuntimeMXBean().getStartTime()))
|
||||
+ " To " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z").format(new Date()));
|
||||
context.put("properties", properties);
|
||||
}
|
||||
|
||||
private String formatUptime(long uptime) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
if (uptime > DAY) {
|
||||
long days = (uptime - uptime % DAY) / DAY;
|
||||
buf.append(days);
|
||||
buf.append(" Days");
|
||||
uptime = uptime % DAY;
|
||||
}
|
||||
if (uptime > HOUR) {
|
||||
long hours = (uptime - uptime % HOUR) / HOUR;
|
||||
if (buf.length() > 0) {
|
||||
buf.append(", ");
|
||||
}
|
||||
buf.append(hours);
|
||||
buf.append(" Hours");
|
||||
uptime = uptime % HOUR;
|
||||
}
|
||||
if (uptime > MINUTE) {
|
||||
long minutes = (uptime - uptime % MINUTE) / MINUTE;
|
||||
if (buf.length() > 0) {
|
||||
buf.append(", ");
|
||||
}
|
||||
buf.append(minutes);
|
||||
buf.append(" Minutes");
|
||||
uptime = uptime % MINUTE;
|
||||
}
|
||||
if (uptime > SECOND) {
|
||||
long seconds = (uptime - uptime % SECOND) / SECOND;
|
||||
if (buf.length() > 0) {
|
||||
buf.append(", ");
|
||||
}
|
||||
buf.append(seconds);
|
||||
buf.append(" Seconds");
|
||||
uptime = uptime % SECOND;
|
||||
}
|
||||
if (uptime > 0) {
|
||||
if (buf.length() > 0) {
|
||||
buf.append(", ");
|
||||
}
|
||||
buf.append(uptime);
|
||||
buf.append(" Milliseconds");
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.sysinfo.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.logger.Level;
|
||||
import com.alibaba.dubbo.common.logger.LoggerFactory;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class Logs extends Restful {
|
||||
|
||||
private static final int SHOW_LOG_LENGTH = 30000;
|
||||
|
||||
public void index(Map<String, Object> context) throws Exception {
|
||||
long size;
|
||||
String content;
|
||||
String modified;
|
||||
File file = LoggerFactory.getFile();
|
||||
if (file != null && file.exists()) {
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
FileChannel channel = fis.getChannel();
|
||||
size = channel.size();
|
||||
ByteBuffer bb;
|
||||
if (size <= SHOW_LOG_LENGTH) {
|
||||
bb = ByteBuffer.allocate((int) size);
|
||||
channel.read(bb, 0);
|
||||
} else {
|
||||
int pos = (int) (size - SHOW_LOG_LENGTH);
|
||||
bb = ByteBuffer.allocate(SHOW_LOG_LENGTH);
|
||||
channel.read(bb, pos);
|
||||
}
|
||||
bb.flip();
|
||||
content = new String(bb.array()).replace("<", "<").replace(">", ">");
|
||||
modified = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(file.lastModified()));
|
||||
} else {
|
||||
size = 0;
|
||||
content = "";
|
||||
modified = "Not exist";
|
||||
}
|
||||
Level level = LoggerFactory.getLevel();
|
||||
context.put("name", file == null ? "" : file.getAbsoluteFile());
|
||||
context.put("size", String.valueOf(size));
|
||||
context.put("level", level == null ? "" : level);
|
||||
context.put("modified", modified);
|
||||
context.put("content", content);
|
||||
}
|
||||
|
||||
public boolean change(Map<String, Object> context) throws Exception {
|
||||
String contextLevel = (String) context.get("level");
|
||||
if (contextLevel == null || contextLevel.length() == 0) {
|
||||
context.put("message", getMessage("MissRequestParameters", "level"));
|
||||
return false;
|
||||
}
|
||||
if (!User.ROOT.equals(role)) {
|
||||
context.put("message", getMessage("HaveNoRootPrivilege"));
|
||||
return false;
|
||||
}
|
||||
Level level = Level.valueOf(contextLevel);
|
||||
if (level != LoggerFactory.getLevel()) {
|
||||
LoggerFactory.setLevel(level);
|
||||
}
|
||||
context.put("redirect", "/sysinfo/logs");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.sysinfo.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.extension.ExtensionLoader;
|
||||
import com.alibaba.dubbo.common.status.StatusChecker;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
import com.alibaba.dubbo.registry.common.StatusManager;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Statuses extends Restful {
|
||||
public void index(Map<String, Object> context) throws Exception {
|
||||
ExtensionLoader<StatusChecker> loader = ExtensionLoader.getExtensionLoader(StatusChecker.class);
|
||||
Map<String, com.alibaba.dubbo.common.status.Status> statusList = new LinkedHashMap<String, com.alibaba.dubbo.common.status.Status>();
|
||||
for (String name : loader.getSupportedExtensions()) {
|
||||
com.alibaba.dubbo.common.status.Status status = loader.getExtension(name).check();
|
||||
if (status.getLevel() != null && status.getLevel() != com.alibaba.dubbo.common.status.Status.Level.UNKNOWN) {
|
||||
statusList.put(name, status);
|
||||
}
|
||||
}
|
||||
statusList.put("summary", StatusManager.getStatusSummary(statusList));
|
||||
context.put("statusList", statusList);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.sysinfo.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.ConsumerService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
import com.alibaba.dubbo.registry.common.domain.Consumer;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Versions extends Restful {
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
|
||||
@Autowired
|
||||
private ConsumerService consumerService;
|
||||
|
||||
public void index(Map<String, Object> context) {
|
||||
List<Provider> providers = providerService.findAll();
|
||||
List<Consumer> consumers = consumerService.findAll();
|
||||
Set<String> parametersSet = new HashSet<String>();
|
||||
for (Provider provider : providers) {
|
||||
parametersSet.add(provider.getParameters());
|
||||
}
|
||||
for (Consumer consumer : consumers) {
|
||||
parametersSet.add(consumer.getParameters());
|
||||
}
|
||||
Map<String, Set<String>> versions = new HashMap<String, Set<String>>();
|
||||
Iterator<String> temp = parametersSet.iterator();
|
||||
while (temp.hasNext()) {
|
||||
Map<String, String> parameter = StringUtils.parseQueryString(temp.next());
|
||||
if (parameter != null) {
|
||||
String dubbo = parameter.get("dubbo");
|
||||
if (dubbo == null) dubbo = "0.0.0";
|
||||
String application = parameter.get("application");
|
||||
if (versions.get(dubbo) == null) {
|
||||
Set<String> apps = new HashSet<String>();
|
||||
versions.put(dubbo, apps);
|
||||
}
|
||||
versions.get(dubbo).add(application);
|
||||
}
|
||||
}
|
||||
context.put("versions", versions);
|
||||
}
|
||||
|
||||
public void show(Long[] ids, Map<String, Object> context) {
|
||||
String version = (String) context.get("version");
|
||||
if (version != null && version.length() > 0) {
|
||||
List<Provider> providers = providerService.findAll();
|
||||
List<Consumer> consumers = consumerService.findAll();
|
||||
Set<String> parametersSet = new HashSet<String>();
|
||||
Set<String> applications = new HashSet<String>();
|
||||
for (Provider provider : providers) {
|
||||
parametersSet.add(provider.getParameters());
|
||||
}
|
||||
for (Consumer consumer : consumers) {
|
||||
parametersSet.add(consumer.getParameters());
|
||||
}
|
||||
Iterator<String> temp = parametersSet.iterator();
|
||||
while (temp.hasNext()) {
|
||||
Map<String, String> parameter = StringUtils.parseQueryString(temp.next());
|
||||
if (parameter != null) {
|
||||
String dubbo = parameter.get("dubbo");
|
||||
if (dubbo == null) dubbo = "0.0.0";
|
||||
String application = parameter.get("application");
|
||||
if (version.equals(dubbo)) {
|
||||
applications.add(application);
|
||||
}
|
||||
}
|
||||
}
|
||||
context.put("applications", applications);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.sysmanage.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.governance.service.ConfigService;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
import com.alibaba.dubbo.registry.common.domain.Config;
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Configs extends Restful {
|
||||
|
||||
@Autowired
|
||||
private ConfigService configDAO;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
public void index(Map<String, Object> context) {
|
||||
context.put("configs", configDAO.findAllConfigsMap());
|
||||
}
|
||||
|
||||
public boolean update(Map<String, Object> context) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String[]> all = request.getParameterMap();
|
||||
;
|
||||
if (all != null && all.size() > 0) {
|
||||
if (!User.ROOT.equals(currentUser.getRole())) {
|
||||
context.put("message", getMessage("HaveNoRootPrivilege"));
|
||||
return false;
|
||||
}
|
||||
List<Config> configs = new ArrayList<Config>();
|
||||
for (Map.Entry<String, String[]> entry : all.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String[] values = entry.getValue();
|
||||
if (key != null && key.length() > 0 && !key.startsWith("_")) {
|
||||
String value = "";
|
||||
if (values != null && values.length > 0
|
||||
&& values[0] != null && values[0].length() > 0) {
|
||||
value = values[0];
|
||||
}
|
||||
Config config = new Config();
|
||||
config.setKey(key);
|
||||
config.setUsername(currentUser.getUsername());
|
||||
config.setOperatorAddress((String) context.get("operatorAddress"));
|
||||
config.setValue(value);
|
||||
configs.add(config);
|
||||
}
|
||||
}
|
||||
if (configs.size() > 0) {
|
||||
configDAO.update(configs);
|
||||
|
||||
Set<String> usernames = new HashSet<String>();
|
||||
usernames.add(currentUser.getName());
|
||||
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("configs", configs);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
context.put("message", getMessage("MissRequestParameters", "configKey,configValue"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.sysmanage.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
|
||||
public class Privileges extends Restful {
|
||||
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.sysmanage.module.screen;
|
||||
|
||||
import com.alibaba.dubbo.governance.service.OwnerService;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Providers. URI: /services/$service/owners
|
||||
*
|
||||
*/
|
||||
public class Userown extends Restful {
|
||||
|
||||
@Autowired
|
||||
private OwnerService ownerDAO;
|
||||
|
||||
public void index(Map<String, Object> context) {
|
||||
String user = (String) context.get("user");
|
||||
List<String> services;
|
||||
services = ownerDAO.findServiceNamesByUsername(user);
|
||||
context.put("user", user);
|
||||
context.put("services", services);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,108 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.util;
|
||||
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
import com.alibaba.dubbo.common.logger.LoggerFactory;
|
||||
import com.alibaba.dubbo.common.status.StatusChecker;
|
||||
import com.alibaba.dubbo.registry.common.StatusManager;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
public class GovernanceWarmup implements InitializingBean {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GovernanceWarmup.class);
|
||||
|
||||
private StatusChecker memoryStatusChecker;
|
||||
|
||||
private StatusChecker threadPoolStatusChecker;
|
||||
|
||||
private StatusChecker cacheStatusChecker;
|
||||
|
||||
private StatusChecker databaseStatusChecker;
|
||||
|
||||
private StatusChecker failureStatusChecker;
|
||||
|
||||
private StatusChecker loadStatusChecker;
|
||||
|
||||
private StatusChecker SocketStatusChecker;
|
||||
|
||||
private StatusChecker timerStatusChecker;
|
||||
|
||||
private StatusChecker warmupStatusChecker;
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
logger.info("Registry Console warn up.");
|
||||
|
||||
StatusManager statusManager = StatusManager.getInstance();
|
||||
|
||||
statusManager.addStatusHandler("memory", memoryStatusChecker);
|
||||
statusManager.addStatusHandler("load", loadStatusChecker);
|
||||
// statusManager.addStatusHandler("database",databaseStatusChecker);
|
||||
// statusManager.addStatusHandler("cache",cacheStatusChecker);
|
||||
// statusManager.addStatusHandler("threadpool",threadPoolStatusChecker);
|
||||
// statusManager.addStatusHandler("failure",failureStatusChecker);
|
||||
// statusManager.addStatusHandler("socket",SocketStatusChecker);
|
||||
// statusManager.addStatusHandler("threadpool",threadPoolStatusChecker);
|
||||
// statusManager.addStatusHandler("timer",timerStatusChecker);
|
||||
// statusManager.addStatusHandler("warmup",warmupStatusChecker);
|
||||
}
|
||||
|
||||
public void setMemoryStatusChecker(StatusChecker memoryStatusChecker) {
|
||||
this.memoryStatusChecker = memoryStatusChecker;
|
||||
}
|
||||
|
||||
|
||||
public void setThreadPoolStatusChecker(StatusChecker threadPoolStatusChecker) {
|
||||
this.threadPoolStatusChecker = threadPoolStatusChecker;
|
||||
}
|
||||
|
||||
|
||||
public void setCacheStatusChecker(StatusChecker cacheStatusChecker) {
|
||||
this.cacheStatusChecker = cacheStatusChecker;
|
||||
}
|
||||
|
||||
|
||||
public void setDatabaseStatusChecker(StatusChecker databaseStatusChecker) {
|
||||
this.databaseStatusChecker = databaseStatusChecker;
|
||||
}
|
||||
|
||||
|
||||
public void setFailureStatusChecker(StatusChecker failureStatusChecker) {
|
||||
this.failureStatusChecker = failureStatusChecker;
|
||||
}
|
||||
|
||||
|
||||
public void setLoadStatusChecker(StatusChecker loadStatusChecker) {
|
||||
this.loadStatusChecker = loadStatusChecker;
|
||||
}
|
||||
|
||||
|
||||
public void setSocketStatusChecker(StatusChecker socketStatusChecker) {
|
||||
SocketStatusChecker = socketStatusChecker;
|
||||
}
|
||||
|
||||
|
||||
public void setTimerStatusChecker(StatusChecker timerStatusChecker) {
|
||||
this.timerStatusChecker = timerStatusChecker;
|
||||
}
|
||||
|
||||
public void setWarmupStatusChecker(StatusChecker warmupStatusChecker) {
|
||||
this.warmupStatusChecker = warmupStatusChecker;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,195 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* TODO Comment of Paginator
|
||||
*
|
||||
*/
|
||||
public class Paginator implements Serializable, Cloneable {
|
||||
|
||||
private static final long serialVersionUID = 3688506614705500726L;
|
||||
|
||||
// The default number of items per page; default is 10
|
||||
int itemsPerPage = 10;
|
||||
|
||||
// Sliding window default size; default: 7
|
||||
int sliderSize = 7;
|
||||
|
||||
// The current page.
|
||||
int currentPage;
|
||||
|
||||
// The current page.
|
||||
String path;
|
||||
|
||||
// total mumber of items
|
||||
int totalItems;
|
||||
|
||||
// total number of pages
|
||||
int totalPage;
|
||||
|
||||
/**
|
||||
* The most simple paging constructor.
|
||||
*
|
||||
* @param currentPage
|
||||
* @param totalItems
|
||||
* @param path
|
||||
*/
|
||||
public Paginator(int currentPage, int totalItems, String path) {
|
||||
initPagination(currentPage, totalItems, 0, 0, path);
|
||||
}
|
||||
|
||||
public Paginator(String currentPage, int totalItems, String path) {
|
||||
int currentPageTemp = 1;
|
||||
if (!(currentPage == null || currentPage.equals(""))) {
|
||||
currentPageTemp = Integer.parseInt(currentPage);
|
||||
}
|
||||
initPagination(currentPageTemp, totalItems, 0, 0, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete paging constructor.
|
||||
*
|
||||
* @param currentPageT
|
||||
* @param totalItemsT
|
||||
* @param sliderSizeT
|
||||
* @param itemsPerPageT
|
||||
* @param path
|
||||
*/
|
||||
public void initPagination(int currentPageT, int totalItemsT, int sliderSizeT, int itemsPerPageT, String path) {
|
||||
this.totalItems = (totalItemsT > 0) ? totalItemsT : 0;
|
||||
this.sliderSize = (sliderSizeT > 0) ? sliderSizeT : sliderSize;
|
||||
this.itemsPerPage = (itemsPerPageT > 0) ? itemsPerPageT : itemsPerPage;
|
||||
this.totalPage = totalItems / itemsPerPage + (totalItems % itemsPerPage == 0 ? 0 : 1);
|
||||
this.currentPage = (currentPageT > 0) ? currentPageT : 1;
|
||||
this.currentPage = currentPage < totalPage ? currentPage : totalPage;
|
||||
this.currentPage = (currentPage == 0) ? 1 : currentPage;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public int getItemsPerPage() {
|
||||
return this.itemsPerPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a sliding window of fixed size, and the current page should lie in the middle of the sliding window.
|
||||
* For example: a total of 13 pages, the current page is page 5, a size of 5 sliding window should consists of 3,4,5,6,7, page 5 is placed in the middle. If the current page is 12, the return page number should be 9, 10, 11, 12, 13.
|
||||
*
|
||||
* @return An array containing page numbers, or an empty array if the specified sliding window size is less than 1 or the total number of pages is zero.
|
||||
*/
|
||||
public int[] getSlider() {
|
||||
int width = sliderSize;
|
||||
if ((totalItems < 1)) {
|
||||
return new int[0];
|
||||
|
||||
} else {
|
||||
if (width > totalPage) {
|
||||
width = totalPage;
|
||||
}
|
||||
|
||||
int[] slider = new int[width];
|
||||
|
||||
int startPage = currentPage - ((width - 1) / 2);
|
||||
|
||||
if (startPage < 1) {
|
||||
startPage = 1;
|
||||
}
|
||||
|
||||
if (((startPage + width) - 1) > totalPage) {
|
||||
startPage = totalPage - width + 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < width; i++) {
|
||||
slider[i] = startPage + i;
|
||||
}
|
||||
return slider;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construction pagination toolbar
|
||||
*/
|
||||
public String getPaginatorBar() {
|
||||
|
||||
StringBuffer str = new StringBuffer("<div class=\"page\">");
|
||||
str.append("<script type=\"text/javascript\">function gotoPage(page){window.location.href=\"/" + path
|
||||
+ "/pages/\" + page;}</script>");
|
||||
|
||||
// generate flip section
|
||||
// The total number of records
|
||||
str.append("total items: " + this.totalItems + " ");
|
||||
|
||||
// 2. Pages: current page / total pages
|
||||
str.append("page " + this.currentPage + " of " + this.totalPage + "nbsp; ");
|
||||
|
||||
// 3. Home, Previous
|
||||
if (this.currentPage > 1) {
|
||||
str.append("<a class=\"prev\" href=\"#\" onclick=\"gotoPage(1);\">Home</a>");
|
||||
str.append("<a class=\"prev\" href=\"#\" onclick=\"gotoPage(" + (this.currentPage - 1) + ");\">Previous</a>");
|
||||
} else {
|
||||
str.append("<a class=\"prev\" href=\"#\">Home</a>");
|
||||
str.append("<a class=\"prev\" href=\"#\">Previous</a>");
|
||||
}
|
||||
|
||||
// 4. Activity block
|
||||
int[] slider = getSlider();
|
||||
for (int i = 0; i < slider.length; i++) {
|
||||
if (slider[i] == this.currentPage) {
|
||||
str.append("<a class=\"num current_num\" href=\"#\">");
|
||||
} else {
|
||||
str.append("<a class=\"num\" href=\"#\" onclick=\"gotoPage(" + slider[i] + ");\">");
|
||||
}
|
||||
str.append(slider[i] + "</a>");
|
||||
}
|
||||
|
||||
// 5. Next page
|
||||
if (this.currentPage < this.totalPage) {
|
||||
str.append("<a class=\"prev\" href=\"#\" onclick=\"gotoPage(" + (this.currentPage + 1) + ");\">");
|
||||
} else {
|
||||
str.append("<a class=\"prev\" href=\"#\">");
|
||||
}
|
||||
str.append("Next</a> ");
|
||||
|
||||
// 6. Jump section
|
||||
str.append("jump to page ");
|
||||
str.append("<SELECT size=1 onchange=\"gotoPage(this.value);\">");
|
||||
for (int i = 1; i < this.totalPage + 1; i++) {
|
||||
if (i == this.currentPage) {
|
||||
str.append("<OPTION value=" + i + " selected>" + i + "</OPTION>");
|
||||
} else {
|
||||
str.append("<OPTION value=" + i + ">" + i + "</OPTION>");
|
||||
}
|
||||
}
|
||||
str.append("</SELECT>");
|
||||
|
||||
// 7. Implicit conditions
|
||||
str.append("</div>");
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the initial record
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getStartIndex() {
|
||||
return (this.currentPage - 1) * this.itemsPerPage + 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* UrlUtils.java
|
||||
*
|
||||
*/
|
||||
public class UrlUtils {
|
||||
|
||||
public static String paramsMapToString(Map<String, String[]> params) {
|
||||
StringBuilder paramsString = new StringBuilder();
|
||||
for (Entry<String, String[]> param : params.entrySet()) {
|
||||
if (paramsString != null) {
|
||||
paramsString.append("&");
|
||||
}
|
||||
paramsString.append(param.getKey());
|
||||
paramsString.append("=");
|
||||
for (int i = 0; i < param.getValue().length; i++) {
|
||||
if (i == 0) {
|
||||
paramsString.append(param.getValue()[i]);
|
||||
} else {
|
||||
paramsString.append(",");
|
||||
paramsString.append(param.getValue()[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return paramsString.toString();
|
||||
}
|
||||
|
||||
public static String arrayToString(String[] values) {
|
||||
StringBuilder paramsString = new StringBuilder();
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
if (i == 0) {
|
||||
paramsString.append(values[i]);
|
||||
} else {
|
||||
paramsString.append(",");
|
||||
paramsString.append(values[i]);
|
||||
}
|
||||
}
|
||||
return paramsString.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.util;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Contains the constants used in the web layer
|
||||
*
|
||||
*/
|
||||
public class WebConstants {
|
||||
|
||||
/**
|
||||
* In the session to save the current user object's key.
|
||||
*/
|
||||
public static final String CURRENT_USER_KEY = "currentUser";
|
||||
/**
|
||||
* The current registered server address
|
||||
*/
|
||||
public static final String REGISTRY_ADDRESS = "registryAddress";
|
||||
/**
|
||||
* Service exposed address
|
||||
*/
|
||||
public static final String SERVICE_URL = "serviceUrl";
|
||||
/**
|
||||
* Service name
|
||||
*/
|
||||
public static final String SERVICE_NAME = "serviceName";
|
||||
/**
|
||||
* Service name
|
||||
*/
|
||||
public static final String ENTRY = "entry";
|
||||
/**
|
||||
* buc sso logout
|
||||
*/
|
||||
public static final String SSO_LOGOUT_URL = "SSO_LOGOUT_URL";
|
||||
/**
|
||||
* buc sso logon
|
||||
*/
|
||||
public static final String BUC_SSO_USERNAME = "buc_sso_username";
|
||||
/**
|
||||
* Operation record page The default page record shows the number of records
|
||||
*/
|
||||
public static final Integer OPRATION_RECORDS_PAGE_SIZE = 100;
|
||||
Map<String, Object> context;
|
||||
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.registry.common;
|
||||
|
||||
public interface ChangeListener {
|
||||
|
||||
/**
|
||||
* Invoked when data changed
|
||||
*
|
||||
* @param type data type
|
||||
*/
|
||||
void onChanged(String type);
|
||||
|
||||
}
|
||||
|
|
@ -1,122 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.registry.common;
|
||||
|
||||
import com.alibaba.dubbo.common.status.Status;
|
||||
import com.alibaba.dubbo.common.status.Status.Level;
|
||||
import com.alibaba.dubbo.common.status.StatusChecker;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* StatusManager
|
||||
*
|
||||
*/
|
||||
public class StatusManager {
|
||||
|
||||
private static final StatusManager INSTANCE = new StatusManager();
|
||||
private final Map<String, StatusChecker> statusHandlers = new ConcurrentHashMap<String, StatusChecker>();
|
||||
|
||||
private StatusManager() {
|
||||
}
|
||||
|
||||
public static StatusManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static Status getStatusSummary(Map<String, Status> statusList) {
|
||||
return getSummaryStatus(statusList);
|
||||
}
|
||||
|
||||
public static Status getSummaryStatus(Map<String, Status> statuses) {
|
||||
Level level = Level.OK;
|
||||
StringBuilder msg = new StringBuilder();
|
||||
for (Map.Entry<String, Status> entry : statuses.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Status status = entry.getValue();
|
||||
Level l = status.getLevel();
|
||||
if (Level.ERROR.equals(l)) {
|
||||
level = Level.ERROR;
|
||||
if (msg.length() > 0) {
|
||||
msg.append(",");
|
||||
}
|
||||
msg.append(key);
|
||||
} else if (Level.WARN.equals(l)) {
|
||||
if (!Level.ERROR.equals(level)) {
|
||||
level = Level.WARN;
|
||||
}
|
||||
if (msg.length() > 0) {
|
||||
msg.append(",");
|
||||
}
|
||||
msg.append(key);
|
||||
}
|
||||
}
|
||||
return new Status(level, msg.toString());
|
||||
}
|
||||
|
||||
public void addStatusHandler(String name, StatusChecker statusHandler) {
|
||||
this.statusHandlers.put(name, statusHandler);
|
||||
}
|
||||
|
||||
public void addStatusHandlers(Map<String, StatusChecker> statusHandlers) {
|
||||
this.statusHandlers.putAll(statusHandlers);
|
||||
}
|
||||
|
||||
public void addStatusHandlers(Collection<StatusChecker> statusHandlers) {
|
||||
for (StatusChecker statusChecker : statusHandlers) {
|
||||
String name = statusChecker.getClass().getSimpleName();
|
||||
if (name.endsWith(StatusChecker.class.getSimpleName())) {
|
||||
name = name.substring(0, name.length() - StatusChecker.class.getSimpleName().length());
|
||||
}
|
||||
this.statusHandlers.put(name, statusChecker);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeStatusHandler(String name) {
|
||||
this.statusHandlers.remove(name);
|
||||
}
|
||||
|
||||
public void clearStatusHandlers() {
|
||||
this.statusHandlers.clear();
|
||||
}
|
||||
|
||||
public Map<String, Status> getStatusList() {
|
||||
return getStatusList(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude items do not need to show in Summary Page
|
||||
*/
|
||||
public Map<String, Status> getStatusList(String[] excludes) {
|
||||
Map<String, Status> statuses = new HashMap<String, Status>();
|
||||
Map<String, StatusChecker> temp = new HashMap<String, StatusChecker>();
|
||||
temp.putAll(statusHandlers);
|
||||
if (excludes != null && excludes.length > 0) {
|
||||
for (String exclude : excludes) {
|
||||
temp.remove(exclude);
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, StatusChecker> entry : temp.entrySet()) {
|
||||
statuses.put(entry.getKey(), entry.getValue().check());
|
||||
}
|
||||
return statuses;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.registry.common.domain;
|
||||
|
||||
public class Access extends Entity {
|
||||
|
||||
private static final long serialVersionUID = -962351722638094446L;
|
||||
|
||||
private String service; /*service name*/
|
||||
|
||||
private String address; /*address of consumer*/
|
||||
|
||||
private boolean allow; /*status*/
|
||||
|
||||
private String username; /*user name*/
|
||||
|
||||
public Access() {
|
||||
}
|
||||
|
||||
public Access(Long id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public String getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
public void setService(String service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public boolean isAllow() {
|
||||
return allow;
|
||||
}
|
||||
|
||||
public void setAllow(boolean allow) {
|
||||
this.allow = allow;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.registry.common.domain;
|
||||
|
||||
/**
|
||||
* Specifies the applied Quality of Service Level Agreement (SLA) object.
|
||||
*
|
||||
*/
|
||||
public class Agreement extends Entity {
|
||||
|
||||
private static final long serialVersionUID = -4888604682731513790L;
|
||||
|
||||
private String service; // service name
|
||||
|
||||
private String consumerApplication; // application of consumer
|
||||
|
||||
private long invocationQuantity; // call of the day
|
||||
|
||||
private int tps; // TPS limit
|
||||
|
||||
private int responseTime; // Response time in milliseconds
|
||||
|
||||
private double availability; // ratio of available
|
||||
|
||||
private String username;
|
||||
|
||||
public Agreement() {
|
||||
}
|
||||
|
||||
public Agreement(Long id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public String getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
public void setService(String service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public String getConsumerApplication() {
|
||||
return consumerApplication;
|
||||
}
|
||||
|
||||
public void setConsumerApplication(String consumerApplication) {
|
||||
this.consumerApplication = consumerApplication;
|
||||
}
|
||||
|
||||
public long getInvocationQuantity() {
|
||||
return invocationQuantity;
|
||||
}
|
||||
|
||||
public void setInvocationQuantity(long invocationQuantity) {
|
||||
this.invocationQuantity = invocationQuantity;
|
||||
}
|
||||
|
||||
public int getTps() {
|
||||
return tps;
|
||||
}
|
||||
|
||||
public void setTps(int tps) {
|
||||
this.tps = tps;
|
||||
}
|
||||
|
||||
public int getResponseTime() {
|
||||
return responseTime;
|
||||
}
|
||||
|
||||
public void setResponseTime(int responseTime) {
|
||||
this.responseTime = responseTime;
|
||||
}
|
||||
|
||||
public double getAvailability() {
|
||||
return availability;
|
||||
}
|
||||
|
||||
public void setAvailability(double availability) {
|
||||
this.availability = availability;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.registry.common.domain;
|
||||
|
||||
/**
|
||||
* Service online approval.
|
||||
*
|
||||
*/
|
||||
public class Approval extends Entity {
|
||||
private static final long serialVersionUID = -8778092807313048367L;
|
||||
|
||||
private String service; // service name
|
||||
|
||||
private String version;
|
||||
// You can use wildcards, *,1.1.*
|
||||
// Can contain more than one, 1.1.3,1.1.5,2.*
|
||||
|
||||
private boolean forProvider; // Provider or consumer
|
||||
|
||||
private String machineList; // service machine
|
||||
// You can use wildcards, 172.3.8.*
|
||||
// an contain more than one, 172.1.9.8,172.1.9.123,172.3.3.*
|
||||
|
||||
private String username;
|
||||
|
||||
private String approveUser; // approver
|
||||
|
||||
public String getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
public void setService(String service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public boolean isForProvider() {
|
||||
return forProvider;
|
||||
}
|
||||
|
||||
public void setForProvider(boolean forProvider) {
|
||||
this.forProvider = forProvider;
|
||||
}
|
||||
|
||||
public String getMachineList() {
|
||||
return machineList;
|
||||
}
|
||||
|
||||
public void setMachineList(String machineList) {
|
||||
this.machineList = machineList;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getApproveUser() {
|
||||
return approveUser;
|
||||
}
|
||||
|
||||
public void setApproveUser(String approveUser) {
|
||||
this.approveUser = approveUser;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.registry.common.domain;
|
||||
|
||||
/**
|
||||
* Service online / offline approval
|
||||
*
|
||||
*/
|
||||
public class ApprovalRequisition extends Entity {
|
||||
private static final long serialVersionUID = -8778092807313048367L;
|
||||
|
||||
private char operation; // Apply for action: add (C), modify (U), delete (D)
|
||||
|
||||
private Long approvalId;
|
||||
|
||||
private String service; // service name
|
||||
|
||||
private String version;
|
||||
// wildcards, *,1.1.*
|
||||
// more than one, 1.1.3,1.1.5,2.*
|
||||
|
||||
private boolean forProvider;
|
||||
|
||||
private String machineList; // servcice machine
|
||||
// wildcards, 172.3.8.*
|
||||
// more thaan one, 172.1.9.8,172.1.9.123,172.3.3.*
|
||||
|
||||
private String username;
|
||||
|
||||
public char getOperation() {
|
||||
return operation;
|
||||
}
|
||||
|
||||
public void setOperation(char operation) {
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
public Long getApprovalId() {
|
||||
return approvalId;
|
||||
}
|
||||
|
||||
public void setApprovalId(Long approvalId) {
|
||||
this.approvalId = approvalId;
|
||||
}
|
||||
|
||||
public String getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
public void setService(String service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public boolean isForProvider() {
|
||||
return forProvider;
|
||||
}
|
||||
|
||||
public void setForProvider(boolean forProvider) {
|
||||
this.forProvider = forProvider;
|
||||
}
|
||||
|
||||
public String getMachineList() {
|
||||
return machineList;
|
||||
}
|
||||
|
||||
public void setMachineList(String machineList) {
|
||||
this.machineList = machineList;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.registry.common.domain;
|
||||
|
||||
/**
|
||||
* Service change information object
|
||||
*
|
||||
*/
|
||||
public class Change extends Entity {
|
||||
|
||||
public static final String PROVIDER_TYPE = "P"; //provider change
|
||||
public static final String CONSUMER_TYPE = "N"; //consumer change
|
||||
public static final String ROUTE_TYPE = "R"; //route change
|
||||
public static final String WEIGHT_TYPE = "W"; //weight change
|
||||
public static final String LOADBALANCE_TYPE = "L"; //loadbalance change
|
||||
public static final String CLUSTER_TYPE = "G"; //group change
|
||||
public static final String USER_TYPE = "U"; //user change
|
||||
public static final String CONFIG_TYPE = "C"; //system config change
|
||||
public static final String FEATURE_TYPE = "F"; //feature change
|
||||
public static final String LAYER_TYPE = "Y"; //layer change
|
||||
public static final String TEST_TYPE = "T"; //service test change
|
||||
public static final String MOCK_TYPE = "M"; //service mock change
|
||||
public static final String ACCESS_TYPE = "A"; //access change
|
||||
public static final String OVERRIDE_TYPE = "O"; //override change
|
||||
private static final long serialVersionUID = 15528419903956898L;
|
||||
private String type; /* type of change */
|
||||
|
||||
private String service; /* service name */
|
||||
|
||||
private long sequence; /* NO. of change */
|
||||
|
||||
private String data; /* what is changed */
|
||||
|
||||
public Change() {
|
||||
}
|
||||
|
||||
public Change(Long id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public Change(String type, String serviceName) {
|
||||
this.type = type;
|
||||
this.service = serviceName;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
public void setService(String service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* us id as sequence
|
||||
*/
|
||||
public long getSequence() {
|
||||
return sequence;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* use id as sequence
|
||||
*/
|
||||
public void setSequence(long sequence) {
|
||||
this.sequence = sequence;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.registry.common.domain;
|
||||
|
||||
public class Cluster extends Entity {
|
||||
|
||||
private static final long serialVersionUID = 8704571999015097948L;
|
||||
|
||||
private String name; /* Service provider group name, a group can contain several providers*/
|
||||
|
||||
private String address; /* address of consumer */
|
||||
|
||||
private String username;
|
||||
|
||||
public Cluster() {
|
||||
}
|
||||
|
||||
public Cluster(Long id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.registry.common.domain;
|
||||
|
||||
/**
|
||||
* Config instance
|
||||
*
|
||||
*/
|
||||
public class Config extends Entity {
|
||||
|
||||
public static final String MAIL_ENABLED = "MailEnabled";
|
||||
public static final String MAIL_HOST = "MailHost";
|
||||
public static final String MAIL_PORT = "MailPort";
|
||||
public static final String MAIL_FROM = "MailFrom";
|
||||
public static final String MAIL_AUTH = "MailAuth";
|
||||
public static final String MAIL_USERNAME = "MailUsername";
|
||||
public static final String MAIL_PASSWORD = "MailPassword";
|
||||
public static final String BULLETIN_MESSAGE = "BulletinMessage";
|
||||
public static final String ALLOW_ANONYMOUS_LOGIN = "AllowAnonymousLogin"; // Whether to allow anonymous login
|
||||
public static final String ALLOW_LEGACY_LOGIN = "AllowLegacyLogin"; // Whether to allow legacy system login
|
||||
public static final String MAX_THREAD_SIZE = "MaxThreadSize"; // The maximum number of threads
|
||||
public static final String MAX_CONNECTION_SIZE = "MaxConnectionSize"; // The maximum number of connections
|
||||
public static final String MAX_CACHE_SIZE = "MaxCacheSize"; // The maximum number of cache (not space)
|
||||
public static final String MAX_MAIL_SIZE = "MaxMailSize"; // The maximum number of mail queues
|
||||
public static final String ALIVED_CHECK_INTERVAL = "AlivedCheckInterval";
|
||||
public static final String DIRTY_CHECK_INTERVAL = "DirtyCheckInterval";
|
||||
public static final String CHANGED_CHECK_INTERVAL = "ChangedCheckInterval";
|
||||
public static final String CHANGED_CLEAR_INTERVAL = "ChangedClearInterval";
|
||||
public static final String FAILED_RETRY_INTERVAL = "FailedRetryInterval";
|
||||
public static final String HEARTBEAT_CHECK_INTERVAL = "HeartbeatCheckInterval";// Heartbeat check interval
|
||||
public static final String HEARTBEAT_CHECK_TIMEOUT = "HeartbeatCheckTimeout";// The biggest interval for not receive a heartbeat
|
||||
public static final String WARMUP_WAIT_TIME = "WarmupWaitTime";
|
||||
public static final String AUTO_REDIRECT_INTERVAL = "AutoRedirectInterval";
|
||||
public static final String AUTO_REDIRECT_THRESHOLD = "AutoRedirectThreshold";
|
||||
public static final String AUTO_REDIRECT_TOLERATE_PERCENT = "AutoRedirectToleratePercent";
|
||||
public static final String NOTIFY_TIMEOUT = "NotifyTimeout";
|
||||
public static final String ROUTE_ENABLED = "RouteEnabled";
|
||||
public static final String BUC_SERVICE_ADDRESS = "BucServiceAddress";
|
||||
public static final String DEFAULT_SERVICE_PARAMETERS = "DefaultServiceParameters";
|
||||
public static final String WARM_UP_ENABLED = "WarmupEnabled";
|
||||
public static final String HELP_DOCUMENT_URL = "HelpDocumentUrl";
|
||||
public static final String HOMEPAGE_DOMAIN = "HomepageDomain";
|
||||
public static final String HOMEPAGE_URL = "HomepageUrl";
|
||||
public static final String LOG_LEVEL = "LogLevel";
|
||||
public static final String DEFAULT_ROLE = "DefaultRole"; // The default role of user
|
||||
public static final String SERVER_ROUTE_ENABLED = "ServerRouteEnabled";
|
||||
private static final long serialVersionUID = 7938303018328907548L;
|
||||
private String key;
|
||||
|
||||
private String value;
|
||||
|
||||
private String username;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public String toString() {
|
||||
return key + "=" + value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,229 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.registry.common.domain;
|
||||
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Consumer
|
||||
*
|
||||
*/
|
||||
public class Consumer extends Entity {
|
||||
|
||||
private static final long serialVersionUID = -1140894843784583237L;
|
||||
|
||||
private String service; /* The name of the service referenced by the consumer */
|
||||
|
||||
private String parameters;
|
||||
|
||||
private String result; /*route result*/
|
||||
|
||||
private String address; /* address of consumer */
|
||||
|
||||
private String registry; /* Consumer connected registry address */
|
||||
|
||||
private String application; /* application name */
|
||||
|
||||
private String username; /* user name of consumer */
|
||||
|
||||
private String statistics; /* Service call statistics */
|
||||
|
||||
private Date collected; /* Date statistics was recorded */
|
||||
|
||||
private Override override;
|
||||
|
||||
private List<Override> overrides;
|
||||
|
||||
private List<Route> routes;
|
||||
|
||||
private List<Provider> providers;
|
||||
|
||||
private Date expired;
|
||||
|
||||
private long alived; /*Time to live in milliseconds*/
|
||||
|
||||
public Consumer() {
|
||||
}
|
||||
|
||||
public Consumer(Long id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public String getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
public void setService(String service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public String getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void setParameters(String parameters) {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getRegistry() {
|
||||
return registry;
|
||||
}
|
||||
|
||||
public void setRegistry(String registry) {
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getStatistics() {
|
||||
return statistics;
|
||||
}
|
||||
|
||||
public void setStatistics(String statistics) {
|
||||
this.statistics = statistics;
|
||||
}
|
||||
|
||||
public Date getCollected() {
|
||||
return collected;
|
||||
}
|
||||
|
||||
public void setCollected(Date collected) {
|
||||
this.collected = collected;
|
||||
}
|
||||
|
||||
public String getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(String result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public String getApplication() {
|
||||
return application;
|
||||
}
|
||||
|
||||
public void setApplication(String application) {
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public Date getExpired() {
|
||||
return expired;
|
||||
}
|
||||
|
||||
|
||||
public void setExpired(Date expired) {
|
||||
this.expired = expired;
|
||||
}
|
||||
|
||||
|
||||
public long getAlived() {
|
||||
return alived;
|
||||
}
|
||||
|
||||
|
||||
public void setAlived(long alived) {
|
||||
this.alived = alived;
|
||||
}
|
||||
|
||||
public Override getOverride() {
|
||||
return override;
|
||||
}
|
||||
|
||||
public void setOverride(Override override) {
|
||||
this.override = override;
|
||||
}
|
||||
|
||||
public List<Override> getOverrides() {
|
||||
return overrides;
|
||||
}
|
||||
|
||||
public void setOverrides(List<Override> overrides) {
|
||||
this.overrides = overrides;
|
||||
}
|
||||
|
||||
public List<Route> getRoutes() {
|
||||
return routes;
|
||||
}
|
||||
|
||||
public void setRoutes(List<Route> routes) {
|
||||
this.routes = routes;
|
||||
}
|
||||
|
||||
public List<Provider> getProviders() {
|
||||
return providers;
|
||||
}
|
||||
|
||||
public void setProviders(List<Provider> providers) {
|
||||
this.providers = providers;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Consumer [service=" + service + ", parameters=" + parameters + ", result=" + result
|
||||
+ ", address=" + address + ", registry=" + registry + ", application="
|
||||
+ application + ", username=" + username + ", statistics=" + statistics
|
||||
+ ", collected=" + collected + ", routes=" + routes + ", overrides=" + overrides
|
||||
+ ", expired=" + expired + ", alived=" + alived + "]";
|
||||
}
|
||||
|
||||
public URL toUrl() {
|
||||
String group = null;
|
||||
String version = null;
|
||||
String path = service;
|
||||
int i = path.indexOf("/");
|
||||
if (i > 0) {
|
||||
group = path.substring(0, i);
|
||||
path = path.substring(i + 1);
|
||||
}
|
||||
i = path.lastIndexOf(":");
|
||||
if (i > 0) {
|
||||
version = path.substring(i + 1);
|
||||
path = path.substring(0, i);
|
||||
}
|
||||
Map<String, String> param = StringUtils.parseQueryString(parameters);
|
||||
param.put(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY);
|
||||
if (group != null) {
|
||||
param.put(Constants.GROUP_KEY, group);
|
||||
}
|
||||
if (version != null) {
|
||||
param.put(Constants.VERSION_KEY, version);
|
||||
}
|
||||
return URL.valueOf(Constants.CONSUMER_PROTOCOL + "://" + address + "/" + path
|
||||
+ "?" + StringUtils.toQueryString(param));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.registry.common.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* DependItem
|
||||
*
|
||||
*/
|
||||
public class DependItem {
|
||||
|
||||
private final List<Integer> recursives = new ArrayList<Integer>();
|
||||
private String application;
|
||||
private int index;
|
||||
private int level;
|
||||
private DependItem parent;
|
||||
|
||||
public DependItem() {
|
||||
}
|
||||
|
||||
public DependItem(String application, int level) {
|
||||
this.application = application;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public DependItem(DependItem parent, String application, int level, int index) {
|
||||
this.parent = parent;
|
||||
this.application = application;
|
||||
this.level = level;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public String getApplication() {
|
||||
return application;
|
||||
}
|
||||
|
||||
public void setApplication(String application) {
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public DependItem getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(DependItem parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public List<Integer> getRecursives() {
|
||||
return recursives;
|
||||
}
|
||||
|
||||
public void addRecursive(int padding, int value) {
|
||||
while (recursives.size() < padding) {
|
||||
recursives.add(0);
|
||||
}
|
||||
recursives.add(value);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "DependItem [application=" + application + ", index=" + index + ", level=" + level
|
||||
+ "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.registry.common.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Dependency implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 8526869025719540547L;
|
||||
|
||||
private String providerApplication;
|
||||
|
||||
private String consumerApplication;
|
||||
|
||||
public String getProviderApplication() {
|
||||
return providerApplication;
|
||||
}
|
||||
|
||||
public void setProviderApplication(String providerApplication) {
|
||||
this.providerApplication = providerApplication;
|
||||
}
|
||||
|
||||
public String getConsumerApplication() {
|
||||
return consumerApplication;
|
||||
}
|
||||
|
||||
public void setConsumerApplication(String consumerApplication) {
|
||||
this.consumerApplication = consumerApplication;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.registry.common.domain;
|
||||
|
||||
/**
|
||||
* Document
|
||||
*
|
||||
*/
|
||||
public class Document extends Entity {
|
||||
|
||||
public static final String EXTERNAL_TYPE = "E";
|
||||
public static final String INTERNAL_TYPE = "I";
|
||||
public static final String API_TYPE = "A";
|
||||
private static final long serialVersionUID = 5059135057592486874L;
|
||||
private String service;
|
||||
|
||||
private String title;
|
||||
|
||||
private String type;
|
||||
|
||||
private String content;
|
||||
|
||||
private String username;
|
||||
|
||||
public Document() {
|
||||
}
|
||||
|
||||
public Document(Long id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
public void setService(String service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue