-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide Consul dynamic configuration center implementation (#3560)
* Provide Consul dynamic configuration center implementation * Add more unit tests * Fix unit test * Add more unit tests and remove unused file * Remove redundant doc
- Loading branch information
1 parent
46318e0
commit 81f4c08
Showing
24 changed files
with
1,118 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
oap-server/server-configuration/configuration-consul/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Licensed to the Apache Software Foundation (ASF) under one or more | ||
~ contributor license agreements. See the NOTICE file distributed with | ||
~ this work for additional information regarding copyright ownership. | ||
~ The ASF licenses this file to You under the Apache License, Version 2.0 | ||
~ (the "License"); you may not use this file except in compliance with | ||
~ the License. You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
~ | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>server-configuration</artifactId> | ||
<groupId>org.apache.skywalking</groupId> | ||
<version>6.5.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>configuration-consul</artifactId> | ||
|
||
<properties> | ||
<consul.client.version>1.2.6</consul.client.version> | ||
<consul.image.version>0.9</consul.image.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.skywalking</groupId> | ||
<artifactId>configuration-api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.skywalking</groupId> | ||
<artifactId>library-client</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.orbitz.consul</groupId> | ||
<artifactId>consul-client</artifactId> | ||
<version>${consul.client.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<profiles> | ||
<profile> | ||
<id>CI-with-IT</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>docker-maven-plugin</artifactId> | ||
<configuration> | ||
<sourceMode>all</sourceMode> | ||
<showLogs>true</showLogs> | ||
<logDate>default</logDate> | ||
<verbose>true</verbose> | ||
<imagePullPolicy>IfNotPresent</imagePullPolicy> | ||
<images> | ||
<image> | ||
<name>consul:${consul.image.version}</name> | ||
<alias>cluster-consul-plugin-integration-test-cluster</alias> | ||
<run> | ||
<cmd>agent -server -bootstrap-expect=1 -client=0.0.0.0</cmd> | ||
<ports> | ||
<port>consul.port:8500</port> | ||
</ports> | ||
<wait> | ||
<log>Synced node info</log> | ||
<time>30000</time> | ||
</wait> | ||
</run> | ||
</image> | ||
</images> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>start</id> | ||
<phase>pre-integration-test</phase> | ||
<goals> | ||
<goal>start</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>stop</id> | ||
<phase>post-integration-test</phase> | ||
<goals> | ||
<goal>stop</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.gmaven</groupId> | ||
<artifactId>gmaven-plugin</artifactId> | ||
<version>${gmaven-plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>add-default-properties</id> | ||
<phase>initialize</phase> | ||
<goals> | ||
<goal>execute</goal> | ||
</goals> | ||
<configuration> | ||
<providerSelection>2.0</providerSelection> | ||
<source> | ||
project.properties.setProperty('docker.hostname', 'localhost') | ||
|
||
log.info("Docker hostname is " + project.properties['docker.hostname']) | ||
</source> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<consul.address> | ||
${docker.hostname}:${consul.port} | ||
</consul.address> | ||
</systemPropertyVariables> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>integration-test</goal> | ||
<goal>verify</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
36 changes: 36 additions & 0 deletions
36
.../apache/skywalking/oap/server/configuration/consul/ConsulConfigurationCenterSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package org.apache.skywalking.oap.server.configuration.consul; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.apache.skywalking.oap.server.library.module.ModuleConfig; | ||
|
||
/** | ||
* @author kezhenxu94 | ||
*/ | ||
public class ConsulConfigurationCenterSettings extends ModuleConfig { | ||
@Getter | ||
@Setter | ||
private long period; | ||
|
||
@Getter | ||
@Setter | ||
private String hostAndPorts; | ||
} |
63 changes: 63 additions & 0 deletions
63
...va/org/apache/skywalking/oap/server/configuration/consul/ConsulConfigurationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package org.apache.skywalking.oap.server.configuration.consul; | ||
|
||
import com.google.common.base.Strings; | ||
import org.apache.skywalking.oap.server.configuration.api.AbstractConfigurationProvider; | ||
import org.apache.skywalking.oap.server.configuration.api.ConfigWatcherRegister; | ||
import org.apache.skywalking.oap.server.library.module.ModuleConfig; | ||
import org.apache.skywalking.oap.server.library.module.ModuleStartException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Get configuration from Consul. | ||
* | ||
* @author kezhenxu94 | ||
*/ | ||
public class ConsulConfigurationProvider extends AbstractConfigurationProvider { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(ConsulConfigurationProvider.class); | ||
|
||
private final ConsulConfigurationCenterSettings settings; | ||
|
||
public ConsulConfigurationProvider() { | ||
this.settings = new ConsulConfigurationCenterSettings(); | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return "consul"; | ||
} | ||
|
||
@Override | ||
public ModuleConfig createConfigBeanIfAbsent() { | ||
return settings; | ||
} | ||
|
||
@Override | ||
protected ConfigWatcherRegister initConfigReader() throws ModuleStartException { | ||
LOGGER.info("consul settings: {}", settings); | ||
|
||
if (Strings.isNullOrEmpty(settings.getHostAndPorts())) { | ||
throw new ModuleStartException("Consul hostAndPorts cannot be null or empty"); | ||
} | ||
|
||
return new ConsulConfigurationWatcherRegister(settings); | ||
} | ||
} |
Oops, something went wrong.