Commit 23a9ba4d by lepdou

Merge pull request #217 from lepdou/portal_db

envs 配置在db里
parents 39c0c08a 6a50e2a2
package com.ctrip.framework.apollo.portal; package com.ctrip.framework.apollo.portal;
import com.google.common.collect.Lists;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
...@@ -22,6 +25,8 @@ import org.springframework.stereotype.Component; ...@@ -22,6 +25,8 @@ import org.springframework.stereotype.Component;
import com.ctrip.framework.apollo.core.enums.Env; import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.portal.api.AdminServiceAPI; import com.ctrip.framework.apollo.portal.api.AdminServiceAPI;
import com.ctrip.framework.apollo.portal.entity.po.ServerConfig;
import com.ctrip.framework.apollo.portal.repository.ServerConfigRepository;
@Component @Component
public class PortalSettings { public class PortalSettings {
...@@ -30,12 +35,15 @@ public class PortalSettings { ...@@ -30,12 +35,15 @@ public class PortalSettings {
private static final int HEALTH_CHECK_INTERVAL = 5000; private static final int HEALTH_CHECK_INTERVAL = 5000;
@Value("#{'${apollo.portal.env}'.split(',')}") @Value("#{'${apollo.portal.envs}'.split(',')}")
private List<String> allStrEnvs; private List<String> allStrEnvs;
@Autowired @Autowired
ApplicationContext applicationContext; ApplicationContext applicationContext;
@Autowired
private ServerConfigRepository serverConfigRepository;
private List<Env> allEnvs = new ArrayList<Env>(); private List<Env> allEnvs = new ArrayList<Env>();
private List<Env> activeEnvs; private List<Env> activeEnvs;
...@@ -47,11 +55,20 @@ public class PortalSettings { ...@@ -47,11 +55,20 @@ public class PortalSettings {
@PostConstruct @PostConstruct
private void postConstruct() { private void postConstruct() {
//init origin config envs //初始化portal支持操作的环境集合,线上的portal可能支持所有的环境操作,而线下环境则支持一部分.
// 每个环境的portal支持哪些环境配置在数据库里
ServerConfig serverConfig = serverConfigRepository.findByKey("apollo.portal.envs");
// TODO: 16/5/24 线上环境暂时从本地配置里拿,之后也放在数据库上并提供界面可操作
if (serverConfig != null){//如果db有配置则从db里取
String[] configedEnvs = serverConfig.getValue().split(",");
allStrEnvs = Arrays.asList(configedEnvs);
}
for (String e : allStrEnvs) { for (String e : allStrEnvs) {
allEnvs.add(Env.valueOf(e.toUpperCase())); allEnvs.add(Env.valueOf(e.toUpperCase()));
} }
for (Env env : allEnvs) { for (Env env : allEnvs) {
envStatusMark.put(env, true); envStatusMark.put(env, true);
} }
......
spring.application.name= apollo-portal spring.application.name= apollo-portal
apollo.portal.env= fat,uat apollo.portal.envs= fat,uat,pro
ctrip.appid= 100003173 ctrip.appid= 100003173
server.port= 8070 server.port= 8070
logging.file= /opt/logs/100003173/apollo-portal.log logging.file= /opt/logs/100003173/apollo-portal.log
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