Skip to content

Commit b1c42ef

Browse files
committed
Updates for moss-client:
1. Force service discovery to ZooKeeper for moss-client both 2.x and 1.x. 2. Remove '/infoLogFile' and '/errorLogFile' endpoint, use '/logfile' and '/logfile/{requiredLogFileName}'. 3. Add logFileRegistry for '/logfile' endpoint. 4. Change '/appInfo' to '/appinfo' endpoint. 5. Add hateoas support for moss-client 1.x. 6. Add '/prometheus' endpoint for both client by default. 7. Auto collect metadata for registration in {AutoRegistrationCustomizer} and {MetaDataProvider} 8. Support on outer servlet container such as Tomcat. @see {DiscoveryClientRegistrationInvoker} DiscoveryClient registration depends on {EmbeddedServletContainerInitializedEvent} in 1.5.x and {ServletWebServerInitializedEvent} in Spring Boot 2.x. The registration logic is in {AbstractAutoServiceRegistration} in Spring Boot 2.x and {AbstractDiscoveryLifecycle}. The spring cloud official has't been fixed it on thier repository issues, guess that won't be fixed. @see (spring-cloud/spring-cloud-commons@1d64629). So we had to manually publish an event for registration in outer Tomcat. 9. Add some default bootstrap configuration in META-INF/moss-client/bootstrap.properties. It will loaded by {ManagementEnvironmentCustomizer}. And the environment customizer is registered by spring.factories. Add the new client
1 parent 77000df commit b1c42ef

File tree

59 files changed

+1308
-1251
lines changed

Some content is hidden

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

59 files changed

+1308
-1251
lines changed
Lines changed: 128 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,139 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<modelVersion>4.0.0</modelVersion>
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
55

6-
<parent>
7-
<groupId>org.springframework.boot</groupId>
8-
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>1.5.13.RELEASE</version>
10-
</parent>
116

12-
<groupId>org.xujin.moss</groupId>
13-
<artifactId>moss-client-1.x</artifactId>
14-
<version>1.0.0.RELEASE</version>
15-
<packaging>jar</packaging>
7+
<groupId>org.xujin.moss</groupId>
8+
<artifactId>moss-client-1.x</artifactId>
9+
<version>1.0.0.RELEASE</version>
10+
<packaging>jar</packaging>
1611

17-
<name>moss-client-1.x</name>
18-
<description>moss-client-1.x</description>
12+
<name>moss-client-1.x</name>
13+
<description>moss-client-1.x</description>
1914

20-
<properties>
21-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22-
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
23-
<java.version>1.8</java.version>
24-
</properties>
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
18+
<java.version>1.8</java.version>
2519

26-
<dependencies>
27-
<dependency>
28-
<groupId>org.xujin.moss</groupId>
29-
<artifactId>moss-client-common</artifactId>
30-
<version>1.0.0.RELEASE</version>
31-
</dependency>
20+
<spring-boot-version>1.5.12.RELEASE</spring-boot-version>
21+
<spring-cloud-version>Edgware.SR4</spring-cloud-version>
22+
</properties>
3223

33-
<dependency>
34-
<groupId>org.apache.commons</groupId>
35-
<artifactId>commons-lang3</artifactId>
36-
<version>3.4</version>
37-
</dependency>
38-
<dependency>
39-
<groupId>org.springframework.boot</groupId>
40-
<artifactId>spring-boot-starter-actuator</artifactId>
41-
</dependency>
42-
<dependency>
43-
<groupId>org.springframework.boot</groupId>
44-
<artifactId>spring-boot-starter-web</artifactId>
45-
<scope>provided</scope>
46-
</dependency>
24+
<dependencyManagement>
25+
<dependencies>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-parent</artifactId>
29+
<version>${spring-boot-version}</version>
30+
<type>pom</type>
31+
<scope>import</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.cloud</groupId>
35+
<artifactId>spring-cloud-starter-parent</artifactId>
36+
<version>${spring-cloud-version}</version>
37+
<type>pom</type>
38+
<scope>import</scope>
39+
</dependency>
40+
</dependencies>
41+
</dependencyManagement>
4742

48-
<dependency>
49-
<groupId>org.jolokia</groupId>
50-
<artifactId>jolokia-core</artifactId>
51-
</dependency>
52-
</dependencies>
43+
<dependencies>
44+
<dependency>
45+
<groupId>org.xujin.moss</groupId>
46+
<artifactId>moss-client-common</artifactId>
47+
<version>1.0.0.RELEASE</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.jolokia</groupId>
51+
<artifactId>jolokia-core</artifactId>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.springframework.cloud</groupId>
55+
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
56+
<version>RELEASE</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.springframework.boot</groupId>
60+
<artifactId>spring-boot-starter-actuator</artifactId>
61+
</dependency>
62+
<dependency>
63+
<groupId>io.prometheus</groupId>
64+
<artifactId>simpleclient_spring_boot</artifactId>
65+
<version>0.6.0</version>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.springframework.hateoas</groupId>
69+
<artifactId>spring-hateoas</artifactId>
70+
</dependency>
5371

