Commit 71ffb8c6 authored by lepdou's avatar lepdou

portal read config

parent 8d374626
......@@ -11,50 +11,28 @@
<artifactId>apollo-adminservice</artifactId>
<name>Apollo AdminService</name>
<dependencies>
<!-- apollo -->
<!-- apollo -->
<dependency>
<groupId>com.ctrip.apollo</groupId>
<artifactId>apollo-biz</artifactId>
</dependency>
<!-- end of apollo -->
<!-- web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- end of web -->
<!-- redis -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<!-- end of redis -->
<!-- eureka -->
<!-- end of apollo -->
<!-- redis -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<!-- end of redis -->
<!-- eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<!-- end of eureka -->
<!-- jsp -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- end of jsp -->
<!-- end of eureka -->
</dependencies>
<build>
<plugins>
......
package com.ctrip.apollo.adminservice;
package com.ctrip.apollo;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
......@@ -6,7 +6,7 @@ import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@EnableEurekaClient
//@EnableEurekaClient
public class AdminServiceApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(AdminServiceApplication.class).web(true).run(args);
......
package com.ctrip.apollo.adminservice.controller;
import com.ctrip.apollo.biz.service.AdminConfigService;
import com.ctrip.apollo.core.dto.ClusterDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/cluster")
public class ClusterController {
@Autowired
private AdminConfigService adminConfigService;
@RequestMapping("/app/{appId}")
public List<ClusterDTO> findClustersByApp(@PathVariable long appId){
return adminConfigService.findClustersByApp(appId);
}
}
package com.ctrip.apollo.adminservice.controller;
import com.ctrip.apollo.biz.service.AdminConfigService;
import com.ctrip.apollo.core.dto.ConfigItemDTO;
import com.ctrip.apollo.core.dto.ReleaseSnapshotDTO;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/configs")
public class ConfigController {
@Resource(name = "adminConfigService")
private AdminConfigService adminConfigService;
@RequestMapping("/release/{releaseId}")
public List<ReleaseSnapshotDTO> getRelaseSnapshot(@PathVariable long releaseId){
return adminConfigService.findReleaseSnapshotByReleaseId(releaseId);
}
@RequestMapping("/latest")
public List<ConfigItemDTO> findConfigItemsByClusters(@RequestParam(value = "clusterIds") List<Long> clusterIds){
return adminConfigService.findConfigItemsByClusters(clusterIds);
}
}
package com.ctrip.apollo.adminservice.controller;
import com.ctrip.apollo.biz.service.AdminConfigService;
import com.ctrip.apollo.core.dto.VersionDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/version")
public class VersionController {
@Autowired
private AdminConfigService adminConfigService;
@RequestMapping("/app/{appId}")
public List<VersionDTO> versions(@PathVariable long appId){
return adminConfigService.findVersionsByApp(appId);
}
@RequestMapping("/{versionId}")
public VersionDTO version(@PathVariable long versionId){
return adminConfigService.loadVersionById(versionId);
}
}
package com.ctrip.apollo.biz.entity;
import com.ctrip.apollo.core.dto.ClusterDTO;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
......@@ -18,8 +20,12 @@ public class Cluster {
@GeneratedValue
private long id;
@Column(nullable = false)
private String name;
@Column(nullable = false)
private long appId;
private boolean isDeleted;
public Cluster() {
......@@ -56,4 +62,12 @@ public class Cluster {
public void setDeleted(boolean deleted) {
isDeleted = deleted;
}
public ClusterDTO toDTO(){
ClusterDTO dto = new ClusterDTO();
dto.setAppId(appId);
dto.setId(id);
dto.setName(name);
return dto;
}
}
package com.ctrip.apollo.biz.entity;
import com.ctrip.apollo.core.dto.ConfigItemDTO;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Date;
@Entity
@Where(clause = "isDeleted = 0")
@SQLDelete(sql = "Update ConfigItem set isDeleted = 1 where id = ?")
public class ConfigItem {
@Id
@GeneratedValue
private long id;
@Column(nullable = false)
private long clusterId;
@Column(nullable = false)
private String clusterName;
@Column(nullable = false)
private long appId;
@Column(nullable = false)
private String key;
@Column
private String value;
@Column
private String comment;
@Column
private String dataChangeCreatedBy;
@Column
private Date dataChangeCreatedTime;
@Column
private String dataChangeLastModifiedBy;
@Column
private Date dataChangeLastModifiedTime;
@Column
private boolean IsDeleted;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getClusterId() {
return clusterId;
}
public void setClusterId(long clusterId) {
this.clusterId = clusterId;
}
public String getClusterName() {
return clusterName;
}
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}
public long getAppId() {
return appId;
}
public void setAppId(long appId) {
this.appId = appId;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getDataChangeCreatedBy() {
return dataChangeCreatedBy;
}
public void setDataChangeCreatedBy(String dataChangeCreatedBy) {
this.dataChangeCreatedBy = dataChangeCreatedBy;
}
public Date getDataChangeCreatedTime() {
return dataChangeCreatedTime;
}
public void setDataChangeCreatedTime(Date dataChangeCreatedTime) {
this.dataChangeCreatedTime = dataChangeCreatedTime;
}
public String getDataChangeLastModifiedBy() {
return dataChangeLastModifiedBy;
}
public void setDataChangeLastModifiedBy(String dataChangeLastModifiedBy) {
this.dataChangeLastModifiedBy = dataChangeLastModifiedBy;
}
public boolean isDeleted() {
return IsDeleted;
}
public void setDeleted(boolean isDeleted) {
IsDeleted = isDeleted;
}
public Date getDataChangeLastModifiedTime() {
return dataChangeLastModifiedTime;
}
public void setDataChangeLastModifiedTime(Date dataChangeLastModifiedTime) {
this.dataChangeLastModifiedTime = dataChangeLastModifiedTime;
}
public ConfigItemDTO toDTO(){
ConfigItemDTO dto = new ConfigItemDTO();
dto.setAppId(appId);
dto.setId(id);
dto.setClusterId(clusterId);
dto.setClusterName(clusterName);
dto.setDataChangeCreatedBy(dataChangeCreatedBy);
dto.setDataChangeLastModifiedBy(dataChangeLastModifiedBy);
dto.setDataChangeCreatedTime(dataChangeCreatedTime);
dto.setDataChangeLastModifiedTime(dataChangeLastModifiedTime);
dto.setKey(key);
dto.setValue(value);
dto.setComment(comment);
return dto;
}
}
package com.ctrip.apollo.biz.entity;
import com.ctrip.apollo.core.dto.ReleaseSnapshotDTO;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
......@@ -18,10 +20,15 @@ public class ReleaseSnapShot {
@GeneratedValue
private long id;
@Column(nullable = false)
private long releaseId;
@Column(nullable = false)
private String clusterName;
@Column(nullable = false)
private String configurations;
private boolean isDeleted;
public ReleaseSnapShot() {
......@@ -66,4 +73,13 @@ public class ReleaseSnapShot {
public void setDeleted(boolean deleted) {
isDeleted = deleted;
}
public ReleaseSnapshotDTO toDTO(){
ReleaseSnapshotDTO dto = new ReleaseSnapshotDTO();
dto.setId(id);
dto.setClusterName(clusterName);
dto.setConfigurations(configurations);
dto.setReleaseId(releaseId);
return dto;
}
}
package com.ctrip.apollo.biz.entity;
import com.ctrip.apollo.core.dto.VersionDTO;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
......@@ -18,9 +20,13 @@ public class Version {
@GeneratedValue
private long id;
@Column(nullable = false)
private String name;
@Column(nullable = false)
private long appId;
@Column(nullable = false)
private long releaseId;
//parent version could be null
private Long parentVersion;
......@@ -76,4 +82,14 @@ public class Version {
public void setParentVersion(Long parentVersion) {
this.parentVersion = parentVersion;
}
public VersionDTO toDTO() {
VersionDTO dto = new VersionDTO();
dto.setAppId(this.appId);
dto.setId(this.id);
dto.setName(this.name);
dto.setParentVersion(this.parentVersion);
dto.setReleaseId(this.releaseId);
return dto;
}
}
package com.ctrip.apollo.biz.repository;
import com.ctrip.apollo.biz.entity.Cluster;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface ClusterRepository extends PagingAndSortingRepository<Cluster, Long> {
List<Cluster> findByAppId(long appId);
}
package com.ctrip.apollo.biz.repository;
import com.ctrip.apollo.biz.entity.ConfigItem;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface ConfigItemRepository extends PagingAndSortingRepository<ConfigItem, Long> {
List<ConfigItem> findByClusterIdIsIn(List<Long> clusterIds);
}
......@@ -3,9 +3,13 @@ package com.ctrip.apollo.biz.repository;
import com.ctrip.apollo.biz.entity.ReleaseSnapShot;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public interface ReleaseSnapShotRepository extends PagingAndSortingRepository<ReleaseSnapShot, Long> {
ReleaseSnapShot findByReleaseIdAndClusterName(long releaseId, String clusterName);
List<ReleaseSnapShot> findByReleaseId(long releaseId);
}
......@@ -3,9 +3,15 @@ package com.ctrip.apollo.biz.repository;
import com.ctrip.apollo.biz.entity.Version;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public interface VersionRepository extends PagingAndSortingRepository<Version, Long> {
Version findByAppIdAndName(long appId, String name);
Version findById(long id);
List<Version> findByAppId(long appId);
}
package com.ctrip.apollo.biz.service;
import com.ctrip.apollo.core.dto.*;
import java.util.List;
/**
* config service for admin
*/
public interface AdminConfigService {
List<ReleaseSnapshotDTO> findReleaseSnapshotByReleaseId(long releaseId);
List<VersionDTO> findVersionsByApp(long appId);
VersionDTO loadVersionById(long versionId);
List<ClusterDTO> findClustersByApp(long appId);
List<ConfigItemDTO> findConfigItemsByClusters(List<Long> clusterIds);
}
package com.ctrip.apollo.biz.service.impl;
import com.ctrip.apollo.biz.entity.Cluster;
import com.ctrip.apollo.biz.entity.ConfigItem;
import com.ctrip.apollo.biz.entity.ReleaseSnapShot;
import com.ctrip.apollo.biz.entity.Version;
import com.ctrip.apollo.biz.repository.ClusterRepository;
import com.ctrip.apollo.biz.repository.ConfigItemRepository;
import com.ctrip.apollo.biz.repository.ReleaseSnapShotRepository;
import com.ctrip.apollo.biz.repository.VersionRepository;
import com.ctrip.apollo.biz.service.AdminConfigService;
import com.ctrip.apollo.core.dto.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
@Service("adminConfigService")
public class AdminConfigServiceImpl implements AdminConfigService {
@Autowired
private VersionRepository versionRepository;
@Autowired
private ReleaseSnapShotRepository releaseSnapShotRepository;
@Autowired
private ClusterRepository clusterRepository;
@Autowired
private ConfigItemRepository configItemRepository;
@Override
public List<ReleaseSnapshotDTO> findReleaseSnapshotByReleaseId(long releaseId) {
if (releaseId <= 0){
return Collections.EMPTY_LIST;
}
List<ReleaseSnapShot> releaseSnapShots = releaseSnapShotRepository.findByReleaseId(releaseId);
if (releaseSnapShots == null || releaseSnapShots.size() == 0){
return Collections.EMPTY_LIST;
}
List<ReleaseSnapshotDTO> result = new ArrayList<>(releaseSnapShots.size());
for (ReleaseSnapShot releaseSnapShot: releaseSnapShots){
result.add(releaseSnapShot.toDTO());
}
return result;
}
@Override
public List<VersionDTO> findVersionsByApp(long appId) {
if (appId <= 0) {
return Collections.EMPTY_LIST;
}
List<Version> versions = versionRepository.findByAppId(appId);
if (versions == null || versions.size() == 0) {
return Collections.EMPTY_LIST;
}
List<VersionDTO> result = new ArrayList<>(versions.size());
for (Version version : versions) {
result.add(version.toDTO());
}
return result;
}
@Override
public VersionDTO loadVersionById(long versionId) {
if (versionId <= 0){
return null;
}
Version version = versionRepository.findById(versionId);
return version.toDTO();
}
@Override
public List<ClusterDTO> findClustersByApp(long appId) {
if (appId <= 0){
return Collections.EMPTY_LIST;
}
List<Cluster> clusters = clusterRepository.findByAppId(appId);
if (clusters == null || clusters.size() == 0){
return Collections.EMPTY_LIST;
}
List<ClusterDTO> result = new ArrayList<>(clusters.size());
for (Cluster cluster: clusters){
result.add(cluster.toDTO());
}
return result;
}
@Override
public List<ConfigItemDTO> findConfigItemsByClusters(List<Long> clusterIds) {
if (clusterIds == null || clusterIds.size() == 0){
return Collections.EMPTY_LIST;
}
List<ConfigItem> configItems = configItemRepository.findByClusterIdIsIn(clusterIds);
if (configItems == null || configItems.size() == 0){
return Collections.EMPTY_LIST;
}
List<ConfigItemDTO> result = new ArrayList<>(configItems.size());
for (ConfigItem configItem: configItems){
result.add(configItem.toDTO());
}
return result;
}
}
INSERT INTO Cluster (AppId, IsDeleted, Name) VALUES (100, 0, 'default');
INSERT INTO Cluster (AppId, IsDeleted, Name) VALUES (101, 0, 'default');
INSERT INTO Cluster (ID, AppId, IsDeleted, Name) VALUES (100, 6666, 0, 'default-cluster-name');
INSERT INTO Cluster (ID, AppId, IsDeleted, Name) VALUES (101, 6666, 0, 'cluster1');
INSERT INTO Version (AppId, IsDeleted, Name, ReleaseId) VALUES (101, 0, '1.0', 1);
INSERT INTO Version (AppId, IsDeleted, Name, ReleaseId) VALUES (102, 0, '1.0', 2);
INSERT INTO Version (ID, AppId, IsDeleted, Name, ReleaseId) VALUES (100, 6666, 0, '1.0', 11111);
INSERT INTO Version (ID, AppId, IsDeleted, Name, ReleaseId) VALUES (101, 6666, 0, '2.0', 11112);
INSERT INTO RELEASESNAPSHOT (ClusterName, IsDeleted, ReleaseId, Configurations) VALUES ('default', 0, 1, '{"apollo.foo":"bar", "apollo.bar":"foo"}');
INSERT INTO RELEASESNAPSHOT (ClusterName, IsDeleted, ReleaseId, Configurations) VALUES ('default', 0, 2, '{"demo.foo":"demo1", "demo.bar":"demo2"}');
INSERT INTO RELEASESNAPSHOT (ClusterName, IsDeleted, ReleaseId, Configurations) VALUES ('default-cluster-name', 0, 11111, '{"6666.foo":"demo1", "6666.bar":"demo2","3333.foo":"1008","4444.bar":"99901"}');
INSERT INTO RELEASESNAPSHOT (ClusterName, IsDeleted, ReleaseId, Configurations) VALUES ('cluster1', 0, 11111, '{"6666.foo":"demo1"}');
INSERT INTO RELEASESNAPSHOT (ClusterName, IsDeleted, ReleaseId, Configurations) VALUES ('cluster2', 0, 11111, '{"6666.bar":"bar2222"}');
INSERT INTO RELEASESNAPSHOT (ClusterName, IsDeleted, ReleaseId, Configurations) VALUES ('default-cluster-name', 0, 11112, '{"6666.foo":"verson2.0", "6666.bar":"verson2.0","3333.foo":"1008","4444.bar":"99901"}');
INSERT INTO ConfigItem(ClusterId, ClusterName, AppId, Key, Value, comment, dataChangeCreatedBy, dataChangeCreatedTime, dataChangeLastModifiedBy, dataChangeLastModifiedTime, IsDeleted) VALUES (100, 'default-cluster-name', 6666, '6666.k1', '6666.v1', 'comment1', 'lepdou', '2016-03-23 12:00:00', '王五', NOW(), 0);
INSERT INTO ConfigItem(ClusterId, ClusterName, AppId, Key, Value, comment, dataChangeCreatedBy, dataChangeCreatedTime, dataChangeLastModifiedBy, dataChangeLastModifiedTime, IsDeleted) VALUES (100, 'default-cluster-name', 6666, '6666.k2', '6666.v2', 'xxxx', 'lepdou', '2016-03-23 12:00:00', '王五1', NOW(),0);
INSERT INTO ConfigItem(ClusterId, ClusterName, AppId, Key, Value, comment, dataChangeCreatedBy, dataChangeCreatedTime, dataChangeLastModifiedBy, dataChangeLastModifiedTime, IsDeleted) VALUES (100, 'default-cluster-name', 6666, '6666.k3', '6666.v3', 'yyyy', 'lepdou', '2016-03-23 12:00:00', '王五2', NOW(),0);
INSERT INTO ConfigItem(ClusterId, ClusterName, AppId, Key, Value, comment, dataChangeCreatedBy, dataChangeCreatedTime, dataChangeLastModifiedBy, dataChangeLastModifiedTime, IsDeleted) VALUES (100, 'default-cluster-name', 5555, '5555.k1', '5555.v11', 'zzzz', 'lepdou', '2016-03-23 12:00:00', '王五3', NOW(),0);
INSERT INTO ConfigItem(ClusterId, ClusterName, AppId, Key, Value, comment, dataChangeCreatedBy, dataChangeCreatedTime, dataChangeLastModifiedBy, dataChangeLastModifiedTime, IsDeleted) VALUES (101, 'cluster1', 6666, '6666.k1', '6666.v122', 'qqqqq', 'lepdou', '2016-03-23 12:00:00', '王五4', NOW(),0);
INSERT INTO RELEASESNAPSHOT (ClusterName, IsDeleted, ReleaseId, Configurations) VALUES ('default', 0, 3, '{"apollo.foo":"another bar", "apollo.bar_new":"foo"}');
......@@ -7,8 +7,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
ConfigServiceImplTest.class
})
ConfigServiceImplTest.class})
public class AllTests {
}
package com.ctrip.apollo.core;
public interface Constants {
String DEFAULT_CLUSTER_NAME = "default-cluster-name";
long LASTEST_VERSION_ID = -1;
}
package com.ctrip.apollo.core.dto;
public class ClusterDTO {
private long id;
private String name;
private long appId;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getAppId() {
return appId;
}
public void setAppId(long appId) {
this.appId = appId;
}
}
package com.ctrip.apollo.core.dto;
import java.util.Date;
public class ConfigItemDTO {
private long id;
private long clusterId;
private String clusterName;
private long appId;
private String key;
private String value;
private String comment;
private String dataChangeCreatedBy;
private Date dataChangeCreatedTime;
private String DataChangeLastModifiedBy;
private Date dataChangeLastModifiedTime;
public ConfigItemDTO(){
}
public ConfigItemDTO(String key, String value){
this.key = key;
this.value = value;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getClusterId() {
return clusterId;
}
public void setClusterId(long clusterId) {
this.clusterId = clusterId;
}
public String getClusterName() {
return clusterName;
}
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}
public long getAppId() {
return appId;
}
public void setAppId(long appId) {
this.appId = appId;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getDataChangeCreatedBy() {
return dataChangeCreatedBy;
}
public void setDataChangeCreatedBy(String dataChangeCreatedBy) {
this.dataChangeCreatedBy = dataChangeCreatedBy;
}
public Date getDataChangeCreatedTime() {
return dataChangeCreatedTime;
}
public void setDataChangeCreatedTime(Date dataChangeCreatedTime) {
this.dataChangeCreatedTime = dataChangeCreatedTime;
}
public String getDataChangeLastModifiedBy() {
return DataChangeLastModifiedBy;
}
public void setDataChangeLastModifiedBy(String dataChangeLastModifiedBy) {
DataChangeLastModifiedBy = dataChangeLastModifiedBy;
}
public Date getDataChangeLastModifiedTime() {
return dataChangeLastModifiedTime;
}
public void setDataChangeLastModifiedTime(Date dataChangeLastModifiedTime) {
this.dataChangeLastModifiedTime = dataChangeLastModifiedTime;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}
package com.ctrip.apollo.core.dto;
public class ReleaseSnapshotDTO {
private long id;
private long releaseId;
private String clusterName;
private String configurations;
public ReleaseSnapshotDTO() {
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getReleaseId() {
return releaseId;
}
public void setReleaseId(long releaseId) {
this.releaseId = releaseId;
}
public String getClusterName() {
return clusterName;
}
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}
public String getConfigurations() {
return configurations;
}
public void setConfigurations(String configurations) {
this.configurations = configurations;
}
}
package com.ctrip.apollo.core.dto;
public class VersionDTO {
private long id;
private String name;
private long appId;
private long releaseId;
private Long parentVersion;
public VersionDTO(){
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getAppId() {
return appId;
}
public void setAppId(long appId) {
this.appId = appId;
}
public long getReleaseId() {
return releaseId;
}
public void setReleaseId(long releaseId) {
this.releaseId = releaseId;
}
public Long getParentVersion() {
return parentVersion;
}
public void setParentVersion(Long parentVersion) {
this.parentVersion = parentVersion;
}
}
......@@ -37,6 +37,7 @@
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
......
package com.ctrip.apollo.portal;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
public class RestUtils {
private static RestTemplate restTemplate = new RestTemplate();
public static <T> T exchangeInGET(String url, Class<T> responseType) {
ResponseEntity<T> response =
restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<Void>((Void) null), responseType);
return response.getBody();
}
}
......@@ -28,7 +28,7 @@ public class AppController {
}
@RequestMapping("/{appid}")
public App detail(@PathVariable String appid) {
public App detail(@PathVariable long appid) {
App app = appService.detail(appid);
if (app == null) {
throw new NotFoundException();
......
package com.ctrip.apollo.portal.controller;
import com.ctrip.apollo.core.Constants;
import com.ctrip.apollo.portal.entity.AppConfigVO;
import com.ctrip.apollo.portal.exception.NotFoundException;
import com.ctrip.apollo.portal.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/configs")
public class ConfigController {
@Autowired
private ConfigService configService;
@RequestMapping("/{appId}/{env}/{versionId}")
public AppConfigVO detail(@PathVariable long appId, @PathVariable String env, @PathVariable long versionId) {
if (appId <= 0) {
throw new NotFoundException();
}
if (versionId == Constants.LASTEST_VERSION_ID) {
return configService.loadLatestConfig(appId);
} else if (versionId > 0) {
return configService.loadReleaseConfig(appId, versionId);
} else {
throw new NotFoundException();
}
}
}
package com.ctrip.apollo.portal.controller;
import com.ctrip.apollo.core.dto.VersionDTO;
import com.ctrip.apollo.portal.service.VersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/version")
public class VersionController {
@Autowired
private VersionService versionService;
@RequestMapping("/{appId}/{env}")
public List<VersionDTO> versions(@PathVariable long appId, @PathVariable String env){
return versionService.findVersionsByApp(appId, env);
}
}
......@@ -16,7 +16,7 @@ public class App implements Serializable {
private static final long serialVersionUID = 7348554309210401557L;
@Id
private String appId;
private long appId;
@Column(nullable = false)
private String name;
......@@ -36,11 +36,12 @@ public class App implements Serializable {
@Column
private Date lastUpdatedTimestamp;
public String getAppId() {
public long getAppId() {
return appId;
}
public void setAppId(String appId) {
public void setAppId(long appId) {
this.appId = appId;
}
......
package com.ctrip.apollo.portal.entity;
import com.ctrip.apollo.core.dto.ConfigItemDTO;
import com.ctrip.apollo.portal.enums.Env;
import java.util.LinkedList;
import java.util.List;
public class AppConfigVO {
private long appId;
private Env env;
/**
* latest version if version is zero, or is release version
*/
private long versionId;
/**
* default cluster and app self’s configs
*/
private List<ConfigItemDTO> defaultClusterConfigs;
/**
* default cluster and override other app configs
*/
private List<OverrideAppConfig> overrideAppConfigs;
/**
* configs in different cluster maybe different.
* overrideClusterConfigs only save diff configs from default cluster.
* For example:
* default cluster has 3 configs:
* {a -> A, b -> B, c -> C}
*
* cluster1 has 1 config
* {b -> D}
*
* if client read cluster1 configs will return {a -> A, b -> D, c -> C}
*
*
*/
private List<OverrideClusterConfig> overrideClusterConfigs;
public AppConfigVO(){
}
public static AppConfigVO newInstance(long appId, long versionId){
AppConfigVO instance = new AppConfigVO();
instance.setAppId(appId);
instance.setVersionId(versionId);
instance.setDefaultClusterConfigs(new LinkedList<>());
instance.setOverrideAppConfigs(new LinkedList<>());
instance.setOverrideClusterConfigs(new LinkedList<>());
return instance;
}
public boolean isLatestVersion() {
return versionId == 0;
}
public static class OverrideAppConfig {
private long appId;
private List<ConfigItemDTO> configs;
public OverrideAppConfig(){
}
public long getAppId() {
return appId;
}
public void setAppId(long appId) {
this.appId = appId;
}
public List<ConfigItemDTO> getConfigs() {
return configs;
}
public void setConfigs(List<ConfigItemDTO> configs) {
this.configs = configs;
}
public void addConfig(ConfigItemDTO config){
if (configs == null){
configs = new LinkedList<>();
}
configs.add(config);
}
}
public static class OverrideClusterConfig {
private String clusterName;
private List<ConfigItemDTO> configs;
public OverrideClusterConfig(){}
public String getClusterName() {
return clusterName;
}
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}
public List<ConfigItemDTO> getConfigs() {
return configs;
}
public void setConfigs(List<ConfigItemDTO> configs) {
this.configs = configs;
}
}
public long getAppId() {
return appId;
}
public void setAppId(long appId) {
this.appId = appId;
}
public Env getEnv() {
return env;
}
public void setEnv(Env env) {
this.env = env;
}
public long getVersionId() {
return versionId;
}
public void setVersionId(long versionId) {
this.versionId = versionId;
}
public List<ConfigItemDTO> getDefaultClusterConfigs() {
return defaultClusterConfigs;
}
public void setDefaultClusterConfigs(List<ConfigItemDTO> defaultClusterConfigs) {
this.defaultClusterConfigs = defaultClusterConfigs;
}
public List<OverrideAppConfig> getOverrideAppConfigs() {
return overrideAppConfigs;
}
public void setOverrideAppConfigs(List<OverrideAppConfig> overrideAppConfigs) {
this.overrideAppConfigs = overrideAppConfigs;
}
public List<OverrideClusterConfig> getOverrideClusterConfigs() {
return overrideClusterConfigs;
}
public void setOverrideClusterConfigs(List<OverrideClusterConfig> overrideClusterConfigs) {
this.overrideClusterConfigs = overrideClusterConfigs;
}
@Override
public String toString() {
return "Config4PortalDTO{" +
"appId=" + appId +
", env=" + env +
", versionId=" + versionId +
", defaultClusterConfigs=" + defaultClusterConfigs +
", overrideAppConfigs=" + overrideAppConfigs +
", overrideClusterConfigs=" + overrideClusterConfigs +
'}';
}
}
......@@ -26,7 +26,7 @@ public class Privilege implements Serializable {
private String privilType;
@Column
private String appId;
private long appId;
public long getId() {
return id;
......@@ -52,11 +52,11 @@ public class Privilege implements Serializable {
this.privilType = privilType;
}
public String getAppId() {
public long getAppId() {
return appId;
}
public void setAppId(String appId) {
public void setAppId(long appId) {
this.appId = appId;
}
}
package com.ctrip.apollo.portal.enums;
public enum Env {
DEV("dev"), FWS("fws"), FAT("fat"), UAT("uat"), LPT("lpt"), PROD("prod"), TOOLS("tools"), UN_KNOW("");
private String value;
Env(String value) {
this.value = value;
}
public static Env valueFrom(String env) {
if (env == null || "".equals(env)) {
return UN_KNOW;
} else if ("dev".equals(env)) {
return DEV;
} else if ("fws".equals(env)) {
return FWS;
} else if ("fat".equals(env)) {
return FAT;
} else if ("uat".equals(env)) {
return UAT;
} else if ("prod".equals(env)) {
return PROD;
} else if ("tools".equals(env)) {
return TOOLS;
} else{
return UN_KNOW;
}
}
}
......@@ -9,4 +9,6 @@ import com.ctrip.apollo.portal.entity.App;
public interface AppRepository extends PagingAndSortingRepository<App, String> {
Page<App> findAll(Pageable pageable);
App findByAppId(long appId);
}
......@@ -8,9 +8,9 @@ import com.ctrip.apollo.portal.entity.Privilege;
public interface PrivilegeRepository extends PagingAndSortingRepository<Privilege, Long> {
List<Privilege> findByAppId(String appId);
List<Privilege> findByAppId(long appId);
List<Privilege> findByAppIdAndPrivilType(String appId, String privilType);
List<Privilege> findByAppIdAndPrivilType(long appId, String privilType);
Privilege findByAppIdAndNameAndPrivilType(String appId, String name, String privilType);
Privilege findByAppIdAndNameAndPrivilType(long appId, String name, String privilType);
}
......@@ -16,8 +16,8 @@ public class AppService {
@Autowired
private AppRepository appRepository;
public App detail(String appId) {
return appRepository.findOne(appId);
public App detail(long appId) {
return appRepository.findByAppId(appId);
}
public Page<App> list(Pageable pageable) {
......
package com.ctrip.apollo.portal.service;
import com.ctrip.apollo.portal.entity.AppConfigVO;
public interface ConfigService {
/**
* load config info by appId and versionId
* @param appId
* @param versionId
* @return
*/
AppConfigVO loadReleaseConfig(long appId, long versionId);
/**
*
* @param appId
* @return
*/
AppConfigVO loadLatestConfig(long appId);
}
......@@ -19,7 +19,7 @@ public class PrivilegeService {
@Autowired
private PrivilegeRepository privilRepo;
public Privilege addPrivilege(String appId, String name, PrivilType privilType) {
public Privilege addPrivilege(long appId, String name, PrivilType privilType) {
Privilege privil = privilRepo.findByAppIdAndNameAndPrivilType(appId, name, privilType.name());
if (privil == null) {
privil = new Privilege();
......@@ -31,16 +31,16 @@ public class PrivilegeService {
return privil;
}
public boolean hasPrivilege(String appId, String name, PrivilType privilType) {
public boolean hasPrivilege(long appId, String name, PrivilType privilType) {
Privilege privil = privilRepo.findByAppIdAndNameAndPrivilType(appId, name, privilType.name());
return (privil != null) ? true : false;
}
public List<Privilege> listPrivileges(String appId) {
public List<Privilege> listPrivileges(long appId) {
return privilRepo.findByAppId(appId);
}
public void removePrivilege(String appId, String name, PrivilType privilType) {
public void removePrivilege(long appId, String name, PrivilType privilType) {
Privilege privil = privilRepo.findByAppIdAndNameAndPrivilType(appId, name, privilType.name());
if (privil == null) {
throw new NotFoundException();
......
package com.ctrip.apollo.portal.service;
import com.ctrip.apollo.core.dto.VersionDTO;
import com.ctrip.apollo.portal.RestUtils;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class VersionService {
public List<VersionDTO> findVersionsByApp(long appId, String env){
return RestUtils.exchangeInGET("http://localhost:8090/version/app/" + appId, List.class);
}
}
package com.ctrip.apollo.portal.service.impl;
import com.ctrip.apollo.core.Constants;
import com.ctrip.apollo.core.dto.*;
import com.ctrip.apollo.portal.RestUtils;
import com.ctrip.apollo.portal.entity.AppConfigVO;
import com.ctrip.apollo.portal.service.ConfigService;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.*;
@Service
public class ConfigServiceImpl implements ConfigService {
public static final String ADMIN_SERVICE_HOST = "http://localhost:8090";
private ObjectMapper objectMapper = new ObjectMapper();
@Override
public AppConfigVO loadReleaseConfig(long appId, long versionId) {
if (appId <= 0 || versionId <= 0) {
return null;
}
long releaseId = getReleaseIdFromVersionId(versionId);
ReleaseSnapshotDTO[] releaseSnapShots = RestUtils.exchangeInGET(
ADMIN_SERVICE_HOST + "/configs/release/" + releaseId, ReleaseSnapshotDTO[].class);
if (releaseSnapShots == null || releaseSnapShots.length == 0) {
return null;
}
AppConfigVO appConfigVO = AppConfigVO.newInstance(appId, versionId);
for (ReleaseSnapshotDTO snapShot : releaseSnapShots) {
//default cluster
if (Constants.DEFAULT_CLUSTER_NAME.equals(snapShot.getClusterName())) {
collectDefaultClusterConfigs(appId, snapShot, appConfigVO);
} else {//cluster special configs
collectSpecialClusterConfigs(appId, snapShot, appConfigVO);
}
}
return appConfigVO;
}
private long getReleaseIdFromVersionId(long versionId) {
VersionDTO version =
RestUtils.exchangeInGET(ADMIN_SERVICE_HOST + "/version/" + versionId, VersionDTO.class);
if (version == null) {
return -1;
}
return version.getReleaseId();
}
private void collectDefaultClusterConfigs(long appId, ReleaseSnapshotDTO snapShot, AppConfigVO appConfigVO) {
Map<Long, List<ConfigItemDTO>> groupedConfigs =
groupConfigsByApp(snapShot.getConfigurations());
List<AppConfigVO.OverrideAppConfig> overrideAppConfigs =
appConfigVO.getOverrideAppConfigs();
for (Map.Entry<Long, List<ConfigItemDTO>> entry : groupedConfigs.entrySet()) {
long configAppId = entry.getKey();
List<ConfigItemDTO> kvs = entry.getValue();
if (configAppId == appId) {
appConfigVO.setDefaultClusterConfigs(kvs);
} else {
AppConfigVO.OverrideAppConfig overrideAppConfig =
new AppConfigVO.OverrideAppConfig();
overrideAppConfig.setAppId(configAppId);
overrideAppConfig.setConfigs(kvs);
overrideAppConfigs.add(overrideAppConfig);
}
}
}
/**
* appId -> List<KV>
*/
private Map<Long, List<ConfigItemDTO>> groupConfigsByApp(String configJson) {
if (configJson == null || "".equals(configJson)) {
return Maps.newHashMap();
}
Map<Long, List<ConfigItemDTO>> appIdMapKVs = new HashMap<>();
String key;
Object value;
Map<String, String> kvMaps = null;
try {
kvMaps = objectMapper.readValue(configJson, Map.class);
} catch (IOException e) {
//todo log
}
for (Map.Entry<String, String> entry : kvMaps.entrySet()) {
key = entry.getKey();
value = entry.getValue();
Long appId = getAppIdFromKey(key);
List<ConfigItemDTO> kvs = appIdMapKVs.get(appId);
if (kvs == null) {
kvs = new LinkedList<>();
appIdMapKVs.put(appId, kvs);
}
kvs.add(new ConfigItemDTO(key, value.toString()));
}
return appIdMapKVs;
}
private Long getAppIdFromKey(String key) {
return Long.valueOf(key.substring(0, key.indexOf(".")));
}
private void collectSpecialClusterConfigs(long appId, ReleaseSnapshotDTO snapShot, AppConfigVO appConfigVO) {
List<AppConfigVO.OverrideClusterConfig> overrideClusterConfigs =
appConfigVO.getOverrideClusterConfigs();
AppConfigVO.OverrideClusterConfig overrideClusterConfig =
new AppConfigVO.OverrideClusterConfig();
overrideClusterConfig.setClusterName(snapShot.getClusterName());
//todo step1: cluster special config can't override other app config
overrideClusterConfig.setConfigs(groupConfigsByApp(snapShot.getConfigurations()).get(appId));
overrideClusterConfigs.add(overrideClusterConfig);
}
@Override
public AppConfigVO loadLatestConfig(long appId) {
if (appId <= 0) {
return null;
}
ClusterDTO[] clusters = RestUtils.exchangeInGET(
ADMIN_SERVICE_HOST + "/cluster/app/" + appId, ClusterDTO[].class);
if (clusters == null || clusters.length == 0) {
return null;
}
StringBuilder sb = new StringBuilder();
for (ClusterDTO cluster : clusters) {
sb.append(cluster.getId()).append(",");
}
ConfigItemDTO[] configItems = RestUtils.exchangeInGET(
ADMIN_SERVICE_HOST + "/configs/latest?clusterIds=" + sb.substring(0,
sb.length() - 1), ConfigItemDTO[].class);
return buildAPPConfigVO(appId, Arrays.asList(configItems));
}
private AppConfigVO buildAPPConfigVO(long appId, List<ConfigItemDTO> configItems) {
if (configItems == null || configItems.size() == 0) {
return null;
}
Map<String, List<ConfigItemDTO>> groupedClusterConfigs = groupConfigByCluster(configItems);
AppConfigVO appConfigVO =
AppConfigVO.newInstance(appId, Constants.LASTEST_VERSION_ID);
groupConfigByAppAndEnrichDTO(groupedClusterConfigs, appConfigVO);
return appConfigVO;
}
private Map<String, List<ConfigItemDTO>> groupConfigByCluster(List<ConfigItemDTO> configItems) {
Map<String, List<ConfigItemDTO>> groupedClusterConfigs = new HashMap<>();
String clusterName;
for (ConfigItemDTO configItem : configItems) {
clusterName = configItem.getClusterName();
List<ConfigItemDTO> clusterConfigs = groupedClusterConfigs.get(clusterName);
if (clusterConfigs == null) {
clusterConfigs = new LinkedList<>();
groupedClusterConfigs.put(clusterName, clusterConfigs);
}
clusterConfigs.add(configItem);
}
return groupedClusterConfigs;
}
private void groupConfigByAppAndEnrichDTO(Map<String, List<ConfigItemDTO>> groupedClusterConfigs, AppConfigVO appConfigVO) {
long appId = appConfigVO.getAppId();
List<ConfigItemDTO> defaultClusterConfigs = appConfigVO.getDefaultClusterConfigs();
List<AppConfigVO.OverrideAppConfig> overrideAppConfigs =
appConfigVO.getOverrideAppConfigs();
List<AppConfigVO.OverrideClusterConfig> overrideClusterConfigs =
appConfigVO.getOverrideClusterConfigs();
String clusterName;
List<ConfigItemDTO> clusterConfigs;
for (Map.Entry<String, List<ConfigItemDTO>> entry : groupedClusterConfigs.entrySet()) {
clusterName = entry.getKey();
clusterConfigs = entry.getValue();
if (Constants.DEFAULT_CLUSTER_NAME.equals(clusterName)) {
//default cluster configs
collectDefaultClusterConfigs(appId, clusterConfigs, defaultClusterConfigs, overrideAppConfigs);
} else {
//override cluster configs
collectSpecialClusterConfigs(clusterName, clusterConfigs, overrideClusterConfigs);
}
}
}
private void collectDefaultClusterConfigs(long appId, List<ConfigItemDTO> clusterConfigs, List<ConfigItemDTO> defaultClusterConfigs, List<AppConfigVO.OverrideAppConfig> overrideAppConfigs) {
Map<Long, AppConfigVO.OverrideAppConfig> appIdMapOverrideAppConfig = null;
for (ConfigItemDTO config : clusterConfigs) {
long targetAppId = config.getAppId();
if (appId == targetAppId) {//app self's configs
defaultClusterConfigs.add(config);
} else {//override other app configs
if (appIdMapOverrideAppConfig == null) {
appIdMapOverrideAppConfig = new HashMap<>();
}
AppConfigVO.OverrideAppConfig overrideAppConfig =
appIdMapOverrideAppConfig.get(targetAppId);
if (overrideAppConfig == null) {
overrideAppConfig = new AppConfigVO.OverrideAppConfig();
appIdMapOverrideAppConfig.put(targetAppId, overrideAppConfig);
overrideAppConfigs.add(overrideAppConfig);
}
overrideAppConfig.setAppId(targetAppId);
overrideAppConfig.addConfig(config);
}
}
}
private void collectSpecialClusterConfigs(String clusterName, List<ConfigItemDTO> clusterConfigs, List<AppConfigVO.OverrideClusterConfig> overrideClusterConfigs) {
AppConfigVO.OverrideClusterConfig overrideClusterConfig =
new AppConfigVO.OverrideClusterConfig();
overrideClusterConfig.setClusterName(clusterName);
overrideClusterConfig.setConfigs(clusterConfigs);
overrideClusterConfigs.add(overrideClusterConfig);
}
}
......@@ -6,6 +6,9 @@ spring:
name: apollo-portal
datasource:
url: jdbc:h2:mem:~/fxapolloportaldb
jpa:
hibernate:
naming_strategy: org.hibernate.cfg.EJB3NamingStrategy
logging:
level:
......
INSERT INTO App(appId, name,owner, ownerPhone, ownerMail, createTimestamp, lastUpdatedTimestamp) VALUES (6666,'apollo', 'lepdou', '18722435754', 'zhanglea@ctrip.com', NOW(),NOW());
application_module.controller("AppConfigController",
['$scope', '$rootScope', '$state', '$location', 'toastr',
'AppService', 'ConfigService', 'VersionService',
function ($scope, $rootScope, $state, $location, toastr, AppService, ConfigService, VersionService) {
application_module.controller("AppConfigController", ["$scope", '$state', '$location', 'AppService',
function ($scope, $state, $location, AppService) {
var configLocation = {
appId: $rootScope.appId,
env: 'uat',
versionId: -1
};
//model定义
$scope.env = {
fat: false,
uat: true,
product: false
$rootScope.breadcrumb.nav = '配置';
$rootScope.breadcrumb.env = configLocation.env;
};
$scope.configLocation = configLocation;
//mock data
$scope.config = {
baseConfigs: [
{
key: 'pageSize',
value: 10,
lastUpdateTime: '2016-01-14'
},
{
key: 'pageCount',
value: 20,
lastUpdateTime: '2016-01-14'
}
],
overrideConfigs: [
{
project: 'cat',
configs: [
{
key: 'pageSize',
value: 10,
lastUpdateTime: '2016-01-14'
},
{
key: 'pageCount',
value: 20,
lastUpdateTime: '2016-01-14'
}
]
},
{
project: 'hermas',
configs: [
{
key: 'pageSize',
value: 20,
lastUpdateTime: '2016-01-14'
},
{
key: 'pageCount',
value: 30,
lastUpdateTime: '2016-01-14'
}
]
}
]
};
/**env*/
$scope.envs = ['dev', 'fws', 'fat', 'uat', 'lpt', 'prod', 'tools'];
$scope.switchEnv = function (env) {
clearEnvNav();
if ('fat' == env) {
switchToFat();
} else if ('uat' == env) {
switchToUat();
} else if ('product' == env) {
switchToProduct();
}
$scope.switchEnv = function (selectedEnv) {
configLocation.env = selectedEnv;
$rootScope.breadcrumb.env = configLocation.env;
refreshConfigs();
};
};
function switchToFat() {
$scope.env.fat = true;
}
/**version*/
$scope.releaseVersions = [];
$scope.currentVersionIsRelease = false;
function switchToUat() {
$scope.env.uat = true;
}
VersionService.load(configLocation.appId, configLocation.env).then(function (result) {
$scope.releaseVersions = result;
}, function (result) {
toastr.error("获取版本失败", result);
});
function switchToProduct() {
$scope.env.product = true;
}
$scope.switchVersion = function (versionId) {
configLocation.versionId = versionId;
$scope.currentVersionIsRelease = configLocation.versionId > 0;
refreshConfigs();
};
function clearEnvNav() {
$scope.env = {
fat: false,
uat: false,
product: false
/**config*/
refreshConfigs();
//refresh app config infomations
function refreshConfigs() {
ConfigService.load(configLocation.appId, configLocation.env, configLocation.versionId).then(function (result) {
$scope.config = result;
};
}
$scope.showClusterConfigs = false;
if (result.overrideClusterConfigs && result.overrideClusterConfigs[0]) {
$scope.showClusterConfigs = true;
//default selected
$scope.config.selectedCluster = result.overrideClusterConfigs[0];
$scope.config.selectedClusterKVs = result.overrideClusterConfigs[0].configs;
//build map clusterName -> configs for switch cluster
$scope.config.overrideClusters = {};
$.each(result.overrideClusterConfigs, function (index, value) {
$scope.config.overrideClusters[value.clusterName] = value.configs;
});
}
}, function (result) {
toastr.error("加载配置出错", result);
});
}
//switch cluster
$scope.selectCluster = function () {
$scope.config.selectedClusterKVs = $scope.config.overrideClusters[$scope.config.selectedCluster.clusterName];
};
}]);
}]);
application_module.controller("AppInfoController", ["$scope", '$state', '$location', 'toastr', 'AppService',
function ($scope, $state, $location, toastr, AppService) {
$scope.appId = $location.$$url.split("=")[1];
application_module.controller("AppInfoController", ["$scope", '$rootScope', '$state', '$location', 'toastr', 'AppService',
function ($scope, $rootScope, $state, $location, toastr, AppService) {
$rootScope.breadcrumb.nav = '应用信息';
$rootScope.breadcrumb.env = '';
AppService.load($scope.appId).then(function (result) {
$scope.app = result;
}, function(result){
}, function (result) {
toastr.error("加载出错");
});
......
//page context ctl
application_module.controller("AppPageController", ['$rootScope', '$location',
function ($rootScope, $location) {
$rootScope.appId = $location.$$url.split("=")[1];
if(!$rootScope.appId){
$rootScope.appId = 6666;
}
$rootScope.breadcrumb = {
project: '6666-apollo',
nav: '配置',
env: 'uat'
}
}]);
appService.service("ConfigService", ['$resource', '$q', function ($resource, $q) {
var config_source = $resource("/configs/:appId/:env/:versionId", {}, {
load_config: {
method: 'GET',
isArray: false
}
});
return {
load: function (appId, env, versionId) {
var d = $q.defer();
config_source.load_config({
appId: appId,
env: env,
versionId: versionId
}, function (result) {
d.resolve(result);
}, function (result) {
de.reject(result);
});
return d.promise;
}
}
}]);
appService.service("VersionService", ['$resource', '$q', function ($resource, $q) {
var config_source = $resource("/version/:appId/:env", {}, {
load_config: {
method: 'GET',
isArray: true
}
});
return {
load: function (appId, env) {
var d = $q.defer();
config_source.load_config({
appId: appId,
env: env
}, function (result) {
d.resolve(result);
}, function (result) {
d.reject(result);
});
return d.promise;
}
}
}]);
......@@ -28,7 +28,7 @@ body {
/*sec-panel*/
.sec-panel {
padding-left: 5%;
/*padding-left: 5%;*/
}
.sec-panel .panel-heading {
......
......@@ -15,9 +15,11 @@
<div ng-include="'../common/nav.html'"></div>
<div class="container">
<div class="container-fluid">
<div class="app">
<div class="app" ng-controller="AppPageController">
<ol class="breadcrumb">
<li>10024-hotel.service</li>
<li >{{breadcrumb.project}}</li>
<li>{{breadcrumb.nav}}</li>
<li ng-show="breadcrumb.env">{{breadcrumb.env}}</li>
<!--<li>1.0</li>-->
<!--<li>default</li>-->
</ol>
......@@ -57,12 +59,12 @@
<!--biz script-->
<script type="application/javascript" src="../../scripts/app.js"></script>
<script type="application/javascript"
src="../../scripts/services/AppService.js"></script>
<script type="application/javascript"
src="../../scripts/controller/app/AppConfigController.js"></script>
<script type="application/javascript"
src="../../scripts/controller/app/AppInfoController.js"></script>
<script type="application/javascript" src="../../scripts/services/AppService.js"></script>
<script type="application/javascript" src="../../scripts/services/ConfigService.js"></script>
<script type="application/javascript" src="../../scripts/services/VersionService.js"></script>
<script type="application/javascript" src="../../scripts/controller/app/AppConfigController.js"></script>
<script type="application/javascript" src="../../scripts/controller/app/AppInfoController.js"></script>
<script type="application/javascript" src="../../scripts/controller/app/AppPageController.js"></script>
</body>
</html>
......@@ -3,7 +3,7 @@
<div class="panel">
<div class="panel-body">
<form class="form-horizontal" ng-controller="AppInfoController">
<form class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label">应用ID:</label>
<label class="col-sm-3 control-label text-left">
......
package com.ctrip.apollo.portal;
import com.ctrip.apollo.portal.service.ConfigServiceTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
......@@ -9,8 +10,7 @@ import com.ctrip.apollo.portal.repository.AppRepositoryTest;
import com.ctrip.apollo.portal.service.PrivilegeServiceTest;
@RunWith(Suite.class)
@SuiteClasses({AppControllerTest.class, AppRepositoryTest.class, PrivilegeServiceTest.class,
@SuiteClasses({AppControllerTest.class, AppRepositoryTest.class, PrivilegeServiceTest.class, ConfigServiceTest.class
})
public class AllTests {
......
......@@ -32,7 +32,7 @@ public class AppControllerTest extends AbstractPortalTest {
@Test
public void testCreate() throws URISyntaxException {
App newApp = new App();
newApp.setAppId(String.valueOf(System.currentTimeMillis()));
newApp.setAppId(System.currentTimeMillis());
newApp.setName("new app " + System.currentTimeMillis());
newApp.setOwner("owner " + System.currentTimeMillis());
......@@ -43,7 +43,7 @@ public class AppControllerTest extends AbstractPortalTest {
Assert.assertNull(newApp.getCreateTimestamp());
Assert.assertNotNull(createdApp.getCreateTimestamp());
App foundApp = appRepository.findOne(newApp.getAppId());
App foundApp = appRepository.findByAppId(newApp.getAppId());
Assert.assertEquals(newApp.getAppId(), foundApp.getAppId());
}
......@@ -51,7 +51,7 @@ public class AppControllerTest extends AbstractPortalTest {
@Test
public void testList() throws URISyntaxException {
App newApp = new App();
newApp.setAppId(String.valueOf(System.currentTimeMillis()));
newApp.setAppId(System.currentTimeMillis());
newApp.setName("new app " + System.currentTimeMillis());
newApp.setOwner("owner " + System.currentTimeMillis());
appRepository.save(newApp);
......@@ -66,7 +66,7 @@ public class AppControllerTest extends AbstractPortalTest {
@Test
public void testListOutOfRange() throws URISyntaxException {
App newApp = new App();
newApp.setAppId(String.valueOf(System.currentTimeMillis()));
newApp.setAppId(System.currentTimeMillis());
newApp.setName("new app " + System.currentTimeMillis());
newApp.setOwner("owner " + System.currentTimeMillis());
appRepository.save(newApp);
......
......@@ -18,7 +18,7 @@ public class AppRepositoryTest extends AbstractPortalTest{
Assert.assertEquals(0, repository.count());
App ramdomApp = new App();
ramdomApp.setAppId(String.valueOf(System.currentTimeMillis()));
ramdomApp.setAppId(System.currentTimeMillis());
ramdomApp.setName("new app " + System.currentTimeMillis());
ramdomApp.setOwner("owner " + System.currentTimeMillis());
repository.save(ramdomApp);
......
......@@ -21,7 +21,7 @@ public class PrivilegeServiceTest extends AbstractPortalTest {
@Test
public void testAddAndRemovePrivilege() {
App newApp = new App();
newApp.setAppId(String.valueOf(System.currentTimeMillis()));
newApp.setAppId((System.currentTimeMillis()));
newApp.setName("new app " + System.currentTimeMillis());
newApp.setOwner("owner " + System.currentTimeMillis());
appService.save(newApp);
......@@ -42,7 +42,7 @@ public class PrivilegeServiceTest extends AbstractPortalTest {
@Test
public void testCheckPrivilege() {
App newApp = new App();
newApp.setAppId(String.valueOf(System.currentTimeMillis()));
newApp.setAppId((System.currentTimeMillis()));
newApp.setName("new app " + System.currentTimeMillis());
newApp.setOwner("owner " + System.currentTimeMillis());
appService.save(newApp);
......
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