Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
51dddbfd
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
51dddbfd
编写于
9月 29, 2019
作者:
H
huangjian888
提交者:
Liang Zhang
9月 29, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Registry center for Nacos (#3150)
* check codes by checkstyle
上级
0656fea7
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
264 addition
and
0 deletion
+264
-0
sharding-orchestration/sharding-orchestration-reg/pom.xml
sharding-orchestration/sharding-orchestration-reg/pom.xml
+1
-0
sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-nacos/pom.xml
...rchestration-reg/sharding-orchestration-reg-nacos/pom.xml
+46
-0
sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-nacos/src/main/java/org/apache/shardingsphere/orchestration/reg/nacos/NacosRegistryCenter.java
...ngsphere/orchestration/reg/nacos/NacosRegistryCenter.java
+149
-0
sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-nacos/src/main/resources/META-INF/services/org.apache.shardingsphere.orchestration.reg.api.RegistryCenter
...pache.shardingsphere.orchestration.reg.api.RegistryCenter
+18
-0
sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-nacos/src/test/java/org/apache/shardingsphere/orchestration/reg/nacos/NacosRegistryCenterTest.java
...here/orchestration/reg/nacos/NacosRegistryCenterTest.java
+50
-0
未找到文件。
sharding-orchestration/sharding-orchestration-reg/pom.xml
浏览文件 @
51dddbfd
...
...
@@ -30,5 +30,6 @@
<modules>
<module>
sharding-orchestration-reg-api
</module>
<module>
sharding-orchestration-reg-zookeeper-curator
</module>
<module>
sharding-orchestration-reg-nacos
</module>
</modules>
</project>
sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-nacos/pom.xml
0 → 100644
浏览文件 @
51dddbfd
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
org.apache.shardingsphere
</groupId>
<artifactId>
sharding-orchestration-reg
</artifactId>
<version>
4.0.0-RC3-SNAPSHOT
</version>
</parent>
<artifactId>
sharding-orchestration-reg-nacos
</artifactId>
<name>
${project.artifactId}
</name>
<properties>
<nacos-client.verison>
1.0.0
</nacos-client.verison>
</properties>
<dependencies>
<dependency>
<groupId>
org.apache.shardingsphere
</groupId>
<artifactId>
sharding-orchestration-reg-api
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
com.alibaba.nacos
</groupId>
<artifactId>
nacos-client
</artifactId>
<version>
${nacos-client.verison}
</version>
<scope>
provided
</scope>
</dependency>
</dependencies>
</project>
sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-nacos/src/main/java/org/apache/shardingsphere/orchestration/reg/nacos/NacosRegistryCenter.java
0 → 100644
浏览文件 @
51dddbfd
/*
* 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.shardingsphere.orchestration.reg.nacos
;
import
com.alibaba.nacos.api.NacosFactory
;
import
com.alibaba.nacos.api.config.ConfigService
;
import
com.alibaba.nacos.api.config.listener.Listener
;
import
com.alibaba.nacos.api.exception.NacosException
;
import
com.google.common.base.Strings
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.shardingsphere.orchestration.reg.api.RegistryCenter
;
import
org.apache.shardingsphere.orchestration.reg.api.RegistryCenterConfiguration
;
import
org.apache.shardingsphere.orchestration.reg.listener.DataChangedEvent
;
import
org.apache.shardingsphere.orchestration.reg.listener.DataChangedEventListener
;
import
java.util.List
;
import
java.util.Properties
;
import
java.util.concurrent.Executor
;
@Slf4j
public
class
NacosRegistryCenter
implements
RegistryCenter
{
private
ConfigService
configService
;
@Getter
@Setter
private
Properties
properties
=
new
Properties
();
@Override
public
void
init
(
final
RegistryCenterConfiguration
config
)
{
try
{
configService
=
NacosFactory
.
createConfigService
(
config
.
getServerLists
());
}
catch
(
NacosException
e
)
{
log
.
debug
(
"exception for: {}"
,
e
.
toString
());
}
}
@Override
public
String
get
(
final
String
key
)
{
return
getDirectly
(
key
);
}
@Override
public
String
getDirectly
(
final
String
key
)
{
try
{
String
dataId
=
key
.
replace
(
"/"
,
"."
);
String
group
=
properties
.
getProperty
(
"group"
,
"SHARDING_SPHERE_DEFAULT_GROUP"
);
long
timeoutMs
=
Long
.
parseLong
(
properties
.
getProperty
(
"timeout"
,
"3000"
));
return
configService
.
getConfig
(
dataId
,
group
,
timeoutMs
);
}
catch
(
NacosException
e
)
{
log
.
debug
(
"exception for: {}"
,
e
.
toString
());
return
null
;
}
}
@Override
public
boolean
isExisted
(
final
String
key
)
{
return
!
Strings
.
isNullOrEmpty
(
getDirectly
(
key
));
}
@Override
public
List
<
String
>
getChildrenKeys
(
final
String
key
)
{
return
null
;
}
@Override
public
void
persist
(
final
String
key
,
final
String
value
)
{
update
(
key
,
value
);
}
@Override
public
void
update
(
final
String
key
,
final
String
value
)
{
try
{
String
dataId
=
key
.
replace
(
"/"
,
"."
);
String
group
=
properties
.
getProperty
(
"group"
,
"SHARDING_SPHERE_DEFAULT_GROUP"
);
configService
.
publishConfig
(
dataId
,
group
,
value
);
}
catch
(
NacosException
e
)
{
log
.
debug
(
"exception for: {}"
,
e
.
toString
());
}
}
@Override
public
void
persistEphemeral
(
final
String
key
,
final
String
value
)
{
}
@Override
public
void
watch
(
final
String
key
,
final
DataChangedEventListener
dataChangedEventListener
)
{
try
{
String
dataId
=
key
.
replace
(
"/"
,
"."
);
String
group
=
properties
.
getProperty
(
"group"
,
"SHARDING_SPHERE_DEFAULT_GROUP"
);
configService
.
addListener
(
dataId
,
group
,
new
Listener
()
{
@Override
public
Executor
getExecutor
()
{
return
null
;
}
@Override
public
void
receiveConfigInfo
(
final
String
configInfo
)
{
dataChangedEventListener
.
onChange
(
new
DataChangedEvent
(
key
,
configInfo
,
DataChangedEvent
.
ChangedType
.
UPDATED
));
}
});
}
catch
(
NacosException
e
)
{
log
.
debug
(
"exception for: {}"
,
e
.
toString
());
}
}
@Override
public
void
close
()
{
}
@Override
public
void
initLock
(
final
String
key
)
{
}
@Override
public
boolean
tryLock
()
{
return
false
;
}
@Override
public
void
tryRelease
()
{
}
@Override
public
String
getType
()
{
return
"nacos"
;
}
}
sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-nacos/src/main/resources/META-INF/services/org.apache.shardingsphere.orchestration.reg.api.RegistryCenter
0 → 100644
浏览文件 @
51dddbfd
#
# 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.shardingsphere.orchestration.reg.nacos.NacosRegistryCenter
sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-nacos/src/test/java/org/apache/shardingsphere/orchestration/reg/nacos/NacosRegistryCenterTest.java
0 → 100644
浏览文件 @
51dddbfd
/*
* 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.shardingsphere.orchestration.reg.nacos
;
import
org.apache.shardingsphere.orchestration.reg.api.RegistryCenter
;
import
org.apache.shardingsphere.orchestration.reg.api.RegistryCenterConfiguration
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.util.Properties
;
public
class
NacosRegistryCenterTest
{
private
static
RegistryCenter
nacosRegistryCenter
=
new
NacosRegistryCenter
();
@BeforeClass
public
static
void
init
()
{
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
"group"
,
"SHARDING_SPHERE_DEFAULT_GROUP"
);
properties
.
setProperty
(
"timeout"
,
"3000"
);
RegistryCenterConfiguration
configuration
=
new
RegistryCenterConfiguration
(
nacosRegistryCenter
.
getType
(),
properties
);
configuration
.
setServerLists
(
"127.0.0.1:8848"
);
nacosRegistryCenter
.
init
(
configuration
);
}
@Test
public
void
assertPersist
()
{
nacosRegistryCenter
.
persist
(
"sharding/test"
,
"value1"
);
}
@Test
public
void
assertUpdate
()
{
nacosRegistryCenter
.
update
(
"sharding/test"
,
"value2"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录