Commit 8563b8b9 by Jason Song

Merge pull request #47 from lepdou/portal_optimize

重构portal api
parents babb3c6a ff0364c1
......@@ -77,6 +77,9 @@ public class AdminConfigServiceImpl implements AdminConfigService {
return null;
}
Version version = versionRepository.findById(versionId);
if (version == null){
return null;
}
return version.toDTO();
}
......
......@@ -15,12 +15,12 @@ INSERT INTO RELEASESNAPSHOT (ClusterName, IsDeleted, ReleaseId, Configurations)
INSERT INTO RELEASESNAPSHOT (ClusterName, IsDeleted, ReleaseId, Configurations) VALUES ('cluster2', 0, 11111, '{"6666.bar":"bar2222"}');
INSERT INTO RELEASESNAPSHOT (ClusterName, IsDeleted, ReleaseId, Configurations) VALUES ('default', 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, DataChange_CreatedBy, DataChange_CreatedTime, DataChange_LastModifiedBy, DataChange_LastModifiedTime, IsDeleted) VALUES (100, 'default', 6666, '6666.k1', '6666.v1', 'comment1', 'lepdou', '2016-03-23 12:00:00', '王五', NOW(), 0);
INSERT INTO ConfigItem(ClusterId, ClusterName, AppId, Key, Value, comment, DataChange_CreatedBy, DataChange_CreatedTime, DataChange_LastModifiedBy, DataChange_LastTime, IsDeleted) VALUES (100, 'default', 6666, '6666.k1', '6666.v1', 'comment1', 'lepdou', '2016-03-23 12:00:00', '王五', NOW(), 0);
INSERT INTO ConfigItem(ClusterId, ClusterName, AppId, Key, Value, comment, DataChange_CreatedBy, DataChange_CreatedTime, DataChange_LastModifiedBy, DataChange_LastModifiedTime, IsDeleted) VALUES (100, 'default', 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, DataChange_CreatedBy, DataChange_CreatedTime, DataChange_LastModifiedBy, DataChange_LastTime, IsDeleted) VALUES (100, 'default', 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, DataChange_CreatedBy, DataChange_CreatedTime, DataChange_LastModifiedBy, DataChange_LastModifiedTime, IsDeleted) VALUES (100, 'default', 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, DataChange_CreatedBy, DataChange_CreatedTime, DataChange_LastModifiedBy, DataChange_LastTime, IsDeleted) VALUES (100, 'default', 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, DataChange_CreatedBy, DataChange_CreatedTime, DataChange_LastModifiedBy, DataChange_LastModifiedTime, IsDeleted) VALUES (100, 'default', 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, DataChange_CreatedBy, DataChange_CreatedTime, DataChange_LastModifiedBy, DataChange_LastTime, IsDeleted) VALUES (100, 'default', 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, DataChange_CreatedBy, DataChange_CreatedTime, DataChange_LastModifiedBy, DataChange_LastModifiedTime, IsDeleted) VALUES (101, 'cluster1', 6666, '6666.k1', '6666.v122', 'qqqqq', 'lepdou', '2016-03-23 12:00:00', '王五4', NOW(),0);
INSERT INTO ConfigItem(ClusterId, ClusterName, AppId, Key, Value, comment, DataChange_CreatedBy, DataChange_CreatedTime, DataChange_LastModifiedBy, DataChange_LastTime, IsDeleted) VALUES (101, 'cluster1', 6666, '6666.k1', '6666.v122', 'qqqqq', 'lepdou', '2016-03-23 12:00:00', '王五4', NOW(),0);
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();
}
}
package com.ctrip.apollo.portal.api;
import com.ctrip.apollo.Apollo;
import com.ctrip.apollo.portal.service.ServiceLocator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.client.RestTemplate;
public class API {
@Autowired
protected ServiceLocator serviceLocator;
protected RestTemplate restTemplate = new RestTemplate();
public String getAdminServiceHost(Apollo.Env env){
//本地测试用
// return "http://localhost:8090";
return serviceLocator.getAdminService(env);
}
}
package com.ctrip.apollo.portal.api;
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.VersionDTO;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class AdminServiceAPI {
@Service
public static class ConfigAPI extends API {
public static String CONFIG_RELEASE_API = "/configs/release/";
public ReleaseSnapshotDTO[] getConfigByReleaseId(Apollo.Env env, long releaseId) {
if (releaseId <= 0) {
return null;
}
return restTemplate.getForObject(getAdminServiceHost(env) + CONFIG_RELEASE_API + releaseId,
ReleaseSnapshotDTO[].class);
}
public ConfigItemDTO[] getLatestConfigItemsByClusters(Apollo.Env env, List<Long> clusterIds) {
if (clusterIds == null || clusterIds.size() == 0) {
return null;
}
StringBuilder sb = new StringBuilder();
for (long clusterId : clusterIds) {
sb.append(clusterId).append(",");
}
return restTemplate.getForObject(getAdminServiceHost(env) + "/configs/latest?clusterIds=" + sb
.substring(0, sb.length() - 1), ConfigItemDTO[].class);
}
}
@Service
public static class ClusterAPI extends API {
public static String CLUSTER_APP_API = "/cluster/app/";
public ClusterDTO[] getClustersByApp(Apollo.Env env, long appId) {
if (appId <= 0) {
return null;
}
return restTemplate
.getForObject(getAdminServiceHost(env) + CLUSTER_APP_API + appId, ClusterDTO[].class);
}
}
@Service
public static class VersionAPI extends API{
public static String VERSION_API = "/version/";
public static String VERSION_APP_API = "/version/app/";
public VersionDTO getVersionById(Apollo.Env env, long versionId){
if (versionId <= 0){
return null;
}
return restTemplate.getForObject(getAdminServiceHost(env) + VERSION_API + versionId, VersionDTO.class);
}
public VersionDTO[] getVersionsByApp(Apollo.Env env, long appId){
if (appId <= 0){
return null;
}
return restTemplate.getForObject(getAdminServiceHost(env) + VERSION_APP_API + appId,
VersionDTO[].class);
}
}
}
package com.ctrip.apollo.portal.service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -16,33 +19,38 @@ 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.VersionDTO;
import com.ctrip.apollo.core.serivce.ApolloService;
import com.ctrip.apollo.portal.RestUtils;
import com.ctrip.apollo.portal.api.AdminServiceAPI;
import com.ctrip.apollo.portal.constants.PortalConstants;
import com.ctrip.apollo.portal.entity.AppConfigVO;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Maps;
@Service
public class ConfigService {
private Logger logger = LoggerFactory.getLogger(ConfigService.class);
@Autowired
private AdminServiceAPI.ConfigAPI configAPI;
@Autowired
private AdminServiceAPI.ClusterAPI clusterAPI;
@Autowired
private ServiceLocator serviceLocator;
private AdminServiceAPI.VersionAPI versionAPI;
private ObjectMapper objectMapper = new ObjectMapper();
public AppConfigVO loadReleaseConfig(Env env, long appId, long versionId) {
if (appId <= 0 || versionId <= 0) {
return null;
}
long releaseId = getReleaseIdFromVersionId(env, versionId);
if (releaseId == -1) {
return null;
}
String serviceHost = serviceLocator.getAdminService(env);
ReleaseSnapshotDTO[] releaseSnapShots = RestUtils
.exchangeInGET(serviceHost + "/configs/release/" + releaseId, ReleaseSnapshotDTO[].class);
ReleaseSnapshotDTO[] releaseSnapShots = configAPI.getConfigByReleaseId(Env.DEV, releaseId);
if (releaseSnapShots == null || releaseSnapShots.length == 0) {
return null;
}
......@@ -63,9 +71,7 @@ public class ConfigService {
}
private long getReleaseIdFromVersionId(Env env, long versionId) {
String serviceHost = serviceLocator.getAdminService(env);
VersionDTO version =
RestUtils.exchangeInGET(serviceHost + "/version/" + versionId, VersionDTO.class);
VersionDTO version = versionAPI.getVersionById(env, versionId);
if (version == null) {
return -1;
}
......@@ -152,21 +158,17 @@ public class ConfigService {
return null;
}
String serviceHost = serviceLocator.getAdminService(env);
ClusterDTO[] clusters =
RestUtils.exchangeInGET(serviceHost + "/cluster/app/" + appId, ClusterDTO[].class);
ClusterDTO[] clusters = clusterAPI.getClustersByApp(env, appId);
if (clusters == null || clusters.length == 0) {
return null;
}
StringBuilder sb = new StringBuilder();
List<Long> clusterIds = new ArrayList<>(clusters.length);
for (ClusterDTO cluster : clusters) {
sb.append(cluster.getId()).append(",");
clusterIds.add(cluster.getId());
}
ConfigItemDTO[] configItems = RestUtils.exchangeInGET(
serviceHost + "/configs/latest?clusterIds=" + sb.substring(0, sb.length() - 1),
ConfigItemDTO[].class);
ConfigItemDTO[] configItems = configAPI.getLatestConfigItemsByClusters(env, clusterIds);
return buildAPPConfigVO(appId, Arrays.asList(configItems));
}
......
......@@ -30,8 +30,6 @@ public class ServiceLocator {
}
public String getAdminService(Env env) {
//本地测试用
// return "http://localhost:8090";
List<ApolloService> services = getAdminServices(env);
if (services.size() == 0) {
throw new RuntimeException("No available admin service");
......
......@@ -2,22 +2,28 @@ package com.ctrip.apollo.portal.service;
import com.ctrip.apollo.Apollo;
import com.ctrip.apollo.core.dto.VersionDTO;
import com.ctrip.apollo.portal.RestUtils;
import com.ctrip.apollo.portal.api.AdminServiceAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@Service
public class VersionService {
@Autowired
private ServiceLocator serviceLocator;
private AdminServiceAPI.VersionAPI versionAPI;
public List<VersionDTO> findVersionsByApp(Apollo.Env env, long appId) {
return RestUtils
.exchangeInGET(serviceLocator.getAdminService(env) + "/version/app/" + appId, List.class);
VersionDTO[] versions = versionAPI.getVersionsByApp(env, appId);
if (versions == null || versions.length == 0){
return Collections.EMPTY_LIST;
}
return Arrays.asList(versions);
}
}
......@@ -13,7 +13,7 @@ spring:
logging:
level:
org.springframework.cloud: 'DEBUG'
file: /opt/logs/${ctrip.appid}/apollo-adminservice.log
file: /opt/logs/${ctrip.appid}/apollo-portal.log
ctrip:
appid: 100003173
......@@ -7,6 +7,10 @@ body {
padding-bottom: 50px;
}
a{
cursor: pointer;
}
.container {
width: 100%;
min-height: 550px;
......
......@@ -3,7 +3,7 @@
<!--环境nav-->
<ul class="nav nav-pills nav-justified">
<li ng-repeat="env in envs" ng-class="{active:configLocation.env == env}">
<a href="#" ng-click="switchEnv(env)">{{env}}</a>
<a ng-click="switchEnv(env)">{{env}}</a>
</li>
</ul>
......@@ -14,12 +14,12 @@
<ul class="nav nav-pills nav-stacked">
<li class="dropdown-header">未发布</li>
<li role="presentation" ng-class="{active:configLocation.versionId == -1}"
ng-click="switchVersion(-1)"><a href="#">latest</a></li>
ng-click="switchVersion(-1)"><a>latest</a></li>
<li role="separator" class="divider"></li>
<li class="dropdown-header">已发布</li>
<li ng-repeat="version in releaseVersions"
ng-class="{active:configLocation.versionId == version.id}">
<a href="#" ng-click="switchVersion(version.id)">{{version.name}}</a>
<a ng-click="switchVersion(version.id)">{{version.name}}</a>
</li>
</ul>
</div>
......@@ -31,13 +31,13 @@
<div class="col-md-6">项目的基本配置</div>
<div class="col-md-6" ng-show="!currentVersionIsRelease">
<p class="text-right">
<a href="#" data-toggle="tooltip"
<a data-toggle="tooltip"
data-placement="top" title="下载配置">
<span class="glyphicon glyphicon-save"
aria-hidden="true"></span>
</a>
&nbsp;
<a href="#" data-toggle="tooltip"
<a data-toggle="tooltip"
data-placement="top" title="添加配置">
<span class="glyphicon glyphicon-plus"
aria-hidden="true"></span>
......@@ -93,12 +93,12 @@
</td>
<td ng-show="!currentVersionIsRelease">
<a href="#" data-toggle="tooltip"
<a data-toggle="tooltip"
data-placement="top" title="修改">
<span class="glyphicon glyphicon-edit"
aria-hidden="true"></span>
</a>
<a href="#" data-toggle="tooltip"
<a data-toggle="tooltip"
data-placement="top" title="删除">
<span class="glyphicon glyphicon-remove"
aria-hidden="true"></span>
......@@ -110,17 +110,17 @@
<nav class="text-right">
<ul class="pagination">
<li>
<a href="#" aria-label="Previous">
<a aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a >1</a></li>
<li><a >2</a></li>
<li><a >3</a></li>
<li><a >4</a></li>
<li><a >5</a></li>
<li>
<a href="#" aria-label="Next">
<a aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
......@@ -135,18 +135,18 @@
<header class="panel-heading">
<div class="row">
<div class="col-md-6">重写<a
href="#">{{overrideAppConfig.appId}}</a>的配置
>{{overrideAppConfig.appId}}</a>的配置
</div>
<div class="col-md-6" ng-show="!currentVersionIsRelease">
<p class="text-right">
<a href="#" data-toggle="tooltip"
<a data-toggle="tooltip"
data-placement="top"
title="下载配置">
<span class="glyphicon glyphicon-save"
aria-hidden="true"></span>
</a>
&nbsp;
<a href="#" data-toggle="tooltip"
<a data-toggle="tooltip"
data-placement="top"
title="添加配置">
<span class="glyphicon glyphicon-plus"
......@@ -202,13 +202,13 @@
</td>
<td ng-show="!currentVersionIsRelease">
<a href="#" data-toggle="tooltip"
<a data-toggle="tooltip"
data-placement="top"
title="修改">
<span class="glyphicon glyphicon-edit"
aria-hidden="true"></span>
</a>
<a href="#" data-toggle="tooltip"
<a data-toggle="tooltip"
data-placement="top"
title="删除">
<span class="glyphicon glyphicon-remove"
......@@ -247,13 +247,13 @@
</div>
<div class="col-md-6" ng-show="!currentVersionIsRelease">
<p class="text-right">
<a href="#" data-toggle="tooltip"
<a data-toggle="tooltip"
data-placement="top" title="下载配置">
<span class="glyphicon glyphicon-save"
aria-hidden="true"></span>
</a>
&nbsp;
<a href="#" data-toggle="tooltip"
<a data-toggle="tooltip"
data-placement="top" title="添加配置">
<span class="glyphicon glyphicon-plus"
aria-hidden="true"></span>
......@@ -308,13 +308,13 @@
</td>
<td ng-show="!currentVersionIsRelease">
<a href="#" data-toggle="tooltip"
<a data-toggle="tooltip"
data-placement="top"
title="修改">
<span class="glyphicon glyphicon-edit"
aria-hidden="true"></span>
</a>
<a href="#" data-toggle="tooltip"
<a data-toggle="tooltip"
data-placement="top"
title="删除">
<span class="glyphicon glyphicon-remove"
......
package com.ctrip.apollo.portal.service;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
......@@ -16,10 +12,6 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.client.RestTemplate;
......@@ -29,34 +21,42 @@ 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.VersionDTO;
import com.ctrip.apollo.core.serivce.ApolloService;
import com.ctrip.apollo.portal.RestUtils;
import com.ctrip.apollo.portal.api.AdminServiceAPI;
import com.ctrip.apollo.portal.constants.PortalConstants;
import com.ctrip.apollo.portal.entity.AppConfigVO;
import java.util.Arrays;
@RunWith(MockitoJUnitRunner.class)
public class ConfigServiceTest {
@Mock
private RestTemplate restTemplate;
@Mock
private ResponseEntity releaseSnapShotResponse;
@Mock
private ResponseEntity versionResponse;
@Mock
private ResponseEntity clusterResponse;
@Mock
private ResponseEntity configItemResponse;
@InjectMocks
private ConfigService configService;
@Spy
@Mock
private ServiceLocator serviceLocator;
@Spy
private AdminServiceAPI.VersionAPI versionAPI;
@Spy
private AdminServiceAPI.ClusterAPI clusterAPI;
@Spy
private AdminServiceAPI.ConfigAPI configAPI;
@Before
public void setUp() {
ReflectionTestUtils.setField(RestUtils.class, "restTemplate", restTemplate);
ReflectionTestUtils.setField(versionAPI, "restTemplate", restTemplate);
ReflectionTestUtils.setField(clusterAPI, "restTemplate", restTemplate);
ReflectionTestUtils.setField(configAPI, "restTemplate", restTemplate);
ReflectionTestUtils.setField(versionAPI, "serviceLocator", serviceLocator);
ReflectionTestUtils.setField(clusterAPI, "serviceLocator", serviceLocator);
ReflectionTestUtils.setField(configAPI, "serviceLocator", serviceLocator);
String defaultAdminService = "http://localhost:8090";
Mockito.doReturn(defaultAdminService).when(serviceLocator).getAdminService(Env.DEV);
}
......@@ -70,11 +70,8 @@ public class ConfigServiceTest {
VersionDTO someVersion = assembleVersion(appId, "1.0", releaseId);
ReleaseSnapshotDTO[] someReleaseSnapShots = assembleReleaseSnapShots();
restInvoke(serviceLocator.getAdminService(Env.DEV) + "/configs/release/" + releaseId,
ReleaseSnapshotDTO[].class, someReleaseSnapShots, releaseSnapShotResponse);
restInvoke(serviceLocator.getAdminService(Env.DEV) + "/version/" + versionId, VersionDTO.class,
someVersion, versionResponse);
when(versionAPI.getVersionById(Env.DEV, versionId)).thenReturn(someVersion);
when(configAPI.getConfigByReleaseId(Env.DEV, releaseId)).thenReturn(someReleaseSnapShots);
AppConfigVO appConfigVO = configService.loadReleaseConfig(Env.DEV, appId, versionId);
......@@ -92,15 +89,12 @@ public class ConfigServiceTest {
long releaseId = 11111;
VersionDTO someVersion = assembleVersion(appId, "1.0", releaseId);
ReleaseSnapshotDTO[] releaseSnapShots = new ReleaseSnapshotDTO[1];
releaseSnapShots[0] = assembleReleaseSnapShot(11111, Constants.DEFAULT_CLUSTER_NAME,
ReleaseSnapshotDTO[] someReleaseSnapShots = new ReleaseSnapshotDTO[1];
someReleaseSnapShots[0] = assembleReleaseSnapShot(11111, Constants.DEFAULT_CLUSTER_NAME,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}");
restInvoke(serviceLocator.getAdminService(Env.DEV) + "/configs/release/" + releaseId,
ReleaseSnapshotDTO[].class, releaseSnapShots, releaseSnapShotResponse);
restInvoke(serviceLocator.getAdminService(Env.DEV) + "/version/" + versionId, VersionDTO.class,
someVersion, versionResponse);
when(versionAPI.getVersionById(Env.DEV, versionId)).thenReturn(someVersion);
when(configAPI.getConfigByReleaseId(Env.DEV, releaseId)).thenReturn(someReleaseSnapShots);
AppConfigVO appConfigVO = configService.loadReleaseConfig(Env.DEV, appId, versionId);
......@@ -117,15 +111,12 @@ public class ConfigServiceTest {
long versionId = 100;
long releaseId = 11111;
VersionDTO someVersion = assembleVersion(appId, "1.0", releaseId);
ReleaseSnapshotDTO[] releaseSnapShots = new ReleaseSnapshotDTO[1];
releaseSnapShots[0] = assembleReleaseSnapShot(11111, Constants.DEFAULT_CLUSTER_NAME,
ReleaseSnapshotDTO[] someReleaseSnapShots = new ReleaseSnapshotDTO[1];
someReleaseSnapShots[0] = assembleReleaseSnapShot(11111, Constants.DEFAULT_CLUSTER_NAME,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\", \"5555.bar\":\"demo2\", \"22.bar\":\"demo2\"}");
restInvoke(serviceLocator.getAdminService(Env.DEV) + "/configs/release/" + releaseId,
ReleaseSnapshotDTO[].class, releaseSnapShots, releaseSnapShotResponse);
restInvoke(serviceLocator.getAdminService(Env.DEV) + "/version/" + versionId, VersionDTO.class,
someVersion, versionResponse);
when(versionAPI.getVersionById(Env.DEV, versionId)).thenReturn(someVersion);
when(configAPI.getConfigByReleaseId(Env.DEV, releaseId)).thenReturn(someReleaseSnapShots);
AppConfigVO appConfigVO = configService.loadReleaseConfig(Env.DEV, appId, versionId);
......@@ -142,17 +133,14 @@ public class ConfigServiceTest {
long versionId = 100;
long releaseId = 11111;
VersionDTO someVersion = assembleVersion(appId, "1.0", releaseId);
ReleaseSnapshotDTO[] releaseSnapShots = new ReleaseSnapshotDTO[2];
releaseSnapShots[0] = assembleReleaseSnapShot(11111, Constants.DEFAULT_CLUSTER_NAME,
ReleaseSnapshotDTO[] someReleaseSnapShots = new ReleaseSnapshotDTO[2];
someReleaseSnapShots[0] = assembleReleaseSnapShot(11111, Constants.DEFAULT_CLUSTER_NAME,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}");
releaseSnapShots[1] = assembleReleaseSnapShot(11112, "cluster1",
someReleaseSnapShots[1] = assembleReleaseSnapShot(11112, "cluster1",
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}");
restInvoke(serviceLocator.getAdminService(Env.DEV) + "/configs/release/" + releaseId,
ReleaseSnapshotDTO[].class, releaseSnapShots, releaseSnapShotResponse);
restInvoke(serviceLocator.getAdminService(Env.DEV) + "/version/" + versionId, VersionDTO.class,
someVersion, versionResponse);
when(versionAPI.getVersionById(Env.DEV, versionId)).thenReturn(someVersion);
when(configAPI.getConfigByReleaseId(Env.DEV, releaseId)).thenReturn(someReleaseSnapShots);
AppConfigVO appConfigVO = configService.loadReleaseConfig(Env.DEV, appId, versionId);
......@@ -169,11 +157,9 @@ public class ConfigServiceTest {
ClusterDTO[] someClusters = assembleClusters();
ConfigItemDTO[] someConfigItem = assembleConfigItems();
restInvoke(serviceLocator.getAdminService(Env.DEV) + "/cluster/app/" + appId, ClusterDTO[].class,
someClusters, clusterResponse);
restInvoke(serviceLocator.getAdminService(Env.DEV) + "/configs/latest?clusterIds=100,101",
ConfigItemDTO[].class, someConfigItem, configItemResponse);
when(clusterAPI.getClustersByApp(Env.DEV, appId)).thenReturn(someClusters);
when(configAPI.getLatestConfigItemsByClusters(Env.DEV, Arrays
.asList(Long.valueOf(100), Long.valueOf(101)))).thenReturn(someConfigItem);
AppConfigVO appConfigVO = configService.loadLatestConfig(Env.DEV, appId);
......@@ -184,15 +170,6 @@ public class ConfigServiceTest {
assertEquals(appConfigVO.getOverrideClusterConfigs().size(), 1);
}
private <T> void restInvoke(String url, Class<T> responseType, T result,
ResponseEntity someResponse) {
when(
restTemplate.exchange(eq(url), eq(HttpMethod.GET), any(HttpEntity.class), eq(responseType)))
.thenReturn(someResponse);
when(someResponse.getStatusCode()).thenReturn(HttpStatus.OK);
when(someResponse.getBody()).thenReturn(result);
}
private VersionDTO assembleVersion(long appId, String versionName, long releaseId) {
VersionDTO version = new VersionDTO();
version.setAppId(appId);
......@@ -236,10 +213,14 @@ public class ConfigServiceTest {
private ConfigItemDTO[] assembleConfigItems() {
ConfigItemDTO[] configItems = new ConfigItemDTO[5];
configItems[0] = assembleConfigItem(100, Constants.DEFAULT_CLUSTER_NAME, 6666, "6666.k1", "6666.v1");
configItems[1] = assembleConfigItem(100, Constants.DEFAULT_CLUSTER_NAME, 6666, "6666.k2", "6666.v2");
configItems[2] = assembleConfigItem(100, Constants.DEFAULT_CLUSTER_NAME, 6666, "6666.k3", "6666.v3");
configItems[3] = assembleConfigItem(100, Constants.DEFAULT_CLUSTER_NAME, 5555, "5555.k1", "5555.v1");
configItems[0] =
assembleConfigItem(100, Constants.DEFAULT_CLUSTER_NAME, 6666, "6666.k1", "6666.v1");
configItems[1] =
assembleConfigItem(100, Constants.DEFAULT_CLUSTER_NAME, 6666, "6666.k2", "6666.v2");
configItems[2] =
assembleConfigItem(100, Constants.DEFAULT_CLUSTER_NAME, 6666, "6666.k3", "6666.v3");
configItems[3] =
assembleConfigItem(100, Constants.DEFAULT_CLUSTER_NAME, 5555, "5555.k1", "5555.v1");
configItems[4] = assembleConfigItem(101, "cluster1", 6666, "6666.k1", "6666.v1");
return configItems;
}
......
server:
port: 8080
port: 8070
spring:
application:
name: apollo-portal
datasource:
url: jdbc:h2:file:~/fxapolloportaldb
username: sa
password: sa
url: jdbc:h2:mem:~/fxapolloportaldb
jpa:
show-sql: true
hibernate:
naming_strategy: org.hibernate.cfg.EJB3NamingStrategy
logging:
level:
org.springframework.cloud: 'DEBUG'
file: /opt/logs/${ctrip.appid}/apollo-portal.log
ctrip:
appid: 100003173
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