Skip to content

Commit 0900d8d

Browse files
authored
Merge branch 'master' into master
2 parents 29ed1dd + 7c435bd commit 0900d8d

File tree

147 files changed

+6068
-242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+6068
-242
lines changed

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,18 @@ Java客户端不依赖任何框架,能够运行于所有Java运行时环境,
106106
* [开源配置中心Apollo的设计与实现](http://www.infoq.com/cn/articles/open-source-configuration-center-apollo)
107107

108108
# Support
109-
![tech-support-qq](https://raw.githubusercontent.com/ctripcorp/apollo/master/doc/images/tech-support-qq.png)
109+
<table>
110+
<thead>
111+
<th>Apollo配置中心技术支持②群<br />群号:904287263</th>
112+
<th>Apollo配置中心技术支持①群<br />群号:375526581(已满)</th>
113+
</thead>
114+
<tbody>
115+
<tr>
116+
<td><img src="https://raw.githubusercontent.com/ctripcorp/apollo/master/doc/images/tech-support-qq-2.png" alt="tech-support-qq-2"></td>
117+
<td><img src="https://raw.githubusercontent.com/ctripcorp/apollo/master/doc/images/tech-support-qq-1.png" alt="tech-support-qq-1"></td>
118+
</tr>
119+
</tbody>
120+
</table>
110121

111122
# Contribution
112123
* Source Code: https://github.com/ctripcorp/apollo
@@ -206,3 +217,13 @@ The project is licensed under the [Apache 2 license](https://github.com/ctripcor
206217
![万谷盛世](https://raw.githubusercontent.com/ctripcorp/apollo/master/doc/images/known-users/wgss.png)
207218
![铂涛旅行](https://raw.githubusercontent.com/ctripcorp/apollo/master/doc/images/known-users/plateno.png)
208219
![乐心](https://raw.githubusercontent.com/ctripcorp/apollo/master/doc/images/known-users/lifesense.png)
220+
![亿投传媒](https://raw.githubusercontent.com/ctripcorp/apollo/master/doc/images/known-users/reachmedia.png)
221+
![股先生](https://raw.githubusercontent.com/ctripcorp/apollo/master/doc/images/known-users/guxiansheng.png)
222+
![财学堂](https://raw.githubusercontent.com/ctripcorp/apollo/master/doc/images/known-users/caixuetang.png)
223+
![4399](https://raw.githubusercontent.com/ctripcorp/apollo/master/doc/images/known-users/4399.png)
224+
![汽车之家](https://raw.githubusercontent.com/ctripcorp/apollo/master/doc/images/known-users/autohome.png)
225+
![面包财经](https://raw.githubusercontent.com/ctripcorp/apollo/master/doc/images/known-users/mbcaijing.png)
226+
![虎扑](https://raw.githubusercontent.com/ctripcorp/apollo/master/doc/images/known-users/hoopchina.png)
227+
![搜狐汽车](https://raw.githubusercontent.com/ctripcorp/apollo/master/doc/images/known-users/sohu-auto.png)
228+
![量富征信](https://raw.githubusercontent.com/ctripcorp/apollo/master/doc/images/known-users/liangfuzhengxin.png)
229+
![卖好车](https://raw.githubusercontent.com/ctripcorp/apollo/master/doc/images/known-users/maihaoche.png)

apollo-adminservice/src/main/docker/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ MAINTAINER ameizi <sxyx2008@163.com>
99

1010
ENV VERSION 1.1.0-SNAPSHOT
1111

12-
RUN echo "http://mirrors.aliyun.com/alpine/v3.6/main" > /etc/apk/repositories \
13-
&& echo "http://mirrors.aliyun.com/alpine/v3.6/community" >> /etc/apk/repositories \
12+
RUN echo "http://mirrors.aliyun.com/alpine/v3.8/main" > /etc/apk/repositories \
13+
&& echo "http://mirrors.aliyun.com/alpine/v3.8/community" >> /etc/apk/repositories \
1414
&& apk update upgrade \
1515
&& apk add --no-cache procps unzip curl bash tzdata \
1616
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \

apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/AdminServiceApplication.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
import com.ctrip.framework.apollo.biz.ApolloBizConfig;
44
import com.ctrip.framework.apollo.common.ApolloCommonConfig;
55

6-
import org.springframework.boot.actuate.system.ApplicationPidFileWriter;
7-
import org.springframework.boot.actuate.system.EmbeddedServerPortFileWriter;
6+
import org.springframework.boot.SpringApplication;
87
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
9-
import org.springframework.boot.builder.SpringApplicationBuilder;
108
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
11-
import org.springframework.context.ConfigurableApplicationContext;
129
import org.springframework.context.annotation.ComponentScan;
1310
import org.springframework.context.annotation.Configuration;
1411
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@@ -25,9 +22,6 @@
2522
AdminServiceApplication.class})
2623
public class AdminServiceApplication {
2724
public static void main(String[] args) {
28-
ConfigurableApplicationContext context =
29-
new SpringApplicationBuilder(AdminServiceApplication.class).run(args);
30-
context.addApplicationListener(new ApplicationPidFileWriter());
31-
context.addApplicationListener(new EmbeddedServerPortFileWriter());
25+
SpringApplication.run(AdminServiceApplication.class, args);
3226
}
3327
}

apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ItemController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public ItemDTO create(@PathVariable("appId") String appId,
4343
ConfigChangeContentBuilder builder = new ConfigChangeContentBuilder();
4444
Item managedEntity = itemService.findOne(appId, clusterName, namespaceName, entity.getKey());
4545
if (managedEntity != null) {
46-
throw new BadRequestException("item already exist");
46+
throw new BadRequestException("item already exists");
4747
} else {
4848
entity = itemService.save(entity);
4949
builder.createItem(entity);

apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ReleaseController.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,35 @@ public void rollback(@PathVariable("releaseId") long releaseId,
176176
Topics.APOLLO_RELEASE_TOPIC);
177177
}
178178

179+
@Transactional
180+
@RequestMapping(path = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/gray-del-releases", method = RequestMethod.POST)
181+
public ReleaseDTO publish(@PathVariable("appId") String appId,
182+
@PathVariable("clusterName") String clusterName,
183+
@PathVariable("namespaceName") String namespaceName,
184+
@RequestParam("operator") String operator,
185+
@RequestParam("releaseName") String releaseName,
186+
@RequestParam(name = "comment", required = false) String releaseComment,
187+
@RequestParam(name = "isEmergencyPublish", defaultValue = "false") boolean isEmergencyPublish,
188+
@RequestParam(name = "grayDelKeys") Set<String> grayDelKeys){
189+
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
190+
if (namespace == null) {
191+
throw new NotFoundException(String.format("Could not find namespace for %s %s %s", appId,
192+
clusterName, namespaceName));
193+
}
194+
195+
Release release = releaseService.grayDeletionPublish(namespace, releaseName, releaseComment, operator, isEmergencyPublish, grayDelKeys);
196+
197+
//send release message
198+
Namespace parentNamespace = namespaceService.findParentNamespace(namespace);
199+
String messageCluster;
200+
if (parentNamespace != null) {
201+
messageCluster = parentNamespace.getClusterName();
202+
} else {
203+
messageCluster = clusterName;
204+
}
205+
messageSender.sendMessage(ReleaseMessageKeyGenerator.generate(appId, messageCluster, namespaceName),
206+
Topics.APOLLO_RELEASE_TOPIC);
207+
return BeanUtils.transfrom(ReleaseDTO.class, release);
208+
}
209+
179210
}

apollo-adminservice/src/main/resources/application.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ server:
1111
port: 8090
1212

1313
logging:
14-
file: /opt/logs/100003172/apollo-adminservice.log
14+
path: /opt/logs/100003172
15+
file: ${logging.path}/apollo-adminservice.log

apollo-adminservice/src/main/resources/logback.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,22 @@
33
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
44
<property name="LOG_FILE"
55
value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}apollo-adminservice.log}" />
6+
<property name="LOG_PATH" value="${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}" />
67
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
78
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
89
<root level="INFO">
910
<appender-ref ref="FILE" />
1011
<appender-ref ref="CONSOLE" />
1112
</root>
13+
14+
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
15+
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
16+
<fileNamePattern>${LOG_PATH}/apollo-adminservice.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
17+
<maxFileSize>50MB</maxFileSize>
18+
<maxHistory>30</maxHistory>
19+
</rollingPolicy>
20+
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
21+
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
22+
</encoder>
23+
</appender>
1224
</configuration>

apollo-assembly/src/main/java/com/ctrip/framework/apollo/assembly/ApolloApplication.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import org.slf4j.Logger;
88
import org.slf4j.LoggerFactory;
9-
import org.springframework.boot.actuate.system.ApplicationPidFileWriter;
109
import org.springframework.boot.autoconfigure.SpringBootApplication;
1110
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
1211
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
@@ -26,7 +25,6 @@ public static void main(String[] args) throws Exception {
2625
*/
2726
ConfigurableApplicationContext commonContext =
2827
new SpringApplicationBuilder(ApolloApplication.class).web(false).run(args);
29-
commonContext.addApplicationListener(new ApplicationPidFileWriter());
3028
logger.info(commonContext.getId() + " isActive: " + commonContext.isActive());
3129

3230
/**

apollo-assembly/src/test/java/com/ctrip/framework/apollo/assembly/LocalApolloApplication.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import org.slf4j.Logger;
88
import org.slf4j.LoggerFactory;
9-
import org.springframework.boot.actuate.system.ApplicationPidFileWriter;
109
import org.springframework.boot.autoconfigure.SpringBootApplication;
1110
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
1211
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
@@ -26,7 +25,6 @@ public static void main(String[] args) throws Exception {
2625
*/
2726
ConfigurableApplicationContext commonContext =
2827
new SpringApplicationBuilder(ApolloApplication.class).web(false).run(args);
29-
commonContext.addApplicationListener(new ApplicationPidFileWriter());
3028
logger.info(commonContext.getId() + " isActive: " + commonContext.isActive());
3129

3230
/**

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseService.java

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,49 @@ public Release publish(Namespace namespace, String releaseName, String releaseCo
185185
return release;
186186
}
187187

188+
private Release publishBranchNamespace(Namespace parentNamespace, Namespace childNamespace,
189+
Map<String, String> childNamespaceItems,
190+
String releaseName, String releaseComment,
191+
String operator, boolean isEmergencyPublish, Set<String> grayDelKeys) {
192+
Release parentLatestRelease = findLatestActiveRelease(parentNamespace);
193+
Map<String, String> parentConfigurations = parentLatestRelease != null ?
194+
gson.fromJson(parentLatestRelease.getConfigurations(),
195+
GsonType.CONFIG) : new HashMap<>();
196+
long baseReleaseId = parentLatestRelease == null ? 0 : parentLatestRelease.getId();
197+
198+
Map<String, String> configsToPublish = mergeConfiguration(parentConfigurations, childNamespaceItems);
199+
200+
if(!(grayDelKeys == null || grayDelKeys.size()==0)){
201+
for (String key : grayDelKeys){
202+
configsToPublish.remove(key);
203+
}
204+
}
205+
206+
return branchRelease(parentNamespace, childNamespace, releaseName, releaseComment,
207+
configsToPublish, baseReleaseId, operator,
208+
ReleaseOperation.GRAY_RELEASE, isEmergencyPublish);
209+
210+
}
211+
212+
@Transactional
213+
public Release grayDeletionPublish(Namespace namespace, String releaseName, String releaseComment,
214+
String operator, boolean isEmergencyPublish, Set<String> grayDelKeys) {
215+
216+
checkLock(namespace, isEmergencyPublish, operator);
217+
218+
Map<String, String> operateNamespaceItems = getNamespaceItems(namespace);
219+
220+
Namespace parentNamespace = namespaceService.findParentNamespace(namespace);
221+
222+
//branch release
223+
if (parentNamespace != null) {
224+
return publishBranchNamespace(parentNamespace, namespace, operateNamespaceItems,
225+
releaseName, releaseComment, operator, isEmergencyPublish, grayDelKeys);
226+
}else {
227+
throw new NotFoundException("Parent namespace not found");
228+
}
229+
}
230+
188231
private void checkLock(Namespace namespace, boolean isEmergencyPublish, String operator) {
189232
if (!isEmergencyPublish) {
190233
NamespaceLock lock = namespaceLockService.findLock(namespace.getId());
@@ -222,17 +265,8 @@ private Release publishBranchNamespace(Namespace parentNamespace, Namespace chil
222265
Map<String, String> childNamespaceItems,
223266
String releaseName, String releaseComment,
224267
String operator, boolean isEmergencyPublish) {
225-
Release parentLatestRelease = findLatestActiveRelease(parentNamespace);
226-
Map<String, String> parentConfigurations = parentLatestRelease != null ?
227-
gson.fromJson(parentLatestRelease.getConfigurations(),
228-
GsonType.CONFIG) : new HashMap<>();
229-
long baseReleaseId = parentLatestRelease == null ? 0 : parentLatestRelease.getId();
230-
231-
Map<String, String> childNamespaceToPublishConfigs = mergeConfiguration(parentConfigurations, childNamespaceItems);
232-
233-
return branchRelease(parentNamespace, childNamespace, releaseName, releaseComment,
234-
childNamespaceToPublishConfigs, baseReleaseId, operator,
235-
ReleaseOperation.GRAY_RELEASE, isEmergencyPublish);
268+
return publishBranchNamespace(parentNamespace, childNamespace, childNamespaceItems, releaseName, releaseComment,
269+
operator, isEmergencyPublish, null);
236270

237271
}
238272

apollo-client/src/main/java/com/ctrip/framework/apollo/Config.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.ctrip.framework.apollo;
22

3+
import com.ctrip.framework.apollo.enums.ConfigSourceType;
34
import com.google.common.base.Function;
45

56
import java.util.Date;
@@ -178,6 +179,14 @@ public interface Config {
178179
*/
179180
public void addChangeListener(ConfigChangeListener listener, Set<String> interestedKeys);
180181

182+
/**
183+
* Remove the change listener
184+
*
185+
* @param listener the specific config change listener to remove
186+
* @return true if the specific config change listener is found and removed
187+
*/
188+
public boolean removeChangeListener(ConfigChangeListener listener);
189+
181190
/**
182191
* Return a set of the property names
183192
*
@@ -195,4 +204,11 @@ public interface Config {
195204
* @return the property value
196205
*/
197206
public <T> T getProperty(String key, Function<String, T> function, T defaultValue);
207+
208+
/**
209+
* Return the config's source type, i.e. where is the config loaded from
210+
*
211+
* @return the config's source type
212+
*/
213+
public ConfigSourceType getSourceType();
198214
}

apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigFile.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.ctrip.framework.apollo;
22

33
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
4+
import com.ctrip.framework.apollo.enums.ConfigSourceType;
45

56
/**
67
* @author Jason Song(song_s@ctrip.com)
@@ -36,4 +37,19 @@ public interface ConfigFile {
3637
* @param listener the config file change listener
3738
*/
3839
void addChangeListener(ConfigFileChangeListener listener);
40+
41+
/**
42+
* Remove the change listener
43+
*
44+
* @param listener the specific config change listener to remove
45+
* @return true if the specific config change listener is found and removed
46+
*/
47+
public boolean removeChangeListener(ConfigChangeListener listener);
48+
49+
/**
50+
* Return the config's source type, i.e. where is the config loaded from
51+
*
52+
* @return the config's source type
53+
*/
54+
public ConfigSourceType getSourceType();
3955
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.ctrip.framework.apollo.enums;
2+
3+
/**
4+
* To indicate the config's source type, i.e. where is the config loaded from
5+
*/
6+
public enum ConfigSourceType {
7+
REMOTE("Loaded from remote config service"), LOCAL("Loaded from local cache"), NONE("Load failed");
8+
9+
private final String description;
10+
11+
ConfigSourceType(String description) {
12+
this.description = description;
13+
}
14+
15+
public String getDescription() {
16+
return description;
17+
}
18+
}

apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ public void addChangeListener(ConfigChangeListener listener, Set<String> interes
8585
}
8686
}
8787

88+
@Override
89+
public boolean removeChangeListener(ConfigChangeListener listener) {
90+
m_interestedKeys.remove(listener);
91+
return m_listeners.remove(listener);
92+
}
93+
8894
@Override
8995
public Integer getIntProperty(String key, Integer defaultValue) {
9096
try {

apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfigFile.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.ctrip.framework.apollo.internals;
22

3+
import com.ctrip.framework.apollo.ConfigChangeListener;
4+
import com.ctrip.framework.apollo.enums.ConfigSourceType;
35
import java.util.List;
46
import java.util.Properties;
57
import java.util.concurrent.ExecutorService;
@@ -25,10 +27,12 @@
2527
public abstract class AbstractConfigFile implements ConfigFile, RepositoryChangeListener {
2628
private static final Logger logger = LoggerFactory.getLogger(AbstractConfigFile.class);
2729
private static ExecutorService m_executorService;
28-
protected ConfigRepository m_configRepository;
29-
protected String m_namespace;
30-
protected AtomicReference<Properties> m_configProperties;
31-
private List<ConfigFileChangeListener> m_listeners = Lists.newCopyOnWriteArrayList();
30+
protected final ConfigRepository m_configRepository;
31+
protected final String m_namespace;
32+
protected final AtomicReference<Properties> m_configProperties;
33+
private final List<ConfigFileChangeListener> m_listeners = Lists.newCopyOnWriteArrayList();
34+
35+
private volatile ConfigSourceType m_sourceType = ConfigSourceType.NONE;
3236

3337
static {
3438
m_executorService = Executors.newCachedThreadPool(ApolloThreadFactory
@@ -45,6 +49,7 @@ public AbstractConfigFile(String namespace, ConfigRepository configRepository) {
4549
private void initialize() {
4650
try {
4751
m_configProperties.set(m_configRepository.getConfig());
52+
m_sourceType = m_configRepository.getSourceType();
4853
} catch (Throwable ex) {
4954
Tracer.logError(ex);
5055
logger.warn("Init Apollo Config File failed - namespace: {}, reason: {}.",
@@ -74,6 +79,7 @@ public synchronized void onRepositoryChange(String namespace, Properties newProp
7479
String oldValue = getContent();
7580

7681
update(newProperties);
82+
m_sourceType = m_configRepository.getSourceType();
7783

7884
String newValue = getContent();
7985

@@ -97,6 +103,16 @@ public void addChangeListener(ConfigFileChangeListener listener) {
97103
}
98104
}
99105

106+
@Override
107+
public boolean removeChangeListener(ConfigChangeListener listener) {
108+
return m_listeners.remove(listener);
109+
}
110+
111+
@Override
112+
public ConfigSourceType getSourceType() {
113+
return m_sourceType;
114+
}
115+
100116
private void fireConfigChange(final ConfigFileChangeEvent changeEvent) {
101117
for (final ConfigFileChangeListener listener : m_listeners) {
102118
m_executorService.submit(new Runnable() {

0 commit comments

Comments
 (0)