54-
<build>
55-
<plugins>
56-
<plugin>
57-
<groupId>org.apache.maven.plugins</groupId>
58-
<artifactId>maven-resources-plugin</artifactId>
59-
<version>3.0.2</version>
60-
<executions>
61-
<execution>
62-
<id>copy-resources</id>
63-
<phase>validate</phase>
64-
<goals>
65-
<goal>copy-resources</goal>
66-
</goals>
67-
<configuration>
68-
<outputDirectory>${basedir}/target/classes</outputDirectory>
69-
<includeEmptyDirs>true</includeEmptyDirs>
70-
<resources>
71-
<resource>
72-
<directory>src/main/resource</directory>
73-
<filtering>true</filtering>
74-
</resource>
75-
</resources>
76-
</configuration>
77-
</execution>
78-
</executions>
79-
</plugin>
80-
<plugin>
81-
<artifactId>maven-compiler-plugin</artifactId>
82-
<version>3.7.0</version>
83-
<configuration>
84-
<source>1.8</source>
85-
<target>1.8</target>
86-
<encoding>UTF-8</encoding>
87-
</configuration>
88-
</plugin>
89-
<plugin>
90-
<groupId>org.apache.maven.plugins</groupId>
91-
<artifactId>maven-source-plugin</artifactId>
92-
<version>3.0.1</version>
93-
<executions>
94-
<execution>
95-
<id>attach-sources</id>
96-
<goals>
97-
<goal>jar-no-fork</goal>
98-
</goals>
99-
</execution>
100-
</executions>
101-
</plugin>
102-
</plugins>
103-
</build>
72+
<dependency>
73+
<groupId>org.springframework.boot</groupId>
74+
<artifactId>spring-boot-starter-web</artifactId>
75+
<scope>provided</scope>
76+
</dependency>
77+
<dependency>
78+
<groupId>org.springframework.boot</groupId>
79+
<artifactId>spring-boot-configuration-processor</artifactId>
80+
<optional>true</optional>
81+
</dependency>
82+
<dependency>
83+
<groupId>org.projectlombok</groupId>
84+
<artifactId>lombok</artifactId>
85+
<optional>true</optional>
86+
</dependency>
87+
</dependencies>
88+
89+
<build>
90+
<plugins>
91+
<plugin>
92+
<groupId>org.apache.maven.plugins</groupId>
93+
<artifactId>maven-resources-plugin</artifactId>
94+
<version>3.0.2</version>
95+
<executions>
96+
<execution>
97+
<id>copy-resources</id>
98+
<phase>validate</phase>
99+
<goals>
100+
<goal>copy-resources</goal>
101+
</goals>
102+
<configuration>
103+
<outputDirectory>${basedir}/target/classes</outputDirectory>
104+
<includeEmptyDirs>true</includeEmptyDirs>
105+
<resources>
106+
<resource>
107+
<directory>src/main/resource</directory>
108+
<filtering>true</filtering>
109+
</resource>
110+
</resources>
111+
</configuration>
112+
</execution>
113+
</executions>
114+
</plugin>
115+
<plugin>
116+
<artifactId>maven-compiler-plugin</artifactId>
117+
<version>3.7.0</version>
118+
<configuration>
119+
<source>1.8</source>
120+
<target>1.8</target>
121+
<encoding>UTF-8</encoding>
122+
</configuration>
123+
</plugin>
124+
<plugin>
125+
<groupId>org.apache.maven.plugins</groupId>
126+
<artifactId>maven-source-plugin</artifactId>
127+
<version>3.0.1</version>
128+
<executions>
129+
<execution>
130+
<id>attach-sources</id>
131+
<goals>
132+
<goal>jar-no-fork</goal>
133+
</goals>
134+
</execution>
135+
</executions>
136+
</plugin>
137+
</plugins>
138+
</build>
104139
</project>
Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
1-
package org.xujin.moss.config;
1+
package org.xujin.moss.client.config;
22

3+
import org.apache.curator.framework.CuratorFramework;
4+
import org.apache.curator.x.discovery.details.InstanceSerializer;
35
import org.springframework.beans.factory.ObjectProvider;
46
import org.springframework.beans.factory.annotation.Autowired;
5-
import org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration;
67
import org.springframework.boot.actuate.endpoint.PublicMetrics;
7-
import org.springframework.boot.actuate.health.HealthAggregator;
8-
import org.springframework.boot.actuate.health.HealthIndicator;
98
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
9+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
1010
import org.springframework.cache.CacheManager;
11+
import org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryProperties;
12+
import org.springframework.cloud.zookeeper.discovery.ZookeeperInstance;
13+
import org.springframework.cloud.zookeeper.support.ServiceDiscoveryCustomizer;
1114
import org.springframework.context.annotation.Bean;
15+
import org.springframework.context.annotation.Configuration;
1216
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
1317
import org.springframework.core.env.Environment;
14-
import org.xujin.moss.endpoint.*;
18+
import org.xujin.moss.client.endpoint.*;
1519

