提交 fc369a00 编写于 作者: L lepdou

portal support switch env

上级 b271bebe
......@@ -24,14 +24,20 @@ public class ConfigController {
public AppConfigVO detail(@PathVariable String appId, @PathVariable String env,
@PathVariable long versionId) {
if (Strings.isNullOrEmpty(appId)) {
if (Strings.isNullOrEmpty(appId) || Strings.isNullOrEmpty(env)) {
throw new NotFoundException();
}
Apollo.Env e = Apollo.Env.valueOf(env);
if (versionId == PortalConstants.LASTEST_VERSION_ID) {
return configService.loadLatestConfig(Apollo.Env.DEV, appId);
return configService.loadLatestConfig(e, appId);
} else if (versionId > 0) {
return configService.loadReleaseConfig(Apollo.Env.DEV, appId, versionId);
return configService.loadReleaseConfig(e, appId, versionId);
} else {
throw new NotFoundException();
}
......
package com.ctrip.apollo.portal.controller;
import com.ctrip.apollo.Apollo;
import com.ctrip.apollo.portal.PortalSettings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/envs")
public class EnvController {
@Autowired
private PortalSettings portalSettings;
@RequestMapping("")
public List<Apollo.Env> envs(){
return portalSettings.getEnvs();
}
}
package com.ctrip.apollo.portal.controller;
import com.google.common.base.Strings;
import com.ctrip.apollo.Apollo;
import com.ctrip.apollo.core.dto.VersionDTO;
import com.ctrip.apollo.portal.service.VersionService;
......@@ -9,6 +11,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
import java.util.List;
@RestController
......@@ -20,6 +23,11 @@ public class VersionController {
@RequestMapping("/{appId}/{env}")
public List<VersionDTO> versions(@PathVariable String appId, @PathVariable String env) {
return versionService.findVersionsByApp(Apollo.Env.DEV, appId);
if (Strings.isNullOrEmpty(appId) || Strings.isNullOrEmpty(env)){
return Collections.EMPTY_LIST;
}
return versionService.findVersionsByApp(Apollo.Env.valueOf(env), appId);
}
}
......@@ -49,10 +49,11 @@ public class ConfigService {
long releaseId = getReleaseIdFromVersionId(env, versionId);
if (releaseId == -1) {
logger.warn("get release id error env:{}, app id:{}, version id:{}", env, appId, versionId);
return null;
}
ReleaseSnapshotDTO[] releaseSnapShots = configAPI.getConfigByReleaseId(Env.DEV, releaseId);
ReleaseSnapshotDTO[] releaseSnapShots = configAPI.getConfigByReleaseId(env, releaseId);
if (releaseSnapShots == null || releaseSnapShots.length == 0) {
return null;
}
......@@ -83,7 +84,8 @@ public class ConfigService {
private void collectDefaultClusterConfigs(String appId, ReleaseSnapshotDTO snapShot,
AppConfigVO appConfigVO) {
Map<String, List<ConfigItemDTO>> groupedConfigs = groupConfigsByApp(snapShot.getConfigurations());
Map<String, List<ConfigItemDTO>> groupedConfigs =
groupConfigsByApp(appId, snapShot.getConfigurations());
List<AppConfigVO.OverrideAppConfig> overrideAppConfigs = appConfigVO.getOverrideAppConfigs();
......@@ -107,7 +109,7 @@ public class ConfigService {
/**
* appId -> List<KV>
*/
private Map<String, List<ConfigItemDTO>> groupConfigsByApp(String configJson) {
private Map<String, List<ConfigItemDTO>> groupConfigsByApp(String selfAppId, String configJson) {
if (configJson == null || "".equals(configJson)) {
return Maps.newHashMap();
}
......@@ -120,8 +122,10 @@ public class ConfigService {
try {
kvMaps = objectMapper.readValue(configJson, Map.class);
} catch (IOException e) {
// todo log
logger.error("parse release snapshot json error. app id:{}", selfAppId);
return Maps.newHashMap();
}
for (Map.Entry<String, String> entry : kvMaps.entrySet()) {
key = entry.getKey();
value = entry.getValue();
......@@ -151,7 +155,7 @@ public class ConfigService {
new AppConfigVO.OverrideClusterConfig();
overrideClusterConfig.setClusterName(snapShot.getClusterName());
// todo step1: cluster special config can't override other app config
overrideClusterConfig.setConfigs(groupConfigsByApp(snapShot.getConfigurations()).get(appId));
overrideClusterConfig.setConfigs(groupConfigsByApp(appId, snapShot.getConfigurations()).get(appId));
overrideClusterConfigs.add(overrideClusterConfig);
}
......@@ -242,7 +246,7 @@ public class ConfigService {
for (ConfigItemDTO config : clusterConfigs) {
String targetAppId = config.getAppId();
if (appId == targetAppId) {// app self's configs
if (appId.equals(targetAppId)) {// app self's configs
defaultClusterConfigs.add(config);
} else {// override other app configs
if (appIdMapOverrideAppConfig == null) {
......
......@@ -20,4 +20,4 @@ ctrip:
apollo:
portal:
env: dev,fws,uat
env: local,dev,fws,uat
application_module.controller("AppConfigController",
['$scope', '$rootScope', '$state', '$location', 'toastr',
'AppService', 'ConfigService', 'VersionService',
function ($scope, $rootScope, $state, $location, toastr, AppService, ConfigService, VersionService) {
'AppService', 'EnvService', 'ConfigService', 'VersionService',
function ($scope, $rootScope, $state, $location, toastr, AppService, EnvService, ConfigService, VersionService) {
var configLocation = {
appId: $rootScope.appId,
env: 'uat',
env: 'LOCAL',
versionId: -1
};
......@@ -15,7 +15,11 @@ application_module.controller("AppConfigController",
$scope.configLocation = configLocation;
/**env*/
$scope.envs = ['dev', 'fws', 'fat', 'uat', 'lpt', 'prod', 'tools'];
EnvService.getAllEnvs().then(function(result){
$scope.envs = result;
}, function(result){
toastr.error("加载环境信息失败", result);
});
$scope.switchEnv = function (selectedEnv) {
configLocation.env = selectedEnv;
......
appService.service('EnvService', ['$resource', '$q', function ($resource, $q) {
var env_resource = $resource('/envs', {}, {
all: {
method: 'GET',
isArray: true
}
});
return {
getAllEnvs: function getAllEnvs() {
var d = $q.defer();
env_resource.all({}, function (result) {
d.resolve(result);
}, function (result) {
d.reject(result);
});
return d.promise;
}
}
}]);
......@@ -107,25 +107,6 @@
</tr>
</tbody>
</table>
<nav class="text-right">
<ul class="pagination">
<li>
<a aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</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 aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
......
......@@ -60,6 +60,7 @@
<!--biz script-->
<script type="application/javascript" src="../../scripts/app.js"></script>
<script type="application/javascript" src="../../scripts/services/AppService.js"></script>
<script type="application/javascript" src="../../scripts/services/EnvService.js"></script>
<script type="application/javascript" src="../../scripts/services/ConfigService.js"></script>
<script type="application/javascript" src="../../scripts/services/VersionService.js"></script>
<script type="application/javascript" src="../../scripts/controller/app/AppConfigController.js"></script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册