Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
812ef596
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,发现更多精彩内容 >>
提交
812ef596
编写于
11月 15, 2017
作者:
J
junxiong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#428 add orchestrator provider
上级
d5196703
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
190 addition
and
21 deletion
+190
-21
sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/api/OrchestratorBuilder.java
...o/shardingjdbc/orchestration/api/OrchestratorBuilder.java
+13
-21
sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/api/OrchestratorFactory.java
...o/shardingjdbc/orchestration/api/OrchestratorFactory.java
+14
-0
sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/reg/etcd/EtcdConfigurationService.java
...jdbc/orchestration/reg/etcd/EtcdConfigurationService.java
+7
-0
sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/reg/etcd/EtcdDataSourceService.java
...ingjdbc/orchestration/reg/etcd/EtcdDataSourceService.java
+7
-0
sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/reg/etcd/EtcdInstanceStateService.java
...jdbc/orchestration/reg/etcd/EtcdInstanceStateService.java
+7
-0
sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/reg/etcd/EtcdOrchestratorFactory.java
...gjdbc/orchestration/reg/etcd/EtcdOrchestratorFactory.java
+39
-0
sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/reg/zookeeper/ZookeeperOrchestratorFactory.java
...estration/reg/zookeeper/ZookeeperOrchestratorFactory.java
+47
-0
sharding-jdbc-orchestration/src/main/resources/META-INF/services/io.shardingjdbc.orchestration.api.OrchestratorFactory
...ces/io.shardingjdbc.orchestration.api.OrchestratorFactory
+2
-0
sharding-jdbc-orchestration/src/test/java/io/shardingjdbc/orchestration/reg/AllRegTests.java
...t/java/io/shardingjdbc/orchestration/reg/AllRegTests.java
+11
-0
sharding-jdbc-orchestration/src/test/java/io/shardingjdbc/orchestration/reg/OrchestratorBuilderIntegrateTest.java
...c/orchestration/reg/OrchestratorBuilderIntegrateTest.java
+43
-0
未找到文件。
sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/api/OrchestratorBuilder.java
浏览文件 @
812ef596
package
io.shardingjdbc.orchestration.api
;
import
io.shardingjdbc.orchestration.api.config.OrchestratorConfiguration
;
import
io.shardingjdbc.orchestration.internal.OrchestratorImpl
;
import
io.shardingjdbc.orchestration.reg.base.*
;
import
io.shardingjdbc.orchestration.reg.zookeeper.ZookeeperConfiguration
;
import
io.shardingjdbc.orchestration.reg.zookeeper.ZookeeperRegistryCenter
;
import
io.shardingjdbc.orchestration.reg.zookeeper.config.ZkConfigurationService
;
import
io.shardingjdbc.orchestration.reg.zookeeper.state.datasource.ZkDataSourceService
;
import
io.shardingjdbc.orchestration.reg.zookeeper.state.instance.ZkInstanceStateService
;
import
io.shardingjdbc.orchestration.reg.zookeeper.ZookeeperOrchestratorFactory
;
import
java.util.ServiceLoader
;
/**
* Orchestrator builder
...
...
@@ -20,6 +16,7 @@ public class OrchestratorBuilder {
/**
* New orchestrator builder
*
* @return OrchestratorBuilder
*/
public
static
OrchestratorBuilder
newBuilder
()
{
...
...
@@ -28,6 +25,7 @@ public class OrchestratorBuilder {
/**
* with orchestorator configuration
*
* @param configuration orchestrator configuration
* @return self
*/
...
...
@@ -42,20 +40,14 @@ public class OrchestratorBuilder {
* @return orchestrator instance
*/
public
Orchestrator
build
()
{
// TODO build different kind of orchestrator
String
name
=
configuration
.
getName
();
boolean
overwrite
=
configuration
.
isOverwrite
();
CoordinatorRegistryCenter
registryCenter
=
setupRegistryCenterIfNeeded
(
configuration
);
ConfigurationService
configurationService
=
new
ZkConfigurationService
(
name
,
overwrite
,
registryCenter
);
InstanceStateService
instanceStateService
=
new
ZkInstanceStateService
(
name
,
configurationService
,
registryCenter
);
DataSourceService
dataSourceService
=
new
ZkDataSourceService
(
name
,
configurationService
,
registryCenter
);
return
new
OrchestratorImpl
(
configurationService
,
instanceStateService
,
dataSourceService
);
String
type
=
configuration
.
getRegistryCenter
().
get
(
"type"
);
ServiceLoader
<
OrchestratorFactory
>
serviceLoader
=
ServiceLoader
.
load
(
OrchestratorFactory
.
class
);
for
(
OrchestratorFactory
orchestratorFactory
:
serviceLoader
)
{
if
(
orchestratorFactory
.
target
(
type
))
{
return
orchestratorFactory
.
create
(
configuration
);
}
private
CoordinatorRegistryCenter
setupRegistryCenterIfNeeded
(
OrchestratorConfiguration
config
)
{
ZookeeperConfiguration
zkConfig
=
ZookeeperConfiguration
.
from
(
config
);
CoordinatorRegistryCenter
registryCenter
=
new
ZookeeperRegistryCenter
(
zkConfig
);
registryCenter
.
init
();
return
registryCenter
;
}
return
new
ZookeeperOrchestratorFactory
().
create
(
configuration
);
}
}
sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/api/OrchestratorFactory.java
0 → 100644
浏览文件 @
812ef596
package
io.shardingjdbc.orchestration.api
;
import
io.shardingjdbc.orchestration.api.Orchestrator
;
import
io.shardingjdbc.orchestration.api.config.OrchestratorConfiguration
;
/**
* Orchestrator factory
*
* @author junxiong
*/
public
interface
OrchestratorFactory
{
boolean
target
(
String
type
);
Orchestrator
create
(
OrchestratorConfiguration
configuration
);
}
sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/reg/etcd/EtcdConfigurationService.java
浏览文件 @
812ef596
...
...
@@ -6,6 +6,7 @@ import io.shardingjdbc.core.jdbc.core.datasource.MasterSlaveDataSource;
import
io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource
;
import
io.shardingjdbc.core.rule.MasterSlaveRule
;
import
io.shardingjdbc.orchestration.reg.base.ConfigurationService
;
import
io.shardingjdbc.orchestration.reg.base.CoordinatorRegistryCenter
;
import
javax.sql.DataSource
;
import
java.util.Map
;
...
...
@@ -15,6 +16,12 @@ import java.util.Properties;
* @author junxiong
*/
public
class
EtcdConfigurationService
implements
ConfigurationService
{
private
CoordinatorRegistryCenter
registryCenter
;
public
EtcdConfigurationService
(
CoordinatorRegistryCenter
registryCenter
)
{
this
.
registryCenter
=
registryCenter
;
}
@Override
public
void
persistShardingConfiguration
(
Map
<
String
,
DataSource
>
dataSourceMap
,
ShardingRuleConfiguration
shardingRuleConfig
,
Properties
props
,
ShardingDataSource
shardingDataSource
)
{
...
...
sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/reg/etcd/EtcdDataSourceService.java
浏览文件 @
812ef596
package
io.shardingjdbc.orchestration.reg.etcd
;
import
io.shardingjdbc.core.jdbc.core.datasource.MasterSlaveDataSource
;
import
io.shardingjdbc.orchestration.reg.base.CoordinatorRegistryCenter
;
import
io.shardingjdbc.orchestration.reg.base.DataSourceService
;
/**
* @author junxiong
*/
public
class
EtcdDataSourceService
implements
DataSourceService
{
private
CoordinatorRegistryCenter
registryCenter
;
public
EtcdDataSourceService
(
CoordinatorRegistryCenter
registryCenter
)
{
this
.
registryCenter
=
registryCenter
;
}
@Override
public
void
persistDataSourcesNodeOnline
(
MasterSlaveDataSource
masterSlaveDataSource
)
{
...
...
sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/reg/etcd/EtcdInstanceStateService.java
浏览文件 @
812ef596
...
...
@@ -2,12 +2,19 @@ package io.shardingjdbc.orchestration.reg.etcd;
import
io.shardingjdbc.core.jdbc.core.datasource.MasterSlaveDataSource
;
import
io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource
;
import
io.shardingjdbc.orchestration.reg.base.CoordinatorRegistryCenter
;
import
io.shardingjdbc.orchestration.reg.base.InstanceStateService
;
/**
* @author junxiong
*/
public
class
EtcdInstanceStateService
implements
InstanceStateService
{
private
CoordinatorRegistryCenter
registryCenter
;
public
EtcdInstanceStateService
(
CoordinatorRegistryCenter
registryCenter
)
{
this
.
registryCenter
=
registryCenter
;
}
@Override
public
void
persistShardingInstanceOnline
(
ShardingDataSource
shardingDataSource
)
{
...
...
sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/reg/etcd/EtcdOrchestratorFactory.java
0 → 100644
浏览文件 @
812ef596
package
io.shardingjdbc.orchestration.reg.etcd
;
import
io.shardingjdbc.orchestration.api.Orchestrator
;
import
io.shardingjdbc.orchestration.api.OrchestratorFactory
;
import
io.shardingjdbc.orchestration.api.config.OrchestratorConfiguration
;
import
io.shardingjdbc.orchestration.internal.OrchestratorImpl
;
import
io.shardingjdbc.orchestration.reg.base.ConfigurationService
;
import
io.shardingjdbc.orchestration.reg.base.CoordinatorRegistryCenter
;
import
io.shardingjdbc.orchestration.reg.base.DataSourceService
;
import
io.shardingjdbc.orchestration.reg.base.InstanceStateService
;
/**
* Etcd Orchestrator factory
*
* @author junxiong
*/
public
class
EtcdOrchestratorFactory
implements
OrchestratorFactory
{
@Override
public
boolean
target
(
String
type
)
{
return
"etcd"
.
equalsIgnoreCase
(
type
);
}
@Override
public
Orchestrator
create
(
OrchestratorConfiguration
configuration
)
{
CoordinatorRegistryCenter
registryCenter
=
setUpCoordinatorRegistryCenter
(
configuration
);
ConfigurationService
configurationService
=
new
EtcdConfigurationService
(
registryCenter
);
DataSourceService
dataSourceService
=
new
EtcdDataSourceService
(
registryCenter
);
InstanceStateService
instanceStateService
=
new
EtcdInstanceStateService
(
registryCenter
);
return
new
OrchestratorImpl
(
configurationService
,
instanceStateService
,
dataSourceService
);
}
private
CoordinatorRegistryCenter
setUpCoordinatorRegistryCenter
(
OrchestratorConfiguration
configuration
)
{
return
new
EtcdRegistryCenter
(
EtcdConfiguration
.
builder
()
.
namespace
(
configuration
.
getRegistryCenter
().
get
(
"namespace"
))
.
serverLists
(
configuration
.
getRegistryCenter
().
get
(
"server-lists"
))
.
build
());
}
}
sharding-jdbc-orchestration/src/main/java/io/shardingjdbc/orchestration/reg/zookeeper/ZookeeperOrchestratorFactory.java
0 → 100644
浏览文件 @
812ef596
package
io.shardingjdbc.orchestration.reg.zookeeper
;
import
io.shardingjdbc.orchestration.api.OrchestratorFactory
;
import
io.shardingjdbc.orchestration.api.Orchestrator
;
import
io.shardingjdbc.orchestration.api.config.OrchestratorConfiguration
;
import
io.shardingjdbc.orchestration.internal.OrchestratorImpl
;
import
io.shardingjdbc.orchestration.reg.base.ConfigurationService
;
import
io.shardingjdbc.orchestration.reg.base.CoordinatorRegistryCenter
;
import
io.shardingjdbc.orchestration.reg.base.DataSourceService
;
import
io.shardingjdbc.orchestration.reg.base.InstanceStateService
;
import
io.shardingjdbc.orchestration.reg.zookeeper.config.ZkConfigurationService
;
import
io.shardingjdbc.orchestration.reg.zookeeper.state.datasource.ZkDataSourceService
;
import
io.shardingjdbc.orchestration.reg.zookeeper.state.instance.ZkInstanceStateService
;
/**
* @author junxiong
*/
public
class
ZookeeperOrchestratorFactory
implements
OrchestratorFactory
{
@Override
public
boolean
target
(
String
type
)
{
return
"zk"
.
equalsIgnoreCase
(
type
);
}
/**
* build specific orchestrator instance
*
* @return orchestrator instance
*/
@Override
public
Orchestrator
create
(
OrchestratorConfiguration
configuration
)
{
String
name
=
configuration
.
getName
();
boolean
overwrite
=
configuration
.
isOverwrite
();
CoordinatorRegistryCenter
registryCenter
=
setupRegistryCenterIfNeeded
(
configuration
);
ConfigurationService
configurationService
=
new
ZkConfigurationService
(
name
,
overwrite
,
registryCenter
);
InstanceStateService
instanceStateService
=
new
ZkInstanceStateService
(
name
,
configurationService
,
registryCenter
);
DataSourceService
dataSourceService
=
new
ZkDataSourceService
(
name
,
configurationService
,
registryCenter
);
return
new
OrchestratorImpl
(
configurationService
,
instanceStateService
,
dataSourceService
);
}
private
CoordinatorRegistryCenter
setupRegistryCenterIfNeeded
(
OrchestratorConfiguration
config
)
{
ZookeeperConfiguration
zkConfig
=
ZookeeperConfiguration
.
from
(
config
);
CoordinatorRegistryCenter
registryCenter
=
new
ZookeeperRegistryCenter
(
zkConfig
);
registryCenter
.
init
();
return
registryCenter
;
}
}
sharding-jdbc-orchestration/src/main/resources/META-INF/services/io.shardingjdbc.orchestration.api.OrchestratorFactory
0 → 100644
浏览文件 @
812ef596
io.shardingjdbc.orchestration.reg.etcd.EtcdOrchestratorFactory
io.shardingjdbc.orchestration.reg.zookeeper.ZookeeperOrchestratorFactory
\ No newline at end of file
sharding-jdbc-orchestration/src/test/java/io/shardingjdbc/orchestration/reg/AllRegTests.java
0 → 100644
浏览文件 @
812ef596
package
io.shardingjdbc.orchestration.reg
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Suite
;
@RunWith
(
Suite
.
class
)
@Suite
.
SuiteClasses
({
OrchestratorBuilderIntegrateTest
.
class
})
public
class
AllRegTests
{
}
sharding-jdbc-orchestration/src/test/java/io/shardingjdbc/orchestration/reg/OrchestratorBuilderIntegrateTest.java
0 → 100644
浏览文件 @
812ef596
package
io.shardingjdbc.orchestration.reg
;
import
com.google.common.collect.Maps
;
import
io.shardingjdbc.orchestration.api.Orchestrator
;
import
io.shardingjdbc.orchestration.api.OrchestratorBuilder
;
import
io.shardingjdbc.orchestration.api.config.OrchestratorConfiguration
;
import
io.shardingjdbc.orchestration.util.EmbedTestingServer
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.util.Map
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
public
class
OrchestratorBuilderIntegrateTest
{
@BeforeClass
public
static
void
before
()
{
EmbedTestingServer
.
start
();
}
@Test
public
void
testBuildZookeeperOrchestor
()
{
Map
<
String
,
String
>
registryCenter
=
Maps
.
newHashMap
();
registryCenter
.
put
(
"type"
,
"zk"
);
registryCenter
.
put
(
"namespace"
,
"test"
);
registryCenter
.
put
(
"server-lists"
,
"localhost:3181"
);
OrchestratorConfiguration
configuration
=
new
OrchestratorConfiguration
(
"test"
,
false
,
registryCenter
);
Orchestrator
orchestrator
=
OrchestratorBuilder
.
newBuilder
().
with
(
configuration
).
build
();
assertNotNull
(
orchestrator
);
}
@Test
public
void
testBuildEtcdOrchestor
()
{
Map
<
String
,
String
>
registryCenter
=
Maps
.
newHashMap
();
registryCenter
.
put
(
"type"
,
"etcd"
);
registryCenter
.
put
(
"namespace"
,
"test"
);
registryCenter
.
put
(
"server-lists"
,
"http://localhost:2379"
);
OrchestratorConfiguration
configuration
=
new
OrchestratorConfiguration
(
"test"
,
false
,
registryCenter
);
Orchestrator
orchestrator
=
OrchestratorBuilder
.
newBuilder
().
with
(
configuration
).
build
();
assertNotNull
(
orchestrator
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录