16-
import java.util.*;
20+
import java.util.ArrayList;
21+
import java.util.Collection;
22+
import java.util.Collections;
23+
import java.util.List;
1724

18-
@ManagementContextConfiguration
25+
@Configuration
26+
@EnableConfigurationProperties(LogFileRegistry.class)
1927
public class AdminEndPointConfiguration {
2028

2129
@Autowired
@@ -35,13 +43,8 @@ public JarDependenciesEndpoint jarDependenciesEndpoint() {
3543
}
3644

3745
@Bean
38-
public InfoLogFileEndPoint infoLogFileEndPoin() {
39-
return new InfoLogFileEndPoint();
40-
}
41-
42-
@Bean
43-
public ErrorLogFileEndPoint errorLogFileEndPoint() {
44-
return new ErrorLogFileEndPoint();
46+
public LogFileEndPoint logFileEndPoint(LogFileRegistry logFileRegistry) {
47+
return new LogFileEndPoint(env, logFileRegistry);
4548
}
4649

4750

@@ -71,10 +74,15 @@ public CacheManagerEndpoint cacheManagerEndpoint(){
7174
return new CacheManagerEndpoint();
7275
}
7376

77+
7478
@Bean
75-
public AnotherHealthEndpoint anotherHealthEndpoint(HealthAggregator healthAggregator,
76-
Map<String, HealthIndicator> healthIndicators){
77-
return new AnotherHealthEndpoint(healthAggregator,healthIndicators);
79+
public ServiceDiscoveryCustomizer defaultServiceDiscoveryCustomizer(CuratorFramework curator,
80+
ZookeeperDiscoveryProperties properties,
81+
InstanceSerializer<ZookeeperInstance> serializer) {
82+
return new AutoRegistrationCustomizer(curator, properties, serializer);
83+
}
84+
@Bean
85+
public MetaDataProvider metaDataProvider() {
86+
return new MetaDataProvider();
7887
}
79-
8088
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package org.xujin.moss.client.config;
2+
3+
import org.apache.commons.lang3.StringUtils;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.SpringApplicationRunListener;
6+
import org.springframework.context.ConfigurableApplicationContext;
7+
import org.springframework.core.env.ConfigurableEnvironment;
8+
import org.springframework.core.env.Environment;
9+
import org.springframework.core.io.support.SpringFactoriesLoader;
10+
import org.springframework.util.CollectionUtils;
11+
import org.springframework.web.context.ContextLoader;
12+
13+
import java.util.Arrays;
14+
import java.util.Collection;
15+
import java.util.List;
16+
17+
public class AdminEndpointApplicationRunListener implements SpringApplicationRunListener {
18+
19+
@Override
20+
public void starting() {
21+
22+
}
23+
24+
@Override
25+
public void environmentPrepared(ConfigurableEnvironment env) {
26+
if("bootstrap".equals(env.getProperty("spring.config.name"))) {
27+
List<EnvironmentCustomizer> environmentCustomizers =
28+
SpringFactoriesLoader.loadFactories(EnvironmentCustomizer.class, AdminEndpointApplicationRunListener.class.getClassLoader());
29+
if(CollectionUtils.isEmpty(environmentCustomizers)) return;
30+
for(EnvironmentCustomizer customizer: environmentCustomizers) {
31+
customizer.customize(env);
32+
}
33+
}
34+
}
35+
@Override
36+
public void contextPrepared(ConfigurableApplicationContext configurableApplicationContext) {
37+
38+
}
39+
40+
@Override
41+
public void contextLoaded(ConfigurableApplicationContext configurableApplicationContext) {
42+
43+
}
44+
45+
@Override
46+
public void finished(ConfigurableApplicationContext context, Throwable throwable) {
47+
Collection<ApplicationContextCustomizer> applicationContextCustomizers =
48+
Arrays.asList(new DiscoveryClientRegistrationInvoker());
49+
for(ApplicationContextCustomizer customizer: applicationContextCustomizers) {
50+
customizer.customize(context);
51+
}
52+
}
53+
54+
public AdminEndpointApplicationRunListener(SpringApplication application, String[] args) {
55+
}
56+
public static boolean isEmbeddedServletServer(Environment env) {
57+
return StringUtils.isEmpty(env.getProperty(ContextLoader.CONFIG_LOCATION_PARAM));
58+
}
59+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.xujin.moss.client.config;
2+
3+
import org.springframework.context.ConfigurableApplicationContext;
4+
5+
public interface ApplicationContextCustomizer<T extends ConfigurableApplicationContext> {
6+
void customize(T t);
7+
}

0 commit comments

Comments
 (0)