Commit 50109173 authored by zl张乐(IT)'s avatar zl张乐(IT)

Merge branch 'master' into 'release'

Master



See merge request !36
parents 5331b637 84536ff6
...@@ -15,7 +15,7 @@ Apollo(阿波罗)是携程框架部门研发的配置管理平台,能够 ...@@ -15,7 +15,7 @@ Apollo(阿波罗)是携程框架部门研发的配置管理平台,能够
服务端基于Spring Boot和Spring Cloud开发,打包后可以直接运行,不需要额外安装Tomcat等应用容器。 服务端基于Spring Boot和Spring Cloud开发,打包后可以直接运行,不需要额外安装Tomcat等应用容器。
客户端不依赖任何框架,能够运行于所有Java运行时环境。 客户端不依赖任何框架,能够运行于所有Java运行时环境。(.Net客户端即将开源)
更多产品介绍参见[Apollo配置中心介绍](https://github.com/ctripcorp/apollo/wiki/Apollo%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83%E4%BB%8B%E7%BB%8D) 更多产品介绍参见[Apollo配置中心介绍](https://github.com/ctripcorp/apollo/wiki/Apollo%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83%E4%BB%8B%E7%BB%8D)
...@@ -46,8 +46,9 @@ Apollo(阿波罗)是携程框架部门研发的配置管理平台,能够 ...@@ -46,8 +46,9 @@ Apollo(阿波罗)是携程框架部门研发的配置管理平台,能够
* **客户端配置信息监控** * **客户端配置信息监控**
* 可以方便的看到配置在被哪些实例使用 * 可以方便的看到配置在被哪些实例使用
* **提供Java原生客户端** * **提供Java和.Net原生客户端**
* 提供了Java的原生客户端,方便应用集成  
* 提供了Java和.Net的原生客户端,方便应用集成(.Net客户端即将开源)
* 同时提供了Http接口,非Java应用也可以方便的使用 * 同时提供了Http接口,非Java应用也可以方便的使用
* **提供开放平台API** * **提供开放平台API**
...@@ -57,6 +58,11 @@ Apollo(阿波罗)是携程框架部门研发的配置管理平台,能够 ...@@ -57,6 +58,11 @@ Apollo(阿波罗)是携程框架部门研发的配置管理平台,能够
* 还有一些使用方如DAL,不仅有特定的格式,而且对输入的值也需要进行校验后方可保存,如检查数据库、用户名和密码是否匹配。 * 还有一些使用方如DAL,不仅有特定的格式,而且对输入的值也需要进行校验后方可保存,如检查数据库、用户名和密码是否匹配。
* 对于这类应用,Apollo支持应用方通过开放接口在Apollo进行配置的修改和发布,并且具备完善的授权和权限控制 * 对于这类应用,Apollo支持应用方通过开放接口在Apollo进行配置的修改和发布,并且具备完善的授权和权限控制
* **部署简单**
* 配置中心作为基础服务,可用性要求非常高,这就要求Apollo对外部依赖尽可能地少
* 目前唯一的外部依赖是MySQL,所以部署非常简单,只要安装好Java和MySQL就可以让Apollo跑起来
* Apollo还提供了打包脚本,一键就可以生成所有需要的安装包,并且支持自定义运行时参数
#Usage #Usage
1. [应用接入指南](https://github.com/ctripcorp/apollo/wiki/%E5%BA%94%E7%94%A8%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97) 1. [应用接入指南](https://github.com/ctripcorp/apollo/wiki/%E5%BA%94%E7%94%A8%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97)
2. [Java客户端使用指南](https://github.com/ctripcorp/apollo/wiki/Java%E5%AE%A2%E6%88%B7%E7%AB%AF%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97) 2. [Java客户端使用指南](https://github.com/ctripcorp/apollo/wiki/Java%E5%AE%A2%E6%88%B7%E7%AB%AF%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97)
...@@ -65,6 +71,12 @@ Apollo(阿波罗)是携程框架部门研发的配置管理平台,能够 ...@@ -65,6 +71,12 @@ Apollo(阿波罗)是携程框架部门研发的配置管理平台,能够
#Design #Design
* [Apollo配置中心设计](https://github.com/ctripcorp/apollo/wiki/Apollo%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83%E8%AE%BE%E8%AE%A1) * [Apollo配置中心设计](https://github.com/ctripcorp/apollo/wiki/Apollo%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83%E8%AE%BE%E8%AE%A1)
#Development
* [Apollo开发指南](https://github.com/ctripcorp/apollo/wiki/Apollo%E5%BC%80%E5%8F%91%E6%8C%87%E5%8D%97)
* Code Styles
* [Eclipse Code Style](https://github.com/ctripcorp/apollo/blob/master/apollo-buildtools/style/eclipse-java-google-style.xml)
* [Intellij Code Style](https://github.com/ctripcorp/apollo/blob/master/apollo-buildtools/style/intellij-java-google-style.xml)
#Deployment #Deployment
* [Quick Start](https://github.com/ctripcorp/apollo/wiki/Quick-Start) * [Quick Start](https://github.com/ctripcorp/apollo/wiki/Quick-Start)
* [分布式部署指南](https://github.com/ctripcorp/apollo/wiki/%E5%88%86%E5%B8%83%E5%BC%8F%E9%83%A8%E7%BD%B2%E6%8C%87%E5%8D%97) * [分布式部署指南](https://github.com/ctripcorp/apollo/wiki/%E5%88%86%E5%B8%83%E5%BC%8F%E9%83%A8%E7%BD%B2%E6%8C%87%E5%8D%97)
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.ctrip.framework.apollo</groupId> <groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId> <artifactId>apollo</artifactId>
<version>0.2.0</version> <version>0.4.0</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -19,11 +19,6 @@ ...@@ -19,11 +19,6 @@
<groupId>com.ctrip.framework.apollo</groupId> <groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-biz</artifactId> <artifactId>apollo-biz</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-buildtools</artifactId>
<scope>test</scope>
</dependency>
<!-- end of apollo --> <!-- end of apollo -->
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
...@@ -108,11 +103,6 @@ ...@@ -108,11 +103,6 @@
<package.environment>github</package.environment> <package.environment>github</package.environment>
</properties> </properties>
<dependencies> <dependencies>
<!-- disable cat for outside use -->
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-buildtools</artifactId>
</dependency>
</dependencies> </dependencies>
</profile> </profile>
</profiles> </profiles>
......
package com.ctrip.framework.apollo.adminservice; package com.ctrip.framework.apollo.adminservice;
import com.ctrip.framework.apollo.biz.service.AppService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.ctrip.framework.apollo.biz.service.AppService;
@Component @Component
public class AdminServiceHealthIndicator implements HealthIndicator { public class AdminServiceHealthIndicator implements HealthIndicator {
......
package com.ctrip.framework.apollo.adminservice.controller; package com.ctrip.framework.apollo.adminservice.controller;
import java.util.List; import com.ctrip.framework.apollo.biz.service.AdminService;
import com.ctrip.framework.apollo.biz.service.AppService;
import com.ctrip.framework.apollo.common.dto.AppDTO;
import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.utils.InputValidator;
import com.ctrip.framework.apollo.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
...@@ -11,15 +19,7 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -11,15 +19,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.ctrip.framework.apollo.common.entity.App; import java.util.List;
import com.ctrip.framework.apollo.biz.service.AdminService;
import com.ctrip.framework.apollo.biz.service.AppService;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.utils.InputValidator;
import com.ctrip.framework.apollo.common.dto.AppDTO;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.core.utils.StringUtils;
@RestController @RestController
public class AppController { public class AppController {
......
package com.ctrip.framework.apollo.adminservice.controller; package com.ctrip.framework.apollo.adminservice.controller;
import com.ctrip.framework.apollo.biz.service.AppNamespaceService;
import com.ctrip.framework.apollo.common.dto.AppNamespaceDTO;
import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.biz.service.AppNamespaceService;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.dto.AppNamespaceDTO;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.core.utils.StringUtils;
@RestController @RestController
public class AppNamespaceController { public class AppNamespaceController {
......
package com.ctrip.framework.apollo.adminservice.controller; package com.ctrip.framework.apollo.adminservice.controller;
import java.util.List; import com.ctrip.framework.apollo.biz.entity.Cluster;
import com.ctrip.framework.apollo.biz.service.ClusterService;
import com.ctrip.framework.apollo.common.dto.ClusterDTO;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.utils.InputValidator;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
...@@ -10,13 +16,7 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -10,13 +16,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.ctrip.framework.apollo.biz.entity.Cluster; import java.util.List;
import com.ctrip.framework.apollo.biz.service.ClusterService;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.utils.InputValidator;
import com.ctrip.framework.apollo.common.dto.ClusterDTO;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.exception.NotFoundException;
@RestController @RestController
public class ClusterController { public class ClusterController {
......
...@@ -2,8 +2,8 @@ package com.ctrip.framework.apollo.adminservice.controller; ...@@ -2,8 +2,8 @@ package com.ctrip.framework.apollo.adminservice.controller;
import com.ctrip.framework.apollo.biz.entity.Commit; import com.ctrip.framework.apollo.biz.entity.Commit;
import com.ctrip.framework.apollo.biz.service.CommitService; import com.ctrip.framework.apollo.biz.service.CommitService;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.dto.CommitDTO; import com.ctrip.framework.apollo.common.dto.CommitDTO;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
......
package com.ctrip.framework.apollo.adminservice.controller; package com.ctrip.framework.apollo.adminservice.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ctrip.framework.apollo.adminservice.aop.PreAcquireNamespaceLock; import com.ctrip.framework.apollo.adminservice.aop.PreAcquireNamespaceLock;
import com.ctrip.framework.apollo.biz.entity.Commit; import com.ctrip.framework.apollo.biz.entity.Commit;
import com.ctrip.framework.apollo.biz.entity.Item; import com.ctrip.framework.apollo.biz.entity.Item;
...@@ -18,10 +8,20 @@ import com.ctrip.framework.apollo.biz.service.CommitService; ...@@ -18,10 +8,20 @@ import com.ctrip.framework.apollo.biz.service.CommitService;
import com.ctrip.framework.apollo.biz.service.ItemService; import com.ctrip.framework.apollo.biz.service.ItemService;
import com.ctrip.framework.apollo.biz.service.NamespaceService; import com.ctrip.framework.apollo.biz.service.NamespaceService;
import com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder; import com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.dto.ItemDTO; import com.ctrip.framework.apollo.common.dto.ItemDTO;
import com.ctrip.framework.apollo.common.exception.BadRequestException; import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.exception.NotFoundException; import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController @RestController
public class ItemController { public class ItemController {
......
package com.ctrip.framework.apollo.adminservice.controller; package com.ctrip.framework.apollo.adminservice.controller;
import com.ctrip.framework.apollo.adminservice.aop.PreAcquireNamespaceLock;
import com.ctrip.framework.apollo.biz.service.ItemSetService;
import com.ctrip.framework.apollo.common.dto.ItemChangeSets;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -9,10 +13,6 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -9,10 +13,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.ctrip.framework.apollo.adminservice.aop.PreAcquireNamespaceLock;
import com.ctrip.framework.apollo.biz.service.ItemSetService;
import com.ctrip.framework.apollo.common.dto.ItemChangeSets;
@RestController @RestController
public class ItemSetController { public class ItemSetController {
......
package com.ctrip.framework.apollo.adminservice.controller; package com.ctrip.framework.apollo.adminservice.controller;
import java.util.List; import com.ctrip.framework.apollo.biz.entity.Namespace;
import com.ctrip.framework.apollo.biz.service.NamespaceService;
import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.utils.InputValidator;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
...@@ -10,13 +16,7 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -10,13 +16,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.ctrip.framework.apollo.biz.entity.Namespace; import java.util.List;
import com.ctrip.framework.apollo.biz.service.NamespaceService;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.utils.InputValidator;
import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.exception.NotFoundException;
@RestController @RestController
public class NamespaceController { public class NamespaceController {
......
...@@ -5,9 +5,9 @@ import com.ctrip.framework.apollo.biz.entity.NamespaceLock; ...@@ -5,9 +5,9 @@ import com.ctrip.framework.apollo.biz.entity.NamespaceLock;
import com.ctrip.framework.apollo.biz.service.NamespaceLockService; import com.ctrip.framework.apollo.biz.service.NamespaceLockService;
import com.ctrip.framework.apollo.biz.service.NamespaceService; import com.ctrip.framework.apollo.biz.service.NamespaceService;
import com.ctrip.framework.apollo.biz.utils.ApolloSwitcher; import com.ctrip.framework.apollo.biz.utils.ApolloSwitcher;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.dto.NamespaceLockDTO; import com.ctrip.framework.apollo.common.dto.NamespaceLockDTO;
import com.ctrip.framework.apollo.common.exception.BadRequestException; import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
......
...@@ -13,9 +13,9 @@ import com.ctrip.framework.apollo.biz.service.ReleaseService; ...@@ -13,9 +13,9 @@ import com.ctrip.framework.apollo.biz.service.ReleaseService;
import com.ctrip.framework.apollo.biz.utils.ReleaseMessageKeyGenerator; import com.ctrip.framework.apollo.biz.utils.ReleaseMessageKeyGenerator;
import com.ctrip.framework.apollo.common.constants.NamespaceBranchStatus; import com.ctrip.framework.apollo.common.constants.NamespaceBranchStatus;
import com.ctrip.framework.apollo.common.dto.ItemChangeSets; import com.ctrip.framework.apollo.common.dto.ItemChangeSets;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.dto.ReleaseDTO; import com.ctrip.framework.apollo.common.dto.ReleaseDTO;
import com.ctrip.framework.apollo.common.exception.NotFoundException; import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
......
package com.ctrip.framework.apollo.adminservice.controller; package com.ctrip.framework.apollo.adminservice.controller;
import com.google.common.base.Strings;
import com.google.common.collect.Sets;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.ctrip.framework.apollo.biz.entity.Namespace;
import com.ctrip.framework.apollo.biz.entity.Release;
import com.ctrip.framework.apollo.biz.entity.ReleaseHistory; import com.ctrip.framework.apollo.biz.entity.ReleaseHistory;
import com.ctrip.framework.apollo.biz.repository.NamespaceRepository;
import com.ctrip.framework.apollo.biz.repository.ReleaseHistoryRepository;
import com.ctrip.framework.apollo.biz.repository.ReleaseRepository;
import com.ctrip.framework.apollo.biz.service.ReleaseHistoryService; import com.ctrip.framework.apollo.biz.service.ReleaseHistoryService;
import com.ctrip.framework.apollo.common.constants.ReleaseOperation;
import com.ctrip.framework.apollo.common.dto.PageDTO; import com.ctrip.framework.apollo.common.dto.PageDTO;
import com.ctrip.framework.apollo.common.dto.ReleaseHistoryDTO; import com.ctrip.framework.apollo.common.dto.ReleaseHistoryDTO;
import com.ctrip.framework.apollo.common.utils.BeanUtils; import com.ctrip.framework.apollo.common.utils.BeanUtils;
...@@ -20,7 +12,6 @@ import com.ctrip.framework.apollo.common.utils.BeanUtils; ...@@ -20,7 +12,6 @@ import com.ctrip.framework.apollo.common.utils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
...@@ -29,11 +20,8 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -29,11 +20,8 @@ import org.springframework.web.bind.annotation.RestController;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
...@@ -48,113 +36,62 @@ public class ReleaseHistoryController { ...@@ -48,113 +36,62 @@ public class ReleaseHistoryController {
@Autowired @Autowired
private ReleaseHistoryService releaseHistoryService; private ReleaseHistoryService releaseHistoryService;
@Autowired
private ReleaseRepository releaseRepository;
@Autowired
private NamespaceRepository namespaceRepository;
@Autowired
private ReleaseHistoryRepository releaseHistoryRepository;
@RequestMapping(value = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/histories", @RequestMapping(value = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/histories",
method = RequestMethod.GET) method = RequestMethod.GET)
public PageDTO<ReleaseHistoryDTO> findReleaseHistoriesByNamespace( public PageDTO<ReleaseHistoryDTO> findReleaseHistoriesByNamespace(
@PathVariable String appId, @PathVariable String clusterName, @PathVariable String appId, @PathVariable String clusterName,
@PathVariable String namespaceName, Pageable pageable) { @PathVariable String namespaceName,
Page<ReleaseHistory> result = releaseHistoryService.findReleaseHistoriesByNamespace(appId, Pageable pageable) {
clusterName, namespaceName, pageable);
if (!result.hasContent()) { Page<ReleaseHistory> result = releaseHistoryService.findReleaseHistoriesByNamespace(appId, clusterName,
return null; namespaceName, pageable);
return transform2PageDTO(result, pageable);
} }
List<ReleaseHistory> releaseHistories = result.getContent();
List<ReleaseHistoryDTO> releaseHistoryDTOs = new ArrayList<>(releaseHistories.size());
for (ReleaseHistory releaseHistory : releaseHistories) {
ReleaseHistoryDTO dto = new ReleaseHistoryDTO();
BeanUtils.copyProperties(releaseHistory, dto, "operationContext");
dto.setOperationContext(gson.fromJson(releaseHistory.getOperationContext(),
configurationTypeReference));
releaseHistoryDTOs.add(dto); @RequestMapping(value = "/releases/histories/by_release_id_and_operation", method = RequestMethod.GET)
} public PageDTO<ReleaseHistoryDTO> findReleaseHistoryByReleaseIdAndOperation(
@RequestParam("releaseId") long releaseId,
@RequestParam("operation") int operation,
Pageable pageable) {
Page<ReleaseHistory> result = releaseHistoryService.findByReleaseIdAndOperation(releaseId, operation, pageable);
return new PageDTO<>(releaseHistoryDTOs, pageable, result.getTotalElements()); return transform2PageDTO(result, pageable);
} }
@RequestMapping(value = "/release-histories/conversions", method = RequestMethod.POST) @RequestMapping(value = "/releases/histories/by_previous_release_id_and_operation", method = RequestMethod.GET)
public void releaseHistoryConversion( public PageDTO<ReleaseHistoryDTO> findReleaseHistoryByPreviousReleaseIdAndOperation(
@RequestParam(name = "namespaceId", required = false) String namespaceId) { @RequestParam("previousReleaseId") long previousReleaseId,
Iterable<Namespace> namespaces; @RequestParam("operation") int operation,
Pageable pageable) {
if (Strings.isNullOrEmpty(namespaceId)) {
namespaces = namespaceRepository.findAll();
} else {
Set<Long> idList = Arrays.stream(namespaceId.split(",")).map(Long::valueOf).collect
(Collectors.toSet());
namespaces = namespaceRepository.findAll(idList);
}
for (Namespace namespace : namespaces) { Page<ReleaseHistory> result = releaseHistoryService.findByPreviousReleaseIdAndOperation(previousReleaseId, operation, pageable);
List<Release> releases = releaseRepository
.findByAppIdAndClusterNameAndNamespaceNameOrderByIdAsc(namespace.getAppId(), namespace
.getClusterName(), namespace.getNamespaceName());
if (CollectionUtils.isEmpty(releases)) {
continue;
}
Release previousRelease = null;
Set<ReleaseHistory> releaseHistories = Sets.newLinkedHashSet();//ordered set return transform2PageDTO(result, pageable);
for (Release release : releases) {
List<ReleaseHistory> histories = releaseHistoryService.findReleaseHistoriesByReleaseId
(release.getId());
//already processed
if (!CollectionUtils.isEmpty(histories)) {
continue;
} }
long previousReleaseId = previousRelease == null ? 0 : previousRelease.getId(); private PageDTO<ReleaseHistoryDTO> transform2PageDTO(Page<ReleaseHistory> releaseHistoriesPage, Pageable pageable){
ReleaseHistory releaseHistory = assembleReleaseHistory( if (!releaseHistoriesPage.hasContent()) {
release, ReleaseOperation .NORMAL_RELEASE, previousReleaseId); return null;
releaseHistories.add(releaseHistory);
//rollback
if (release.isAbandoned() && previousRelease != null) {
releaseHistory.setDataChangeLastModifiedTime(release.getDataChangeCreatedTime());
ReleaseHistory rollBackReleaseHistory = assembleReleaseHistory(previousRelease,
ReleaseOperation.ROLLBACK, release.getId());
rollBackReleaseHistory.setDataChangeCreatedBy(release.getDataChangeLastModifiedBy());
rollBackReleaseHistory.setDataChangeCreatedTime(release.getDataChangeLastModifiedTime());
rollBackReleaseHistory.setDataChangeLastModifiedTime(release.getDataChangeLastModifiedTime());
releaseHistories.add(rollBackReleaseHistory);
} else {
previousRelease = release;
}
} }
releaseHistoryRepository.save(releaseHistories); List<ReleaseHistory> releaseHistories = releaseHistoriesPage.getContent();
List<ReleaseHistoryDTO> releaseHistoryDTOs = new ArrayList<>(releaseHistories.size());
for (ReleaseHistory releaseHistory : releaseHistories) {
releaseHistoryDTOs.add(transformReleaseHistory2DTO(releaseHistory));
} }
return new PageDTO<>(releaseHistoryDTOs, pageable, releaseHistoriesPage.getTotalElements());
} }
public ReleaseHistory assembleReleaseHistory(Release release, int releaseOperation, long private ReleaseHistoryDTO transformReleaseHistory2DTO(ReleaseHistory releaseHistory) {
previousReleaseId) { ReleaseHistoryDTO dto = new ReleaseHistoryDTO();
ReleaseHistory releaseHistory = new ReleaseHistory(); BeanUtils.copyProperties(releaseHistory, dto, "operationContext");
releaseHistory.setAppId(release.getAppId()); dto.setOperationContext(gson.fromJson(releaseHistory.getOperationContext(),
releaseHistory.setClusterName(release.getClusterName()); configurationTypeReference));
releaseHistory.setNamespaceName(release.getNamespaceName());
releaseHistory.setBranchName(release.getClusterName()); return dto;
releaseHistory.setReleaseId(release.getId());
releaseHistory.setPreviousReleaseId(previousReleaseId);
releaseHistory.setOperation(releaseOperation);
releaseHistory.setOperationContext("{}"); //default empty object
releaseHistory.setDataChangeCreatedBy(release.getDataChangeCreatedBy());
releaseHistory.setDataChangeCreatedTime(release.getDataChangeCreatedTime());
releaseHistory.setDataChangeLastModifiedTime(release.getDataChangeLastModifiedTime());
releaseHistory.setDataChangeLastModifiedBy("apollo"); //mark
return releaseHistory;
} }
} }
#!/bin/bash #!/bin/bash
SERVICE_NAME=apollo-adminservice SERVICE_NAME=apollo-adminservice
## Adjust log dir if necessary
LOG_DIR=/opt/logs/100003172 LOG_DIR=/opt/logs/100003172
## Adjust server port if necessary
SERVER_PORT=8090 SERVER_PORT=8090
## Adjust memory settings if necessary
export JAVA_OPTS="-server -Xms2560m -Xmx2560m -Xss256k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=384m -XX:NewSize=1024m -XX:MaxNewSize=1024m -XX:SurvivorRatio=22" export JAVA_OPTS="-server -Xms2560m -Xmx2560m -Xss256k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=384m -XX:NewSize=1024m -XX:MaxNewSize=1024m -XX:SurvivorRatio=22"
########### The following is the same for configservice, adminservice, portal ########### ########### The following is the same for configservice, adminservice, portal ###########
export JAVA_OPTS="$JAVA_OPTS -XX:+UseParNewGC -XX:ParallelGCThreads=4 -XX:MaxTenuringThreshold=9 -XX:+UseConcMarkSweepGC -XX:+DisableExplicitGC -XX:+UseCMSInitiatingOccupancyOnly -XX:+ScavengeBeforeFullGC -XX:+UseCMSCompactAtFullCollection -XX:+CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=9 -XX:CMSInitiatingOccupancyFraction=60 -XX:+CMSClassUnloadingEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:-ReduceInitialCardMarks -XX:+CMSPermGenSweepingEnabled -XX:CMSInitiatingPermOccupancyFraction=70 -XX:+ExplicitGCInvokesConcurrent -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationConcurrentTime -XX:+PrintHeapAtGC -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -Duser.timezone=Asia/Shanghai -Dclient.encoding.override=UTF-8 -Dfile.encoding=UTF-8 -Xloggc:$LOG_DIR/heap_trace.txt -XX:HeapDumpPath=$LOG_DIR/HeapDumpOnOutOfMemoryError/ -Djava.security.egd=file:/dev/./urandom" export JAVA_OPTS="$JAVA_OPTS -XX:+UseParNewGC -XX:ParallelGCThreads=4 -XX:MaxTenuringThreshold=9 -XX:+UseConcMarkSweepGC -XX:+DisableExplicitGC -XX:+UseCMSInitiatingOccupancyOnly -XX:+ScavengeBeforeFullGC -XX:+UseCMSCompactAtFullCollection -XX:+CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=9 -XX:CMSInitiatingOccupancyFraction=60 -XX:+CMSClassUnloadingEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:-ReduceInitialCardMarks -XX:+CMSPermGenSweepingEnabled -XX:CMSInitiatingPermOccupancyFraction=70 -XX:+ExplicitGCInvokesConcurrent -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationConcurrentTime -XX:+PrintHeapAtGC -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -Duser.timezone=Asia/Shanghai -Dclient.encoding.override=UTF-8 -Dfile.encoding=UTF-8 -Djava.security.egd=file:/dev/./urandom"
export JAVA_OPTS="$JAVA_OPTS -Dserver.port=$SERVER_PORT -Dlogging.file=$LOG_DIR/$SERVICE_NAME.log -Xloggc:$LOG_DIR/heap_trace.txt -XX:HeapDumpPath=$LOG_DIR/HeapDumpOnOutOfMemoryError/"
PATH_TO_JAR=$SERVICE_NAME".jar" PATH_TO_JAR=$SERVICE_NAME".jar"
SERVER_URL="http://localhost:$SERVER_PORT" SERVER_URL="http://localhost:$SERVER_PORT"
...@@ -62,7 +66,7 @@ declare -i max_counter=16 # 16*5=80s ...@@ -62,7 +66,7 @@ declare -i max_counter=16 # 16*5=80s
declare -i total_time=0 declare -i total_time=0
printf "Waiting for server startup" >> $STARTUP_LOG printf "Waiting for server startup" >> $STARTUP_LOG
until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --head $SERVER_URL | grep "Coyote")" != "" ]]; until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "Coyote")" != "" ]];
do do
printf "." >> $STARTUP_LOG printf "." >> $STARTUP_LOG
counter+=1 counter+=1
......
package com.ctrip.framework.apollo; package com.ctrip.framework.apollo;
import com.ctrip.framework.apollo.adminservice.AdminServiceApplication;
import com.ctrip.framework.apollo.common.controller.HttpMessageConverterConfiguration; import com.ctrip.framework.apollo.common.controller.HttpMessageConverterConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
...@@ -8,8 +9,6 @@ import org.springframework.context.annotation.ComponentScan.Filter; ...@@ -8,8 +9,6 @@ import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType; import org.springframework.context.annotation.FilterType;
import com.ctrip.framework.apollo.adminservice.AdminServiceApplication;
@Configuration @Configuration
@ComponentScan(excludeFilters = {@Filter(type = FilterType.ASSIGNABLE_TYPE, value = { @ComponentScan(excludeFilters = {@Filter(type = FilterType.ASSIGNABLE_TYPE, value = {
LocalAdminServiceApplication.class, AdminServiceApplication.class, LocalAdminServiceApplication.class, AdminServiceApplication.class,
......
package com.ctrip.framework.apollo.adminservice.controller; package com.ctrip.framework.apollo.adminservice.controller;
import javax.annotation.PostConstruct; import com.ctrip.framework.apollo.AdminServiceTestConfiguration;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -13,7 +13,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -13,7 +13,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.client.DefaultResponseErrorHandler; import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import com.ctrip.framework.apollo.AdminServiceTestConfiguration; import javax.annotation.PostConstruct;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = AdminServiceTestConfiguration.class) @SpringApplicationConfiguration(classes = AdminServiceTestConfiguration.class)
......
package com.ctrip.framework.apollo.adminservice.controller; package com.ctrip.framework.apollo.adminservice.controller;
import com.ctrip.framework.apollo.biz.repository.AppRepository;
import com.ctrip.framework.apollo.common.dto.AppDTO;
import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -9,11 +14,6 @@ import org.springframework.test.context.jdbc.Sql; ...@@ -9,11 +14,6 @@ import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.Sql.ExecutionPhase; import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.HttpClientErrorException;
import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.biz.repository.AppRepository;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.dto.AppDTO;
public class AppControllerTest extends AbstractControllerTest { public class AppControllerTest extends AbstractControllerTest {
@Autowired @Autowired
......
package com.ctrip.framework.apollo.adminservice.controller; package com.ctrip.framework.apollo.adminservice.controller;
import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.biz.repository.AppNamespaceRepository; import com.ctrip.framework.apollo.biz.repository.AppNamespaceRepository;
import com.ctrip.framework.apollo.common.dto.AppNamespaceDTO; import com.ctrip.framework.apollo.common.dto.AppNamespaceDTO;
import com.ctrip.framework.apollo.common.entity.AppNamespace;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
......
package com.ctrip.framework.apollo.adminservice.controller; package com.ctrip.framework.apollo.adminservice.controller;
import static org.mockito.Matchers.any; import com.ctrip.framework.apollo.biz.service.AdminService;
import static org.mockito.Mockito.when; import com.ctrip.framework.apollo.biz.service.AppService;
import com.ctrip.framework.apollo.common.dto.AppDTO;
import java.util.ArrayList; import com.ctrip.framework.apollo.common.entity.App;
import java.util.List; import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.exception.ServiceException;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
...@@ -16,12 +17,11 @@ import org.springframework.data.domain.PageRequest; ...@@ -16,12 +17,11 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
import com.ctrip.framework.apollo.common.entity.App; import java.util.ArrayList;
import com.ctrip.framework.apollo.biz.service.AdminService; import java.util.List;
import com.ctrip.framework.apollo.biz.service.AppService;
import com.ctrip.framework.apollo.common.dto.AppDTO; import static org.mockito.Matchers.any;
import com.ctrip.framework.apollo.common.exception.NotFoundException; import static org.mockito.Mockito.when;
import com.ctrip.framework.apollo.common.exception.ServiceException;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class ControllerExceptionTest { public class ControllerExceptionTest {
......
package com.ctrip.framework.apollo.adminservice.controller; package com.ctrip.framework.apollo.adminservice.controller;
import static org.mockito.Matchers.any; import com.google.gson.Gson;
import static org.mockito.Mockito.when;
import java.util.Map; import com.ctrip.framework.apollo.biz.service.AdminService;
import com.ctrip.framework.apollo.biz.service.AppService;
import com.ctrip.framework.apollo.common.dto.AppDTO;
import com.ctrip.framework.apollo.common.entity.App;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
...@@ -16,12 +18,10 @@ import org.springframework.test.context.jdbc.Sql.ExecutionPhase; ...@@ -16,12 +18,10 @@ import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.client.HttpStatusCodeException; import org.springframework.web.client.HttpStatusCodeException;
import com.ctrip.framework.apollo.common.entity.App; import java.util.Map;
import com.ctrip.framework.apollo.biz.service.AdminService;
import com.ctrip.framework.apollo.biz.service.AppService;
import com.ctrip.framework.apollo.common.dto.AppDTO;
import com.google.gson.Gson; import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;
public class ControllerIntegrationExceptionTest extends AbstractControllerTest { public class ControllerIntegrationExceptionTest extends AbstractControllerTest {
......
package com.ctrip.framework.apollo.adminservice.controller; package com.ctrip.framework.apollo.adminservice.controller;
import java.util.List; import com.ctrip.framework.apollo.biz.entity.Item;
import com.ctrip.framework.apollo.biz.repository.ItemRepository;
import com.ctrip.framework.apollo.common.dto.AppDTO;
import com.ctrip.framework.apollo.common.dto.ClusterDTO;
import com.ctrip.framework.apollo.common.dto.ItemChangeSets;
import com.ctrip.framework.apollo.common.dto.ItemDTO;
import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
...@@ -12,13 +18,7 @@ import org.springframework.test.context.jdbc.Sql; ...@@ -12,13 +18,7 @@ import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.Sql.ExecutionPhase; import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import com.ctrip.framework.apollo.biz.entity.Item; import java.util.List;
import com.ctrip.framework.apollo.biz.repository.ItemRepository;
import com.ctrip.framework.apollo.common.dto.AppDTO;
import com.ctrip.framework.apollo.common.dto.ClusterDTO;
import com.ctrip.framework.apollo.common.dto.ItemChangeSets;
import com.ctrip.framework.apollo.common.dto.ItemDTO;
import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
public class ItemSetControllerTest extends AbstractControllerTest { public class ItemSetControllerTest extends AbstractControllerTest {
......
...@@ -9,12 +9,12 @@ import com.ctrip.framework.apollo.biz.message.Topics; ...@@ -9,12 +9,12 @@ import com.ctrip.framework.apollo.biz.message.Topics;
import com.ctrip.framework.apollo.biz.repository.ReleaseRepository; import com.ctrip.framework.apollo.biz.repository.ReleaseRepository;
import com.ctrip.framework.apollo.biz.service.NamespaceService; import com.ctrip.framework.apollo.biz.service.NamespaceService;
import com.ctrip.framework.apollo.biz.service.ReleaseService; import com.ctrip.framework.apollo.biz.service.ReleaseService;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.common.dto.AppDTO; import com.ctrip.framework.apollo.common.dto.AppDTO;
import com.ctrip.framework.apollo.common.dto.ClusterDTO; import com.ctrip.framework.apollo.common.dto.ClusterDTO;
import com.ctrip.framework.apollo.common.dto.ItemDTO; import com.ctrip.framework.apollo.common.dto.ItemDTO;
import com.ctrip.framework.apollo.common.dto.NamespaceDTO; import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
import com.ctrip.framework.apollo.common.dto.ReleaseDTO; import com.ctrip.framework.apollo.common.dto.ReleaseDTO;
import com.ctrip.framework.apollo.core.ConfigConsts;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
......
<plexus>
<components>
<component>
<role>com.dianping.cat.configuration.ClientConfigManager</role>
<implementation>com.ctrip.framework.apollo.cat.NullClientConfigManager
</implementation>
</component>
<component>
<role>com.dianping.cat.message.io.TransportManager</role>
<implementation>com.ctrip.framework.apollo.cat.NullTransportManager
</implementation>
</component>
<component>
<role>com.dianping.cat.message.spi.MessageManager</role>
<implementation>com.ctrip.framework.apollo.cat.NullMessageManager
</implementation>
<requirements>
<requirement>
<role>com.dianping.cat.message.internal.MessageIdFactory</role>
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.message.MessageProducer</role>
<implementation>com.ctrip.framework.apollo.cat.NullMessageProducer
</implementation>
<requirements>
<requirement>
<role>com.dianping.cat.message.spi.MessageManager</role>
</requirement>
<requirement>
<role>com.dianping.cat.message.internal.MessageIdFactory</role>
</requirement>
</requirements>
</component>
<component>
<role>org.codehaus.plexus.logging.LoggerManager</role>
<implementation>com.ctrip.framework.apollo.cat.NullLoggerManager
</implementation>
</component>
</components>
</plexus>
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.ctrip.framework.apollo</groupId> <groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId> <artifactId>apollo</artifactId>
<version>0.2.0</version> <version>0.4.0</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -27,11 +27,6 @@ ...@@ -27,11 +27,6 @@
<groupId>com.ctrip.framework.apollo</groupId> <groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-portal</artifactId> <artifactId>apollo-portal</artifactId>
</dependency> </dependency>
<!-- disable cat for assembly -->
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-buildtools</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.h2database</groupId> <groupId>com.h2database</groupId>
<artifactId>h2</artifactId> <artifactId>h2</artifactId>
......
package com.ctrip.framework.apollo.assembly; package com.ctrip.framework.apollo.assembly;
import com.ctrip.framework.apollo.adminservice.AdminServiceApplication;
import com.ctrip.framework.apollo.configservice.ConfigServiceApplication;
import com.ctrip.framework.apollo.portal.PortalApplication;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.system.ApplicationPidFileWriter; import org.springframework.boot.actuate.system.ApplicationPidFileWriter;
...@@ -10,10 +14,6 @@ import org.springframework.boot.builder.SpringApplicationBuilder; ...@@ -10,10 +14,6 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.context.scope.refresh.RefreshScope; import org.springframework.cloud.context.scope.refresh.RefreshScope;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import com.ctrip.framework.apollo.portal.PortalApplication;
import com.ctrip.framework.apollo.adminservice.AdminServiceApplication;
import com.ctrip.framework.apollo.configservice.ConfigServiceApplication;
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class,
HibernateJpaAutoConfiguration.class}) HibernateJpaAutoConfiguration.class})
public class ApolloApplication { public class ApolloApplication {
......
<plexus>
<components>
<component>
<role>com.dianping.cat.configuration.ClientConfigManager</role>
<implementation>com.ctrip.framework.apollo.cat.NullClientConfigManager
</implementation>
</component>
<component>
<role>com.dianping.cat.message.io.TransportManager</role>
<implementation>com.ctrip.framework.apollo.cat.NullTransportManager
</implementation>
</component>
<component>
<role>com.dianping.cat.message.spi.MessageManager</role>
<implementation>com.ctrip.framework.apollo.cat.NullMessageManager
</implementation>
<requirements>
<requirement>
<role>com.dianping.cat.message.internal.MessageIdFactory</role>
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.message.MessageProducer</role>
<implementation>com.ctrip.framework.apollo.cat.NullMessageProducer
</implementation>
<requirements>
<requirement>
<role>com.dianping.cat.message.spi.MessageManager</role>
</requirement>
<requirement>
<role>com.dianping.cat.message.internal.MessageIdFactory</role>
</requirement>
</requirements>
</component>
<component>
<role>org.codehaus.plexus.logging.LoggerManager</role>
<implementation>com.ctrip.framework.apollo.cat.NullLoggerManager
</implementation>
</component>
</components>
</plexus>
package com.ctrip.framework.apollo.assembly; package com.ctrip.framework.apollo.assembly;
import com.ctrip.framework.apollo.adminservice.AdminServiceApplication;
import com.ctrip.framework.apollo.configservice.ConfigServiceApplication;
import com.ctrip.framework.apollo.portal.PortalApplication;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.system.ApplicationPidFileWriter; import org.springframework.boot.actuate.system.ApplicationPidFileWriter;
...@@ -10,10 +14,6 @@ import org.springframework.boot.builder.SpringApplicationBuilder; ...@@ -10,10 +14,6 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.context.scope.refresh.RefreshScope; import org.springframework.cloud.context.scope.refresh.RefreshScope;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import com.ctrip.framework.apollo.adminservice.AdminServiceApplication;
import com.ctrip.framework.apollo.configservice.ConfigServiceApplication;
import com.ctrip.framework.apollo.portal.PortalApplication;
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class,
HibernateJpaAutoConfiguration.class}) HibernateJpaAutoConfiguration.class})
public class LocalApolloApplication { public class LocalApolloApplication {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<parent> <parent>
<artifactId>apollo</artifactId> <artifactId>apollo</artifactId>
<groupId>com.ctrip.framework.apollo</groupId> <groupId>com.ctrip.framework.apollo</groupId>
<version>0.2.0</version> <version>0.4.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>apollo-biz</artifactId> <artifactId>apollo-biz</artifactId>
...@@ -24,11 +24,6 @@ ...@@ -24,11 +24,6 @@
<artifactId>spring-cloud-starter-eureka</artifactId> <artifactId>spring-cloud-starter-eureka</artifactId>
</dependency> </dependency>
<!-- end of eureka --> <!-- end of eureka -->
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-buildtools</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>com.h2database</groupId> <groupId>com.h2database</groupId>
<artifactId>h2</artifactId> <artifactId>h2</artifactId>
......
...@@ -2,13 +2,13 @@ package com.ctrip.framework.apollo.biz.entity; ...@@ -2,13 +2,13 @@ package com.ctrip.framework.apollo.biz.entity;
import com.ctrip.framework.apollo.common.entity.BaseEntity; import com.ctrip.framework.apollo.common.entity.BaseEntity;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
@Entity @Entity
@Table(name = "Audit") @Table(name = "Audit")
@SQLDelete(sql = "Update Audit set isDeleted = 1 where id = ?") @SQLDelete(sql = "Update Audit set isDeleted = 1 where id = ?")
......
...@@ -2,13 +2,13 @@ package com.ctrip.framework.apollo.biz.entity; ...@@ -2,13 +2,13 @@ package com.ctrip.framework.apollo.biz.entity;
import com.ctrip.framework.apollo.common.entity.BaseEntity; import com.ctrip.framework.apollo.common.entity.BaseEntity;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
*/ */
......
...@@ -2,7 +2,6 @@ package com.ctrip.framework.apollo.biz.entity; ...@@ -2,7 +2,6 @@ package com.ctrip.framework.apollo.biz.entity;
import com.ctrip.framework.apollo.common.entity.BaseEntity; import com.ctrip.framework.apollo.common.entity.BaseEntity;
import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where; import org.hibernate.annotations.Where;
......
...@@ -2,14 +2,14 @@ package com.ctrip.framework.apollo.biz.entity; ...@@ -2,14 +2,14 @@ package com.ctrip.framework.apollo.biz.entity;
import com.ctrip.framework.apollo.common.entity.BaseEntity; import com.ctrip.framework.apollo.common.entity.BaseEntity;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Lob; import javax.persistence.Lob;
import javax.persistence.Table; import javax.persistence.Table;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
@Entity @Entity
@Table(name = "Item") @Table(name = "Item")
@SQLDelete(sql = "Update Item set isDeleted = 1 where id = ?") @SQLDelete(sql = "Update Item set isDeleted = 1 where id = ?")
......
...@@ -2,13 +2,13 @@ package com.ctrip.framework.apollo.biz.entity; ...@@ -2,13 +2,13 @@ package com.ctrip.framework.apollo.biz.entity;
import com.ctrip.framework.apollo.common.entity.BaseEntity; import com.ctrip.framework.apollo.common.entity.BaseEntity;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
@Entity @Entity
@Table(name = "Namespace") @Table(name = "Namespace")
@SQLDelete(sql = "Update Namespace set isDeleted = 1 where id = ?") @SQLDelete(sql = "Update Namespace set isDeleted = 1 where id = ?")
...@@ -24,6 +24,16 @@ public class Namespace extends BaseEntity { ...@@ -24,6 +24,16 @@ public class Namespace extends BaseEntity {
@Column(name = "NamespaceName", nullable = false) @Column(name = "NamespaceName", nullable = false)
private String namespaceName; private String namespaceName;
public Namespace(){
}
public Namespace(String appId, String clusterName, String namespaceName) {
this.appId = appId;
this.clusterName = clusterName;
this.namespaceName = namespaceName;
}
public String getAppId() { public String getAppId() {
return appId; return appId;
} }
......
...@@ -2,13 +2,13 @@ package com.ctrip.framework.apollo.biz.entity; ...@@ -2,13 +2,13 @@ package com.ctrip.framework.apollo.biz.entity;
import com.ctrip.framework.apollo.common.entity.BaseEntity; import com.ctrip.framework.apollo.common.entity.BaseEntity;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
@Entity @Entity
@Table(name = "Privilege") @Table(name = "Privilege")
@SQLDelete(sql = "Update Privilege set isDeleted = 1 where id = ?") @SQLDelete(sql = "Update Privilege set isDeleted = 1 where id = ?")
......
...@@ -20,9 +20,8 @@ import com.ctrip.framework.apollo.common.dto.GrayReleaseRuleItemDTO; ...@@ -20,9 +20,8 @@ import com.ctrip.framework.apollo.common.dto.GrayReleaseRuleItemDTO;
import com.ctrip.framework.apollo.common.utils.GrayReleaseRuleItemTransformer; import com.ctrip.framework.apollo.common.utils.GrayReleaseRuleItemTransformer;
import com.ctrip.framework.apollo.core.ConfigConsts; import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory; import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.dianping.cat.Cat; import com.ctrip.framework.apollo.tracer.Tracer;
import com.dianping.cat.message.Message; import com.ctrip.framework.apollo.tracer.spi.Transaction;
import com.dianping.cat.message.Transaction;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -102,12 +101,12 @@ public class GrayReleaseRulesHolder implements ReleaseMessageListener, Initializ ...@@ -102,12 +101,12 @@ public class GrayReleaseRulesHolder implements ReleaseMessageListener, Initializ
} }
private void periodicScanRules() { private void periodicScanRules() {
Transaction transaction = Cat.newTransaction("Apollo.GrayReleaseRulesScanner", Transaction transaction = Tracer.newTransaction("Apollo.GrayReleaseRulesScanner",
"scanGrayReleaseRules"); "scanGrayReleaseRules");
try { try {
loadVersion.incrementAndGet(); loadVersion.incrementAndGet();
scanGrayReleaseRules(); scanGrayReleaseRules();
transaction.setStatus(Message.SUCCESS); transaction.setStatus(Transaction.SUCCESS);
} catch (Throwable ex) { } catch (Throwable ex) {
transaction.setStatus(ex); transaction.setStatus(ex);
logger.error("Scan gray release rule failed", ex); logger.error("Scan gray release rule failed", ex);
...@@ -238,7 +237,7 @@ public class GrayReleaseRulesHolder implements ReleaseMessageListener, Initializ ...@@ -238,7 +237,7 @@ public class GrayReleaseRulesHolder implements ReleaseMessageListener, Initializ
ruleItems = GrayReleaseRuleItemTransformer.batchTransformFromJSON(grayReleaseRule.getRules()); ruleItems = GrayReleaseRuleItemTransformer.batchTransformFromJSON(grayReleaseRule.getRules());
} catch (Throwable ex) { } catch (Throwable ex) {
ruleItems = Sets.newHashSet(); ruleItems = Sets.newHashSet();
Cat.logError(ex); Tracer.logError(ex);
logger.error("parse rule for gray release rule {} failed", grayReleaseRule.getId(), ex); logger.error("parse rule for gray release rule {} failed", grayReleaseRule.getId(), ex);
} }
...@@ -257,7 +256,7 @@ public class GrayReleaseRulesHolder implements ReleaseMessageListener, Initializ ...@@ -257,7 +256,7 @@ public class GrayReleaseRulesHolder implements ReleaseMessageListener, Initializ
databaseScanInterval = Integer.parseInt(interval); databaseScanInterval = Integer.parseInt(interval);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(ex); Tracer.logError(ex);
logger.error("Load apollo gray release rule scan interval from server config failed", ex); logger.error("Load apollo gray release rule scan interval from server config failed", ex);
} }
} }
......
...@@ -2,9 +2,8 @@ package com.ctrip.framework.apollo.biz.message; ...@@ -2,9 +2,8 @@ package com.ctrip.framework.apollo.biz.message;
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage; import com.ctrip.framework.apollo.biz.entity.ReleaseMessage;
import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository; import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository;
import com.dianping.cat.Cat; import com.ctrip.framework.apollo.tracer.Tracer;
import com.dianping.cat.message.Message; import com.ctrip.framework.apollo.tracer.spi.Transaction;
import com.dianping.cat.message.Transaction;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -31,11 +30,11 @@ public class DatabaseMessageSender implements MessageSender { ...@@ -31,11 +30,11 @@ public class DatabaseMessageSender implements MessageSender {
return; return;
} }
Cat.logEvent("Apollo.AdminService.ReleaseMessage", message); Tracer.logEvent("Apollo.AdminService.ReleaseMessage", message);
Transaction transaction = Cat.newTransaction("Apollo.AdminService", "sendMessage"); Transaction transaction = Tracer.newTransaction("Apollo.AdminService", "sendMessage");
try { try {
releaseMessageRepository.save(new ReleaseMessage(message)); releaseMessageRepository.save(new ReleaseMessage(message));
transaction.setStatus(Message.SUCCESS); transaction.setStatus(Transaction.SUCCESS);
} catch (Throwable ex) { } catch (Throwable ex) {
logger.error("Sending message to database failed", ex); logger.error("Sending message to database failed", ex);
transaction.setStatus(ex); transaction.setStatus(ex);
......
...@@ -5,9 +5,8 @@ import com.google.common.collect.Lists; ...@@ -5,9 +5,8 @@ import com.google.common.collect.Lists;
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage; import com.ctrip.framework.apollo.biz.entity.ReleaseMessage;
import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository; import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository;
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory; import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.dianping.cat.Cat; import com.ctrip.framework.apollo.tracer.Tracer;
import com.dianping.cat.message.Message; import com.ctrip.framework.apollo.tracer.spi.Transaction;
import com.dianping.cat.message.Transaction;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -48,10 +47,10 @@ public class ReleaseMessageScanner implements InitializingBean { ...@@ -48,10 +47,10 @@ public class ReleaseMessageScanner implements InitializingBean {
populateDataBaseInterval(); populateDataBaseInterval();
maxIdScanned = loadLargestMessageId(); maxIdScanned = loadLargestMessageId();
executorService.scheduleWithFixedDelay((Runnable) () -> { executorService.scheduleWithFixedDelay((Runnable) () -> {
Transaction transaction = Cat.newTransaction("Apollo.ReleaseMessageScanner", "scanMessage"); Transaction transaction = Tracer.newTransaction("Apollo.ReleaseMessageScanner", "scanMessage");
try { try {
scanMessages(); scanMessages();
transaction.setStatus(Message.SUCCESS); transaction.setStatus(Transaction.SUCCESS);
} catch (Throwable ex) { } catch (Throwable ex) {
transaction.setStatus(ex); transaction.setStatus(ex);
logger.error("Scan and send message failed", ex); logger.error("Scan and send message failed", ex);
...@@ -119,7 +118,7 @@ public class ReleaseMessageScanner implements InitializingBean { ...@@ -119,7 +118,7 @@ public class ReleaseMessageScanner implements InitializingBean {
try { try {
listener.handleMessage(message, Topics.APOLLO_RELEASE_TOPIC); listener.handleMessage(message, Topics.APOLLO_RELEASE_TOPIC);
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(ex); Tracer.logError(ex);
logger.error("Failed to invoke message listener {}", listener.getClass(), ex); logger.error("Failed to invoke message listener {}", listener.getClass(), ex);
} }
} }
...@@ -134,7 +133,7 @@ public class ReleaseMessageScanner implements InitializingBean { ...@@ -134,7 +133,7 @@ public class ReleaseMessageScanner implements InitializingBean {
databaseScanInterval = Integer.parseInt(interval); databaseScanInterval = Integer.parseInt(interval);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(ex); Tracer.logError(ex);
logger.error("Load apollo message scan interval from system property failed", ex); logger.error("Load apollo message scan interval from system property failed", ex);
} }
} }
......
package com.ctrip.framework.apollo.biz.repository; package com.ctrip.framework.apollo.biz.repository;
import org.springframework.data.repository.PagingAndSortingRepository;
import com.ctrip.framework.apollo.common.entity.AppNamespace; import com.ctrip.framework.apollo.common.entity.AppNamespace;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
......
package com.ctrip.framework.apollo.biz.repository; package com.ctrip.framework.apollo.biz.repository;
import java.util.List; import com.ctrip.framework.apollo.common.entity.App;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import com.ctrip.framework.apollo.common.entity.App; import java.util.List;
public interface AppRepository extends PagingAndSortingRepository<App, Long> { public interface AppRepository extends PagingAndSortingRepository<App, Long> {
......
package com.ctrip.framework.apollo.biz.repository; package com.ctrip.framework.apollo.biz.repository;
import java.util.List; import com.ctrip.framework.apollo.biz.entity.Audit;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import com.ctrip.framework.apollo.biz.entity.Audit; import java.util.List;
public interface AuditRepository extends PagingAndSortingRepository<Audit, Long> { public interface AuditRepository extends PagingAndSortingRepository<Audit, Long> {
......
package com.ctrip.framework.apollo.biz.repository; package com.ctrip.framework.apollo.biz.repository;
import com.ctrip.framework.apollo.biz.entity.GrayReleaseRule; import com.ctrip.framework.apollo.biz.entity.GrayReleaseRule;
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.PagingAndSortingRepository;
......
...@@ -4,6 +4,7 @@ import com.ctrip.framework.apollo.biz.entity.InstanceConfig; ...@@ -4,6 +4,7 @@ import com.ctrip.framework.apollo.biz.entity.InstanceConfig;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
...@@ -26,6 +27,10 @@ public interface InstanceConfigRepository extends PagingAndSortingRepository<Ins ...@@ -26,6 +27,10 @@ public interface InstanceConfigRepository extends PagingAndSortingRepository<Ins
List<InstanceConfig> findByConfigAppIdAndConfigClusterNameAndConfigNamespaceNameAndDataChangeLastModifiedTimeAfterAndReleaseKeyNotIn( List<InstanceConfig> findByConfigAppIdAndConfigClusterNameAndConfigNamespaceNameAndDataChangeLastModifiedTimeAfterAndReleaseKeyNotIn(
String appId, String clusterName, String namespaceName, Date validDate, Set<String> releaseKey); String appId, String clusterName, String namespaceName, Date validDate, Set<String> releaseKey);
@Modifying
@Query("delete from InstanceConfig where ConfigAppId=?1 and ConfigClusterName=?2 and ConfigNamespaceName = ?3")
int batchDelete(String appId, String clusterName, String namespaceName);
@Query( @Query(
value = "select b.Id from `InstanceConfig` a inner join `Instance` b on b.Id =" + value = "select b.Id from `InstanceConfig` a inner join `Instance` b on b.Id =" +
" a.`InstanceId` where a.`ConfigAppId` = :configAppId and a.`ConfigClusterName` = " + " a.`InstanceId` where a.`ConfigAppId` = :configAppId and a.`ConfigClusterName` = " +
......
package com.ctrip.framework.apollo.biz.repository; package com.ctrip.framework.apollo.biz.repository;
import java.util.List; import com.ctrip.framework.apollo.biz.entity.Item;
import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.PagingAndSortingRepository;
import com.ctrip.framework.apollo.biz.entity.Item; import java.util.List;
public interface ItemRepository extends PagingAndSortingRepository<Item, Long> { public interface ItemRepository extends PagingAndSortingRepository<Item, Long> {
......
package com.ctrip.framework.apollo.biz.repository; package com.ctrip.framework.apollo.biz.repository;
import java.util.List; import com.ctrip.framework.apollo.biz.entity.Namespace;
import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.PagingAndSortingRepository;
import com.ctrip.framework.apollo.biz.entity.Namespace; import java.util.List;
public interface NamespaceRepository extends PagingAndSortingRepository<Namespace, Long> { public interface NamespaceRepository extends PagingAndSortingRepository<Namespace, Long> {
......
package com.ctrip.framework.apollo.biz.repository; package com.ctrip.framework.apollo.biz.repository;
import org.springframework.data.repository.PagingAndSortingRepository;
import com.ctrip.framework.apollo.biz.entity.Privilege; import com.ctrip.framework.apollo.biz.entity.Privilege;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List; import java.util.List;
public interface PrivilegeRepository extends PagingAndSortingRepository<Privilege, Long> { public interface PrivilegeRepository extends PagingAndSortingRepository<Privilege, Long> {
......
...@@ -4,6 +4,8 @@ import com.ctrip.framework.apollo.biz.entity.ReleaseHistory; ...@@ -4,6 +4,8 @@ import com.ctrip.framework.apollo.biz.entity.ReleaseHistory;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List; import java.util.List;
...@@ -15,5 +17,12 @@ public interface ReleaseHistoryRepository extends PagingAndSortingRepository<Rel ...@@ -15,5 +17,12 @@ public interface ReleaseHistoryRepository extends PagingAndSortingRepository<Rel
Page<ReleaseHistory> findByAppIdAndClusterNameAndNamespaceNameOrderByIdDesc(String appId, String Page<ReleaseHistory> findByAppIdAndClusterNameAndNamespaceNameOrderByIdDesc(String appId, String
clusterName, String namespaceName, Pageable pageable); clusterName, String namespaceName, Pageable pageable);
List<ReleaseHistory> findByReleaseId(long releaseId); Page<ReleaseHistory> findByReleaseIdAndOperationOrderByIdDesc(long releaseId, int operation, Pageable pageable);
Page<ReleaseHistory> findByPreviousReleaseIdAndOperationOrderByIdDesc(long previousReleaseId, int operation, Pageable pageable);
@Modifying
@Query("update ReleaseHistory set isdeleted=1,DataChange_LastModifiedBy = ?4 where appId=?1 and clusterName=?2 and namespaceName = ?3")
int batchDelete(String appId, String clusterName, String namespaceName, String operator);
} }
package com.ctrip.framework.apollo.biz.repository; package com.ctrip.framework.apollo.biz.repository;
import java.util.List; import com.ctrip.framework.apollo.biz.entity.Release;
import java.util.Set;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Modifying;
...@@ -9,7 +8,8 @@ import org.springframework.data.jpa.repository.Query; ...@@ -9,7 +8,8 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import com.ctrip.framework.apollo.biz.entity.Release; import java.util.List;
import java.util.Set;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
......
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.core.ConfigConsts;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.core.ConfigConsts;
@Service @Service
public class AdminService { public class AdminService {
......
...@@ -8,10 +8,10 @@ import com.ctrip.framework.apollo.biz.entity.Cluster; ...@@ -8,10 +8,10 @@ import com.ctrip.framework.apollo.biz.entity.Cluster;
import com.ctrip.framework.apollo.biz.entity.Namespace; import com.ctrip.framework.apollo.biz.entity.Namespace;
import com.ctrip.framework.apollo.biz.repository.AppNamespaceRepository; import com.ctrip.framework.apollo.biz.repository.AppNamespaceRepository;
import com.ctrip.framework.apollo.common.entity.AppNamespace; import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.common.exception.ServiceException;
import com.ctrip.framework.apollo.common.utils.BeanUtils; import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.ConfigConsts; import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.common.exception.ServiceException;
import com.ctrip.framework.apollo.core.utils.StringUtils; import com.ctrip.framework.apollo.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -34,8 +34,6 @@ public class AppNamespaceService { ...@@ -34,8 +34,6 @@ public class AppNamespaceService {
private ClusterService clusterService; private ClusterService clusterService;
@Autowired @Autowired
private AuditService auditService; private AuditService auditService;
@Autowired
private ServerConfigService serverConfigService;
public boolean isAppNamespaceNameUnique(String appId, String namespaceName) { public boolean isAppNamespaceNameUnique(String appId, String namespaceName) {
Objects.requireNonNull(appId, "AppId must not be null"); Objects.requireNonNull(appId, "AppId must not be null");
......
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import java.util.List; import com.ctrip.framework.apollo.biz.entity.Audit;
import java.util.Objects; import com.ctrip.framework.apollo.biz.repository.AppRepository;
import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.common.exception.ServiceException;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
...@@ -9,11 +12,8 @@ import org.springframework.data.domain.Pageable; ...@@ -9,11 +12,8 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.ctrip.framework.apollo.common.entity.App; import java.util.List;
import com.ctrip.framework.apollo.biz.entity.Audit; import java.util.Objects;
import com.ctrip.framework.apollo.biz.repository.AppRepository;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.exception.ServiceException;
@Service @Service
public class AppService { public class AppService {
......
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import java.util.List; import com.ctrip.framework.apollo.biz.entity.Audit;
import com.ctrip.framework.apollo.biz.repository.AuditRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.ctrip.framework.apollo.biz.entity.Audit; import java.util.List;
import com.ctrip.framework.apollo.biz.repository.AuditRepository;
@Service @Service
public class AuditService { public class AuditService {
......
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import java.util.Collections; import com.google.common.base.Strings;
import java.util.List;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ctrip.framework.apollo.biz.entity.Audit; import com.ctrip.framework.apollo.biz.entity.Audit;
import com.ctrip.framework.apollo.biz.entity.Cluster; import com.ctrip.framework.apollo.biz.entity.Cluster;
import com.ctrip.framework.apollo.biz.repository.ClusterRepository; import com.ctrip.framework.apollo.biz.repository.ClusterRepository;
import com.ctrip.framework.apollo.common.exception.BadRequestException; import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.exception.ServiceException;
import com.ctrip.framework.apollo.common.utils.BeanUtils; import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.ConfigConsts; import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.common.exception.ServiceException;
import com.google.common.base.Strings; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@Service @Service
public class ClusterService { public class ClusterService {
......
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Interner;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.ctrip.framework.apollo.biz.entity.Instance; import com.ctrip.framework.apollo.biz.entity.Instance;
...@@ -172,4 +171,9 @@ public class InstanceService { ...@@ -172,4 +171,9 @@ public class InstanceService {
return instanceConfigRepository.save(existedInstanceConfig); return instanceConfigRepository.save(existedInstanceConfig);
} }
@Transactional
public int batchDeleteInstanceConfig(String configAppId, String configClusterName, String configNamespaceName){
return instanceConfigRepository.batchDelete(configAppId, configClusterName, configNamespaceName);
}
} }
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import com.google.common.base.Strings;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ctrip.framework.apollo.biz.entity.Audit; import com.ctrip.framework.apollo.biz.entity.Audit;
import com.ctrip.framework.apollo.biz.entity.Item; import com.ctrip.framework.apollo.biz.entity.Item;
import com.ctrip.framework.apollo.biz.entity.Namespace; import com.ctrip.framework.apollo.biz.entity.Namespace;
import com.ctrip.framework.apollo.biz.repository.ItemRepository; import com.ctrip.framework.apollo.biz.repository.ItemRepository;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.exception.BadRequestException; import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.exception.NotFoundException; import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.ctrip.framework.apollo.core.utils.StringUtils; import com.ctrip.framework.apollo.core.utils.StringUtils;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.tracer.spi.Transaction;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.lang.reflect.Type;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
@Service @Service
public class ItemService { public class ItemService implements InitializingBean {
private static final int DEFAULT_LIMIT_UPDATE_INTERVAL_IN_SECONDS = 60;
@Autowired @Autowired
private ItemRepository itemRepository; private ItemRepository itemRepository;
...@@ -31,6 +47,61 @@ public class ItemService { ...@@ -31,6 +47,61 @@ public class ItemService {
@Autowired @Autowired
private ServerConfigService serverConfigService; private ServerConfigService serverConfigService;
private AtomicInteger globalKeyLengthLimit;
private AtomicInteger globalValueLengthLimit;
private AtomicReference<Map<Long, Integer>> namespaceValueLengthOverride;
private Gson gson;
private ScheduledExecutorService executorService;
private static final Type namespaceValueLengthOverrideTypeReference =
new TypeToken<Map<Long, Integer>>() {
}.getType();
public ItemService() {
gson = new Gson();
globalKeyLengthLimit = new AtomicInteger(128);
globalValueLengthLimit = new AtomicInteger(20000);
namespaceValueLengthOverride = new AtomicReference<>();
executorService = Executors.newScheduledThreadPool(1, ApolloThreadFactory
.create("ItemServiceLimitUpdater", true));
}
@Override
public void afterPropertiesSet() throws Exception {
executorService.scheduleWithFixedDelay(() -> {
Transaction transaction = Tracer.newTransaction("Apollo.ItemServiceLimitUpdater", "updateLimit");
try {
updateLimits();
transaction.setStatus(Transaction.SUCCESS);
} catch (Throwable ex) {
transaction.setStatus(ex);
} finally {
transaction.complete();
}
}, 0, getLimitUpdateIntervalInSeconds(), TimeUnit.SECONDS);
}
private void updateLimits() {
String keyLengthLimit = serverConfigService.getValue("item.key.length.limit", null);
if (!Strings.isNullOrEmpty(keyLengthLimit)) {
globalKeyLengthLimit.set(Integer.valueOf(keyLengthLimit));
}
String valueLengthLimit = serverConfigService.getValue("item.value.length.limit", null);
if (!Strings.isNullOrEmpty(valueLengthLimit)) {
globalValueLengthLimit.set(Integer.valueOf(valueLengthLimit));
}
String namespaceValueLengthOverrideString =
serverConfigService.getValue("namespace.value.length.limit.override", null);
if (!Strings.isNullOrEmpty(namespaceValueLengthOverrideString)) {
namespaceValueLengthOverride.set(gson.fromJson(
namespaceValueLengthOverrideString, namespaceValueLengthOverrideTypeReference));
}
}
@Transactional @Transactional
public Item delete(long id, String operator) { public Item delete(long id, String operator) {
Item item = itemRepository.findOne(id); Item item = itemRepository.findOne(id);
...@@ -100,7 +171,7 @@ public class ItemService { ...@@ -100,7 +171,7 @@ public class ItemService {
@Transactional @Transactional
public Item save(Item entity) { public Item save(Item entity) {
checkItemKeyLength(entity.getKey()); checkItemKeyLength(entity.getKey());
checkItemValueLength(entity.getValue()); checkItemValueLength(entity.getNamespaceId(), entity.getValue());
entity.setId(0);//protection entity.setId(0);//protection
...@@ -120,7 +191,7 @@ public class ItemService { ...@@ -120,7 +191,7 @@ public class ItemService {
@Transactional @Transactional
public Item update(Item item) { public Item update(Item item) {
checkItemValueLength(item.getValue()); checkItemValueLength(item.getNamespaceId(), item.getValue());
Item managedItem = itemRepository.findOne(item.getId()); Item managedItem = itemRepository.findOne(item.getId());
BeanUtils.copyEntityProperties(item, managedItem); BeanUtils.copyEntityProperties(item, managedItem);
managedItem = itemRepository.save(managedItem); managedItem = itemRepository.save(managedItem);
...@@ -131,20 +202,30 @@ public class ItemService { ...@@ -131,20 +202,30 @@ public class ItemService {
return managedItem; return managedItem;
} }
private boolean checkItemValueLength(String value) { private boolean checkItemValueLength(long namespaceId, String value) {
int lengthLimit = Integer.valueOf(serverConfigService.getValue("item.value.length.limit", "20000")); int limit = getItemValueLengthLimit(namespaceId);
if (!StringUtils.isEmpty(value) && value.length() > lengthLimit) { if (!StringUtils.isEmpty(value) && value.length() > limit) {
throw new BadRequestException("value too long. length limit:" + lengthLimit); throw new BadRequestException("value too long. length limit:" + limit);
} }
return true; return true;
} }
private boolean checkItemKeyLength(String key) { private boolean checkItemKeyLength(String key) {
int lengthLimit = Integer.valueOf(serverConfigService.getValue("item.key.length.limit", "128")); if (!StringUtils.isEmpty(key) && key.length() > globalKeyLengthLimit.get()) {
if (!StringUtils.isEmpty(key) && key.length() > lengthLimit) { throw new BadRequestException("key too long. length limit:" + globalKeyLengthLimit.get());
throw new BadRequestException("key too long. length limit:" + lengthLimit);
} }
return true; return true;
} }
private int getItemValueLengthLimit(long namespaceId) {
if (namespaceValueLengthOverride.get() != null && namespaceValueLengthOverride.get()
.containsKey(namespaceId)) {
return namespaceValueLengthOverride.get().get(namespaceId);
}
return globalValueLengthLimit.get();
}
private int getLimitUpdateIntervalInSeconds() {
return DEFAULT_LIMIT_UPDATE_INTERVAL_IN_SECONDS;
}
} }
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import com.ctrip.framework.apollo.biz.entity.Audit; import com.ctrip.framework.apollo.biz.entity.Audit;
import com.ctrip.framework.apollo.biz.entity.Commit; import com.ctrip.framework.apollo.biz.entity.Commit;
import com.ctrip.framework.apollo.biz.entity.Item; import com.ctrip.framework.apollo.biz.entity.Item;
import com.ctrip.framework.apollo.biz.entity.Namespace; import com.ctrip.framework.apollo.biz.entity.Namespace;
import com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder; import com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.dto.ItemChangeSets; import com.ctrip.framework.apollo.common.dto.ItemChangeSets;
import com.ctrip.framework.apollo.common.dto.ItemDTO; import com.ctrip.framework.apollo.common.dto.ItemDTO;
import com.ctrip.framework.apollo.common.exception.NotFoundException; import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@Service @Service
......
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import com.ctrip.framework.apollo.biz.entity.Audit; import com.ctrip.framework.apollo.biz.entity.Audit;
import com.ctrip.framework.apollo.biz.entity.Cluster; import com.ctrip.framework.apollo.biz.entity.Cluster;
import com.ctrip.framework.apollo.biz.entity.Namespace; import com.ctrip.framework.apollo.biz.entity.Namespace;
import com.ctrip.framework.apollo.biz.repository.NamespaceRepository; import com.ctrip.framework.apollo.biz.repository.NamespaceRepository;
import com.ctrip.framework.apollo.common.constants.NamespaceBranchStatus;
import com.ctrip.framework.apollo.common.entity.AppNamespace; import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.exception.ServiceException; import com.ctrip.framework.apollo.common.exception.ServiceException;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
@Service @Service
public class NamespaceService { public class NamespaceService {
...@@ -38,6 +37,15 @@ public class NamespaceService { ...@@ -38,6 +37,15 @@ public class NamespaceService {
private ReleaseService releaseService; private ReleaseService releaseService;
@Autowired @Autowired
private ClusterService clusterService; private ClusterService clusterService;
@Autowired
private NamespaceBranchService namespaceBranchService;
@Autowired
private ReleaseHistoryService releaseHistoryService;
@Autowired
private NamespaceLockService namespaceLockService;
@Autowired
private InstanceService instanceService;
public Namespace findOne(Long namespaceId) { public Namespace findOne(Long namespaceId) {
...@@ -57,25 +65,25 @@ public class NamespaceService { ...@@ -57,25 +65,25 @@ public class NamespaceService {
return namespaces; return namespaces;
} }
public List<Namespace> findByAppIdAndNamespaceName(String appId, String namespaceName){ public List<Namespace> findByAppIdAndNamespaceName(String appId, String namespaceName) {
return namespaceRepository.findByAppIdAndNamespaceName(appId, namespaceName); return namespaceRepository.findByAppIdAndNamespaceName(appId, namespaceName);
} }
public Namespace findChildNamespace(String appId, String parentClusterName, String namespaceName){ public Namespace findChildNamespace(String appId, String parentClusterName, String namespaceName) {
List<Namespace> namespaces = findByAppIdAndNamespaceName(appId, namespaceName); List<Namespace> namespaces = findByAppIdAndNamespaceName(appId, namespaceName);
if (CollectionUtils.isEmpty(namespaces) || namespaces.size() == 1){ if (CollectionUtils.isEmpty(namespaces) || namespaces.size() == 1) {
return null; return null;
} }
List<Cluster> childClusters = clusterService.findChildClusters(appId, parentClusterName); List<Cluster> childClusters = clusterService.findChildClusters(appId, parentClusterName);
if (CollectionUtils.isEmpty(childClusters)){ if (CollectionUtils.isEmpty(childClusters)) {
return null; return null;
} }
Set<String> childClusterNames = childClusters.stream().map(Cluster::getName).collect(Collectors.toSet()); Set<String> childClusterNames = childClusters.stream().map(Cluster::getName).collect(Collectors.toSet());
//the child namespace is the intersection of the child clusters and child namespaces //the child namespace is the intersection of the child clusters and child namespaces
for (Namespace namespace: namespaces){ for (Namespace namespace : namespaces) {
if (childClusterNames.contains(namespace.getClusterName())){ if (childClusterNames.contains(namespace.getClusterName())) {
return namespace; return namespace;
} }
} }
...@@ -83,7 +91,7 @@ public class NamespaceService { ...@@ -83,7 +91,7 @@ public class NamespaceService {
return null; return null;
} }
public Namespace findChildNamespace(Namespace parentNamespace){ public Namespace findChildNamespace(Namespace parentNamespace) {
String appId = parentNamespace.getAppId(); String appId = parentNamespace.getAppId();
String parentClusterName = parentNamespace.getClusterName(); String parentClusterName = parentNamespace.getClusterName();
String namespaceName = parentNamespace.getNamespaceName(); String namespaceName = parentNamespace.getNamespaceName();
...@@ -92,12 +100,16 @@ public class NamespaceService { ...@@ -92,12 +100,16 @@ public class NamespaceService {
} }
public Namespace findParentNamespace(Namespace namespace){ public Namespace findParentNamespace(String appId, String clusterName, String namespaceName){
return findParentNamespace(new Namespace(appId, clusterName, namespaceName));
}
public Namespace findParentNamespace(Namespace namespace) {
String appId = namespace.getAppId(); String appId = namespace.getAppId();
String namespaceName = namespace.getNamespaceName(); String namespaceName = namespace.getNamespaceName();
Cluster cluster = clusterService.findOne(appId, namespace.getClusterName()); Cluster cluster = clusterService.findOne(appId, namespace.getClusterName());
if (cluster != null && cluster.getParentClusterId() > 0){ if (cluster != null && cluster.getParentClusterId() > 0) {
Cluster parentCluster = clusterService.findOne(cluster.getParentClusterId()); Cluster parentCluster = clusterService.findOne(cluster.getParentClusterId());
return findOne(appId, parentCluster.getName(), namespaceName); return findOne(appId, parentCluster.getName(), namespaceName);
} }
...@@ -105,7 +117,11 @@ public class NamespaceService { ...@@ -105,7 +117,11 @@ public class NamespaceService {
return null; return null;
} }
public boolean isChildNamespace(Namespace namespace){ public boolean isChildNamespace(String appId, String clusterName, String namespaceName){
return isChildNamespace(new Namespace(appId, clusterName, namespaceName));
}
public boolean isChildNamespace(Namespace namespace) {
return findParentNamespace(namespace) != null; return findParentNamespace(namespace) != null;
} }
...@@ -118,11 +134,11 @@ public class NamespaceService { ...@@ -118,11 +134,11 @@ public class NamespaceService {
} }
@Transactional @Transactional
public void deleteByAppIdAndClusterName(String appId, String clusterName, String operator){ public void deleteByAppIdAndClusterName(String appId, String clusterName, String operator) {
List<Namespace> toDeleteNamespaces = findNamespaces(appId, clusterName); List<Namespace> toDeleteNamespaces = findNamespaces(appId, clusterName);
for (Namespace namespace: toDeleteNamespaces){ for (Namespace namespace : toDeleteNamespaces) {
deleteNamespace(namespace, operator); deleteNamespace(namespace, operator);
...@@ -130,17 +146,33 @@ public class NamespaceService { ...@@ -130,17 +146,33 @@ public class NamespaceService {
} }
@Transactional @Transactional
public Namespace deleteNamespace(Namespace namespace, String operator){ public Namespace deleteNamespace(Namespace namespace, String operator) {
String appId = namespace.getAppId(); String appId = namespace.getAppId();
String clusterName = namespace.getClusterName(); String clusterName = namespace.getClusterName();
String namespaceName = namespace.getNamespaceName();
itemService.batchDelete(namespace.getId(), operator); itemService.batchDelete(namespace.getId(), operator);
commitService.batchDelete(appId, clusterName, namespace.getNamespaceName(), operator); commitService.batchDelete(appId, clusterName, namespace.getNamespaceName(), operator);
if (!isChildNamespace(namespace)){ if (!isChildNamespace(namespace)) {
releaseService.batchDelete(appId, clusterName, namespace.getNamespaceName(), operator); releaseService.batchDelete(appId, clusterName, namespace.getNamespaceName(), operator);
} }
//delete child namespace
Namespace childNamespace = findChildNamespace(namespace);
if (childNamespace != null) {
namespaceBranchService.deleteBranch(appId, clusterName, namespaceName,
childNamespace.getClusterName(), NamespaceBranchStatus.DELETED, operator);
//delete child namespace's releases. Notice: delete child namespace will not delete child namespace's releases
releaseService.batchDelete(appId, childNamespace.getClusterName(), namespaceName, operator);
}
releaseHistoryService.batchDelete(appId, clusterName, namespaceName, operator);
instanceService.batchDeleteInstanceConfig(appId, clusterName, namespaceName);
namespaceLockService.unlock(namespace.getId());
namespace.setDeleted(true); namespace.setDeleted(true);
namespace.setDataChangeLastModifiedBy(operator); namespace.setDataChangeLastModifiedBy(operator);
...@@ -182,7 +214,7 @@ public class NamespaceService { ...@@ -182,7 +214,7 @@ public class NamespaceService {
//load all private app namespace //load all private app namespace
List<AppNamespace> privateAppNamespaces = appNamespaceService.findPrivateAppNamespace(appId); List<AppNamespace> privateAppNamespaces = appNamespaceService.findPrivateAppNamespace(appId);
//create all private namespace //create all private namespace
for (AppNamespace appNamespace: privateAppNamespaces){ for (AppNamespace appNamespace : privateAppNamespaces) {
Namespace ns = new Namespace(); Namespace ns = new Namespace();
ns.setAppId(appId); ns.setAppId(appId);
ns.setClusterName(clusterName); ns.setClusterName(clusterName);
......
...@@ -13,7 +13,6 @@ import org.springframework.stereotype.Service; ...@@ -13,7 +13,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -21,16 +20,13 @@ import java.util.Map; ...@@ -21,16 +20,13 @@ import java.util.Map;
*/ */
@Service @Service
public class ReleaseHistoryService { public class ReleaseHistoryService {
@Autowired private Gson gson = new Gson();
private ReleaseHistoryRepository releaseHistoryRepository;
@Autowired @Autowired
private ReleaseService releaseService; private ReleaseHistoryRepository releaseHistoryRepository;
@Autowired @Autowired
private AuditService auditService; private AuditService auditService;
private Gson gson = new Gson();
public Page<ReleaseHistory> findReleaseHistoriesByNamespace(String appId, String clusterName, public Page<ReleaseHistory> findReleaseHistoriesByNamespace(String appId, String clusterName,
String namespaceName, Pageable String namespaceName, Pageable
...@@ -39,8 +35,12 @@ public class ReleaseHistoryService { ...@@ -39,8 +35,12 @@ public class ReleaseHistoryService {
namespaceName, pageable); namespaceName, pageable);
} }
public List<ReleaseHistory> findReleaseHistoriesByReleaseId(long releaseId) { public Page<ReleaseHistory> findByReleaseIdAndOperation(long releaseId, int operation, Pageable page) {
return releaseHistoryRepository.findByReleaseId(releaseId); return releaseHistoryRepository.findByReleaseIdAndOperationOrderByIdDesc(releaseId, operation, page);
}
public Page<ReleaseHistory> findByPreviousReleaseIdAndOperation(long previousReleaseId, int operation, Pageable page) {
return releaseHistoryRepository.findByPreviousReleaseIdAndOperationOrderByIdDesc(previousReleaseId, operation, page);
} }
@Transactional @Transactional
...@@ -72,4 +72,8 @@ public class ReleaseHistoryService { ...@@ -72,4 +72,8 @@ public class ReleaseHistoryService {
return releaseHistory; return releaseHistory;
} }
@Transactional
public int batchDelete(String appId, String clusterName, String namespaceName, String operator) {
return releaseHistoryRepository.batchDelete(appId, clusterName, namespaceName, operator);
}
} }
...@@ -4,7 +4,7 @@ import com.google.common.collect.Lists; ...@@ -4,7 +4,7 @@ import com.google.common.collect.Lists;
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage; import com.ctrip.framework.apollo.biz.entity.ReleaseMessage;
import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository; import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository;
import com.dianping.cat.Cat; import com.ctrip.framework.apollo.tracer.Tracer;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -13,7 +13,6 @@ import org.springframework.util.CollectionUtils; ...@@ -13,7 +13,6 @@ import org.springframework.util.CollectionUtils;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
...@@ -43,7 +42,7 @@ public class ReleaseMessageService { ...@@ -43,7 +42,7 @@ public class ReleaseMessageService {
releaseMessage.setId((Long) o[1]); releaseMessage.setId((Long) o[1]);
releaseMessages.add(releaseMessage); releaseMessages.add(releaseMessage);
} catch (Exception ex) { } catch (Exception ex) {
Cat.logError("Parsing LatestReleaseMessagesGroupByMessages failed", ex); Tracer.logError("Parsing LatestReleaseMessagesGroupByMessages failed", ex);
} }
} }
return releaseMessages; return releaseMessages;
......
...@@ -6,7 +6,6 @@ import com.google.gson.GsonBuilder; ...@@ -6,7 +6,6 @@ import com.google.gson.GsonBuilder;
import com.ctrip.framework.apollo.biz.entity.Item; import com.ctrip.framework.apollo.biz.entity.Item;
import com.ctrip.framework.apollo.core.utils.StringUtils; import com.ctrip.framework.apollo.core.utils.StringUtils;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
......
package com.ctrip.framework.apollo.biz.repository; package com.ctrip.framework.apollo.biz.repository;
import com.ctrip.framework.apollo.biz.AbstractIntegrationTest;
import com.ctrip.framework.apollo.common.entity.App;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import com.ctrip.framework.apollo.biz.AbstractIntegrationTest;
import com.ctrip.framework.apollo.common.entity.App;
public class AppRepositoryTest extends AbstractIntegrationTest{ public class AppRepositoryTest extends AbstractIntegrationTest{
@Autowired @Autowired
......
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import java.util.Date;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.ctrip.framework.apollo.biz.AbstractIntegrationTest; import com.ctrip.framework.apollo.biz.AbstractIntegrationTest;
import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.biz.entity.Audit; import com.ctrip.framework.apollo.biz.entity.Audit;
import com.ctrip.framework.apollo.biz.entity.Cluster; import com.ctrip.framework.apollo.biz.entity.Cluster;
import com.ctrip.framework.apollo.biz.entity.Namespace; import com.ctrip.framework.apollo.biz.entity.Namespace;
import com.ctrip.framework.apollo.biz.repository.AppRepository; import com.ctrip.framework.apollo.biz.repository.AppRepository;
import com.ctrip.framework.apollo.core.ConfigConsts; import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.common.exception.ServiceException; import com.ctrip.framework.apollo.common.exception.ServiceException;
import com.ctrip.framework.apollo.core.ConfigConsts;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
import java.util.List;
public class AdminServiceTest extends AbstractIntegrationTest{ public class AdminServiceTest extends AbstractIntegrationTest{
......
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import java.util.Date; import com.ctrip.framework.apollo.biz.AbstractIntegrationTest;
import com.ctrip.framework.apollo.biz.repository.AppNamespaceRepository;
import com.ctrip.framework.apollo.biz.repository.AppRepository;
import com.ctrip.framework.apollo.biz.repository.ClusterRepository;
import com.ctrip.framework.apollo.biz.repository.NamespaceRepository;
import com.ctrip.framework.apollo.common.entity.App;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
...@@ -11,12 +16,7 @@ import org.springframework.test.annotation.Rollback; ...@@ -11,12 +16,7 @@ import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.transaction.AfterTransaction; import org.springframework.test.context.transaction.AfterTransaction;
import org.springframework.test.context.transaction.BeforeTransaction; import org.springframework.test.context.transaction.BeforeTransaction;
import com.ctrip.framework.apollo.biz.AbstractIntegrationTest; import java.util.Date;
import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.biz.repository.AppNamespaceRepository;
import com.ctrip.framework.apollo.biz.repository.AppRepository;
import com.ctrip.framework.apollo.biz.repository.ClusterRepository;
import com.ctrip.framework.apollo.biz.repository.NamespaceRepository;
public class AdminServiceTransactionTest extends AbstractIntegrationTest { public class AdminServiceTransactionTest extends AbstractIntegrationTest {
......
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import java.util.Date; import com.ctrip.framework.apollo.biz.AbstractIntegrationTest;
import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.common.exception.ServiceException;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import com.ctrip.framework.apollo.biz.AbstractIntegrationTest; import java.util.Date;
import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.common.exception.ServiceException;
public class ClusterServiceTest extends AbstractIntegrationTest { public class ClusterServiceTest extends AbstractIntegrationTest {
......
...@@ -14,7 +14,6 @@ import org.springframework.data.domain.Page; ...@@ -14,7 +14,6 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.util.AssertionErrors;
public class NamespaceBranchServiceTest extends AbstractIntegrationTest { public class NamespaceBranchServiceTest extends AbstractIntegrationTest {
......
package com.ctrip.framework.apollo.biz.service;
import com.ctrip.framework.apollo.biz.AbstractIntegrationTest;
import com.ctrip.framework.apollo.biz.entity.Cluster;
import com.ctrip.framework.apollo.biz.entity.Commit;
import com.ctrip.framework.apollo.biz.entity.InstanceConfig;
import com.ctrip.framework.apollo.biz.entity.Item;
import com.ctrip.framework.apollo.biz.entity.Namespace;
import com.ctrip.framework.apollo.biz.entity.Release;
import com.ctrip.framework.apollo.biz.entity.ReleaseHistory;
import com.ctrip.framework.apollo.biz.repository.InstanceConfigRepository;
import com.ctrip.framework.apollo.common.entity.AppNamespace;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.jdbc.Sql;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
* @author lepdou 2016-11-28
*/
public class NamespaceServiceTest extends AbstractIntegrationTest {
@Autowired
private NamespaceService namespaceService;
@Autowired
private ItemService itemService;
@Autowired
private CommitService commitService;
@Autowired
private AppNamespaceService appNamespaceService;
@Autowired
private ClusterService clusterService;
@Autowired
private ReleaseService releaseService;
@Autowired
private ReleaseHistoryService releaseHistoryService;
@Autowired
private InstanceConfigRepository instanceConfigRepository;
private String testApp = "testApp";
private String testCluster = "default";
private String testChildCluster = "child-cluster";
private String testPrivateNamespace = "application";
private String testUser = "apollo";
@Test
@Sql(scripts = "/sql/namespace-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testDeleteNamespace() {
Namespace namespace = new Namespace();
namespace.setAppId(testApp);
namespace.setClusterName(testCluster);
namespace.setNamespaceName(testPrivateNamespace);
namespace.setId(1);
namespaceService.deleteNamespace(namespace, testUser);
List<Item> items = itemService.findItems(testApp, testCluster, testPrivateNamespace);
List<Commit> commits = commitService.find(testApp, testCluster, testPrivateNamespace, new PageRequest(0, 10));
AppNamespace appNamespace = appNamespaceService.findOne(testApp, testPrivateNamespace);
List<Cluster> childClusters = clusterService.findChildClusters(testApp, testCluster);
InstanceConfig instanceConfig = instanceConfigRepository.findOne(1L);
List<Release> parentNamespaceReleases = releaseService.findActiveReleases(testApp, testCluster,
testPrivateNamespace,
new PageRequest(0, 10));
List<Release> childNamespaceReleases = releaseService.findActiveReleases(testApp, testChildCluster,
testPrivateNamespace,
new PageRequest(0, 10));
Page<ReleaseHistory> releaseHistories =
releaseHistoryService
.findReleaseHistoriesByNamespace(testApp, testCluster, testPrivateNamespace, new PageRequest(0, 10));
assertEquals(0, items.size());
assertEquals(0, commits.size());
assertNotNull(appNamespace);
assertEquals(0, childClusters.size());
assertEquals(0, parentNamespaceReleases.size());
assertEquals(0, childNamespaceReleases.size());
assertTrue(!releaseHistories.hasContent());
assertNull(instanceConfig);
}
}
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import java.util.Date; import com.ctrip.framework.apollo.biz.AbstractIntegrationTest;
import java.util.List; import com.ctrip.framework.apollo.biz.entity.Cluster;
import com.ctrip.framework.apollo.biz.entity.Namespace;
import com.ctrip.framework.apollo.biz.entity.Privilege;
import com.ctrip.framework.apollo.common.entity.App;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import com.ctrip.framework.apollo.biz.AbstractIntegrationTest; import java.util.Date;
import com.ctrip.framework.apollo.common.entity.App; import java.util.List;
import com.ctrip.framework.apollo.biz.entity.Cluster;
import com.ctrip.framework.apollo.biz.entity.Namespace;
import com.ctrip.framework.apollo.biz.entity.Privilege;
public class PrivilegeServiceTest extends AbstractIntegrationTest { public class PrivilegeServiceTest extends AbstractIntegrationTest {
......
...@@ -19,7 +19,6 @@ import org.springframework.data.domain.Pageable; ...@@ -19,7 +19,6 @@ import org.springframework.data.domain.Pageable;
import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.Sql;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.List;
import java.util.Map; import java.util.Map;
public class ReleaseCreationTest extends AbstractIntegrationTest { public class ReleaseCreationTest extends AbstractIntegrationTest {
......
...@@ -11,7 +11,8 @@ import org.junit.Test; ...@@ -11,7 +11,8 @@ import org.junit.Test;
import org.mockito.Mock; import org.mockito.Mock;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
......
<plexus>
<components>
<component>
<role>com.dianping.cat.configuration.ClientConfigManager</role>
<implementation>com.ctrip.framework.apollo.cat.NullClientConfigManager
</implementation>
</component>
<component>
<role>com.dianping.cat.message.io.TransportManager</role>
<implementation>com.ctrip.framework.apollo.cat.NullTransportManager
</implementation>
</component>
<component>
<role>com.dianping.cat.message.spi.MessageManager</role>
<implementation>com.ctrip.framework.apollo.cat.NullMessageManager
</implementation>
<requirements>
<requirement>
<role>com.dianping.cat.message.internal.MessageIdFactory</role>
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.message.MessageProducer</role>
<implementation>com.ctrip.framework.apollo.cat.NullMessageProducer
</implementation>
<requirements>
<requirement>
<role>com.dianping.cat.message.spi.MessageManager</role>
</requirement>
<requirement>
<role>com.dianping.cat.message.internal.MessageIdFactory</role>
</requirement>
</requirements>
</component>
<component>
<role>org.codehaus.plexus.logging.LoggerManager</role>
<implementation>com.ctrip.framework.apollo.cat.NullLoggerManager
</implementation>
</component>
</components>
</plexus>
DELETE FROM App; DELETE FROM App;
DELETE FROM AppNamespace;
DELETE FROM Cluster; DELETE FROM Cluster;
DELETE FROM namespace; DELETE FROM namespace;
DELETE FROM grayreleaserule; DELETE FROM grayreleaserule;
...@@ -6,3 +7,5 @@ DELETE FROM release; ...@@ -6,3 +7,5 @@ DELETE FROM release;
DELETE FROM item; DELETE FROM item;
DELETE FROM releasemessage; DELETE FROM releasemessage;
DELETE FROM releasehistory; DELETE FROM releasehistory;
DELETE FROM namespacelock;
DELETE FROM `commit`;
INSERT INTO `app` ( `AppId`, `Name`, `OrgId`, `OrgName`, `OwnerName`, `OwnerEmail`, `IsDeleted`, `DataChange_CreatedBy`, `DataChange_LastModifiedBy`)VALUES('testApp', 'test', 'default', 'default', 'default', 'default', 0, 'default', 'default');
INSERT INTO `cluster` (`ID`, `Name`, `AppId`, `ParentClusterId`, `IsDeleted`, `DataChange_CreatedBy`, `DataChange_LastModifiedBy`) VALUES (1, 'default', 'testApp', 0, 0, 'default', 'default');
INSERT INTO `cluster` (`Name`, `AppId`, `ParentClusterId`, `IsDeleted`, `DataChange_CreatedBy`, `DataChange_LastModifiedBy`)VALUES('child-cluster', 'testApp', 1, 0, 'default', 'default');
INSERT INTO `appnamespace` (`Name`, `AppId`, `Format`, `IsPublic`) VALUES ( 'application', 'testApp', 'properties', 0);
INSERT INTO `namespace` (`ID`, `AppId`, `ClusterName`, `NamespaceName`, `IsDeleted`, `DataChange_CreatedBy`, `DataChange_LastModifiedBy`)VALUES(1,'testApp', 'default', 'application', 0, 'apollo', 'apollo');
INSERT INTO `namespace` (`AppId`, `ClusterName`, `NamespaceName`, `IsDeleted`, `DataChange_CreatedBy`, `DataChange_LastModifiedBy`)VALUES('testApp', 'child-cluster', 'application', 0, 'apollo', 'apollo');
INSERT INTO `commit` (`ChangeSets`, `AppId`, `ClusterName`, `NamespaceName`)VALUES('{}', 'testApp', 'default', 'application');
INSERT INTO `item` (`NamespaceId`, `Key`, `Value`, `Comment`, `LineNum`)VALUES(1, 'k1', 'v1', '', 1);
INSERT INTO `namespacelock` (`NamespaceId`)VALUES(1);
INSERT INTO `release` (`AppId`, `ClusterName`, `NamespaceName`, `Configurations`, `IsAbandoned`)VALUES('branch-test', 'default', 'application', '{}', 0);
INSERT INTO `release` (`AppId`, `ClusterName`, `NamespaceName`, `Configurations`, `IsAbandoned`)VALUES('branch-test', 'child-cluster', 'application', '{}', 0);
INSERT INTO `releasehistory` (`AppId`, `ClusterName`, `NamespaceName`, `BranchName`, `ReleaseId`, `PreviousReleaseId`, `Operation`, `OperationContext`)VALUES('branch-test', 'default', 'application', 'default', 0, 0, 7, '{}');
INSERT INTO `instanceconfig` (`ID`, `InstanceId`, `ConfigAppId`, `ConfigClusterName`, `ConfigNamespaceName`, `ReleaseKey`, `ReleaseDeliveryTime`, `DataChange_CreatedTime`, `DataChange_LastTime`)
VALUES
(1, 90, 'testApp', 'default', 'application', '20160829134524-dee271ddf9fced58', '2016-08-29 13:45:24', '2016-08-30 17:03:32', '2016-10-19 11:13:47');
...@@ -4,22 +4,12 @@ ...@@ -4,22 +4,12 @@
<parent> <parent>
<groupId>com.ctrip.framework.apollo</groupId> <groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId> <artifactId>apollo</artifactId>
<version>0.2.0</version> <version>0.4.0</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>apollo-buildtools</artifactId> <artifactId>apollo-buildtools</artifactId>
<name>Apollo BuildTools</name> <name>Apollo BuildTools</name>
<properties>
<java.version>1.7</java.version>
<github.path>${project.artifactId}</github.path>
</properties>
<dependencies>
<dependency>
<groupId>com.dianping.cat</groupId>
<artifactId>cat-client</artifactId>
</dependency>
</dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
......
package com.ctrip.framework.apollo.cat;
import java.io.File;
import java.util.List;
import com.dianping.cat.configuration.ClientConfigManager;
import com.dianping.cat.configuration.client.entity.Domain;
import com.dianping.cat.configuration.client.entity.Server;
public class NullClientConfigManager implements ClientConfigManager{
@Override
public Domain getDomain() {
return null;
}
@Override
public int getMaxMessageLength() {
return 0;
}
@Override
public String getServerConfigUrl() {
return null;
}
@Override
public List<Server> getServers() {
return null;
}
@Override
public int getTaggedTransactionCacheSize() {
return 0;
}
@Override
public void initialize(File configFile) throws Exception {
}
@Override
public boolean isCatEnabled() {
return false;
}
@Override
public boolean isDumpLocked() {
return false;
}
@Override
public int getQueueSize() {
return 0;
}
}
package com.ctrip.framework.apollo.cat;
import org.codehaus.plexus.logging.console.ConsoleLoggerManager;
public class NullLoggerManager extends ConsoleLoggerManager{
}
package com.ctrip.framework.apollo.cat;
import java.io.IOException;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.unidal.lookup.ContainerHolder;
import org.unidal.lookup.annotation.Inject;
import com.dianping.cat.message.Message;
import com.dianping.cat.message.Transaction;
import com.dianping.cat.message.internal.MessageIdFactory;
import com.dianping.cat.message.spi.MessageManager;
import com.dianping.cat.message.spi.MessageTree;
public class NullMessageManager extends ContainerHolder
implements
MessageManager,
Initializable,
LogEnabled {
@Inject
private MessageIdFactory m_factory;
@Override
public void enableLogging(Logger logger) {
}
@Override
public void initialize() throws InitializationException {
try {
m_factory.initialize("localhost");
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void add(Message message) {
}
@Override
public void end(Transaction transaction) {
}
@Override
public Transaction getPeekTransaction() {
return null;
}
@Override
public MessageTree getThreadLocalMessageTree() {
return null;
}
@Override
public boolean hasContext() {
return false;
}
@Override
public boolean isMessageEnabled() {
return false;
}
@Override
public boolean isCatEnabled() {
return false;
}
@Override
public boolean isTraceMode() {
return false;
}
@Override
public void reset() {
}
@Override
public void setTraceMode(boolean traceMode) {
}
@Override
public void setup() {
}
@Override
public void start(Transaction transaction, boolean forked) {
}
@Override
public void bind(String tag, String title) {
}
@Override
public String getDomain() {
return null;
}
}
package com.ctrip.framework.apollo.cat;
import com.dianping.cat.message.io.MessageSender;
import com.dianping.cat.message.io.TransportManager;
import com.dianping.cat.message.spi.MessageTree;
public class NullTransportManager implements TransportManager {
private static final MessageSender nullMessageSender = new MessageSender() {
@Override
public void initialize() {
}
@Override
public void send(MessageTree tree) {
}
@Override
public void shutdown() {
}
};
@Override
public MessageSender getSender() {
return nullMessageSender;
}
}
...@@ -88,7 +88,7 @@ If you need this functionality, you could specify the cluster as follows: ...@@ -88,7 +88,7 @@ If you need this functionality, you could specify the cluster as follows:
<dependency> <dependency>
<groupId>com.ctrip.framework.apollo</groupId> <groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId> <artifactId>apollo-client</artifactId>
<version>0.2.0</version> <version>0.4.0</version>
</dependency> </dependency>
## III. Client Usage ## III. Client Usage
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.ctrip.framework.apollo</groupId> <groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo</artifactId> <artifactId>apollo</artifactId>
<version>0.2.0</version> <version>0.4.0</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -20,16 +20,11 @@ ...@@ -20,16 +20,11 @@
<groupId>com.ctrip.framework.apollo</groupId> <groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-core</artifactId> <artifactId>apollo-core</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-buildtools</artifactId>
<scope>test</scope>
</dependency>
<!-- end of apollo --> <!-- end of apollo -->
<!-- foundation service --> <!-- foundation service -->
<dependency> <dependency>
<groupId>com.ctrip.framework</groupId> <groupId>org.unidal.framework</groupId>
<artifactId>framework-foundation</artifactId> <artifactId>foundation-service</artifactId>
</dependency> </dependency>
<!-- end of foundation service --> <!-- end of foundation service -->
<!-- log --> <!-- log -->
...@@ -37,27 +32,6 @@ ...@@ -37,27 +32,6 @@
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
</exclusions>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>provided</scope>
</dependency>
<!-- end of log -->
<!-- test --> <!-- test -->
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
...@@ -69,13 +43,29 @@ ...@@ -69,13 +43,29 @@
<artifactId>commons-logging</artifactId> <artifactId>commons-logging</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
<!-- end of test --> <!-- end of test -->
<!-- dal-jdbc --> <!-- dal-jdbc -->
<dependency> <dependency>
<groupId>org.unidal.framework</groupId> <groupId>org.unidal.framework</groupId>
<artifactId>dal-jdbc</artifactId> <artifactId>dal-jdbc</artifactId>
<version>2.4.0</version> <version>2.4.0</version>
<scope>provided</scope> <optional>true</optional>
<exclusions>
<exclusion>
<groupId>com.dianping.cat</groupId>
<artifactId>cat-client</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<!-- end of dal-jdbc --> <!-- end of dal-jdbc -->
</dependencies> </dependencies>
......
...@@ -6,7 +6,7 @@ import com.ctrip.framework.apollo.exceptions.ApolloConfigException; ...@@ -6,7 +6,7 @@ import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.internals.ConfigManager; import com.ctrip.framework.apollo.internals.ConfigManager;
import com.ctrip.framework.apollo.spi.ConfigFactory; import com.ctrip.framework.apollo.spi.ConfigFactory;
import com.ctrip.framework.apollo.spi.ConfigRegistry; import com.ctrip.framework.apollo.spi.ConfigRegistry;
import com.dianping.cat.Cat; import com.ctrip.framework.apollo.tracer.Tracer;
import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
...@@ -51,7 +51,7 @@ public class ConfigService { ...@@ -51,7 +51,7 @@ public class ConfigService {
return s_instance.m_container.lookup(ConfigManager.class); return s_instance.m_container.lookup(ConfigManager.class);
} catch (ComponentLookupException ex) { } catch (ComponentLookupException ex) {
ApolloConfigException exception = new ApolloConfigException("Unable to load ConfigManager!", ex); ApolloConfigException exception = new ApolloConfigException("Unable to load ConfigManager!", ex);
Cat.logError(exception); Tracer.logError(exception);
throw exception; throw exception;
} }
} }
...@@ -61,7 +61,7 @@ public class ConfigService { ...@@ -61,7 +61,7 @@ public class ConfigService {
return s_instance.m_container.lookup(ConfigRegistry.class); return s_instance.m_container.lookup(ConfigRegistry.class);
} catch (ComponentLookupException ex) { } catch (ComponentLookupException ex) {
ApolloConfigException exception = new ApolloConfigException("Unable to load ConfigRegistry!", ex); ApolloConfigException exception = new ApolloConfigException("Unable to load ConfigRegistry!", ex);
Cat.logError(exception); Tracer.logError(exception);
throw exception; throw exception;
} }
} }
......
...@@ -11,10 +11,9 @@ import com.ctrip.framework.apollo.enums.PropertyChangeType; ...@@ -11,10 +11,9 @@ import com.ctrip.framework.apollo.enums.PropertyChangeType;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException; import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.model.ConfigChange; import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent; import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.tracer.spi.Transaction;
import com.ctrip.framework.apollo.util.parser.Parsers; import com.ctrip.framework.apollo.util.parser.Parsers;
import com.dianping.cat.Cat;
import com.dianping.cat.message.Message;
import com.dianping.cat.message.Transaction;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -63,7 +62,7 @@ public abstract class AbstractConfig implements Config { ...@@ -63,7 +62,7 @@ public abstract class AbstractConfig implements Config {
return Integer.parseInt(value); return Integer.parseInt(value);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(new ApolloConfigException( Tracer.logError(new ApolloConfigException(
String.format("getIntProperty for %s failed, return default value %d", key, String.format("getIntProperty for %s failed, return default value %d", key,
defaultValue), ex)); defaultValue), ex));
} }
...@@ -79,7 +78,7 @@ public abstract class AbstractConfig implements Config { ...@@ -79,7 +78,7 @@ public abstract class AbstractConfig implements Config {
return Long.parseLong(value); return Long.parseLong(value);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(new ApolloConfigException( Tracer.logError(new ApolloConfigException(
String.format("getLongProperty for %s failed, return default value %d", key, String.format("getLongProperty for %s failed, return default value %d", key,
defaultValue), ex)); defaultValue), ex));
} }
...@@ -95,7 +94,7 @@ public abstract class AbstractConfig implements Config { ...@@ -95,7 +94,7 @@ public abstract class AbstractConfig implements Config {
return Short.parseShort(value); return Short.parseShort(value);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(new ApolloConfigException( Tracer.logError(new ApolloConfigException(
String.format("getShortProperty for %s failed, return default value %d", key, String.format("getShortProperty for %s failed, return default value %d", key,
defaultValue), ex)); defaultValue), ex));
} }
...@@ -111,7 +110,7 @@ public abstract class AbstractConfig implements Config { ...@@ -111,7 +110,7 @@ public abstract class AbstractConfig implements Config {
return Float.parseFloat(value); return Float.parseFloat(value);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(new ApolloConfigException( Tracer.logError(new ApolloConfigException(
String.format("getFloatProperty for %s failed, return default value %f", key, String.format("getFloatProperty for %s failed, return default value %f", key,
defaultValue), ex)); defaultValue), ex));
} }
...@@ -127,7 +126,7 @@ public abstract class AbstractConfig implements Config { ...@@ -127,7 +126,7 @@ public abstract class AbstractConfig implements Config {
return Double.parseDouble(value); return Double.parseDouble(value);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(new ApolloConfigException( Tracer.logError(new ApolloConfigException(
String.format("getDoubleProperty for %s failed, return default value %f", key, String.format("getDoubleProperty for %s failed, return default value %f", key,
defaultValue), ex)); defaultValue), ex));
} }
...@@ -143,7 +142,7 @@ public abstract class AbstractConfig implements Config { ...@@ -143,7 +142,7 @@ public abstract class AbstractConfig implements Config {
return Byte.parseByte(value); return Byte.parseByte(value);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(new ApolloConfigException( Tracer.logError(new ApolloConfigException(
String.format("getByteProperty for %s failed, return default value %d", key, String.format("getByteProperty for %s failed, return default value %d", key,
defaultValue), ex)); defaultValue), ex));
} }
...@@ -159,7 +158,7 @@ public abstract class AbstractConfig implements Config { ...@@ -159,7 +158,7 @@ public abstract class AbstractConfig implements Config {
return Boolean.parseBoolean(value); return Boolean.parseBoolean(value);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(new ApolloConfigException( Tracer.logError(new ApolloConfigException(
String.format("getBooleanProperty for %s failed, return default value %b", key, String.format("getBooleanProperty for %s failed, return default value %b", key,
defaultValue), ex)); defaultValue), ex));
} }
...@@ -175,7 +174,7 @@ public abstract class AbstractConfig implements Config { ...@@ -175,7 +174,7 @@ public abstract class AbstractConfig implements Config {
return value.split(delimiter); return value.split(delimiter);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(new ApolloConfigException( Tracer.logError(new ApolloConfigException(
String.format("getArrayProperty for %s failed, return default value", key), ex)); String.format("getArrayProperty for %s failed, return default value", key), ex));
} }
return defaultValue; return defaultValue;
...@@ -190,7 +189,7 @@ public abstract class AbstractConfig implements Config { ...@@ -190,7 +189,7 @@ public abstract class AbstractConfig implements Config {
return Enum.valueOf(enumType, value); return Enum.valueOf(enumType, value);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(new ApolloConfigException( Tracer.logError(new ApolloConfigException(
String.format("getEnumProperty for %s failed, return default value %s", key, String.format("getEnumProperty for %s failed, return default value %s", key,
defaultValue), ex)); defaultValue), ex));
} }
...@@ -207,7 +206,7 @@ public abstract class AbstractConfig implements Config { ...@@ -207,7 +206,7 @@ public abstract class AbstractConfig implements Config {
return Parsers.forDate().parse(value); return Parsers.forDate().parse(value);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(new ApolloConfigException( Tracer.logError(new ApolloConfigException(
String.format("getDateProperty for %s failed, return default value %s", key, String.format("getDateProperty for %s failed, return default value %s", key,
defaultValue), ex)); defaultValue), ex));
} }
...@@ -224,7 +223,7 @@ public abstract class AbstractConfig implements Config { ...@@ -224,7 +223,7 @@ public abstract class AbstractConfig implements Config {
return Parsers.forDate().parse(value, format); return Parsers.forDate().parse(value, format);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(new ApolloConfigException( Tracer.logError(new ApolloConfigException(
String.format("getDateProperty for %s failed, return default value %s", key, String.format("getDateProperty for %s failed, return default value %s", key,
defaultValue), ex)); defaultValue), ex));
} }
...@@ -241,7 +240,7 @@ public abstract class AbstractConfig implements Config { ...@@ -241,7 +240,7 @@ public abstract class AbstractConfig implements Config {
return Parsers.forDate().parse(value, format, locale); return Parsers.forDate().parse(value, format, locale);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(new ApolloConfigException( Tracer.logError(new ApolloConfigException(
String.format("getDateProperty for %s failed, return default value %s", key, String.format("getDateProperty for %s failed, return default value %s", key,
defaultValue), ex)); defaultValue), ex));
} }
...@@ -258,7 +257,7 @@ public abstract class AbstractConfig implements Config { ...@@ -258,7 +257,7 @@ public abstract class AbstractConfig implements Config {
return Parsers.forDuration().parseToMillis(value); return Parsers.forDuration().parseToMillis(value);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(new ApolloConfigException( Tracer.logError(new ApolloConfigException(
String.format("getDurationProperty for %s failed, return default value %d", key, String.format("getDurationProperty for %s failed, return default value %d", key,
defaultValue), ex)); defaultValue), ex));
} }
...@@ -272,13 +271,13 @@ public abstract class AbstractConfig implements Config { ...@@ -272,13 +271,13 @@ public abstract class AbstractConfig implements Config {
@Override @Override
public void run() { public void run() {
String listenerName = listener.getClass().getName(); String listenerName = listener.getClass().getName();
Transaction transaction = Cat.newTransaction("Apollo.ConfigChangeListener", listenerName); Transaction transaction = Tracer.newTransaction("Apollo.ConfigChangeListener", listenerName);
try { try {
listener.onChange(changeEvent); listener.onChange(changeEvent);
transaction.setStatus(Message.SUCCESS); transaction.setStatus(Transaction.SUCCESS);
} catch (Throwable ex) { } catch (Throwable ex) {
transaction.setStatus(ex); transaction.setStatus(ex);
Cat.logError(ex); Tracer.logError(ex);
logger.error("Failed to invoke config change listener {}", listenerName, ex); logger.error("Failed to invoke config change listener {}", listenerName, ex);
} finally { } finally {
transaction.complete(); transaction.complete();
......
package com.ctrip.framework.apollo.internals; package com.ctrip.framework.apollo.internals;
import com.ctrip.framework.apollo.ConfigFile; import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.util.ExceptionUtil; import com.ctrip.framework.apollo.util.ExceptionUtil;
import com.dianping.cat.Cat;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -30,7 +30,7 @@ public abstract class AbstractConfigFile implements ConfigFile, RepositoryChange ...@@ -30,7 +30,7 @@ public abstract class AbstractConfigFile implements ConfigFile, RepositoryChange
try { try {
m_configProperties.set(m_configRepository.getConfig()); m_configProperties.set(m_configRepository.getConfig());
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(ex); Tracer.logError(ex);
logger.warn("Init Apollo Config File failed - namespace: {}, reason: {}.", logger.warn("Init Apollo Config File failed - namespace: {}, reason: {}.",
m_namespace, ExceptionUtil.getDetailMessage(ex)); m_namespace, ExceptionUtil.getDetailMessage(ex));
} finally { } finally {
...@@ -55,7 +55,7 @@ public abstract class AbstractConfigFile implements ConfigFile, RepositoryChange ...@@ -55,7 +55,7 @@ public abstract class AbstractConfigFile implements ConfigFile, RepositoryChange
m_configProperties.set(newConfigProperties); m_configProperties.set(newConfigProperties);
Cat.logEvent("Apollo.Client.ConfigChanges", m_namespace); Tracer.logEvent("Apollo.Client.ConfigChanges", m_namespace);
} }
} }
...@@ -2,8 +2,8 @@ package com.ctrip.framework.apollo.internals; ...@@ -2,8 +2,8 @@ package com.ctrip.framework.apollo.internals;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.util.ExceptionUtil; import com.ctrip.framework.apollo.util.ExceptionUtil;
import com.dianping.cat.Cat;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -23,7 +23,7 @@ public abstract class AbstractConfigRepository implements ConfigRepository { ...@@ -23,7 +23,7 @@ public abstract class AbstractConfigRepository implements ConfigRepository {
sync(); sync();
return true; return true;
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(ex); Tracer.logError(ex);
logger logger
.warn("Sync config failed, will retry. Repository {}, reason: {}", this.getClass(), ExceptionUtil .warn("Sync config failed, will retry. Repository {}, reason: {}", this.getClass(), ExceptionUtil
.getDetailMessage(ex)); .getDetailMessage(ex));
...@@ -50,7 +50,7 @@ public abstract class AbstractConfigRepository implements ConfigRepository { ...@@ -50,7 +50,7 @@ public abstract class AbstractConfigRepository implements ConfigRepository {
try { try {
listener.onRepositoryChange(namespace, newProperties); listener.onRepositoryChange(namespace, newProperties);
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(ex); Tracer.logError(ex);
logger.error("Failed to invoke repository change listener {}", listener.getClass(), ex); logger.error("Failed to invoke repository change listener {}", listener.getClass(), ex);
} }
} }
......
...@@ -11,13 +11,12 @@ import com.google.gson.reflect.TypeToken; ...@@ -11,13 +11,12 @@ import com.google.gson.reflect.TypeToken;
import com.ctrip.framework.apollo.core.dto.ServiceDTO; import com.ctrip.framework.apollo.core.dto.ServiceDTO;
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory; import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException; import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.tracer.spi.Transaction;
import com.ctrip.framework.apollo.util.ConfigUtil; import com.ctrip.framework.apollo.util.ConfigUtil;
import com.ctrip.framework.apollo.util.http.HttpRequest; import com.ctrip.framework.apollo.util.http.HttpRequest;
import com.ctrip.framework.apollo.util.http.HttpResponse; import com.ctrip.framework.apollo.util.http.HttpResponse;
import com.ctrip.framework.apollo.util.http.HttpUtil; import com.ctrip.framework.apollo.util.http.HttpUtil;
import com.dianping.cat.Cat;
import com.dianping.cat.message.Message;
import com.dianping.cat.message.Transaction;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
...@@ -94,7 +93,7 @@ public class ConfigServiceLocator implements Initializable { ...@@ -94,7 +93,7 @@ public class ConfigServiceLocator implements Initializable {
@Override @Override
public void run() { public void run() {
logger.debug("refresh config services"); logger.debug("refresh config services");
Cat.logEvent("Apollo.MetaService", "periodicRefresh"); Tracer.logEvent("Apollo.MetaService", "periodicRefresh");
tryUpdateConfigServices(); tryUpdateConfigServices();
} }
}, m_configUtil.getRefreshInterval(), m_configUtil.getRefreshInterval(), }, m_configUtil.getRefreshInterval(), m_configUtil.getRefreshInterval(),
...@@ -109,11 +108,11 @@ public class ConfigServiceLocator implements Initializable { ...@@ -109,11 +108,11 @@ public class ConfigServiceLocator implements Initializable {
Throwable exception = null; Throwable exception = null;
for (int i = 0; i < maxRetries; i++) { for (int i = 0; i < maxRetries; i++) {
Transaction transaction = Cat.newTransaction("Apollo.MetaService", "getConfigService"); Transaction transaction = Tracer.newTransaction("Apollo.MetaService", "getConfigService");
transaction.addData("Url", url); transaction.addData("Url", url);
try { try {
HttpResponse<List<ServiceDTO>> response = m_httpUtil.doGet(request, m_responseType); HttpResponse<List<ServiceDTO>> response = m_httpUtil.doGet(request, m_responseType);
transaction.setStatus(Message.SUCCESS); transaction.setStatus(Transaction.SUCCESS);
List<ServiceDTO> services = response.getBody(); List<ServiceDTO> services = response.getBody();
if (services == null || services.isEmpty()) { if (services == null || services.isEmpty()) {
logConfigServiceToCat("Empty response!"); logConfigServiceToCat("Empty response!");
...@@ -123,7 +122,7 @@ public class ConfigServiceLocator implements Initializable { ...@@ -123,7 +122,7 @@ public class ConfigServiceLocator implements Initializable {
logConfigServicesToCat(services); logConfigServicesToCat(services);
return; return;
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(ex); Tracer.logError(ex);
transaction.setStatus(ex); transaction.setStatus(ex);
exception = ex; exception = ex;
} finally { } finally {
...@@ -162,6 +161,6 @@ public class ConfigServiceLocator implements Initializable { ...@@ -162,6 +161,6 @@ public class ConfigServiceLocator implements Initializable {
} }
private void logConfigServiceToCat(String serviceUrl) { private void logConfigServiceToCat(String serviceUrl) {
Cat.logEvent("Apollo.Config.Services", serviceUrl); Tracer.logEvent("Apollo.Config.Services", serviceUrl);
} }
} }
...@@ -6,8 +6,8 @@ import com.ctrip.framework.apollo.core.utils.ClassLoaderUtil; ...@@ -6,8 +6,8 @@ import com.ctrip.framework.apollo.core.utils.ClassLoaderUtil;
import com.ctrip.framework.apollo.enums.PropertyChangeType; import com.ctrip.framework.apollo.enums.PropertyChangeType;
import com.ctrip.framework.apollo.model.ConfigChange; import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent; import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.util.ExceptionUtil; import com.ctrip.framework.apollo.util.ExceptionUtil;
import com.dianping.cat.Cat;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -51,7 +51,7 @@ public class DefaultConfig extends AbstractConfig implements RepositoryChangeLis ...@@ -51,7 +51,7 @@ public class DefaultConfig extends AbstractConfig implements RepositoryChangeLis
try { try {
m_configProperties.set(m_configRepository.getConfig()); m_configProperties.set(m_configRepository.getConfig());
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(ex); Tracer.logError(ex);
logger.warn("Init Apollo Local Config failed - namespace: {}, reason: {}.", logger.warn("Init Apollo Local Config failed - namespace: {}, reason: {}.",
m_namespace, ExceptionUtil.getDetailMessage(ex)); m_namespace, ExceptionUtil.getDetailMessage(ex));
} finally { } finally {
...@@ -119,7 +119,7 @@ public class DefaultConfig extends AbstractConfig implements RepositoryChangeLis ...@@ -119,7 +119,7 @@ public class DefaultConfig extends AbstractConfig implements RepositoryChangeLis
this.fireConfigChange(new ConfigChangeEvent(m_namespace, actualChanges)); this.fireConfigChange(new ConfigChangeEvent(m_namespace, actualChanges));
Cat.logEvent("Apollo.Client.ConfigChanges", m_namespace); Tracer.logEvent("Apollo.Client.ConfigChanges", m_namespace);
} }
private Map<String, ConfigChange> updateAndCalcConfigChanges(Properties newConfigProperties) { private Map<String, ConfigChange> updateAndCalcConfigChanges(Properties newConfigProperties) {
...@@ -185,7 +185,7 @@ public class DefaultConfig extends AbstractConfig implements RepositoryChangeLis ...@@ -185,7 +185,7 @@ public class DefaultConfig extends AbstractConfig implements RepositoryChangeLis
try { try {
properties.load(in); properties.load(in);
} catch (IOException ex) { } catch (IOException ex) {
Cat.logError(ex); Tracer.logError(ex);
logger.error("Load resource config for namespace {} failed", namespace, ex); logger.error("Load resource config for namespace {} failed", namespace, ex);
} finally { } finally {
try { try {
......
package com.ctrip.framework.apollo.internals;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public class JsonConfigFile extends PlainTextConfigFile {
public JsonConfigFile(String namespace,
ConfigRepository configRepository) {
super(namespace, configRepository);
}
@Override
public ConfigFileFormat getConfigFileFormat() {
return ConfigFileFormat.JSON;
}
}
...@@ -6,11 +6,10 @@ import com.google.common.base.Preconditions; ...@@ -6,11 +6,10 @@ import com.google.common.base.Preconditions;
import com.ctrip.framework.apollo.core.ConfigConsts; import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.utils.ClassLoaderUtil; import com.ctrip.framework.apollo.core.utils.ClassLoaderUtil;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException; import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.tracer.spi.Transaction;
import com.ctrip.framework.apollo.util.ConfigUtil; import com.ctrip.framework.apollo.util.ConfigUtil;
import com.ctrip.framework.apollo.util.ExceptionUtil; import com.ctrip.framework.apollo.util.ExceptionUtil;
import com.dianping.cat.Cat;
import com.dianping.cat.message.Message;
import com.dianping.cat.message.Transaction;
import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
...@@ -58,7 +57,7 @@ public class LocalFileConfigRepository extends AbstractConfigRepository ...@@ -58,7 +57,7 @@ public class LocalFileConfigRepository extends AbstractConfigRepository
try { try {
m_configUtil = m_container.lookup(ConfigUtil.class); m_configUtil = m_container.lookup(ConfigUtil.class);
} catch (ComponentLookupException ex) { } catch (ComponentLookupException ex) {
Cat.logError(ex); Tracer.logError(ex);
throw new ApolloConfigException("Unable to load component!", ex); throw new ApolloConfigException("Unable to load component!", ex);
} }
this.setLocalCacheDir(findLocalCacheDir(), false); this.setLocalCacheDir(findLocalCacheDir(), false);
...@@ -135,14 +134,14 @@ public class LocalFileConfigRepository extends AbstractConfigRepository ...@@ -135,14 +134,14 @@ public class LocalFileConfigRepository extends AbstractConfigRepository
return; return;
} }
Transaction transaction = Cat.newTransaction("Apollo.ConfigService", "syncLocalConfig"); Transaction transaction = Tracer.newTransaction("Apollo.ConfigService", "syncLocalConfig");
Throwable exception = null; Throwable exception = null;
try { try {
transaction.addData("Basedir", m_baseDir.getAbsolutePath()); transaction.addData("Basedir", m_baseDir.getAbsolutePath());
m_fileProperties = this.loadFromLocalCacheFile(m_baseDir, m_namespace); m_fileProperties = this.loadFromLocalCacheFile(m_baseDir, m_namespace);
transaction.setStatus(Message.SUCCESS); transaction.setStatus(Transaction.SUCCESS);
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(ex); Tracer.logError(ex);
transaction.setStatus(ex); transaction.setStatus(ex);
exception = ex; exception = ex;
//ignore //ignore
...@@ -165,7 +164,7 @@ public class LocalFileConfigRepository extends AbstractConfigRepository ...@@ -165,7 +164,7 @@ public class LocalFileConfigRepository extends AbstractConfigRepository
updateFileProperties(properties); updateFileProperties(properties);
return true; return true;
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(ex); Tracer.logError(ex);
logger logger
.warn("Sync config from upstream repository {} failed, reason: {}", m_upstream.getClass(), .warn("Sync config from upstream repository {} failed, reason: {}", m_upstream.getClass(),
ExceptionUtil.getDetailMessage(ex)); ExceptionUtil.getDetailMessage(ex));
...@@ -197,7 +196,7 @@ public class LocalFileConfigRepository extends AbstractConfigRepository ...@@ -197,7 +196,7 @@ public class LocalFileConfigRepository extends AbstractConfigRepository
properties.load(in); properties.load(in);
logger.debug("Loading local config file {} successfully!", file.getAbsolutePath()); logger.debug("Loading local config file {} successfully!", file.getAbsolutePath());
} catch (IOException ex) { } catch (IOException ex) {
Cat.logError(ex); Tracer.logError(ex);
throw new ApolloConfigException(String throw new ApolloConfigException(String
.format("Loading config from local cache file %s failed", file.getAbsolutePath()), ex); .format("Loading config from local cache file %s failed", file.getAbsolutePath()), ex);
} finally { } finally {
...@@ -225,17 +224,17 @@ public class LocalFileConfigRepository extends AbstractConfigRepository ...@@ -225,17 +224,17 @@ public class LocalFileConfigRepository extends AbstractConfigRepository
OutputStream out = null; OutputStream out = null;
Transaction transaction = Cat.newTransaction("Apollo.ConfigService", "persistLocalConfigFile"); Transaction transaction = Tracer.newTransaction("Apollo.ConfigService", "persistLocalConfigFile");
transaction.addData("LocalConfigFile", file.getAbsolutePath()); transaction.addData("LocalConfigFile", file.getAbsolutePath());
try { try {
out = new FileOutputStream(file); out = new FileOutputStream(file);
m_fileProperties.store(out, "Persisted by DefaultConfig"); m_fileProperties.store(out, "Persisted by DefaultConfig");
transaction.setStatus(Message.SUCCESS); transaction.setStatus(Transaction.SUCCESS);
} catch (IOException ex) { } catch (IOException ex) {
ApolloConfigException exception = ApolloConfigException exception =
new ApolloConfigException( new ApolloConfigException(
String.format("Persist local cache file %s failed", file.getAbsolutePath()), ex); String.format("Persist local cache file %s failed", file.getAbsolutePath()), ex);
Cat.logError(exception); Tracer.logError(exception);
transaction.setStatus(exception); transaction.setStatus(exception);
logger.warn("Persist local cache file {} failed, reason: {}.", file.getAbsolutePath(), logger.warn("Persist local cache file {} failed, reason: {}.", file.getAbsolutePath(),
ExceptionUtil.getDetailMessage(ex)); ExceptionUtil.getDetailMessage(ex));
...@@ -255,17 +254,17 @@ public class LocalFileConfigRepository extends AbstractConfigRepository ...@@ -255,17 +254,17 @@ public class LocalFileConfigRepository extends AbstractConfigRepository
if (baseDir.exists()) { if (baseDir.exists()) {
return; return;
} }
Transaction transaction = Cat.newTransaction("Apollo.ConfigService", "createLocalConfigDir"); Transaction transaction = Tracer.newTransaction("Apollo.ConfigService", "createLocalConfigDir");
transaction.addData("BaseDir", baseDir.getAbsolutePath()); transaction.addData("BaseDir", baseDir.getAbsolutePath());
try { try {
Files.createDirectory(baseDir.toPath()); Files.createDirectory(baseDir.toPath());
transaction.setStatus(Message.SUCCESS); transaction.setStatus(Transaction.SUCCESS);
} catch (IOException ex) { } catch (IOException ex) {
ApolloConfigException exception = ApolloConfigException exception =
new ApolloConfigException( new ApolloConfigException(
String.format("Create local config directory %s failed", baseDir.getAbsolutePath()), String.format("Create local config directory %s failed", baseDir.getAbsolutePath()),
ex); ex);
Cat.logError(exception); Tracer.logError(exception);
transaction.setStatus(exception); transaction.setStatus(exception);
logger.warn( logger.warn(
"Unable to create local config cache directory {}, reason: {}. Will not able to cache config file.", "Unable to create local config cache directory {}, reason: {}. Will not able to cache config file.",
......
package com.ctrip.framework.apollo.internals;
import com.ctrip.framework.apollo.core.ConfigConsts;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public abstract class PlainTextConfigFile extends AbstractConfigFile {
public PlainTextConfigFile(String namespace, ConfigRepository configRepository) {
super(namespace, configRepository);
}
@Override
public String getContent() {
if (m_configProperties.get() == null) {
return null;
}
return m_configProperties.get().getProperty(ConfigConsts.CONFIG_FILE_CONTENT_KEY);
}
@Override
public boolean hasContent() {
if (m_configProperties.get() == null) {
return false;
}
return m_configProperties.get().containsKey(ConfigConsts.CONFIG_FILE_CONTENT_KEY);
}
}
...@@ -3,8 +3,8 @@ package com.ctrip.framework.apollo.internals; ...@@ -3,8 +3,8 @@ package com.ctrip.framework.apollo.internals;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.core.utils.PropertiesUtil; import com.ctrip.framework.apollo.core.utils.PropertiesUtil;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException; import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.util.ExceptionUtil; import com.ctrip.framework.apollo.util.ExceptionUtil;
import com.dianping.cat.Cat;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -45,7 +45,7 @@ public class PropertiesConfigFile extends AbstractConfigFile { ...@@ -45,7 +45,7 @@ public class PropertiesConfigFile extends AbstractConfigFile {
new ApolloConfigException(String new ApolloConfigException(String
.format("Parse properties file content failed for namespace: %s, cause: %s", .format("Parse properties file content failed for namespace: %s, cause: %s",
m_namespace, ExceptionUtil.getDetailMessage(ex))); m_namespace, ExceptionUtil.getDetailMessage(ex)));
Cat.logError(exception); Tracer.logError(exception);
throw exception; throw exception;
} }
} }
......
...@@ -21,14 +21,13 @@ import com.ctrip.framework.apollo.core.schedule.ExponentialSchedulePolicy; ...@@ -21,14 +21,13 @@ import com.ctrip.framework.apollo.core.schedule.ExponentialSchedulePolicy;
import com.ctrip.framework.apollo.core.schedule.SchedulePolicy; import com.ctrip.framework.apollo.core.schedule.SchedulePolicy;
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory; import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException; import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.tracer.spi.Transaction;
import com.ctrip.framework.apollo.util.ConfigUtil; import com.ctrip.framework.apollo.util.ConfigUtil;
import com.ctrip.framework.apollo.util.ExceptionUtil; import com.ctrip.framework.apollo.util.ExceptionUtil;
import com.ctrip.framework.apollo.util.http.HttpRequest; import com.ctrip.framework.apollo.util.http.HttpRequest;
import com.ctrip.framework.apollo.util.http.HttpResponse; import com.ctrip.framework.apollo.util.http.HttpResponse;
import com.ctrip.framework.apollo.util.http.HttpUtil; import com.ctrip.framework.apollo.util.http.HttpUtil;
import com.dianping.cat.Cat;
import com.dianping.cat.message.Message;
import com.dianping.cat.message.Transaction;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
...@@ -123,7 +122,7 @@ public class RemoteConfigLongPollService implements Initializable { ...@@ -123,7 +122,7 @@ public class RemoteConfigLongPollService implements Initializable {
m_longPollStarted.set(false); m_longPollStarted.set(false);
ApolloConfigException exception = ApolloConfigException exception =
new ApolloConfigException("Schedule long polling refresh failed", ex); new ApolloConfigException("Schedule long polling refresh failed", ex);
Cat.logError(exception); Tracer.logError(exception);
logger.warn(ExceptionUtil.getDetailMessage(exception)); logger.warn(ExceptionUtil.getDetailMessage(exception));
} }
} }
...@@ -143,7 +142,7 @@ public class RemoteConfigLongPollService implements Initializable { ...@@ -143,7 +142,7 @@ public class RemoteConfigLongPollService implements Initializable {
} catch (InterruptedException e) { } catch (InterruptedException e) {
} }
} }
Transaction transaction = Cat.newTransaction("Apollo.ConfigService", "pollNotification"); Transaction transaction = Tracer.newTransaction("Apollo.ConfigService", "pollNotification");
try { try {
if (lastServiceDto == null) { if (lastServiceDto == null) {
List<ServiceDTO> configServices = getConfigServices(); List<ServiceDTO> configServices = getConfigServices();
...@@ -178,10 +177,10 @@ public class RemoteConfigLongPollService implements Initializable { ...@@ -178,10 +177,10 @@ public class RemoteConfigLongPollService implements Initializable {
m_longPollFailSchedulePolicyInSecond.success(); m_longPollFailSchedulePolicyInSecond.success();
transaction.addData("StatusCode", response.getStatusCode()); transaction.addData("StatusCode", response.getStatusCode());
transaction.setStatus(Message.SUCCESS); transaction.setStatus(Transaction.SUCCESS);
} catch (Throwable ex) { } catch (Throwable ex) {
lastServiceDto = null; lastServiceDto = null;
Cat.logError(ex); Tracer.logError(ex);
transaction.setStatus(ex); transaction.setStatus(ex);
long sleepTimeInSecond = m_longPollFailSchedulePolicyInSecond.fail(); long sleepTimeInSecond = m_longPollFailSchedulePolicyInSecond.fail();
logger.warn( logger.warn(
...@@ -215,7 +214,7 @@ public class RemoteConfigLongPollService implements Initializable { ...@@ -215,7 +214,7 @@ public class RemoteConfigLongPollService implements Initializable {
try { try {
remoteConfigRepository.onLongPollNotified(lastServiceDto); remoteConfigRepository.onLongPollNotified(lastServiceDto);
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(ex); Tracer.logError(ex);
} }
} }
} }
......
...@@ -15,13 +15,12 @@ import com.ctrip.framework.apollo.core.dto.ServiceDTO; ...@@ -15,13 +15,12 @@ import com.ctrip.framework.apollo.core.dto.ServiceDTO;
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory; import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException; import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.exceptions.ApolloConfigStatusCodeException; import com.ctrip.framework.apollo.exceptions.ApolloConfigStatusCodeException;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.tracer.spi.Transaction;
import com.ctrip.framework.apollo.util.ConfigUtil; import com.ctrip.framework.apollo.util.ConfigUtil;
import com.ctrip.framework.apollo.util.http.HttpRequest; import com.ctrip.framework.apollo.util.http.HttpRequest;
import com.ctrip.framework.apollo.util.http.HttpResponse; import com.ctrip.framework.apollo.util.http.HttpResponse;
import com.ctrip.framework.apollo.util.http.HttpUtil; import com.ctrip.framework.apollo.util.http.HttpUtil;
import com.dianping.cat.Cat;
import com.dianping.cat.message.Message;
import com.dianping.cat.message.Transaction;
import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
...@@ -78,7 +77,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository { ...@@ -78,7 +77,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
m_serviceLocator = m_container.lookup(ConfigServiceLocator.class); m_serviceLocator = m_container.lookup(ConfigServiceLocator.class);
remoteConfigLongPollService = m_container.lookup(RemoteConfigLongPollService.class); remoteConfigLongPollService = m_container.lookup(RemoteConfigLongPollService.class);
} catch (ComponentLookupException ex) { } catch (ComponentLookupException ex) {
Cat.logError(ex); Tracer.logError(ex);
throw new ApolloConfigException("Unable to load component!", ex); throw new ApolloConfigException("Unable to load component!", ex);
} }
m_longPollServiceDto = new AtomicReference<>(); m_longPollServiceDto = new AtomicReference<>();
...@@ -108,10 +107,10 @@ public class RemoteConfigRepository extends AbstractConfigRepository { ...@@ -108,10 +107,10 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {
Cat.logEvent("Apollo.ConfigService", String.format("periodicRefresh: %s", m_namespace)); Tracer.logEvent("Apollo.ConfigService", String.format("periodicRefresh: %s", m_namespace));
logger.debug("refresh config for namespace: {}", m_namespace); logger.debug("refresh config for namespace: {}", m_namespace);
trySync(); trySync();
Cat.logEvent("Apollo.Client.Version", Apollo.VERSION); Tracer.logEvent("Apollo.Client.Version", Apollo.VERSION);
} }
}, m_configUtil.getRefreshInterval(), m_configUtil.getRefreshInterval(), }, m_configUtil.getRefreshInterval(), m_configUtil.getRefreshInterval(),
m_configUtil.getRefreshIntervalTimeUnit()); m_configUtil.getRefreshIntervalTimeUnit());
...@@ -119,7 +118,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository { ...@@ -119,7 +118,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
@Override @Override
protected synchronized void sync() { protected synchronized void sync() {
Transaction transaction = Cat.newTransaction("Apollo.ConfigService", "syncRemoteConfig"); Transaction transaction = Tracer.newTransaction("Apollo.ConfigService", "syncRemoteConfig");
try { try {
ApolloConfig previous = m_configCache.get(); ApolloConfig previous = m_configCache.get();
...@@ -133,11 +132,11 @@ public class RemoteConfigRepository extends AbstractConfigRepository { ...@@ -133,11 +132,11 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
} }
if (current != null) { if (current != null) {
Cat.logEvent(String.format("Apollo.Client.Configs.%s", current.getNamespaceName()), Tracer.logEvent(String.format("Apollo.Client.Configs.%s", current.getNamespaceName()),
current.getReleaseKey()); current.getReleaseKey());
} }
transaction.setStatus(Message.SUCCESS); transaction.setStatus(Transaction.SUCCESS);
} catch (Throwable ex) { } catch (Throwable ex) {
transaction.setStatus(ex); transaction.setStatus(ex);
throw ex; throw ex;
...@@ -163,7 +162,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository { ...@@ -163,7 +162,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
String appId = m_configUtil.getAppId(); String appId = m_configUtil.getAppId();
String cluster = m_configUtil.getCluster(); String cluster = m_configUtil.getCluster();
String dataCenter = m_configUtil.getDataCenter(); String dataCenter = m_configUtil.getDataCenter();
Cat.logEvent("Apollo.Client.ConfigMeta", STRING_JOINER.join(appId, cluster, m_namespace)); Tracer.logEvent("Apollo.Client.ConfigMeta", STRING_JOINER.join(appId, cluster, m_namespace));
int maxRetries = 2; int maxRetries = 2;
Throwable exception = null; Throwable exception = null;
...@@ -184,14 +183,14 @@ public class RemoteConfigRepository extends AbstractConfigRepository { ...@@ -184,14 +183,14 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
logger.debug("Loading config from {}", url); logger.debug("Loading config from {}", url);
HttpRequest request = new HttpRequest(url); HttpRequest request = new HttpRequest(url);
Transaction transaction = Cat.newTransaction("Apollo.ConfigService", "queryConfig"); Transaction transaction = Tracer.newTransaction("Apollo.ConfigService", "queryConfig");
transaction.addData("Url", url); transaction.addData("Url", url);
try { try {
HttpResponse<ApolloConfig> response = m_httpUtil.doGet(request, ApolloConfig.class); HttpResponse<ApolloConfig> response = m_httpUtil.doGet(request, ApolloConfig.class);
transaction.addData("StatusCode", response.getStatusCode()); transaction.addData("StatusCode", response.getStatusCode());
transaction.setStatus(Message.SUCCESS); transaction.setStatus(Transaction.SUCCESS);
if (response.getStatusCode() == 304) { if (response.getStatusCode() == 304) {
logger.debug("Config server responds with 304 HTTP status code."); logger.debug("Config server responds with 304 HTTP status code.");
...@@ -214,11 +213,11 @@ public class RemoteConfigRepository extends AbstractConfigRepository { ...@@ -214,11 +213,11 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
statusCodeException = new ApolloConfigStatusCodeException(ex.getStatusCode(), statusCodeException = new ApolloConfigStatusCodeException(ex.getStatusCode(),
message); message);
} }
Cat.logError(statusCodeException); Tracer.logError(statusCodeException);
transaction.setStatus(statusCodeException); transaction.setStatus(statusCodeException);
exception = statusCodeException; exception = statusCodeException;
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(ex); Tracer.logError(ex);
transaction.setStatus(ex); transaction.setStatus(ex);
exception = ex; exception = ex;
} finally { } finally {
......
...@@ -5,8 +5,8 @@ import com.google.common.collect.Maps; ...@@ -5,8 +5,8 @@ import com.google.common.collect.Maps;
import com.ctrip.framework.apollo.model.ConfigChange; import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent; import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.util.ExceptionUtil; import com.ctrip.framework.apollo.util.ExceptionUtil;
import com.dianping.cat.Cat;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -42,7 +42,7 @@ public class SimpleConfig extends AbstractConfig implements RepositoryChangeList ...@@ -42,7 +42,7 @@ public class SimpleConfig extends AbstractConfig implements RepositoryChangeList
try { try {
m_configProperties = m_configRepository.getConfig(); m_configProperties = m_configRepository.getConfig();
} catch (Throwable ex) { } catch (Throwable ex) {
Cat.logError(ex); Tracer.logError(ex);
logger.warn("Init Apollo Simple Config failed - namespace: {}, reason: {}", m_namespace, logger.warn("Init Apollo Simple Config failed - namespace: {}, reason: {}", m_namespace,
ExceptionUtil.getDetailMessage(ex)); ExceptionUtil.getDetailMessage(ex));
} finally { } finally {
...@@ -93,6 +93,6 @@ public class SimpleConfig extends AbstractConfig implements RepositoryChangeList ...@@ -93,6 +93,6 @@ public class SimpleConfig extends AbstractConfig implements RepositoryChangeList
this.fireConfigChange(new ConfigChangeEvent(m_namespace, changeMap)); this.fireConfigChange(new ConfigChangeEvent(m_namespace, changeMap));
Cat.logEvent("Apollo.Client.ConfigChanges", m_namespace); Tracer.logEvent("Apollo.Client.ConfigChanges", m_namespace);
} }
} }
package com.ctrip.framework.apollo.internals; package com.ctrip.framework.apollo.internals;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
*/ */
public class XmlConfigFile extends AbstractConfigFile { public class XmlConfigFile extends PlainTextConfigFile {
public XmlConfigFile(String namespace, public XmlConfigFile(String namespace,
ConfigRepository configRepository) { ConfigRepository configRepository) {
super(namespace, configRepository); super(namespace, configRepository);
} }
@Override
public String getContent() {
if (m_configProperties.get() == null) {
return null;
}
return m_configProperties.get().getProperty(ConfigConsts.CONFIG_FILE_CONTENT_KEY);
}
@Override
public boolean hasContent() {
if (m_configProperties.get() == null) {
return false;
}
return m_configProperties.get().containsKey(ConfigConsts.CONFIG_FILE_CONTENT_KEY);
}
@Override @Override
public ConfigFileFormat getConfigFileFormat() { public ConfigFileFormat getConfigFileFormat() {
return ConfigFileFormat.XML; return ConfigFileFormat.XML;
......
package com.ctrip.framework.apollo.internals;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public class YamlConfigFile extends PlainTextConfigFile {
public YamlConfigFile(String namespace, ConfigRepository configRepository) {
super(namespace, configRepository);
}
@Override
public ConfigFileFormat getConfigFileFormat() {
return ConfigFileFormat.YAML;
}
}
package com.ctrip.framework.apollo.internals;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public class YmlConfigFile extends PlainTextConfigFile {
public YmlConfigFile(String namespace, ConfigRepository configRepository) {
super(namespace, configRepository);
}
@Override
public ConfigFileFormat getConfigFileFormat() {
return ConfigFileFormat.YML;
}
}
...@@ -5,10 +5,13 @@ import com.ctrip.framework.apollo.ConfigFile; ...@@ -5,10 +5,13 @@ import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.internals.ConfigRepository; import com.ctrip.framework.apollo.internals.ConfigRepository;
import com.ctrip.framework.apollo.internals.DefaultConfig; import com.ctrip.framework.apollo.internals.DefaultConfig;
import com.ctrip.framework.apollo.internals.JsonConfigFile;
import com.ctrip.framework.apollo.internals.LocalFileConfigRepository; import com.ctrip.framework.apollo.internals.LocalFileConfigRepository;
import com.ctrip.framework.apollo.internals.PropertiesConfigFile; import com.ctrip.framework.apollo.internals.PropertiesConfigFile;
import com.ctrip.framework.apollo.internals.RemoteConfigRepository; import com.ctrip.framework.apollo.internals.RemoteConfigRepository;
import com.ctrip.framework.apollo.internals.XmlConfigFile; import com.ctrip.framework.apollo.internals.XmlConfigFile;
import com.ctrip.framework.apollo.internals.YamlConfigFile;
import com.ctrip.framework.apollo.internals.YmlConfigFile;
import com.ctrip.framework.apollo.util.ConfigUtil; import com.ctrip.framework.apollo.util.ConfigUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -40,6 +43,12 @@ public class DefaultConfigFactory implements ConfigFactory { ...@@ -40,6 +43,12 @@ public class DefaultConfigFactory implements ConfigFactory {
return new PropertiesConfigFile(namespace, configRepository); return new PropertiesConfigFile(namespace, configRepository);
case XML: case XML:
return new XmlConfigFile(namespace, configRepository); return new XmlConfigFile(namespace, configRepository);
case JSON:
return new JsonConfigFile(namespace, configRepository);
case YAML:
return new YamlConfigFile(namespace, configRepository);
case YML:
return new YmlConfigFile(namespace, configRepository);
} }
return null; return null;
......
...@@ -21,7 +21,7 @@ import java.util.concurrent.TimeUnit; ...@@ -21,7 +21,7 @@ import java.util.concurrent.TimeUnit;
@Named(type = ConfigUtil.class) @Named(type = ConfigUtil.class)
public class ConfigUtil { public class ConfigUtil {
private static final Logger logger = LoggerFactory.getLogger(ConfigUtil.class); private static final Logger logger = LoggerFactory.getLogger(ConfigUtil.class);
private static final String TOOLING_CLUSTER = "TOOLING"; private static final String TOOLING_CLUSTER = "tooling";
private int refreshInterval = 5; private int refreshInterval = 5;
private TimeUnit refreshIntervalTimeUnit = TimeUnit.MINUTES; private TimeUnit refreshIntervalTimeUnit = TimeUnit.MINUTES;
private int connectTimeout = 1000; //1 second private int connectTimeout = 1000; //1 second
...@@ -65,6 +65,14 @@ public class ConfigUtil { ...@@ -65,6 +65,14 @@ public class ConfigUtil {
//Load data center from system property //Load data center from system property
cluster = System.getProperty(ConfigConsts.APOLLO_CLUSTER_KEY); cluster = System.getProperty(ConfigConsts.APOLLO_CLUSTER_KEY);
String env = Foundation.server().getEnvType();
//LPT and DEV will be treated as a cluster(lower case)
if (Strings.isNullOrEmpty(cluster) &&
(Env.DEV.name().equalsIgnoreCase(env) || Env.LPT.name().equalsIgnoreCase(env))
) {
cluster = env.toLowerCase();
}
//Use TOOLING cluster if tooling=true in server.properties //Use TOOLING cluster if tooling=true in server.properties
if (Strings.isNullOrEmpty(cluster) && isToolingZone()) { if (Strings.isNullOrEmpty(cluster) && isToolingZone()) {
cluster = TOOLING_CLUSTER; cluster = TOOLING_CLUSTER;
......
...@@ -4,6 +4,7 @@ package com.ctrip.framework.apollo; ...@@ -4,6 +4,7 @@ package com.ctrip.framework.apollo;
import com.ctrip.framework.apollo.integration.ConfigIntegrationTest; import com.ctrip.framework.apollo.integration.ConfigIntegrationTest;
import com.ctrip.framework.apollo.internals.DefaultConfigManagerTest; import com.ctrip.framework.apollo.internals.DefaultConfigManagerTest;
import com.ctrip.framework.apollo.internals.DefaultConfigTest; import com.ctrip.framework.apollo.internals.DefaultConfigTest;
import com.ctrip.framework.apollo.internals.JsonConfigFileTest;
import com.ctrip.framework.apollo.internals.LocalFileConfigRepositoryTest; import com.ctrip.framework.apollo.internals.LocalFileConfigRepositoryTest;
import com.ctrip.framework.apollo.internals.PropertiesConfigFileTest; import com.ctrip.framework.apollo.internals.PropertiesConfigFileTest;
import com.ctrip.framework.apollo.internals.RemoteConfigLongPollServiceTest; import com.ctrip.framework.apollo.internals.RemoteConfigLongPollServiceTest;
...@@ -28,7 +29,7 @@ import org.junit.runners.Suite.SuiteClasses; ...@@ -28,7 +29,7 @@ import org.junit.runners.Suite.SuiteClasses;
RemoteConfigRepositoryTest.class, SimpleConfigTest.class, DefaultConfigFactoryTest.class, RemoteConfigRepositoryTest.class, SimpleConfigTest.class, DefaultConfigFactoryTest.class,
ConfigIntegrationTest.class, ExceptionUtilTest.class, XmlConfigFileTest.class, ConfigIntegrationTest.class, ExceptionUtilTest.class, XmlConfigFileTest.class,
PropertiesConfigFileTest.class, RemoteConfigLongPollServiceTest.class, DateParserTest.class, PropertiesConfigFileTest.class, RemoteConfigLongPollServiceTest.class, DateParserTest.class,
DurationParserTest.class DurationParserTest.class, JsonConfigFileTest.class
}) })
public class AllTests { public class AllTests {
......
...@@ -5,8 +5,8 @@ import com.google.common.collect.Lists; ...@@ -5,8 +5,8 @@ import com.google.common.collect.Lists;
import com.google.common.io.Files; import com.google.common.io.Files;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.core.dto.ServiceDTO; import com.ctrip.framework.apollo.core.dto.ServiceDTO;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.core.utils.ClassLoaderUtil; import com.ctrip.framework.apollo.core.utils.ClassLoaderUtil;
import com.ctrip.framework.apollo.util.ConfigUtil; import com.ctrip.framework.apollo.util.ConfigUtil;
......
...@@ -5,7 +5,6 @@ import com.ctrip.framework.apollo.ConfigFile; ...@@ -5,7 +5,6 @@ import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.spi.ConfigFactory; import com.ctrip.framework.apollo.spi.ConfigFactory;
import com.ctrip.framework.apollo.spi.ConfigFactoryManager; import com.ctrip.framework.apollo.spi.ConfigFactoryManager;
import com.ctrip.framework.apollo.spi.ConfigRegistry;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
......
package com.ctrip.framework.apollo.internals;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@RunWith(MockitoJUnitRunner.class)
public class JsonConfigFileTest {
private String someNamespace;
@Mock
private ConfigRepository configRepository;
@Before
public void setUp() throws Exception {
someNamespace = "someName";
}
@Test
public void testWhenHasContent() throws Exception {
Properties someProperties = new Properties();
String key = ConfigConsts.CONFIG_FILE_CONTENT_KEY;
String someValue = "someValue";
someProperties.setProperty(key, someValue);
when(configRepository.getConfig()).thenReturn(someProperties);
JsonConfigFile configFile = new JsonConfigFile(someNamespace, configRepository);
assertEquals(ConfigFileFormat.JSON, configFile.getConfigFileFormat());
assertEquals(someNamespace, configFile.getNamespace());
assertTrue(configFile.hasContent());
assertEquals(someValue, configFile.getContent());
}
@Test
public void testWhenHasNoContent() throws Exception {
when(configRepository.getConfig()).thenReturn(null);
JsonConfigFile configFile = new JsonConfigFile(someNamespace, configRepository);
assertFalse(configFile.hasContent());
assertNull(configFile.getContent());
}
@Test
public void testWhenConfigRepositoryHasError() throws Exception {
when(configRepository.getConfig()).thenThrow(new RuntimeException("someError"));
JsonConfigFile configFile = new JsonConfigFile(someNamespace, configRepository);
assertFalse(configFile.hasContent());
assertNull(configFile.getContent());
}
@Test
public void testOnRepositoryChange() throws Exception {
Properties someProperties = new Properties();
String key = ConfigConsts.CONFIG_FILE_CONTENT_KEY;
String someValue = "someValue";
String anotherValue = "anotherValue";
someProperties.setProperty(key, someValue);
when(configRepository.getConfig()).thenReturn(someProperties);
JsonConfigFile configFile = new JsonConfigFile(someNamespace, configRepository);
assertEquals(someValue, configFile.getContent());
Properties anotherProperties = new Properties();
anotherProperties.setProperty(key, anotherValue);
configFile.onRepositoryChange(someNamespace, anotherProperties);
assertEquals(anotherValue, configFile.getContent());
}
@Test
public void testWhenConfigRepositoryHasErrorAndThenRecovered() throws Exception {
Properties someProperties = new Properties();
String key = ConfigConsts.CONFIG_FILE_CONTENT_KEY;
String someValue = "someValue";
someProperties.setProperty(key, someValue);
when(configRepository.getConfig()).thenThrow(new RuntimeException("someError"));
JsonConfigFile configFile = new JsonConfigFile(someNamespace, configRepository);
assertFalse(configFile.hasContent());
assertNull(configFile.getContent());
configFile.onRepositoryChange(someNamespace, someProperties);
assertTrue(configFile.hasContent());
assertEquals(someValue, configFile.getContent());
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment