Commit fc369a00 by lepdou

portal support switch env

parent b271bebe
...@@ -24,14 +24,20 @@ public class ConfigController { ...@@ -24,14 +24,20 @@ public class ConfigController {
public AppConfigVO detail(@PathVariable String appId, @PathVariable String env, public AppConfigVO detail(@PathVariable String appId, @PathVariable String env,
@PathVariable long versionId) { @PathVariable long versionId) {
if (Strings.isNullOrEmpty(appId)) { if (Strings.isNullOrEmpty(appId) || Strings.isNullOrEmpty(env)) {
throw new NotFoundException(); throw new NotFoundException();
} }
Apollo.Env e = Apollo.Env.valueOf(env);
if (versionId == PortalConstants.LASTEST_VERSION_ID) { if (versionId == PortalConstants.LASTEST_VERSION_ID) {
return configService.loadLatestConfig(Apollo.Env.DEV, appId);
return configService.loadLatestConfig(e, appId);
} else if (versionId > 0) { } else if (versionId > 0) {
return configService.loadReleaseConfig(Apollo.Env.DEV, appId, versionId);
return configService.loadReleaseConfig(e, appId, versionId);
} else { } else {
throw new NotFoundException(); 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; package com.ctrip.apollo.portal.controller;
import com.google.common.base.Strings;
import com.ctrip.apollo.Apollo; import com.ctrip.apollo.Apollo;
import com.ctrip.apollo.core.dto.VersionDTO; import com.ctrip.apollo.core.dto.VersionDTO;
import com.ctrip.apollo.portal.service.VersionService; import com.ctrip.apollo.portal.service.VersionService;
...@@ -9,6 +11,7 @@ import org.springframework.web.bind.annotation.PathVariable; ...@@ -9,6 +11,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
import java.util.List; import java.util.List;
@RestController @RestController
...@@ -20,6 +23,11 @@ public class VersionController { ...@@ -20,6 +23,11 @@ public class VersionController {
@RequestMapping("/{appId}/{env}") @RequestMapping("/{appId}/{env}")
public List<VersionDTO> versions(@PathVariable String appId, @PathVariable String 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 { ...@@ -49,10 +49,11 @@ public class ConfigService {
long releaseId = getReleaseIdFromVersionId(env, versionId); long releaseId = getReleaseIdFromVersionId(env, versionId);
if (releaseId == -1) { if (releaseId == -1) {
logger.warn("get release id error env:{}, app id:{}, version id:{}", env, appId, versionId);
return null; return null;
} }
ReleaseSnapshotDTO[] releaseSnapShots = configAPI.getConfigByReleaseId(Env.DEV, releaseId); ReleaseSnapshotDTO[] releaseSnapShots = configAPI.getConfigByReleaseId(env, releaseId);
if (releaseSnapShots == null || releaseSnapShots.length == 0) { if (releaseSnapShots == null || releaseSnapShots.length == 0) {
return null; return null;
} }
...@@ -83,7 +84,8 @@ public class ConfigService { ...@@ -83,7 +84,8 @@ public class ConfigService {
private void collectDefaultClusterConfigs(String appId, ReleaseSnapshotDTO snapShot, private void collectDefaultClusterConfigs(String appId, ReleaseSnapshotDTO snapShot,
AppConfigVO appConfigVO) { 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(); List<AppConfigVO.OverrideAppConfig> overrideAppConfigs = appConfigVO.getOverrideAppConfigs();
...@@ -107,7 +109,7 @@ public class ConfigService { ...@@ -107,7 +109,7 @@ public class ConfigService {
/** /**
* appId -> List<KV> * 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)) { if (configJson == null || "".equals(configJson)) {
return Maps.newHashMap(); return Maps.newHashMap();
} }
...@@ -120,8 +122,10 @@ public class ConfigService { ...@@ -120,8 +122,10 @@ public class ConfigService {
try { try {
kvMaps = objectMapper.readValue(configJson, Map.class); kvMaps = objectMapper.readValue(configJson, Map.class);
} catch (IOException e) { } 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()) { for (Map.Entry<String, String> entry : kvMaps.entrySet()) {
key = entry.getKey(); key = entry.getKey();
value = entry.getValue(); value = entry.getValue();
...@@ -151,7 +155,7 @@ public class ConfigService { ...@@ -151,7 +155,7 @@ public class ConfigService {
new AppConfigVO.OverrideClusterConfig(); new AppConfigVO.OverrideClusterConfig();
overrideClusterConfig.setClusterName(snapShot.getClusterName()); overrideClusterConfig.setClusterName(snapShot.getClusterName());
// todo step1: cluster special config can't override other app config // 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); overrideClusterConfigs.add(overrideClusterConfig);
} }
...@@ -242,7 +246,7 @@ public class ConfigService { ...@@ -242,7 +246,7 @@ public class ConfigService {
for (ConfigItemDTO config : clusterConfigs) { for (ConfigItemDTO config : clusterConfigs) {
String targetAppId = config.getAppId(); String targetAppId = config.getAppId();
if (appId == targetAppId) {// app self's configs if (appId.equals(targetAppId)) {// app self's configs
defaultClusterConfigs.add(config); defaultClusterConfigs.add(config);
} else {// override other app configs } else {// override other app configs
if (appIdMapOverrideAppConfig == null) { if (appIdMapOverrideAppConfig == null) {
......
...@@ -20,4 +20,4 @@ ctrip: ...@@ -20,4 +20,4 @@ ctrip:
apollo: apollo:
portal: portal:
env: dev,fws,uat env: local,dev,fws,uat
application_module.controller("AppConfigController", application_module.controller("AppConfigController",
['$scope', '$rootScope', '$state', '$location', 'toastr', ['$scope', '$rootScope', '$state', '$location', 'toastr',
'AppService', 'ConfigService', 'VersionService', 'AppService', 'EnvService', 'ConfigService', 'VersionService',
function ($scope, $rootScope, $state, $location, toastr, AppService, ConfigService, VersionService) { function ($scope, $rootScope, $state, $location, toastr, AppService, EnvService, ConfigService, VersionService) {
var configLocation = { var configLocation = {
appId: $rootScope.appId, appId: $rootScope.appId,
env: 'uat', env: 'LOCAL',
versionId: -1 versionId: -1
}; };
...@@ -15,7 +15,11 @@ application_module.controller("AppConfigController", ...@@ -15,7 +15,11 @@ application_module.controller("AppConfigController",
$scope.configLocation = configLocation; $scope.configLocation = configLocation;
/**env*/ /**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) { $scope.switchEnv = function (selectedEnv) {
configLocation.env = 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 @@ ...@@ -107,25 +107,6 @@
</tr> </tr>
</tbody> </tbody>
</table> </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>
</div> </div>
......
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
<!--biz script--> <!--biz script-->
<script type="application/javascript" src="../../scripts/app.js"></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/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/ConfigService.js"></script>
<script type="application/javascript" src="../../scripts/services/VersionService.js"></script> <script type="application/javascript" src="../../scripts/services/VersionService.js"></script>
<script type="application/javascript" src="../../scripts/controller/app/AppConfigController.js"></script> <script type="application/javascript" src="../../scripts/controller/app/AppConfigController.js"></script>
......
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