Commit e74556fe by Yiming Liu

Fix AdminService bugs

parent 6da1ec5a
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent> <parent>
<groupId>com.ctrip.apollo</groupId> <groupId>com.ctrip.apollo</groupId>
<artifactId>apollo</artifactId> <artifactId>apollo</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>apollo-adminservice</artifactId> <artifactId>apollo-adminservice</artifactId>
<name>Apollo AdminService</name> <name>Apollo AdminService</name>
<dependencies> <dependencies>
<!-- apollo --> <!-- apollo -->
<dependency> <dependency>
<groupId>com.ctrip.apollo</groupId> <groupId>com.ctrip.apollo</groupId>
<artifactId>apollo-biz</artifactId> <artifactId>apollo-biz</artifactId>
</dependency> </dependency>
<!-- end of apollo --> <!-- end of apollo -->
<!-- redis --> <!-- eureka -->
<dependency> <dependency>
<groupId>org.springframework.data</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-data-redis</artifactId> <artifactId>spring-cloud-starter-eureka</artifactId>
</dependency> </dependency>
<dependency> <!-- end of eureka -->
<groupId>redis.clients</groupId> </dependencies>
<artifactId>jedis</artifactId> <build>
</dependency> <plugins>
<!-- end of redis --> <plugin>
<!-- eureka --> <groupId>org.springframework.boot</groupId>
<dependency> <artifactId>spring-boot-maven-plugin</artifactId>
<groupId>org.springframework.cloud</groupId> </plugin>
<artifactId>spring-cloud-starter-eureka-server</artifactId> </plugins>
</dependency> </build>
<!-- end of eureka -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project> </project>
...@@ -9,6 +9,6 @@ import org.springframework.cloud.netflix.eureka.EnableEurekaClient; ...@@ -9,6 +9,6 @@ import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@EnableEurekaClient @EnableEurekaClient
public class AdminServiceApplication { public class AdminServiceApplication {
public static void main(String[] args) { public static void main(String[] args) {
new SpringApplicationBuilder(AdminServiceApplication.class).web(true).run(args); new SpringApplicationBuilder(AdminServiceApplication.class).run(args);
} }
} }
...@@ -3,6 +3,7 @@ package com.ctrip.apollo.adminservice.controller; ...@@ -3,6 +3,7 @@ package com.ctrip.apollo.adminservice.controller;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
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.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
...@@ -12,22 +13,29 @@ import com.ctrip.apollo.biz.entity.App; ...@@ -12,22 +13,29 @@ import com.ctrip.apollo.biz.entity.App;
import com.ctrip.apollo.biz.service.AppService; import com.ctrip.apollo.biz.service.AppService;
import com.ctrip.apollo.biz.utils.BeanUtils; import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.AppDTO; import com.ctrip.apollo.core.dto.AppDTO;
import com.google.common.base.Strings;
@RestController @RestController
public class AppController { public class AppController {
@Autowired @Autowired
private AppService appService; private AppService appService;
@RequestMapping("/apps/{appId}") @RequestMapping("/apps/{appId}")
public AppDTO findByAppId(@PathVariable("appId") String appId) { public AppDTO getApp(@PathVariable("appId") String appId) {
App app = appService.findByAppId(appId); App app = appService.findOne(appId);
return BeanUtils.transfrom(AppDTO.class, app); return BeanUtils.transfrom(AppDTO.class, app);
} }
@RequestMapping("/apps") @RequestMapping("/apps")
public List<AppDTO> findByName(@RequestParam("name") String name) { public List<AppDTO> findApps(@RequestParam(value = "name", required = false) String name,
List<App> app = appService.findByName(name); Pageable pageable) {
return BeanUtils.batchTransform(AppDTO.class, app); List<App> app = null;
if (Strings.isNullOrEmpty(name)) {
app = appService.findAll(pageable);
} else {
app = appService.findByName(name);
}
return BeanUtils.batchTransform(AppDTO.class, app);
} }
} }
...@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.ctrip.apollo.biz.entity.Cluster; import com.ctrip.apollo.biz.entity.Cluster;
import com.ctrip.apollo.biz.service.ClusterService;
import com.ctrip.apollo.biz.service.ViewService; import com.ctrip.apollo.biz.service.ViewService;
import com.ctrip.apollo.biz.utils.BeanUtils; import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.ClusterDTO; import com.ctrip.apollo.core.dto.ClusterDTO;
...@@ -18,9 +19,19 @@ public class ClusterController { ...@@ -18,9 +19,19 @@ public class ClusterController {
@Autowired @Autowired
private ViewService viewService; private ViewService viewService;
@Autowired
private ClusterService clusterService;
@RequestMapping("/apps/{appId}/clusters") @RequestMapping("/apps/{appId}/clusters")
public List<ClusterDTO> findClusters(@PathVariable("appId") String appId) { public List<ClusterDTO> findClusters(@PathVariable("appId") String appId) {
List<Cluster> clusters = viewService.findClusters(appId); List<Cluster> clusters = viewService.findClusters(appId);
return BeanUtils.batchTransform(ClusterDTO.class, clusters); return BeanUtils.batchTransform(ClusterDTO.class, clusters);
} }
@RequestMapping("/apps/{appId}/clusters/{clusterName}")
public ClusterDTO getCluster(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName) {
Cluster cluster = clusterService.findOne(appId, clusterName);
return BeanUtils.transfrom(ClusterDTO.class, cluster);
}
} }
...@@ -14,24 +14,33 @@ import com.ctrip.apollo.biz.utils.BeanUtils; ...@@ -14,24 +14,33 @@ import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.NamespaceDTO; import com.ctrip.apollo.core.dto.NamespaceDTO;
@RestController @RestController
public class GroupController { public class NamespaceController {
@Autowired @Autowired
private ViewService viewService; private ViewService viewService;
@Autowired @Autowired
private NamespaceService groupService; private NamespaceService namespaceService;
@RequestMapping("/apps/{appId}/clusters/{clusterName}/groups") @RequestMapping("/apps/{appId}/clusters/{clusterName}/namespaces")
public List<NamespaceDTO> findGroups(@PathVariable("appId") String appId, public List<NamespaceDTO> findNamespaces(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName) { @PathVariable("clusterName") String clusterName) {
List<Namespace> groups = viewService.findNamespaces(appId, clusterName); List<Namespace> groups = viewService.findNamespaces(appId, clusterName);
return BeanUtils.batchTransform(NamespaceDTO.class, groups); return BeanUtils.batchTransform(NamespaceDTO.class, groups);
} }
@RequestMapping("/groups/{groupId}") @RequestMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}")
public NamespaceDTO findOne(@PathVariable("groupId") Long groupId) { public NamespaceDTO getNamespace(@PathVariable("appId") String appId,
Namespace group = groupService.findOne(groupId); @PathVariable("clusterName") String clusterName,
return BeanUtils.transfrom(NamespaceDTO.class, group); @PathVariable("namespaceName") String namespaceName) {
Namespace namespace = namespaceService.findOne(appId,
clusterName, namespaceName);
return BeanUtils.transfrom(NamespaceDTO.class, namespace);
}
@RequestMapping("/namespaces/{namespaceId}")
public NamespaceDTO getNamespace(@PathVariable("namespaceId") Long namespaceId) {
Namespace namespace = namespaceService.findOne(namespaceId);
return BeanUtils.transfrom(NamespaceDTO.class, namespace);
} }
} }
package com.ctrip.apollo.adminservice.controller;
import java.util.List;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
PageableHandlerMethodArgumentResolver resolver = new PageableHandlerMethodArgumentResolver();
resolver.setFallbackPageable(new PageRequest(0, 10));
argumentResolvers.add(resolver);
}
}
package com.ctrip.apollo;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@EnableEurekaClient
public class SampleAdminServiceApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(SampleAdminServiceApplication.class).run(args);
}
}
spring.datasource.url = jdbc:h2:mem:~/fxapolloconfigdb;mode=mysql
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.h2.console.enabled = true
spring.h2.console.settings.web-allow-others=true
INSERT INTO App (AppId, Name, OwnerName, OwnerEmail) VALUES ('100003171','apollo-config-service','刘一鸣','liuym@ctrip.com');
INSERT INTO App (AppId, Name, OwnerName, OwnerEmail) VALUES ('100003172','apollo-admin-service','宋顺','song_s@ctrip.com');
INSERT INTO App (AppId, Name, OwnerName, OwnerEmail) VALUES ('100003173','apollo-portal','张乐','zhanglea@ctrip.com');
INSERT INTO App (AppId, Name, OwnerName, OwnerEmail) VALUES ('fxhermesproducer','fx-hermes-producer','梁锦华','jhliang@ctrip.com');
INSERT INTO Cluster (AppId, Name) VALUES ('100003171', 'default');
INSERT INTO Cluster (AppId, Name) VALUES ('100003171', 'cluster1');
INSERT INTO Cluster (AppId, Name) VALUES ('100003172', 'default');
INSERT INTO Cluster (AppId, Name) VALUES ('100003172', 'cluster2');
INSERT INTO Cluster (AppId, Name) VALUES ('100003173', 'default');
INSERT INTO Cluster (AppId, Name) VALUES ('100003173', 'cluster3');
INSERT INTO Cluster (AppId, Name) VALUES ('fxhermesproducer', 'default');
INSERT INTO AppNamespace (AppId, Name) VALUES ('100003171', 'apollo-config-service');
INSERT INTO AppNamespace (AppId, Name) VALUES ('100003172', 'apollo-admin-service');
INSERT INTO AppNamespace (AppId, Name) VALUES ('100003173', 'apollo-portal-service');
INSERT INTO AppNamespace (AppID, Name) VALUES ('fxhermesproducer', 'fx-hermes-producer');
INSERT INTO Namespace (Id, AppId, ClusterName, NamespaceName) VALUES (1, '100003171', 'default', 'apollo-config-service');
INSERT INTO Namespace (Id, AppId, ClusterName, NamespaceName) VALUES (2, 'fxhermesproducer', 'default', 'fx-hermes-producer');
INSERT INTO Namespace (Id, AppId, ClusterName, NamespaceName) VALUES (3, '100003172', 'default', 'apollo-admin-service');
INSERT INTO Namespace (Id, AppId, ClusterName, NamespaceName) VALUES (4, '100003173', 'default', 'apollo-portal');
INSERT INTO Namespace (Id, AppId, ClusterName, NamespaceName) VALUES (5, '100003171', 'default', 'fx-hermes-producer');
INSERT INTO Item (NamespaceId, `Key`, Value, Comment) VALUES (1, 'k1', 'v1', 'comment1');
INSERT INTO Item (NamespaceId, `Key`, Value, Comment) VALUES (1, 'k2', 'v2', 'comment2');
INSERT INTO Item (NamespaceId, `Key`, Value, Comment) VALUES (2, 'k3', 'v3', 'comment3');
INSERT INTO Item (NamespaceId, `Key`, Value, Comment) VALUES (5, 'k3', 'v4', 'comment4');
INSERT INTO `RELEASE` (Name, Comment, AppId, ClusterName, NamespaceName, Configurations) VALUES ('REV1','First Release','100003171', 'default', 'apollo-config-service', '{"k1":"v1"}');
...@@ -19,12 +19,6 @@ ...@@ -19,12 +19,6 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
<profiles> <profiles>
......
...@@ -7,14 +7,14 @@ import org.hibernate.annotations.SQLDelete; ...@@ -7,14 +7,14 @@ import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where; import org.hibernate.annotations.Where;
@Entity @Entity
@SQLDelete(sql = "Update App set isDeleted = 1 where id = ?") @SQLDelete(sql = "Update App set isDeleted = 'false' where id = ?")
@Where(clause = "isDeleted = 0") @Where(clause = "isDeleted = 'false'")
public class App extends BaseEntity { public class App extends BaseEntity {
@Column(nullable = false) @Column(nullable = false)
private String name; private String name;
@Column(nullable = false) @Column(nullable = false, unique = true)
private String appId; private String appId;
@Column(nullable = false) @Column(nullable = false)
......
...@@ -7,11 +7,11 @@ import org.hibernate.annotations.SQLDelete; ...@@ -7,11 +7,11 @@ import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where; import org.hibernate.annotations.Where;
@Entity @Entity
@SQLDelete(sql = "Update AppNamespace set isDeleted = 1 where id = ?") @SQLDelete(sql = "Update AppNamespace set isDeleted = 'false' where id = ?")
@Where(clause = "isDeleted = 0") @Where(clause = "isDeleted = 'false'")
public class AppNamespace extends BaseEntity{ public class AppNamespace extends BaseEntity{
@Column(nullable = false) @Column(nullable = false, unique = true)
private String name; private String name;
@Column(nullable = false) @Column(nullable = false)
......
...@@ -10,8 +10,8 @@ import org.hibernate.annotations.Where; ...@@ -10,8 +10,8 @@ import org.hibernate.annotations.Where;
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
*/ */
@Entity @Entity
@SQLDelete(sql = "Update Cluster set isDeleted = 1 where id = ?") @SQLDelete(sql = "Update Cluster set isDeleted = 'false' where id = ?")
@Where(clause = "isDeleted = 0") @Where(clause = "isDeleted = 'false'")
public class Cluster extends BaseEntity { public class Cluster extends BaseEntity {
@Column(nullable = false) @Column(nullable = false)
......
...@@ -7,8 +7,8 @@ import org.hibernate.annotations.SQLDelete; ...@@ -7,8 +7,8 @@ import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where; import org.hibernate.annotations.Where;
@Entity @Entity
@SQLDelete(sql = "Update Item set isDeleted = 1 where id = ?") @SQLDelete(sql = "Update Item set isDeleted = 'false' where id = ?")
@Where(clause = "isDeleted = 0") @Where(clause = "isDeleted = 'false'")
public class Item extends BaseEntity { public class Item extends BaseEntity {
@Column(nullable = false) @Column(nullable = false)
......
...@@ -7,8 +7,8 @@ import org.hibernate.annotations.SQLDelete; ...@@ -7,8 +7,8 @@ import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where; import org.hibernate.annotations.Where;
@Entity @Entity
@SQLDelete(sql = "Update Namespace set isDeleted = 1 where id = ?") @SQLDelete(sql = "Update Namespace set isDeleted = 'false' where id = ?")
@Where(clause = "isDeleted = 0") @Where(clause = "isDeleted = 'false'")
public class Namespace extends BaseEntity { public class Namespace extends BaseEntity {
@Column(nullable = false) @Column(nullable = false)
......
...@@ -7,8 +7,8 @@ import org.hibernate.annotations.SQLDelete; ...@@ -7,8 +7,8 @@ import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where; import org.hibernate.annotations.Where;
@Entity @Entity
@SQLDelete(sql = "Update Privilege set isDeleted = 1 where id = ?") @SQLDelete(sql = "Update Privilege set isDeleted = 'false' where id = ?")
@Where(clause = "isDeleted = 0") @Where(clause = "isDeleted = 'false'")
public class Privilege extends BaseEntity { public class Privilege extends BaseEntity {
@Column @Column
......
...@@ -11,8 +11,8 @@ import org.hibernate.annotations.Where; ...@@ -11,8 +11,8 @@ import org.hibernate.annotations.Where;
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
*/ */
@Entity @Entity
@SQLDelete(sql = "Update Release set isDeleted = 1 where id = ?") @SQLDelete(sql = "Update Release set isDeleted = 'false' where id = ?")
@Where(clause = "isDeleted = 0") @Where(clause = "isDeleted = 'false'")
public class Release extends BaseEntity { public class Release extends BaseEntity {
@Column(nullable = false) @Column(nullable = false)
......
...@@ -29,7 +29,7 @@ public class AppService { ...@@ -29,7 +29,7 @@ public class AppService {
return appRepository.findByName(name); return appRepository.findByName(name);
} }
public App findByAppId(String appId){ public App findOne(String appId){
return appRepository.findByAppId(appId); return appRepository.findByAppId(appId);
} }
} }
package com.ctrip.apollo.biz.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ctrip.apollo.biz.entity.Cluster;
import com.ctrip.apollo.biz.repository.ClusterRepository;
@Service
public class ClusterService {
@Autowired
private ClusterRepository clusterRepository;
public Cluster findOne(String appId, String name) {
return clusterRepository.findByAppIdAndName(appId, name);
}
}
...@@ -11,8 +11,14 @@ public class NamespaceService { ...@@ -11,8 +11,14 @@ public class NamespaceService {
@Autowired @Autowired
private NamespaceRepository namespaceRepository; private NamespaceRepository namespaceRepository;
public Namespace findOne(Long namespaceId){ public Namespace findOne(Long namespaceId) {
return namespaceRepository.findOne(namespaceId); return namespaceRepository.findOne(namespaceId);
} }
public Namespace findOne(String appId, String clusterName,
String namespaceName) {
return namespaceRepository.findByAppIdAndClusterNameAndNamespaceName(appId, clusterName,
namespaceName);
}
} }
...@@ -3,7 +3,6 @@ package com.ctrip.apollo; ...@@ -3,7 +3,6 @@ package com.ctrip.apollo;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.context.ConfigurableApplicationContext;
/** /**
* Spring boot application entry point * Spring boot application entry point
...@@ -12,11 +11,10 @@ import org.springframework.context.ConfigurableApplicationContext; ...@@ -12,11 +11,10 @@ import org.springframework.context.ConfigurableApplicationContext;
*/ */
@SpringBootApplication @SpringBootApplication
@EnableEurekaServer @EnableEurekaServer
public class ServerApplication { public class ConfigServiceApplication {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
ConfigurableApplicationContext context = new SpringApplicationBuilder(ConfigServiceApplication.class).run(args);
new SpringApplicationBuilder(ServerApplication.class).web(true).run(args);
} }
} }
...@@ -12,7 +12,7 @@ public class ServletInitializer extends SpringBootServletInitializer { ...@@ -12,7 +12,7 @@ public class ServletInitializer extends SpringBootServletInitializer {
@Override @Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ServerApplication.class); return application.sources(ConfigServiceApplication.class);
} }
} }
package com.ctrip.apollo;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class SampleConfigServiceApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(SampleConfigServiceApplication.class).run(args);
}
}
package com.ctrip.apollo.configservice; package com.ctrip.apollo.configservice;
import com.ctrip.apollo.ServerApplication; import com.ctrip.apollo.ConfigServiceApplication;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ServerApplication.class) @SpringApplicationConfiguration(classes = ConfigServiceApplication.class)
public abstract class AbstractConfigServiceTest { public abstract class AbstractConfigServiceTest {
} }
spring:
application:
name: apollo-configservice
datasource:
url: jdbc:h2:mem:~/fxapolloconfigdb;DB_CLOSE_ON_EXIT=FALSE
server: server:
port: 8888 port: ${port:8080}
logging: logging:
level: level:
org.springframework.cloud: 'DEBUG' org.springframework.cloud: 'DEBUG'
file: /opt/logs/${ctrip.appid}/apollo-configservice.log
spring: ctrip:
application: appid: 100003171
name: apollo-configservice \ No newline at end of file
datasource:
url: jdbc:h2:file:~/fxapolloconfigdb;DB_CLOSE_ON_EXIT=FALSE
username: sa
password:
eureka: eureka:
instance: instance:
hostname: localhost hostname: ${hostname:localhost}
preferIpAddress: true
client: client:
serviceUrl: serviceUrl:
defaultZone: http://${eureka.instance.hostname}:8761/eureka/ defaultZone: http://${eureka.instance.hostname}:8080/eureka/
healthcheck:
enabled: true
\ No newline at end of file
...@@ -2,6 +2,8 @@ package com.ctrip.apollo.core.dto; ...@@ -2,6 +2,8 @@ package com.ctrip.apollo.core.dto;
public class AppDTO { public class AppDTO {
private long id;
private String name; private String name;
private String appId; private String appId;
...@@ -14,6 +16,10 @@ public class AppDTO { ...@@ -14,6 +16,10 @@ public class AppDTO {
return appId; return appId;
} }
public long getId() {
return id;
}
public String getName() { public String getName() {
return name; return name;
} }
...@@ -30,6 +36,10 @@ public class AppDTO { ...@@ -30,6 +36,10 @@ public class AppDTO {
this.appId = appId; this.appId = appId;
} }
public void setId(long id) {
this.id = id;
}
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
......
...@@ -4,11 +4,7 @@ public class ItemDTO { ...@@ -4,11 +4,7 @@ public class ItemDTO {
private long id; private long id;
private long clusterId; private long namespaceId;
private String clusterName;
private String appId;
private String key; private String key;
...@@ -25,59 +21,43 @@ public class ItemDTO { ...@@ -25,59 +21,43 @@ public class ItemDTO {
this.value = value; this.value = value;
} }
public long getId() { public String getComment() {
return id; return comment;
}
public void setId(long id) {
this.id = id;
}
public long getClusterId() {
return clusterId;
} }
public void setClusterId(long clusterId) { public long getId() {
this.clusterId = clusterId; return id;
} }
public String getClusterName() { public String getKey() {
return clusterName; return key;
} }
public void setClusterName(String clusterName) { public long getNamespaceId() {
this.clusterName = clusterName; return namespaceId;
} }
public String getAppId() { public String getValue() {
return appId; return value;
} }
public void setAppId(String appId) { public void setComment(String comment) {
this.appId = appId; this.comment = comment;
} }
public String getKey() { public void setId(long id) {
return key; this.id = id;
} }
public void setKey(String key) { public void setKey(String key) {
this.key = key; this.key = key;
} }
public String getValue() { public void setNamespaceId(long namespaceId) {
return value; this.namespaceId = namespaceId;
} }
public void setValue(String value) { public void setValue(String value) {
this.value = value; this.value = value;
} }
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
} }
...@@ -4,41 +4,41 @@ public class NamespaceDTO { ...@@ -4,41 +4,41 @@ public class NamespaceDTO {
private long id; private long id;
private long clusterId; private String appId;
private String clusterName;
private long namespaceId; private String namespaceName;
private String name; public String getAppId() {
return appId;
}
public long getClusterId() { public String getClusterId() {
return clusterId; return clusterName;
} }
public long getId() { public long getId() {
return id; return id;
} }
public String getName() { public String getNamespaceName() {
return name; return namespaceName;
} }
public long getNamespaceId() { public void setAppId(String appId) {
return namespaceId; this.appId = appId;
} }
public void setClusterId(long clusterId) { public void setClusterName(String clusterName) {
this.clusterId = clusterId; this.clusterName = clusterName;
} }
public void setId(long id) { public void setId(long id) {
this.id = id; this.id = id;
} }
public void setName(String name) { public void setNamespaceName(String namespaceName) {
this.name = name; this.namespaceName = namespaceName;
}
public void setNamespaceId(long namespaceId) {
this.namespaceId = namespaceId;
} }
} }
...@@ -4,45 +4,72 @@ public class ReleaseDTO { ...@@ -4,45 +4,72 @@ public class ReleaseDTO {
private long id; private long id;
private long releaseId; private String name;
private String appId;
private String clusterName; private String clusterName;
private String namespaceName;
private String configurations; private String configurations;
public ReleaseDTO() { private String comment;
public String getAppId() {
return appId;
} }
public long getId() { public String getClusterName() {
return id; return clusterName;
} }
public void setId(long id) { public String getComment() {
this.id = id; return comment;
} }
public long getReleaseId() { public String getConfigurations() {
return releaseId; return configurations;
} }
public void setReleaseId(long releaseId) { public long getId() {
this.releaseId = releaseId; return id;
} }
public String getClusterName() { public String getName() {
return clusterName; return name;
}
public String getNamespaceName() {
return namespaceName;
}
public void setAppId(String appId) {
this.appId = appId;
} }
public void setClusterName(String clusterName) { public void setClusterName(String clusterName) {
this.clusterName = clusterName; this.clusterName = clusterName;
} }
public String getConfigurations() { public void setComment(String comment) {
return configurations; this.comment = comment;
} }
public void setConfigurations(String configurations) { public void setConfigurations(String configurations) {
this.configurations = configurations; this.configurations = configurations;
} }
public void setId(long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setNamespaceName(String namespaceName) {
this.namespaceName = namespaceName;
}
} }
...@@ -180,16 +180,16 @@ public class ConfigService { ...@@ -180,16 +180,16 @@ public class ConfigService {
private Map<String, List<ItemDTO>> groupConfigByCluster(List<ItemDTO> configItems) { private Map<String, List<ItemDTO>> groupConfigByCluster(List<ItemDTO> configItems) {
Map<String, List<ItemDTO>> groupedClusterConfigs = new HashMap<>(); Map<String, List<ItemDTO>> groupedClusterConfigs = new HashMap<>();
String clusterName; // String clusterName;
for (ItemDTO configItem : configItems) { // for (ItemDTO configItem : configItems) {
clusterName = configItem.getClusterName(); // clusterName = configItem.getClusterName();
List<ItemDTO> clusterConfigs = groupedClusterConfigs.get(clusterName); // List<ItemDTO> clusterConfigs = groupedClusterConfigs.get(clusterName);
if (clusterConfigs == null) { // if (clusterConfigs == null) {
clusterConfigs = new LinkedList<>(); // clusterConfigs = new LinkedList<>();
groupedClusterConfigs.put(clusterName, clusterConfigs); // groupedClusterConfigs.put(clusterName, clusterConfigs);
} // }
clusterConfigs.add(configItem); // clusterConfigs.add(configItem);
} // }
return groupedClusterConfigs; return groupedClusterConfigs;
} }
...@@ -227,28 +227,28 @@ public class ConfigService { ...@@ -227,28 +227,28 @@ public class ConfigService {
Map<String, AppConfigVO.OverrideAppConfig> appIdMapOverrideAppConfig = null; Map<String, AppConfigVO.OverrideAppConfig> appIdMapOverrideAppConfig = null;
for (ItemDTO config : clusterConfigs) { // for (ItemDTO config : clusterConfigs) {
String targetAppId = config.getAppId(); // String targetAppId = config.getAppId();
if (appId.equals(targetAppId)) {// app self's configs // if (appId.equals(targetAppId)) {// app self's configs
defaultClusterConfigs.add(config); // defaultClusterConfigs.add(config);
} else {// override other app configs // } else {// override other app configs
if (appIdMapOverrideAppConfig == null) { // if (appIdMapOverrideAppConfig == null) {
appIdMapOverrideAppConfig = new HashMap<>(); // appIdMapOverrideAppConfig = new HashMap<>();
} // }
//
AppConfigVO.OverrideAppConfig overrideAppConfig = // AppConfigVO.OverrideAppConfig overrideAppConfig =
appIdMapOverrideAppConfig.get(targetAppId); // appIdMapOverrideAppConfig.get(targetAppId);
//
if (overrideAppConfig == null) { // if (overrideAppConfig == null) {
overrideAppConfig = new AppConfigVO.OverrideAppConfig(); // overrideAppConfig = new AppConfigVO.OverrideAppConfig();
appIdMapOverrideAppConfig.put(targetAppId, overrideAppConfig); // appIdMapOverrideAppConfig.put(targetAppId, overrideAppConfig);
overrideAppConfigs.add(overrideAppConfig); // overrideAppConfigs.add(overrideAppConfig);
} // }
//
overrideAppConfig.setAppId(targetAppId); // overrideAppConfig.setAppId(targetAppId);
overrideAppConfig.addConfig(config); // overrideAppConfig.addConfig(config);
} // }
} // }
} }
private void collectSpecialClusterConfigs(String clusterName, List<ItemDTO> clusterConfigs, private void collectSpecialClusterConfigs(String clusterName, List<ItemDTO> clusterConfigs,
......
...@@ -187,7 +187,7 @@ public class ConfigServiceTest { ...@@ -187,7 +187,7 @@ public class ConfigServiceTest {
private ReleaseDTO assembleReleaseSnapShot(long releaseId, String clusterName, private ReleaseDTO assembleReleaseSnapShot(long releaseId, String clusterName,
String configurations) { String configurations) {
ReleaseDTO releaseSnapShot = new ReleaseDTO(); ReleaseDTO releaseSnapShot = new ReleaseDTO();
releaseSnapShot.setReleaseId(releaseId); // releaseSnapShot.setReleaseId(releaseId);
releaseSnapShot.setClusterName(clusterName); releaseSnapShot.setClusterName(clusterName);
releaseSnapShot.setConfigurations(configurations); releaseSnapShot.setConfigurations(configurations);
return releaseSnapShot; return releaseSnapShot;
...@@ -221,9 +221,9 @@ public class ConfigServiceTest { ...@@ -221,9 +221,9 @@ public class ConfigServiceTest {
private ItemDTO assembleConfigItem(long clusterId, String clusterName, String appId, private ItemDTO assembleConfigItem(long clusterId, String clusterName, String appId,
String key, String value) { String key, String value) {
ItemDTO configItem = new ItemDTO(); ItemDTO configItem = new ItemDTO();
configItem.setClusterName(clusterName); // configItem.setClusterName(clusterName);
configItem.setClusterId(clusterId); // configItem.setClusterId(clusterId);
configItem.setAppId(appId); // configItem.setAppId(appId);
configItem.setKey(key); configItem.setKey(key);
configItem.setValue(value); configItem.setValue(value);
return configItem; return configItem;
......
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