Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
润土的好友猹
SkyWalking
提交
adb7ac44
S
SkyWalking
项目概览
润土的好友猹
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
9
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
adb7ac44
编写于
6月 18, 2019
作者:
于
于玉桔
提交者:
wu-sheng
6月 18, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Provide Zookeeper dynamic configuration center implementation. fixes #2825 (#2852)
* configration-zookeeper
上级
5df62139
变更
21
隐藏空白更改
内联
并排
Showing
21 changed file
with
860 addition
and
24 deletion
+860
-24
docs/en/setup/backend/dynamic-config.md
docs/en/setup/backend/dynamic-config.md
+19
-3
oap-server/pom.xml
oap-server/pom.xml
+29
-0
oap-server/server-cluster-plugin/cluster-zookeeper-plugin/pom.xml
...er/server-cluster-plugin/cluster-zookeeper-plugin/pom.xml
+0
-21
oap-server/server-configuration/configuration-zookeeper/pom.xml
...rver/server-configuration/configuration-zookeeper/pom.xml
+146
-0
oap-server/server-configuration/configuration-zookeeper/src/main/java/org/apache/skywalking/oap/server/configuration/zookeeper/ZookeeperConfigWatcherRegister.java
...nfiguration/zookeeper/ZookeeperConfigWatcherRegister.java
+58
-0
oap-server/server-configuration/configuration-zookeeper/src/main/java/org/apache/skywalking/oap/server/configuration/zookeeper/ZookeeperConfigurationProvider.java
...nfiguration/zookeeper/ZookeeperConfigurationProvider.java
+64
-0
oap-server/server-configuration/configuration-zookeeper/src/main/java/org/apache/skywalking/oap/server/configuration/zookeeper/ZookeeperServerSettings.java
...rver/configuration/zookeeper/ZookeeperServerSettings.java
+45
-0
oap-server/server-configuration/configuration-zookeeper/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider
...pache.skywalking.oap.server.library.module.ModuleProvider
+18
-0
oap-server/server-configuration/configuration-zookeeper/src/test/java/org/apache/skywalking/oap/server/configuration/zookeeper/it/ITZookeeperConfigurationTest.java
...figuration/zookeeper/it/ITZookeeperConfigurationTest.java
+126
-0
oap-server/server-configuration/configuration-zookeeper/src/test/java/org/apache/skywalking/oap/server/configuration/zookeeper/it/MockZookeeperConfigurationModule.java
...ration/zookeeper/it/MockZookeeperConfigurationModule.java
+37
-0
oap-server/server-configuration/configuration-zookeeper/src/test/java/org/apache/skywalking/oap/server/configuration/zookeeper/it/MockZookeeperConfigurationProvider.java
...tion/zookeeper/it/MockZookeeperConfigurationProvider.java
+93
-0
oap-server/server-configuration/configuration-zookeeper/src/test/java/org/apache/skywalking/oap/server/configuration/zookeeper/ut/MockZookeeperConfigWatcherRegister.java
...tion/zookeeper/ut/MockZookeeperConfigWatcherRegister.java
+51
-0
oap-server/server-configuration/configuration-zookeeper/src/test/java/org/apache/skywalking/oap/server/configuration/zookeeper/ut/ZookeeperConfigWatcherRegisterTestCase.java
.../zookeeper/ut/ZookeeperConfigWatcherRegisterTestCase.java
+57
-0
oap-server/server-configuration/configuration-zookeeper/src/test/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleDefine
....apache.skywalking.oap.server.library.module.ModuleDefine
+20
-0
oap-server/server-configuration/configuration-zookeeper/src/test/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider
...pache.skywalking.oap.server.library.module.ModuleProvider
+19
-0
oap-server/server-configuration/configuration-zookeeper/src/test/resources/application.yml
...onfiguration-zookeeper/src/test/resources/application.yml
+27
-0
oap-server/server-configuration/configuration-zookeeper/src/test/resources/log4j2.xml
...ion/configuration-zookeeper/src/test/resources/log4j2.xml
+31
-0
oap-server/server-configuration/pom.xml
oap-server/server-configuration/pom.xml
+1
-0
oap-server/server-starter/pom.xml
oap-server/server-starter/pom.xml
+5
-0
oap-server/server-starter/src/main/assembly/application.yml
oap-server/server-starter/src/main/assembly/application.yml
+7
-0
oap-server/server-starter/src/main/resources/application.yml
oap-server/server-starter/src/main/resources/application.yml
+7
-0
未找到文件。
docs/en/setup/backend/dynamic-config.md
浏览文件 @
adb7ac44
...
...
@@ -33,7 +33,7 @@ configuration:
## Dynamic Configuration Apollo Implementation
[
Apollo
](
https://github.com/ctripcorp/apollo/
)
is also supported
in DCS
, to use it, just configured as follows:
[
Apollo
](
https://github.com/ctripcorp/apollo/
)
is also supported
as DCC(Dynamic Configuration Center)
, to use it, just configured as follows:
```
yaml
configuration
:
...
...
@@ -47,7 +47,7 @@ configuration:
## Dynamic Configuration Nacos Implementation
[
Nacos
](
https://github.com/alibaba/nacos
)
is also supported
in DCS
, to use it, please configure as follows:
[
Nacos
](
https://github.com/alibaba/nacos
)
is also supported
as DCC(Dynamic Configuration Center)
, to use it, please configure as follows:
```
yaml
configuration
:
...
...
@@ -64,8 +64,24 @@ configuration:
clusterName
:
"
default"
```
## Dynamic Configuration Zookeeper Implementation
[
Zookeeper
](
https://github.com/apache/zookeeper
)
is also supported as DCC(Dynamic Configuration Center), to use it, please configure as follows:
```
yaml
configuration
:
zookeeper
:
period
:
60
# Unit seconds, sync period. Default fetch every 60 seconds.
nameSpace
:
/default
hostPort
:
localhost:2181
#Retry Policy
baseSleepTimeMs
:
1000
# initial amount of time to wait between retries
maxRetries
:
3
# max number of times to retry
```
## 3rd party Configuration Center
We are welcome contributions to implement this module provider to support popular configuration center,
such as
Zookeeper, etcd,
Consul. Submit issue to discuss.
such as Consul. Submit issue to discuss.
oap-server/pom.xml
浏览文件 @
adb7ac44
...
...
@@ -79,6 +79,8 @@
<apollo.version>
1.4.0
</apollo.version>
<maven-docker-plugin.version>
0.30.0
</maven-docker-plugin.version>
<nacos.version>
1.0.0
</nacos.version>
<curator.version>
4.0.1
</curator.version>
<curator-test.version>
2.12.0
</curator-test.version>
<etcd4j.version>
2.17.0
</etcd4j.version>
<etcd.version>
v3.2.3
</etcd.version>
</properties>
...
...
@@ -378,6 +380,33 @@
<artifactId>
etcd4j
</artifactId>
<version>
${etcd4j.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.curator
</groupId>
<artifactId>
curator-x-discovery
</artifactId>
<version>
${curator.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>
<dependency>
<groupId>
org.apache.curator
</groupId>
<artifactId>
curator-test
</artifactId>
<version>
${curator-test.version}
</version>
<exclusions>
<exclusion>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
</exclusion>
</exclusions>
<scope>
test
</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
oap-server/server-cluster-plugin/cluster-zookeeper-plugin/pom.xml
浏览文件 @
adb7ac44
...
...
@@ -30,7 +30,6 @@
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<curator.version>
4.0.1
</curator.version>
</properties>
<dependencies>
...
...
@@ -46,30 +45,10 @@
<dependency>
<groupId>
org.apache.curator
</groupId>
<artifactId>
curator-x-discovery
</artifactId>
<version>
${curator.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>
<dependency>
<groupId>
org.apache.curator
</groupId>
<artifactId>
curator-test
</artifactId>
<version>
2.12.0
</version>
<!--<version>${curator.version}</version>-->
<exclusions>
<exclusion>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
</exclusion>
</exclusions>
<scope>
test
</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
oap-server/server-configuration/configuration-zookeeper/pom.xml
0 → 100644
浏览文件 @
adb7ac44
<?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.2.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
configuration-zookeeper
</artifactId>
<properties>
<zookeeper.image.version>
3.5
</zookeeper.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>
org.apache.skywalking
</groupId>
<artifactId>
cluster-zookeeper-plugin
</artifactId>
<version>
${project.version}
</version>
</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>
<logDate>
default
</logDate>
<verbose>
true
</verbose>
<showLogs>
true
</showLogs>
<imagePullPolicy>
IfNotPresent
</imagePullPolicy>
</configuration>
<executions>
<execution>
<id>
prepare-zookeeper
</id>
<phase>
pre-integration-test
</phase>
<goals>
<goal>
start
</goal>
</goals>
<configuration>
<images>
<image>
<name>
zookeeper:${zookeeper.image.version}
</name>
<alias>
zookeeper-dynamic-configuration-integration-test-zookeeper
</alias>
<run>
<ports>
<port>
zk-port:2181
</port>
</ports>
<wait>
<log>
binding to port
</log>
<time>
30000
</time>
</wait>
</run>
</image>
</images>
</configuration>
</execution>
<execution>
<id>
prepare-zookeeper-start
</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')
</source>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-failsafe-plugin
</artifactId>
<configuration>
<systemPropertyVariables>
<zk.address>
${docker.hostname}:${zk-port}
</zk.address>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>
integration-test
</goal>
<goal>
verify
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
oap-server/server-configuration/configuration-zookeeper/src/main/java/org/apache/skywalking/oap/server/configuration/zookeeper/ZookeeperConfigWatcherRegister.java
0 → 100644
浏览文件 @
adb7ac44
/*
* 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.zookeeper
;
import
org.apache.curator.RetryPolicy
;
import
org.apache.curator.framework.CuratorFramework
;
import
org.apache.curator.framework.CuratorFrameworkFactory
;
import
org.apache.curator.framework.recipes.cache.ChildData
;
import
org.apache.curator.framework.recipes.cache.PathChildrenCache
;
import
org.apache.curator.retry.ExponentialBackoffRetry
;
import
org.apache.skywalking.oap.server.configuration.api.ConfigTable
;
import
org.apache.skywalking.oap.server.configuration.api.ConfigWatcherRegister
;
import
java.util.Set
;
/**
* @author zhaoyuguang
*/
public
class
ZookeeperConfigWatcherRegister
extends
ConfigWatcherRegister
{
private
final
PathChildrenCache
childrenCache
;
private
final
String
prefix
;
public
ZookeeperConfigWatcherRegister
(
ZookeeperServerSettings
settings
)
throws
Exception
{
super
(
settings
.
getPeriod
());
prefix
=
settings
.
getNameSpace
()
+
"/"
;
RetryPolicy
retryPolicy
=
new
ExponentialBackoffRetry
(
settings
.
getBaseSleepTimeMs
(),
settings
.
getMaxRetries
());
CuratorFramework
client
=
CuratorFrameworkFactory
.
newClient
(
settings
.
getHostPort
(),
retryPolicy
);
client
.
start
();
this
.
childrenCache
=
new
PathChildrenCache
(
client
,
settings
.
getNameSpace
(),
true
);
this
.
childrenCache
.
start
();
}
@Override
public
ConfigTable
readConfig
(
Set
<
String
>
keys
)
{
ConfigTable
table
=
new
ConfigTable
();
keys
.
forEach
(
s
->
{
ChildData
data
=
this
.
childrenCache
.
getCurrentData
(
this
.
prefix
+
s
);
table
.
add
(
new
ConfigTable
.
ConfigItem
(
s
,
data
==
null
?
null
:
new
String
(
data
.
getData
())));
});
return
table
;
}
}
oap-server/server-configuration/configuration-zookeeper/src/main/java/org/apache/skywalking/oap/server/configuration/zookeeper/ZookeeperConfigurationProvider.java
0 → 100644
浏览文件 @
adb7ac44
/*
* 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.zookeeper
;
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
;
/**
* Get configuration from Zookeeper.
*
* @author zhaoyuguang
*/
public
class
ZookeeperConfigurationProvider
extends
AbstractConfigurationProvider
{
private
ZookeeperServerSettings
settings
;
public
ZookeeperConfigurationProvider
()
{
settings
=
new
ZookeeperServerSettings
();
}
@Override
public
String
name
()
{
return
"zookeeper"
;
}
@Override
public
ModuleConfig
createConfigBeanIfAbsent
()
{
return
settings
;
}
@Override
protected
ConfigWatcherRegister
initConfigReader
()
throws
ModuleStartException
{
if
(
Strings
.
isNullOrEmpty
(
settings
.
getHostPort
()))
{
throw
new
ModuleStartException
(
"Zookeeper hostPort cannot be null or empty."
);
}
if
(
Strings
.
isNullOrEmpty
(
settings
.
getNameSpace
()))
{
throw
new
ModuleStartException
(
"Zookeeper nameSpace cannot be null or empty."
);
}
try
{
return
new
ZookeeperConfigWatcherRegister
(
settings
);
}
catch
(
Exception
e
)
{
throw
new
ModuleStartException
(
e
.
getMessage
(),
e
);
}
}
}
oap-server/server-configuration/configuration-zookeeper/src/main/java/org/apache/skywalking/oap/server/configuration/zookeeper/ZookeeperServerSettings.java
0 → 100644
浏览文件 @
adb7ac44
/*
* 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.zookeeper
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.apache.skywalking.oap.server.library.module.ModuleConfig
;
/**
* @author zhaoyuguang
*/
@Getter
@Setter
public
class
ZookeeperServerSettings
extends
ModuleConfig
{
private
String
nameSpace
=
"/default"
;
private
String
hostPort
;
private
int
baseSleepTimeMs
=
1000
;
private
int
maxRetries
=
3
;
private
int
period
=
60
;
@Override
public
String
toString
()
{
return
"ZookeeperServerSettings(nameSpace="
+
this
.
getNameSpace
()
+
", hostPort="
+
this
.
getHostPort
()
+
", baseSleepTimeMs="
+
this
.
getBaseSleepTimeMs
()
+
", maxRetries="
+
this
.
getMaxRetries
()
+
", period="
+
this
.
getPeriod
()
+
")"
;
}
}
oap-server/server-configuration/configuration-zookeeper/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider
0 → 100644
浏览文件 @
adb7ac44
#
# 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.
#
#
org.apache.skywalking.oap.server.configuration.zookeeper.ZookeeperConfigurationProvider
\ No newline at end of file
oap-server/server-configuration/configuration-zookeeper/src/test/java/org/apache/skywalking/oap/server/configuration/zookeeper/it/ITZookeeperConfigurationTest.java
0 → 100644
浏览文件 @
adb7ac44
/*
* 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.zookeeper.it
;
import
org.apache.curator.RetryPolicy
;
import
org.apache.curator.framework.CuratorFramework
;
import
org.apache.curator.framework.CuratorFrameworkFactory
;
import
org.apache.curator.retry.ExponentialBackoffRetry
;
import
org.apache.skywalking.apm.util.PropertyPlaceholderHelper
;
import
org.apache.skywalking.oap.server.library.module.ApplicationConfiguration
;
import
org.apache.skywalking.oap.server.library.module.ModuleManager
;
import
org.apache.skywalking.oap.server.library.util.CollectionUtils
;
import
org.apache.skywalking.oap.server.library.util.ResourceUtils
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.yaml.snakeyaml.Yaml
;
import
java.io.FileNotFoundException
;
import
java.io.Reader
;
import
java.util.Map
;
import
java.util.Properties
;
import
static
org
.
junit
.
Assert
.*;
/**
* @author zhaoyuguang
*/
public
class
ITZookeeperConfigurationTest
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ITZookeeperConfigurationTest
.
class
);
private
final
Yaml
yaml
=
new
Yaml
();
private
MockZookeeperConfigurationProvider
provider
;
@Before
public
void
setUp
()
throws
Exception
{
final
ApplicationConfiguration
applicationConfiguration
=
new
ApplicationConfiguration
();
loadConfig
(
applicationConfiguration
);
final
ModuleManager
moduleManager
=
new
ModuleManager
();
moduleManager
.
init
(
applicationConfiguration
);
provider
=
(
MockZookeeperConfigurationProvider
)
moduleManager
.
find
(
MockZookeeperConfigurationModule
.
NAME
)
.
provider
();
assertNotNull
(
provider
);
}
@SuppressWarnings
(
"StatementWithEmptyBody"
)
@Test
(
timeout
=
20000
)
public
void
shouldReadUpdated
()
throws
Exception
{
String
nameSpace
=
"/default"
;
String
key
=
"test-module.default.testKey"
;
assertNull
(
provider
.
watcher
.
value
());
String
zkAddress
=
System
.
getProperty
(
"zk.address"
);
LOGGER
.
info
(
"zkAddress: "
+
zkAddress
);
RetryPolicy
retryPolicy
=
new
ExponentialBackoffRetry
(
1000
,
3
);
CuratorFramework
client
=
CuratorFrameworkFactory
.
newClient
(
zkAddress
,
retryPolicy
);
client
.
start
();
LOGGER
.
info
(
"per path: "
+
nameSpace
+
"/"
+
key
);
assertTrue
(
client
.
create
().
creatingParentsIfNeeded
().
forPath
(
nameSpace
+
"/"
+
key
,
"500"
.
getBytes
())
!=
null
);
LOGGER
.
info
(
"data: "
+
new
String
(
client
.
getData
().
forPath
(
nameSpace
+
"/"
+
key
)));
for
(
String
v
=
provider
.
watcher
.
value
();
v
==
null
;
v
=
provider
.
watcher
.
value
())
{
}
assertTrue
(
client
.
delete
().
forPath
(
nameSpace
+
"/"
+
key
)
==
null
);
for
(
String
v
=
provider
.
watcher
.
value
();
v
!=
null
;
v
=
provider
.
watcher
.
value
())
{
}
assertNull
(
provider
.
watcher
.
value
());
}
@SuppressWarnings
(
"unchecked"
)
private
void
loadConfig
(
ApplicationConfiguration
configuration
)
throws
FileNotFoundException
{
Reader
applicationReader
=
ResourceUtils
.
read
(
"application.yml"
);
Map
<
String
,
Map
<
String
,
Map
<
String
,
?>>>
moduleConfig
=
yaml
.
loadAs
(
applicationReader
,
Map
.
class
);
if
(
CollectionUtils
.
isNotEmpty
(
moduleConfig
))
{
moduleConfig
.
forEach
((
moduleName
,
providerConfig
)
->
{
if
(
providerConfig
.
size
()
>
0
)
{
ApplicationConfiguration
.
ModuleConfiguration
moduleConfiguration
=
configuration
.
addModule
(
moduleName
);
providerConfig
.
forEach
((
name
,
propertiesConfig
)
->
{
Properties
properties
=
new
Properties
();
if
(
propertiesConfig
!=
null
)
{
propertiesConfig
.
forEach
((
key
,
value
)
->
{
properties
.
put
(
key
,
value
);
final
Object
replaceValue
=
yaml
.
load
(
PropertyPlaceholderHelper
.
INSTANCE
.
replacePlaceholders
(
value
+
""
,
properties
));
if
(
replaceValue
!=
null
)
{
properties
.
replace
(
key
,
replaceValue
);
}
});
}
moduleConfiguration
.
addProviderConfiguration
(
name
,
properties
);
});
}
});
}
}
}
oap-server/server-configuration/configuration-zookeeper/src/test/java/org/apache/skywalking/oap/server/configuration/zookeeper/it/MockZookeeperConfigurationModule.java
0 → 100644
浏览文件 @
adb7ac44
/*
* 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.zookeeper.it
;
import
org.apache.skywalking.oap.server.library.module.ModuleDefine
;
/**
* @author zhaoyuguang
*/
public
class
MockZookeeperConfigurationModule
extends
ModuleDefine
{
public
static
final
String
NAME
=
"test-module"
;
public
MockZookeeperConfigurationModule
()
{
super
(
NAME
);
}
@Override
public
Class
[]
services
()
{
return
new
Class
[
0
];
}
}
oap-server/server-configuration/configuration-zookeeper/src/test/java/org/apache/skywalking/oap/server/configuration/zookeeper/it/MockZookeeperConfigurationProvider.java
0 → 100644
浏览文件 @
adb7ac44
/*
* 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.zookeeper.it
;
import
org.apache.skywalking.oap.server.configuration.api.ConfigChangeWatcher
;
import
org.apache.skywalking.oap.server.configuration.api.ConfigurationModule
;
import
org.apache.skywalking.oap.server.configuration.api.DynamicConfigurationService
;
import
org.apache.skywalking.oap.server.library.module.*
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* @author zhaoyuguang
*/
public
class
MockZookeeperConfigurationProvider
extends
ModuleProvider
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
MockZookeeperConfigurationProvider
.
class
);
ConfigChangeWatcher
watcher
;
@Override
public
String
name
()
{
return
"default"
;
}
@Override
public
Class
<?
extends
ModuleDefine
>
module
()
{
return
MockZookeeperConfigurationModule
.
class
;
}
@Override
public
ModuleConfig
createConfigBeanIfAbsent
()
{
return
new
ModuleConfig
()
{
};
}
@Override
public
void
prepare
()
throws
ServiceNotProvidedException
{
watcher
=
new
ConfigChangeWatcher
(
MockZookeeperConfigurationModule
.
NAME
,
this
,
"testKey"
)
{
private
volatile
String
testValue
;
@Override
public
void
notify
(
ConfigChangeEvent
value
)
{
LOGGER
.
info
(
"ConfigChangeWatcher.ConfigChangeEvent: {}"
,
value
);
if
(
EventType
.
DELETE
.
equals
(
value
.
getEventType
()))
{
testValue
=
null
;
}
else
{
testValue
=
value
.
getNewValue
();
}
}
@Override
public
String
value
()
{
return
testValue
;
}
};
}
@Override
public
void
start
()
throws
ServiceNotProvidedException
{
getManager
().
find
(
ConfigurationModule
.
NAME
)
.
provider
()
.
getService
(
DynamicConfigurationService
.
class
)
.
registerConfigChangeWatcher
(
watcher
);
}
@Override
public
void
notifyAfterCompleted
()
throws
ServiceNotProvidedException
{
}
@Override
public
String
[]
requiredModules
()
{
return
new
String
[]
{
ConfigurationModule
.
NAME
};
}
}
oap-server/server-configuration/configuration-zookeeper/src/test/java/org/apache/skywalking/oap/server/configuration/zookeeper/ut/MockZookeeperConfigWatcherRegister.java
0 → 100644
浏览文件 @
adb7ac44
/*
* 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.zookeeper.ut
;
import
org.apache.curator.framework.recipes.cache.ChildData
;
import
org.apache.curator.framework.recipes.cache.PathChildrenCache
;
import
org.apache.skywalking.oap.server.configuration.api.ConfigTable
;
import
org.apache.skywalking.oap.server.configuration.api.ConfigWatcherRegister
;
import
org.apache.skywalking.oap.server.configuration.zookeeper.ZookeeperServerSettings
;
import
java.util.Set
;
/**
* @author zhaoyuguang
*/
public
class
MockZookeeperConfigWatcherRegister
extends
ConfigWatcherRegister
{
private
PathChildrenCache
childrenCache
;
private
final
String
prefix
;
public
MockZookeeperConfigWatcherRegister
(
ZookeeperServerSettings
settings
)
throws
Exception
{
super
(
settings
.
getPeriod
());
prefix
=
settings
.
getNameSpace
()
+
"/"
;
}
@Override
public
ConfigTable
readConfig
(
Set
<
String
>
keys
)
{
ConfigTable
table
=
new
ConfigTable
();
keys
.
forEach
(
s
->
{
ChildData
data
=
this
.
childrenCache
.
getCurrentData
(
this
.
prefix
+
s
);
table
.
add
(
new
ConfigTable
.
ConfigItem
(
s
,
data
==
null
?
null
:
new
String
(
data
.
getData
())));
});
return
table
;
}
}
\ No newline at end of file
oap-server/server-configuration/configuration-zookeeper/src/test/java/org/apache/skywalking/oap/server/configuration/zookeeper/ut/ZookeeperConfigWatcherRegisterTestCase.java
0 → 100644
浏览文件 @
adb7ac44
/*
* 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.zookeeper.ut
;
import
com.google.common.collect.Sets
;
import
org.apache.curator.framework.recipes.cache.ChildData
;
import
org.apache.curator.framework.recipes.cache.PathChildrenCache
;
import
org.apache.skywalking.oap.server.configuration.api.ConfigTable
;
import
org.apache.skywalking.oap.server.configuration.zookeeper.ZookeeperServerSettings
;
import
org.junit.Test
;
import
org.powermock.reflect.Whitebox
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Mockito
.*;
/**
* @author zhaoyuguang
*/
public
class
ZookeeperConfigWatcherRegisterTestCase
{
@Test
public
void
TestCase
()
throws
Exception
{
final
String
nameSpace
=
"/default"
;
final
String
key
=
"receiver-trace.default.slowDBAccessThreshold"
;
final
String
value
=
"default:100,mongodb:50"
;
final
ZookeeperServerSettings
mockSettings
=
mock
(
ZookeeperServerSettings
.
class
);
when
(
mockSettings
.
getNameSpace
()).
thenReturn
(
nameSpace
);
final
MockZookeeperConfigWatcherRegister
mockRegister
=
spy
(
new
MockZookeeperConfigWatcherRegister
(
mockSettings
));
final
PathChildrenCache
mockPathChildrenCache
=
mock
(
PathChildrenCache
.
class
);
when
(
mockPathChildrenCache
.
getCurrentData
(
nameSpace
+
"/"
+
key
)).
thenReturn
(
new
ChildData
(
nameSpace
+
"/"
+
key
,
null
,
value
.
getBytes
()));
Whitebox
.
setInternalState
(
mockRegister
,
"childrenCache"
,
mockPathChildrenCache
);
final
ConfigTable
configTable
=
mockRegister
.
readConfig
(
Sets
.
newHashSet
(
key
));
assertEquals
(
1
,
configTable
.
getItems
().
size
());
assertEquals
(
key
,
configTable
.
getItems
().
get
(
0
).
getName
());
assertEquals
(
value
,
configTable
.
getItems
().
get
(
0
).
getValue
());
}
}
oap-server/server-configuration/configuration-zookeeper/src/test/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleDefine
0 → 100644
浏览文件 @
adb7ac44
#
# 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.
#
#
org.apache.skywalking.oap.server.configuration.api.ConfigurationModule
org.apache.skywalking.oap.server.configuration.zookeeper.it.MockZookeeperConfigurationModule
oap-server/server-configuration/configuration-zookeeper/src/test/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleProvider
0 → 100644
浏览文件 @
adb7ac44
#
# 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.
#
#
org.apache.skywalking.oap.server.configuration.zookeeper.it.MockZookeeperConfigurationProvider
\ No newline at end of file
oap-server/server-configuration/configuration-zookeeper/src/test/resources/application.yml
0 → 100644
浏览文件 @
adb7ac44
# 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.
test-module
:
default
:
testKey
:
300
configuration
:
zookeeper
:
period
:
1
# Unit seconds, sync period. Default fetch every 60 seconds.
nameSpace
:
/default
hostPort
:
${zk.address}
baseSleepTimeMs
:
1000
# initial amount of time to wait between retries
maxRetries
:
3
# max number of times to retry
oap-server/server-configuration/configuration-zookeeper/src/test/resources/log4j2.xml
0 → 100644
浏览文件 @
adb7ac44
<?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.
~
-->
<Configuration
status=
"INFO"
>
<Appenders>
<Console
name=
"Console"
target=
"SYSTEM_OUT"
>
<PatternLayout
charset=
"UTF-8"
pattern=
"%d - %c -%-4r [%t] %-5p %x - %m%n"
/>
</Console>
</Appenders>
<Loggers>
<Root
level=
"INFO"
>
<AppenderRef
ref=
"Console"
/>
</Root>
</Loggers>
</Configuration>
\ No newline at end of file
oap-server/server-configuration/pom.xml
浏览文件 @
adb7ac44
...
...
@@ -34,6 +34,7 @@
<module>
grpc-configuration-sync
</module>
<module>
configuration-apollo
</module>
<module>
configuration-nacos
</module>
<module>
configuration-zookeeper
</module>
<module>
configuration-etcd
</module>
</modules>
...
...
oap-server/server-starter/pom.xml
浏览文件 @
adb7ac44
...
...
@@ -194,6 +194,11 @@
<artifactId>
configuration-nacos
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.skywalking
</groupId>
<artifactId>
configuration-zookeeper
</artifactId>
<version>
${project.version}
</version>
</dependency>
</dependencies>
<build>
<finalName>
skywalking-oap
</finalName>
...
...
oap-server/server-starter/src/main/assembly/application.yml
浏览文件 @
adb7ac44
...
...
@@ -140,6 +140,13 @@ configuration:
# period : 60
# # the name of current cluster, set the name if you want to upstream system known.
# clusterName: "default"
# zookeeper:
# period : 60 # Unit seconds, sync period. Default fetch every 60 seconds.
# nameSpace: /default
# hostPort: localhost:2181
# #Retry Policy
# baseSleepTimeMs: 1000 # initial amount of time to wait between retries
# maxRetries: 3 # max number of times to retry
#exporter:
# grpc:
# targetHost: ${SW_EXPORTER_GRPC_HOST:127.0.0.1}
...
...
oap-server/server-starter/src/main/resources/application.yml
浏览文件 @
adb7ac44
...
...
@@ -152,6 +152,13 @@ configuration:
# period : 5
# # the name of current cluster, set the name if you want to upstream system known.
# clusterName: "default"
# zookeeper:
# period : 60 # Unit seconds, sync period. Default fetch every 60 seconds.
# nameSpace: /default
# hostPort: localhost:2181
# #Retry Policy
# baseSleepTimeMs: 1000 # initial amount of time to wait between retries
# maxRetries: 3 # max number of times to retry
#exporter:
# grpc:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录