Commit 85f2ff01 authored by Jason Song's avatar Jason Song

Merge pull request #59 from yiming187/entity

Entity and Biz Refactor
parents 60f5869a 98b4c848
package com.ctrip.apollo.adminservice.controller;
import com.ctrip.apollo.biz.service.AdminConfigService;
import com.ctrip.apollo.biz.service.AdminReleaseService;
import com.ctrip.apollo.core.dto.ConfigItemDTO;
import com.ctrip.apollo.core.dto.ReleaseSnapshotDTO;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -11,27 +8,26 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import com.ctrip.apollo.biz.entity.App;
import com.ctrip.apollo.biz.service.AppService;
import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.AppDTO;
@RestController
@RequestMapping("/configs")
public class ConfigController {
public class AppController {
@Autowired
private AdminConfigService adminConfigService;
@Autowired
private AdminReleaseService adminReleaseService;
private AppService appService;
@RequestMapping("/release/{releaseId}")
public List<ReleaseSnapshotDTO> getRelaseSnapshot(@PathVariable long releaseId) {
return adminReleaseService.findReleaseSnapshotByReleaseId(releaseId);
@RequestMapping("/apps/{appId}")
public AppDTO findByAppId(@PathVariable("appId") String appId) {
App app = appService.findByAppId(appId);
return BeanUtils.transfrom(AppDTO.class, app);
}
@RequestMapping("/latest")
public List<ConfigItemDTO> findConfigItemsByClusters(
@RequestParam(value = "clusterIds") List<Long> clusterIds) {
return adminConfigService.findConfigItemsByClusters(clusterIds);
@RequestMapping("/apps")
public List<AppDTO> findByName(@RequestParam("name") String name) {
List<App> app = appService.findByName(name);
return BeanUtils.batchTransform(AppDTO.class, app);
}
}
package com.ctrip.apollo.adminservice.controller;
import com.ctrip.apollo.biz.service.AdminConfigService;
import com.ctrip.apollo.core.dto.ClusterDTO;
import java.util.List;
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;
import com.ctrip.apollo.biz.entity.Cluster;
import com.ctrip.apollo.biz.service.ViewService;
import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.ClusterDTO;
@RestController
@RequestMapping("/cluster")
public class ClusterController {
@Autowired
private AdminConfigService adminConfigService;
private ViewService viewService;
@RequestMapping("/app/{appId}")
public List<ClusterDTO> findClustersByApp(@PathVariable String appId) {
return adminConfigService.findClustersByApp(appId);
@RequestMapping("/apps/{appId}/clusters")
public List<ClusterDTO> findClusters(@PathVariable("appId") String appId) {
List<Cluster> clusters = viewService.findClusters(appId);
return BeanUtils.batchTransform(ClusterDTO.class, clusters);
}
}
package com.ctrip.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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ctrip.apollo.biz.entity.Group;
import com.ctrip.apollo.biz.service.GroupService;
import com.ctrip.apollo.biz.service.ViewService;
import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.GroupDTO;
@RestController
public class GroupController {
@Autowired
private ViewService viewService;
@Autowired
private GroupService groupService;
@RequestMapping("/apps/{appId}/clusters/{clusterName}/groups")
public List<GroupDTO> findGroups(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName) {
List<Group> groups = viewService.findGroups(appId, clusterName);
return BeanUtils.batchTransform(GroupDTO.class, groups);
}
@RequestMapping("/groups/{groupId}")
public GroupDTO findOne(@PathVariable("groupId") Long groupId) {
Group group = groupService.findOne(groupId);
return BeanUtils.transfrom(GroupDTO.class, group);
}
}
package com.ctrip.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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ctrip.apollo.biz.entity.Item;
import com.ctrip.apollo.biz.service.ItemService;
import com.ctrip.apollo.biz.service.ViewService;
import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.ItemDTO;
@RestController
public class ItemController {
@Autowired
private ViewService viewService;
@Autowired
private ItemService itemService;
@RequestMapping("/apps/{appId}/clusters/{clusterName}/groups/{groupName}/items")
public List<ItemDTO> findItems(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName,
@PathVariable("groupName") String groupName) {
List<Item> items = viewService.findItems(appId, clusterName,groupName);
return BeanUtils.batchTransform(ItemDTO.class, items);
}
@RequestMapping("/items/{itemId}")
public ItemDTO findOne(@PathVariable("itemId") long itemId) {
Item item = itemService.findOne(itemId);
return BeanUtils.transfrom(ItemDTO.class, item);
}
}
package com.ctrip.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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ctrip.apollo.biz.entity.Release;
import com.ctrip.apollo.biz.service.ReleaseService;
import com.ctrip.apollo.biz.service.ViewService;
import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.ReleaseDTO;
@RestController
public class ReleaseController {
@Autowired
private ViewService viewSerivce;
@Autowired
private ReleaseService releaseService;
@RequestMapping("/release/{releaseId}")
public ReleaseDTO findOne(@PathVariable("releaseId") long releaseId) {
Release release = releaseService.findOne(releaseId);
return BeanUtils.transfrom(ReleaseDTO.class, release);
}
@RequestMapping("/apps/{appId}/clusters/{clusterId}/groups/{groupId}/releases")
public List<ReleaseDTO> findReleases(@PathVariable("groupId") Long groupId){
List<Release> releases = viewSerivce.findReleases(groupId);
return BeanUtils.batchTransform(ReleaseDTO.class, releases);
}
}
package com.ctrip.apollo.adminservice.controller;
import com.ctrip.apollo.biz.service.AdminReleaseService;
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 AdminReleaseService adminReleaseService;
@RequestMapping("/app/{appId}")
public List<VersionDTO> versions(@PathVariable String appId) {
return adminReleaseService.findVersionsByApp(appId);
}
@RequestMapping("/{versionId}")
public VersionDTO version(@PathVariable long versionId) {
return adminReleaseService.loadVersionById(versionId);
}
}
package com.ctrip.apollo.biz.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import org.hibernate.annotations.SQLDelete;
@Entity
@SQLDelete(sql = "Update App set isDeleted = 1 where id = ?")
public class App extends BaseEntity {
@Column(nullable = false)
private String name;
@Column(nullable = false)
private String appId;
@Column(nullable = false)
private String ownerName;
@Column(nullable = false)
private String ownerEmail;
public String getAppId() {
return appId;
}
public String getName() {
return name;
}
public String getOwnerEmail() {
return ownerEmail;
}
public String getOwnerName() {
return ownerName;
}
public void setAppId(String appId) {
this.appId = appId;
}
public void setName(String name) {
this.name = name;
}
public void setOwnerEmail(String ownerEmail) {
this.ownerEmail = ownerEmail;
}
public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}
}
package com.ctrip.apollo.biz.entity;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
import org.hibernate.annotations.Where;
@Where(clause = "isDeleted = 0")
@SQLDelete(sql = "Update ConfigItem set isDeleted = 1 where id = ?")
public class ConfigItem {
public abstract class BaseEntity {
@Id
@GeneratedValue
private long id;
@Column(nullable = false)
private long clusterId;
@Column(nullable = false)
private String clusterName;
@Column(nullable = false)
private String appId;
@Column(nullable = false)
private String key;
@Column
private String value;
@Column
private String comment;
private boolean isDeleted;
@Column(name = "DataChange_CreatedBy")
private String dataChangeCreatedBy;
......@@ -49,103 +29,51 @@ public class ConfigItem {
@Column(name = "DataChange_LastTime")
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 String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
public String getDataChangeCreatedBy() {
return dataChangeCreatedBy;
}
public String getValue() {
return value;
public Date getDataChangeCreatedTime() {
return dataChangeCreatedTime;
}
public void setValue(String value) {
this.value = value;
public String getDataChangeLastModifiedBy() {
return dataChangeLastModifiedBy;
}
public String getComment() {
return comment;
public Date getDataChangeLastModifiedTime() {
return dataChangeLastModifiedTime;
}
public void setComment(String comment) {
this.comment = comment;
public long getId() {
return id;
}
public String getDataChangeCreatedBy() {
return dataChangeCreatedBy;
public boolean isDeleted() {
return isDeleted;
}
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 void setDataChangeLastModifiedTime(Date dataChangeLastModifiedTime) {
this.dataChangeLastModifiedTime = dataChangeLastModifiedTime;
}
public Date getDataChangeLastModifiedTime() {
return dataChangeLastModifiedTime;
public void setDeleted(boolean deleted) {
isDeleted = deleted;
}
public void setDataChangeLastModifiedTime(Date dataChangeLastModifiedTime) {
this.dataChangeLastModifiedTime = dataChangeLastModifiedTime;
public void setId(long id) {
this.id = id;
}
}
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;
import org.hibernate.annotations.SQLDelete;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Entity
@Where(clause = "isDeleted = 0")
@SQLDelete(sql = "Update Cluster set isDeleted = 1 where id = ?")
public class Cluster {
@Id
@GeneratedValue
private long id;
public class Cluster extends BaseEntity {
@Column(nullable = false)
private String name;
......@@ -27,48 +18,20 @@ public class Cluster {
@Column(nullable = false)
private String appId;
private boolean isDeleted;
public Cluster() {
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
public String getAppId() {
return appId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public boolean isDeleted() {
return isDeleted;
}
public void setDeleted(boolean deleted) {
isDeleted = deleted;
public void setName(String name) {
this.name = name;
}
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 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;
/**
* @author Jason Song(song_s@ctrip.com)
*/
import org.hibernate.annotations.SQLDelete;
@Entity
@Where(clause = "isDeleted = 0")
@SQLDelete(sql = "Update Version set isDeleted = 1 where id = ?")
public class Version {
@Id
@GeneratedValue
private long id;
@SQLDelete(sql = "Update Group set isDeleted = 1 where id = ?")
public class Group extends BaseEntity {
@Column(nullable = false)
private String name;
......@@ -26,60 +16,52 @@ public class Version {
private String appId;
@Column(nullable = false)
private long releaseId;
//parent version could be null
private Long parentVersion;
private boolean isDeleted;
private long clusterId;
@Column(nullable = false)
private String clusterName;
public Version() {
@Column(nullable = false)
private long namespaceId;
public String getAppId() {
return appId;
}
public long getId() {
return id;
public long getClusterId() {
return clusterId;
}
public void setId(long id) {
this.id = id;
public String getClusterName() {
return clusterName;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAppId() {
return appId;
public long getNamespaceId() {
return namespaceId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public long getReleaseId() {
return releaseId;
public void setClusterId(long clusterId) {
this.clusterId = clusterId;
}
public void setReleaseId(long releaseId) {
this.releaseId = releaseId;
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}
public boolean isDeleted() {
return isDeleted;
}
public void setDeleted(boolean deleted) {
isDeleted = deleted;
}
public Long getParentVersion() {
return parentVersion;
public void setName(String name) {
this.name = name;
}
public void setParentVersion(Long parentVersion) {
this.parentVersion = parentVersion;
public void setNamespaceId(long namespaceId) {
this.namespaceId = namespaceId;
}
}
package com.ctrip.apollo.biz.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import org.hibernate.annotations.SQLDelete;
@Entity
@SQLDelete(sql = "Update Item set isDeleted = 1 where id = ?")
public class Item extends BaseEntity {
@Column(nullable = false)
private long groupId;
@Column(nullable = false)
private String key;
@Column
private String value;
@Column
private String comment;
public long getGroupId() {
return groupId;
}
public void setGroupId(long groupId) {
this.groupId = groupId;
}
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;
}
}
package com.ctrip.apollo.biz.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import org.hibernate.annotations.SQLDelete;
@Entity
@SQLDelete(sql = "Update Namespace set isDeleted = 1 where id = ?")
public class Namespace extends BaseEntity{
@Column(nullable = false)
private String name;
@Column(nullable = false)
private String appId;
@Column
private String comment;
public String getAppId() {
return appId;
}
public String getComment() {
return comment;
}
public String getName() {
return name;
}
public void setAppId(String appId) {
this.appId = appId;
}
public void setComment(String comment) {
this.comment = comment;
}
public void setName(String name) {
this.name = name;
}
}
package com.ctrip.apollo.biz.entity;
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 javax.persistence.Lob;
import org.hibernate.annotations.SQLDelete;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Entity
@Where(clause = "isDeleted = 0")
@SQLDelete(sql = "Update Release set isDeleted = 1 where id = ?")
public class Release {
@Id
@GeneratedValue
private long id;
public class Release extends BaseEntity {
@Column(nullable = false)
private String name;
@Column(nullable = false)
private String appId;
@Column(nullable = false)
private String clusterName;
@Column
private String groupName;
@Column(nullable = false)
@Lob
private String configurations;
@Column(nullable = false)
private String comment;
private boolean isDeleted;
public Release() {
public String getAppId() {
return appId;
}
public long getId() {
return id;
public String getClusterName() {
return clusterName;
}
public void setId(long id) {
this.id = id;
public String getComment() {
return comment;
}
public String getName() {
return name;
public String getConfigurations() {
return configurations;
}
public void setName(String name) {
this.name = name;
public String getGroupName() {
return groupName;
}
public String getAppId() {
return appId;
public String getName() {
return name;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getComment() {
return comment;
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}
public void setComment(String comment) {
this.comment = comment;
}
public boolean isDeleted() {
return isDeleted;
public void setConfigurations(String configurations) {
this.configurations = configurations;
}
public void setDeleted(boolean deleted) {
isDeleted = deleted;
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public void setName(String name) {
this.name = name;
}
}
package com.ctrip.apollo.biz.entity;
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;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Entity
@Where(clause = "isDeleted = 0")
@SQLDelete(sql = "Update ReleaseSnapShot set isDeleted = 1 where id = ?")
public class ReleaseSnapshot {
@Id
@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() {
}
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;
}
public boolean isDeleted() {
return isDeleted;
}
public void setDeleted(boolean deleted) {
isDeleted = deleted;
}
}
package com.ctrip.apollo.biz.repository;
import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import com.ctrip.apollo.biz.entity.App;
public interface AppRepository extends PagingAndSortingRepository<App, Long> {
@Query("SELECT a from App a WHERE a.name LIKE %':name'%")
List<App> findByName(@Param("name") String name);
App findByAppId(String appId);
}
......@@ -11,4 +11,5 @@ public interface ClusterRepository extends PagingAndSortingRepository<Cluster, L
List<Cluster> findByAppId(String appId);
Cluster findByAppIdAndName(String appId, String name);
}
package com.ctrip.apollo.biz.repository;
import com.ctrip.apollo.biz.entity.Version;
import java.util.List;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
import com.ctrip.apollo.biz.entity.Group;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public interface VersionRepository extends PagingAndSortingRepository<Version, Long> {
Version findByAppIdAndName(String appId, String name);
public interface GroupRepository extends PagingAndSortingRepository<Group, Long> {
Version findById(long id);
List<Group> findByAppIdAndClusterName(String appId, String clusterName);
List<Version> findByAppId(String appId);
Group findByAppIdAndClusterNameAndGroupName(String appId, String clusterName, String groupName);
}
package com.ctrip.apollo.biz.repository;
import com.ctrip.apollo.biz.entity.ConfigItem;
import com.ctrip.apollo.biz.entity.Item;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface ConfigItemRepository extends PagingAndSortingRepository<ConfigItem, Long> {
public interface ItemRepository extends PagingAndSortingRepository<Item, Long> {
List<ConfigItem> findByClusterIdIsIn(List<Long> clusterIds);
List<Item> findByGroupIdIsIn(List<Long> groupIds);
List<Item> findByGroupId(Long groupId);
}
package com.ctrip.apollo.biz.repository;
import org.springframework.data.repository.PagingAndSortingRepository;
import com.ctrip.apollo.biz.entity.Namespace;
public interface NamespaceRepository extends PagingAndSortingRepository<Namespace, Long>{
}
package com.ctrip.apollo.biz.repository;
import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import com.ctrip.apollo.biz.entity.Release;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public interface ReleaseRepository extends PagingAndSortingRepository<Release, Long> {
@Query("SELECT r FROM Release r WHERE r.appId = :appId AND r.clusterName = :clusterName AND r.groupName = :groupName order by id desc litmit 1")
Release findLatest(@Param("appId") String appId, @Param("clusterName") String clusterName,
@Param("groupName") String groupName);
List<Release> findByGroupId(Long groupId);
}
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);
}
package com.ctrip.apollo.biz.service;
import com.google.common.base.Strings;
import com.ctrip.apollo.biz.entity.ReleaseSnapshot;
import com.ctrip.apollo.biz.entity.Version;
import com.ctrip.apollo.biz.repository.ReleaseSnapShotRepository;
import com.ctrip.apollo.biz.repository.VersionRepository;
import com.ctrip.apollo.biz.utils.ApolloBeanUtils;
import com.ctrip.apollo.core.dto.ReleaseSnapshotDTO;
import com.ctrip.apollo.core.dto.VersionDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Service("adminReleaseService")
public class AdminReleaseService {
@Autowired
private ReleaseSnapShotRepository releaseSnapShotRepository;
@Autowired
private VersionRepository versionRepository;
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;
}
return ApolloBeanUtils.batchTransform(ReleaseSnapshotDTO.class, releaseSnapShots);
}
public List<VersionDTO> findVersionsByApp(String appId) {
if (Strings.isNullOrEmpty(appId)) {
return Collections.EMPTY_LIST;
}
List<Version> versions = versionRepository.findByAppId(appId);
if (versions == null || versions.size() == 0) {
return Collections.EMPTY_LIST;
}
return ApolloBeanUtils.batchTransform(VersionDTO.class, versions);
}
public VersionDTO loadVersionById(long versionId) {
if (versionId <= 0) {
return null;
}
Version version = versionRepository.findById(versionId);
if (version == null) {
return null;
}
VersionDTO dto = ApolloBeanUtils.transfrom(VersionDTO.class, version);
return dto;
}
}
package com.ctrip.apollo.biz.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import com.ctrip.apollo.biz.entity.App;
import com.ctrip.apollo.biz.repository.AppRepository;
@Service
public class AppService {
@Autowired
private AppRepository appRepository;
public App save(App entity){
return appRepository.save(entity);
}
public List<App> findAll(Pageable pageable){
Page<App> page = appRepository.findAll(pageable);
return page.getContent();
}
public List<App> findByName(String name){
return appRepository.findByName(name);
}
public App findByAppId(String appId){
return appRepository.findByAppId(appId);
}
}
package com.ctrip.apollo.biz.service;
import com.google.common.collect.Maps;
import com.ctrip.apollo.biz.entity.ReleaseSnapshot;
import com.ctrip.apollo.biz.entity.Version;
import com.ctrip.apollo.biz.repository.ReleaseSnapShotRepository;
import com.ctrip.apollo.biz.repository.VersionRepository;
import com.ctrip.apollo.core.dto.ApolloConfig;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.Map;
import com.ctrip.apollo.biz.entity.Release;
import com.ctrip.apollo.biz.repository.ReleaseRepository;
import com.ctrip.apollo.core.dto.ApolloConfig;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Maps;
/**
* Config Service
*
* @author Jason Song(song_s@ctrip.com)
*/
@Service("configService")
@Service
public class ConfigService {
@Autowired
private VersionRepository versionRepository;
@Autowired
private ReleaseSnapShotRepository releaseSnapShotRepository;
private ReleaseRepository releaseRepository;
@Autowired
private ObjectMapper objectMapper;
private TypeReference<Map<String, Object>> configurationTypeReference =
new TypeReference<Map<String, Object>>() {
};
/**
* Load configuration from database
*/
public ApolloConfig loadConfig(String appId, String clusterName, String versionName) {
Version version = loadVersionByAppIdAndVersionName(appId, versionName);
if (version == null) {
return null;
}
return loadConfigByVersionAndClusterName(version, clusterName);
}
private TypeReference<Map<String, Object>> configurationTypeReference =
new TypeReference<Map<String, Object>>() {};
/**
* Load Version by appId and versionName from database
*/
public Version loadVersionByAppIdAndVersionName(String appId, String versionName) {
return versionRepository.findByAppIdAndName(appId, versionName);
public Release findRelease(String appId, String clusterName, String groupName) {
Release release = releaseRepository.findLatest(appId, clusterName, groupName);
return release;
}
/**
* Load Config by version and clusterName from database
* Load configuration from database
*/
public ApolloConfig loadConfigByVersionAndClusterName(Version version, String clusterName) {
ReleaseSnapshot releaseSnapShot =
releaseSnapShotRepository
.findByReleaseIdAndClusterName(version.getReleaseId(), clusterName);
if (releaseSnapShot == null) {
public ApolloConfig loadConfig(Release release, String groupName, String versionName) {
if (release == null) {
return null;
}
return assembleConfig(version, releaseSnapShot);
}
private ApolloConfig assembleConfig(Version version, ReleaseSnapshot releaseSnapShot) {
ApolloConfig config =
new ApolloConfig(version.getAppId(), releaseSnapShot.getClusterName(), version.getName(),
version.getReleaseId());
config.setConfigurations(transformConfigurationToMap(releaseSnapShot.getConfigurations()));
ApolloConfig config = new ApolloConfig(release.getAppId(), release.getClusterName(), groupName,
versionName, release.getId());
config.setConfigurations(transformConfigurationToMap(release.getConfigurations()));
return config;
}
......
package com.ctrip.apollo.biz.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ctrip.apollo.biz.entity.Group;
import com.ctrip.apollo.biz.repository.GroupRepository;
@Service
public class GroupService {
@Autowired
private GroupRepository groupRepository;
public Group findOne(Long groupId){
return groupRepository.findOne(groupId);
}
}
package com.ctrip.apollo.biz.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ctrip.apollo.biz.entity.Item;
import com.ctrip.apollo.biz.repository.ItemRepository;
@Service
public class ItemService {
@Autowired
private ItemRepository itemRepository;
public Item findOne(long itemId) {
Item item = itemRepository.findOne(itemId);
return item;
}
}
package com.ctrip.apollo.biz.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ctrip.apollo.biz.entity.Release;
import com.ctrip.apollo.biz.repository.ReleaseRepository;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Service
public class ReleaseService {
@Autowired
private ReleaseRepository releaseRepository;
public Release findOne(long releaseId) {
Release release = releaseRepository.findOne(releaseId);
return release;
}
}
package com.ctrip.apollo.biz.service;
import com.google.common.base.Strings;
import com.ctrip.apollo.biz.entity.Cluster;
import com.ctrip.apollo.biz.entity.ConfigItem;
import com.ctrip.apollo.biz.repository.ClusterRepository;
import com.ctrip.apollo.biz.repository.ConfigItemRepository;
import com.ctrip.apollo.biz.utils.ApolloBeanUtils;
import com.ctrip.apollo.core.dto.ClusterDTO;
import com.ctrip.apollo.core.dto.ConfigItemDTO;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
import com.ctrip.apollo.biz.entity.Cluster;
import com.ctrip.apollo.biz.entity.Group;
import com.ctrip.apollo.biz.entity.Item;
import com.ctrip.apollo.biz.entity.Release;
import com.ctrip.apollo.biz.repository.ClusterRepository;
import com.ctrip.apollo.biz.repository.GroupRepository;
import com.ctrip.apollo.biz.repository.ItemRepository;
import com.ctrip.apollo.biz.repository.ReleaseRepository;
import com.google.common.base.Strings;
/**
* config service for admin
*/
@Service("adminConfigService")
public class AdminConfigService {
@Service
public class ViewService {
@Autowired
private ClusterRepository clusterRepository;
@Autowired
private ConfigItemRepository configItemRepository;
private GroupRepository groupRepository;
@Autowired
private ItemRepository itemRepository;
@Autowired
private ReleaseRepository releaseRepository;
public List<ClusterDTO> findClustersByApp(String appId) {
public List<Cluster> findClusters(String appId) {
if (Strings.isNullOrEmpty(appId)) {
return Collections.EMPTY_LIST;
}
List<Cluster> clusters = clusterRepository.findByAppId(appId);
if (clusters == null || clusters.size() == 0) {
if (clusters == null) {
return Collections.EMPTY_LIST;
}
return clusters;
}
return ApolloBeanUtils.batchTransform(ClusterDTO.class, clusters);
public List<Group> findGroups(String appId, String clusterName) {
List<Group> groups = groupRepository.findByAppIdAndClusterName(appId, clusterName);
if (groups == null) {
return Collections.EMPTY_LIST;
}
return groups;
}
public List<ConfigItemDTO> findConfigItemsByClusters(List<Long> clusterIds) {
if (clusterIds == null || clusterIds.size() == 0) {
public List<Item> findItems(String appId, String clusterName, String groupName) {
Group group =
groupRepository.findByAppIdAndClusterNameAndGroupName(appId, clusterName, groupName);
if (group != null) {
return findItems(group.getId());
} else {
return Collections.EMPTY_LIST;
}
List<ConfigItem> configItems = configItemRepository.findByClusterIdIsIn(clusterIds);
if (configItems == null || configItems.size() == 0) {
}
public List<Item> findItems(Long groupId) {
List<Item> items = itemRepository.findByGroupId(groupId);
if (items == null) {
return Collections.EMPTY_LIST;
}
return items;
}
return ApolloBeanUtils.batchTransform(ConfigItemDTO.class, configItems);
public List<Release> findReleases(Long groupId) {
List<Release> releases = releaseRepository.findByGroupId(groupId);
if (releases == null) {
return Collections.EMPTY_LIST;
}
return releases;
}
}
......@@ -14,7 +14,7 @@ import java.util.Map;
import java.util.Set;
public class ApolloBeanUtils {
public class BeanUtils {
/**
* <pre>
......
package com.ctrip.apollo.biz.service;
import com.google.common.collect.Maps;
import com.ctrip.apollo.biz.entity.ReleaseSnapshot;
import com.ctrip.apollo.biz.entity.Version;
import com.ctrip.apollo.biz.repository.ReleaseSnapShotRepository;
import com.ctrip.apollo.biz.repository.VersionRepository;
import com.ctrip.apollo.biz.entity.Release;
import com.ctrip.apollo.biz.repository.ReleaseRepository;
import com.ctrip.apollo.biz.service.ConfigService;
import com.ctrip.apollo.core.dto.ApolloConfig;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -22,7 +18,6 @@ import java.io.IOException;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.anyObject;
import static org.mockito.Mockito.eq;
......@@ -36,9 +31,7 @@ import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class ConfigServiceTest {
@Mock
private VersionRepository versionRepository;
@Mock
private ReleaseSnapShotRepository releaseSnapShotRepository;
private ReleaseRepository releaseRepository;
@Mock
private ObjectMapper objectMapper;
private ConfigService configService;
......@@ -46,90 +39,91 @@ public class ConfigServiceTest {
@Before
public void setUp() throws Exception {
configService = new ConfigService();
ReflectionTestUtils.setField(configService, "versionRepository", versionRepository);
ReflectionTestUtils
.setField(configService, "releaseSnapShotRepository", releaseSnapShotRepository);
.setField(configService, "releaseRepository", releaseRepository);
ReflectionTestUtils.setField(configService, "objectMapper", objectMapper);
}
@Test
public void testLoadConfig() throws Exception {
String someAppId = "1";
String someClusterName = "someClusterName";
String someVersionName = "someVersionName";
long someReleaseId = 1;
String someValidConfiguration = "{\"apollo.bar\": \"foo\"}";
Version someVersion = assembleVersion(someAppId, someVersionName, someReleaseId);
ReleaseSnapshot
someReleaseSnapShot =
assembleReleaseSnapShot(someReleaseId, someClusterName, someValidConfiguration);
Map<String, Object> someMap = Maps.newHashMap();
when(versionRepository.findByAppIdAndName(someAppId, someVersionName)).thenReturn(someVersion);
when(releaseSnapShotRepository.findByReleaseIdAndClusterName(someReleaseId, someClusterName))
.thenReturn(someReleaseSnapShot);
when(objectMapper.readValue(eq(someValidConfiguration), (TypeReference) anyObject()))
.thenReturn(someMap);
ApolloConfig result = configService.loadConfig(someAppId, someClusterName, someVersionName);
assertEquals(someAppId, result.getAppId());
assertEquals(someClusterName, result.getCluster());
assertEquals(someVersionName, result.getVersion());
assertEquals(someReleaseId, result.getReleaseId());
assertEquals(someMap, result.getConfigurations());
}
@Test
public void testLoadConfigWithVersionNotFound() throws Exception {
String someAppId = "1";
String someClusterName = "someClusterName";
String someVersionName = "someVersionName";
when(versionRepository.findByAppIdAndName(someAppId, someVersionName)).thenReturn(null);
ApolloConfig result = configService.loadConfig(someAppId, someClusterName, someVersionName);
assertNull(result);
verify(versionRepository, times(1)).findByAppIdAndName(someAppId, someVersionName);
}
@Test
public void testLoadConfigWithConfigNotFound() throws Exception {
String someAppId = "1";
String someClusterName = "someClusterName";
String someVersionName = "someVersionName";
long someReleaseId = 1;
Version someVersion = assembleVersion(someAppId, someVersionName, someReleaseId);
when(versionRepository.findByAppIdAndName(someAppId, someVersionName)).thenReturn(someVersion);
when(releaseSnapShotRepository.findByReleaseIdAndClusterName(someReleaseId, someClusterName))
.thenReturn(null);
ApolloConfig result = configService.loadConfig(someAppId, someClusterName, someVersionName);
assertNull(result);
verify(versionRepository, times(1)).findByAppIdAndName(someAppId, someVersionName);
verify(releaseSnapShotRepository, times(1))
.findByReleaseIdAndClusterName(someReleaseId, someClusterName);
}
private Version assembleVersion(String appId, String versionName, long releaseId) {
Version version = new Version();
version.setAppId(appId);
version.setName(versionName);
version.setReleaseId(releaseId);
return version;
}
private ReleaseSnapshot assembleReleaseSnapShot(long releaseId, String clusterName,
// @Test
// public void testLoadConfig() throws Exception {
// String someAppId = "1";
// String someClusterName = "someClusterName";
// String someGroupName = "someGroupName";
// String someVersionName = "someVersionName";
// long someReleaseId = 1;
// String someValidConfiguration = "{\"apollo.bar\": \"foo\"}";
//
// Version someVersion = assembleVersion(someAppId, someVersionName, someReleaseId);
// Release
// someRelease =
// assembleRelease(someReleaseId, someClusterName, someGroupName, someValidConfiguration);
// Map<String, Object> someMap = Maps.newHashMap();
//
// when(versionRepository.findByAppIdAndName(someAppId, someVersionName)).thenReturn(someVersion);
// when(releaseRepository.findByReleaseIdAndClusterName(someReleaseId, someClusterName))
// .thenReturn(someReleaseSnapShot);
// when(objectMapper.readValue(eq(someValidConfiguration), (TypeReference) anyObject()))
// .thenReturn(someMap);
//
// ApolloConfig result = configService.loadConfig(someAppId, someClusterName, someVersionName);
//
// assertEquals(someAppId, result.getAppId());
// assertEquals(someClusterName, result.getCluster());
// assertEquals(someVersionName, result.getVersion());
// assertEquals(someReleaseId, result.getReleaseId());
// assertEquals(someMap, result.getConfigurations());
// }
//
// @Test
// public void testLoadConfigWithVersionNotFound() throws Exception {
// String someAppId = "1";
// String someClusterName = "someClusterName";
// String someVersionName = "someVersionName";
//
// when(versionRepository.findByAppIdAndName(someAppId, someVersionName)).thenReturn(null);
//
// ApolloConfig result = configService.loadConfig(someAppId, someClusterName, someVersionName);
//
// assertNull(result);
// verify(versionRepository, times(1)).findByAppIdAndName(someAppId, someVersionName);
// }
//
// @Test
// public void testLoadConfigWithConfigNotFound() throws Exception {
// String someAppId = "1";
// String someClusterName = "someClusterName";
// String someVersionName = "someVersionName";
// long someReleaseId = 1;
// Version someVersion = assembleVersion(someAppId, someVersionName, someReleaseId);
//
// when(versionRepository.findByAppIdAndName(someAppId, someVersionName)).thenReturn(someVersion);
// when(releaseRepository.findByReleaseIdAndClusterName(someReleaseId, someClusterName))
// .thenReturn(null);
//
// ApolloConfig result = configService.loadConfig(someAppId, someClusterName, someVersionName);
//
// assertNull(result);
// verify(versionRepository, times(1)).findByAppIdAndName(someAppId, someVersionName);
// verify(releaseRepository, times(1))
// .findByReleaseIdAndClusterName(someReleaseId, someClusterName);
// }
//
// private Version assembleVersion(String appId, String versionName, long releaseId) {
// Version version = new Version();
// version.setAppId(appId);
// version.setName(versionName);
// version.setReleaseId(releaseId);
// return version;
// }
private Release assembleRelease(long releaseId, String clusterName, String groupName,
String configurations) {
ReleaseSnapshot releaseSnapShot = new ReleaseSnapshot();
releaseSnapShot.setReleaseId(releaseId);
releaseSnapShot.setClusterName(clusterName);
releaseSnapShot.setConfigurations(configurations);
return releaseSnapShot;
Release release = new Release();
release.setId(releaseId);
release.setClusterName(clusterName);
release.setGroupName(groupName);
release.setConfigurations(configurations);
return release;
}
......
......@@ -197,10 +197,11 @@ public class ConfigLoaderManagerTest {
ApolloConfig assembleApolloConfig(String appId, Map<String, Object> configurations) {
String someCluster = "someCluster";
String someGroup = "someGroup";
String someVersion = "someVersion";
long someReleaseId = 1;
ApolloConfig config = new ApolloConfig(appId, someCluster, someVersion, someReleaseId);
ApolloConfig config = new ApolloConfig(appId, someCluster, someGroup, someVersion, someReleaseId);
config.setConfigurations(configurations);
......
package com.ctrip.apollo.configservice.controller;
import com.ctrip.apollo.biz.entity.Version;
import com.ctrip.apollo.biz.service.ConfigService;
import com.ctrip.apollo.core.dto.ApolloConfig;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -11,9 +11,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import com.ctrip.apollo.biz.entity.Release;
import com.ctrip.apollo.biz.service.ConfigService;
import com.ctrip.apollo.core.dto.ApolloConfig;
/**
* @author Jason Song(song_s@ctrip.com)
......@@ -24,32 +24,31 @@ public class ConfigController {
@Autowired
private ConfigService configService;
@RequestMapping(value = "/{appId}/{clusterName}/{versionName:.*}", method = RequestMethod.GET)
public ApolloConfig queryConfig(@PathVariable String appId,
@PathVariable String clusterName,
@PathVariable String versionName,
@RequestMapping(value = "/{appId}/{clusterName}/{groupName}/{versionName:.*}", method = RequestMethod.GET)
public ApolloConfig queryConfig(@PathVariable String appId, @PathVariable String clusterName,
@PathVariable String groupName, @PathVariable String versionName,
@RequestParam(value = "releaseId", defaultValue = "-1") long clientSideReleaseId,
HttpServletResponse response) throws IOException {
Version version = configService.loadVersionByAppIdAndVersionName(appId, versionName);
if (version == null) {
Release release = configService.findRelease(appId, clusterName, groupName);
if (release == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND,
String.format("Could not load version with appId: %s, versionName: %s", appId,
versionName));
String.format(
"Could not load version with appId: %s, clusterName: %s, groupName: %s, versionName: %s",
appId, clusterName, groupName, versionName));
return null;
}
if (version.getReleaseId() == clientSideReleaseId) {
//Client side configuration is the same with server side, return 304
if (release.getId() == clientSideReleaseId) {
// Client side configuration is the same with server side, return 304
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return null;
}
ApolloConfig apolloConfig =
configService.loadConfigByVersionAndClusterName(version, clusterName);
ApolloConfig apolloConfig = configService.loadConfig(release, groupName, versionName);
if (apolloConfig == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND,
String.format("Could not load config with releaseId: %d, clusterName: %s",
version.getReleaseId(), clusterName));
release.getId(), clusterName));
return null;
}
......
package com.ctrip.apollo.configservice.controller;
import com.ctrip.apollo.biz.entity.Version;
import com.ctrip.apollo.biz.entity.Release;
import com.ctrip.apollo.biz.service.ConfigService;
import com.ctrip.apollo.core.dto.ApolloConfig;
......@@ -39,104 +39,94 @@ public class ConfigControllerTest {
ReflectionTestUtils.setField(configController, "configService", configService);
}
@Test
public void testQueryConfig() throws Exception {
ApolloConfig someApolloConfig = mock(ApolloConfig.class);
String someAppId = "1";
String someClusterName = "someClusterName";
String someVersionName = "someVersion";
long someClientSideReleaseId = 1;
long someServerSideNewReleaseId = 2;
HttpServletResponse someResponse = mock(HttpServletResponse.class);
Version someVersion = mock(Version.class);
when(configService.loadVersionByAppIdAndVersionName(someAppId, someVersionName))
.thenReturn(someVersion);
when(someVersion.getReleaseId()).thenReturn(someServerSideNewReleaseId);
when(configService.loadConfigByVersionAndClusterName(someVersion, someClusterName))
.thenReturn(someApolloConfig);
ApolloConfig
result =
configController
.queryConfig(someAppId, someClusterName, someVersionName, someClientSideReleaseId,
someResponse);
assertEquals(someApolloConfig, result);
verify(configService, times(1)).loadVersionByAppIdAndVersionName(someAppId, someVersionName);
verify(configService, times(1)).loadConfigByVersionAndClusterName(someVersion, someClusterName);
}
@Test
public void testQueryConfigWithVersionNotFound() throws Exception {
String someAppId = "1";
String someClusterName = "someClusterName";
String someVersionName = "someVersion";
long someClientSideReleaseId = 1;
HttpServletResponse someResponse = mock(HttpServletResponse.class);
when(configService.loadVersionByAppIdAndVersionName(someAppId, someVersionName))
.thenReturn(null);
ApolloConfig
result =
configController
.queryConfig(someAppId, someClusterName, someVersionName, someClientSideReleaseId,
someResponse);
assertNull(result);
verify(someResponse, times(1)).sendError(eq(HttpServletResponse.SC_NOT_FOUND), anyString());
}
@Test
public void testQueryConfigWithApolloConfigNotFound() throws Exception {
String someAppId = "1";
String someClusterName = "someClusterName";
String someVersionName = "someVersion";
long someClientSideReleaseId = 1;
long someServerSideNewReleaseId = 2;
HttpServletResponse someResponse = mock(HttpServletResponse.class);
Version someVersion = mock(Version.class);
when(configService.loadVersionByAppIdAndVersionName(someAppId, someVersionName))
.thenReturn(someVersion);
when(someVersion.getReleaseId()).thenReturn(someServerSideNewReleaseId);
when(configService.loadConfigByVersionAndClusterName(someVersion, someClusterName))
.thenReturn(null);
ApolloConfig
result =
configController
.queryConfig(someAppId, someClusterName, someVersionName, someClientSideReleaseId,
someResponse);
assertNull(result);
verify(someResponse, times(1)).sendError(eq(HttpServletResponse.SC_NOT_FOUND), anyString());
}
@Test
public void testQueryConfigWithApolloConfigNotModified() throws Exception {
String someAppId = "1";
String someClusterName = "someClusterName";
String someVersionName = "someVersion";
long someClientSideReleaseId = 1;
long someServerSideReleaseId = someClientSideReleaseId;
HttpServletResponse someResponse = mock(HttpServletResponse.class);
Version someVersion = mock(Version.class);
when(configService.loadVersionByAppIdAndVersionName(someAppId, someVersionName))
.thenReturn(someVersion);
when(someVersion.getReleaseId()).thenReturn(someServerSideReleaseId);
ApolloConfig
result =
configController
.queryConfig(someAppId, someClusterName, someVersionName, someClientSideReleaseId,
someResponse);
assertNull(result);
verify(someResponse, times(1)).setStatus(HttpServletResponse.SC_NOT_MODIFIED);
verify(configService, never())
.loadConfigByVersionAndClusterName(any(Version.class), anyString());
}
// @Test
// public void testQueryConfig() throws Exception {
// ApolloConfig someApolloConfig = mock(ApolloConfig.class);
// String someAppId = "1";
// String someClusterName = "someClusterName";
// String someGroupName = "someGroupName";
// long someClientSideReleaseId = 1;
// long someServerSideNewReleaseId = 2;
// HttpServletResponse someResponse = mock(HttpServletResponse.class);
// Release someRelease = mock(Release.class);
//
// when(configService.findRelease(someAppId, someClusterName, someGroupName))
// .thenReturn(someRelease);
// when(someRelease.getId()).thenReturn(someServerSideNewReleaseId);
// when(configService.loadConfig(someRelease, someGroupName))
// .thenReturn(someApolloConfig);
//
// ApolloConfig result = configController.queryConfig(someAppId, someClusterName, someGroupName,
// someClientSideReleaseId, someResponse);
//
// assertEquals(someApolloConfig, result);
// verify(configService, times(1)).findRelease(someAppId, someClusterName, someGroupName
// someVersinName);
// verify(configService, times(1)).loadConfig(someRelease, someGroupName,);
// }
//
// @Test
// public void testQueryConfigWithVersionNotFound() throws Exception {
// String someAppId = "1";
// String someClusterName = "someClusterName";
// String someGroupName = "someGroupName";
// String someVersionName = "someVersion";
// long someClientSideReleaseId = 1;
// HttpServletResponse someResponse = mock(HttpServletResponse.class);
//
// when(configService.findRelease(someAppId, someClusterName, someGroupName, someVersionName))
// .thenReturn(null);
//
// ApolloConfig result = configController.queryConfig(someAppId, someClusterName, someGroupName,
// someVersionName, someClientSideReleaseId, someResponse);
//
// assertNull(result);
// verify(someResponse, times(1)).sendError(eq(HttpServletResponse.SC_NOT_FOUND), anyString());
// }
//
// @Test
// public void testQueryConfigWithApolloConfigNotFound() throws Exception {
// String someAppId = "1";
// String someClusterName = "someClusterName";
// String someGroupName = "someGroupName";
// String someVersionName = "someVersion";
// long someClientSideReleaseId = 1;
// long someServerSideNewReleaseId = 2;
// HttpServletResponse someResponse = mock(HttpServletResponse.class);
// Release someRelease = mock(Release.class);
//
// when(configService.findRelease(someAppId, someClusterName, someGroupName, someVersionName))
// .thenReturn(someRelease);
// when(someRelease.getId()).thenReturn(someServerSideNewReleaseId);
// when(configService.loadConfig(someRelease, someGroupName, someVersionName)).thenReturn(null);
//
// ApolloConfig result = configController.queryConfig(someAppId, someClusterName, someGroupName,
// someVersionName, someClientSideReleaseId, someResponse);
//
// assertNull(result);
// verify(someResponse, times(1)).sendError(eq(HttpServletResponse.SC_NOT_FOUND), anyString());
// }
//
// @Test
// public void testQueryConfigWithApolloConfigNotModified() throws Exception {
// String someAppId = "1";
// String someClusterName = "someClusterName";
// String someGroupName = "someGroupName";
// String someVersionName = "someVersion";
// long someClientSideReleaseId = 1;
// long someServerSideReleaseId = someClientSideReleaseId;
// HttpServletResponse someResponse = mock(HttpServletResponse.class);
// Release someRelease = mock(Release.class);
//
// when(configService.findRelease(someAppId, someClusterName, someGroupName, someVersionName))
// .thenReturn(someRelease);
// when(someRelease.getId()).thenReturn(someServerSideReleaseId);
//
// ApolloConfig result = configController.queryConfig(someAppId, someClusterName, someGroupName,
// someVersionName, someClientSideReleaseId, someResponse);
//
// assertNull(result);
// verify(someResponse, times(1)).setStatus(HttpServletResponse.SC_NOT_MODIFIED);
// verify(configService, never()).loadConfig(any(Release.class), anyString(), anyString());
// }
}
......@@ -16,6 +16,8 @@ public class ApolloConfig implements Comparable<ApolloConfig> {
private String cluster;
private String group;
private String version;
private Map<String, Object> configurations;
......@@ -27,21 +29,26 @@ public class ApolloConfig implements Comparable<ApolloConfig> {
@JsonCreator
public ApolloConfig(@JsonProperty("appId") String appId,
@JsonProperty("cluster") String cluster,
@JsonProperty("group") String group,
@JsonProperty("version") String version,
@JsonProperty("releaseId") long releaseId) {
super();
this.appId = appId;
this.cluster = cluster;
this.group = group;
this.version = version;
this.releaseId = releaseId;
}
public Map<String, Object> getConfigurations() {
return configurations;
@Override
public int compareTo(ApolloConfig toCompare) {
if (toCompare == null || this.getOrder() > toCompare.getOrder()) {
return 1;
}
public void setConfigurations(Map<String, Object> configurations) {
this.configurations = configurations;
if (toCompare.getOrder() > this.getOrder()) {
return -1;
}
return 0;
}
public String getAppId() {
......@@ -52,18 +59,34 @@ public class ApolloConfig implements Comparable<ApolloConfig> {
return cluster;
}
public String getVersion() {
return version;
public Map<String, Object> getConfigurations() {
return configurations;
}
public long getReleaseId() {
return releaseId;
public String getGroup() {
return group;
}
public int getOrder() {
return order;
}
public long getReleaseId() {
return releaseId;
}
public String getVersion() {
return version;
}
public void setConfigurations(Map<String, Object> configurations) {
this.configurations = configurations;
}
public void setGroup(String group) {
this.group = group;
}
public void setOrder(int order) {
this.order = order;
}
......@@ -74,20 +97,10 @@ public class ApolloConfig implements Comparable<ApolloConfig> {
.omitNullValues()
.add("appId", appId)
.add("cluster", cluster)
.add("group", group)
.add("version", version)
.add("releaseId", releaseId)
.add("configurations", configurations)
.toString();
}
@Override
public int compareTo(ApolloConfig toCompare) {
if (toCompare == null || this.getOrder() > toCompare.getOrder()) {
return 1;
}
if (toCompare.getOrder() > this.getOrder()) {
return -1;
}
return 0;
}
}
package com.ctrip.apollo.core.dto;
public class AppDTO {
private String name;
private String appId;
private String ownerName;
private String ownerEmail;
public String getAppId() {
return appId;
}
public String getName() {
return name;
}
public String getOwnerEmail() {
return ownerEmail;
}
public String getOwnerName() {
return ownerName;
}
public void setAppId(String appId) {
this.appId = appId;
}
public void setName(String name) {
this.name = name;
}
public void setOwnerEmail(String ownerEmail) {
this.ownerEmail = ownerEmail;
}
public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}
}
package com.ctrip.apollo.core.dto;
public class GroupDTO {
private long id;
private long clusterId;
private long namespaceId;
private String name;
public long getClusterId() {
return clusterId;
}
public long getId() {
return id;
}
public String getName() {
return name;
}
public long getNamespaceId() {
return namespaceId;
}
public void setClusterId(long clusterId) {
this.clusterId = clusterId;
}
public void setId(long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setNamespaceId(long namespaceId) {
this.namespaceId = namespaceId;
}
}
......@@ -2,7 +2,7 @@ package com.ctrip.apollo.core.dto;
import java.util.Date;
public class ConfigItemDTO {
public class ItemDTO {
private long id;
......@@ -18,19 +18,11 @@ public class ConfigItemDTO {
private String comment;
private String dataChangeCreatedBy;
private Date dataChangeCreatedTime;
private String dataChangeLastModifiedBy;
private Date dataChangeLastModifiedTime;
public ConfigItemDTO() {
public ItemDTO() {
}
public ConfigItemDTO(String key, String value) {
public ItemDTO(String key, String value) {
this.key = key;
this.value = value;
}
......@@ -83,38 +75,6 @@ public class ConfigItemDTO {
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) {
this.dataChangeLastModifiedBy = dataChangeLastModifiedBy;
}
public Date getDataChangeLastModifiedTime() {
return dataChangeLastModifiedTime;
}
public void setDataChangeLastModifiedTime(Date dataChangeLastModifiedTime) {
this.dataChangeLastModifiedTime = dataChangeLastModifiedTime;
}
public String getComment() {
return comment;
}
......
package com.ctrip.apollo.core.dto;
public class ReleaseSnapshotDTO {
public class ReleaseDTO {
private long id;
......@@ -10,7 +10,7 @@ public class ReleaseSnapshotDTO {
private String configurations;
public ReleaseSnapshotDTO() {
public ReleaseDTO() {
}
public long getId() {
......
......@@ -4,8 +4,8 @@ import com.google.common.base.Strings;
import com.ctrip.apollo.Apollo;
import com.ctrip.apollo.core.dto.ClusterDTO;
import com.ctrip.apollo.core.dto.ConfigItemDTO;
import com.ctrip.apollo.core.dto.ReleaseSnapshotDTO;
import com.ctrip.apollo.core.dto.ItemDTO;
import com.ctrip.apollo.core.dto.ReleaseDTO;
import com.ctrip.apollo.core.dto.VersionDTO;
import org.springframework.stereotype.Service;
......@@ -19,16 +19,16 @@ public class AdminServiceAPI {
public static class ConfigAPI extends API {
public static String CONFIG_RELEASE_API = "/configs/release/";
public ReleaseSnapshotDTO[] getConfigByReleaseId(Apollo.Env env, long releaseId) {
public ReleaseDTO[] getConfigByReleaseId(Apollo.Env env, long releaseId) {
if (releaseId <= 0) {
return null;
}
return restTemplate.getForObject(getAdminServiceHost(env) + CONFIG_RELEASE_API + releaseId,
ReleaseSnapshotDTO[].class);
ReleaseDTO[].class);
}
public ConfigItemDTO[] getLatestConfigItemsByClusters(Apollo.Env env, List<Long> clusterIds) {
public ItemDTO[] getLatestConfigItemsByClusters(Apollo.Env env, List<Long> clusterIds) {
if (clusterIds == null || clusterIds.size() == 0) {
return null;
}
......@@ -38,7 +38,7 @@ public class AdminServiceAPI {
}
return restTemplate.getForObject(getAdminServiceHost(env) + "/configs/latest?clusterIds=" + sb
.substring(0, sb.length() - 1), ConfigItemDTO[].class);
.substring(0, sb.length() - 1), ItemDTO[].class);
}
}
......
......@@ -2,7 +2,7 @@ package com.ctrip.apollo.portal.entity;
import com.ctrip.apollo.Apollo.Env;
import com.ctrip.apollo.core.dto.ConfigItemDTO;
import com.ctrip.apollo.core.dto.ItemDTO;
import java.util.LinkedList;
import java.util.List;
......@@ -21,7 +21,7 @@ public class AppConfigVO {
/**
* default cluster and app self’s configs
*/
private List<ConfigItemDTO> defaultClusterConfigs;
private List<ItemDTO> defaultClusterConfigs;
/**
* default cluster and override other app configs
......@@ -63,7 +63,7 @@ public class AppConfigVO {
public static class OverrideAppConfig {
private String appId;
private List<ConfigItemDTO> configs;
private List<ItemDTO> configs;
public OverrideAppConfig() {
......@@ -77,15 +77,15 @@ public class AppConfigVO {
this.appId = appId;
}
public List<ConfigItemDTO> getConfigs() {
public List<ItemDTO> getConfigs() {
return configs;
}
public void setConfigs(List<ConfigItemDTO> configs) {
public void setConfigs(List<ItemDTO> configs) {
this.configs = configs;
}
public void addConfig(ConfigItemDTO config) {
public void addConfig(ItemDTO config) {
if (configs == null) {
configs = new LinkedList<>();
}
......@@ -97,7 +97,7 @@ public class AppConfigVO {
public static class OverrideClusterConfig {
private String clusterName;
private List<ConfigItemDTO> configs;
private List<ItemDTO> configs;
public OverrideClusterConfig() {
}
......@@ -110,11 +110,11 @@ public class AppConfigVO {
this.clusterName = clusterName;
}
public List<ConfigItemDTO> getConfigs() {
public List<ItemDTO> getConfigs() {
return configs;
}
public void setConfigs(List<ConfigItemDTO> configs) {
public void setConfigs(List<ItemDTO> configs) {
this.configs = configs;
}
}
......@@ -144,11 +144,11 @@ public class AppConfigVO {
this.versionId = versionId;
}
public List<ConfigItemDTO> getDefaultClusterConfigs() {
public List<ItemDTO> getDefaultClusterConfigs() {
return defaultClusterConfigs;
}
public void setDefaultClusterConfigs(List<ConfigItemDTO> defaultClusterConfigs) {
public void setDefaultClusterConfigs(List<ItemDTO> defaultClusterConfigs) {
this.defaultClusterConfigs = defaultClusterConfigs;
}
......
......@@ -16,8 +16,8 @@ import org.springframework.stereotype.Service;
import com.ctrip.apollo.Apollo.Env;
import com.ctrip.apollo.core.ConfigConsts;
import com.ctrip.apollo.core.dto.ClusterDTO;
import com.ctrip.apollo.core.dto.ConfigItemDTO;
import com.ctrip.apollo.core.dto.ReleaseSnapshotDTO;
import com.ctrip.apollo.core.dto.ItemDTO;
import com.ctrip.apollo.core.dto.ReleaseDTO;
import com.ctrip.apollo.core.dto.VersionDTO;
import com.ctrip.apollo.portal.api.AdminServiceAPI;
import com.ctrip.apollo.portal.constants.PortalConstants;
......@@ -53,14 +53,14 @@ public class ConfigService {
return null;
}
ReleaseSnapshotDTO[] releaseSnapShots = configAPI.getConfigByReleaseId(env, releaseId);
ReleaseDTO[] releaseSnapShots = configAPI.getConfigByReleaseId(env, releaseId);
if (releaseSnapShots == null || releaseSnapShots.length == 0) {
return null;
}
AppConfigVO appConfigVO = AppConfigVO.newInstance(appId, versionId);
for (ReleaseSnapshotDTO snapShot : releaseSnapShots) {
for (ReleaseDTO snapShot : releaseSnapShots) {
// default cluster
if (ConfigConsts.DEFAULT_CLUSTER_NAME.equals(snapShot.getClusterName())) {
......@@ -81,17 +81,17 @@ public class ConfigService {
return version.getReleaseId();
}
private void collectDefaultClusterConfigs(String appId, ReleaseSnapshotDTO snapShot,
private void collectDefaultClusterConfigs(String appId, ReleaseDTO snapShot,
AppConfigVO appConfigVO) {
Map<String, List<ConfigItemDTO>> groupedConfigs =
Map<String, List<ItemDTO>> groupedConfigs =
groupConfigsByApp(appId, snapShot.getConfigurations());
List<AppConfigVO.OverrideAppConfig> overrideAppConfigs = appConfigVO.getOverrideAppConfigs();
for (Map.Entry<String, List<ConfigItemDTO>> entry : groupedConfigs.entrySet()) {
for (Map.Entry<String, List<ItemDTO>> entry : groupedConfigs.entrySet()) {
String configAppId = entry.getKey();
List<ConfigItemDTO> kvs = entry.getValue();
List<ItemDTO> kvs = entry.getValue();
if (configAppId.equals(appId)) {
appConfigVO.setDefaultClusterConfigs(kvs);
......@@ -109,12 +109,12 @@ public class ConfigService {
/**
* appId -> List<KV>
*/
private Map<String, List<ConfigItemDTO>> groupConfigsByApp(String selfAppId, String configJson) {
private Map<String, List<ItemDTO>> groupConfigsByApp(String selfAppId, String configJson) {
if (configJson == null || "".equals(configJson)) {
return Maps.newHashMap();
}
Map<String, List<ConfigItemDTO>> appIdMapKVs = new HashMap<>();
Map<String, List<ItemDTO>> appIdMapKVs = new HashMap<>();
String key;
Object value;
......@@ -131,12 +131,12 @@ public class ConfigService {
value = entry.getValue();
String appId = getAppIdFromKey(key);
List<ConfigItemDTO> kvs = appIdMapKVs.get(appId);
List<ItemDTO> kvs = appIdMapKVs.get(appId);
if (kvs == null) {
kvs = new LinkedList<>();
appIdMapKVs.put(appId, kvs);
}
kvs.add(new ConfigItemDTO(key, value.toString()));
kvs.add(new ItemDTO(key, value.toString()));
}
return appIdMapKVs;
......@@ -147,7 +147,7 @@ public class ConfigService {
return key.substring(0, key.indexOf("."));
}
private void collectSpecialClusterConfigs(String appId, ReleaseSnapshotDTO snapShot,
private void collectSpecialClusterConfigs(String appId, ReleaseDTO snapShot,
AppConfigVO appConfigVO) {
List<AppConfigVO.OverrideClusterConfig> overrideClusterConfigs =
appConfigVO.getOverrideClusterConfigs();
......@@ -174,17 +174,17 @@ public class ConfigService {
clusterIds.add(cluster.getId());
}
ConfigItemDTO[] configItems = configAPI.getLatestConfigItemsByClusters(env, clusterIds);
ItemDTO[] configItems = configAPI.getLatestConfigItemsByClusters(env, clusterIds);
return buildAPPConfigVO(appId, Arrays.asList(configItems));
}
private AppConfigVO buildAPPConfigVO(String appId, List<ConfigItemDTO> configItems) {
private AppConfigVO buildAPPConfigVO(String appId, List<ItemDTO> configItems) {
if (configItems == null || configItems.size() == 0) {
return null;
}
Map<String, List<ConfigItemDTO>> groupedClusterConfigs = groupConfigByCluster(configItems);
Map<String, List<ItemDTO>> groupedClusterConfigs = groupConfigByCluster(configItems);
AppConfigVO appConfigVO = AppConfigVO.newInstance(appId, PortalConstants.LASTEST_VERSION_ID);
......@@ -194,13 +194,13 @@ public class ConfigService {
}
private Map<String, List<ConfigItemDTO>> groupConfigByCluster(List<ConfigItemDTO> configItems) {
Map<String, List<ConfigItemDTO>> groupedClusterConfigs = new HashMap<>();
private Map<String, List<ItemDTO>> groupConfigByCluster(List<ItemDTO> configItems) {
Map<String, List<ItemDTO>> groupedClusterConfigs = new HashMap<>();
String clusterName;
for (ConfigItemDTO configItem : configItems) {
for (ItemDTO configItem : configItems) {
clusterName = configItem.getClusterName();
List<ConfigItemDTO> clusterConfigs = groupedClusterConfigs.get(clusterName);
List<ItemDTO> clusterConfigs = groupedClusterConfigs.get(clusterName);
if (clusterConfigs == null) {
clusterConfigs = new LinkedList<>();
groupedClusterConfigs.put(clusterName, clusterConfigs);
......@@ -210,11 +210,11 @@ public class ConfigService {
return groupedClusterConfigs;
}
private void groupConfigByAppAndEnrichDTO(Map<String, List<ConfigItemDTO>> groupedClusterConfigs,
private void groupConfigByAppAndEnrichDTO(Map<String, List<ItemDTO>> groupedClusterConfigs,
AppConfigVO appConfigVO) {
String appId = appConfigVO.getAppId();
List<ConfigItemDTO> defaultClusterConfigs = appConfigVO.getDefaultClusterConfigs();
List<ItemDTO> defaultClusterConfigs = appConfigVO.getDefaultClusterConfigs();
List<AppConfigVO.OverrideAppConfig> overrideAppConfigs = appConfigVO.getOverrideAppConfigs();
......@@ -222,8 +222,8 @@ public class ConfigService {
appConfigVO.getOverrideClusterConfigs();
String clusterName;
List<ConfigItemDTO> clusterConfigs;
for (Map.Entry<String, List<ConfigItemDTO>> entry : groupedClusterConfigs.entrySet()) {
List<ItemDTO> clusterConfigs;
for (Map.Entry<String, List<ItemDTO>> entry : groupedClusterConfigs.entrySet()) {
clusterName = entry.getKey();
clusterConfigs = entry.getValue();
......@@ -238,13 +238,13 @@ public class ConfigService {
}
}
private void collectDefaultClusterConfigs(String appId, List<ConfigItemDTO> clusterConfigs,
List<ConfigItemDTO> defaultClusterConfigs,
private void collectDefaultClusterConfigs(String appId, List<ItemDTO> clusterConfigs,
List<ItemDTO> defaultClusterConfigs,
List<AppConfigVO.OverrideAppConfig> overrideAppConfigs) {
Map<String, AppConfigVO.OverrideAppConfig> appIdMapOverrideAppConfig = null;
for (ConfigItemDTO config : clusterConfigs) {
for (ItemDTO config : clusterConfigs) {
String targetAppId = config.getAppId();
if (appId.equals(targetAppId)) {// app self's configs
defaultClusterConfigs.add(config);
......@@ -268,7 +268,7 @@ public class ConfigService {
}
}
private void collectSpecialClusterConfigs(String clusterName, List<ConfigItemDTO> clusterConfigs,
private void collectSpecialClusterConfigs(String clusterName, List<ItemDTO> clusterConfigs,
List<AppConfigVO.OverrideClusterConfig> overrideClusterConfigs) {
AppConfigVO.OverrideClusterConfig overrideClusterConfig =
new AppConfigVO.OverrideClusterConfig();
......
......@@ -17,8 +17,8 @@ import org.springframework.web.client.RestTemplate;
import com.ctrip.apollo.Apollo.Env;
import com.ctrip.apollo.core.ConfigConsts;
import com.ctrip.apollo.core.dto.ClusterDTO;
import com.ctrip.apollo.core.dto.ConfigItemDTO;
import com.ctrip.apollo.core.dto.ReleaseSnapshotDTO;
import com.ctrip.apollo.core.dto.ItemDTO;
import com.ctrip.apollo.core.dto.ReleaseDTO;
import com.ctrip.apollo.core.dto.ServiceDTO;
import com.ctrip.apollo.core.dto.VersionDTO;
import com.ctrip.apollo.core.exception.ServiceException;
......@@ -71,7 +71,7 @@ public class ConfigServiceTest {
long releaseId = 11111;
VersionDTO someVersion = assembleVersion(appId, "1.0", releaseId);
ReleaseSnapshotDTO[] someReleaseSnapShots = assembleReleaseSnapShots();
ReleaseDTO[] someReleaseSnapShots = assembleReleaseSnapShots();
when(versionAPI.getVersionById(Env.DEV, versionId)).thenReturn(someVersion);
when(configAPI.getConfigByReleaseId(Env.DEV, releaseId)).thenReturn(someReleaseSnapShots);
......@@ -92,7 +92,7 @@ public class ConfigServiceTest {
long releaseId = 11111;
VersionDTO someVersion = assembleVersion(appId, "1.0", releaseId);
ReleaseSnapshotDTO[] someReleaseSnapShots = new ReleaseSnapshotDTO[1];
ReleaseDTO[] someReleaseSnapShots = new ReleaseDTO[1];
someReleaseSnapShots[0] = assembleReleaseSnapShot(11111, ConfigConsts.DEFAULT_CLUSTER_NAME,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}");
......@@ -114,7 +114,7 @@ public class ConfigServiceTest {
long versionId = 100;
long releaseId = 11111;
VersionDTO someVersion = assembleVersion(appId, "1.0", releaseId);
ReleaseSnapshotDTO[] someReleaseSnapShots = new ReleaseSnapshotDTO[1];
ReleaseDTO[] someReleaseSnapShots = new ReleaseDTO[1];
someReleaseSnapShots[0] = assembleReleaseSnapShot(11111, ConfigConsts.DEFAULT_CLUSTER_NAME,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\", \"5555.bar\":\"demo2\", \"22.bar\":\"demo2\"}");
......@@ -136,7 +136,7 @@ public class ConfigServiceTest {
long versionId = 100;
long releaseId = 11111;
VersionDTO someVersion = assembleVersion(appId, "1.0", releaseId);
ReleaseSnapshotDTO[] someReleaseSnapShots = new ReleaseSnapshotDTO[2];
ReleaseDTO[] someReleaseSnapShots = new ReleaseDTO[2];
someReleaseSnapShots[0] = assembleReleaseSnapShot(11111, ConfigConsts.DEFAULT_CLUSTER_NAME,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}");
someReleaseSnapShots[1] = assembleReleaseSnapShot(11112, "cluster1",
......@@ -158,7 +158,7 @@ public class ConfigServiceTest {
public void testLoadLastestConfig() {
String appId = "6666";
ClusterDTO[] someClusters = assembleClusters();
ConfigItemDTO[] someConfigItem = assembleConfigItems();
ItemDTO[] someConfigItem = assembleConfigItems();
when(clusterAPI.getClustersByApp(Env.DEV, appId)).thenReturn(someClusters);
when(configAPI.getLatestConfigItemsByClusters(Env.DEV, Arrays
......@@ -181,8 +181,8 @@ public class ConfigServiceTest {
return version;
}
private ReleaseSnapshotDTO[] assembleReleaseSnapShots() {
ReleaseSnapshotDTO[] releaseSnapShots = new ReleaseSnapshotDTO[3];
private ReleaseDTO[] assembleReleaseSnapShots() {
ReleaseDTO[] releaseSnapShots = new ReleaseDTO[3];
releaseSnapShots[0] = assembleReleaseSnapShot(11111, ConfigConsts.DEFAULT_CLUSTER_NAME,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\",\"3333.foo\":\"1008\",\"4444.bar\":\"99901\"}");
releaseSnapShots[1] = assembleReleaseSnapShot(11111, "cluster1", "{\"6666.foo\":\"demo1\"}");
......@@ -190,9 +190,9 @@ public class ConfigServiceTest {
return releaseSnapShots;
}
private ReleaseSnapshotDTO assembleReleaseSnapShot(long releaseId, String clusterName,
private ReleaseDTO assembleReleaseSnapShot(long releaseId, String clusterName,
String configurations) {
ReleaseSnapshotDTO releaseSnapShot = new ReleaseSnapshotDTO();
ReleaseDTO releaseSnapShot = new ReleaseDTO();
releaseSnapShot.setReleaseId(releaseId);
releaseSnapShot.setClusterName(clusterName);
releaseSnapShot.setConfigurations(configurations);
......@@ -214,8 +214,8 @@ public class ConfigServiceTest {
return cluster;
}
private ConfigItemDTO[] assembleConfigItems() {
ConfigItemDTO[] configItems = new ConfigItemDTO[5];
private ItemDTO[] assembleConfigItems() {
ItemDTO[] configItems = new ItemDTO[5];
configItems[0] = assembleConfigItem(100, ConfigConsts.DEFAULT_CLUSTER_NAME, "6666", "6666.k1", "6666.v1");
configItems[1] = assembleConfigItem(100, ConfigConsts.DEFAULT_CLUSTER_NAME, "6666", "6666.k2", "6666.v2");
configItems[2] = assembleConfigItem(100, ConfigConsts.DEFAULT_CLUSTER_NAME, "6666", "6666.k3", "6666.v3");
......@@ -224,9 +224,9 @@ public class ConfigServiceTest {
return configItems;
}
private ConfigItemDTO assembleConfigItem(long clusterId, String clusterName, String appId,
private ItemDTO assembleConfigItem(long clusterId, String clusterName, String appId,
String key, String value) {
ConfigItemDTO configItem = new ConfigItemDTO();
ItemDTO configItem = new ItemDTO();
configItem.setClusterName(clusterName);
configItem.setClusterId(clusterId);
configItem.setAppId(appId);
......
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