Reformat code
This commit is contained in:
parent
5e5b9e670d
commit
17619dfa97
|
|
@ -13,141 +13,141 @@
|
|||
- See the License for the specific language governing permissions and
|
||||
- limitations under the License.
|
||||
-->
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-parent</artifactId>
|
||||
<version>2.5.4-SNAPSHOT</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>
|
||||
<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.github.sgroschupf</groupId>
|
||||
<artifactId>zkclient</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.netflix.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>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>
|
||||
</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 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.5.4-SNAPSHOT</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>
|
||||
<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.github.sgroschupf</groupId>
|
||||
<artifactId>zkclient</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.netflix.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>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>
|
||||
</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,11 +1,11 @@
|
|||
/**
|
||||
* Project: dubbo.registry-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-5-26
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2010 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -14,25 +14,25 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Context
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
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();
|
||||
|
|
@ -40,11 +40,11 @@ public interface PageContext {
|
|||
public String getOperateAddress();
|
||||
|
||||
public String getRegistryAddress();
|
||||
|
||||
|
||||
public String getURI();
|
||||
|
||||
|
||||
public String getURL();
|
||||
|
||||
|
||||
public String getReferer();
|
||||
|
||||
public User getLoginUser();
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
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;
|
||||
|
||||
import com.alibaba.dubbo.governance.biz.common.i18n.MessageResourceService;
|
||||
import com.alibaba.dubbo.governance.web.common.i18n.LocaleUtil;
|
||||
|
||||
public class MessageResourceServiceImpl implements MessageResourceService {
|
||||
|
||||
@Autowired
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.server-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-6-30
|
||||
* $Id: ConfigService.java 181723 2012-06-26 01:56:06Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,21 +15,21 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.service;
|
||||
|
||||
import com.alibaba.dubbo.registry.common.domain.Config;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.dubbo.registry.common.domain.Config;
|
||||
|
||||
/**
|
||||
* TODO Comment of ConfigDAO
|
||||
*
|
||||
*
|
||||
* @author rain.chenjr
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface ConfigService {
|
||||
|
||||
void update(List<Config> configs);
|
||||
void update(List<Config> configs);
|
||||
|
||||
Map<String, String> findAllConfigsMap();
|
||||
Map<String, String> findAllConfigsMap();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-4-15
|
||||
* $Id: ConsumerService.java 182013 2012-06-26 10:32:43Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,13 +15,13 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.dubbo.registry.common.domain.Consumer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 消费者数据访问对象
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public interface ConsumerService {
|
||||
|
|
@ -29,30 +29,30 @@ public interface ConsumerService {
|
|||
List<Consumer> findByService(String serviceName);
|
||||
|
||||
Consumer findConsumer(Long id);
|
||||
|
||||
|
||||
List<Consumer> findAll();
|
||||
|
||||
/**
|
||||
* 查询所有的消费者地址
|
||||
*/
|
||||
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();
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -15,37 +15,37 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.dubbo.registry.common.domain.Override;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tony.chenl
|
||||
*/
|
||||
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,25 +1,25 @@
|
|||
package com.alibaba.dubbo.governance.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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> 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);
|
||||
|
||||
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,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-4-15
|
||||
* $Id: ProviderService.java 182143 2012-06-27 03:25:50Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,41 +15,41 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ProviderService
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
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);
|
||||
|
|
@ -61,13 +61,13 @@ public interface ProviderService {
|
|||
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);
|
||||
|
||||
|
||||
Provider findByServiceAndAddress(String service, String address);
|
||||
|
||||
}
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-4-15
|
||||
* $Id: RouteService.java 182337 2012-06-27 09:04:15Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,43 +15,43 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.dubbo.registry.common.domain.Route;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* RouteService
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
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,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-4-15
|
||||
* $Id: UserService.java 182013 2012-06-26 10:32:43Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,35 +15,35 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* UserService
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
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,11 +1,11 @@
|
|||
/**
|
||||
* Project: dubbo.registry.server-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-6-28
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2010 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -14,35 +14,33 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.service.impl;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class AbstractService {
|
||||
|
||||
protected static final Logger logger = LoggerFactory.getLogger(AbstractService.class);
|
||||
|
||||
@Autowired
|
||||
private RegistryServerSync sync;
|
||||
|
||||
@Autowired
|
||||
protected RegistryService registryService;
|
||||
|
||||
public ConcurrentMap<String, ConcurrentMap<String, Map<Long, URL>>> getRegistryCache(){
|
||||
@Autowired
|
||||
private RegistryServerSync sync;
|
||||
|
||||
public ConcurrentMap<String, ConcurrentMap<String, Map<Long, URL>>> getRegistryCache() {
|
||||
return sync.getRegistryCache();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.server-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-6-30
|
||||
* $Id: ConfigServiceImpl.java 181735 2012-06-26 02:31:34Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,25 +15,25 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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
|
||||
* @author rain.chenjr
|
||||
*
|
||||
*/
|
||||
public class ConfigServiceImpl extends AbstractService implements ConfigService{
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-4-15
|
||||
* $Id: ConsumerServiceImpl.java 184666 2012-07-05 11:13:17Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,12 +15,6 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.governance.service.ConsumerService;
|
||||
|
|
@ -28,8 +22,14 @@ 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;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class ConsumerServiceImpl extends AbstractService implements ConsumerService {
|
||||
|
|
@ -41,7 +41,7 @@ public class ConsumerServiceImpl extends AbstractService implements ConsumerServ
|
|||
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);
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ public class ConsumerServiceImpl extends AbstractService implements ConsumerServ
|
|||
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);
|
||||
|
|
@ -59,51 +59,51 @@ public class ConsumerServiceImpl extends AbstractService implements ConsumerServ
|
|||
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()) {
|
||||
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()) {
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
String app = u.getAddress();
|
||||
if(app != null) ret.add(app);
|
||||
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);
|
||||
for(Map.Entry<String, Map<Long, URL>> e1 : consumerUrls.entrySet()) {
|
||||
for (Map.Entry<String, Map<Long, URL>> e1 : consumerUrls.entrySet()) {
|
||||
Map<Long, URL> value = e1.getValue();
|
||||
for(Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
if(application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
|
||||
if (application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
|
||||
String addr = u.getAddress();
|
||||
if(addr != null) ret.add(addr);
|
||||
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()) {
|
||||
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);
|
||||
if (app != null) ret.add(app);
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public List<Consumer> findByAddress(String consumerAddress) {
|
||||
return SyncUtils.url2ConsumerList(findConsumerUrlByAddress(consumerAddress));
|
||||
}
|
||||
|
|
@ -111,19 +111,19 @@ public class ConsumerServiceImpl extends AbstractService implements ConsumerServ
|
|||
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()) {
|
||||
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()) {
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
if(address.equals(u.getAddress())) {
|
||||
if (address.equals(u.getAddress())) {
|
||||
ret.add(e1.getKey());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -131,89 +131,89 @@ public class ConsumerServiceImpl extends AbstractService implements ConsumerServ
|
|||
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()) {
|
||||
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()) {
|
||||
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);
|
||||
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;
|
||||
|
||||
if (consumerUrls == null) return ret;
|
||||
|
||||
Map<Long, URL> value = consumerUrls.get(service);
|
||||
if(value == null){
|
||||
return ret;
|
||||
if (value == null) {
|
||||
return ret;
|
||||
}
|
||||
for(Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
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);
|
||||
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()) {
|
||||
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()) {
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
if(application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
|
||||
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());
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,10 +15,6 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.service.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.governance.service.OverrideService;
|
||||
|
|
@ -26,11 +22,16 @@ 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
|
||||
*
|
||||
* @author tony.chenl
|
||||
*/
|
||||
public class OverrideServiceImpl extends AbstractService implements OverrideService{
|
||||
public class OverrideServiceImpl extends AbstractService implements OverrideService {
|
||||
|
||||
public void saveOverride(Override override) {
|
||||
URL url = getUrlFromOverride(override);
|
||||
|
|
@ -39,105 +40,105 @@ public class OverrideServiceImpl extends AbstractService implements OverrideServ
|
|||
|
||||
public void updateOverride(Override override) {
|
||||
Long id = override.getId();
|
||||
if(id == null) {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no override id");
|
||||
}
|
||||
URL oldOverride = findOverrideUrl(id);
|
||||
if(oldOverride == null) {
|
||||
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) {
|
||||
if (oldOverride == null) {
|
||||
throw new IllegalStateException("Route was changed!");
|
||||
}
|
||||
registryService.unregister(oldOverride);
|
||||
}
|
||||
|
||||
public void enableOverride(Long id) {
|
||||
if(id == null) {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no override id");
|
||||
}
|
||||
|
||||
|
||||
URL oldOverride = findOverrideUrl(id);
|
||||
if(oldOverride == null) {
|
||||
if (oldOverride == null) {
|
||||
throw new IllegalStateException("Override was changed!");
|
||||
}
|
||||
if(oldOverride.getParameter("enabled", true)) {
|
||||
if (oldOverride.getParameter("enabled", true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
URL newOverride = oldOverride.removeParameter("enabled");
|
||||
registryService.unregister(oldOverride);
|
||||
registryService.register(newOverride);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void disableOverride(Long id) {
|
||||
if(id == null) {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no override id");
|
||||
}
|
||||
|
||||
|
||||
URL oldProvider = findOverrideUrl(id);
|
||||
if(oldProvider == null) {
|
||||
if (oldProvider == null) {
|
||||
throw new IllegalStateException("Override was changed!");
|
||||
}
|
||||
if(!oldProvider.getParameter("enabled", true)) {
|
||||
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);
|
||||
filter.put(SyncUtils.SERVICE_FILTER_KEY, service);
|
||||
}
|
||||
if (address != null && address.length() > 0) {
|
||||
filter.put(SyncUtils.ADDRESS_FILTER_KEY, address);
|
||||
filter.put(SyncUtils.ADDRESS_FILTER_KEY, address);
|
||||
}
|
||||
if (application != null && application.length() > 0) {
|
||||
filter.put(Constants.APPLICATION_KEY, application);
|
||||
filter.put(Constants.APPLICATION_KEY, application);
|
||||
}
|
||||
return SyncUtils.filterFromCategory(getRegistryCache(), filter);
|
||||
}
|
||||
|
||||
public List<Override> findByAddress(String address) {
|
||||
return SyncUtils.url2OverrideList(findOverrideUrl(null, address, null));
|
||||
return SyncUtils.url2OverrideList(findOverrideUrl(null, address, null));
|
||||
}
|
||||
|
||||
public List<Override> findByServiceAndAddress(String service, String address) {
|
||||
return SyncUtils.url2OverrideList(findOverrideUrl(service, address, null));
|
||||
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));
|
||||
return SyncUtils.url2OverrideList(findOverrideUrl(service, null, null));
|
||||
}
|
||||
|
||||
public List<Override> findByServiceAndApplication(String service, String application) {
|
||||
return SyncUtils.url2OverrideList(findOverrideUrl(service, null, 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);
|
||||
}
|
||||
|
|
@ -145,9 +146,9 @@ public class OverrideServiceImpl extends AbstractService implements OverrideServ
|
|||
public Override findById(Long id) {
|
||||
return SyncUtils.url2Override(findOverrideUrlPair(id));
|
||||
}
|
||||
|
||||
|
||||
private URL getUrlFromOverride(Override override) {
|
||||
return override.toUrl();
|
||||
return override.toUrl();
|
||||
/*Map<String, String> params = ConvertUtil.serviceName2Map(override.getService());
|
||||
if(!params.containsKey(Constants.INTERFACE_KEY)) {
|
||||
throw new IllegalArgumentException("No interface info");
|
||||
|
|
@ -179,8 +180,8 @@ public class OverrideServiceImpl extends AbstractService implements OverrideServ
|
|||
url = url.addParameterString(override.getParams());
|
||||
return url;*/
|
||||
}
|
||||
|
||||
URL findOverrideUrl(Long id){
|
||||
|
||||
URL findOverrideUrl(Long id) {
|
||||
return getUrlFromOverride(findById(id));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,5 @@
|
|||
package com.alibaba.dubbo.governance.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.OverrideService;
|
||||
|
|
@ -16,11 +9,18 @@ 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;
|
||||
|
||||
|
|
@ -42,101 +42,101 @@ public class OwnerServiceImpl extends AbstractService implements OwnerService {
|
|||
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);
|
||||
return toOverrideLiset(pList, cList);
|
||||
}
|
||||
|
||||
public List<Owner> findAll() {
|
||||
List<Provider> pList = providerService.findAll();
|
||||
List<Override> cList = overrideService.findAll();
|
||||
return toOverrideLiset(pList,cList);
|
||||
return toOverrideLiset(pList, cList);
|
||||
}
|
||||
|
||||
public Owner findById(Long id) {
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<Owner> toOverrideLiset(List<Provider> pList, List<Override> cList){
|
||||
|
||||
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 (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();
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
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);
|
||||
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);
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
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,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-4-15
|
||||
* $Id: ProviderServiceImpl.java 185206 2012-07-09 03:06:37Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,15 +15,6 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.service.impl;
|
||||
|
||||
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;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
|
|
@ -35,15 +26,24 @@ 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
|
||||
*
|
||||
*
|
||||
* @author tony.chenl
|
||||
*/
|
||||
public class ProviderServiceImpl extends AbstractService implements ProviderService {
|
||||
|
||||
@Autowired
|
||||
OverrideService overrideService;
|
||||
|
||||
@Autowired
|
||||
OverrideService overrideService;
|
||||
|
||||
public void create(Provider provider) {
|
||||
URL url = provider.toUrl();
|
||||
|
|
@ -51,159 +51,159 @@ public class ProviderServiceImpl extends AbstractService implements ProviderServ
|
|||
}
|
||||
|
||||
public void enableProvider(Long id) {
|
||||
if(id == null) {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no provider id");
|
||||
}
|
||||
|
||||
|
||||
Provider oldProvider = findProvider(id);
|
||||
|
||||
if(oldProvider == null) {
|
||||
|
||||
if (oldProvider == null) {
|
||||
throw new IllegalStateException("Provider was changed!");
|
||||
}
|
||||
}
|
||||
if (oldProvider.isDynamic()) {
|
||||
//保证disable的override唯一
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
//保证disable的override唯一
|
||||
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);
|
||||
oldProvider.setEnabled(true);
|
||||
updateProvider(oldProvider);
|
||||
}
|
||||
}
|
||||
|
||||
public void disableProvider(Long id) {
|
||||
if(id == null) {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no provider id");
|
||||
}
|
||||
|
||||
|
||||
Provider oldProvider = findProvider(id);
|
||||
if(oldProvider == null) {
|
||||
if (oldProvider == null) {
|
||||
throw new IllegalStateException("Provider was changed!");
|
||||
}
|
||||
|
||||
|
||||
if (oldProvider.isDynamic()) {
|
||||
//保证disable的override唯一
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
//保证disable的override唯一
|
||||
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);
|
||||
oldProvider.setEnabled(false);
|
||||
updateProvider(oldProvider);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void doublingProvider(Long id) {
|
||||
setWeight(id, 2F);
|
||||
setWeight(id, 2F);
|
||||
}
|
||||
|
||||
|
||||
public void halvingProvider(Long id) {
|
||||
setWeight(id, 0.5F);
|
||||
setWeight(id, 0.5F);
|
||||
}
|
||||
|
||||
public void setWeight(Long id, float factor) {
|
||||
if(id == null) {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no provider id");
|
||||
}
|
||||
Provider oldProvider = findProvider(id);
|
||||
if(oldProvider == null) {
|
||||
if (oldProvider == null) {
|
||||
throw new IllegalStateException("Provider was changed!");
|
||||
}
|
||||
Map<String, String> map = StringUtils.parseQueryString(oldProvider.getParameters());
|
||||
String weight = map.get(Constants.WEIGHT_KEY);
|
||||
String weight = map.get(Constants.WEIGHT_KEY);
|
||||
if (oldProvider.isDynamic()) {
|
||||
//保证disable的override唯一
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
//保证disable的override唯一
|
||||
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);
|
||||
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;
|
||||
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) {
|
||||
if (oldProvider == null) {
|
||||
throw new IllegalStateException("Provider was changed!");
|
||||
}
|
||||
registryService.unregister(oldProvider);
|
||||
|
|
@ -211,16 +211,16 @@ public class ProviderServiceImpl extends AbstractService implements ProviderServ
|
|||
|
||||
public void updateProvider(Provider provider) {
|
||||
Long id = provider.getId();
|
||||
if(id == null) {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no provider id");
|
||||
}
|
||||
|
||||
|
||||
URL oldProvider = findProviderUrl(id);
|
||||
if(oldProvider == null) {
|
||||
if (oldProvider == null) {
|
||||
throw new IllegalStateException("Provider was changed!");
|
||||
}
|
||||
URL newProvider = provider.toUrl();
|
||||
|
||||
|
||||
registryService.unregister(oldProvider);
|
||||
registryService.register(newProvider);
|
||||
}
|
||||
|
|
@ -228,7 +228,7 @@ public class ProviderServiceImpl extends AbstractService implements ProviderServ
|
|||
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);
|
||||
}
|
||||
|
|
@ -236,152 +236,152 @@ public class ProviderServiceImpl extends AbstractService implements ProviderServ
|
|||
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());
|
||||
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()) {
|
||||
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()) {
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
String app = u.getAddress();
|
||||
if(app != null) ret.add(app);
|
||||
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()) {
|
||||
for (Map.Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
|
||||
Map<Long, URL> value = e1.getValue();
|
||||
for(Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
if(application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
|
||||
if (application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
|
||||
String addr = u.getAddress();
|
||||
if(addr != null) ret.add(addr);
|
||||
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()) {
|
||||
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);
|
||||
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;
|
||||
|
||||
if (null == providerUrls) return ret;
|
||||
|
||||
Map<Long, URL> value = providerUrls.get(service);
|
||||
if(value == null){
|
||||
return ret;
|
||||
if (value == null) {
|
||||
return ret;
|
||||
}
|
||||
for(Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
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);
|
||||
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()) {
|
||||
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()) {
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
if(address.equals(u.getAddress())) {
|
||||
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()) {
|
||||
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()) {
|
||||
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);
|
||||
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);
|
||||
|
|
@ -391,21 +391,21 @@ public class ProviderServiceImpl extends AbstractService implements ProviderServ
|
|||
|
||||
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()) {
|
||||
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()) {
|
||||
for (Map.Entry<Long, URL> e2 : value.entrySet()) {
|
||||
URL u = e2.getValue();
|
||||
if(application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
|
||||
if (application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
|
||||
ret.add(e1.getKey());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -413,11 +413,11 @@ public class ProviderServiceImpl extends AbstractService implements ProviderServ
|
|||
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;
|
||||
|
||||
if (providerUrls == null || service == null || service.length() == 0) return ret;
|
||||
|
||||
Map<Long, URL> providers = providerUrls.get(service);
|
||||
if(null == providers || providers.isEmpty()) return ret;
|
||||
|
||||
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) {
|
||||
|
|
@ -427,8 +427,8 @@ public class ProviderServiceImpl extends AbstractService implements ProviderServ
|
|||
if (methods == null || methods.length == 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
for(String m : methods) {
|
||||
|
||||
for (String m : methods) {
|
||||
ret.add(m);
|
||||
}
|
||||
return ret;
|
||||
|
|
@ -441,20 +441,19 @@ public class ProviderServiceImpl extends AbstractService implements ProviderServ
|
|||
public Provider findByServiceAndAddress(String service, String address) {
|
||||
return SyncUtils.url2Provider(findProviderUrl(service, address));
|
||||
}
|
||||
|
||||
private Pair<Long, URL> findProviderUrl(String service, String 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()) {
|
||||
if (ret.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Long key = ret.entrySet().iterator().next().getKey();
|
||||
return new Pair<Long, URL>(key, ret.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-4-15
|
||||
* $Id: RouteServiceImpl.java 182851 2012-06-28 09:39:16Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,10 +15,6 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.service.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.governance.service.RouteService;
|
||||
|
|
@ -26,9 +22,13 @@ 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
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class RouteServiceImpl extends AbstractService implements RouteService {
|
||||
|
|
@ -39,84 +39,84 @@ public class RouteServiceImpl extends AbstractService implements RouteService {
|
|||
|
||||
public void updateRoute(Route route) {
|
||||
Long id = route.getId();
|
||||
if(id == null) {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no route id");
|
||||
}
|
||||
URL oldRoute = findRouteUrl(id);
|
||||
if(oldRoute == null) {
|
||||
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) {
|
||||
if (oldRoute == null) {
|
||||
throw new IllegalStateException("Route was changed!");
|
||||
}
|
||||
registryService.unregister(oldRoute);
|
||||
}
|
||||
|
||||
public void enableRoute(Long id) {
|
||||
if(id == null) {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no route id");
|
||||
}
|
||||
|
||||
|
||||
URL oldRoute = findRouteUrl(id);
|
||||
if(oldRoute == null) {
|
||||
if (oldRoute == null) {
|
||||
throw new IllegalStateException("Route was changed!");
|
||||
}
|
||||
if(oldRoute.getParameter("enabled", true)) {
|
||||
if (oldRoute.getParameter("enabled", true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
registryService.unregister(oldRoute);
|
||||
URL newRoute= oldRoute.addParameter("enabled", true);
|
||||
registryService.unregister(oldRoute);
|
||||
URL newRoute = oldRoute.addParameter("enabled", true);
|
||||
registryService.register(newRoute);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void disableRoute(Long id) {
|
||||
if(id == null) {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("no route id");
|
||||
}
|
||||
|
||||
|
||||
URL oldRoute = findRouteUrl(id);
|
||||
if(oldRoute == null) {
|
||||
if (oldRoute == null) {
|
||||
throw new IllegalStateException("Route was changed!");
|
||||
}
|
||||
if(!oldRoute.getParameter("enabled", true)) {
|
||||
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){
|
||||
|
||||
private URL findRouteUrl(Long id) {
|
||||
return findRoute(id).toUrl();
|
||||
}
|
||||
|
||||
|
|
@ -124,13 +124,13 @@ public class RouteServiceImpl extends AbstractService implements RouteService {
|
|||
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);
|
||||
filter.put(SyncUtils.SERVICE_FILTER_KEY, service);
|
||||
}
|
||||
if (address != null && address.length() > 0) {
|
||||
filter.put(SyncUtils.ADDRESS_FILTER_KEY, address);
|
||||
filter.put(SyncUtils.ADDRESS_FILTER_KEY, address);
|
||||
}
|
||||
if (force) {
|
||||
filter.put("force", "true");
|
||||
filter.put("force", "true");
|
||||
}
|
||||
return SyncUtils.filterFromCategory(getRegistryCache(), filter);
|
||||
}
|
||||
|
|
@ -150,7 +150,7 @@ public class RouteServiceImpl extends AbstractService implements RouteService {
|
|||
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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-4-15
|
||||
* $Id: UserServiceImpl.java 182013 2012-06-26 10:32:43Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,35 +15,34 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class UserServiceImpl extends AbstractService implements UserService {
|
||||
|
||||
private String rootPassword;
|
||||
private String rootPassword;
|
||||
private String guestPassword;
|
||||
|
||||
public void setRootPassword(String password) {
|
||||
this.rootPassword = (password == null ? "" : password);
|
||||
}
|
||||
public void setRootPassword(String password) {
|
||||
this.rootPassword = (password == null ? "" : password);
|
||||
}
|
||||
|
||||
private String guestPassword;
|
||||
|
||||
public void setGuestPassword(String password) {
|
||||
this.guestPassword = (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();
|
||||
if ("guest".equals(username)) {
|
||||
User user = new User();
|
||||
user.setUsername(username);
|
||||
user.setPassword(Coder.encodeMd5(username + ":" + User.REALM + ":" + guestPassword));
|
||||
user.setName(username);
|
||||
|
|
@ -52,8 +51,8 @@ public class UserServiceImpl extends AbstractService implements UserService {
|
|||
user.setLocale("zh");
|
||||
user.setServicePrivilege("");
|
||||
return user;
|
||||
} else if ("root".equals(username)) {
|
||||
User user = new User();
|
||||
} else if ("root".equals(username)) {
|
||||
User user = new User();
|
||||
user.setUsername(username);
|
||||
user.setPassword(Coder.encodeMd5(username + ":" + User.REALM + ":" + rootPassword));
|
||||
user.setName(username);
|
||||
|
|
@ -62,8 +61,8 @@ public class UserServiceImpl extends AbstractService implements UserService {
|
|||
user.setLocale("zh");
|
||||
user.setServicePrivilege("*");
|
||||
return user;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<User> findAllUsers() {
|
||||
|
|
@ -83,17 +82,17 @@ public class UserServiceImpl extends AbstractService implements UserService {
|
|||
|
||||
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) {
|
||||
|
|
@ -103,22 +102,22 @@ public class UserServiceImpl extends AbstractService implements UserService {
|
|||
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.server-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2009-12-27
|
||||
* $Id: DatabaseStatusChecker.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,32 +15,31 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.status;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class DatabaseStatusChecker implements StatusChecker {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DatabaseStatusChecker.class);
|
||||
|
||||
|
||||
private int version;
|
||||
|
||||
|
||||
private String message;
|
||||
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
|
|
@ -63,9 +62,9 @@ public class DatabaseStatusChecker implements StatusChecker {
|
|||
}
|
||||
if (message == null) {
|
||||
message = metaData.getURL()
|
||||
+ " (" + metaData.getDatabaseProductName()
|
||||
+ " " + metaData.getDatabaseProductVersion()
|
||||
+ ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")";
|
||||
+ " (" + metaData.getDatabaseProductName()
|
||||
+ " " + metaData.getDatabaseProductVersion()
|
||||
+ ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")";
|
||||
}
|
||||
if (version == 0) {
|
||||
version = metaData.getDatabaseMajorVersion();
|
||||
|
|
@ -77,9 +76,9 @@ public class DatabaseStatusChecker implements StatusChecker {
|
|||
logger.error(e.getMessage(), e);
|
||||
ok = false;
|
||||
}
|
||||
return new Status(! ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message);
|
||||
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";
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.server-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2009-12-27
|
||||
* $Id: LoadStatusChecker.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,30 +15,30 @@
|
|||
*/
|
||||
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;
|
||||
|
||||
import com.alibaba.dubbo.common.status.Status;
|
||||
import com.alibaba.dubbo.common.status.StatusChecker;
|
||||
|
||||
/**
|
||||
* Load Status
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
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();
|
||||
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,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.server-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2009-12-27
|
||||
* $Id: MemoryStatusChecker.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -20,7 +20,7 @@ import com.alibaba.dubbo.common.status.StatusChecker;
|
|||
|
||||
/**
|
||||
* MemoryStatus
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class MemoryStatusChecker implements StatusChecker {
|
||||
|
|
@ -31,9 +31,9 @@ public class MemoryStatusChecker implements StatusChecker {
|
|||
long totalMemory = runtime.totalMemory();
|
||||
long maxMemory = runtime.maxMemory();
|
||||
boolean ok = (maxMemory - (totalMemory - freeMemory) > 2048); // 剩余空间小于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";
|
||||
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,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.console-2.2.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at Mar 21, 2012
|
||||
* $Id: RegistryServerSync.java 182143 2012-06-27 03:25:50Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2100 Alibaba.com Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,17 +15,6 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.sync;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
|
|
@ -36,6 +25,17 @@ 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.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* @author ding.lid
|
||||
*/
|
||||
|
|
@ -44,29 +44,27 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
|
|||
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));
|
||||
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();
|
||||
|
||||
// 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;
|
||||
|
||||
// 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>>>();
|
||||
|
||||
public ConcurrentMap<String, ConcurrentMap<String, Map<Long, URL>>> getRegistryCache(){
|
||||
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);
|
||||
|
|
@ -75,55 +73,55 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
|
|||
public void destroy() throws Exception {
|
||||
registryService.unsubscribe(SUBSCRIBE, this);
|
||||
}
|
||||
|
||||
|
||||
// 收到的通知对于 ,同一种类型数据(override、subcribe、route、其它是Provider),同一个服务的数据是全量的
|
||||
public void notify(List<URL> urls) {
|
||||
if(urls == null || urls.isEmpty()) {
|
||||
return;
|
||||
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>>>();
|
||||
for(URL url : urls) {
|
||||
String category = url.getParameter(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY);
|
||||
if(Constants.EMPTY_PROTOCOL.equalsIgnoreCase(url.getProtocol())) { // 注意:empty协议的group和version为*
|
||||
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);
|
||||
// 注意:empty协议的group和version为*
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (URL url : urls) {
|
||||
String category = url.getParameter(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY);
|
||||
if (Constants.EMPTY_PROTOCOL.equalsIgnoreCase(url.getProtocol())) { // 注意:empty协议的group和version为*
|
||||
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);
|
||||
// 注意:empty协议的group和version为*
|
||||
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 {
|
||||
Map<String, Map<Long, URL>> services = categories.get(category);
|
||||
if(services == null) {
|
||||
services = new HashMap<String, Map<Long,URL>>();
|
||||
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) {
|
||||
if (ids == null) {
|
||||
ids = new HashMap<Long, URL>();
|
||||
services.put(service, ids);
|
||||
}
|
||||
ids.put(ID.incrementAndGet(), url);
|
||||
}
|
||||
}
|
||||
for(Map.Entry<String, Map<String, Map<Long, URL>>> categoryEntry : categories.entrySet()) {
|
||||
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>>();
|
||||
if (services == null) {
|
||||
services = new ConcurrentHashMap<String, Map<Long, URL>>();
|
||||
registryCache.put(category, services);
|
||||
}
|
||||
services.putAll(categoryEntry.getValue());
|
||||
|
|
|
|||
|
|
@ -19,65 +19,65 @@ import java.util.Map;
|
|||
|
||||
public class Pair<K, V> implements Map.Entry<K, V> {
|
||||
|
||||
private K key;
|
||||
private K key;
|
||||
|
||||
private V value;
|
||||
|
||||
public Pair() {
|
||||
}
|
||||
|
||||
private V value;
|
||||
|
||||
public Pair() {
|
||||
}
|
||||
|
||||
public Pair(K key, V value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public K getKey() {
|
||||
return key;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(K key) {
|
||||
this.key = key;
|
||||
}
|
||||
public void setKey(K key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public V getValue() {
|
||||
return value;
|
||||
}
|
||||
public V getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public V setValue(V value) {
|
||||
V old = this.value;
|
||||
this.value = value;
|
||||
return old;
|
||||
}
|
||||
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 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;
|
||||
}
|
||||
@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,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.governance-2.2.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at Mar 31, 2012
|
||||
* $Id: SyncUtils.java 184666 2012-07-05 11:13:17Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2100 Alibaba.com Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,11 +15,6 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.sync.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
|
|
@ -27,22 +22,27 @@ 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;
|
||||
|
||||
/**
|
||||
* @author ding.lid
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
if (pair == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Long id = pair.getKey();
|
||||
URL url = pair.getValue();
|
||||
|
||||
|
|
@ -64,20 +64,20 @@ public class SyncUtils {
|
|||
|
||||
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()) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (pair == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Long id = pair.getKey();
|
||||
URL url = pair.getValue();
|
||||
|
||||
|
|
@ -93,21 +93,21 @@ public class SyncUtils {
|
|||
|
||||
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()) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (pair == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Long id = pair.getKey();
|
||||
URL url = pair.getValue();
|
||||
|
||||
|
|
@ -124,21 +124,21 @@ public class SyncUtils {
|
|||
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()) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (pair == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Long id = pair.getKey();
|
||||
URL url = pair.getValue();
|
||||
|
||||
|
|
@ -163,7 +163,7 @@ public class SyncUtils {
|
|||
|
||||
String host = url.getHost();
|
||||
boolean anyhost = url.getParameter(Constants.ANYHOST_VALUE, false);
|
||||
if(!anyhost || !"0.0.0.0".equals(host)) {
|
||||
if (!anyhost || !"0.0.0.0".equals(host)) {
|
||||
o.setAddress(url.getAddress());
|
||||
}
|
||||
|
||||
|
|
@ -174,84 +174,82 @@ public class SyncUtils {
|
|||
|
||||
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");
|
||||
|
||||
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()) {
|
||||
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;
|
||||
|
||||
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()) {
|
||||
if (s == null) {
|
||||
for (Map.Entry<String, Map<Long, URL>> entry : urls.entrySet()) {
|
||||
filterFromUrls(entry.getValue(), ret, filter);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} 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()) {
|
||||
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()) {
|
||||
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())) {
|
||||
|
||||
if (ADDRESS_FILTER_KEY.equals(key)) {
|
||||
if (!value.equals(url.getAddress())) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(!value.equals(url.getParameter(key))) {
|
||||
} else {
|
||||
if (!value.equals(url.getParameter(key))) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(match) {
|
||||
|
||||
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()) {
|
||||
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));
|
||||
if (u.containsKey(id)) return new Pair<Long, URL>(id, u.get(id));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +1,30 @@
|
|||
/**
|
||||
* Function: dubbo用户类
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2011-08-17
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2011 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.auth;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* MinasUser: DubboUser
|
||||
*
|
||||
*
|
||||
* @author guanghui.shigh
|
||||
*/
|
||||
public class DubboUser implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final ThreadLocal<User> userHolder = new ThreadLocal<User>();
|
||||
private static final ThreadLocal<User> userHolder = new ThreadLocal<User>();
|
||||
|
||||
private DubboUser() {
|
||||
}
|
||||
private DubboUser() {
|
||||
}
|
||||
|
||||
public static final User getCurrentUser() {
|
||||
return (User) userHolder.get();
|
||||
|
|
|
|||
|
|
@ -5,10 +5,6 @@ import java.util.Locale;
|
|||
public class LocaleUtil {
|
||||
private static ThreadLocal<Locale> userLocale = new ThreadLocal<Locale>();
|
||||
|
||||
public static void setLocale(Locale locale) {
|
||||
userLocale.set(locale);
|
||||
}
|
||||
|
||||
public static void cleanLocale() {
|
||||
userLocale.remove();
|
||||
}
|
||||
|
|
@ -17,4 +13,8 @@ public class LocaleUtil {
|
|||
return userLocale.get();
|
||||
}
|
||||
|
||||
public static void setLocale(Locale locale) {
|
||||
userLocale.set(locale);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,13 @@
|
|||
/**
|
||||
* Function: 拦截器
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2011-08-11
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2011 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.interceptor;
|
||||
|
||||
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;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.citrus.service.pipeline.PipelineContext;
|
||||
import com.alibaba.citrus.service.pipeline.support.AbstractValve;
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
|
|
@ -32,6 +18,19 @@ 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;
|
||||
|
||||
/**
|
||||
* @author william.liangf
|
||||
* @author guanghui.shigh
|
||||
|
|
@ -41,15 +40,36 @@ import com.alibaba.dubbo.registry.common.util.Coder;
|
|||
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;
|
||||
|
||||
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 {
|
||||
|
|
@ -60,23 +80,23 @@ public class AuthorizationValve extends AbstractValve {
|
|||
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());
|
||||
}
|
||||
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);
|
||||
}
|
||||
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;
|
||||
if (!uri.startsWith("/status/")) {
|
||||
User user = null;
|
||||
String authType = null;
|
||||
String authorization = request.getHeader("Authorization");
|
||||
if (authorization != null && authorization.length() > 0) {
|
||||
|
|
@ -99,32 +119,20 @@ public class AuthorizationValve extends AbstractValve {
|
|||
request.getSession().setAttribute(WebConstants.CURRENT_USER_KEY, user);
|
||||
pipelineContext.invokeNext();
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
pipelineContext.invokeNext();
|
||||
}
|
||||
}
|
||||
|
||||
private User getUser(String username) {
|
||||
return userService.findUser(username);
|
||||
return userService.findUser(username);
|
||||
}
|
||||
|
||||
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 String logout = "/logout";
|
||||
|
||||
private String logoutCookie = "logout";
|
||||
|
||||
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) + "\"");
|
||||
+ UUID.randomUUID().toString().replace("-", "") + "\", opaque=\""
|
||||
+ Coder.encodeMd5(REALM) + "\"");
|
||||
} else {
|
||||
response.setHeader("WWW-Authenticate", CHALLENGE + " realm=\"" + REALM + "\"");
|
||||
}
|
||||
|
|
@ -132,7 +140,7 @@ public class AuthorizationValve extends AbstractValve {
|
|||
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(':');
|
||||
|
|
@ -175,11 +183,11 @@ public class AuthorizationValve extends AbstractValve {
|
|||
String a1 = pwd;
|
||||
|
||||
String a2 = "auth-int".equals(qop)
|
||||
? Coder.encodeMd5(method + ":" + uri + ":" + Coder.encodeMd5(readToBytes(request.getInputStream())))
|
||||
: Coder.encodeMd5(method + ":" + uri);
|
||||
? 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);
|
||||
? Coder.encodeMd5(a1 + ":" + nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" + a2)
|
||||
: Coder.encodeMd5(a1 + ":" + nonce + ":" + a2);
|
||||
if (digest.equals(passwordDigest)) {
|
||||
return user;
|
||||
}
|
||||
|
|
@ -189,7 +197,7 @@ public class AuthorizationValve extends AbstractValve {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private boolean isLogout() {
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if (cookies != null && cookies.length > 0) {
|
||||
|
|
@ -201,27 +209,8 @@ public class AuthorizationValve extends AbstractValve {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void setLogout(boolean logoutValue) {
|
||||
response.addCookie(new Cookie(logoutCookie, String.valueOf(logoutValue)));
|
||||
}
|
||||
|
||||
private static Pattern PARAMETER_PATTERN = Pattern.compile("(\\w+)=[\"]?([^,\"]+)[\"]?[,]?\\s*");
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.console-2.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at Sep 13, 2011
|
||||
* $Id: LocaleValve.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2100 Alibaba.com Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,31 +15,28 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.interceptor;
|
||||
|
||||
import static com.alibaba.citrus.turbine.util.TurbineUtil.getTurbineRunData;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author guanghui.shigh
|
||||
*/
|
||||
public class LocaleValve extends AbstractValve {
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
//添加拦截器例外设置
|
||||
private final static Set<String> TARGET_WITHOUT_CHECK = new HashSet<String>();
|
||||
|
||||
static {
|
||||
TARGET_WITHOUT_CHECK.add("/ok");
|
||||
TARGET_WITHOUT_CHECK.add("/error");
|
||||
|
|
@ -47,6 +44,9 @@ public class LocaleValve extends AbstractValve {
|
|||
TARGET_WITHOUT_CHECK.add("/logout");
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
private boolean ignoreTarget(String target) {
|
||||
return TARGET_WITHOUT_CHECK.contains(target);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.console-2.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at Sep 5, 2011
|
||||
* $Id: RestfuleUrlRewriter.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2100 Alibaba.com Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,6 +15,11 @@
|
|||
*/
|
||||
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;
|
||||
|
|
@ -25,22 +30,28 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Restful URL Rewrite成 WebX的URL。
|
||||
*
|
||||
*
|
||||
* @author ding.lid
|
||||
*/
|
||||
public class RestfuleUrlRewriter implements RewriteSubstitutionHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(RestfuleUrlRewriter.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(RestfuleUrlRewriter.class);
|
||||
|
||||
private static final Map<String, String> pl2single;
|
||||
private static final Set<String> appParameter;
|
||||
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>();
|
||||
|
||||
|
|
@ -64,18 +75,6 @@ public class RestfuleUrlRewriter implements RewriteSubstitutionHandler {
|
|||
appParameter = Collections.unmodifiableSet(set);
|
||||
}
|
||||
|
||||
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+$");
|
||||
|
||||
public void postSubstitution(RewriteSubstitutionContext context) {
|
||||
final String oldPath = context.getPath();
|
||||
String path = oldPath;
|
||||
|
|
@ -96,28 +95,28 @@ public class RestfuleUrlRewriter implements RewriteSubstitutionHandler {
|
|||
}
|
||||
List<String> temp = Arrays.asList(SLASH_PATTERN.split(path));
|
||||
//兼容2.0.x注册中心的shell风格url 如:http://root:hello1234@127.0.0.1:8080/status/dubbo.test.api.HelloService:1.1
|
||||
if("status".equals(temp.get(0))&&temp.size()>1){
|
||||
if ("status".equals(temp.get(0)) && temp.size() > 1) {
|
||||
context.setPath("servicestatus");
|
||||
return;
|
||||
}
|
||||
//兼容包含group的path
|
||||
String[] split = temp.toArray(new String[temp.size()]);
|
||||
|
||||
if(temp.size()>2&&temp.contains("services")){
|
||||
|
||||
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+"))) {
|
||||
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);
|
||||
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;
|
||||
|
|
@ -169,20 +168,20 @@ public class RestfuleUrlRewriter implements RewriteSubstitutionHandler {
|
|||
}
|
||||
|
||||
String method = param.get(METHOD_KEY);
|
||||
|
||||
|
||||
String defaultRedirect = null;
|
||||
if(method == null || method.equals("index")){
|
||||
if (method == null || method.equals("index")) {
|
||||
defaultRedirect = oldPath;
|
||||
}else{
|
||||
} else {
|
||||
defaultRedirect = oldPath.split("/" + method)[0];
|
||||
}
|
||||
String id = param.get(ID_KEY);
|
||||
if(id != null){
|
||||
if (id != null) {
|
||||
int i = defaultRedirect.lastIndexOf("/");
|
||||
defaultRedirect = defaultRedirect.substring(0,i);
|
||||
defaultRedirect = defaultRedirect.substring(0, i);
|
||||
}
|
||||
context.getParameters().setString("defaultRedirect", defaultRedirect);
|
||||
|
||||
|
||||
final String module = split[0];
|
||||
context.setPath("/" + module + "/" + type + ".htm");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,13 @@
|
|||
/**
|
||||
* Function: 拦截器
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2011-08-11
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2011 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.interceptor;
|
||||
|
||||
import static com.alibaba.citrus.turbine.util.TurbineUtil.getTurbineRunData;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.citrus.service.pipeline.PipelineContext;
|
||||
import com.alibaba.citrus.service.pipeline.support.AbstractValve;
|
||||
import com.alibaba.citrus.turbine.TurbineRunData;
|
||||
|
|
@ -25,14 +16,22 @@ 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;
|
||||
|
||||
/**
|
||||
* @author guanghui.shigh
|
||||
*/
|
||||
public class ServicePrivilegeCheckValve extends AbstractValve {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ServicePrivilegeCheckValve.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(ServicePrivilegeCheckValve.class);
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Override
|
||||
protected void init() throws Exception {
|
||||
|
|
@ -43,56 +42,56 @@ public class ServicePrivilegeCheckValve extends AbstractValve {
|
|||
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();
|
||||
|
||||
//记录上次操作到请求中
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
private void invokeCheckServicePrivilege(User user) {
|
||||
TurbineRunData rundata = getTurbineRunData(request);
|
||||
HttpSession session = request.getSession();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String[]> requestMapping = request.getParameterMap();
|
||||
|
||||
//记录上次操作到请求中
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 无权限跳转
|
||||
* @param rundata
|
||||
*/
|
||||
private void redirectToNoRight(TurbineRunData rundata) {
|
||||
if(logger.isInfoEnabled()) {
|
||||
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;
|
||||
}
|
||||
|
||||
rundata.getParameters().setString("returnURL1", (String) rundata.getRequest().getAttribute("returnURL"));
|
||||
rundata.setRedirectLocation("http://localhost:8080/governance/noServicePrivilege?returnURL=" + rundata.getRequest().getAttribute("returnURL"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,15 +15,15 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.module.screen;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
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");
|
||||
|
||||
public void execute(Map<String, Object> context) throws Throwable {
|
||||
String contextPath = (String) context.get("request.contextPath");
|
||||
context.put("rootContextPath", new RootContextPath(contextPath));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,15 +15,15 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.module.screen;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
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");
|
||||
|
||||
public void execute(Map<String, Object> context) throws Throwable {
|
||||
String contextPath = (String) context.get("request.contextPath");
|
||||
context.put("rootContextPath", new RootContextPath(contextPath));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,15 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.module.screen;
|
||||
|
||||
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.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
|
@ -14,200 +23,32 @@ import java.lang.reflect.Modifier;
|
|||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* BaseScreen
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public abstract class Restful {
|
||||
|
||||
protected static final Logger logger = Logger.getLogger(Restful.class);
|
||||
|
||||
protected static final Pattern SPACE_SPLIT_PATTERN = Pattern.compile("\\s+");
|
||||
protected static final Logger logger = Logger.getLogger(Restful.class);
|
||||
|
||||
@Autowired
|
||||
private MessageResourceService messageResourceService;
|
||||
|
||||
public String getMessage(String key, Object... args) {
|
||||
return messageResourceService.getMessage(key, args);
|
||||
}
|
||||
|
||||
//FIXME 把这些辅助方法提取出去
|
||||
protected String role = null;
|
||||
protected String operator = null;
|
||||
protected User currentUser = null;
|
||||
protected String operatorAddress = null;
|
||||
protected String currentRegistry = null;
|
||||
|
||||
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));
|
||||
|
||||
// 分析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)) { // 因表单不能提交PUT请求,用POST代替
|
||||
method = "update";
|
||||
} else if ("delete".equalsIgnoreCase(httpMethod)) { // 因表单不能提交DELETE请求,用参数代替
|
||||
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 static boolean isPrimitive(Class<?> cls) {
|
||||
return cls.isPrimitive()|| cls == Boolean.class || cls == Byte.class
|
||||
protected static final Pattern SPACE_SPLIT_PATTERN = Pattern.compile("\\s+");
|
||||
//FIXME 把这些辅助方法提取出去
|
||||
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);
|
||||
|
|
@ -228,10 +69,166 @@ public abstract class Restful {
|
|||
}
|
||||
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));
|
||||
|
||||
// 分析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)) { // 因表单不能提交PUT请求,用POST代替
|
||||
method = "update";
|
||||
} else if ("delete".equalsIgnoreCase(httpMethod)) { // 因表单不能提交DELETE请求,用参数代替
|
||||
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;
|
||||
return defaultRedirect;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,26 @@
|
|||
package com.alibaba.dubbo.governance.web.common.pulltool;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
/**
|
||||
* DateFormat Utility
|
||||
*
|
||||
*
|
||||
* @author guanghui.shigh
|
||||
*/
|
||||
public class DateFormatUtil {
|
||||
|
||||
private static final String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
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>>();
|
||||
private static final ThreadLocal<Map<String, DateFormat>> tl = new ThreadLocal<Map<String, DateFormat>>();
|
||||
|
||||
/**
|
||||
* According to the specified format, Get a DateFormat
|
||||
*
|
||||
*
|
||||
* @param format
|
||||
* @return
|
||||
*/
|
||||
|
|
@ -48,7 +48,7 @@ public class DateFormatUtil {
|
|||
|
||||
/**
|
||||
* Get Default DateFormat
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static DateFormat getDateFormat() {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: iris-web-1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at Jul 9, 2010
|
||||
* $Id: I18nMessageTool.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,33 +15,32 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.pulltool;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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.
|
||||
*
|
||||
*
|
||||
* @author gerry
|
||||
*/
|
||||
public class I18nMessageTool implements ToolFactory {
|
||||
|
||||
@Autowired
|
||||
private MessageResourceService messageResourceService;
|
||||
private boolean singleton = true; //应该是global范围的对象!!
|
||||
|
||||
public Object createTool() throws Exception {
|
||||
return messageResourceService;
|
||||
}
|
||||
|
||||
private boolean singleton = true; //应该是global范围的对象!!
|
||||
|
||||
public void setSingleton(boolean singleton) {
|
||||
this.singleton = singleton;
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
return this.singleton;
|
||||
}
|
||||
|
||||
public void setSingleton(boolean singleton) {
|
||||
this.singleton = singleton;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,25 +16,25 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
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,11 +1,11 @@
|
|||
/**
|
||||
* Project: dubbo.registry.server-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-7-27
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2010 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -14,21 +14,6 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.pulltool;
|
||||
|
||||
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;
|
||||
|
||||
import com.alibaba.dubbo.common.Constants;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.utils.NetUtils;
|
||||
|
|
@ -45,24 +30,46 @@ 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
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class Tool {
|
||||
|
||||
private OverrideService overrideService;
|
||||
|
||||
private RouteService routeService;
|
||||
|
||||
public void setOverrideService(OverrideService overrideService) {
|
||||
this.overrideService = overrideService;
|
||||
}
|
||||
|
||||
public void setRouteService(RouteService routeService) {
|
||||
this.routeService = routeService;
|
||||
}
|
||||
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();
|
||||
|
|
@ -74,15 +81,15 @@ public class Tool {
|
|||
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)) {
|
||||
if (!address.startsWith(hostname)) {
|
||||
return "(" + hostname + ")";
|
||||
}
|
||||
}
|
||||
|
|
@ -92,19 +99,19 @@ public class Tool {
|
|||
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 port = address.substring(i + 1);
|
||||
String hostname = NetUtils.getHostName(address);
|
||||
if (! address.equals(hostname)) {
|
||||
if (!address.equals(hostname)) {
|
||||
return hostname + ":" + port;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
public static String getPath(String url) {
|
||||
try {
|
||||
return URL.valueOf(url).getPath();
|
||||
|
|
@ -112,7 +119,7 @@ public class Tool {
|
|||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getAddress(String url) {
|
||||
try {
|
||||
return URL.valueOf(url).getAddress();
|
||||
|
|
@ -122,46 +129,46 @@ public class Tool {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
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 (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);
|
||||
}
|
||||
|
|
@ -179,10 +186,10 @@ public class Tool {
|
|||
} catch (UnknownHostException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return address;
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
||||
|
||||
public static String encode(String url) {
|
||||
try {
|
||||
return URLEncoder.encode(url, "UTF-8");
|
||||
|
|
@ -190,7 +197,7 @@ public class Tool {
|
|||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String escape(String html) {
|
||||
return StringEscapeUtils.escapeHtml(html);
|
||||
}
|
||||
|
|
@ -198,70 +205,53 @@ public class Tool {
|
|||
public static String unescape(String html) {
|
||||
return StringEscapeUtils.unescapeHtml(html);
|
||||
}
|
||||
|
||||
|
||||
public static String encodeUrl(String url) {
|
||||
return URL.encode(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);
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
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) {
|
||||
|
||||
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) {
|
||||
|
|
@ -271,14 +261,14 @@ public class Tool {
|
|||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public static String getParameter(String parameters, String key){
|
||||
|
||||
public static String getParameter(String parameters, String key) {
|
||||
String value = "";
|
||||
if (parameters != null && parameters.length() > 0) {
|
||||
String[] pairs = parameters.split("&");
|
||||
for(String pair : pairs){
|
||||
for (String pair : pairs) {
|
||||
String[] kv = pair.split("=");
|
||||
if(key.equals(kv[0])){
|
||||
if (key.equals(kv[0])) {
|
||||
value = kv[1];
|
||||
break;
|
||||
}
|
||||
|
|
@ -286,168 +276,176 @@ public class Tool {
|
|||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static Map<String, String> toParameterMap(String parameters){
|
||||
return StringUtils.parseQueryString(parameters);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从provider的paramters参数中获取版本值
|
||||
* @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 String formatTimestamp(String timestamp){
|
||||
if (timestamp == null || timestamp.length() == 0) {
|
||||
return "";
|
||||
}
|
||||
return formatDate(new Date(Long.valueOf(timestamp)));
|
||||
}
|
||||
|
||||
//时间格式化
|
||||
public String formatDate(Date date){
|
||||
if(date==null){
|
||||
return "";
|
||||
}
|
||||
return DateFormatUtil.getDateFormat().format(date);
|
||||
public static Map<String, String> toParameterMap(String parameters) {
|
||||
return StringUtils.parseQueryString(parameters);
|
||||
}
|
||||
|
||||
public String formatDate(Date date, String template){
|
||||
if(date==null || template==null){
|
||||
return "";
|
||||
}
|
||||
return DateFormatUtil.getDateFormat(template).format(date);
|
||||
|
||||
/**
|
||||
* 从provider的paramters参数中获取版本值
|
||||
*
|
||||
* @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 boolean beforeNow(Date date){
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
//时间格式化
|
||||
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;
|
||||
if (now.after(date)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//时间相减
|
||||
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 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 long dateMinus(Date date1, Date date2) {
|
||||
return (date1.getTime() - date1.getTime()) / 1000;
|
||||
}
|
||||
|
||||
public int getProviderWeight(Provider provider){
|
||||
List<Override> oList = overrideService.findByServiceAndAddress(provider.getService(), provider.getAddress());
|
||||
return getProviderWeight(provider, oList);
|
||||
public boolean isProviderEnabled(Provider provider) {
|
||||
List<Override> oList = overrideService.findByServiceAndAddress(provider.getService(), provider.getAddress());
|
||||
return isProviderEnabled(provider, oList);
|
||||
}
|
||||
|
||||
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 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);
|
||||
}
|
||||
|
||||
public boolean isInBlackList(Consumer consumer) {
|
||||
String service = consumer.getService();
|
||||
List<Route> routes = routeService.findForceRouteByService(service);
|
||||
if (routes == null || routes.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
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 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 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){
|
||||
|
||||
public boolean checkUrl(User user, String uri) {
|
||||
return true;
|
||||
/*if(!User.ROOT.equals(user.getRole())){
|
||||
List<String> disabledSysinfo = new ArrayList<String>();
|
||||
|
|
|
|||
|
|
@ -1,38 +1,37 @@
|
|||
package com.alibaba.dubbo.governance.web.common.pulltool;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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.
|
||||
*
|
||||
*
|
||||
* @author gerry
|
||||
*/
|
||||
public class ToolUtil implements ToolFactory {
|
||||
@Autowired
|
||||
OverrideService overrideService;
|
||||
|
||||
@Autowired
|
||||
RouteService routeService;
|
||||
@Autowired
|
||||
OverrideService overrideService;
|
||||
|
||||
@Autowired
|
||||
RouteService routeService;
|
||||
private boolean singleton = false; //应该是global范围的对象!!
|
||||
|
||||
public Object createTool() throws Exception {
|
||||
Tool tool = new Tool();
|
||||
tool.setOverrideService(overrideService);
|
||||
tool.setRouteService(routeService);
|
||||
Tool tool = new Tool();
|
||||
tool.setOverrideService(overrideService);
|
||||
tool.setRouteService(routeService);
|
||||
return tool;
|
||||
}
|
||||
|
||||
private boolean singleton = false; //应该是global范围的对象!!
|
||||
|
||||
public boolean isSingleton() {
|
||||
return this.singleton;
|
||||
}
|
||||
|
||||
|
||||
public void setSingleton(boolean singleton) {
|
||||
this.singleton = singleton;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,21 +7,20 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.resolver;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class MapDataResolverFactory implements DataResolverFactory {
|
||||
|
|
@ -35,12 +34,12 @@ public class MapDataResolverFactory implements DataResolverFactory {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public class MapDataResolver implements DataResolver {
|
||||
|
||||
|
||||
public final DataResolverContext context;
|
||||
|
||||
public MapDataResolver(DataResolverContext context){
|
||||
public MapDataResolver(DataResolverContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
|
@ -50,5 +49,5 @@ public class MapDataResolverFactory implements DataResolverFactory {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,37 +7,36 @@
|
|||
*/
|
||||
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;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.alibaba.citrus.turbine.Context;
|
||||
import com.alibaba.citrus.turbine.TurbineRunDataInternal;
|
||||
|
||||
/**
|
||||
* ParameterMap
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
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.";
|
||||
|
|
@ -47,7 +46,7 @@ public class ParameterMap implements Map<String, Object> {
|
|||
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";
|
||||
|
|
@ -65,13 +64,13 @@ public class ParameterMap implements Map<String, Object> {
|
|||
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){
|
||||
public ParameterMap(HttpServletRequest request, Context context, TurbineRunDataInternal navigator) {
|
||||
super();
|
||||
this.request = request;
|
||||
this.context = context;
|
||||
|
|
@ -174,18 +173,18 @@ public class ParameterMap implements Map<String, Object> {
|
|||
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 {
|
||||
} else {
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Object getCookieValue(String key) {
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if (cookies != null && cookies.length > 0) {
|
||||
|
|
@ -327,14 +326,14 @@ public class ParameterMap implements Map<String, Object> {
|
|||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
|
||||
private class ParameterEntry implements Entry<String, Object> {
|
||||
|
||||
private final String key;
|
||||
|
||||
|
||||
private volatile Object value;
|
||||
|
||||
public ParameterEntry(String key){
|
||||
public ParameterEntry(String key) {
|
||||
this.key = key;
|
||||
this.value = ParameterMap.this.get(key);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.server-2.0.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at Jan 24, 2011
|
||||
* $Id: RelateUserUtils.java 181723 2012-06-26 01:56:06Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2100 Alibaba.com Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,19 +15,19 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.common.utils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.alibaba.dubbo.governance.service.OwnerService;
|
||||
import com.alibaba.dubbo.registry.common.route.ParseUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author ding.lid
|
||||
*/
|
||||
public class RelateUserUtils {
|
||||
/**
|
||||
* 添加与服务相关的Owner
|
||||
*
|
||||
*
|
||||
* @param usernames 用于添加的用户名
|
||||
* @param serviceName 不含通配符
|
||||
*/
|
||||
|
|
@ -44,12 +44,12 @@ public class RelateUserUtils {
|
|||
|
||||
/**
|
||||
* 添加与服务模式相关的Owner
|
||||
*
|
||||
*
|
||||
* @param usernames 用于添加的用户名
|
||||
* @param serviceNamePattern 服务模式,Glob模式
|
||||
*/
|
||||
public static void addOwnersOfServicePattern(Set<String> usernames, String serviceNamePattern,
|
||||
OwnerService ownerDAO) {
|
||||
OwnerService ownerDAO) {
|
||||
List<String> serviceNamePatterns = ownerDAO.findAllServiceNames();
|
||||
for (String p : serviceNamePatterns) {
|
||||
if (ParseUtils.hasIntersection(p, serviceNamePattern)) {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,17 @@
|
|||
*/
|
||||
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;
|
||||
|
|
@ -20,31 +31,22 @@ import java.util.Map.Entry;
|
|||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Providers. URI: /services/$service/accesses
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
* @author ding.lid
|
||||
* @author tony.chenl
|
||||
*/
|
||||
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;
|
||||
|
||||
private RouteService routeService;
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
private ProviderService providerService;
|
||||
|
||||
public void index(Map<String, Object> context) throws Exception {
|
||||
String service = (String) context.get("service");
|
||||
|
|
@ -59,28 +61,28 @@ public class Accesses extends Restful {
|
|||
routes = routeService.findAllForceRoute();
|
||||
}
|
||||
List<Access> accesses = new ArrayList<Access>();
|
||||
if(routes == null){
|
||||
if (routes == null) {
|
||||
context.put("accesses", accesses);
|
||||
return;
|
||||
}
|
||||
for(Route route :routes){
|
||||
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()){
|
||||
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()){
|
||||
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);
|
||||
|
|
@ -91,71 +93,66 @@ public class Accesses extends Restful {
|
|||
context.put("serviceList", serviceList);
|
||||
}
|
||||
|
||||
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}$");
|
||||
|
||||
public boolean create(Map<String, Object> context) throws Exception {
|
||||
String addr = (String) context.get("consumerAddress");
|
||||
String services = (String) context.get("service");
|
||||
String services = (String) context.get("service");
|
||||
Set<String> consumerAddresses = toAddr(addr);
|
||||
Set<String> aimServices = toService(services);
|
||||
for(String aimService : aimServices) {
|
||||
for (String aimService : aimServices) {
|
||||
boolean isFirst = false;
|
||||
List<Route> routes = routeService.findForceRouteByService(aimService);
|
||||
Route route = null;
|
||||
if(routes==null||routes.size()==0){
|
||||
if (routes == null || routes.size() == 0) {
|
||||
isFirst = true;
|
||||
route = new Route();
|
||||
route = new Route();
|
||||
route.setService(aimService);
|
||||
route.setForce(true);
|
||||
route.setName(aimService+" blackwhitelist");
|
||||
route.setName(aimService + " blackwhitelist");
|
||||
route.setFilterRule("false");
|
||||
route.setEnabled(true);
|
||||
}else{
|
||||
} else {
|
||||
route = routes.get(0);
|
||||
}
|
||||
Map<String, MatchPair> when = null;
|
||||
MatchPair matchPair = null;
|
||||
if(isFirst){
|
||||
if (isFirst) {
|
||||
when = new HashMap<String, MatchPair>();
|
||||
matchPair = new MatchPair(new HashSet<String>(),new HashSet<String>());
|
||||
matchPair = new MatchPair(new HashSet<String>(), new HashSet<String>());
|
||||
when.put("consumer.host", matchPair);
|
||||
}else{
|
||||
} else {
|
||||
when = RouteRule.parseRule(route.getMatchRule());
|
||||
matchPair = when.get("consumer.host");
|
||||
}
|
||||
for (String consumerAddress : consumerAddresses) {
|
||||
if(Boolean.valueOf((String) context.get("allow"))){
|
||||
if (Boolean.valueOf((String) context.get("allow"))) {
|
||||
matchPair.getUnmatches().add(Tool.getIP(consumerAddress));
|
||||
|
||||
}else{
|
||||
|
||||
} else {
|
||||
matchPair.getMatches().add(Tool.getIP(consumerAddress));
|
||||
}
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
RouteRule.contidionToString(sb,when);
|
||||
RouteRule.contidionToString(sb, when);
|
||||
route.setMatchRule(sb.toString());
|
||||
route.setUsername(operator);
|
||||
if(isFirst){
|
||||
if (isFirst) {
|
||||
routeService.createRoute(route);
|
||||
}else{
|
||||
} else {
|
||||
routeService.updateRoute(route);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private Set<String> toAddr(String addr) throws IOException{
|
||||
|
||||
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)
|
||||
|
|
@ -172,15 +169,15 @@ public class Accesses extends Restful {
|
|||
}
|
||||
return consumerAddresses;
|
||||
}
|
||||
|
||||
private Set<String> toService(String services) throws IOException{
|
||||
Set<String> aimServices = new HashSet<String>();
|
||||
|
||||
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)
|
||||
|
|
@ -193,63 +190,64 @@ public class Accesses extends Restful {
|
|||
|
||||
/**
|
||||
* 删除动作
|
||||
* @throws ParseException
|
||||
*
|
||||
* @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];
|
||||
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);
|
||||
if (addresses == null) {
|
||||
prepareToDeleate.put(service, new HashSet<String>());
|
||||
addresses = prepareToDeleate.get(service);
|
||||
}
|
||||
addresses.add(address);
|
||||
}
|
||||
for(Entry<String, Set<String>> entry : prepareToDeleate.entrySet()){
|
||||
|
||||
for (Entry<String, Set<String>> entry : prepareToDeleate.entrySet()) {
|
||||
|
||||
String service = entry.getKey();
|
||||
List<Route> routes = routeService.findForceRouteByService(service);
|
||||
if(routes == null || routes.size() == 0){
|
||||
if (routes == null || routes.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
for(Route blackwhitelist : routes){
|
||||
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)){
|
||||
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;
|
||||
}
|
||||
}
|
||||
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){
|
||||
if (matches.size() == 0 && unmatches.size() == 0) {
|
||||
routeService.deleteRoute(blackwhitelist.getId());
|
||||
}else{
|
||||
} else {
|
||||
Map<String, MatchPair> condition = new HashMap<String, MatchPair>();
|
||||
condition.put("consumer.host", new MatchPair(matches,unmatches));
|
||||
condition.put("consumer.host", new MatchPair(matches, unmatches));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
RouteRule.contidionToString(sb,condition);
|
||||
RouteRule.contidionToString(sb, condition);
|
||||
blackwhitelist.setMatchRule(sb.toString());
|
||||
routeService.updateRoute(blackwhitelist);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,30 +7,30 @@
|
|||
*/
|
||||
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;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Providers.
|
||||
* URI: /services/$service/providers
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class Addresses extends Restful {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ConsumerService consumerService;
|
||||
|
||||
|
|
@ -39,19 +39,18 @@ public class Addresses extends Restful {
|
|||
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 {
|
||||
} else {
|
||||
providerAddresses = providerService.findAddresses();
|
||||
consumerAddresses = consumerService.findAddresses();
|
||||
}
|
||||
|
||||
|
||||
Set<String> addresses = new TreeSet<String>();
|
||||
if (providerAddresses != null) {
|
||||
addresses.addAll(providerAddresses);
|
||||
|
|
@ -62,17 +61,17 @@ public class Addresses extends Restful {
|
|||
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;
|
||||
|
||||
if ("*".equals(keyword)) return;
|
||||
|
||||
keyword = keyword.toLowerCase();
|
||||
Set<String> newList = new HashSet<String>();
|
||||
Set<String> newProviders = new HashSet<String>();
|
||||
|
|
@ -101,15 +100,15 @@ public class Addresses extends Restful {
|
|||
|
||||
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");
|
||||
Set<String> list = (Set<String>) context.get("addresses");
|
||||
String keyword = (String) context.get("keyword");
|
||||
if(StringUtils.isNotEmpty(keyword)){
|
||||
if (StringUtils.isNotEmpty(keyword)) {
|
||||
keyword = keyword.toLowerCase();
|
||||
for(String o : list){
|
||||
if(o.toLowerCase().indexOf(keyword)!=-1){
|
||||
for (String o : list) {
|
||||
if (o.toLowerCase().indexOf(keyword) != -1) {
|
||||
newList.add(o);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,17 +7,6 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
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;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.ConsumerService;
|
||||
|
|
@ -27,27 +16,38 @@ 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
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
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>();
|
||||
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);
|
||||
|
|
@ -57,19 +57,19 @@ public class Applications extends Restful {
|
|||
applications.addAll(consumerApplications);
|
||||
}
|
||||
context.put("applications", applications);
|
||||
context.put("providerApplications", providerApplications);
|
||||
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
|
||||
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>();
|
||||
List<Override> appOverrides = new ArrayList<Override>();
|
||||
for (Override override : overrides) {
|
||||
if (override.isMatch(service, null, a)) {
|
||||
appOverrides.add(override);
|
||||
appOverrides.add(override);
|
||||
}
|
||||
}
|
||||
Collections.sort(appOverrides, OverrideUtils.OVERRIDE_COMPARATOR);
|
||||
|
|
@ -77,10 +77,10 @@ public class Applications extends Restful {
|
|||
}
|
||||
}
|
||||
}
|
||||
context.put("overrides", application2Overrides);
|
||||
context.put("overrides", application2Overrides);
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (context.get("service") == null
|
||||
&& context.get("application") == null
|
||||
&& context.get("address") == null) {
|
||||
|
|
@ -95,17 +95,17 @@ public class Applications extends Restful {
|
|||
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();
|
||||
if (StringUtils.isNotEmpty(keyword) && !"*".equals(keyword)) {
|
||||
keyword = keyword.toLowerCase();
|
||||
for (String o : applications) {
|
||||
if (o.toLowerCase().indexOf(keyword) != -1) {
|
||||
newList.add(o);
|
||||
|
|
@ -126,18 +126,18 @@ public class Applications extends Restful {
|
|||
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");
|
||||
Set<String> apps = (Set<String>) context.get("applications");
|
||||
String keyword = (String) context.get("keyword");
|
||||
if(StringUtils.isNotEmpty(keyword)){
|
||||
if (StringUtils.isNotEmpty(keyword)) {
|
||||
keyword = keyword.toLowerCase();
|
||||
for(String o : apps){
|
||||
if(o.toLowerCase().indexOf(keyword)!=-1){
|
||||
for (String o : apps) {
|
||||
if (o.toLowerCase().indexOf(keyword) != -1) {
|
||||
newList.add(o);
|
||||
}
|
||||
}
|
||||
|
|
@ -146,110 +146,110 @@ public class Applications extends Restful {
|
|||
}
|
||||
|
||||
public boolean shield(Map<String, Object> context) throws Exception {
|
||||
return mock(context, "force:return null");
|
||||
return mock(context, "force:return null");
|
||||
}
|
||||
|
||||
public boolean tolerant(Map<String, Object> context) throws Exception {
|
||||
return mock(context, "fail:return null");
|
||||
return mock(context, "fail:return null");
|
||||
}
|
||||
|
||||
public boolean recover(Map<String, Object> context) throws Exception {
|
||||
return mock(context, "");
|
||||
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");
|
||||
String service = (String) context.get("service");
|
||||
String applications = (String) context.get("application");
|
||||
if (service == null || service.length() == 0
|
||||
|| applications == null || applications.length() == 0){
|
||||
|| applications == null || applications.length() == 0) {
|
||||
context.put("message", getMessage("NoSuchOperationData"));
|
||||
return false;
|
||||
}
|
||||
if (! super.currentUser.hasServicePrivilege(service)) {
|
||||
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);
|
||||
}
|
||||
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");
|
||||
return allmock(context, "force:return null");
|
||||
}
|
||||
|
||||
public boolean alltolerant(Map<String, Object> context) throws Exception {
|
||||
return allmock(context, "fail:return null");
|
||||
return allmock(context, "fail:return null");
|
||||
}
|
||||
|
||||
public boolean allrecover(Map<String, Object> context) throws Exception {
|
||||
return allmock(context, "");
|
||||
return allmock(context, "");
|
||||
}
|
||||
|
||||
|
||||
private boolean allmock(Map<String, Object> context, String mock) throws Exception {
|
||||
String service = (String) context.get("service");
|
||||
String service = (String) context.get("service");
|
||||
if (service == null || service.length() == 0) {
|
||||
context.put("message", getMessage("NoSuchOperationData"));
|
||||
return false;
|
||||
}
|
||||
if (! super.currentUser.hasServicePrivilege(service)) {
|
||||
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;
|
||||
}
|
||||
for (Override override : overrides) {
|
||||
if (override.isDefault()) {
|
||||
allOverride = override;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (allOverride != null) {
|
||||
Map<String, String> map = StringUtils.parseQueryString(allOverride.getParams());
|
||||
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);
|
||||
allOverride.setParams(StringUtils.toQueryString(map));
|
||||
allOverride.setEnabled(true);
|
||||
allOverride.setOperator(operator);
|
||||
allOverride.setOperatorAddress(operatorAddress);
|
||||
overrideService.updateOverride(allOverride);
|
||||
} else {
|
||||
overrideService.deleteOverride(allOverride.getId());
|
||||
overrideService.deleteOverride(allOverride.getId());
|
||||
}
|
||||
} else if (mock != null && mock.length() > 0) {
|
||||
Override override = new Override();
|
||||
|
|
|
|||
|
|
@ -7,15 +7,6 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.ConsumerService;
|
||||
|
|
@ -33,25 +24,34 @@ 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
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
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");
|
||||
|
|
@ -59,13 +59,13 @@ public class Consumers extends Restful {
|
|||
List<Consumer> consumers;
|
||||
List<Override> overrides;
|
||||
List<Provider> providers = null;
|
||||
List<Route> routes = 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);
|
||||
routes = routeService.findByService(service);
|
||||
}
|
||||
// address
|
||||
else if (address != null && address.length() > 0) {
|
||||
|
|
@ -84,46 +84,46 @@ public class Consumers extends Restful {
|
|||
}
|
||||
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());
|
||||
}
|
||||
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);
|
||||
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 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());
|
||||
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);
|
||||
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;
|
||||
}
|
||||
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));
|
||||
|
|
@ -132,9 +132,9 @@ public class Consumers extends Restful {
|
|||
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());
|
||||
}
|
||||
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());
|
||||
|
|
@ -142,13 +142,13 @@ public class Consumers extends Restful {
|
|||
Override override = consumer.getOverride();
|
||||
if (override != null) {
|
||||
if (newMap.size() > 0) {
|
||||
override.setParams(StringUtils.toQueryString(newMap));
|
||||
override.setParams(StringUtils.toQueryString(newMap));
|
||||
override.setEnabled(true);
|
||||
override.setOperator(operator);
|
||||
override.setOperatorAddress(operatorAddress);
|
||||
overrideService.updateOverride(override);
|
||||
} else {
|
||||
overrideService.deleteOverride(override.getId());
|
||||
overrideService.deleteOverride(override.getId());
|
||||
}
|
||||
} else {
|
||||
override = new Override();
|
||||
|
|
@ -162,40 +162,40 @@ public class Consumers extends Restful {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void routed(Long id, Map<String, Object> context) {
|
||||
show(id, context);
|
||||
show(id, context);
|
||||
}
|
||||
|
||||
public void notified(Long id, Map<String, Object> context) {
|
||||
show(id, context);
|
||||
show(id, context);
|
||||
}
|
||||
|
||||
public void overrided(Long id, Map<String, Object> context) {
|
||||
show(id, context);
|
||||
show(id, context);
|
||||
}
|
||||
|
||||
|
||||
public boolean shield(Long[] ids, Map<String, Object> context) throws Exception {
|
||||
return mock(ids, context, "force:return null");
|
||||
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");
|
||||
return mock(ids, context, "fail:return null");
|
||||
}
|
||||
|
||||
public boolean recover(Long[] ids, Map<String, Object> context) throws Exception {
|
||||
return mock(ids, context, "");
|
||||
return mock(ids, context, "");
|
||||
}
|
||||
|
||||
private boolean mock(Long[] ids, Map<String, Object> context, String mock) throws Exception {
|
||||
if (ids == null || ids.length == 0){
|
||||
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){
|
||||
if (c != null) {
|
||||
consumers.add(c);
|
||||
if (!super.currentUser.hasServicePrivilege(c.getService())) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", c.getService()));
|
||||
|
|
@ -203,12 +203,12 @@ public class Consumers extends Restful {
|
|||
}
|
||||
}
|
||||
}
|
||||
for(Consumer consumer : consumers) {
|
||||
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) {
|
||||
for (Override override : overrides) {
|
||||
Map<String, String> map = StringUtils.parseQueryString(override.getParams());
|
||||
if (mock == null || mock.length() == 0) {
|
||||
map.remove("mock");
|
||||
|
|
@ -216,13 +216,13 @@ public class Consumers extends Restful {
|
|||
map.put("mock", URL.encode(mock));
|
||||
}
|
||||
if (map.size() > 0) {
|
||||
override.setParams(StringUtils.toQueryString(map));
|
||||
override.setParams(StringUtils.toQueryString(map));
|
||||
override.setEnabled(true);
|
||||
override.setOperator(operator);
|
||||
override.setOperatorAddress(operatorAddress);
|
||||
overrideService.updateOverride(override);
|
||||
} else {
|
||||
overrideService.deleteOverride(override.getId());
|
||||
overrideService.deleteOverride(override.getId());
|
||||
}
|
||||
}
|
||||
} else if (mock != null && mock.length() > 0) {
|
||||
|
|
@ -240,52 +240,52 @@ public class Consumers extends Restful {
|
|||
}
|
||||
|
||||
public boolean allshield(Map<String, Object> context) throws Exception {
|
||||
return allmock(context, "force:return null");
|
||||
return allmock(context, "force:return null");
|
||||
}
|
||||
|
||||
public boolean alltolerant(Map<String, Object> context) throws Exception {
|
||||
return allmock(context, "fail:return null");
|
||||
return allmock(context, "fail:return null");
|
||||
}
|
||||
|
||||
public boolean allrecover(Map<String, Object> context) throws Exception {
|
||||
return allmock(context, "");
|
||||
return allmock(context, "");
|
||||
}
|
||||
|
||||
|
||||
private boolean allmock(Map<String, Object> context, String mock) throws Exception {
|
||||
String service = (String) context.get("service");
|
||||
String service = (String) context.get("service");
|
||||
if (service == null || service.length() == 0) {
|
||||
context.put("message", getMessage("NoSuchOperationData"));
|
||||
return false;
|
||||
}
|
||||
if (! super.currentUser.hasServicePrivilege(service)) {
|
||||
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;
|
||||
}
|
||||
for (Override override : overrides) {
|
||||
if (override.isDefault()) {
|
||||
allOverride = override;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (allOverride != null) {
|
||||
Map<String, String> map = StringUtils.parseQueryString(allOverride.getParams());
|
||||
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);
|
||||
allOverride.setParams(StringUtils.toQueryString(map));
|
||||
allOverride.setEnabled(true);
|
||||
allOverride.setOperator(operator);
|
||||
allOverride.setOperatorAddress(operatorAddress);
|
||||
overrideService.updateOverride(allOverride);
|
||||
} else {
|
||||
overrideService.deleteOverride(allOverride.getId());
|
||||
overrideService.deleteOverride(allOverride.getId());
|
||||
}
|
||||
} else if (mock != null && mock.length() > 0) {
|
||||
Override override = new Override();
|
||||
|
|
@ -300,30 +300,30 @@ public class Consumers extends Restful {
|
|||
}
|
||||
|
||||
public boolean allow(Long[] ids, Map<String, Object> context) throws Exception {
|
||||
return access(ids, context, true, false);
|
||||
return access(ids, context, true, false);
|
||||
}
|
||||
|
||||
|
||||
public boolean forbid(Long[] ids, Map<String, Object> context) throws Exception {
|
||||
return access(ids, context, false, false);
|
||||
return access(ids, context, false, false);
|
||||
}
|
||||
|
||||
public boolean onlyallow(Long[] ids, Map<String, Object> context) throws Exception {
|
||||
return access(ids, context, true, true);
|
||||
return access(ids, context, true, true);
|
||||
}
|
||||
|
||||
public boolean onlyforbid(Long[] ids, Map<String, Object> context) throws Exception {
|
||||
return access(ids, context, false, true);
|
||||
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){
|
||||
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){
|
||||
if (c != null) {
|
||||
consumers.add(c);
|
||||
if (!super.currentUser.hasServicePrivilege(c.getService())) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", c.getService()));
|
||||
|
|
@ -332,27 +332,27 @@ public class Consumers extends Restful {
|
|||
}
|
||||
}
|
||||
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 (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()) {
|
||||
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){
|
||||
if (routes == null || routes.size() == 0) {
|
||||
isFirst = true;
|
||||
route = new Route();
|
||||
route = new Route();
|
||||
route.setService(service);
|
||||
route.setForce(true);
|
||||
route.setName(service+" blackwhitelist");
|
||||
route.setName(service + " blackwhitelist");
|
||||
route.setFilterRule("false");
|
||||
route.setEnabled(true);
|
||||
} else {
|
||||
|
|
@ -360,53 +360,53 @@ public class Consumers extends Restful {
|
|||
}
|
||||
Map<String, MatchPair> when = null;
|
||||
MatchPair matchPair = null;
|
||||
if(isFirst){
|
||||
if (isFirst) {
|
||||
when = new HashMap<String, MatchPair>();
|
||||
matchPair = new MatchPair(new HashSet<String>(),new HashSet<String>());
|
||||
matchPair = new MatchPair(new HashSet<String>(), new HashSet<String>());
|
||||
when.put("consumer.host", matchPair);
|
||||
}else{
|
||||
} 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());
|
||||
}
|
||||
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) { // 白名单优先
|
||||
matchPair.getMatches().remove(consumerAddress); // 去掉黑名单中相同数据
|
||||
if (allow) { // 如果允许访问
|
||||
matchPair.getUnmatches().add(consumerAddress); // 加入白名单
|
||||
} else { // 如果禁止访问
|
||||
matchPair.getUnmatches().remove(consumerAddress); // 从白名单中去除
|
||||
}
|
||||
for (String consumerAddress : entry.getValue()) {
|
||||
if (matchPair.getUnmatches().size() > 0) { // 白名单优先
|
||||
matchPair.getMatches().remove(consumerAddress); // 去掉黑名单中相同数据
|
||||
if (allow) { // 如果允许访问
|
||||
matchPair.getUnmatches().add(consumerAddress); // 加入白名单
|
||||
} else { // 如果禁止访问
|
||||
matchPair.getUnmatches().remove(consumerAddress); // 从白名单中去除
|
||||
}
|
||||
} else { // 黑名单生效
|
||||
if (allow) { // 如果允许访问
|
||||
matchPair.getMatches().remove(consumerAddress); // 从黑名单中去除
|
||||
} else { // 如果禁止访问
|
||||
matchPair.getMatches().add(consumerAddress); // 加入黑名单
|
||||
}
|
||||
if (allow) { // 如果允许访问
|
||||
matchPair.getMatches().remove(consumerAddress); // 从黑名单中去除
|
||||
} else { // 如果禁止访问
|
||||
matchPair.getMatches().add(consumerAddress); // 加入黑名单
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
RouteRule.contidionToString(sb,when);
|
||||
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);
|
||||
if (isFirst) {
|
||||
routeService.createRoute(route);
|
||||
} else {
|
||||
routeService.updateRoute(route);
|
||||
routeService.updateRoute(route);
|
||||
}
|
||||
} else if (! isFirst) {
|
||||
routeService.deleteRoute(route.getId());
|
||||
}
|
||||
} else if (!isFirst) {
|
||||
routeService.deleteRoute(route.getId());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,13 +7,6 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.dubbo.common.utils.CollectionUtils;
|
||||
import com.alibaba.dubbo.governance.service.OverrideService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
|
|
@ -23,27 +16,34 @@ 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
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
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());
|
||||
|
|
@ -52,16 +52,16 @@ public class Loadbalances extends Restful {
|
|||
}
|
||||
|
||||
public void show(Long id, Map<String, Object> context) {
|
||||
LoadBalance loadbalance = OverrideUtils.overrideToLoadBalance(overrideService.findById(id));
|
||||
LoadBalance loadbalance = OverrideUtils.overrideToLoadBalance(overrideService.findById(id));
|
||||
context.put("loadbalance", loadbalance);
|
||||
}
|
||||
|
||||
|
||||
public void add(Map<String, Object> context) {
|
||||
String service = (String)context.get("service");
|
||||
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){
|
||||
for (Provider provider : providerList) {
|
||||
addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
|
||||
}
|
||||
context.put("addressList", addressList);
|
||||
|
|
@ -71,37 +71,38 @@ public class Loadbalances extends Restful {
|
|||
List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
|
||||
context.put("serviceList", serviceList);
|
||||
}
|
||||
if(context.get("input") != null) context.put("input", context.get("input"));
|
||||
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);
|
||||
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));
|
||||
|
||||
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));
|
||||
overrideService.updateOverride(OverrideUtils.loadBalanceToOverride(loadBalance));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除动作
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
|
|
@ -113,9 +114,9 @@ public class Loadbalances extends Restful {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (Long id : ids) {
|
||||
overrideService.deleteOverride(id);
|
||||
overrideService.deleteOverride(id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/**
|
||||
* Function:
|
||||
*
|
||||
* Function:
|
||||
* <p>
|
||||
* File Created at 2010-11-17
|
||||
* $Id: NoServicePrivilege.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2009 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import com.alibaba.citrus.turbine.Context;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.citrus.turbine.Context;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* TODO Comment of NoServicePrivilege
|
||||
*
|
||||
*
|
||||
* @author guanghui.shigh
|
||||
*/
|
||||
public class NoServicePrivilege {
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
|
||||
public void execute(Context context) {
|
||||
context.put("returnUrl", request.getParameter("returnUrl"));
|
||||
context.put("returnUrl", request.getParameter("returnUrl"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,17 +15,6 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
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;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.utils.CollectionUtils;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
|
|
@ -35,19 +24,59 @@ 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;
|
||||
|
||||
/**
|
||||
* @author ding.lid
|
||||
*/
|
||||
public class Overrides extends Restful {
|
||||
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");
|
||||
|
|
@ -55,12 +84,11 @@ public class Overrides extends Restful {
|
|||
List<Override> overrides;
|
||||
if (StringUtils.isNotEmpty(service)) {
|
||||
overrides = overrideService.findByService(service);
|
||||
} else if(StringUtils.isNotEmpty(application)){
|
||||
} else if (StringUtils.isNotEmpty(application)) {
|
||||
overrides = overrideService.findByApplication(application);
|
||||
}else if(StringUtils.isNotEmpty(address)){
|
||||
} else if (StringUtils.isNotEmpty(address)) {
|
||||
overrides = overrideService.findByAddress(address);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
overrides = overrideService.findAll();
|
||||
}
|
||||
context.put("overrides", overrides);
|
||||
|
|
@ -68,129 +96,110 @@ public class Overrides extends Restful {
|
|||
|
||||
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) {
|
||||
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();
|
||||
|
||||
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)) {
|
||||
|
||||
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){
|
||||
|
||||
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)){
|
||||
if (StringUtils.isNotEmpty(application)) {
|
||||
serviceList.addAll(providerService.findServicesByApplication(application));
|
||||
serviceList.addAll(consumerService.findServicesByApplication(application));
|
||||
context.put("serviceList", serviceList);
|
||||
}else if(StringUtils.isNotEmpty(service)){
|
||||
} else if (StringUtils.isNotEmpty(service)) {
|
||||
applicationList.addAll(providerService.findApplicationsByServiceName(service));
|
||||
applicationList.addAll(consumerService.findApplicationsByServiceName(service));
|
||||
context.put("applicationList", applicationList);
|
||||
}else{
|
||||
} 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))));
|
||||
}
|
||||
}
|
||||
|
||||
static final Pattern AND = Pattern.compile("\\&");
|
||||
static final Pattern EQUAL = Pattern.compile("([^=\\s]*)\\s*=\\s*(\\S*)");
|
||||
|
||||
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 edit(Long id, Map<String, Object> context) {
|
||||
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){
|
||||
|
||||
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) {
|
||||
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();
|
||||
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)) {
|
||||
|
||||
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;
|
||||
|
|
@ -208,28 +217,10 @@ public class Overrides extends Restful {
|
|||
tokens[1] = mock;
|
||||
return tokens;
|
||||
}
|
||||
|
||||
static final String DEFAULT_MOCK_JSON_KEY = "mock";
|
||||
static final String MOCK_JSON_KEY_POSTFIX = ".mock";
|
||||
|
||||
// FORM KEY
|
||||
|
||||
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";
|
||||
|
||||
|
||||
boolean catchParams(Override override, Map<String, Object> context) {
|
||||
String service = (String) context.get("service");
|
||||
if(service == null || service.trim().length() == 0) {
|
||||
if (service == null || service.trim().length() == 0) {
|
||||
context.put("message", getMessage("service is blank!"));
|
||||
return false;
|
||||
}
|
||||
|
|
@ -237,90 +228,90 @@ public class Overrides extends Restful {
|
|||
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()) {
|
||||
|
||||
for (Map.Entry<String, Object> param : context.entrySet()) {
|
||||
String key = param.getKey().trim();
|
||||
if(! (param.getValue() instanceof String) ) continue;
|
||||
|
||||
if (!(param.getValue() instanceof String)) continue;
|
||||
|
||||
String value = (String) param.getValue();
|
||||
|
||||
if(key.startsWith(FORM_OVERRIDE_KEY) && value != null && value.trim().length() > 0) {
|
||||
|
||||
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) {
|
||||
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) {
|
||||
|
||||
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) {
|
||||
|
||||
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) {
|
||||
|
||||
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) {
|
||||
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;
|
||||
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;
|
||||
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) {
|
||||
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;
|
||||
|
||||
if (!catchParams(override, context)) return false;
|
||||
|
||||
overrideService.saveOverride(override);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean update(Override override,Map<String, Object> context) {
|
||||
|
||||
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;
|
||||
|
||||
|
||||
if (!catchParams(override, context)) return false;
|
||||
|
||||
overrideService.updateOverride(override);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -328,51 +319,49 @@ public class Overrides extends Restful {
|
|||
for (Long id : ids) {
|
||||
overrideService.deleteOverride(id);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean enable(Long[] ids, Map<String, Object> context) {
|
||||
for(Long id : ids){
|
||||
for (Long id : ids) {
|
||||
Override override = overrideService.findById(id);
|
||||
if(override == null){
|
||||
if (override == null) {
|
||||
context.put("message", getMessage("NoSuchOperationData", id));
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
if (!super.currentUser.hasServicePrivilege(override.getService())) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", override.getService()));
|
||||
return false;
|
||||
}
|
||||
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){
|
||||
for (Long id : ids) {
|
||||
Override override = overrideService.findById(id);
|
||||
if(override == null){
|
||||
if (override == null) {
|
||||
context.put("message", getMessage("NoSuchOperationData", id));
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
if (!super.currentUser.hasServicePrivilege(override.getService())) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", override.getService()));
|
||||
return false;
|
||||
}
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", override.getService()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (Long id : ids) {
|
||||
overrideService.disableOverride(id);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,83 +7,83 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class Owners extends Restful {
|
||||
|
||||
@Autowired
|
||||
private OwnerService ownerService;
|
||||
@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) {
|
||||
@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){
|
||||
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)) {
|
||||
if (!super.currentUser.hasServicePrivilege(service)) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", service));
|
||||
return false;
|
||||
}
|
||||
ownerService.saveOwner(owner);
|
||||
return true;
|
||||
}
|
||||
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){
|
||||
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)) {
|
||||
if (!super.currentUser.hasServicePrivilege(service)) {
|
||||
context.put("message", getMessage("HaveNoServicePrivilege", service));
|
||||
return false;
|
||||
}
|
||||
ownerService.deleteOwner(owner);
|
||||
return true;
|
||||
}
|
||||
ownerService.deleteOwner(owner);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,17 +7,6 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.OverrideService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
|
|
@ -27,6 +16,16 @@ 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.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>Providers.</p>
|
||||
* URI: <br>
|
||||
|
|
@ -57,7 +56,7 @@ import com.alibaba.dubbo.registry.common.util.Tool;
|
|||
* GET /services/$service/providers/$id/disable 禁用<br>
|
||||
* GET /services/$service/providers/$id/reconnect 重连<br>
|
||||
* GET /services/$service/providers/$id/recover 恢复<br>
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class Providers extends Restful {
|
||||
|
|
@ -67,121 +66,123 @@ public class Providers extends Restful {
|
|||
|
||||
@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 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);
|
||||
|
||||
|
||||
// 设置搜索结果到cookie中
|
||||
setSearchHistroy(context, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置search记录到cookie中,操作步骤:
|
||||
* 检查加入的记录是否已经存在cookie中,如果存在,则更新列表次序;如果不存在,则插入到最前面
|
||||
*
|
||||
* @param context
|
||||
* @param value
|
||||
*/
|
||||
private void setSearchHistroy(Map<String, Object> context, String value) {
|
||||
//分析已有的cookie
|
||||
String separatorsB = "\\.\\.\\.\\.\\.\\.";
|
||||
//分析已有的cookie
|
||||
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); // 设置Cookie的存活时间为30分钟
|
||||
_cookie.setPath("/");
|
||||
response.addCookie(_cookie); // 写入客户端硬盘
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public void show(Long id, Map<String, Object> context) {
|
||||
Cookie _cookie = new Cookie("HISTORY", newCookiev);
|
||||
_cookie.setMaxAge(60 * 60 * 24 * 7); // 设置Cookie的存活时间为30分钟
|
||||
_cookie.setPath("/");
|
||||
response.addCookie(_cookie); // 写入客户端硬盘
|
||||
}
|
||||
|
||||
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);
|
||||
List<Override> overrides = overrideService.findByServiceAndAddress(provider.getService(), provider.getAddress());
|
||||
OverrideUtils.setProviderOverrides(provider, overrides);
|
||||
}
|
||||
context.put("provider", provider);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 装载新增服务页面,获取所有的服务名称
|
||||
*
|
||||
* @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));
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
show(id, context);
|
||||
}
|
||||
|
||||
public boolean create(Provider provider, Map<String, Object> context) {
|
||||
|
|
@ -191,14 +192,14 @@ public class Providers extends Restful {
|
|||
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));
|
||||
}
|
||||
}
|
||||
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
|
||||
providerService.create(provider);
|
||||
|
|
@ -206,13 +207,13 @@ public class Providers extends Restful {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
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));
|
||||
|
|
@ -221,24 +222,24 @@ public class Providers extends Restful {
|
|||
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 (entry.getValue().equals(newMap.get(entry.getKey()))) {
|
||||
newMap.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
if (provider.isDynamic()) {
|
||||
if (provider.isDynamic()) {
|
||||
String address = provider.getAddress();
|
||||
List<Override> overrides = overrideService.findByServiceAndAddress(provider.getService(), provider.getAddress());
|
||||
OverrideUtils.setProviderOverrides(provider, overrides);
|
||||
Override override = provider.getOverride();
|
||||
OverrideUtils.setProviderOverrides(provider, overrides);
|
||||
Override override = provider.getOverride();
|
||||
if (override != null) {
|
||||
if (newMap.size() > 0) {
|
||||
override.setParams(StringUtils.toQueryString(newMap));
|
||||
override.setParams(StringUtils.toQueryString(newMap));
|
||||
override.setEnabled(true);
|
||||
override.setOperator(operator);
|
||||
override.setOperatorAddress(operatorAddress);
|
||||
overrideService.updateOverride(override);
|
||||
} else {
|
||||
overrideService.deleteOverride(override.getId());
|
||||
overrideService.deleteOverride(override.getId());
|
||||
}
|
||||
} else {
|
||||
override = new Override();
|
||||
|
|
@ -250,101 +251,101 @@ public class Providers extends Restful {
|
|||
override.setOperatorAddress(operatorAddress);
|
||||
overrideService.saveOverride(override);
|
||||
}
|
||||
} else {
|
||||
provider.setParameters(parameters);
|
||||
providerService.updateProvider(provider);
|
||||
}
|
||||
} 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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,16 +7,6 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
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;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.dubbo.common.utils.CollectionUtils;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.ConsumerService;
|
||||
|
|
@ -32,456 +22,69 @@ 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
|
||||
*
|
||||
*
|
||||
* @author ding.lid
|
||||
* @author william.liangf
|
||||
* @author tony.chenl
|
||||
*/
|
||||
public class Routes extends Restful {
|
||||
|
||||
private static final int MAX_RULE_LENGTH = 1000;
|
||||
|
||||
|
||||
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"}, // 要校验Cluster是否存在
|
||||
{"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 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"}, // 要校验Cluster是否存在
|
||||
{"provider.host", "providerHost", "unproviderHost"},
|
||||
{"provider.protocol", "providerProtocol", "unproviderProtocol"},
|
||||
{"provider.port", "providerPort", "unproviderPort"},
|
||||
{"provider.version", "providerVersion", "unproviderVersion"},
|
||||
{"provider.group", "providerGroup", "unproviderGroup"}
|
||||
};
|
||||
|
||||
/**
|
||||
* 路由模块首页
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示路由详细信息
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 载入新增路由页面
|
||||
* @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"));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 载入修改路由页面
|
||||
* @param context
|
||||
*/
|
||||
public void edit(Map<String, Object> context) {
|
||||
add(context);
|
||||
show(context);
|
||||
}
|
||||
|
||||
static void checkService(String service) {
|
||||
if(service.contains(",")) throw new IllegalStateException("service(" + service + ") contain illegale ','");
|
||||
|
||||
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);
|
||||
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) {
|
||||
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!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存路由信息到数据库中
|
||||
* @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])); // value不为null的情况,这里处理,后面会保证
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
//限制表达式的长度
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新数据到数据库中
|
||||
* @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;
|
||||
}
|
||||
//判断参数,拼凑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])); // value不为null的情况,这里处理,后面会保证
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
//限制表达式的长度
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定ID的route规则
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
public boolean delete(Long[] ids, Map<String, Object> context) {
|
||||
for (Long id : ids) {
|
||||
routeService.deleteRoute(id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用指定ID的route规则(可以批量处理)
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
public boolean enable(Long[] ids, Map<String, Object> context) {
|
||||
for(Long id : ids){
|
||||
routeService.enableRoute(id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用指定ID的route规则(可以批量处理)
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
public boolean disable(Long[] ids, Map<String, Object> context) {
|
||||
for(Long id : ids){
|
||||
routeService.disableRoute(id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择消费者
|
||||
* @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);
|
||||
// 获取数据
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加与服务相关的Owner
|
||||
*
|
||||
* @param usernames 用于添加的用户名
|
||||
*
|
||||
* @param usernames 用于添加的用户名
|
||||
* @param serviceName 不含通配符
|
||||
*/
|
||||
public static void addOwnersOfService(Set<String> usernames, String serviceName,
|
||||
|
|
@ -497,12 +100,12 @@ public class Routes extends Restful {
|
|||
|
||||
/**
|
||||
* 添加与服务模式相关的Owner
|
||||
*
|
||||
* @param usernames 用于添加的用户名
|
||||
*
|
||||
* @param usernames 用于添加的用户名
|
||||
* @param serviceNamePattern 服务模式,Glob模式
|
||||
*/
|
||||
public static void addOwnersOfServicePattern(Set<String> usernames, String serviceNamePattern,
|
||||
OwnerService ownerDAO) {
|
||||
OwnerService ownerDAO) {
|
||||
List<String> serviceNamePatterns = ownerDAO.findAllServiceNames();
|
||||
for (String p : serviceNamePatterns) {
|
||||
if (ParseUtils.hasIntersection(p, serviceNamePattern)) {
|
||||
|
|
@ -511,4 +114,404 @@ public class Routes extends Restful {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 路由模块首页
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示路由详细信息
|
||||
*
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 载入新增路由页面
|
||||
*
|
||||
* @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"));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 载入修改路由页面
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public void edit(Map<String, Object> context) {
|
||||
add(context);
|
||||
show(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存路由信息到数据库中
|
||||
*
|
||||
* @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])); // value不为null的情况,这里处理,后面会保证
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
//限制表达式的长度
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新数据到数据库中
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
//判断参数,拼凑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])); // value不为null的情况,这里处理,后面会保证
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
//限制表达式的长度
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定ID的route规则
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
public boolean delete(Long[] ids, Map<String, Object> context) {
|
||||
for (Long id : ids) {
|
||||
routeService.deleteRoute(id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用指定ID的route规则(可以批量处理)
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
public boolean enable(Long[] ids, Map<String, Object> context) {
|
||||
for (Long id : ids) {
|
||||
routeService.enableRoute(id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用指定ID的route规则(可以批量处理)
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
public boolean disable(Long[] ids, Map<String, Object> context) {
|
||||
for (Long id : ids) {
|
||||
routeService.disableRoute(id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择消费者
|
||||
*
|
||||
* @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);
|
||||
// 获取数据
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,17 +7,6 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
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;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.ConsumerService;
|
||||
|
|
@ -28,32 +17,43 @@ 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
|
||||
*
|
||||
*
|
||||
* @author ding.lid
|
||||
*/
|
||||
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;
|
||||
|
|
@ -70,7 +70,7 @@ public class Services extends Restful {
|
|||
consumerServices = consumerService.findServices();
|
||||
overrides = overrideService.findAll();
|
||||
}
|
||||
|
||||
|
||||
Set<String> services = new TreeSet<String>();
|
||||
if (providerServices != null) {
|
||||
services.addAll(providerServices);
|
||||
|
|
@ -78,16 +78,16 @@ public class Services extends Restful {
|
|||
if (consumerServices != null) {
|
||||
services.addAll(consumerServices);
|
||||
}
|
||||
|
||||
|
||||
Map<String, List<Override>> service2Overrides = new HashMap<String, List<Override>>();
|
||||
if (overrides != null && overrides.size() > 0
|
||||
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);
|
||||
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);
|
||||
|
|
@ -95,19 +95,19 @@ public class Services extends Restful {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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)) {
|
||||
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);
|
||||
|
|
@ -130,61 +130,61 @@ public class Services extends Restful {
|
|||
}
|
||||
|
||||
public boolean shield(Map<String, Object> context) throws Exception {
|
||||
return mock(context, "force:return null");
|
||||
return mock(context, "force:return null");
|
||||
}
|
||||
|
||||
public boolean tolerant(Map<String, Object> context) throws Exception {
|
||||
return mock(context, "fail:return null");
|
||||
return mock(context, "fail:return null");
|
||||
}
|
||||
|
||||
public boolean recover(Map<String, Object> context) throws Exception {
|
||||
return mock(context, "");
|
||||
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");
|
||||
String services = (String) context.get("service");
|
||||
String application = (String) context.get("application");
|
||||
if (services == null || services.length() == 0
|
||||
|| application == null || application.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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,19 +7,6 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.governance.module.screen;
|
||||
|
||||
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;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.dubbo.common.utils.CollectionUtils;
|
||||
import com.alibaba.dubbo.governance.service.OverrideService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
|
|
@ -29,20 +16,35 @@ 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
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
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");
|
||||
|
|
@ -57,19 +59,18 @@ public class Weights extends Restful {
|
|||
}
|
||||
context.put("weights", weights);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* load页面供新增操作
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public void add(Map<String, Object> context) {
|
||||
String service = (String)context.get("service");
|
||||
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){
|
||||
for (Provider provider : providerList) {
|
||||
addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
|
||||
}
|
||||
context.put("addressList", addressList);
|
||||
|
|
@ -79,51 +80,47 @@ public class Weights extends Restful {
|
|||
List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
|
||||
context.put("serviceList", serviceList);
|
||||
}
|
||||
if(context.get("input") != null) context.put("input", context.get("input"));
|
||||
if (context.get("input") != null) context.put("input", context.get("input"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* load页面供新增操作
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public void multiadd(Map<String, Object> context) {
|
||||
List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
|
||||
context.put("serviceList", serviceList);
|
||||
}
|
||||
|
||||
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}$");
|
||||
|
||||
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 services = (String) context.get("multiservice");
|
||||
if (services == null || services.trim().length() == 0) {
|
||||
services = (String) context.get("service");
|
||||
}
|
||||
String weight = (String) context.get("weight");
|
||||
|
||||
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) {
|
||||
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 (port.trim().length() == 0) port = null;
|
||||
}
|
||||
if (!IP_PATTERN.matcher(ip).matches()) {
|
||||
context.put("message", "illegal IP: " + s);
|
||||
|
|
@ -133,8 +130,8 @@ public class Weights extends Restful {
|
|||
context.put("message", "local IP or any host ip is illegal: " + s);
|
||||
return false;
|
||||
}
|
||||
if(port != null) {
|
||||
if(!NumberUtils.isDigits(port)) {
|
||||
if (port != null) {
|
||||
if (!NumberUtils.isDigits(port)) {
|
||||
context.put("message", "illegal port: " + s);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -142,14 +139,14 @@ public class Weights extends Restful {
|
|||
addresses.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> aimServices = new HashSet<String>();
|
||||
|
||||
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)
|
||||
|
|
@ -161,11 +158,11 @@ public class Weights extends Restful {
|
|||
aimServices.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
for(String aimService : aimServices) {
|
||||
|
||||
for (String aimService : aimServices) {
|
||||
for (String a : addresses) {
|
||||
Weight wt = new Weight();
|
||||
wt.setUsername((String)context.get("operator"));
|
||||
wt.setUsername((String) context.get("operator"));
|
||||
wt.setAddress(Tool.getIP(a));
|
||||
wt.setService(aimService);
|
||||
wt.setWeight(w);
|
||||
|
|
@ -180,34 +177,36 @@ public class Weights extends Restful {
|
|||
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对象供编辑操作
|
||||
*
|
||||
* @param id
|
||||
* @param context
|
||||
*/
|
||||
public void show(Long id, Map<String, Object> context) {
|
||||
Weight weight = OverrideUtils.overrideToWeight(overrideService.findById(id));
|
||||
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));
|
||||
overrideService.updateOverride(OverrideUtils.weightToOverride(weight));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除动作
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
|
|
@ -219,9 +218,9 @@ public class Weights extends Restful {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (Long id : ids) {
|
||||
overrideService.deleteOverride(id);
|
||||
overrideService.deleteOverride(id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,14 @@
|
|||
/**
|
||||
* Function:
|
||||
*
|
||||
* Function:
|
||||
* <p>
|
||||
* File Created at 2010-11-17
|
||||
* $Id: Menu.java 185206 2012-07-09 03:06:37Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2009 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.control;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.citrus.service.requestcontext.parser.CookieParser;
|
||||
import com.alibaba.citrus.turbine.Context;
|
||||
import com.alibaba.dubbo.governance.sync.RegistryServerSync;
|
||||
|
|
@ -22,6 +16,12 @@ 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;
|
||||
|
||||
/**
|
||||
* @author guanghui.shigh
|
||||
* @author ding.lid
|
||||
|
|
@ -29,27 +29,25 @@ import com.alibaba.dubbo.registry.common.domain.User;
|
|||
*/
|
||||
public class Menu {
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
@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("bucLogoutAddress")) {
|
||||
context.put("bucLogoutAddress", rootContextPath.getURI("logout"));
|
||||
}
|
||||
if (! context.containsKey("helpUrl")) {
|
||||
context.put("helpUrl", "http://code.alibabatech.com/wiki/display/dubbo");
|
||||
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"));
|
||||
|
|
|
|||
|
|
@ -7,15 +7,14 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tony.chenl
|
||||
|
|
@ -23,8 +22,8 @@ import com.alibaba.dubbo.registry.common.domain.Provider;
|
|||
public class Disable extends Shell {
|
||||
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
|
||||
private ProviderService providerService;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
|
|
@ -32,28 +31,28 @@ public class Disable extends Shell {
|
|||
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.";
|
||||
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.";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,15 +15,6 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.citrus.turbine.Context;
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
import com.alibaba.dubbo.common.logger.LoggerFactory;
|
||||
|
|
@ -33,9 +24,17 @@ 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
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class Index {
|
||||
|
|
@ -44,16 +43,16 @@ public class Index {
|
|||
|
||||
@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>();
|
||||
Set<String> services = new HashSet<String>();
|
||||
List<Provider> pList = new ArrayList<Provider>();
|
||||
try {
|
||||
pList = providerService.findAll();
|
||||
|
|
@ -64,7 +63,7 @@ public class Index {
|
|||
applications.add(p.getApplication());
|
||||
services.add(p.getService());
|
||||
}
|
||||
List<Consumer> cList = new ArrayList<Consumer>();
|
||||
List<Consumer> cList = new ArrayList<Consumer>();
|
||||
try {
|
||||
cList = consumerService.findAll();
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -15,68 +15,68 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author tony.chenl
|
||||
*/
|
||||
public class Lookup extends Restful{
|
||||
|
||||
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()){
|
||||
if (inf == null || inf.isEmpty()) {
|
||||
throw new IllegalArgumentException("please give me the interface");
|
||||
}
|
||||
String group = null;
|
||||
if(inf.contains("/")) {
|
||||
if (inf.contains("/")) {
|
||||
int idx = inf.indexOf('/');
|
||||
group = inf.substring(idx);
|
||||
inf = inf.substring(idx + 1, inf.length());
|
||||
}
|
||||
String version = null;
|
||||
if(inf.contains(":")) {
|
||||
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) {
|
||||
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) {
|
||||
if (group != null) {
|
||||
u.addParameter("group", group);
|
||||
}
|
||||
|
||||
if(version != null) u.addParameter("version", version);
|
||||
|
||||
|
||||
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, 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) {
|
||||
|
||||
for (URL u2 : lookup) {
|
||||
urls.put(u2.toIdentityString(), u2.toParameterString());
|
||||
}
|
||||
|
||||
|
||||
Result result = new Result();
|
||||
result.setMessage(serviceUrl);
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -24,15 +24,15 @@ import java.util.Map;
|
|||
public class Reg extends Restful {
|
||||
|
||||
public Result doExecute(Map<String, Object> context) throws Exception {
|
||||
if(url==null){
|
||||
if (url == null) {
|
||||
throw new IllegalArgumentException("please give me the url");
|
||||
}
|
||||
if(url.getPath().isEmpty()){
|
||||
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>>();
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -7,18 +7,17 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author tony.chenl
|
||||
*/
|
||||
|
|
@ -29,35 +28,35 @@ public class Register extends Shell {
|
|||
|
||||
@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();
|
||||
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");
|
||||
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());
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,39 +7,36 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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 {
|
||||
|
||||
@Autowired
|
||||
private HttpServletResponse response;
|
||||
|
||||
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
|
||||
// RegistryValidator registryService;
|
||||
|
||||
protected String role = null;
|
||||
protected String operator = null;
|
||||
protected User currentUser = null;
|
||||
protected String operatorAddress = null;
|
||||
protected URL url = null;
|
||||
@Autowired
|
||||
private HttpServletResponse response;
|
||||
|
||||
public void execute(Map<String, Object> context) throws Exception {
|
||||
Result result = new Result();
|
||||
if(request.getParameter("url")!=null){
|
||||
if (request.getParameter("url") != null) {
|
||||
url = URL.valueOf(URL.decode(request.getParameter("url")));
|
||||
}
|
||||
if (context.get(WebConstants.CURRENT_USER_KEY) != null) {
|
||||
|
|
@ -50,7 +47,7 @@ public abstract class Restful {
|
|||
context.put(WebConstants.CURRENT_USER_KEY, user);
|
||||
}
|
||||
operatorAddress = (String) context.get("clientid");
|
||||
if(operatorAddress==null || operatorAddress.isEmpty()){
|
||||
if (operatorAddress == null || operatorAddress.isEmpty()) {
|
||||
operatorAddress = (String) context.get("request.remoteHost");
|
||||
}
|
||||
context.put("operator", operator);
|
||||
|
|
@ -69,7 +66,7 @@ public abstract class Restful {
|
|||
// result.setCode(2);
|
||||
// result.setMessage(t.getMessage());
|
||||
// }
|
||||
catch (Throwable t){
|
||||
catch (Throwable t) {
|
||||
result.setStatus("ERROR");
|
||||
result.setCode(1);
|
||||
result.setMessage(t.getMessage());
|
||||
|
|
@ -82,7 +79,7 @@ public abstract class Restful {
|
|||
} catch (Exception e) {
|
||||
response.setStatus(500);
|
||||
os.print(e.getMessage());
|
||||
}finally{
|
||||
} finally {
|
||||
os.flush();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ import java.io.Serializable;
|
|||
public class Result implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 4922467873471920132L;
|
||||
private String status;
|
||||
private Object message;
|
||||
private int code;
|
||||
private String status;
|
||||
private Object message;
|
||||
private int code;
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
|
|
@ -42,12 +42,12 @@ public class Result implements Serializable {
|
|||
public void setMessage(Object message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/**
|
||||
* Project: dubbo.registry-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-5-14
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2010 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -21,36 +21,36 @@ package com.alibaba.dubbo.governance.web.home.module.screen;
|
|||
* use it only in accordance with the terms of the license agreement you entered
|
||||
* into with Alibaba.com.
|
||||
*/
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tony.chenl
|
||||
*/
|
||||
public class Servicestatus{
|
||||
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 {
|
||||
public void execute(Map<String, Object> context) throws Exception {
|
||||
String uri = request.getRequestURI();
|
||||
String contextPath = request.getContextPath();
|
||||
if (contextPath != null && ! "/".equals(contextPath)) {
|
||||
if (contextPath != null && !"/".equals(contextPath)) {
|
||||
uri = uri.substring(contextPath.length());
|
||||
}
|
||||
if (uri.startsWith("/status/")) {
|
||||
|
|
|
|||
|
|
@ -7,66 +7,62 @@
|
|||
*/
|
||||
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;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.dubbo.governance.web.util.WebConstants;
|
||||
import com.alibaba.dubbo.registry.common.domain.User;
|
||||
|
||||
public abstract class Shell {
|
||||
@Autowired
|
||||
private HttpServletResponse response;
|
||||
|
||||
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;
|
||||
|
||||
public void execute(Map<String,Object> context) throws Exception {
|
||||
if(context.get(WebConstants.CURRENT_USER_KEY)!=null){
|
||||
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");
|
||||
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()));
|
||||
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();
|
||||
}
|
||||
PrintWriter writer = response.getWriter();
|
||||
writer.print(context.get("message"));
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
protected abstract String doExecute(Map<String,Object> context) throws Exception;
|
||||
|
||||
private static final Pattern OK_PATTERN = Pattern.compile("ok", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
private static final Pattern ERROR_PATTERN = Pattern.compile("error", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
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");
|
||||
}
|
||||
protected abstract String doExecute(Map<String, Object> context) throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,13 @@
|
|||
*/
|
||||
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;
|
||||
|
|
@ -14,22 +21,22 @@ import java.util.Date;
|
|||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.dubbo.common.status.Status.Level;
|
||||
import com.alibaba.dubbo.common.status.StatusChecker;
|
||||
import com.alibaba.dubbo.registry.common.StatusManager;
|
||||
|
||||
/**
|
||||
* @author tony.chenl
|
||||
*/
|
||||
public class Status{
|
||||
public class Status {
|
||||
private static final Pattern OK_PATTERN = Pattern.compile("o(k)", Pattern.CASE_INSENSITIVE);
|
||||
@Autowired
|
||||
private HttpServletResponse response;
|
||||
|
||||
public void execute(Map<String,Object> context) throws Exception {
|
||||
public static String filterOK(String message) {
|
||||
if (message == null)
|
||||
return "";
|
||||
// 避免ok关键字,用数字0代替字母o
|
||||
return OK_PATTERN.matcher(message).replaceAll("0$1");
|
||||
}
|
||||
|
||||
public void execute(Map<String, Object> context) throws Exception {
|
||||
//FIXME cache监控存在性能问题 汇总页面去掉
|
||||
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);
|
||||
|
|
@ -45,15 +52,6 @@ public class Status{
|
|||
writer.print(context.get("message").toString());
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
private static final Pattern OK_PATTERN = Pattern.compile("o(k)", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
public static String filterOK(String message) {
|
||||
if (message == null)
|
||||
return "";
|
||||
// 避免ok关键字,用数字0代替字母o
|
||||
return OK_PATTERN.matcher(message).replaceAll("0$1");
|
||||
}
|
||||
|
||||
public void setStatusHandlers(Collection<StatusChecker> statusHandlers) {
|
||||
StatusManager.getInstance().addStatusHandlers(statusHandlers);
|
||||
|
|
|
|||
|
|
@ -22,30 +22,31 @@ import java.util.Set;
|
|||
|
||||
/**
|
||||
* UnReg.java
|
||||
*
|
||||
* @author tony.chenl
|
||||
*/
|
||||
public class Unreg extends Restful{
|
||||
|
||||
public class Unreg extends Restful {
|
||||
|
||||
public Result doExecute(Map<String, Object> context) throws Exception {
|
||||
if(url==null){
|
||||
if (url == null) {
|
||||
throw new IllegalArgumentException("please give me the url");
|
||||
}
|
||||
if(url.getPath().isEmpty()){
|
||||
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>();
|
||||
Set<String> serviceUrl = new HashSet<String>();
|
||||
serviceUrl.add(url.toIdentityString());
|
||||
String name = url.getPath();
|
||||
String version =url.getParameter("version");
|
||||
if(version != null){
|
||||
String version = url.getParameter("version");
|
||||
if (version != null) {
|
||||
name = name + ":" + version;
|
||||
}
|
||||
String group =url.getParameter("group");
|
||||
if(group != null){
|
||||
String group = url.getParameter("group");
|
||||
if (group != null) {
|
||||
name = group + "/" + name;
|
||||
}
|
||||
services.put(name,serviceUrl);
|
||||
services.put(name, serviceUrl);
|
||||
// registryService.unregister(operatorAddress,services);
|
||||
Result result = new Result();
|
||||
result.setMessage("Unregister Successfully!");
|
||||
|
|
|
|||
|
|
@ -7,51 +7,50 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author tony.chenl
|
||||
*/
|
||||
public class Unregister extends Shell {
|
||||
|
||||
@Autowired
|
||||
private ProviderService providervice;
|
||||
|
||||
private ProviderService providervice;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected String doExecute(Map<String,Object> context) throws Exception {
|
||||
Map<String, String[]> params = request.getParameterMap();
|
||||
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");
|
||||
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())) {
|
||||
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());
|
||||
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.";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,15 +7,14 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.home.module.screen;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
import com.alibaba.dubbo.registry.common.domain.Provider;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tony.chenl
|
||||
|
|
@ -23,33 +22,33 @@ import com.alibaba.dubbo.registry.common.domain.Provider;
|
|||
public class Unregisterall extends Shell {
|
||||
|
||||
@Autowired
|
||||
private ProviderService providerService;
|
||||
|
||||
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.";
|
||||
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,13 +1,13 @@
|
|||
package com.alibaba.dubbo.governance.web.personal.module.screen;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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;
|
||||
|
|
@ -16,7 +16,7 @@ public class Infos extends Restful {
|
|||
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());
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
package com.alibaba.dubbo.governance.web.personal.module.screen;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -15,6 +15,16 @@
|
|||
*/
|
||||
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;
|
||||
|
|
@ -26,27 +36,16 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author tony.chenl
|
||||
*/
|
||||
public class Dump extends Restful {
|
||||
|
||||
@Autowired
|
||||
ProviderService providerDAO;
|
||||
|
||||
@Autowired
|
||||
ConsumerService consumerDAO;
|
||||
ProviderService providerDAO;
|
||||
|
||||
@Autowired
|
||||
ConsumerService consumerDAO;
|
||||
|
||||
@Autowired
|
||||
HttpServletResponse response;
|
||||
|
|
@ -106,7 +105,7 @@ public class Dump extends Restful {
|
|||
writer.flush();
|
||||
response.setContentType("text/plain");
|
||||
}
|
||||
|
||||
|
||||
public void versions(Map<String, Object> context) throws IOException {
|
||||
PrintWriter writer = response.getWriter();
|
||||
List<Provider> providers = providerDAO.findAll();
|
||||
|
|
@ -141,7 +140,7 @@ public class Dump extends Restful {
|
|||
writer.flush();
|
||||
response.setContentType("text/plain");
|
||||
}
|
||||
|
||||
|
||||
private List<String> getNoProviders() {
|
||||
List<String> providerServices = providerDAO.findServices();
|
||||
List<String> consumerServices = consumerDAO.findServices();
|
||||
|
|
|
|||
|
|
@ -15,28 +15,27 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.sysinfo.module.screen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author tony.chenl
|
||||
*/
|
||||
public class Dumps extends Restful {
|
||||
|
||||
@Autowired
|
||||
ProviderService providerDAO;
|
||||
ProviderService providerDAO;
|
||||
|
||||
@Autowired
|
||||
ConsumerService consumerDAO;
|
||||
ConsumerService consumerDAO;
|
||||
|
||||
@Autowired
|
||||
HttpServletResponse response;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.console-2.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at Sep 13, 2011
|
||||
* $Id: Envs.java 185206 2012-07-09 03:06:37Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2100 Alibaba.com Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,6 +15,10 @@
|
|||
*/
|
||||
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;
|
||||
|
|
@ -22,15 +26,16 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.alibaba.dubbo.common.Version;
|
||||
import com.alibaba.dubbo.common.utils.NetUtils;
|
||||
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
||||
|
||||
/**
|
||||
* @author ding.lid
|
||||
*/
|
||||
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();
|
||||
|
|
@ -46,20 +51,12 @@ public class Envs extends Restful {
|
|||
+ 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()))
|
||||
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 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;
|
||||
|
||||
|
||||
private String formatUptime(long uptime) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
if (uptime > DAY) {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,11 @@
|
|||
*/
|
||||
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;
|
||||
|
|
@ -23,11 +28,6 @@ import java.text.SimpleDateFormat;
|
|||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author tony.chenl
|
||||
*/
|
||||
|
|
@ -68,15 +68,15 @@ public class Logs extends Restful {
|
|||
context.put("modified", modified);
|
||||
context.put("content", content);
|
||||
}
|
||||
|
||||
|
||||
public boolean change(Map<String, Object> context) throws Exception {
|
||||
String contextLevel = (String)context.get("level");
|
||||
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"));
|
||||
if (!User.ROOT.equals(role)) {
|
||||
context.put("message", getMessage("HaveNoRootPrivilege"));
|
||||
return false;
|
||||
}
|
||||
Level level = Level.valueOf(contextLevel);
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.console-2.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at Sep 13, 2011
|
||||
* $Id: Status.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2100 Alibaba.com Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,27 +15,27 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.sysinfo.module.screen;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author ding.lid
|
||||
*/
|
||||
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>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,15 +15,6 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.sysinfo.module.screen;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.dubbo.common.utils.StringUtils;
|
||||
import com.alibaba.dubbo.governance.service.ConsumerService;
|
||||
import com.alibaba.dubbo.governance.service.ProviderService;
|
||||
|
|
@ -31,16 +22,25 @@ 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;
|
||||
|
||||
/**
|
||||
* @author tony.chenl
|
||||
*/
|
||||
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();
|
||||
|
|
@ -57,7 +57,7 @@ public class Versions extends Restful {
|
|||
Map<String, String> parameter = StringUtils.parseQueryString(temp.next());
|
||||
if (parameter != null) {
|
||||
String dubbo = parameter.get("dubbo");
|
||||
if(dubbo == null) dubbo = "0.0.0";
|
||||
if (dubbo == null) dubbo = "0.0.0";
|
||||
String application = parameter.get("application");
|
||||
if (versions.get(dubbo) == null) {
|
||||
Set<String> apps = new HashSet<String>();
|
||||
|
|
@ -70,7 +70,7 @@ public class Versions extends Restful {
|
|||
}
|
||||
|
||||
public void show(Long[] ids, Map<String, Object> context) {
|
||||
String version =(String)context.get("version");
|
||||
String version = (String) context.get("version");
|
||||
if (version != null && version.length() > 0) {
|
||||
List<Provider> providers = providerService.findAll();
|
||||
List<Consumer> consumers = consumerService.findAll();
|
||||
|
|
@ -87,7 +87,7 @@ public class Versions extends Restful {
|
|||
Map<String, String> parameter = StringUtils.parseQueryString(temp.next());
|
||||
if (parameter != null) {
|
||||
String dubbo = parameter.get("dubbo");
|
||||
if(dubbo == null) dubbo = "0.0.0";
|
||||
if (dubbo == null) dubbo = "0.0.0";
|
||||
String application = parameter.get("application");
|
||||
if (version.equals(dubbo)) {
|
||||
applications.add(application);
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.console-2.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at Sep 13, 2011
|
||||
* $Id: Configs.java 181723 2012-06-26 01:56:06Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2100 Alibaba.com Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,6 +15,14 @@
|
|||
*/
|
||||
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;
|
||||
|
|
@ -22,35 +30,27 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author ding.lid
|
||||
*/
|
||||
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();;
|
||||
Map<String, String[]> all = request.getParameterMap();
|
||||
;
|
||||
if (all != null && all.size() > 0) {
|
||||
if (! User.ROOT.equals(currentUser.getRole())) {
|
||||
if (!User.ROOT.equals(currentUser.getRole())) {
|
||||
context.put("message", getMessage("HaveNoRootPrivilege"));
|
||||
return false;
|
||||
}
|
||||
|
|
@ -58,7 +58,7 @@ public class Configs extends Restful {
|
|||
for (Map.Entry<String, String[]> entry : all.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String[] values = entry.getValue();
|
||||
if (key != null && key.length() > 0 && ! key.startsWith("_")) {
|
||||
if (key != null && key.length() > 0 && !key.startsWith("_")) {
|
||||
String value = "";
|
||||
if (values != null && values.length > 0
|
||||
&& values[0] != null && values[0].length() > 0) {
|
||||
|
|
@ -74,10 +74,10 @@ public class Configs extends Restful {
|
|||
}
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.console-2.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at Sep 13, 2011
|
||||
* $Id: Privileges.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2100 Alibaba.com Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -22,5 +22,5 @@ import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
|
|||
*
|
||||
*/
|
||||
public class Privileges extends Restful {
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,29 +7,29 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.sysmanage.module.screen;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class Userown extends Restful {
|
||||
|
||||
@Autowired
|
||||
private OwnerService ownerDAO;
|
||||
@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);
|
||||
}
|
||||
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,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.console-2.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at Oct 31, 2011
|
||||
* $Id: ContextUtil.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2100 Alibaba.com Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -23,13 +23,13 @@ import java.util.Map;
|
|||
*
|
||||
*/
|
||||
public class ContextUtil {
|
||||
|
||||
private ContextUtil(Map<String, Object> c){
|
||||
|
||||
private ContextUtil(Map<String, Object> c) {
|
||||
}
|
||||
|
||||
public static Object get(Map<String, Object> context, Object key, Object defaultv){
|
||||
|
||||
public static Object get(Map<String, Object> context, Object key, Object defaultv) {
|
||||
Object res = context.get(key);
|
||||
if(res == null){
|
||||
if (res == null) {
|
||||
res = defaultv;
|
||||
}
|
||||
return res;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.console-2.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at Nov 1, 2011
|
||||
* $Id: GovernanceWarmup.java 182013 2012-06-26 10:32:43Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2100 Alibaba.com Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,13 +15,13 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.governance.web.util;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author ding.lid
|
||||
*/
|
||||
|
|
@ -52,8 +52,8 @@ public class GovernanceWarmup implements InitializingBean {
|
|||
|
||||
StatusManager statusManager = StatusManager.getInstance();
|
||||
|
||||
statusManager.addStatusHandler("memory",memoryStatusChecker);
|
||||
statusManager.addStatusHandler("load",loadStatusChecker);
|
||||
statusManager.addStatusHandler("memory", memoryStatusChecker);
|
||||
statusManager.addStatusHandler("load", loadStatusChecker);
|
||||
// statusManager.addStatusHandler("database",databaseStatusChecker);
|
||||
// statusManager.addStatusHandler("cache",cacheStatusChecker);
|
||||
// statusManager.addStatusHandler("threadpool",threadPoolStatusChecker);
|
||||
|
|
@ -63,42 +63,42 @@ public class GovernanceWarmup implements InitializingBean {
|
|||
// 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
/**
|
||||
* Function: 分页封装类,控制分页
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2011-6-10
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2011 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
|
@ -12,7 +12,7 @@ import java.io.Serializable;
|
|||
|
||||
/**
|
||||
* TODO Comment of Paginator
|
||||
*
|
||||
*
|
||||
* @author guanghui.shigh
|
||||
*/
|
||||
public class Paginator implements Serializable, Cloneable {
|
||||
|
|
@ -20,33 +20,33 @@ public class Paginator implements Serializable, Cloneable {
|
|||
private static final long serialVersionUID = 3688506614705500726L;
|
||||
|
||||
// 每页默认的项数; 默认:10
|
||||
int itemsPerPage = 10;
|
||||
int itemsPerPage = 10;
|
||||
|
||||
// 滑动窗口默认的大小; 默认:7
|
||||
int sliderSize = 7;
|
||||
int sliderSize = 7;
|
||||
|
||||
// 当前页面;
|
||||
int currentPage;
|
||||
int currentPage;
|
||||
|
||||
// 当前页面;
|
||||
String path;
|
||||
String path;
|
||||
|
||||
// 总记录数
|
||||
int totalItems;
|
||||
int totalItems;
|
||||
|
||||
// 总页数
|
||||
int totalPage;
|
||||
int totalPage;
|
||||
|
||||
/**
|
||||
* 最简化的分页构造器。
|
||||
*
|
||||
*
|
||||
* @param itemsPerPage 每页项数。
|
||||
*/
|
||||
public Paginator(int currentPage, int totalItems, String path){
|
||||
public Paginator(int currentPage, int totalItems, String path) {
|
||||
initPagination(currentPage, totalItems, 0, 0, path);
|
||||
}
|
||||
|
||||
public Paginator(String currentPage, int totalItems, String path){
|
||||
public Paginator(String currentPage, int totalItems, String path) {
|
||||
int currentPageTemp = 1;
|
||||
if (!(currentPage == null || currentPage.equals(""))) {
|
||||
currentPageTemp = Integer.parseInt(currentPage);
|
||||
|
|
@ -56,7 +56,7 @@ public class Paginator implements Serializable, Cloneable {
|
|||
|
||||
/**
|
||||
* 完整的分页构造器。
|
||||
*
|
||||
*
|
||||
* @param currentPage 。
|
||||
* @param totalItems(必须项) 记录总数,大于等于0
|
||||
* @param sliderSize
|
||||
|
|
@ -80,7 +80,7 @@ public class Paginator implements Serializable, Cloneable {
|
|||
/**
|
||||
* 取得指定大小的页码滑动窗口,并将当前页尽可能地放在滑动窗口的中间部位。例如: 总共有13页,当前页是第5页,取得一个大小为5的滑动窗口,将包括 3,4,5,6, 7这几个页码,第5页被放在中间。如果当前页是12,则返回页码为
|
||||
* 9,10,11,12,13。
|
||||
*
|
||||
*
|
||||
* @return 包含页码的数组,如果指定滑动窗口大小小于1或总页数为0,则返回空数组。
|
||||
*/
|
||||
public int[] getSlider() {
|
||||
|
|
@ -119,7 +119,7 @@ public class Paginator implements Serializable, Cloneable {
|
|||
|
||||
StringBuffer str = new StringBuffer("<div class=\"page\">");
|
||||
str.append("<script type=\"text/javascript\">function gotoPage(page){window.location.href=\"/" + path
|
||||
+ "/pages/\" + page;}</script>");
|
||||
+ "/pages/\" + page;}</script>");
|
||||
|
||||
// 生成翻页部分
|
||||
// 1. 总记录数
|
||||
|
|
@ -175,7 +175,7 @@ public class Paginator implements Serializable, Cloneable {
|
|||
|
||||
/**
|
||||
* 获得起始记录
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getStartIndex() {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import java.util.Map.Entry;
|
|||
|
||||
/**
|
||||
* UrlUtils.java
|
||||
*
|
||||
*
|
||||
* @author tony.chenl
|
||||
*/
|
||||
public class UrlUtils {
|
||||
|
|
@ -57,5 +57,5 @@ public class UrlUtils {
|
|||
}
|
||||
return paramsString.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,51 +4,43 @@ import java.util.Map;
|
|||
|
||||
/**
|
||||
* 包含在web层用到的常量
|
||||
*
|
||||
*
|
||||
* @author guanghui.shigh
|
||||
*/
|
||||
public class WebConstants {
|
||||
|
||||
Map<String, Object> context;
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* 在session中保存当前用户对象的key。
|
||||
*/
|
||||
public static final String CURRENT_USER_KEY = "currentUser";
|
||||
|
||||
/**
|
||||
* 当前的挂号服务器地址
|
||||
*/
|
||||
public static final String REGISTRY_ADDRESS = "registryAddress";
|
||||
|
||||
/**
|
||||
public static final String REGISTRY_ADDRESS = "registryAddress";
|
||||
/**
|
||||
* 服务暴露地址
|
||||
*/
|
||||
public static final String SERVICE_URL = "serviceUrl";
|
||||
|
||||
/**
|
||||
* 服务名称
|
||||
*/
|
||||
public static final String SERVICE_NAME = "serviceName";
|
||||
|
||||
/**
|
||||
* 服务名称
|
||||
*/
|
||||
public static final String ENTRY = "entry";
|
||||
|
||||
/**
|
||||
* buc sso 登出地址
|
||||
*/
|
||||
public static final String SSO_LOGOUT_URL = "SSO_LOGOUT_URL";
|
||||
|
||||
/**
|
||||
* buc sso 用户名
|
||||
*/
|
||||
public static final String BUC_SSO_USERNAME = "buc_sso_username";
|
||||
|
||||
/**
|
||||
* 操作记录页面默认页面记录显示条数
|
||||
*/
|
||||
public static final Integer OPRATION_RECORDS_PAGE_SIZE = 100;
|
||||
|
||||
* 操作记录页面默认页面记录显示条数
|
||||
*/
|
||||
public static final Integer OPRATION_RECORDS_PAGE_SIZE = 100;
|
||||
Map<String, Object> context;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ package com.alibaba.dubbo.registry.common;
|
|||
|
||||
public interface ChangeListener {
|
||||
|
||||
/**
|
||||
* 数据变更
|
||||
*
|
||||
* @param type 数据类型
|
||||
* @param services 影响的服务
|
||||
*/
|
||||
void onChanged(String type);
|
||||
/**
|
||||
* 数据变更
|
||||
*
|
||||
* @param type 数据类型
|
||||
* @param services 影响的服务
|
||||
*/
|
||||
void onChanged(String type);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.core.service.server-1.0.5-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2009-12-27
|
||||
* $Id: StatusManager.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,32 +15,62 @@
|
|||
*/
|
||||
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;
|
||||
|
||||
import com.alibaba.dubbo.common.status.Status;
|
||||
import com.alibaba.dubbo.common.status.Status.Level;
|
||||
import com.alibaba.dubbo.common.status.StatusChecker;
|
||||
|
||||
/**
|
||||
* StatusManager
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
private StatusManager() {}
|
||||
|
||||
private final Map<String, StatusChecker> statusHandlers = new ConcurrentHashMap<String, StatusChecker>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
@ -48,7 +78,7 @@ public class StatusManager {
|
|||
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();
|
||||
|
|
@ -66,11 +96,11 @@ public class StatusManager {
|
|||
public void clearStatusHandlers() {
|
||||
this.statusHandlers.clear();
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Status> getStatusList() {
|
||||
return getStatusList(null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 过滤不需要汇总页面的监控项
|
||||
*/
|
||||
|
|
@ -78,45 +108,15 @@ public class StatusManager {
|
|||
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){
|
||||
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());
|
||||
statuses.put(entry.getKey(), entry.getValue().check());
|
||||
}
|
||||
return statuses;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.server-2.0.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-7-14
|
||||
* $Id: Access.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2010 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -16,58 +16,58 @@
|
|||
package com.alibaba.dubbo.registry.common.domain;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class Access extends Entity {
|
||||
|
||||
private static final long serialVersionUID = -962351722638094446L;
|
||||
private static final long serialVersionUID = -962351722638094446L;
|
||||
|
||||
private String service; /*服务名*/
|
||||
|
||||
private String address; /*消费者地址*/
|
||||
|
||||
private String service; /*服务名*/
|
||||
|
||||
private String address; /*消费者地址*/
|
||||
|
||||
private boolean allow; /*状态*/
|
||||
|
||||
|
||||
private String username; /*用户名*/
|
||||
|
||||
|
||||
public Access() {
|
||||
}
|
||||
|
||||
|
||||
public Access(Long id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public String getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
public void setService(String service) {
|
||||
this.service = service;
|
||||
}
|
||||
public String getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
public void setService(String service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public boolean isAllow() {
|
||||
return allow;
|
||||
}
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public void setAllow(boolean allow) {
|
||||
this.allow = allow;
|
||||
}
|
||||
public boolean isAllow() {
|
||||
return allow;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
public void setAllow(boolean allow) {
|
||||
this.allow = allow;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.server-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-7-14
|
||||
* $Id: Agreement.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -17,35 +17,35 @@ package com.alibaba.dubbo.registry.common.domain;
|
|||
|
||||
/**
|
||||
* 指定应用的服务质量等级协定(SLA)对象。
|
||||
*
|
||||
*
|
||||
* @author rain.chenjr
|
||||
* @author ding.lid
|
||||
*/
|
||||
public class Agreement extends Entity{
|
||||
public class Agreement extends Entity {
|
||||
|
||||
private static final long serialVersionUID = -4888604682731513790L;
|
||||
|
||||
|
||||
private String service; //服务名
|
||||
|
||||
|
||||
private String consumerApplication; // 服务消费者应用名
|
||||
|
||||
|
||||
private long invocationQuantity; // 一天调用量
|
||||
|
||||
private int tps; // TPS上限
|
||||
|
||||
|
||||
private int responseTime; // 响应时间,毫秒
|
||||
|
||||
|
||||
private double availability; // 可用率
|
||||
|
||||
private String username;
|
||||
|
||||
private String username;
|
||||
|
||||
public Agreement() {
|
||||
}
|
||||
|
||||
|
||||
public Agreement(Long id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
|
||||
public String getService() {
|
||||
return service;
|
||||
}
|
||||
|
|
@ -101,5 +101,5 @@ public class Agreement extends Entity{
|
|||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.server-2.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at Sep 14, 2011
|
||||
* $Id: Approval.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2100 Alibaba.com Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -17,26 +17,26 @@ package com.alibaba.dubbo.registry.common.domain;
|
|||
|
||||
/**
|
||||
* 服务上线审批。
|
||||
*
|
||||
*
|
||||
* @author ding.lid
|
||||
*/
|
||||
public class Approval extends Entity {
|
||||
private static final long serialVersionUID = -8778092807313048367L;
|
||||
|
||||
|
||||
private String service; // 服务名称
|
||||
|
||||
private String version;
|
||||
|
||||
private String version;
|
||||
// 可以使用通配符, *,1.1.*
|
||||
// 可以包含多个 1.1.3,1.1.5,2.*
|
||||
|
||||
|
||||
private boolean forProvider; // is Provider or consumer
|
||||
|
||||
|
||||
private String machineList; // 服务所在机器
|
||||
// 可以使用通配符 172.3.8.*
|
||||
// 可以有多个 172.1.9.8,172.1.9.123,172.3.3.*
|
||||
|
||||
|
||||
private String username;
|
||||
|
||||
|
||||
private String approveUser; // 审批者
|
||||
|
||||
public String getService() {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.server-2.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at Sep 14, 2011
|
||||
* $Id: ApprovalRequisition.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2100 Alibaba.com Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -17,28 +17,28 @@ package com.alibaba.dubbo.registry.common.domain;
|
|||
|
||||
/**
|
||||
* 服务上线申请。
|
||||
*
|
||||
*
|
||||
* @author ding.lid
|
||||
*/
|
||||
public class ApprovalRequisition extends Entity {
|
||||
private static final long serialVersionUID = -8778092807313048367L;
|
||||
|
||||
|
||||
private char operation; // 申请操作:新增(C),修改(U),删除(D)
|
||||
|
||||
private Long approvalId;
|
||||
|
||||
|
||||
private Long approvalId;
|
||||
|
||||
private String service; // 服务名称
|
||||
|
||||
private String version;
|
||||
|
||||
private String version;
|
||||
// 可以使用通配符, *,1.1.*
|
||||
// 可以包含多个 1.1.3,1.1.5,2.*
|
||||
|
||||
|
||||
private boolean forProvider;
|
||||
|
||||
|
||||
private String machineList; // 服务所在机器
|
||||
// 可以使用通配符 172.3.8.*
|
||||
// 可以有多个 172.1.9.8,172.1.9.123,172.3.3.*
|
||||
|
||||
|
||||
private String username;
|
||||
|
||||
public char getOperation() {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-4-9
|
||||
* $Id: Change.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -17,48 +17,33 @@ package com.alibaba.dubbo.registry.common.domain;
|
|||
|
||||
/**
|
||||
* 服务变更信息对象
|
||||
*
|
||||
*
|
||||
* @author rain.chenjr
|
||||
*/
|
||||
public class Change extends Entity {
|
||||
|
||||
private static final long serialVersionUID = 15528419903956898L;
|
||||
|
||||
public static final String PROVIDER_TYPE = "P"; //服务提供变更
|
||||
|
||||
public static final String CONSUMER_TYPE = "N"; //服务消费者变更
|
||||
|
||||
public static final String ROUTE_TYPE = "R"; //路由变更
|
||||
|
||||
public static final String WEIGHT_TYPE = "W"; //权重变更
|
||||
|
||||
public static final String LOADBALANCE_TYPE = "L"; //负载均衡变更
|
||||
|
||||
public static final String CLUSTER_TYPE = "G"; //分组变更
|
||||
|
||||
public static final String USER_TYPE = "U"; //用户变更
|
||||
|
||||
public static final String CONFIG_TYPE = "C"; //系统配置变更
|
||||
|
||||
public static final String FEATURE_TYPE = "F"; //系统功能变更
|
||||
|
||||
public static final String LAYER_TYPE = "Y"; //系统功能变更
|
||||
|
||||
public static final String TEST_TYPE = "T"; //服务测试变更
|
||||
|
||||
public static final String MOCK_TYPE = "M"; //服务测试变更
|
||||
|
||||
public static final String ACCESS_TYPE = "A"; //服务访问控制变更
|
||||
|
||||
public static final String OVERRIDE_TYPE = "O"; //参数覆盖变更
|
||||
|
||||
private String type; /* 变更类型 */
|
||||
private static final long serialVersionUID = 15528419903956898L;
|
||||
private String type; /* 变更类型 */
|
||||
|
||||
private String service; /* 服务名称 */
|
||||
|
||||
private long sequence; /* 变更序号 */
|
||||
|
||||
private String data; /* 变更内容 */
|
||||
private String service; /* 服务名称 */
|
||||
|
||||
private long sequence; /* 变更序号 */
|
||||
|
||||
private String data; /* 变更内容 */
|
||||
|
||||
public Change() {
|
||||
}
|
||||
|
|
@ -66,7 +51,7 @@ public class Change extends Entity {
|
|||
public Change(Long id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
|
||||
public Change(String type, String serviceName) {
|
||||
this.type = type;
|
||||
this.service = serviceName;
|
||||
|
|
@ -92,17 +77,17 @@ public class Change extends Entity {
|
|||
/**
|
||||
* 用change的id作为sequence
|
||||
*/
|
||||
public long getSequence() {
|
||||
return sequence;
|
||||
}
|
||||
public long getSequence() {
|
||||
return sequence;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* 用change的id作为sequence
|
||||
*/
|
||||
public void setSequence(long sequence) {
|
||||
this.sequence = sequence;
|
||||
}
|
||||
public void setSequence(long sequence) {
|
||||
this.sequence = sequence;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ package com.alibaba.dubbo.registry.common.domain;
|
|||
|
||||
public class Cluster extends Entity {
|
||||
|
||||
private static final long serialVersionUID = 8704571999015097948L;
|
||||
|
||||
private String name; /* 服务提供者分组名 ,一个分组可以包含若干个提供者*/
|
||||
|
||||
private static final long serialVersionUID = 8704571999015097948L;
|
||||
|
||||
private String name; /* 服务提供者分组名 ,一个分组可以包含若干个提供者*/
|
||||
|
||||
private String address; /* 客户端地址 */
|
||||
|
||||
|
||||
private String username;
|
||||
|
||||
public Cluster() {
|
||||
|
|
@ -16,14 +16,14 @@ public class Cluster extends Entity {
|
|||
public Cluster(Long id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.server-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-6-30
|
||||
* $Id: Config.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -20,86 +20,49 @@ package com.alibaba.dubbo.registry.common.domain;
|
|||
* @author rain.chenjr
|
||||
*
|
||||
*/
|
||||
public class Config extends Entity{
|
||||
public class Config extends Entity {
|
||||
|
||||
private static final long serialVersionUID = 7938303018328907548L;
|
||||
|
||||
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"; //是否允许匿名登录
|
||||
|
||||
public static final String ALLOW_LEGACY_LOGIN = "AllowLegacyLogin"; //是否允许遗留系统登录
|
||||
|
||||
public static final String MAX_THREAD_SIZE = "MaxThreadSize"; // 最大线程数
|
||||
|
||||
public static final String MAX_CONNECTION_SIZE = "MaxConnectionSize"; // 最大连接数
|
||||
|
||||
public static final String MAX_CACHE_SIZE = "MaxCacheSize"; // 最大缓存数
|
||||
|
||||
public static final String MAX_MAIL_SIZE = "MaxMailSize"; // 最大邮件队列数
|
||||
|
||||
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";//心跳检查间隔
|
||||
|
||||
public static final String HEARTBEAT_CHECK_TIMEOUT = "HeartbeatCheckTimeout";//心跳超时时间
|
||||
|
||||
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"; // 默认创建用户的权限
|
||||
|
||||
public static final String DEFAULT_ROLE = "DefaultRole"; // 默认创建用户的权限
|
||||
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() {
|
||||
|
|
@ -126,9 +89,9 @@ public class Config extends Entity{
|
|||
this.username = username;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public String toString() {
|
||||
return key + "=" + value;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public String toString() {
|
||||
return key + "=" + value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-4-9
|
||||
* $Id: Consumer.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -15,17 +15,17 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.registry.common.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class Consumer extends Entity {
|
||||
|
|
@ -35,31 +35,31 @@ public class Consumer extends Entity {
|
|||
private String service; /* 消费者所引用的服务名称 */
|
||||
|
||||
private String parameters;
|
||||
|
||||
|
||||
private String result; /*路由结果*/
|
||||
|
||||
private String address; /* 消费者地址 */
|
||||
|
||||
private String registry; /* 消费者连接的注册中心地址 */
|
||||
|
||||
|
||||
private String registry; /* 消费者连接的注册中心地址 */
|
||||
|
||||
private String application; /* 应用名 */
|
||||
|
||||
private String username; /* 消费者用户名 */
|
||||
|
||||
|
||||
private String statistics; /* 服务调用统计信息 */
|
||||
|
||||
private Date collected; /* 服务调用统计时间 */
|
||||
|
||||
private Override override;
|
||||
private Date collected; /* 服务调用统计时间 */
|
||||
|
||||
private List<Override> overrides;
|
||||
private Override override;
|
||||
|
||||
private List<Override> overrides;
|
||||
|
||||
private List<Route> routes;
|
||||
|
||||
|
||||
private List<Provider> providers;
|
||||
|
||||
private Date expired; /*过期时间*/
|
||||
|
||||
|
||||
private Date expired; /*过期时间*/
|
||||
|
||||
private long alived; /*存活时间,单位秒*/
|
||||
|
||||
public Consumer() {
|
||||
|
|
@ -145,52 +145,52 @@ public class Consumer extends Entity {
|
|||
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 Override getOverride() {
|
||||
return override;
|
||||
}
|
||||
|
||||
public void setOverride(Override override) {
|
||||
this.override = override;
|
||||
}
|
||||
public void setOverride(Override override) {
|
||||
this.override = override;
|
||||
}
|
||||
|
||||
public List<Override> getOverrides() {
|
||||
return overrides;
|
||||
}
|
||||
return overrides;
|
||||
}
|
||||
|
||||
public void setOverrides(List<Override> overrides) {
|
||||
this.overrides = overrides;
|
||||
}
|
||||
public void setOverrides(List<Override> overrides) {
|
||||
this.overrides = overrides;
|
||||
}
|
||||
|
||||
public List<Route> getRoutes() {
|
||||
return routes;
|
||||
}
|
||||
return routes;
|
||||
}
|
||||
|
||||
public void setRoutes(List<Route> routes) {
|
||||
this.routes = routes;
|
||||
}
|
||||
public void setRoutes(List<Route> routes) {
|
||||
this.routes = routes;
|
||||
}
|
||||
|
||||
public List<Provider> getProviders() {
|
||||
return providers;
|
||||
}
|
||||
public List<Provider> getProviders() {
|
||||
return providers;
|
||||
}
|
||||
|
||||
public void setProviders(List<Provider> providers) {
|
||||
this.providers = providers;
|
||||
}
|
||||
public void setProviders(List<Provider> providers) {
|
||||
this.providers = providers;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Consumer [service=" + service + ", parameters=" + parameters + ", result=" + result
|
||||
|
|
@ -199,7 +199,7 @@ public class Consumer extends Entity {
|
|||
+ ", collected=" + collected + ", routes=" + routes + ", overrides=" + overrides
|
||||
+ ", expired=" + expired + ", alived=" + alived + "]";
|
||||
}
|
||||
|
||||
|
||||
public URL toUrl() {
|
||||
String group = null;
|
||||
String version = null;
|
||||
|
|
@ -222,7 +222,7 @@ public class Consumer extends Entity {
|
|||
if (version != null) {
|
||||
param.put(Constants.VERSION_KEY, version);
|
||||
}
|
||||
return URL.valueOf(Constants.CONSUMER_PROTOCOL + "://" + address + "/" + path
|
||||
return URL.valueOf(Constants.CONSUMER_PROTOCOL + "://" + address + "/" + path
|
||||
+ "?" + StringUtils.toQueryString(param));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,24 +20,20 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* DependItem
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class DependItem {
|
||||
|
||||
private String application;
|
||||
|
||||
private int index;
|
||||
|
||||
private int level;
|
||||
|
||||
private DependItem parent;
|
||||
|
||||
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;
|
||||
|
|
@ -85,7 +81,7 @@ public class DependItem {
|
|||
public List<Integer> getRecursives() {
|
||||
return recursives;
|
||||
}
|
||||
|
||||
|
||||
public void addRecursive(int padding, int value) {
|
||||
while (recursives.size() < padding) {
|
||||
recursives.add(0);
|
||||
|
|
|
|||
|
|
@ -4,26 +4,26 @@ import java.io.Serializable;
|
|||
|
||||
public class Dependency implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 8526869025719540547L;
|
||||
private static final long serialVersionUID = 8526869025719540547L;
|
||||
|
||||
private String providerApplication;
|
||||
|
||||
private String consumerApplication;
|
||||
private String providerApplication;
|
||||
|
||||
public String getProviderApplication() {
|
||||
return providerApplication;
|
||||
}
|
||||
private String consumerApplication;
|
||||
|
||||
public void setProviderApplication(String providerApplication) {
|
||||
this.providerApplication = providerApplication;
|
||||
}
|
||||
public String getProviderApplication() {
|
||||
return providerApplication;
|
||||
}
|
||||
|
||||
public String getConsumerApplication() {
|
||||
return consumerApplication;
|
||||
}
|
||||
public void setProviderApplication(String providerApplication) {
|
||||
this.providerApplication = providerApplication;
|
||||
}
|
||||
|
||||
public void setConsumerApplication(String consumerApplication) {
|
||||
this.consumerApplication = consumerApplication;
|
||||
}
|
||||
public String getConsumerApplication() {
|
||||
return consumerApplication;
|
||||
}
|
||||
|
||||
public void setConsumerApplication(String consumerApplication) {
|
||||
this.consumerApplication = consumerApplication;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/**
|
||||
* Project: dubbo.registry.server-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-6-29
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2010 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -16,19 +16,15 @@ package com.alibaba.dubbo.registry.common.domain;
|
|||
|
||||
/**
|
||||
* Document
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class Document extends Entity {
|
||||
|
||||
private static final long serialVersionUID = 5059135057592486874L;
|
||||
|
||||
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;
|
||||
|
|
@ -36,7 +32,7 @@ public class Document extends Entity {
|
|||
private String type;
|
||||
|
||||
private String content;
|
||||
|
||||
|
||||
private String username;
|
||||
|
||||
public Document() {
|
||||
|
|
@ -45,7 +41,7 @@ public class Document extends Entity {
|
|||
public Document(Long id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
|
@ -78,12 +74,12 @@ public class Document extends Entity {
|
|||
this.username = username;
|
||||
}
|
||||
|
||||
public String getService() {
|
||||
return service;
|
||||
}
|
||||
public String getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
public void setService(String service) {
|
||||
this.service = service;
|
||||
}
|
||||
public void setService(String service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-4-9
|
||||
* $Id: Entity.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -21,51 +21,51 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* Entity
|
||||
*
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public abstract class Entity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3031128781434583143L;
|
||||
|
||||
private List<Long> ids;
|
||||
private static final long serialVersionUID = -3031128781434583143L;
|
||||
|
||||
private Long id;
|
||||
private List<Long> ids;
|
||||
|
||||
private Date created;
|
||||
private Long id;
|
||||
|
||||
private Date created;
|
||||
|
||||
private Date modified;
|
||||
|
||||
|
||||
private Date now;
|
||||
|
||||
|
||||
private String operator;
|
||||
|
||||
|
||||
private String operatorAddress;
|
||||
|
||||
|
||||
private boolean miss;
|
||||
|
||||
|
||||
public Entity() {
|
||||
}
|
||||
|
||||
|
||||
public Entity(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public List<Long> getIds() {
|
||||
return ids;
|
||||
}
|
||||
|
||||
public void setIds(List<Long> ids) {
|
||||
this.ids = ids;
|
||||
}
|
||||
public List<Long> getIds() {
|
||||
return ids;
|
||||
}
|
||||
|
||||
public void setIds(List<Long> ids) {
|
||||
this.ids = ids;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
|
|
@ -83,29 +83,29 @@ public abstract class Entity implements Serializable {
|
|||
this.modified = modified;
|
||||
}
|
||||
|
||||
public Date getNow() {
|
||||
return now;
|
||||
}
|
||||
public Date getNow() {
|
||||
return now;
|
||||
}
|
||||
|
||||
public void setNow(Date now) {
|
||||
this.now = now;
|
||||
}
|
||||
public void setNow(Date now) {
|
||||
this.now = now;
|
||||
}
|
||||
|
||||
public String getOperator() {
|
||||
return operator;
|
||||
}
|
||||
public String getOperator() {
|
||||
return operator;
|
||||
}
|
||||
|
||||
public void setOperator(String operator) {
|
||||
if (operator != null && operator.length() > 200) {
|
||||
operator = operator.substring(0, 200);
|
||||
}
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
public void setOperator(String operator) {
|
||||
if (operator != null && operator.length() > 200) {
|
||||
operator = operator.substring(0, 200);
|
||||
}
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
public String getOperatorAddress() {
|
||||
return operatorAddress;
|
||||
}
|
||||
|
||||
|
||||
public void setOperatorAddress(String operatorAddress) {
|
||||
this.operatorAddress = operatorAddress;
|
||||
}
|
||||
|
|
@ -113,7 +113,7 @@ public abstract class Entity implements Serializable {
|
|||
public boolean isMiss() {
|
||||
return miss;
|
||||
}
|
||||
|
||||
|
||||
public void setMiss(boolean miss) {
|
||||
this.miss = miss;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@ package com.alibaba.dubbo.registry.common.domain;
|
|||
|
||||
public class Favorite extends Entity {
|
||||
|
||||
private static final long serialVersionUID = -1281982267153430266L;
|
||||
|
||||
private static final long serialVersionUID = -1281982267153430266L;
|
||||
|
||||
private String name;
|
||||
|
||||
|
||||
private String url;
|
||||
|
||||
|
||||
private String username;
|
||||
|
||||
|
||||
public Favorite() {
|
||||
}
|
||||
|
||||
|
|
@ -17,28 +17,28 @@ public class Favorite extends Entity {
|
|||
super(id);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.server-1.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at 2010-6-30
|
||||
* $Id: Feature.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 2008 Alibaba.com Croporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -20,14 +20,14 @@ package com.alibaba.dubbo.registry.common.domain;
|
|||
*
|
||||
* @author ding.lid
|
||||
*/
|
||||
public class Feature extends Entity{
|
||||
|
||||
public class Feature extends Entity {
|
||||
|
||||
private static final long serialVersionUID = 3246619851259746169L;
|
||||
|
||||
private String name;
|
||||
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
|
||||
private String username;
|
||||
|
||||
public Feature() {
|
||||
|
|
@ -36,7 +36,7 @@ public class Feature extends Entity{
|
|||
public Feature(Long id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Project: dubbo.registry.server-2.1.0-SNAPSHOT
|
||||
*
|
||||
* <p>
|
||||
* File Created at Sep 1, 2011
|
||||
* $Id: Layer.java 181192 2012-06-21 05:05:47Z tony.chenl $
|
||||
*
|
||||
* <p>
|
||||
* Copyright 1999-2100 Alibaba.com Corporation Limited.
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* This software is the confidential and proprietary information of
|
||||
* Alibaba Company. ("Confidential Information"). You shall not
|
||||
* disclose such Confidential Information and shall use it only in
|
||||
|
|
@ -21,11 +21,18 @@ package com.alibaba.dubbo.registry.common.domain;
|
|||
public class Layer extends Entity {
|
||||
private static final long serialVersionUID = 6114868933223039253L;
|
||||
|
||||
private String username;
|
||||
private String username;
|
||||
|
||||
private String arch;
|
||||
private String name;
|
||||
private int value;
|
||||
private String arch;
|
||||
private String name;
|
||||
private int value;
|
||||
|
||||
public Layer(Long id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public Layer() {
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
|
|
@ -58,11 +65,4 @@ public class Layer extends Entity {
|
|||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Layer(Long id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public Layer() {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue